Throw an error when parsing an obviously bad Double

Thanks to Robbie Hott for the bug report.

Bug: https://code.google.com/p/android/issues/detail?id=71216
Change-Id: I402fa27e0b90c1c1d26169d79c7061e4a2caa138
Make ByteBuffer.allocateDirect be 8 byte aligned.

Bug: 16449607

Change-Id: I4a854d55f49fe709965c6b6a769fb58c356627dc
Fix serialization / deserialization of SealedObject

Thanks to apphelia@ for the report.

The readObject() implementation had hardcoded the
field order incorrectly leading to a couple of
fields being swapped on each serialization:
paramsAlg and sealAlg. This was wrong as far back
as 2009 so the class has likely never worked for
its intended purpose. Field order during
Serialization is primitives first, then fields.
Secondary ordering is alphabetical.

The purpose of overriding readObject() at all is for
safety in the event of compromised stream data.

It would be more appropriate to clone() rather than
readUnshared(). readUnshared() assumes a
corresponding writeUnshared(), which is not present.
The readUnshared() probably only works here because
the byte[] arrays typically are not shared anyway.

From reading latest guidelines on safe serialization
the code need not be order-specific: it can use
readFields(). s.defaultReadObject() could have been
used instead but the guidelines recommend against.
Performance is probably not a concern.

Until now nobody could have been using SealedObject
for its intended purpose otherwise they would have
noticed this bug (or they were always serializing /
deserializing an even number of times!).

Anybody attempting to use SealedObject on earlier
versions of Android will need to serialize /
deserialize twice to avoid the bug. After this fix
the class will work as intended.

Additional:

Some duplicated code has been extracted into methods,
and streams are now closed when they are finished
with. In reality this will have no effect
given the stream implementations involved.

Bug: https://code.google.com/p/android/issues/detail?id=73235
Change-Id: If745d6556437ae7839543e66dd15f912afd4ec98
Avoid running Runtime.gc() until we need to run finalization.

This prevents excessive explicit GC which are called from apps to get
good GC behavior on Dalvik. Calling System.gc() does not help on ART
since GC for alloc is much rarer.

If running finalizers is requested following a System.gc we remember
that a GC was requested and perform it ahead of finalization.

Bug: 12004934

Change-Id: Id1343ce8b5378c5f53c1e5649c06ddd045f56a3b
Don't account buffer.arrayOffset() twice.

data[OUTPUT_OFFSET] from the perspective of native
code must always be the offset from the start of the
buffer passed in to it.

Change-Id: I4a5c9595aebd105c57ce2239dc95cf85d5bd6256
Update our MIME type map.

Bug: https://code.google.com/p/android/issues/detail?id=61996
Change-Id: I55efc9d38c87d89bb20073e4632ab1e06c77be09
Fix MimeUtils to treat ".flac" as "audio/flac".

(cherry-pick of 77926e913a14b9541df38b6175f795f2ca6c5266.)

Bug: 15715370
Change-Id: I2d99f070c3debea01621a172d8189951a56736b5