Methods Summary |
---|
public final void | appendFrom(android.os.Parcel parcel, int offset, int length)
nativeAppendFrom(mNativePtr, parcel.mNativePtr, offset, length);
|
static native void | clearFileDescriptor(java.io.FileDescriptor desc)
|
static native void | closeFileDescriptor(java.io.FileDescriptor desc)
|
public final IBinder[] | createBinderArray()
int N = readInt();
if (N >= 0) {
IBinder[] val = new IBinder[N];
for (int i=0; i<N; i++) {
val[i] = readStrongBinder();
}
return val;
} else {
return null;
}
|
public final java.util.ArrayList | createBinderArrayList()Read and return a new ArrayList containing IBinder objects from
the parcel that was written with {@link #writeBinderList} at the
current dataPosition(). Returns null if the
previously written list object was null.
int N = readInt();
if (N < 0) {
return null;
}
ArrayList<IBinder> l = new ArrayList<IBinder>(N);
while (N > 0) {
l.add(readStrongBinder());
N--;
}
return l;
|
public final boolean[] | createBooleanArray()
int N = readInt();
// >>2 as a fast divide-by-4 works in the create*Array() functions
// because dataAvail() will never return a negative number. 4 is
// the size of a stored boolean in the stream.
if (N >= 0 && N <= (dataAvail() >> 2)) {
boolean[] val = new boolean[N];
for (int i=0; i<N; i++) {
val[i] = readInt() != 0;
}
return val;
} else {
return null;
}
|
public final byte[] | createByteArray()Read and return a byte[] object from the parcel.
return nativeCreateByteArray(mNativePtr);
|
public final char[] | createCharArray()
int N = readInt();
if (N >= 0 && N <= (dataAvail() >> 2)) {
char[] val = new char[N];
for (int i=0; i<N; i++) {
val[i] = (char)readInt();
}
return val;
} else {
return null;
}
|
public final double[] | createDoubleArray()
int N = readInt();
// >>3 because stored doubles are 8 bytes
if (N >= 0 && N <= (dataAvail() >> 3)) {
double[] val = new double[N];
for (int i=0; i<N; i++) {
val[i] = readDouble();
}
return val;
} else {
return null;
}
|
public final float[] | createFloatArray()
int N = readInt();
// >>2 because stored floats are 4 bytes
if (N >= 0 && N <= (dataAvail() >> 2)) {
float[] val = new float[N];
for (int i=0; i<N; i++) {
val[i] = readFloat();
}
return val;
} else {
return null;
}
|
public final int[] | createIntArray()
int N = readInt();
if (N >= 0 && N <= (dataAvail() >> 2)) {
int[] val = new int[N];
for (int i=0; i<N; i++) {
val[i] = readInt();
}
return val;
} else {
return null;
}
|
public final long[] | createLongArray()
int N = readInt();
// >>3 because stored longs are 64 bits
if (N >= 0 && N <= (dataAvail() >> 3)) {
long[] val = new long[N];
for (int i=0; i<N; i++) {
val[i] = readLong();
}
return val;
} else {
return null;
}
|
public final java.lang.String[] | createStringArray()
int N = readInt();
if (N >= 0) {
String[] val = new String[N];
for (int i=0; i<N; i++) {
val[i] = readString();
}
return val;
} else {
return null;
}
|
public final java.util.ArrayList | createStringArrayList()Read and return a new ArrayList containing String objects from
the parcel that was written with {@link #writeStringList} at the
current dataPosition(). Returns null if the
previously written list object was null.
int N = readInt();
if (N < 0) {
return null;
}
ArrayList<String> l = new ArrayList<String>(N);
while (N > 0) {
l.add(readString());
N--;
}
return l;
|
public final T[] | createTypedArray(Parcelable.Creator c)Read and return a new array containing a particular object type from
the parcel at the current dataPosition(). Returns null if the
previously written array was null. The array must have
previously been written via {@link #writeTypedArray} with the same
object type.
int N = readInt();
if (N < 0) {
return null;
}
T[] l = c.newArray(N);
for (int i=0; i<N; i++) {
if (readInt() != 0) {
l[i] = c.createFromParcel(this);
}
}
return l;
|
public final java.util.ArrayList | createTypedArrayList(Parcelable.Creator c)Read and return a new ArrayList containing a particular object type from
the parcel that was written with {@link #writeTypedList} at the
current dataPosition(). Returns null if the
previously written list object was null. The list must have
previously been written via {@link #writeTypedList} with the same object
type.
int N = readInt();
if (N < 0) {
return null;
}
ArrayList<T> l = new ArrayList<T>(N);
while (N > 0) {
if (readInt() != 0) {
l.add(c.createFromParcel(this));
} else {
l.add(null);
}
N--;
}
return l;
|
public final int | dataAvail()Returns the amount of data remaining to be read from the
parcel. That is, {@link #dataSize}-{@link #dataPosition}.
return nativeDataAvail(mNativePtr);
|
public final int | dataCapacity()Returns the total amount of space in the parcel. This is always
>= {@link #dataSize}. The difference between it and dataSize() is the
amount of room left until the parcel needs to re-allocate its
data buffer.
return nativeDataCapacity(mNativePtr);
|
public final int | dataPosition()Returns the current position in the parcel data. Never
more than {@link #dataSize}.
return nativeDataPosition(mNativePtr);
|
public final int | dataSize()Returns the total amount of data contained in the parcel.
return nativeDataSize(mNativePtr);
|
private void | destroy()
if (mNativePtr != 0) {
if (mOwnsNativeParcelObject) {
nativeDestroy(mNativePtr);
}
mNativePtr = 0;
}
|
static native java.io.FileDescriptor | dupFileDescriptor(java.io.FileDescriptor orig)
|
public final void | enforceInterface(java.lang.String interfaceName)
nativeEnforceInterface(mNativePtr, interfaceName);
|
protected void | finalize()
if (DEBUG_RECYCLE) {
if (mStack != null) {
Log.w(TAG, "Client did not call Parcel.recycle()", mStack);
}
}
destroy();
|
private void | freeBuffer()
if (mOwnsNativeParcelObject) {
nativeFreeBuffer(mNativePtr);
}
|
public static native long | getGlobalAllocCount()
|
public static native long | getGlobalAllocSize()
|
public final boolean | hasFileDescriptors()Report whether the parcel contains any marshalled file descriptors.
return nativeHasFileDescriptors(mNativePtr);
|
private void | init(long nativePtr)
if (nativePtr != 0) {
mNativePtr = nativePtr;
mOwnsNativeParcelObject = false;
} else {
mNativePtr = nativeCreate();
mOwnsNativeParcelObject = true;
}
|
public final byte[] | marshall()Returns the raw bytes of the parcel.
The data you retrieve here must not
be placed in any kind of persistent storage (on local disk, across
a network, etc). For that, you should use standard serialization
or another kind of general serialization mechanism. The Parcel
marshalled representation is highly optimized for local IPC, and as
such does not attempt to maintain compatibility with data created
in different versions of the platform.
return nativeMarshall(mNativePtr);
|
private static native void | nativeAppendFrom(long thisNativePtr, long otherNativePtr, int offset, int length)
|
private static native long | nativeCreate()
|
private static native byte[] | nativeCreateByteArray(long nativePtr)
|
private static native int | nativeDataAvail(long nativePtr)
|
private static native int | nativeDataCapacity(long nativePtr)
|
private static native int | nativeDataPosition(long nativePtr)
|
private static native int | nativeDataSize(long nativePtr)
|
private static native void | nativeDestroy(long nativePtr)
|
private static native void | nativeEnforceInterface(long nativePtr, java.lang.String interfaceName)
|
private static native void | nativeFreeBuffer(long nativePtr)
|
private static native boolean | nativeHasFileDescriptors(long nativePtr)
|
private static native byte[] | nativeMarshall(long nativePtr)
|
private static native boolean | nativePushAllowFds(long nativePtr, boolean allowFds)
|
private static native byte[] | nativeReadBlob(long nativePtr)
|
private static native double | nativeReadDouble(long nativePtr)
|
private static native java.io.FileDescriptor | nativeReadFileDescriptor(long nativePtr)
|
private static native float | nativeReadFloat(long nativePtr)
|
private static native int | nativeReadInt(long nativePtr)
|
private static native long | nativeReadLong(long nativePtr)
|
private static native java.lang.String | nativeReadString(long nativePtr)
|
private static native IBinder | nativeReadStrongBinder(long nativePtr)
|
private static native void | nativeRestoreAllowFds(long nativePtr, boolean lastValue)
|
private static native void | nativeSetDataCapacity(long nativePtr, int size)
|
private static native void | nativeSetDataPosition(long nativePtr, int pos)
|
private static native void | nativeSetDataSize(long nativePtr, int size)
|
private static native void | nativeUnmarshall(long nativePtr, byte[] data, int offset, int length)
|
private static native void | nativeWriteBlob(long nativePtr, byte[] b, int offset, int len)
|
private static native void | nativeWriteByteArray(long nativePtr, byte[] b, int offset, int len)
|
private static native void | nativeWriteDouble(long nativePtr, double val)
|
private static native void | nativeWriteFileDescriptor(long nativePtr, java.io.FileDescriptor val)
|
private static native void | nativeWriteFloat(long nativePtr, float val)
|
private static native void | nativeWriteInt(long nativePtr, int val)
|
private static native void | nativeWriteInterfaceToken(long nativePtr, java.lang.String interfaceName)
|
private static native void | nativeWriteLong(long nativePtr, long val)
|
private static native void | nativeWriteString(long nativePtr, java.lang.String val)
|
private static native void | nativeWriteStrongBinder(long nativePtr, IBinder val)
|
protected static final android.os.Parcel | obtain(int obj)
throw new UnsupportedOperationException();
|
protected static final android.os.Parcel | obtain(long obj)
final Parcel[] pool = sHolderPool;
synchronized (pool) {
Parcel p;
for (int i=0; i<POOL_SIZE; i++) {
p = pool[i];
if (p != null) {
pool[i] = null;
if (DEBUG_RECYCLE) {
p.mStack = new RuntimeException();
}
p.init(obj);
return p;
}
}
}
return new Parcel(obj);
|
public static android.os.Parcel | obtain()Retrieve a new Parcel object from the pool.
final Parcel[] pool = sOwnedPool;
synchronized (pool) {
Parcel p;
for (int i=0; i<POOL_SIZE; i++) {
p = pool[i];
if (p != null) {
pool[i] = null;
if (DEBUG_RECYCLE) {
p.mStack = new RuntimeException();
}
return p;
}
}
}
return new Parcel(0);
|
static native java.io.FileDescriptor | openFileDescriptor(java.lang.String file, int mode)
|
public final boolean | pushAllowFds(boolean allowFds)
return nativePushAllowFds(mNativePtr, allowFds);
|
public final java.lang.Object[] | readArray(java.lang.ClassLoader loader)Read and return a new Object array from the parcel at the current
dataPosition(). Returns null if the previously written array was
null. The given class loader will be used to load any enclosed
Parcelables.
int N = readInt();
if (N < 0) {
return null;
}
Object[] l = new Object[N];
readArrayInternal(l, N, loader);
return l;
|
private void | readArrayInternal(java.lang.Object[] outVal, int N, java.lang.ClassLoader loader)
for (int i = 0; i < N; i++) {
Object value = readValue(loader);
//Log.d(TAG, "Unmarshalling value=" + value);
outVal[i] = value;
}
|
public final java.util.ArrayList | readArrayList(java.lang.ClassLoader loader)Read and return a new ArrayList object from the parcel at the current
dataPosition(). Returns null if the previously written list object was
null. The given class loader will be used to load any enclosed
Parcelables.
int N = readInt();
if (N < 0) {
return null;
}
ArrayList l = new ArrayList(N);
readListInternal(l, N, loader);
return l;
|
public void | readArrayMap(android.util.ArrayMap outVal, java.lang.ClassLoader loader)
final int N = readInt();
if (N < 0) {
return;
}
readArrayMapInternal(outVal, N, loader);
|
void | readArrayMapInternal(android.util.ArrayMap outVal, int N, java.lang.ClassLoader loader)
if (DEBUG_ARRAY_MAP) {
RuntimeException here = new RuntimeException("here");
here.fillInStackTrace();
Log.d(TAG, "Reading " + N + " ArrayMap entries", here);
}
int startPos;
while (N > 0) {
if (DEBUG_ARRAY_MAP) startPos = dataPosition();
String key = readString();
Object value = readValue(loader);
if (DEBUG_ARRAY_MAP) Log.d(TAG, " Read #" + (N-1) + " "
+ (dataPosition()-startPos) + " bytes: key=0x"
+ Integer.toHexString((key != null ? key.hashCode() : 0)) + " " + key);
outVal.append(key, value);
N--;
}
outVal.validate();
|
void | readArrayMapSafelyInternal(android.util.ArrayMap outVal, int N, java.lang.ClassLoader loader)
if (DEBUG_ARRAY_MAP) {
RuntimeException here = new RuntimeException("here");
here.fillInStackTrace();
Log.d(TAG, "Reading safely " + N + " ArrayMap entries", here);
}
while (N > 0) {
String key = readString();
if (DEBUG_ARRAY_MAP) Log.d(TAG, " Read safe #" + (N-1) + ": key=0x"
+ (key != null ? key.hashCode() : 0) + " " + key);
Object value = readValue(loader);
outVal.put(key, value);
N--;
}
|
public final void | readBinderArray(IBinder[] val)
int N = readInt();
if (N == val.length) {
for (int i=0; i<N; i++) {
val[i] = readStrongBinder();
}
} else {
throw new RuntimeException("bad array lengths");
}
|
public final void | readBinderList(java.util.List list)Read into the given List items IBinder objects that were written with
{@link #writeBinderList} at the current dataPosition().
int M = list.size();
int N = readInt();
int i = 0;
for (; i < M && i < N; i++) {
list.set(i, readStrongBinder());
}
for (; i<N; i++) {
list.add(readStrongBinder());
}
for (; i<M; i++) {
list.remove(N);
}
|
public final byte[] | readBlob()Read a blob of data from the parcel and return it as a byte array.
{@hide}
{@SystemApi}
return nativeReadBlob(mNativePtr);
|
public final void | readBooleanArray(boolean[] val)
int N = readInt();
if (N == val.length) {
for (int i=0; i<N; i++) {
val[i] = readInt() != 0;
}
} else {
throw new RuntimeException("bad array lengths");
}
|
public final Bundle | readBundle()Read and return a new Bundle object from the parcel at the current
dataPosition(). Returns null if the previously written Bundle object was
null.
return readBundle(null);
|
public final Bundle | readBundle(java.lang.ClassLoader loader)Read and return a new Bundle object from the parcel at the current
dataPosition(), using the given class loader to initialize the class
loader of the Bundle for later retrieval of Parcelable objects.
Returns null if the previously written Bundle object was null.
int length = readInt();
if (length < 0) {
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);
}
return bundle;
|
public final byte | readByte()Read a byte value from the parcel at the current dataPosition().
return (byte)(readInt() & 0xff);
|
public final void | readByteArray(byte[] val)Read a byte[] object from the parcel and copy it into the
given byte array.
// TODO: make this a native method to avoid the extra copy.
byte[] ba = createByteArray();
if (ba.length == val.length) {
System.arraycopy(ba, 0, val, 0, ba.length);
} else {
throw new RuntimeException("bad array lengths");
}
|
public final void | readCharArray(char[] val)
int N = readInt();
if (N == val.length) {
for (int i=0; i<N; i++) {
val[i] = (char)readInt();
}
} else {
throw new RuntimeException("bad array lengths");
}
|
public final java.lang.CharSequence | readCharSequence()Read a CharSequence value from the parcel at the current dataPosition().
return TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(this);
|
public final java.lang.CharSequence[] | readCharSequenceArray()Read and return a CharSequence[] object from the parcel.
{@hide}
CharSequence[] array = null;
int length = readInt();
if (length >= 0)
{
array = new CharSequence[length];
for (int i = 0 ; i < length ; i++)
{
array[i] = readCharSequence();
}
}
return array;
|
public final T | readCreator(Parcelable.Creator creator, java.lang.ClassLoader loader)
if (creator instanceof Parcelable.ClassLoaderCreator<?>) {
return ((Parcelable.ClassLoaderCreator<T>)creator).createFromParcel(this, loader);
}
return creator.createFromParcel(this);
|
public final double | readDouble()Read a double precision floating point value from the parcel at the
current dataPosition().
return nativeReadDouble(mNativePtr);
|
public final void | readDoubleArray(double[] val)
int N = readInt();
if (N == val.length) {
for (int i=0; i<N; i++) {
val[i] = readDouble();
}
} else {
throw new RuntimeException("bad array lengths");
}
|
public final void | readException()Special function for reading an exception result from the header of
a parcel, to be used after receiving the result of a transaction. This
will throw the exception for you if it had been written to the Parcel,
otherwise return and let you read the normal result data from the Parcel.
int code = readExceptionCode();
if (code != 0) {
String msg = readString();
readException(code, msg);
}
|
public final void | readException(int code, java.lang.String msg)Throw an exception with the given message. Not intended for use
outside the Parcel class.
switch (code) {
case EX_SECURITY:
throw new SecurityException(msg);
case EX_BAD_PARCELABLE:
throw new BadParcelableException(msg);
case EX_ILLEGAL_ARGUMENT:
throw new IllegalArgumentException(msg);
case EX_NULL_POINTER:
throw new NullPointerException(msg);
case EX_ILLEGAL_STATE:
throw new IllegalStateException(msg);
case EX_NETWORK_MAIN_THREAD:
throw new NetworkOnMainThreadException();
case EX_UNSUPPORTED_OPERATION:
throw new UnsupportedOperationException(msg);
}
throw new RuntimeException("Unknown exception code: " + code
+ " msg " + msg);
|
public final int | readExceptionCode()Parses the header of a Binder call's response Parcel and
returns the exception code. Deals with lite or fat headers.
In the common successful case, this header is generally zero.
In less common cases, it's a small negative number and will be
followed by an error string.
This exists purely for android.database.DatabaseUtils and
insulating it from having to handle fat headers as returned by
e.g. StrictMode-induced RPC responses.
int code = readInt();
if (code == EX_HAS_REPLY_HEADER) {
int headerSize = readInt();
if (headerSize == 0) {
Log.e(TAG, "Unexpected zero-sized Parcel reply header.");
} else {
// Currently the only thing in the header is StrictMode stacks,
// but discussions around event/RPC tracing suggest we might
// put that here too. If so, switch on sub-header tags here.
// But for now, just parse out the StrictMode stuff.
StrictMode.readAndHandleBinderCallViolations(this);
}
// And fat response headers are currently only used when
// there are no exceptions, so return no error:
return 0;
}
return code;
|
public final ParcelFileDescriptor | readFileDescriptor()Read a FileDescriptor from the parcel at the current dataPosition().
FileDescriptor fd = nativeReadFileDescriptor(mNativePtr);
return fd != null ? new ParcelFileDescriptor(fd) : null;
|
public final float | readFloat()Read a floating point value from the parcel at the current
dataPosition().
return nativeReadFloat(mNativePtr);
|
public final void | readFloatArray(float[] val)
int N = readInt();
if (N == val.length) {
for (int i=0; i<N; i++) {
val[i] = readFloat();
}
} else {
throw new RuntimeException("bad array lengths");
}
|
public final java.util.HashMap | readHashMap(java.lang.ClassLoader loader)Please use {@link #readBundle(ClassLoader)} instead (whose data must have
been written with {@link #writeBundle}. Read and return a new HashMap
object from the parcel at the current dataPosition(), using the given
class loader to load any enclosed Parcelables. Returns null if
the previously written map object was null.
int N = readInt();
if (N < 0) {
return null;
}
HashMap m = new HashMap(N);
readMapInternal(m, N, loader);
return m;
|
public final int | readInt()Read an integer value from the parcel at the current dataPosition().
return nativeReadInt(mNativePtr);
|
public final void | readIntArray(int[] val)
int N = readInt();
if (N == val.length) {
for (int i=0; i<N; i++) {
val[i] = readInt();
}
} else {
throw new RuntimeException("bad array lengths");
}
|
public final void | readList(java.util.List outVal, java.lang.ClassLoader loader)Read into an existing List object from the parcel at the current
dataPosition(), using the given class loader to load any enclosed
Parcelables. If it is null, the default class loader is used.
int N = readInt();
readListInternal(outVal, N, loader);
|
private void | readListInternal(java.util.List outVal, int N, java.lang.ClassLoader loader)
while (N > 0) {
Object value = readValue(loader);
//Log.d(TAG, "Unmarshalling value=" + value);
outVal.add(value);
N--;
}
|
public final long | readLong()Read a long integer value from the parcel at the current dataPosition().
return nativeReadLong(mNativePtr);
|
public final void | readLongArray(long[] val)
int N = readInt();
if (N == val.length) {
for (int i=0; i<N; i++) {
val[i] = readLong();
}
} else {
throw new RuntimeException("bad array lengths");
}
|
public final void | readMap(java.util.Map outVal, java.lang.ClassLoader loader)Please use {@link #readBundle(ClassLoader)} instead (whose data must have
been written with {@link #writeBundle}. Read into an existing Map object
from the parcel at the current dataPosition().
int N = readInt();
readMapInternal(outVal, N, loader);
|
void | readMapInternal(java.util.Map outVal, int N, java.lang.ClassLoader loader)
while (N > 0) {
Object key = readValue(loader);
Object value = readValue(loader);
outVal.put(key, value);
N--;
}
|
public final T | readParcelable(java.lang.ClassLoader loader)Read and return a new Parcelable from the parcel. The given class loader
will be used to load any enclosed Parcelables. If it is null, the default
class loader will be used.
Parcelable.Creator<T> creator = readParcelableCreator(loader);
if (creator == null) {
return null;
}
if (creator instanceof Parcelable.ClassLoaderCreator<?>) {
return ((Parcelable.ClassLoaderCreator<T>)creator).createFromParcel(this, loader);
}
return creator.createFromParcel(this);
|
public final Parcelable[] | readParcelableArray(java.lang.ClassLoader loader)Read and return a new Parcelable array from the parcel.
The given class loader will be used to load any enclosed
Parcelables.
int N = readInt();
if (N < 0) {
return null;
}
Parcelable[] p = new Parcelable[N];
for (int i = 0; i < N; i++) {
p[i] = (Parcelable) readParcelable(loader);
}
return p;
|
public final Parcelable.Creator | readParcelableCreator(java.lang.ClassLoader loader)
String name = readString();
if (name == null) {
return null;
}
Parcelable.Creator<T> creator;
synchronized (mCreators) {
HashMap<String,Parcelable.Creator> map = mCreators.get(loader);
if (map == null) {
map = new HashMap<String,Parcelable.Creator>();
mCreators.put(loader, map);
}
creator = map.get(name);
if (creator == null) {
try {
Class c = loader == null ?
Class.forName(name) : Class.forName(name, true, loader);
Field f = c.getField("CREATOR");
creator = (Parcelable.Creator)f.get(null);
}
catch (IllegalAccessException e) {
Log.e(TAG, "Illegal access when unmarshalling: "
+ name, e);
throw new BadParcelableException(
"IllegalAccessException when unmarshalling: " + name);
}
catch (ClassNotFoundException e) {
Log.e(TAG, "Class not found when unmarshalling: "
+ name, e);
throw new BadParcelableException(
"ClassNotFoundException when unmarshalling: " + name);
}
catch (ClassCastException e) {
throw new BadParcelableException("Parcelable protocol requires a "
+ "Parcelable.Creator object called "
+ " CREATOR on class " + name);
}
catch (NoSuchFieldException e) {
throw new BadParcelableException("Parcelable protocol requires a "
+ "Parcelable.Creator object called "
+ " CREATOR on class " + name);
}
catch (NullPointerException e) {
throw new BadParcelableException("Parcelable protocol requires "
+ "the CREATOR object to be static on class " + name);
}
if (creator == null) {
throw new BadParcelableException("Parcelable protocol requires a "
+ "Parcelable.Creator object called "
+ " CREATOR on class " + name);
}
map.put(name, creator);
}
}
return creator;
|
public final PersistableBundle | readPersistableBundle()Read and return a new Bundle object from the parcel at the current
dataPosition(). Returns null if the previously written Bundle object was
null.
return readPersistableBundle(null);
|
public final PersistableBundle | readPersistableBundle(java.lang.ClassLoader loader)Read and return a new Bundle object from the parcel at the current
dataPosition(), using the given class loader to initialize the class
loader of the Bundle for later retrieval of Parcelable objects.
Returns null if the previously written Bundle object was null.
int length = readInt();
if (length < 0) {
if (Bundle.DEBUG) Log.d(TAG, "null bundle: length=" + length);
return null;
}
final PersistableBundle bundle = new PersistableBundle(this, length);
if (loader != null) {
bundle.setClassLoader(loader);
}
return bundle;
|
public final java.io.FileDescriptor | readRawFileDescriptor(){@hide}
return nativeReadFileDescriptor(mNativePtr);
|
public final java.io.Serializable | readSerializable()Read and return a new Serializable object from the parcel.
return readSerializable(null);
|
private final java.io.Serializable | readSerializable(java.lang.ClassLoader loader)
String name = readString();
if (name == null) {
// For some reason we were unable to read the name of the Serializable (either there
// is nothing left in the Parcel to read, or the next value wasn't a String), so
// return null, which indicates that the name wasn't found in the parcel.
return null;
}
byte[] serializedData = createByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(serializedData);
try {
ObjectInputStream ois = new ObjectInputStream(bais) {
@Override
protected Class<?> resolveClass(ObjectStreamClass osClass)
throws IOException, ClassNotFoundException {
// try the custom classloader if provided
if (loader != null) {
Class<?> c = Class.forName(osClass.getName(), false, loader);
if (c != null) {
return c;
}
}
return super.resolveClass(osClass);
}
};
return (Serializable) ois.readObject();
} catch (IOException ioe) {
throw new RuntimeException("Parcelable encountered " +
"IOException reading a Serializable object (name = " + name +
")", ioe);
} catch (ClassNotFoundException cnfe) {
throw new RuntimeException("Parcelable encountered " +
"ClassNotFoundException reading a Serializable object (name = "
+ name + ")", cnfe);
}
|
public final android.util.Size | readSize()Read a Size from the parcel at the current dataPosition().
final int width = readInt();
final int height = readInt();
return new Size(width, height);
|
public final android.util.SizeF | readSizeF()Read a SizeF from the parcel at the current dataPosition().
final float width = readFloat();
final float height = readFloat();
return new SizeF(width, height);
|
public final android.util.SparseArray | readSparseArray(java.lang.ClassLoader loader)Read and return a new SparseArray object from the parcel at the current
dataPosition(). Returns null if the previously written list object was
null. The given class loader will be used to load any enclosed
Parcelables.
int N = readInt();
if (N < 0) {
return null;
}
SparseArray sa = new SparseArray(N);
readSparseArrayInternal(sa, N, loader);
return sa;
|
private void | readSparseArrayInternal(android.util.SparseArray outVal, int N, java.lang.ClassLoader loader)
while (N > 0) {
int key = readInt();
Object value = readValue(loader);
//Log.i(TAG, "Unmarshalling key=" + key + " value=" + value);
outVal.append(key, value);
N--;
}
|
public final android.util.SparseBooleanArray | readSparseBooleanArray()Read and return a new SparseBooleanArray object from the parcel at the current
dataPosition(). Returns null if the previously written list object was
null.
int N = readInt();
if (N < 0) {
return null;
}
SparseBooleanArray sa = new SparseBooleanArray(N);
readSparseBooleanArrayInternal(sa, N);
return sa;
|
private void | readSparseBooleanArrayInternal(android.util.SparseBooleanArray outVal, int N)
while (N > 0) {
int key = readInt();
boolean value = this.readByte() == 1;
//Log.i(TAG, "Unmarshalling key=" + key + " value=" + value);
outVal.append(key, value);
N--;
}
|
public final java.lang.String | readString()Read a string value from the parcel at the current dataPosition().
return nativeReadString(mNativePtr);
|
public final void | readStringArray(java.lang.String[] val)
int N = readInt();
if (N == val.length) {
for (int i=0; i<N; i++) {
val[i] = readString();
}
} else {
throw new RuntimeException("bad array lengths");
}
|
public final java.lang.String[] | readStringArray()Read and return a String[] object from the parcel.
{@hide}
String[] array = null;
int length = readInt();
if (length >= 0)
{
array = new String[length];
for (int i = 0 ; i < length ; i++)
{
array[i] = readString();
}
}
return array;
|
public final void | readStringList(java.util.List list)Read into the given List items String objects that were written with
{@link #writeStringList} at the current dataPosition().
int M = list.size();
int N = readInt();
int i = 0;
for (; i < M && i < N; i++) {
list.set(i, readString());
}
for (; i<N; i++) {
list.add(readString());
}
for (; i<M; i++) {
list.remove(N);
}
|
public final IBinder | readStrongBinder()Read an object from the parcel at the current dataPosition().
return nativeReadStrongBinder(mNativePtr);
|
public final void | readTypedArray(T[] val, Parcelable.Creator c)
int N = readInt();
if (N == val.length) {
for (int i=0; i<N; i++) {
if (readInt() != 0) {
val[i] = c.createFromParcel(this);
} else {
val[i] = null;
}
}
} else {
throw new RuntimeException("bad array lengths");
}
|
public final T[] | readTypedArray(Parcelable.Creator c)
return createTypedArray(c);
|
public final void | readTypedList(java.util.List list, Parcelable.Creator c)Read into the given List items containing a particular object type
that were written with {@link #writeTypedList} at the
current dataPosition(). The list must have
previously been written via {@link #writeTypedList} with the same object
type.
int M = list.size();
int N = readInt();
int i = 0;
for (; i < M && i < N; i++) {
if (readInt() != 0) {
list.set(i, c.createFromParcel(this));
} else {
list.set(i, null);
}
}
for (; i<N; i++) {
if (readInt() != 0) {
list.add(c.createFromParcel(this));
} else {
list.add(null);
}
}
for (; i<M; i++) {
list.remove(N);
}
|
public final java.lang.Object | readValue(java.lang.ClassLoader loader)Read a typed object from a parcel. The given class loader will be
used to load any enclosed Parcelables. If it is null, the default class
loader will be used.
int type = readInt();
switch (type) {
case VAL_NULL:
return null;
case VAL_STRING:
return readString();
case VAL_INTEGER:
return readInt();
case VAL_MAP:
return readHashMap(loader);
case VAL_PARCELABLE:
return readParcelable(loader);
case VAL_SHORT:
return (short) readInt();
case VAL_LONG:
return readLong();
case VAL_FLOAT:
return readFloat();
case VAL_DOUBLE:
return readDouble();
case VAL_BOOLEAN:
return readInt() == 1;
case VAL_CHARSEQUENCE:
return readCharSequence();
case VAL_LIST:
return readArrayList(loader);
case VAL_BOOLEANARRAY:
return createBooleanArray();
case VAL_BYTEARRAY:
return createByteArray();
case VAL_STRINGARRAY:
return readStringArray();
case VAL_CHARSEQUENCEARRAY:
return readCharSequenceArray();
case VAL_IBINDER:
return readStrongBinder();
case VAL_OBJECTARRAY:
return readArray(loader);
case VAL_INTARRAY:
return createIntArray();
case VAL_LONGARRAY:
return createLongArray();
case VAL_BYTE:
return readByte();
case VAL_SERIALIZABLE:
return readSerializable(loader);
case VAL_PARCELABLEARRAY:
return readParcelableArray(loader);
case VAL_SPARSEARRAY:
return readSparseArray(loader);
case VAL_SPARSEBOOLEANARRAY:
return readSparseBooleanArray();
case VAL_BUNDLE:
return readBundle(loader); // loading will be deferred
case VAL_PERSISTABLEBUNDLE:
return readPersistableBundle(loader);
case VAL_SIZE:
return readSize();
case VAL_SIZEF:
return readSizeF();
default:
int off = dataPosition() - 4;
throw new RuntimeException(
"Parcel " + this + ": Unmarshalling unknown type code " + type + " at offset " + off);
}
|
public final void | recycle()Put a Parcel object back into the pool. You must not touch
the object after this call.
if (DEBUG_RECYCLE) mStack = null;
freeBuffer();
final Parcel[] pool;
if (mOwnsNativeParcelObject) {
pool = sOwnedPool;
} else {
mNativePtr = 0;
pool = sHolderPool;
}
synchronized (pool) {
for (int i=0; i<POOL_SIZE; i++) {
if (pool[i] == null) {
pool[i] = this;
return;
}
}
}
|
public final void | restoreAllowFds(boolean lastValue)
nativeRestoreAllowFds(mNativePtr, lastValue);
|
public final void | setDataCapacity(int size)Change the capacity (current available space) of the parcel.
nativeSetDataCapacity(mNativePtr, size);
|
public final void | setDataPosition(int pos)Move the current read/write position in the parcel.
nativeSetDataPosition(mNativePtr, pos);
|
public final void | setDataSize(int size)Change the amount of data in the parcel. Can be either smaller or
larger than the current size. If larger than the current capacity,
more memory will be allocated.
nativeSetDataSize(mNativePtr, size);
|
public final void | unmarshall(byte[] data, int offset, int length)Set the bytes in data to be the raw bytes of this Parcel.
nativeUnmarshall(mNativePtr, data, offset, length);
|
public final void | writeArray(java.lang.Object[] val)Flatten an Object array into the parcel at the current dataPosition(),
growing dataCapacity() if needed. The array values are written using
{@link #writeValue} and must follow the specification there.
if (val == null) {
writeInt(-1);
return;
}
int N = val.length;
int i=0;
writeInt(N);
while (i < N) {
writeValue(val[i]);
i++;
}
|
public void | writeArrayMap(android.util.ArrayMap val)
writeArrayMapInternal(val);
|
void | writeArrayMapInternal(android.util.ArrayMap val)Flatten an ArrayMap into the parcel at the current dataPosition(),
growing dataCapacity() if needed. The Map keys must be String objects.
if (val == null) {
writeInt(-1);
return;
}
final int N = val.size();
writeInt(N);
if (DEBUG_ARRAY_MAP) {
RuntimeException here = new RuntimeException("here");
here.fillInStackTrace();
Log.d(TAG, "Writing " + N + " ArrayMap entries", here);
}
int startPos;
for (int i=0; i<N; i++) {
if (DEBUG_ARRAY_MAP) startPos = dataPosition();
writeString(val.keyAt(i));
writeValue(val.valueAt(i));
if (DEBUG_ARRAY_MAP) Log.d(TAG, " Write #" + i + " "
+ (dataPosition()-startPos) + " bytes: key=0x"
+ Integer.toHexString(val.keyAt(i) != null ? val.keyAt(i).hashCode() : 0)
+ " " + val.keyAt(i));
}
|
public final void | writeBinderArray(IBinder[] val)
if (val != null) {
int N = val.length;
writeInt(N);
for (int i=0; i<N; i++) {
writeStrongBinder(val[i]);
}
} else {
writeInt(-1);
}
|
public final void | writeBinderList(java.util.List val)Flatten a List containing IBinder objects into the parcel, at
the current dataPosition() and growing dataCapacity() if needed. They
can later be retrieved with {@link #createBinderArrayList} or
{@link #readBinderList}.
if (val == null) {
writeInt(-1);
return;
}
int N = val.size();
int i=0;
writeInt(N);
while (i < N) {
writeStrongBinder(val.get(i));
i++;
}
|
public final void | writeBlob(byte[] b)Write a blob of data into the parcel at the current {@link #dataPosition},
growing {@link #dataCapacity} if needed.
nativeWriteBlob(mNativePtr, b, 0, (b != null) ? b.length : 0);
|
public final void | writeBooleanArray(boolean[] val)
if (val != null) {
int N = val.length;
writeInt(N);
for (int i=0; i<N; i++) {
writeInt(val[i] ? 1 : 0);
}
} else {
writeInt(-1);
}
|
public final void | writeBundle(Bundle val)Flatten a Bundle into the parcel at the current dataPosition(),
growing dataCapacity() if needed.
if (val == null) {
writeInt(-1);
return;
}
val.writeToParcel(this, 0);
|
public final void | writeByte(byte val)Write a byte value into the parcel at the current dataPosition(),
growing dataCapacity() if needed.
writeInt(val);
|
public final void | writeByteArray(byte[] b)Write a byte array into the parcel at the current {@link #dataPosition},
growing {@link #dataCapacity} if needed.
writeByteArray(b, 0, (b != null) ? b.length : 0);
|
public final void | writeByteArray(byte[] b, int offset, int len)Write a byte array into the parcel at the current {@link #dataPosition},
growing {@link #dataCapacity} if needed.
if (b == null) {
writeInt(-1);
return;
}
Arrays.checkOffsetAndCount(b.length, offset, len);
nativeWriteByteArray(mNativePtr, b, offset, len);
|
public final void | writeCharArray(char[] val)
if (val != null) {
int N = val.length;
writeInt(N);
for (int i=0; i<N; i++) {
writeInt((int)val[i]);
}
} else {
writeInt(-1);
}
|
public final void | writeCharSequence(java.lang.CharSequence val)Write a CharSequence value into the parcel at the current dataPosition(),
growing dataCapacity() if needed.
TextUtils.writeToParcel(val, this, 0);
|
public final void | writeCharSequenceArray(java.lang.CharSequence[] val)
if (val != null) {
int N = val.length;
writeInt(N);
for (int i=0; i<N; i++) {
writeCharSequence(val[i]);
}
} else {
writeInt(-1);
}
|
public final void | writeDouble(double val)Write a double precision floating point value into the parcel at the
current dataPosition(), growing dataCapacity() if needed.
nativeWriteDouble(mNativePtr, val);
|
public final void | writeDoubleArray(double[] val)
if (val != null) {
int N = val.length;
writeInt(N);
for (int i=0; i<N; i++) {
writeDouble(val[i]);
}
} else {
writeInt(-1);
}
|
public final void | writeException(java.lang.Exception e)Special function for writing an exception result at the header of
a parcel, to be used when returning an exception from a transaction.
Note that this currently only supports a few exception types; any other
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).
The supported exception types are:
- {@link BadParcelableException}
- {@link IllegalArgumentException}
- {@link IllegalStateException}
- {@link NullPointerException}
- {@link SecurityException}
- {@link NetworkOnMainThreadException}
int code = 0;
if (e instanceof SecurityException) {
code = EX_SECURITY;
} else if (e instanceof BadParcelableException) {
code = EX_BAD_PARCELABLE;
} else if (e instanceof IllegalArgumentException) {
code = EX_ILLEGAL_ARGUMENT;
} else if (e instanceof NullPointerException) {
code = EX_NULL_POINTER;
} else if (e instanceof IllegalStateException) {
code = EX_ILLEGAL_STATE;
} else if (e instanceof NetworkOnMainThreadException) {
code = EX_NETWORK_MAIN_THREAD;
} else if (e instanceof UnsupportedOperationException) {
code = EX_UNSUPPORTED_OPERATION;
}
writeInt(code);
StrictMode.clearGatheredViolations();
if (code == 0) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new RuntimeException(e);
}
writeString(e.getMessage());
|
public final void | writeFileDescriptor(java.io.FileDescriptor val)Write a FileDescriptor into the parcel at the current dataPosition(),
growing dataCapacity() if needed.
The file descriptor will not be closed, which may
result in file descriptor leaks when objects are returned from Binder
calls. Use {@link ParcelFileDescriptor#writeToParcel} instead, which
accepts contextual flags and will close the original file descriptor
if {@link Parcelable#PARCELABLE_WRITE_RETURN_VALUE} is set.
nativeWriteFileDescriptor(mNativePtr, val);
|
public final void | writeFloat(float val)Write a floating point value into the parcel at the current
dataPosition(), growing dataCapacity() if needed.
nativeWriteFloat(mNativePtr, val);
|
public final void | writeFloatArray(float[] val)
if (val != null) {
int N = val.length;
writeInt(N);
for (int i=0; i<N; i++) {
writeFloat(val[i]);
}
} else {
writeInt(-1);
}
|
public final void | writeInt(int val)Write an integer value into the parcel at the current dataPosition(),
growing dataCapacity() if needed.
nativeWriteInt(mNativePtr, val);
|
public final void | writeIntArray(int[] val)
if (val != null) {
int N = val.length;
writeInt(N);
for (int i=0; i<N; i++) {
writeInt(val[i]);
}
} else {
writeInt(-1);
}
|
public final void | writeInterfaceToken(java.lang.String interfaceName)Store or read an IBinder interface token in the parcel at the current
{@link #dataPosition}. This is used to validate that the marshalled
transaction is intended for the target interface.
nativeWriteInterfaceToken(mNativePtr, interfaceName);
|
public final void | writeList(java.util.List val)Flatten a List into the parcel at the current dataPosition(), growing
dataCapacity() if needed. The List values are written using
{@link #writeValue} and must follow the specification there.
if (val == null) {
writeInt(-1);
return;
}
int N = val.size();
int i=0;
writeInt(N);
while (i < N) {
writeValue(val.get(i));
i++;
}
|
public final void | writeLong(long val)Write a long integer value into the parcel at the current dataPosition(),
growing dataCapacity() if needed.
nativeWriteLong(mNativePtr, val);
|
public final void | writeLongArray(long[] val)
if (val != null) {
int N = val.length;
writeInt(N);
for (int i=0; i<N; i++) {
writeLong(val[i]);
}
} else {
writeInt(-1);
}
|
public final void | writeMap(java.util.Map val)Please use {@link #writeBundle} instead. Flattens a Map into the parcel
at the current dataPosition(),
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.
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.
writeMapInternal((Map<String, Object>) val);
|
void | writeMapInternal(java.util.Map val)Flatten a Map into the parcel at the current dataPosition(),
growing dataCapacity() if needed. The Map keys must be String objects.
if (val == null) {
writeInt(-1);
return;
}
Set<Map.Entry<String,Object>> entries = val.entrySet();
writeInt(entries.size());
for (Map.Entry<String,Object> e : entries) {
writeValue(e.getKey());
writeValue(e.getValue());
}
|
public final void | writeNoException()Special function for writing information at the front of the Parcel
indicating that no exception occurred.
// Despite the name of this function ("write no exception"),
// it should instead be thought of as "write the RPC response
// header", but because this function name is written out by
// the AIDL compiler, we're not going to rename it.
//
// The response header, in the non-exception case (see also
// writeException above, also called by the AIDL compiler), is
// either a 0 (the default case), or EX_HAS_REPLY_HEADER if
// StrictMode has gathered up violations that have occurred
// during a Binder call, in which case we write out the number
// of violations and their details, serialized, before the
// actual RPC respons data. The receiving end of this is
// readException(), below.
if (StrictMode.hasGatheredViolations()) {
writeInt(EX_HAS_REPLY_HEADER);
final int sizePosition = dataPosition();
writeInt(0); // total size of fat header, to be filled in later
StrictMode.writeGatheredViolationsToParcel(this);
final int payloadPosition = dataPosition();
setDataPosition(sizePosition);
writeInt(payloadPosition - sizePosition); // header size
setDataPosition(payloadPosition);
} else {
writeInt(0);
}
|
public final void | writeParcelable(Parcelable p, int parcelableFlags)Flatten the name of the class of the Parcelable and its contents
into the parcel.
if (p == null) {
writeString(null);
return;
}
String name = p.getClass().getName();
writeString(name);
p.writeToParcel(this, parcelableFlags);
|
public final void | writeParcelableArray(T[] value, int parcelableFlags)Write a heterogeneous array of Parcelable objects into the Parcel.
Each object in the array is written along with its class name, so
that the correct class can later be instantiated. As a result, this
has significantly more overhead than {@link #writeTypedArray}, but will
correctly handle an array containing more than one type of object.
if (value != null) {
int N = value.length;
writeInt(N);
for (int i=0; i<N; i++) {
writeParcelable(value[i], parcelableFlags);
}
} else {
writeInt(-1);
}
|
public final void | writeParcelableCreator(Parcelable p)
String name = p.getClass().getName();
writeString(name);
|
public final void | writePersistableBundle(PersistableBundle val)Flatten a PersistableBundle into the parcel at the current dataPosition(),
growing dataCapacity() if needed.
if (val == null) {
writeInt(-1);
return;
}
val.writeToParcel(this, 0);
|
public final void | writeSerializable(java.io.Serializable s)Write a generic serializable object in to a Parcel. It is strongly
recommended that this method be avoided, since the serialization
overhead is extremely large, and this approach will be much slower than
using the other approaches to writing data in to a Parcel.
if (s == null) {
writeString(null);
return;
}
String name = s.getClass().getName();
writeString(name);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(s);
oos.close();
writeByteArray(baos.toByteArray());
} catch (IOException ioe) {
throw new RuntimeException("Parcelable encountered " +
"IOException writing serializable object (name = " + name +
")", ioe);
}
|
public final void | writeSize(android.util.Size val)Flatten a Size into the parcel at the current dataPosition(),
growing dataCapacity() if needed.
writeInt(val.getWidth());
writeInt(val.getHeight());
|
public final void | writeSizeF(android.util.SizeF val)Flatten a SizeF into the parcel at the current dataPosition(),
growing dataCapacity() if needed.
writeFloat(val.getWidth());
writeFloat(val.getHeight());
|
public final void | writeSparseArray(android.util.SparseArray val)Flatten a generic SparseArray into the parcel at the current
dataPosition(), growing dataCapacity() if needed. The SparseArray
values are written using {@link #writeValue} and must follow the
specification there.
if (val == null) {
writeInt(-1);
return;
}
int N = val.size();
writeInt(N);
int i=0;
while (i < N) {
writeInt(val.keyAt(i));
writeValue(val.valueAt(i));
i++;
}
|
public final void | writeSparseBooleanArray(android.util.SparseBooleanArray val)
if (val == null) {
writeInt(-1);
return;
}
int N = val.size();
writeInt(N);
int i=0;
while (i < N) {
writeInt(val.keyAt(i));
writeByte((byte)(val.valueAt(i) ? 1 : 0));
i++;
}
|
public final void | writeString(java.lang.String val)Write a string value into the parcel at the current dataPosition(),
growing dataCapacity() if needed.
nativeWriteString(mNativePtr, val);
|
public final void | writeStringArray(java.lang.String[] val)
if (val != null) {
int N = val.length;
writeInt(N);
for (int i=0; i<N; i++) {
writeString(val[i]);
}
} else {
writeInt(-1);
}
|
public final void | writeStringList(java.util.List val)Flatten a List containing String objects into the parcel, at
the current dataPosition() and growing dataCapacity() if needed. They
can later be retrieved with {@link #createStringArrayList} or
{@link #readStringList}.
if (val == null) {
writeInt(-1);
return;
}
int N = val.size();
int i=0;
writeInt(N);
while (i < N) {
writeString(val.get(i));
i++;
}
|
public final void | writeStrongBinder(IBinder val)Write an object into the parcel at the current dataPosition(),
growing dataCapacity() if needed.
nativeWriteStrongBinder(mNativePtr, val);
|
public final void | writeStrongInterface(IInterface val)Write an object into the parcel at the current dataPosition(),
growing dataCapacity() if needed.
writeStrongBinder(val == null ? null : val.asBinder());
|
public final void | writeTypedArray(T[] val, int parcelableFlags)Flatten a heterogeneous array containing a particular object type into
the parcel, at
the current dataPosition() and growing dataCapacity() if needed. The
type of the objects in the array must be one that implements Parcelable.
Unlike the {@link #writeParcelableArray} method, however, only the
raw data of the objects is written and not their type, so you must use
{@link #readTypedArray} with the correct corresponding
{@link Parcelable.Creator} implementation to unmarshall them.
if (val != null) {
int N = val.length;
writeInt(N);
for (int i=0; i<N; i++) {
T item = val[i];
if (item != null) {
writeInt(1);
item.writeToParcel(this, parcelableFlags);
} else {
writeInt(0);
}
}
} else {
writeInt(-1);
}
|
public final void | writeTypedList(java.util.List val)Flatten a List containing a particular object type into the parcel, at
the current dataPosition() and growing dataCapacity() if needed. The
type of the objects in the list must be one that implements Parcelable.
Unlike the generic writeList() method, however, only the raw data of the
objects is written and not their type, so you must use the corresponding
readTypedList() to unmarshall them.
if (val == null) {
writeInt(-1);
return;
}
int N = val.size();
int i=0;
writeInt(N);
while (i < N) {
T item = val.get(i);
if (item != null) {
writeInt(1);
item.writeToParcel(this, 0);
} else {
writeInt(0);
}
i++;
}
|
public final void | writeValue(java.lang.Object v)Flatten a generic object in to a parcel. The given Object value may
currently be one of the following types:
- null
- String
- Byte
- Short
- Integer
- Long
- Float
- Double
- Boolean
- String[]
- boolean[]
- byte[]
- int[]
- long[]
- Object[] (supporting objects of the same type defined here).
- {@link Bundle}
- Map (as supported by {@link #writeMap}).
- Any object that implements the {@link Parcelable} protocol.
- Parcelable[]
- CharSequence (as supported by {@link TextUtils#writeToParcel}).
- List (as supported by {@link #writeList}).
- {@link SparseArray} (as supported by {@link #writeSparseArray(SparseArray)}).
- {@link IBinder}
- Any object that implements Serializable (but see
{@link #writeSerializable} for caveats). Note that all of the
previous types have relatively efficient implementations for
writing to a Parcel; having to rely on the generic serialization
approach is much less efficient and should be avoided whenever
possible.
{@link Parcelable} objects are written with
{@link Parcelable#writeToParcel} using contextual flags of 0. When
serializing objects containing {@link ParcelFileDescriptor}s,
this may result in file descriptor leaks when they are returned from
Binder calls (where {@link Parcelable#PARCELABLE_WRITE_RETURN_VALUE}
should be used).
if (v == null) {
writeInt(VAL_NULL);
} else if (v instanceof String) {
writeInt(VAL_STRING);
writeString((String) v);
} else if (v instanceof Integer) {
writeInt(VAL_INTEGER);
writeInt((Integer) v);
} else if (v instanceof Map) {
writeInt(VAL_MAP);
writeMap((Map) v);
} else if (v instanceof Bundle) {
// Must be before Parcelable
writeInt(VAL_BUNDLE);
writeBundle((Bundle) v);
} else if (v instanceof Parcelable) {
writeInt(VAL_PARCELABLE);
writeParcelable((Parcelable) v, 0);
} else if (v instanceof Short) {
writeInt(VAL_SHORT);
writeInt(((Short) v).intValue());
} else if (v instanceof Long) {
writeInt(VAL_LONG);
writeLong((Long) v);
} else if (v instanceof Float) {
writeInt(VAL_FLOAT);
writeFloat((Float) v);
} else if (v instanceof Double) {
writeInt(VAL_DOUBLE);
writeDouble((Double) v);
} else if (v instanceof Boolean) {
writeInt(VAL_BOOLEAN);
writeInt((Boolean) v ? 1 : 0);
} else if (v instanceof CharSequence) {
// Must be after String
writeInt(VAL_CHARSEQUENCE);
writeCharSequence((CharSequence) v);
} else if (v instanceof List) {
writeInt(VAL_LIST);
writeList((List) v);
} else if (v instanceof SparseArray) {
writeInt(VAL_SPARSEARRAY);
writeSparseArray((SparseArray) v);
} else if (v instanceof boolean[]) {
writeInt(VAL_BOOLEANARRAY);
writeBooleanArray((boolean[]) v);
} else if (v instanceof byte[]) {
writeInt(VAL_BYTEARRAY);
writeByteArray((byte[]) v);
} else if (v instanceof String[]) {
writeInt(VAL_STRINGARRAY);
writeStringArray((String[]) v);
} else if (v instanceof CharSequence[]) {
// Must be after String[] and before Object[]
writeInt(VAL_CHARSEQUENCEARRAY);
writeCharSequenceArray((CharSequence[]) v);
} else if (v instanceof IBinder) {
writeInt(VAL_IBINDER);
writeStrongBinder((IBinder) v);
} else if (v instanceof Parcelable[]) {
writeInt(VAL_PARCELABLEARRAY);
writeParcelableArray((Parcelable[]) v, 0);
} else if (v instanceof int[]) {
writeInt(VAL_INTARRAY);
writeIntArray((int[]) v);
} else if (v instanceof long[]) {
writeInt(VAL_LONGARRAY);
writeLongArray((long[]) v);
} else if (v instanceof Byte) {
writeInt(VAL_BYTE);
writeInt((Byte) v);
} else if (v instanceof PersistableBundle) {
writeInt(VAL_PERSISTABLEBUNDLE);
writePersistableBundle((PersistableBundle) v);
} else if (v instanceof Size) {
writeInt(VAL_SIZE);
writeSize((Size) v);
} else if (v instanceof SizeF) {
writeInt(VAL_SIZEF);
writeSizeF((SizeF) v);
} else {
Class<?> clazz = v.getClass();
if (clazz.isArray() && clazz.getComponentType() == Object.class) {
// Only pure Object[] are written here, Other arrays of non-primitive types are
// handled by serialization as this does not record the component type.
writeInt(VAL_OBJECTARRAY);
writeArray((Object[]) v);
} else if (v instanceof Serializable) {
// Must be last
writeInt(VAL_SERIALIZABLE);
writeSerializable((Serializable) v);
} else {
throw new RuntimeException("Parcel: unable to marshal value " + v);
}
}
|