diff options
| author | 2015-12-07 23:38:14 +0000 | |
|---|---|---|
| committer | 2015-12-07 23:38:14 +0000 | |
| commit | e769f25fa496827bf1ba9d74518bafd40082ceb6 (patch) | |
| tree | 8cc2600b0511ad5ca412917f3e7adbf9188f3ffe | |
| parent | 2a56ed70b1e40039a532e4060074d62062713fcd (diff) | |
| parent | ff8ef28e73c0959a4993fea975d0bdefbc27a20b (diff) | |
Merge "Add support for reading and writing double array values" am: 61c0b7cd4d
am: ff8ef28e73
* commit 'ff8ef28e73c0959a4993fea975d0bdefbc27a20b':
Add support for reading and writing double array values
| -rw-r--r-- | core/java/android/os/Parcel.java | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java index f2aea08a91ec..8d035b738a72 100644 --- a/core/java/android/os/Parcel.java +++ b/core/java/android/os/Parcel.java @@ -61,12 +61,12 @@ import dalvik.system.VMRuntime; * appropriate to place any Parcel data in to persistent storage: changes * in the underlying implementation of any of the data in the Parcel can * render older data unreadable.</p> - * + * * <p>The bulk of the Parcel API revolves around reading and writing data * of various types. There are six major classes of such functions available.</p> - * + * * <h3>Primitives</h3> - * + * * <p>The most basic data functions are for writing and reading primitive * data types: {@link #writeByte}, {@link #readByte}, {@link #writeDouble}, * {@link #readDouble}, {@link #writeFloat}, {@link #readFloat}, {@link #writeInt}, @@ -74,15 +74,15 @@ import dalvik.system.VMRuntime; * {@link #writeString}, {@link #readString}. Most other * data operations are built on top of these. The given data is written and * read using the endianess of the host CPU.</p> - * + * * <h3>Primitive Arrays</h3> - * + * * <p>There are a variety of methods for reading and writing raw arrays * of primitive objects, which generally result in writing a 4-byte length * followed by the primitive data items. The methods for reading can either * read the data into an existing array, or create and return a new array. * These available types are:</p> - * + * * <ul> * <li> {@link #writeBooleanArray(boolean[])}, * {@link #readBooleanArray(boolean[])}, {@link #createBooleanArray()} @@ -104,9 +104,9 @@ import dalvik.system.VMRuntime; * <li> {@link #writeSparseBooleanArray(SparseBooleanArray)}, * {@link #readSparseBooleanArray()}. * </ul> - * + * * <h3>Parcelables</h3> - * + * * <p>The {@link Parcelable} protocol provides an extremely efficient (but * low-level) protocol for objects to write and read themselves from Parcels. * You can use the direct methods {@link #writeParcelable(Parcelable, int)} @@ -116,7 +116,7 @@ import dalvik.system.VMRuntime; * methods write both the class type and its data to the Parcel, allowing * that class to be reconstructed from the appropriate class loader when * later reading.</p> - * + * * <p>There are also some methods that provide a more efficient way to work * with Parcelables: {@link #writeTypedObject}, {@link #writeTypedArray}, * {@link #writeTypedList}, {@link #readTypedObject}, @@ -129,9 +129,9 @@ import dalvik.system.VMRuntime; * call {@link Parcelable#writeToParcel Parcelable.writeToParcel} and * {@link Parcelable.Creator#createFromParcel Parcelable.Creator.createFromParcel} * yourself.)</p> - * + * * <h3>Bundles</h3> - * + * * <p>A special type-safe container, called {@link Bundle}, is available * for key/value maps of heterogeneous values. This has many optimizations * for improved performance when reading and writing data, and its type-safe @@ -139,16 +139,16 @@ import dalvik.system.VMRuntime; * data contents into a Parcel. The methods to use are * {@link #writeBundle(Bundle)}, {@link #readBundle()}, and * {@link #readBundle(ClassLoader)}. - * + * * <h3>Active Objects</h3> - * + * * <p>An unusual feature of Parcel is the ability to read and write active * objects. For these objects the actual contents of the object is not * written, rather a special token referencing the object is written. When * reading the object back from the Parcel, you do not get a new instance of * the object, but rather a handle that operates on the exact same object that * was originally written. There are two forms of active objects available.</p> - * + * * <p>{@link Binder} objects are a core facility of Android's general cross-process * communication system. The {@link IBinder} interface describes an abstract * protocol with a Binder object. Any such interface can be written in to @@ -161,7 +161,7 @@ import dalvik.system.VMRuntime; * {@link #createBinderArray()}, * {@link #writeBinderList(List)}, {@link #readBinderList(List)}, * {@link #createBinderArrayList()}.</p> - * + * * <p>FileDescriptor objects, representing raw Linux file descriptor identifiers, * can be written and {@link ParcelFileDescriptor} objects returned to operate * on the original file descriptor. The returned file descriptor is a dup @@ -169,9 +169,9 @@ import dalvik.system.VMRuntime; * operating on the same underlying file stream, with the same position, etc. * The methods to use are {@link #writeFileDescriptor(FileDescriptor)}, * {@link #readFileDescriptor()}. - * + * * <h3>Untyped Containers</h3> - * + * * <p>A final class of methods are for writing and reading standard Java * containers of arbitrary types. These all revolve around the * {@link #writeValue(Object)} and {@link #readValue(ClassLoader)} methods @@ -233,6 +233,7 @@ public final class Parcel { private static final int VAL_PERSISTABLEBUNDLE = 25; private static final int VAL_SIZE = 26; private static final int VAL_SIZEF = 27; + private static final int VAL_DOUBLEARRAY = 28; // The initial int32 in a Binder call's reply Parcel header: private static final int EX_SECURITY = -1; @@ -663,7 +664,7 @@ public final class Parcel { * growing dataCapacity() if needed. The Map keys must be String objects. * The Map values are written using {@link #writeValue} and must follow * the specification there. - * + * * <p>It is strongly recommended to use {@link #writeBundle} instead of * this method, since the Bundle class provides a type-safe API that * allows you to avoid mysterious type errors at the point of marshalling. @@ -1429,6 +1430,9 @@ public final class Parcel { } else if (v instanceof SizeF) { writeInt(VAL_SIZEF); writeSizeF((SizeF) v); + } else if (v instanceof double[]) { + writeInt(VAL_DOUBLEARRAY); + writeDoubleArray((double[]) v); } else { Class<?> clazz = v.getClass(); if (clazz.isArray() && clazz.getComponentType() == Object.class) { @@ -1504,7 +1508,7 @@ public final class Parcel { * exception will be re-thrown by this function as a RuntimeException * (to be caught by the system's last-resort exception handling when * dispatching a transaction). - * + * * <p>The supported exception types are: * <ul> * <li>{@link BadParcelableException} @@ -1514,7 +1518,7 @@ public final class Parcel { * <li>{@link SecurityException} * <li>{@link NetworkOnMainThreadException} * </ul> - * + * * @param e The Exception to be written. * * @see #writeNoException @@ -1835,7 +1839,7 @@ public final class Parcel { if (Bundle.DEBUG) Log.d(TAG, "null bundle: length=" + length); return null; } - + final Bundle bundle = new Bundle(this, length); if (loader != null) { bundle.setClassLoader(loader); @@ -2346,7 +2350,7 @@ public final class Parcel { return readArrayList(loader); case VAL_BOOLEANARRAY: - return createBooleanArray(); + return createBooleanArray(); case VAL_BYTEARRAY: return createByteArray(); @@ -2396,6 +2400,9 @@ public final class Parcel { case VAL_SIZEF: return readSizeF(); + case VAL_DOUBLEARRAY: + return createDoubleArray(); + default: int off = dataPosition() - 4; throw new RuntimeException( |