2 * Copyright (C) 2006 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 import android.annotation.IntegerRes;
20 import android.annotation.Nullable;
21 import android.text.TextUtils;
22 import android.util.ArrayMap;
23 import android.util.ArraySet;
24 import android.util.Log;
25 import android.util.Size;
26 import android.util.SizeF;
27 import android.util.SparseArray;
28 import android.util.SparseBooleanArray;
30 import java.io.ByteArrayInputStream;
31 import java.io.ByteArrayOutputStream;
32 import java.io.FileDescriptor;
33 import java.io.FileNotFoundException;
34 import java.io.IOException;
35 import java.io.ObjectInputStream;
36 import java.io.ObjectOutputStream;
37 import java.io.ObjectStreamClass;
38 import java.io.Serializable;
39 import java.lang.reflect.Array;
40 import java.lang.reflect.Field;
41 import java.lang.reflect.Modifier;
42 import java.util.ArrayList;
43 import java.util.Arrays;
44 import java.util.HashMap;
45 import java.util.List;
49 import dalvik.system.VMRuntime;
52 * Container for a message (data and object references) that can
53 * be sent through an IBinder. A Parcel can contain both flattened data
54 * that will be unflattened on the other side of the IPC (using the various
55 * methods here for writing specific types, or the general
56 * {@link Parcelable} interface), and references to live {@link IBinder}
57 * objects that will result in the other side receiving a proxy IBinder
58 * connected with the original IBinder in the Parcel.
60 * <p class="note">Parcel is <strong>not</strong> a general-purpose
61 * serialization mechanism. This class (and the corresponding
62 * {@link Parcelable} API for placing arbitrary objects into a Parcel) is
63 * designed as a high-performance IPC transport. As such, it is not
64 * appropriate to place any Parcel data in to persistent storage: changes
65 * in the underlying implementation of any of the data in the Parcel can
66 * render older data unreadable.</p>
68 * <p>The bulk of the Parcel API revolves around reading and writing data
69 * of various types. There are six major classes of such functions available.</p>
73 * <p>The most basic data functions are for writing and reading primitive
74 * data types: {@link #writeByte}, {@link #readByte}, {@link #writeDouble},
75 * {@link #readDouble}, {@link #writeFloat}, {@link #readFloat}, {@link #writeInt},
76 * {@link #readInt}, {@link #writeLong}, {@link #readLong},
77 * {@link #writeString}, {@link #readString}. Most other
78 * data operations are built on top of these. The given data is written and
79 * read using the endianess of the host CPU.</p>
81 * <h3>Primitive Arrays</h3>
83 * <p>There are a variety of methods for reading and writing raw arrays
84 * of primitive objects, which generally result in writing a 4-byte length
85 * followed by the primitive data items. The methods for reading can either
86 * read the data into an existing array, or create and return a new array.
87 * These available types are:</p>
90 * <li> {@link #writeBooleanArray(boolean[])},
91 * {@link #readBooleanArray(boolean[])}, {@link #createBooleanArray()}
92 * <li> {@link #writeByteArray(byte[])},
93 * {@link #writeByteArray(byte[], int, int)}, {@link #readByteArray(byte[])},
94 * {@link #createByteArray()}
95 * <li> {@link #writeCharArray(char[])}, {@link #readCharArray(char[])},
96 * {@link #createCharArray()}
97 * <li> {@link #writeDoubleArray(double[])}, {@link #readDoubleArray(double[])},
98 * {@link #createDoubleArray()}
99 * <li> {@link #writeFloatArray(float[])}, {@link #readFloatArray(float[])},
100 * {@link #createFloatArray()}
101 * <li> {@link #writeIntArray(int[])}, {@link #readIntArray(int[])},
102 * {@link #createIntArray()}
103 * <li> {@link #writeLongArray(long[])}, {@link #readLongArray(long[])},
104 * {@link #createLongArray()}
105 * <li> {@link #writeStringArray(String[])}, {@link #readStringArray(String[])},
106 * {@link #createStringArray()}.
107 * <li> {@link #writeSparseBooleanArray(SparseBooleanArray)},
108 * {@link #readSparseBooleanArray()}.
111 * <h3>Parcelables</h3>
113 * <p>The {@link Parcelable} protocol provides an extremely efficient (but
114 * low-level) protocol for objects to write and read themselves from Parcels.
115 * You can use the direct methods {@link #writeParcelable(Parcelable, int)}
116 * and {@link #readParcelable(ClassLoader)} or
117 * {@link #writeParcelableArray} and
118 * {@link #readParcelableArray(ClassLoader)} to write or read. These
119 * methods write both the class type and its data to the Parcel, allowing
120 * that class to be reconstructed from the appropriate class loader when
123 * <p>There are also some methods that provide a more efficient way to work
124 * with Parcelables: {@link #writeTypedObject}, {@link #writeTypedArray},
125 * {@link #writeTypedList}, {@link #readTypedObject},
126 * {@link #createTypedArray} and {@link #createTypedArrayList}. These methods
127 * do not write the class information of the original object: instead, the
128 * caller of the read function must know what type to expect and pass in the
129 * appropriate {@link Parcelable.Creator Parcelable.Creator} instead to
130 * properly construct the new object and read its data. (To more efficient
131 * write and read a single Parceable object that is not null, you can directly
132 * call {@link Parcelable#writeToParcel Parcelable.writeToParcel} and
133 * {@link Parcelable.Creator#createFromParcel Parcelable.Creator.createFromParcel}
138 * <p>A special type-safe container, called {@link Bundle}, is available
139 * for key/value maps of heterogeneous values. This has many optimizations
140 * for improved performance when reading and writing data, and its type-safe
141 * API avoids difficult to debug type errors when finally marshalling the
142 * data contents into a Parcel. The methods to use are
143 * {@link #writeBundle(Bundle)}, {@link #readBundle()}, and
144 * {@link #readBundle(ClassLoader)}.
146 * <h3>Active Objects</h3>
148 * <p>An unusual feature of Parcel is the ability to read and write active
149 * objects. For these objects the actual contents of the object is not
150 * written, rather a special token referencing the object is written. When
151 * reading the object back from the Parcel, you do not get a new instance of
152 * the object, but rather a handle that operates on the exact same object that
153 * was originally written. There are two forms of active objects available.</p>
155 * <p>{@link Binder} objects are a core facility of Android's general cross-process
156 * communication system. The {@link IBinder} interface describes an abstract
157 * protocol with a Binder object. Any such interface can be written in to
158 * a Parcel, and upon reading you will receive either the original object
159 * implementing that interface or a special proxy implementation
160 * that communicates calls back to the original object. The methods to use are
161 * {@link #writeStrongBinder(IBinder)},
162 * {@link #writeStrongInterface(IInterface)}, {@link #readStrongBinder()},
163 * {@link #writeBinderArray(IBinder[])}, {@link #readBinderArray(IBinder[])},
164 * {@link #createBinderArray()},
165 * {@link #writeBinderList(List)}, {@link #readBinderList(List)},
166 * {@link #createBinderArrayList()}.</p>
168 * <p>FileDescriptor objects, representing raw Linux file descriptor identifiers,
169 * can be written and {@link ParcelFileDescriptor} objects returned to operate
170 * on the original file descriptor. The returned file descriptor is a dup
171 * of the original file descriptor: the object and fd is different, but
172 * operating on the same underlying file stream, with the same position, etc.
173 * The methods to use are {@link #writeFileDescriptor(FileDescriptor)},
174 * {@link #readFileDescriptor()}.
176 * <h3>Untyped Containers</h3>
178 * <p>A final class of methods are for writing and reading standard Java
179 * containers of arbitrary types. These all revolve around the
180 * {@link #writeValue(Object)} and {@link #readValue(ClassLoader)} methods
181 * which define the types of objects allowed. The container methods are
182 * {@link #writeArray(Object[])}, {@link #readArray(ClassLoader)},
183 * {@link #writeList(List)}, {@link #readList(List, ClassLoader)},
184 * {@link #readArrayList(ClassLoader)},
185 * {@link #writeMap(Map)}, {@link #readMap(Map, ClassLoader)},
186 * {@link #writeSparseArray(SparseArray)},
187 * {@link #readSparseArray(ClassLoader)}.
189 public final class Parcel {
190 private static final boolean DEBUG_RECYCLE = false;
191 private static final boolean DEBUG_ARRAY_MAP = false;
192 private static final String TAG = "Parcel";
194 @SuppressWarnings({"UnusedDeclaration"})
195 private long mNativePtr; // used by native code
198 * Flag indicating if {@link #mNativePtr} was allocated by this object,
199 * indicating that we're responsible for its lifecycle.
201 private boolean mOwnsNativeParcelObject;
202 private long mNativeSize;
204 private RuntimeException mStack;
206 private static final int POOL_SIZE = 6;
207 private static final Parcel[] sOwnedPool = new Parcel[POOL_SIZE];
208 private static final Parcel[] sHolderPool = new Parcel[POOL_SIZE];
210 // Keep in sync with frameworks/native/libs/binder/PersistableBundle.cpp.
211 private static final int VAL_NULL = -1;
212 private static final int VAL_STRING = 0;
213 private static final int VAL_INTEGER = 1;
214 private static final int VAL_MAP = 2;
215 private static final int VAL_BUNDLE = 3;
216 private static final int VAL_PARCELABLE = 4;
217 private static final int VAL_SHORT = 5;
218 private static final int VAL_LONG = 6;
219 private static final int VAL_FLOAT = 7;
220 private static final int VAL_DOUBLE = 8;
221 private static final int VAL_BOOLEAN = 9;
222 private static final int VAL_CHARSEQUENCE = 10;
223 private static final int VAL_LIST = 11;
224 private static final int VAL_SPARSEARRAY = 12;
225 private static final int VAL_BYTEARRAY = 13;
226 private static final int VAL_STRINGARRAY = 14;
227 private static final int VAL_IBINDER = 15;
228 private static final int VAL_PARCELABLEARRAY = 16;
229 private static final int VAL_OBJECTARRAY = 17;
230 private static final int VAL_INTARRAY = 18;
231 private static final int VAL_LONGARRAY = 19;
232 private static final int VAL_BYTE = 20;
233 private static final int VAL_SERIALIZABLE = 21;
234 private static final int VAL_SPARSEBOOLEANARRAY = 22;
235 private static final int VAL_BOOLEANARRAY = 23;
236 private static final int VAL_CHARSEQUENCEARRAY = 24;
237 private static final int VAL_PERSISTABLEBUNDLE = 25;
238 private static final int VAL_SIZE = 26;
239 private static final int VAL_SIZEF = 27;
240 private static final int VAL_DOUBLEARRAY = 28;
242 // The initial int32 in a Binder call's reply Parcel header:
243 // Keep these in sync with libbinder's binder/Status.h.
244 private static final int EX_SECURITY = -1;
245 private static final int EX_BAD_PARCELABLE = -2;
246 private static final int EX_ILLEGAL_ARGUMENT = -3;
247 private static final int EX_NULL_POINTER = -4;
248 private static final int EX_ILLEGAL_STATE = -5;
249 private static final int EX_NETWORK_MAIN_THREAD = -6;
250 private static final int EX_UNSUPPORTED_OPERATION = -7;
251 private static final int EX_SERVICE_SPECIFIC = -8;
252 private static final int EX_HAS_REPLY_HEADER = -128; // special; see below
253 // EX_TRANSACTION_FAILED is used exclusively in native code.
254 // see libbinder's binder/Status.h
255 private static final int EX_TRANSACTION_FAILED = -129;
257 private static native int nativeDataSize(long nativePtr);
258 private static native int nativeDataAvail(long nativePtr);
259 private static native int nativeDataPosition(long nativePtr);
260 private static native int nativeDataCapacity(long nativePtr);
261 private static native long nativeSetDataSize(long nativePtr, int size);
262 private static native void nativeSetDataPosition(long nativePtr, int pos);
263 private static native void nativeSetDataCapacity(long nativePtr, int size);
265 private static native boolean nativePushAllowFds(long nativePtr, boolean allowFds);
266 private static native void nativeRestoreAllowFds(long nativePtr, boolean lastValue);
268 private static native void nativeWriteByteArray(long nativePtr, byte[] b, int offset, int len);
269 private static native void nativeWriteBlob(long nativePtr, byte[] b, int offset, int len);
270 private static native void nativeWriteInt(long nativePtr, int val);
271 private static native void nativeWriteLong(long nativePtr, long val);
272 private static native void nativeWriteFloat(long nativePtr, float val);
273 private static native void nativeWriteDouble(long nativePtr, double val);
274 private static native void nativeWriteString(long nativePtr, String val);
275 private static native void nativeWriteStrongBinder(long nativePtr, IBinder val);
276 private static native long nativeWriteFileDescriptor(long nativePtr, FileDescriptor val);
278 private static native byte[] nativeCreateByteArray(long nativePtr);
279 private static native byte[] nativeReadBlob(long nativePtr);
280 private static native int nativeReadInt(long nativePtr);
281 private static native long nativeReadLong(long nativePtr);
282 private static native float nativeReadFloat(long nativePtr);
283 private static native double nativeReadDouble(long nativePtr);
284 private static native String nativeReadString(long nativePtr);
285 private static native IBinder nativeReadStrongBinder(long nativePtr);
286 private static native FileDescriptor nativeReadFileDescriptor(long nativePtr);
288 private static native long nativeCreate();
289 private static native long nativeFreeBuffer(long nativePtr);
290 private static native void nativeDestroy(long nativePtr);
292 private static native byte[] nativeMarshall(long nativePtr);
293 private static native long nativeUnmarshall(
294 long nativePtr, byte[] data, int offset, int length);
295 private static native long nativeAppendFrom(
296 long thisNativePtr, long otherNativePtr, int offset, int length);
297 private static native boolean nativeHasFileDescriptors(long nativePtr);
298 private static native void nativeWriteInterfaceToken(long nativePtr, String interfaceName);
299 private static native void nativeEnforceInterface(long nativePtr, String interfaceName);
301 private static native long nativeGetBlobAshmemSize(long nativePtr);
303 public final static Parcelable.Creator<String> STRING_CREATOR
304 = new Parcelable.Creator<String>() {
305 public String createFromParcel(Parcel source) {
306 return source.readString();
308 public String[] newArray(int size) {
309 return new String[size];
314 * Retrieve a new Parcel object from the pool.
316 public static Parcel obtain() {
317 final Parcel[] pool = sOwnedPool;
318 synchronized (pool) {
320 for (int i=0; i<POOL_SIZE; i++) {
325 p.mStack = new RuntimeException();
331 return new Parcel(0);
335 * Put a Parcel object back into the pool. You must not touch
336 * the object after this call.
338 public final void recycle() {
339 if (DEBUG_RECYCLE) mStack = null;
343 if (mOwnsNativeParcelObject) {
350 synchronized (pool) {
351 for (int i=0; i<POOL_SIZE; i++) {
352 if (pool[i] == null) {
361 public static native long getGlobalAllocSize();
364 public static native long getGlobalAllocCount();
367 * Returns the total amount of data contained in the parcel.
369 public final int dataSize() {
370 return nativeDataSize(mNativePtr);
374 * Returns the amount of data remaining to be read from the
375 * parcel. That is, {@link #dataSize}-{@link #dataPosition}.
377 public final int dataAvail() {
378 return nativeDataAvail(mNativePtr);
382 * Returns the current position in the parcel data. Never
383 * more than {@link #dataSize}.
385 public final int dataPosition() {
386 return nativeDataPosition(mNativePtr);
390 * Returns the total amount of space in the parcel. This is always
391 * >= {@link #dataSize}. The difference between it and dataSize() is the
392 * amount of room left until the parcel needs to re-allocate its
395 public final int dataCapacity() {
396 return nativeDataCapacity(mNativePtr);
400 * Change the amount of data in the parcel. Can be either smaller or
401 * larger than the current size. If larger than the current capacity,
402 * more memory will be allocated.
404 * @param size The new number of bytes in the Parcel.
406 public final void setDataSize(int size) {
407 updateNativeSize(nativeSetDataSize(mNativePtr, size));
411 * Move the current read/write position in the parcel.
412 * @param pos New offset in the parcel; must be between 0 and
415 public final void setDataPosition(int pos) {
416 nativeSetDataPosition(mNativePtr, pos);
420 * Change the capacity (current available space) of the parcel.
422 * @param size The new capacity of the parcel, in bytes. Can not be
423 * less than {@link #dataSize} -- that is, you can not drop existing data
426 public final void setDataCapacity(int size) {
427 nativeSetDataCapacity(mNativePtr, size);
431 public final boolean pushAllowFds(boolean allowFds) {
432 return nativePushAllowFds(mNativePtr, allowFds);
436 public final void restoreAllowFds(boolean lastValue) {
437 nativeRestoreAllowFds(mNativePtr, lastValue);
441 * Returns the raw bytes of the parcel.
443 * <p class="note">The data you retrieve here <strong>must not</strong>
444 * be placed in any kind of persistent storage (on local disk, across
445 * a network, etc). For that, you should use standard serialization
446 * or another kind of general serialization mechanism. The Parcel
447 * marshalled representation is highly optimized for local IPC, and as
448 * such does not attempt to maintain compatibility with data created
449 * in different versions of the platform.
451 public final byte[] marshall() {
452 return nativeMarshall(mNativePtr);
456 * Set the bytes in data to be the raw bytes of this Parcel.
458 public final void unmarshall(byte[] data, int offset, int length) {
459 updateNativeSize(nativeUnmarshall(mNativePtr, data, offset, length));
462 public final void appendFrom(Parcel parcel, int offset, int length) {
463 updateNativeSize(nativeAppendFrom(mNativePtr, parcel.mNativePtr, offset, length));
467 * Report whether the parcel contains any marshalled file descriptors.
469 public final boolean hasFileDescriptors() {
470 return nativeHasFileDescriptors(mNativePtr);
474 * Store or read an IBinder interface token in the parcel at the current
475 * {@link #dataPosition}. This is used to validate that the marshalled
476 * transaction is intended for the target interface.
478 public final void writeInterfaceToken(String interfaceName) {
479 nativeWriteInterfaceToken(mNativePtr, interfaceName);
482 public final void enforceInterface(String interfaceName) {
483 nativeEnforceInterface(mNativePtr, interfaceName);
487 * Write a byte array into the parcel at the current {@link #dataPosition},
488 * growing {@link #dataCapacity} if needed.
489 * @param b Bytes to place into the parcel.
491 public final void writeByteArray(byte[] b) {
492 writeByteArray(b, 0, (b != null) ? b.length : 0);
496 * Write a byte array into the parcel at the current {@link #dataPosition},
497 * growing {@link #dataCapacity} if needed.
498 * @param b Bytes to place into the parcel.
499 * @param offset Index of first byte to be written.
500 * @param len Number of bytes to write.
502 public final void writeByteArray(byte[] b, int offset, int len) {
507 Arrays.checkOffsetAndCount(b.length, offset, len);
508 nativeWriteByteArray(mNativePtr, b, offset, len);
512 * Write a blob of data into the parcel at the current {@link #dataPosition},
513 * growing {@link #dataCapacity} if needed.
514 * @param b Bytes to place into the parcel.
518 public final void writeBlob(byte[] b) {
519 writeBlob(b, 0, (b != null) ? b.length : 0);
523 * Write a blob of data into the parcel at the current {@link #dataPosition},
524 * growing {@link #dataCapacity} if needed.
525 * @param b Bytes to place into the parcel.
526 * @param offset Index of first byte to be written.
527 * @param len Number of bytes to write.
531 public final void writeBlob(byte[] b, int offset, int len) {
536 Arrays.checkOffsetAndCount(b.length, offset, len);
537 nativeWriteBlob(mNativePtr, b, offset, len);
541 * Write an integer value into the parcel at the current dataPosition(),
542 * growing dataCapacity() if needed.
544 public final void writeInt(int val) {
545 nativeWriteInt(mNativePtr, val);
549 * Write a long integer value into the parcel at the current dataPosition(),
550 * growing dataCapacity() if needed.
552 public final void writeLong(long val) {
553 nativeWriteLong(mNativePtr, val);
557 * Write a floating point value into the parcel at the current
558 * dataPosition(), growing dataCapacity() if needed.
560 public final void writeFloat(float val) {
561 nativeWriteFloat(mNativePtr, val);
565 * Write a double precision floating point value into the parcel at the
566 * current dataPosition(), growing dataCapacity() if needed.
568 public final void writeDouble(double val) {
569 nativeWriteDouble(mNativePtr, val);
573 * Write a string value into the parcel at the current dataPosition(),
574 * growing dataCapacity() if needed.
576 public final void writeString(String val) {
577 nativeWriteString(mNativePtr, val);
581 * Write a CharSequence value into the parcel at the current dataPosition(),
582 * growing dataCapacity() if needed.
585 public final void writeCharSequence(CharSequence val) {
586 TextUtils.writeToParcel(val, this, 0);
590 * Write an object into the parcel at the current dataPosition(),
591 * growing dataCapacity() if needed.
593 public final void writeStrongBinder(IBinder val) {
594 nativeWriteStrongBinder(mNativePtr, val);
598 * Write an object into the parcel at the current dataPosition(),
599 * growing dataCapacity() if needed.
601 public final void writeStrongInterface(IInterface val) {
602 writeStrongBinder(val == null ? null : val.asBinder());
606 * Write a FileDescriptor into the parcel at the current dataPosition(),
607 * growing dataCapacity() if needed.
609 * <p class="caution">The file descriptor will not be closed, which may
610 * result in file descriptor leaks when objects are returned from Binder
611 * calls. Use {@link ParcelFileDescriptor#writeToParcel} instead, which
612 * accepts contextual flags and will close the original file descriptor
613 * if {@link Parcelable#PARCELABLE_WRITE_RETURN_VALUE} is set.</p>
615 public final void writeFileDescriptor(FileDescriptor val) {
616 updateNativeSize(nativeWriteFileDescriptor(mNativePtr, val));
619 private void updateNativeSize(long newNativeSize) {
620 if (mOwnsNativeParcelObject) {
621 if (newNativeSize > Integer.MAX_VALUE) {
622 newNativeSize = Integer.MAX_VALUE;
624 if (newNativeSize != mNativeSize) {
625 int delta = (int) (newNativeSize - mNativeSize);
627 VMRuntime.getRuntime().registerNativeAllocation(delta);
629 VMRuntime.getRuntime().registerNativeFree(-delta);
631 mNativeSize = newNativeSize;
638 * This will be the new name for writeFileDescriptor, for consistency.
640 public final void writeRawFileDescriptor(FileDescriptor val) {
641 nativeWriteFileDescriptor(mNativePtr, val);
646 * Write an array of FileDescriptor objects into the Parcel.
648 * @param value The array of objects to be written.
650 public final void writeRawFileDescriptorArray(FileDescriptor[] value) {
652 int N = value.length;
654 for (int i=0; i<N; i++) {
655 writeRawFileDescriptor(value[i]);
663 * Write a byte value into the parcel at the current dataPosition(),
664 * growing dataCapacity() if needed.
666 public final void writeByte(byte val) {
671 * Please use {@link #writeBundle} instead. Flattens a Map into the parcel
672 * at the current dataPosition(),
673 * growing dataCapacity() if needed. The Map keys must be String objects.
674 * The Map values are written using {@link #writeValue} and must follow
675 * the specification there.
677 * <p>It is strongly recommended to use {@link #writeBundle} instead of
678 * this method, since the Bundle class provides a type-safe API that
679 * allows you to avoid mysterious type errors at the point of marshalling.
681 public final void writeMap(Map val) {
682 writeMapInternal((Map<String, Object>) val);
686 * Flatten a Map into the parcel at the current dataPosition(),
687 * growing dataCapacity() if needed. The Map keys must be String objects.
689 /* package */ void writeMapInternal(Map<String,Object> val) {
694 Set<Map.Entry<String,Object>> entries = val.entrySet();
695 writeInt(entries.size());
696 for (Map.Entry<String,Object> e : entries) {
697 writeValue(e.getKey());
698 writeValue(e.getValue());
703 * Flatten an ArrayMap into the parcel at the current dataPosition(),
704 * growing dataCapacity() if needed. The Map keys must be String objects.
706 /* package */ void writeArrayMapInternal(ArrayMap<String, Object> val) {
711 // Keep the format of this Parcel in sync with writeToParcelInner() in
712 // frameworks/native/libs/binder/PersistableBundle.cpp.
713 final int N = val.size();
715 if (DEBUG_ARRAY_MAP) {
716 RuntimeException here = new RuntimeException("here");
717 here.fillInStackTrace();
718 Log.d(TAG, "Writing " + N + " ArrayMap entries", here);
721 for (int i=0; i<N; i++) {
722 if (DEBUG_ARRAY_MAP) startPos = dataPosition();
723 writeString(val.keyAt(i));
724 writeValue(val.valueAt(i));
725 if (DEBUG_ARRAY_MAP) Log.d(TAG, " Write #" + i + " "
726 + (dataPosition()-startPos) + " bytes: key=0x"
727 + Integer.toHexString(val.keyAt(i) != null ? val.keyAt(i).hashCode() : 0)
728 + " " + val.keyAt(i));
733 * @hide For testing only.
735 public void writeArrayMap(ArrayMap<String, Object> val) {
736 writeArrayMapInternal(val);
740 * Write an array set to the parcel.
742 * @param val The array set to write.
746 public void writeArraySet(@Nullable ArraySet<? extends Object> val) {
747 final int size = (val != null) ? val.size() : -1;
749 for (int i = 0; i < size; i++) {
750 writeValue(val.valueAt(i));
755 * Flatten a Bundle into the parcel at the current dataPosition(),
756 * growing dataCapacity() if needed.
758 public final void writeBundle(Bundle val) {
764 val.writeToParcel(this, 0);
768 * Flatten a PersistableBundle into the parcel at the current dataPosition(),
769 * growing dataCapacity() if needed.
771 public final void writePersistableBundle(PersistableBundle val) {
777 val.writeToParcel(this, 0);
781 * Flatten a Size into the parcel at the current dataPosition(),
782 * growing dataCapacity() if needed.
784 public final void writeSize(Size val) {
785 writeInt(val.getWidth());
786 writeInt(val.getHeight());
790 * Flatten a SizeF into the parcel at the current dataPosition(),
791 * growing dataCapacity() if needed.
793 public final void writeSizeF(SizeF val) {
794 writeFloat(val.getWidth());
795 writeFloat(val.getHeight());
799 * Flatten a List into the parcel at the current dataPosition(), growing
800 * dataCapacity() if needed. The List values are written using
801 * {@link #writeValue} and must follow the specification there.
803 public final void writeList(List val) {
812 writeValue(val.get(i));
818 * Flatten an Object array into the parcel at the current dataPosition(),
819 * growing dataCapacity() if needed. The array values are written using
820 * {@link #writeValue} and must follow the specification there.
822 public final void writeArray(Object[] val) {
837 * Flatten a generic SparseArray into the parcel at the current
838 * dataPosition(), growing dataCapacity() if needed. The SparseArray
839 * values are written using {@link #writeValue} and must follow the
840 * specification there.
842 public final void writeSparseArray(SparseArray<Object> val) {
851 writeInt(val.keyAt(i));
852 writeValue(val.valueAt(i));
857 public final void writeSparseBooleanArray(SparseBooleanArray val) {
866 writeInt(val.keyAt(i));
867 writeByte((byte)(val.valueAt(i) ? 1 : 0));
872 public final void writeBooleanArray(boolean[] val) {
876 for (int i=0; i<N; i++) {
877 writeInt(val[i] ? 1 : 0);
884 public final boolean[] createBooleanArray() {
886 // >>2 as a fast divide-by-4 works in the create*Array() functions
887 // because dataAvail() will never return a negative number. 4 is
888 // the size of a stored boolean in the stream.
889 if (N >= 0 && N <= (dataAvail() >> 2)) {
890 boolean[] val = new boolean[N];
891 for (int i=0; i<N; i++) {
892 val[i] = readInt() != 0;
900 public final void readBooleanArray(boolean[] val) {
902 if (N == val.length) {
903 for (int i=0; i<N; i++) {
904 val[i] = readInt() != 0;
907 throw new RuntimeException("bad array lengths");
911 public final void writeCharArray(char[] val) {
915 for (int i=0; i<N; i++) {
916 writeInt((int)val[i]);
923 public final char[] createCharArray() {
925 if (N >= 0 && N <= (dataAvail() >> 2)) {
926 char[] val = new char[N];
927 for (int i=0; i<N; i++) {
928 val[i] = (char)readInt();
936 public final void readCharArray(char[] val) {
938 if (N == val.length) {
939 for (int i=0; i<N; i++) {
940 val[i] = (char)readInt();
943 throw new RuntimeException("bad array lengths");
947 public final void writeIntArray(int[] val) {
951 for (int i=0; i<N; i++) {
959 public final int[] createIntArray() {
961 if (N >= 0 && N <= (dataAvail() >> 2)) {
962 int[] val = new int[N];
963 for (int i=0; i<N; i++) {
972 public final void readIntArray(int[] val) {
974 if (N == val.length) {
975 for (int i=0; i<N; i++) {
979 throw new RuntimeException("bad array lengths");
983 public final void writeLongArray(long[] val) {
987 for (int i=0; i<N; i++) {
995 public final long[] createLongArray() {
997 // >>3 because stored longs are 64 bits
998 if (N >= 0 && N <= (dataAvail() >> 3)) {
999 long[] val = new long[N];
1000 for (int i=0; i<N; i++) {
1001 val[i] = readLong();
1009 public final void readLongArray(long[] val) {
1011 if (N == val.length) {
1012 for (int i=0; i<N; i++) {
1013 val[i] = readLong();
1016 throw new RuntimeException("bad array lengths");
1020 public final void writeFloatArray(float[] val) {
1024 for (int i=0; i<N; i++) {
1032 public final float[] createFloatArray() {
1034 // >>2 because stored floats are 4 bytes
1035 if (N >= 0 && N <= (dataAvail() >> 2)) {
1036 float[] val = new float[N];
1037 for (int i=0; i<N; i++) {
1038 val[i] = readFloat();
1046 public final void readFloatArray(float[] val) {
1048 if (N == val.length) {
1049 for (int i=0; i<N; i++) {
1050 val[i] = readFloat();
1053 throw new RuntimeException("bad array lengths");
1057 public final void writeDoubleArray(double[] val) {
1061 for (int i=0; i<N; i++) {
1062 writeDouble(val[i]);
1069 public final double[] createDoubleArray() {
1071 // >>3 because stored doubles are 8 bytes
1072 if (N >= 0 && N <= (dataAvail() >> 3)) {
1073 double[] val = new double[N];
1074 for (int i=0; i<N; i++) {
1075 val[i] = readDouble();
1083 public final void readDoubleArray(double[] val) {
1085 if (N == val.length) {
1086 for (int i=0; i<N; i++) {
1087 val[i] = readDouble();
1090 throw new RuntimeException("bad array lengths");
1094 public final void writeStringArray(String[] val) {
1098 for (int i=0; i<N; i++) {
1099 writeString(val[i]);
1106 public final String[] createStringArray() {
1109 String[] val = new String[N];
1110 for (int i=0; i<N; i++) {
1111 val[i] = readString();
1119 public final void readStringArray(String[] val) {
1121 if (N == val.length) {
1122 for (int i=0; i<N; i++) {
1123 val[i] = readString();
1126 throw new RuntimeException("bad array lengths");
1130 public final void writeBinderArray(IBinder[] val) {
1134 for (int i=0; i<N; i++) {
1135 writeStrongBinder(val[i]);
1145 public final void writeCharSequenceArray(CharSequence[] val) {
1149 for (int i=0; i<N; i++) {
1150 writeCharSequence(val[i]);
1160 public final void writeCharSequenceList(ArrayList<CharSequence> val) {
1164 for (int i=0; i<N; i++) {
1165 writeCharSequence(val.get(i));
1172 public final IBinder[] createBinderArray() {
1175 IBinder[] val = new IBinder[N];
1176 for (int i=0; i<N; i++) {
1177 val[i] = readStrongBinder();
1185 public final void readBinderArray(IBinder[] val) {
1187 if (N == val.length) {
1188 for (int i=0; i<N; i++) {
1189 val[i] = readStrongBinder();
1192 throw new RuntimeException("bad array lengths");
1197 * Flatten a List containing a particular object type into the parcel, at
1198 * the current dataPosition() and growing dataCapacity() if needed. The
1199 * type of the objects in the list must be one that implements Parcelable.
1200 * Unlike the generic writeList() method, however, only the raw data of the
1201 * objects is written and not their type, so you must use the corresponding
1202 * readTypedList() to unmarshall them.
1204 * @param val The list of objects to be written.
1206 * @see #createTypedArrayList
1207 * @see #readTypedList
1210 public final <T extends Parcelable> void writeTypedList(List<T> val) {
1219 T item = val.get(i);
1222 item.writeToParcel(this, 0);
1231 * Flatten a List containing String objects into the parcel, at
1232 * the current dataPosition() and growing dataCapacity() if needed. They
1233 * can later be retrieved with {@link #createStringArrayList} or
1234 * {@link #readStringList}.
1236 * @param val The list of strings to be written.
1238 * @see #createStringArrayList
1239 * @see #readStringList
1241 public final void writeStringList(List<String> val) {
1250 writeString(val.get(i));
1256 * Flatten a List containing IBinder objects into the parcel, at
1257 * the current dataPosition() and growing dataCapacity() if needed. They
1258 * can later be retrieved with {@link #createBinderArrayList} or
1259 * {@link #readBinderList}.
1261 * @param val The list of strings to be written.
1263 * @see #createBinderArrayList
1264 * @see #readBinderList
1266 public final void writeBinderList(List<IBinder> val) {
1275 writeStrongBinder(val.get(i));
1281 * Flatten a heterogeneous array containing a particular object type into
1283 * the current dataPosition() and growing dataCapacity() if needed. The
1284 * type of the objects in the array must be one that implements Parcelable.
1285 * Unlike the {@link #writeParcelableArray} method, however, only the
1286 * raw data of the objects is written and not their type, so you must use
1287 * {@link #readTypedArray} with the correct corresponding
1288 * {@link Parcelable.Creator} implementation to unmarshall them.
1290 * @param val The array of objects to be written.
1291 * @param parcelableFlags Contextual flags as per
1292 * {@link Parcelable#writeToParcel(Parcel, int) Parcelable.writeToParcel()}.
1294 * @see #readTypedArray
1295 * @see #writeParcelableArray
1296 * @see Parcelable.Creator
1298 public final <T extends Parcelable> void writeTypedArray(T[] val,
1299 int parcelableFlags) {
1303 for (int i=0; i<N; i++) {
1307 item.writeToParcel(this, parcelableFlags);
1318 * Flatten the Parcelable object into the parcel.
1320 * @param val The Parcelable object to be written.
1321 * @param parcelableFlags Contextual flags as per
1322 * {@link Parcelable#writeToParcel(Parcel, int) Parcelable.writeToParcel()}.
1324 * @see #readTypedObject
1326 public final <T extends Parcelable> void writeTypedObject(T val, int parcelableFlags) {
1329 val.writeToParcel(this, parcelableFlags);
1336 * Flatten a generic object in to a parcel. The given Object value may
1337 * currently be one of the following types:
1354 * <li> Object[] (supporting objects of the same type defined here).
1355 * <li> {@link Bundle}
1356 * <li> Map (as supported by {@link #writeMap}).
1357 * <li> Any object that implements the {@link Parcelable} protocol.
1359 * <li> CharSequence (as supported by {@link TextUtils#writeToParcel}).
1360 * <li> List (as supported by {@link #writeList}).
1361 * <li> {@link SparseArray} (as supported by {@link #writeSparseArray(SparseArray)}).
1362 * <li> {@link IBinder}
1363 * <li> Any object that implements Serializable (but see
1364 * {@link #writeSerializable} for caveats). Note that all of the
1365 * previous types have relatively efficient implementations for
1366 * writing to a Parcel; having to rely on the generic serialization
1367 * approach is much less efficient and should be avoided whenever
1371 * <p class="caution">{@link Parcelable} objects are written with
1372 * {@link Parcelable#writeToParcel} using contextual flags of 0. When
1373 * serializing objects containing {@link ParcelFileDescriptor}s,
1374 * this may result in file descriptor leaks when they are returned from
1375 * Binder calls (where {@link Parcelable#PARCELABLE_WRITE_RETURN_VALUE}
1376 * should be used).</p>
1378 public final void writeValue(Object v) {
1381 } else if (v instanceof String) {
1382 writeInt(VAL_STRING);
1383 writeString((String) v);
1384 } else if (v instanceof Integer) {
1385 writeInt(VAL_INTEGER);
1386 writeInt((Integer) v);
1387 } else if (v instanceof Map) {
1390 } else if (v instanceof Bundle) {
1391 // Must be before Parcelable
1392 writeInt(VAL_BUNDLE);
1393 writeBundle((Bundle) v);
1394 } else if (v instanceof PersistableBundle) {
1395 writeInt(VAL_PERSISTABLEBUNDLE);
1396 writePersistableBundle((PersistableBundle) v);
1397 } else if (v instanceof Parcelable) {
1398 // IMPOTANT: cases for classes that implement Parcelable must
1399 // come before the Parcelable case, so that their specific VAL_*
1400 // types will be written.
1401 writeInt(VAL_PARCELABLE);
1402 writeParcelable((Parcelable) v, 0);
1403 } else if (v instanceof Short) {
1404 writeInt(VAL_SHORT);
1405 writeInt(((Short) v).intValue());
1406 } else if (v instanceof Long) {
1408 writeLong((Long) v);
1409 } else if (v instanceof Float) {
1410 writeInt(VAL_FLOAT);
1411 writeFloat((Float) v);
1412 } else if (v instanceof Double) {
1413 writeInt(VAL_DOUBLE);
1414 writeDouble((Double) v);
1415 } else if (v instanceof Boolean) {
1416 writeInt(VAL_BOOLEAN);
1417 writeInt((Boolean) v ? 1 : 0);
1418 } else if (v instanceof CharSequence) {
1419 // Must be after String
1420 writeInt(VAL_CHARSEQUENCE);
1421 writeCharSequence((CharSequence) v);
1422 } else if (v instanceof List) {
1424 writeList((List) v);
1425 } else if (v instanceof SparseArray) {
1426 writeInt(VAL_SPARSEARRAY);
1427 writeSparseArray((SparseArray) v);
1428 } else if (v instanceof boolean[]) {
1429 writeInt(VAL_BOOLEANARRAY);
1430 writeBooleanArray((boolean[]) v);
1431 } else if (v instanceof byte[]) {
1432 writeInt(VAL_BYTEARRAY);
1433 writeByteArray((byte[]) v);
1434 } else if (v instanceof String[]) {
1435 writeInt(VAL_STRINGARRAY);
1436 writeStringArray((String[]) v);
1437 } else if (v instanceof CharSequence[]) {
1438 // Must be after String[] and before Object[]
1439 writeInt(VAL_CHARSEQUENCEARRAY);
1440 writeCharSequenceArray((CharSequence[]) v);
1441 } else if (v instanceof IBinder) {
1442 writeInt(VAL_IBINDER);
1443 writeStrongBinder((IBinder) v);
1444 } else if (v instanceof Parcelable[]) {
1445 writeInt(VAL_PARCELABLEARRAY);
1446 writeParcelableArray((Parcelable[]) v, 0);
1447 } else if (v instanceof int[]) {
1448 writeInt(VAL_INTARRAY);
1449 writeIntArray((int[]) v);
1450 } else if (v instanceof long[]) {
1451 writeInt(VAL_LONGARRAY);
1452 writeLongArray((long[]) v);
1453 } else if (v instanceof Byte) {
1456 } else if (v instanceof Size) {
1458 writeSize((Size) v);
1459 } else if (v instanceof SizeF) {
1460 writeInt(VAL_SIZEF);
1461 writeSizeF((SizeF) v);
1462 } else if (v instanceof double[]) {
1463 writeInt(VAL_DOUBLEARRAY);
1464 writeDoubleArray((double[]) v);
1466 Class<?> clazz = v.getClass();
1467 if (clazz.isArray() && clazz.getComponentType() == Object.class) {
1468 // Only pure Object[] are written here, Other arrays of non-primitive types are
1469 // handled by serialization as this does not record the component type.
1470 writeInt(VAL_OBJECTARRAY);
1471 writeArray((Object[]) v);
1472 } else if (v instanceof Serializable) {
1474 writeInt(VAL_SERIALIZABLE);
1475 writeSerializable((Serializable) v);
1477 throw new RuntimeException("Parcel: unable to marshal value " + v);
1483 * Flatten the name of the class of the Parcelable and its contents
1486 * @param p The Parcelable object to be written.
1487 * @param parcelableFlags Contextual flags as per
1488 * {@link Parcelable#writeToParcel(Parcel, int) Parcelable.writeToParcel()}.
1490 public final void writeParcelable(Parcelable p, int parcelableFlags) {
1495 writeParcelableCreator(p);
1496 p.writeToParcel(this, parcelableFlags);
1500 public final void writeParcelableCreator(Parcelable p) {
1501 String name = p.getClass().getName();
1506 * Write a generic serializable object in to a Parcel. It is strongly
1507 * recommended that this method be avoided, since the serialization
1508 * overhead is extremely large, and this approach will be much slower than
1509 * using the other approaches to writing data in to a Parcel.
1511 public final void writeSerializable(Serializable s) {
1516 String name = s.getClass().getName();
1519 ByteArrayOutputStream baos = new ByteArrayOutputStream();
1521 ObjectOutputStream oos = new ObjectOutputStream(baos);
1525 writeByteArray(baos.toByteArray());
1526 } catch (IOException ioe) {
1527 throw new RuntimeException("Parcelable encountered " +
1528 "IOException writing serializable object (name = " + name +
1534 * Special function for writing an exception result at the header of
1535 * a parcel, to be used when returning an exception from a transaction.
1536 * Note that this currently only supports a few exception types; any other
1537 * exception will be re-thrown by this function as a RuntimeException
1538 * (to be caught by the system's last-resort exception handling when
1539 * dispatching a transaction).
1541 * <p>The supported exception types are:
1543 * <li>{@link BadParcelableException}
1544 * <li>{@link IllegalArgumentException}
1545 * <li>{@link IllegalStateException}
1546 * <li>{@link NullPointerException}
1547 * <li>{@link SecurityException}
1548 * <li>{@link NetworkOnMainThreadException}
1551 * @param e The Exception to be written.
1553 * @see #writeNoException
1554 * @see #readException
1556 public final void writeException(Exception e) {
1558 if (e instanceof SecurityException) {
1560 } else if (e instanceof BadParcelableException) {
1561 code = EX_BAD_PARCELABLE;
1562 } else if (e instanceof IllegalArgumentException) {
1563 code = EX_ILLEGAL_ARGUMENT;
1564 } else if (e instanceof NullPointerException) {
1565 code = EX_NULL_POINTER;
1566 } else if (e instanceof IllegalStateException) {
1567 code = EX_ILLEGAL_STATE;
1568 } else if (e instanceof NetworkOnMainThreadException) {
1569 code = EX_NETWORK_MAIN_THREAD;
1570 } else if (e instanceof UnsupportedOperationException) {
1571 code = EX_UNSUPPORTED_OPERATION;
1572 } else if (e instanceof ServiceSpecificException) {
1573 code = EX_SERVICE_SPECIFIC;
1576 StrictMode.clearGatheredViolations();
1578 if (e instanceof RuntimeException) {
1579 throw (RuntimeException) e;
1581 throw new RuntimeException(e);
1583 writeString(e.getMessage());
1584 if (e instanceof ServiceSpecificException) {
1585 writeInt(((ServiceSpecificException)e).errorCode);
1590 * Special function for writing information at the front of the Parcel
1591 * indicating that no exception occurred.
1593 * @see #writeException
1594 * @see #readException
1596 public final void writeNoException() {
1597 // Despite the name of this function ("write no exception"),
1598 // it should instead be thought of as "write the RPC response
1599 // header", but because this function name is written out by
1600 // the AIDL compiler, we're not going to rename it.
1602 // The response header, in the non-exception case (see also
1603 // writeException above, also called by the AIDL compiler), is
1604 // either a 0 (the default case), or EX_HAS_REPLY_HEADER if
1605 // StrictMode has gathered up violations that have occurred
1606 // during a Binder call, in which case we write out the number
1607 // of violations and their details, serialized, before the
1608 // actual RPC respons data. The receiving end of this is
1609 // readException(), below.
1610 if (StrictMode.hasGatheredViolations()) {
1611 writeInt(EX_HAS_REPLY_HEADER);
1612 final int sizePosition = dataPosition();
1613 writeInt(0); // total size of fat header, to be filled in later
1614 StrictMode.writeGatheredViolationsToParcel(this);
1615 final int payloadPosition = dataPosition();
1616 setDataPosition(sizePosition);
1617 writeInt(payloadPosition - sizePosition); // header size
1618 setDataPosition(payloadPosition);
1625 * Special function for reading an exception result from the header of
1626 * a parcel, to be used after receiving the result of a transaction. This
1627 * will throw the exception for you if it had been written to the Parcel,
1628 * otherwise return and let you read the normal result data from the Parcel.
1630 * @see #writeException
1631 * @see #writeNoException
1633 public final void readException() {
1634 int code = readExceptionCode();
1636 String msg = readString();
1637 readException(code, msg);
1642 * Parses the header of a Binder call's response Parcel and
1643 * returns the exception code. Deals with lite or fat headers.
1644 * In the common successful case, this header is generally zero.
1645 * In less common cases, it's a small negative number and will be
1646 * followed by an error string.
1648 * This exists purely for android.database.DatabaseUtils and
1649 * insulating it from having to handle fat headers as returned by
1650 * e.g. StrictMode-induced RPC responses.
1654 public final int readExceptionCode() {
1655 int code = readInt();
1656 if (code == EX_HAS_REPLY_HEADER) {
1657 int headerSize = readInt();
1658 if (headerSize == 0) {
1659 Log.e(TAG, "Unexpected zero-sized Parcel reply header.");
1661 // Currently the only thing in the header is StrictMode stacks,
1662 // but discussions around event/RPC tracing suggest we might
1663 // put that here too. If so, switch on sub-header tags here.
1664 // But for now, just parse out the StrictMode stuff.
1665 StrictMode.readAndHandleBinderCallViolations(this);
1667 // And fat response headers are currently only used when
1668 // there are no exceptions, so return no error:
1675 * Throw an exception with the given message. Not intended for use
1676 * outside the Parcel class.
1678 * @param code Used to determine which exception class to throw.
1679 * @param msg The exception message.
1681 public final void readException(int code, String msg) {
1684 throw new SecurityException(msg);
1685 case EX_BAD_PARCELABLE:
1686 throw new BadParcelableException(msg);
1687 case EX_ILLEGAL_ARGUMENT:
1688 throw new IllegalArgumentException(msg);
1689 case EX_NULL_POINTER:
1690 throw new NullPointerException(msg);
1691 case EX_ILLEGAL_STATE:
1692 throw new IllegalStateException(msg);
1693 case EX_NETWORK_MAIN_THREAD:
1694 throw new NetworkOnMainThreadException();
1695 case EX_UNSUPPORTED_OPERATION:
1696 throw new UnsupportedOperationException(msg);
1697 case EX_SERVICE_SPECIFIC:
1698 throw new ServiceSpecificException(readInt(), msg);
1700 throw new RuntimeException("Unknown exception code: " + code
1705 * Read an integer value from the parcel at the current dataPosition().
1707 public final int readInt() {
1708 return nativeReadInt(mNativePtr);
1712 * Read a long integer value from the parcel at the current dataPosition().
1714 public final long readLong() {
1715 return nativeReadLong(mNativePtr);
1719 * Read a floating point value from the parcel at the current
1722 public final float readFloat() {
1723 return nativeReadFloat(mNativePtr);
1727 * Read a double precision floating point value from the parcel at the
1728 * current dataPosition().
1730 public final double readDouble() {
1731 return nativeReadDouble(mNativePtr);
1735 * Read a string value from the parcel at the current dataPosition().
1737 public final String readString() {
1738 return nativeReadString(mNativePtr);
1742 * Read a CharSequence value from the parcel at the current dataPosition().
1745 public final CharSequence readCharSequence() {
1746 return TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(this);
1750 * Read an object from the parcel at the current dataPosition().
1752 public final IBinder readStrongBinder() {
1753 return nativeReadStrongBinder(mNativePtr);
1757 * Read a FileDescriptor from the parcel at the current dataPosition().
1759 public final ParcelFileDescriptor readFileDescriptor() {
1760 FileDescriptor fd = nativeReadFileDescriptor(mNativePtr);
1761 return fd != null ? new ParcelFileDescriptor(fd) : null;
1765 public final FileDescriptor readRawFileDescriptor() {
1766 return nativeReadFileDescriptor(mNativePtr);
1771 * Read and return a new array of FileDescriptors from the parcel.
1772 * @return the FileDescriptor array, or null if the array is null.
1774 public final FileDescriptor[] createRawFileDescriptorArray() {
1779 FileDescriptor[] f = new FileDescriptor[N];
1780 for (int i = 0; i < N; i++) {
1781 f[i] = readRawFileDescriptor();
1788 * Read an array of FileDescriptors from a parcel.
1789 * The passed array must be exactly the length of the array in the parcel.
1790 * @return the FileDescriptor array, or null if the array is null.
1792 public final void readRawFileDescriptorArray(FileDescriptor[] val) {
1794 if (N == val.length) {
1795 for (int i=0; i<N; i++) {
1796 val[i] = readRawFileDescriptor();
1799 throw new RuntimeException("bad array lengths");
1804 /*package*/ static native FileDescriptor openFileDescriptor(String file,
1805 int mode) throws FileNotFoundException;
1806 /*package*/ static native FileDescriptor dupFileDescriptor(FileDescriptor orig)
1808 /*package*/ static native void closeFileDescriptor(FileDescriptor desc)
1810 /*package*/ static native void clearFileDescriptor(FileDescriptor desc);
1813 * Read a byte value from the parcel at the current dataPosition().
1815 public final byte readByte() {
1816 return (byte)(readInt() & 0xff);
1820 * Please use {@link #readBundle(ClassLoader)} instead (whose data must have
1821 * been written with {@link #writeBundle}. Read into an existing Map object
1822 * from the parcel at the current dataPosition().
1824 public final void readMap(Map outVal, ClassLoader loader) {
1826 readMapInternal(outVal, N, loader);
1830 * Read into an existing List object from the parcel at the current
1831 * dataPosition(), using the given class loader to load any enclosed
1832 * Parcelables. If it is null, the default class loader is used.
1834 public final void readList(List outVal, ClassLoader loader) {
1836 readListInternal(outVal, N, loader);
1840 * Please use {@link #readBundle(ClassLoader)} instead (whose data must have
1841 * been written with {@link #writeBundle}. Read and return a new HashMap
1842 * object from the parcel at the current dataPosition(), using the given
1843 * class loader to load any enclosed Parcelables. Returns null if
1844 * the previously written map object was null.
1846 public final HashMap readHashMap(ClassLoader loader)
1852 HashMap m = new HashMap(N);
1853 readMapInternal(m, N, loader);
1858 * Read and return a new Bundle object from the parcel at the current
1859 * dataPosition(). Returns null if the previously written Bundle object was
1862 public final Bundle readBundle() {
1863 return readBundle(null);
1867 * Read and return a new Bundle object from the parcel at the current
1868 * dataPosition(), using the given class loader to initialize the class
1869 * loader of the Bundle for later retrieval of Parcelable objects.
1870 * Returns null if the previously written Bundle object was null.
1872 public final Bundle readBundle(ClassLoader loader) {
1873 int length = readInt();
1875 if (Bundle.DEBUG) Log.d(TAG, "null bundle: length=" + length);
1879 final Bundle bundle = new Bundle(this, length);
1880 if (loader != null) {
1881 bundle.setClassLoader(loader);
1887 * Read and return a new Bundle object from the parcel at the current
1888 * dataPosition(). Returns null if the previously written Bundle object was
1891 public final PersistableBundle readPersistableBundle() {
1892 return readPersistableBundle(null);
1896 * Read and return a new Bundle object from the parcel at the current
1897 * dataPosition(), using the given class loader to initialize the class
1898 * loader of the Bundle for later retrieval of Parcelable objects.
1899 * Returns null if the previously written Bundle object was null.
1901 public final PersistableBundle readPersistableBundle(ClassLoader loader) {
1902 int length = readInt();
1904 if (Bundle.DEBUG) Log.d(TAG, "null bundle: length=" + length);
1908 final PersistableBundle bundle = new PersistableBundle(this, length);
1909 if (loader != null) {
1910 bundle.setClassLoader(loader);
1916 * Read a Size from the parcel at the current dataPosition().
1918 public final Size readSize() {
1919 final int width = readInt();
1920 final int height = readInt();
1921 return new Size(width, height);
1925 * Read a SizeF from the parcel at the current dataPosition().
1927 public final SizeF readSizeF() {
1928 final float width = readFloat();
1929 final float height = readFloat();
1930 return new SizeF(width, height);
1934 * Read and return a byte[] object from the parcel.
1936 public final byte[] createByteArray() {
1937 return nativeCreateByteArray(mNativePtr);
1941 * Read a byte[] object from the parcel and copy it into the
1944 public final void readByteArray(byte[] val) {
1945 // TODO: make this a native method to avoid the extra copy.
1946 byte[] ba = createByteArray();
1947 if (ba.length == val.length) {
1948 System.arraycopy(ba, 0, val, 0, ba.length);
1950 throw new RuntimeException("bad array lengths");
1955 * Read a blob of data from the parcel and return it as a byte array.
1959 public final byte[] readBlob() {
1960 return nativeReadBlob(mNativePtr);
1964 * Read and return a String[] object from the parcel.
1967 public final String[] readStringArray() {
1968 String[] array = null;
1970 int length = readInt();
1973 array = new String[length];
1975 for (int i = 0 ; i < length ; i++)
1977 array[i] = readString();
1985 * Read and return a CharSequence[] object from the parcel.
1988 public final CharSequence[] readCharSequenceArray() {
1989 CharSequence[] array = null;
1991 int length = readInt();
1994 array = new CharSequence[length];
1996 for (int i = 0 ; i < length ; i++)
1998 array[i] = readCharSequence();
2006 * Read and return an ArrayList<CharSequence> object from the parcel.
2009 public final ArrayList<CharSequence> readCharSequenceList() {
2010 ArrayList<CharSequence> array = null;
2012 int length = readInt();
2014 array = new ArrayList<CharSequence>(length);
2016 for (int i = 0 ; i < length ; i++) {
2017 array.add(readCharSequence());
2025 * Read and return a new ArrayList object from the parcel at the current
2026 * dataPosition(). Returns null if the previously written list object was
2027 * null. The given class loader will be used to load any enclosed
2030 public final ArrayList readArrayList(ClassLoader loader) {
2035 ArrayList l = new ArrayList(N);
2036 readListInternal(l, N, loader);
2041 * Read and return a new Object array from the parcel at the current
2042 * dataPosition(). Returns null if the previously written array was
2043 * null. The given class loader will be used to load any enclosed
2046 public final Object[] readArray(ClassLoader loader) {
2051 Object[] l = new Object[N];
2052 readArrayInternal(l, N, loader);
2057 * Read and return a new SparseArray object from the parcel at the current
2058 * dataPosition(). Returns null if the previously written list object was
2059 * null. The given class loader will be used to load any enclosed
2062 public final SparseArray readSparseArray(ClassLoader loader) {
2067 SparseArray sa = new SparseArray(N);
2068 readSparseArrayInternal(sa, N, loader);
2073 * Read and return a new SparseBooleanArray object from the parcel at the current
2074 * dataPosition(). Returns null if the previously written list object was
2077 public final SparseBooleanArray readSparseBooleanArray() {
2082 SparseBooleanArray sa = new SparseBooleanArray(N);
2083 readSparseBooleanArrayInternal(sa, N);
2088 * Read and return a new ArrayList containing a particular object type from
2089 * the parcel that was written with {@link #writeTypedList} at the
2090 * current dataPosition(). Returns null if the
2091 * previously written list object was null. The list <em>must</em> have
2092 * previously been written via {@link #writeTypedList} with the same object
2095 * @return A newly created ArrayList containing objects with the same data
2096 * as those that were previously written.
2098 * @see #writeTypedList
2100 public final <T> ArrayList<T> createTypedArrayList(Parcelable.Creator<T> c) {
2105 ArrayList<T> l = new ArrayList<T>(N);
2107 if (readInt() != 0) {
2108 l.add(c.createFromParcel(this));
2118 * Read into the given List items containing a particular object type
2119 * that were written with {@link #writeTypedList} at the
2120 * current dataPosition(). The list <em>must</em> have
2121 * previously been written via {@link #writeTypedList} with the same object
2124 * @return A newly created ArrayList containing objects with the same data
2125 * as those that were previously written.
2127 * @see #writeTypedList
2129 public final <T> void readTypedList(List<T> list, Parcelable.Creator<T> c) {
2130 int M = list.size();
2133 for (; i < M && i < N; i++) {
2134 if (readInt() != 0) {
2135 list.set(i, c.createFromParcel(this));
2141 if (readInt() != 0) {
2142 list.add(c.createFromParcel(this));
2153 * Read and return a new ArrayList containing String objects from
2154 * the parcel that was written with {@link #writeStringList} at the
2155 * current dataPosition(). Returns null if the
2156 * previously written list object was null.
2158 * @return A newly created ArrayList containing strings with the same data
2159 * as those that were previously written.
2161 * @see #writeStringList
2163 public final ArrayList<String> createStringArrayList() {
2168 ArrayList<String> l = new ArrayList<String>(N);
2170 l.add(readString());
2177 * Read and return a new ArrayList containing IBinder objects from
2178 * the parcel that was written with {@link #writeBinderList} at the
2179 * current dataPosition(). Returns null if the
2180 * previously written list object was null.
2182 * @return A newly created ArrayList containing strings with the same data
2183 * as those that were previously written.
2185 * @see #writeBinderList
2187 public final ArrayList<IBinder> createBinderArrayList() {
2192 ArrayList<IBinder> l = new ArrayList<IBinder>(N);
2194 l.add(readStrongBinder());
2201 * Read into the given List items String objects that were written with
2202 * {@link #writeStringList} at the current dataPosition().
2204 * @return A newly created ArrayList containing strings with the same data
2205 * as those that were previously written.
2207 * @see #writeStringList
2209 public final void readStringList(List<String> list) {
2210 int M = list.size();
2213 for (; i < M && i < N; i++) {
2214 list.set(i, readString());
2217 list.add(readString());
2225 * Read into the given List items IBinder objects that were written with
2226 * {@link #writeBinderList} at the current dataPosition().
2228 * @return A newly created ArrayList containing strings with the same data
2229 * as those that were previously written.
2231 * @see #writeBinderList
2233 public final void readBinderList(List<IBinder> list) {
2234 int M = list.size();
2237 for (; i < M && i < N; i++) {
2238 list.set(i, readStrongBinder());
2241 list.add(readStrongBinder());
2249 * Read and return a new array containing a particular object type from
2250 * the parcel at the current dataPosition(). Returns null if the
2251 * previously written array was null. The array <em>must</em> have
2252 * previously been written via {@link #writeTypedArray} with the same
2255 * @return A newly created array containing objects with the same data
2256 * as those that were previously written.
2258 * @see #writeTypedArray
2260 public final <T> T[] createTypedArray(Parcelable.Creator<T> c) {
2265 T[] l = c.newArray(N);
2266 for (int i=0; i<N; i++) {
2267 if (readInt() != 0) {
2268 l[i] = c.createFromParcel(this);
2274 public final <T> void readTypedArray(T[] val, Parcelable.Creator<T> c) {
2276 if (N == val.length) {
2277 for (int i=0; i<N; i++) {
2278 if (readInt() != 0) {
2279 val[i] = c.createFromParcel(this);
2285 throw new RuntimeException("bad array lengths");
2294 public final <T> T[] readTypedArray(Parcelable.Creator<T> c) {
2295 return createTypedArray(c);
2299 * Read and return a typed Parcelable object from a parcel.
2300 * Returns null if the previous written object was null.
2301 * The object <em>must</em> have previous been written via
2302 * {@link #writeTypedObject} with the same object type.
2304 * @return A newly created object of the type that was previously
2307 * @see #writeTypedObject
2309 public final <T> T readTypedObject(Parcelable.Creator<T> c) {
2310 if (readInt() != 0) {
2311 return c.createFromParcel(this);
2318 * Write a heterogeneous array of Parcelable objects into the Parcel.
2319 * Each object in the array is written along with its class name, so
2320 * that the correct class can later be instantiated. As a result, this
2321 * has significantly more overhead than {@link #writeTypedArray}, but will
2322 * correctly handle an array containing more than one type of object.
2324 * @param value The array of objects to be written.
2325 * @param parcelableFlags Contextual flags as per
2326 * {@link Parcelable#writeToParcel(Parcel, int) Parcelable.writeToParcel()}.
2328 * @see #writeTypedArray
2330 public final <T extends Parcelable> void writeParcelableArray(T[] value,
2331 int parcelableFlags) {
2332 if (value != null) {
2333 int N = value.length;
2335 for (int i=0; i<N; i++) {
2336 writeParcelable(value[i], parcelableFlags);
2344 * Read a typed object from a parcel. The given class loader will be
2345 * used to load any enclosed Parcelables. If it is null, the default class
2346 * loader will be used.
2348 public final Object readValue(ClassLoader loader) {
2349 int type = readInt();
2356 return readString();
2362 return readHashMap(loader);
2364 case VAL_PARCELABLE:
2365 return readParcelable(loader);
2368 return (short) readInt();
2377 return readDouble();
2380 return readInt() == 1;
2382 case VAL_CHARSEQUENCE:
2383 return readCharSequence();
2386 return readArrayList(loader);
2388 case VAL_BOOLEANARRAY:
2389 return createBooleanArray();
2392 return createByteArray();
2394 case VAL_STRINGARRAY:
2395 return readStringArray();
2397 case VAL_CHARSEQUENCEARRAY:
2398 return readCharSequenceArray();
2401 return readStrongBinder();
2403 case VAL_OBJECTARRAY:
2404 return readArray(loader);
2407 return createIntArray();
2410 return createLongArray();
2415 case VAL_SERIALIZABLE:
2416 return readSerializable(loader);
2418 case VAL_PARCELABLEARRAY:
2419 return readParcelableArray(loader);
2421 case VAL_SPARSEARRAY:
2422 return readSparseArray(loader);
2424 case VAL_SPARSEBOOLEANARRAY:
2425 return readSparseBooleanArray();
2428 return readBundle(loader); // loading will be deferred
2430 case VAL_PERSISTABLEBUNDLE:
2431 return readPersistableBundle(loader);
2439 case VAL_DOUBLEARRAY:
2440 return createDoubleArray();
2443 int off = dataPosition() - 4;
2444 throw new RuntimeException(
2445 "Parcel " + this + ": Unmarshalling unknown type code " + type + " at offset " + off);
2450 * Read and return a new Parcelable from the parcel. The given class loader
2451 * will be used to load any enclosed Parcelables. If it is null, the default
2452 * class loader will be used.
2453 * @param loader A ClassLoader from which to instantiate the Parcelable
2454 * object, or null for the default class loader.
2455 * @return Returns the newly created Parcelable, or null if a null
2456 * object has been written.
2457 * @throws BadParcelableException Throws BadParcelableException if there
2458 * was an error trying to instantiate the Parcelable.
2460 @SuppressWarnings("unchecked")
2461 public final <T extends Parcelable> T readParcelable(ClassLoader loader) {
2462 Parcelable.Creator<?> creator = readParcelableCreator(loader);
2463 if (creator == null) {
2466 if (creator instanceof Parcelable.ClassLoaderCreator<?>) {
2467 Parcelable.ClassLoaderCreator<?> classLoaderCreator =
2468 (Parcelable.ClassLoaderCreator<?>) creator;
2469 return (T) classLoaderCreator.createFromParcel(this, loader);
2471 return (T) creator.createFromParcel(this);
2475 @SuppressWarnings("unchecked")
2476 public final <T extends Parcelable> T readCreator(Parcelable.Creator<?> creator,
2477 ClassLoader loader) {
2478 if (creator instanceof Parcelable.ClassLoaderCreator<?>) {
2479 Parcelable.ClassLoaderCreator<?> classLoaderCreator =
2480 (Parcelable.ClassLoaderCreator<?>) creator;
2481 return (T) classLoaderCreator.createFromParcel(this, loader);
2483 return (T) creator.createFromParcel(this);
2487 public final Parcelable.Creator<?> readParcelableCreator(ClassLoader loader) {
2488 String name = readString();
2492 Parcelable.Creator<?> creator;
2493 synchronized (mCreators) {
2494 HashMap<String,Parcelable.Creator<?>> map = mCreators.get(loader);
2496 map = new HashMap<>();
2497 mCreators.put(loader, map);
2499 creator = map.get(name);
2500 if (creator == null) {
2502 // If loader == null, explicitly emulate Class.forName(String) "caller
2503 // classloader" behavior.
2504 ClassLoader parcelableClassLoader =
2505 (loader == null ? getClass().getClassLoader() : loader);
2506 // Avoid initializing the Parcelable class until we know it implements
2507 // Parcelable and has the necessary CREATOR field. http://b/1171613.
2508 Class<?> parcelableClass = Class.forName(name, false /* initialize */,
2509 parcelableClassLoader);
2510 if (!Parcelable.class.isAssignableFrom(parcelableClass)) {
2511 throw new BadParcelableException("Parcelable protocol requires that the "
2512 + "class implements Parcelable");
2514 Field f = parcelableClass.getField("CREATOR");
2515 if ((f.getModifiers() & Modifier.STATIC) == 0) {
2516 throw new BadParcelableException("Parcelable protocol requires "
2517 + "the CREATOR object to be static on class " + name);
2519 Class<?> creatorType = f.getType();
2520 if (!Parcelable.Creator.class.isAssignableFrom(creatorType)) {
2521 // Fail before calling Field.get(), not after, to avoid initializing
2522 // parcelableClass unnecessarily.
2523 throw new BadParcelableException("Parcelable protocol requires a "
2524 + "Parcelable.Creator object called "
2525 + "CREATOR on class " + name);
2527 creator = (Parcelable.Creator<?>) f.get(null);
2529 catch (IllegalAccessException e) {
2530 Log.e(TAG, "Illegal access when unmarshalling: " + name, e);
2531 throw new BadParcelableException(
2532 "IllegalAccessException when unmarshalling: " + name);
2534 catch (ClassNotFoundException e) {
2535 Log.e(TAG, "Class not found when unmarshalling: " + name, e);
2536 throw new BadParcelableException(
2537 "ClassNotFoundException when unmarshalling: " + name);
2539 catch (NoSuchFieldException e) {
2540 throw new BadParcelableException("Parcelable protocol requires a "
2541 + "Parcelable.Creator object called "
2542 + "CREATOR on class " + name);
2544 if (creator == null) {
2545 throw new BadParcelableException("Parcelable protocol requires a "
2546 + "non-null Parcelable.Creator object called "
2547 + "CREATOR on class " + name);
2550 map.put(name, creator);
2558 * Read and return a new Parcelable array from the parcel.
2559 * The given class loader will be used to load any enclosed
2561 * @return the Parcelable array, or null if the array is null
2563 public final Parcelable[] readParcelableArray(ClassLoader loader) {
2568 Parcelable[] p = new Parcelable[N];
2569 for (int i = 0; i < N; i++) {
2570 p[i] = readParcelable(loader);
2576 public final <T extends Parcelable> T[] readParcelableArray(ClassLoader loader,
2582 T[] p = (T[]) Array.newInstance(clazz, N);
2583 for (int i = 0; i < N; i++) {
2584 p[i] = readParcelable(loader);
2590 * Read and return a new Serializable object from the parcel.
2591 * @return the Serializable object, or null if the Serializable name
2592 * wasn't found in the parcel.
2594 public final Serializable readSerializable() {
2595 return readSerializable(null);
2598 private final Serializable readSerializable(final ClassLoader loader) {
2599 String name = readString();
2601 // For some reason we were unable to read the name of the Serializable (either there
2602 // is nothing left in the Parcel to read, or the next value wasn't a String), so
2603 // return null, which indicates that the name wasn't found in the parcel.
2607 byte[] serializedData = createByteArray();
2608 ByteArrayInputStream bais = new ByteArrayInputStream(serializedData);
2610 ObjectInputStream ois = new ObjectInputStream(bais) {
2612 protected Class<?> resolveClass(ObjectStreamClass osClass)
2613 throws IOException, ClassNotFoundException {
2614 // try the custom classloader if provided
2615 if (loader != null) {
2616 Class<?> c = Class.forName(osClass.getName(), false, loader);
2621 return super.resolveClass(osClass);
2624 return (Serializable) ois.readObject();
2625 } catch (IOException ioe) {
2626 throw new RuntimeException("Parcelable encountered " +
2627 "IOException reading a Serializable object (name = " + name +
2629 } catch (ClassNotFoundException cnfe) {
2630 throw new RuntimeException("Parcelable encountered " +
2631 "ClassNotFoundException reading a Serializable object (name = "
2632 + name + ")", cnfe);
2636 // Cache of previously looked up CREATOR.createFromParcel() methods for
2637 // particular classes. Keys are the names of the classes, values are
2639 private static final HashMap<ClassLoader,HashMap<String,Parcelable.Creator<?>>>
2640 mCreators = new HashMap<>();
2642 /** @hide for internal use only. */
2643 static protected final Parcel obtain(int obj) {
2644 throw new UnsupportedOperationException();
2648 static protected final Parcel obtain(long obj) {
2649 final Parcel[] pool = sHolderPool;
2650 synchronized (pool) {
2652 for (int i=0; i<POOL_SIZE; i++) {
2656 if (DEBUG_RECYCLE) {
2657 p.mStack = new RuntimeException();
2664 return new Parcel(obj);
2667 private Parcel(long nativePtr) {
2668 if (DEBUG_RECYCLE) {
2669 mStack = new RuntimeException();
2671 //Log.i(TAG, "Initializing obj=0x" + Integer.toHexString(obj), mStack);
2675 private void init(long nativePtr) {
2676 if (nativePtr != 0) {
2677 mNativePtr = nativePtr;
2678 mOwnsNativeParcelObject = false;
2680 mNativePtr = nativeCreate();
2681 mOwnsNativeParcelObject = true;
2685 private void freeBuffer() {
2686 if (mOwnsNativeParcelObject) {
2687 updateNativeSize(nativeFreeBuffer(mNativePtr));
2691 private void destroy() {
2692 if (mNativePtr != 0) {
2693 if (mOwnsNativeParcelObject) {
2694 nativeDestroy(mNativePtr);
2695 updateNativeSize(0);
2702 protected void finalize() throws Throwable {
2703 if (DEBUG_RECYCLE) {
2704 if (mStack != null) {
2705 Log.w(TAG, "Client did not call Parcel.recycle()", mStack);
2711 /* package */ void readMapInternal(Map outVal, int N,
2712 ClassLoader loader) {
2714 Object key = readValue(loader);
2715 Object value = readValue(loader);
2716 outVal.put(key, value);
2721 /* package */ void readArrayMapInternal(ArrayMap outVal, int N,
2722 ClassLoader loader) {
2723 if (DEBUG_ARRAY_MAP) {
2724 RuntimeException here = new RuntimeException("here");
2725 here.fillInStackTrace();
2726 Log.d(TAG, "Reading " + N + " ArrayMap entries", here);
2730 if (DEBUG_ARRAY_MAP) startPos = dataPosition();
2731 String key = readString();
2732 Object value = readValue(loader);
2733 if (DEBUG_ARRAY_MAP) Log.d(TAG, " Read #" + (N-1) + " "
2734 + (dataPosition()-startPos) + " bytes: key=0x"
2735 + Integer.toHexString((key != null ? key.hashCode() : 0)) + " " + key);
2736 outVal.append(key, value);
2742 /* package */ void readArrayMapSafelyInternal(ArrayMap outVal, int N,
2743 ClassLoader loader) {
2744 if (DEBUG_ARRAY_MAP) {
2745 RuntimeException here = new RuntimeException("here");
2746 here.fillInStackTrace();
2747 Log.d(TAG, "Reading safely " + N + " ArrayMap entries", here);
2750 String key = readString();
2751 if (DEBUG_ARRAY_MAP) Log.d(TAG, " Read safe #" + (N-1) + ": key=0x"
2752 + (key != null ? key.hashCode() : 0) + " " + key);
2753 Object value = readValue(loader);
2754 outVal.put(key, value);
2760 * @hide For testing only.
2762 public void readArrayMap(ArrayMap outVal, ClassLoader loader) {
2763 final int N = readInt();
2767 readArrayMapInternal(outVal, N, loader);
2771 * Reads an array set.
2773 * @param loader The class loader to use.
2777 public @Nullable ArraySet<? extends Object> readArraySet(ClassLoader loader) {
2778 final int size = readInt();
2782 ArraySet<Object> result = new ArraySet<>(size);
2783 for (int i = 0; i < size; i++) {
2784 Object value = readValue(loader);
2785 result.append(value);
2790 private void readListInternal(List outVal, int N,
2791 ClassLoader loader) {
2793 Object value = readValue(loader);
2794 //Log.d(TAG, "Unmarshalling value=" + value);
2800 private void readArrayInternal(Object[] outVal, int N,
2801 ClassLoader loader) {
2802 for (int i = 0; i < N; i++) {
2803 Object value = readValue(loader);
2804 //Log.d(TAG, "Unmarshalling value=" + value);
2809 private void readSparseArrayInternal(SparseArray outVal, int N,
2810 ClassLoader loader) {
2812 int key = readInt();
2813 Object value = readValue(loader);
2814 //Log.i(TAG, "Unmarshalling key=" + key + " value=" + value);
2815 outVal.append(key, value);
2821 private void readSparseBooleanArrayInternal(SparseBooleanArray outVal, int N) {
2823 int key = readInt();
2824 boolean value = this.readByte() == 1;
2825 //Log.i(TAG, "Unmarshalling key=" + key + " value=" + value);
2826 outVal.append(key, value);
2834 public long getBlobAshmemSize() {
2835 return nativeGetBlobAshmemSize(mNativePtr);