Preserve original encoded certificate bytes.

Sadly, the publicly visible android.content.pm.Signature object needs
to return the untouched bytes from the parsed APK certificate.  Since
some CertificateFactory implementations may try re-encoding the
certificate, we defensively keep around the original encoded bytes
and return them when asked.

(cherry-pick of commit 0c990ab4a90b8a5492a67b2b728ac9a4a1ccfa1b)

Bug: 18206852, 18228011
Change-Id: I6016eaea23a7f43cf9249ec43cfde1f8ed4ff841
Fix InetSocketAddress.getHostString(): return the name if available

getHostString() would return the IP address in one of the three
scenarios possible:

1) InetSocketAddress created with a name - already worked, name returned.
2) InetSocketAddress create with an InetAddress with only an address - already worked,
  address returned.
3) InetSocketAddress create with an InetAddress with an address and name: would return
the address.

Change-Id: Id9d1addda5cef589ac56db5397e00e842cf8c5d7
When connecting to a SOCKS proxy, use the resolved IP

Noticed while inspecting the code. In HttpURLConnection a similar
change was made recently (commit
797fdc6cc6bf16372e9464f189b535148f944ce9).

Previously if the Proxy was specified with a resolved
InetSocketAddress (i.e. one with a specific IP address already
determined) the hostname would still be used to work out an IP
address to connect to. For host names with multiple IPs the host
connected to could be a different one than the one specified.

Now if the InetAddress has been resolved it will be used. In the
case where the InetAddress is bad this may delay DNS / resolution
errors to later in the connection process. It will, however, avoid
the "connect to a different host" issue, and avoid a reverse DNS
lookup here when the host is not yet known.

Change-Id: I46df5c38942f2d356ba2fd4541e0269021fd6496
luni: Disable strict aliasing unless explicitly told otherwise.
Only allow once GC request at a time.

There is no reason to allow multiple, allocating threads may have
multiple GC requests before the GC starts.

Bug: 17942071

(cherry picked from commit 71891f9da2fbcb865931da70ae759032e6698106)

Change-Id: I5e2162373bcef1027eb71e5b1699186ff015f92d
Only allow one requestGC at a time

Fixes possible deadlock caused by Thread.getAllStackTraces

Thread.getAllStackTraces suspends all of the threads. If one of
the threads is a thread which holds the GC daemon lock then we
may deadlock when we allocate the stack trace. This happens if we
get a concurrent GC request when we are allocating the stack trace
elements. To fix the deadlock we now only allow a single thread to
requestGC at the same time.

Credits: yamauchi, hboehm

Bug: 18661622

Change-Id: Ia25598e5daa8ff2dc3aa976148d5ff6afa6960f0
Move GC daemon locking logic into heap

Fixes deadlock caused by acquirng the mutator lock while
synchronizing on the daemon thread.

Bug: 18739541
Change-Id: Ib3ac3788081d3d471195a6e3a8ed163237616a4f
Add pipe2 and O_CLOEXEC to the libcore POSIX API.

@hide right now, but we should expose these at some point.

Bug: 18719692
Change-Id: I0a73606cf089ed307d1ab2916a7df28b3c45aaf0
Fix native registration.

I thought I'd tested my previous change but hadn't.

Change-Id: Ie121b571cc2f767dd4bbe10291a56fe31496e6cc
Fix poll to never return EINTR.

Bug: 18759467
Change-Id: Ia5b97a55318b5990ad6b80d15641223aa4fb06f5

Conflicts:
	luni/src/main/native/libcore_io_Posix.cpp
Don't TEMP_FAILURE_RETRY calls that can't fail.

It turns out that while GCC doesn't care, clang is unhappy with us
because it notices that we're comparing an unsigned value (like a uid_t)
against -1:

  libcore/luni/src/main/native/libcore_io_Posix.cpp:727:12: error: comparison
  of integers of different signs: 'typeof (getegid())' (aka 'unsigned int')
  and 'int' [-Werror,-Wsign-compare]
    return TEMP_FAILURE_RETRY(getegid());
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Bug: 18759467
Change-Id: If71b11cbdd0cda2b8efcc1706eb49856c3770bb8
Update ByteBuffer positions in Posix.* functions.

Also add tests in libcore.io.OsTest and update (and simplify)
callers that were updating the position themselves.

bug: 18641009

(cherry picked from commit f3b61eaf1931ae8393e54202a717334a4971ebdf)

Change-Id: I8a810b2dfde7c13278807381bdfe7f532a3481a0