*
*/
public final class Bundle implements Parcelable, Cloneable {
- private static final String LOG_TAG = "Bundle";
+ private static final String TAG = "Bundle";
+ static final boolean DEBUG = false;
public static final Bundle EMPTY;
static final int BUNDLE_MAGIC = 0x4C444E42; // 'B' 'N' 'D' 'L'
unparcel();
int size = mMap.size();
if (size > 1) {
- Log.w(LOG_TAG, "getPairValue() used on Bundle with multiple pairs.");
+ Log.w(TAG, "getPairValue() used on Bundle with multiple pairs.");
}
if (size == 0) {
return null;
*/
/* package */ synchronized void unparcel() {
if (mParcelledData == null) {
+ if (DEBUG) Log.d(TAG, "unparcel " + Integer.toHexString(System.identityHashCode(this))
+ + ": no parcelled data");
return;
}
int N = mParcelledData.readInt();
+ if (DEBUG) Log.d(TAG, "unparcel " + Integer.toHexString(System.identityHashCode(this))
+ + ": reading " + N + " maps");
if (N < 0) {
return;
}
mParcelledData.readArrayMapInternal(mMap, N, mClassLoader);
mParcelledData.recycle();
mParcelledData = null;
+ if (DEBUG) Log.d(TAG, "unparcel " + Integer.toHexString(System.identityHashCode(this))
+ + " final map: " + mMap);
}
/**
*/
public boolean getBoolean(String key) {
unparcel();
+ if (DEBUG) Log.d(TAG, "Getting boolean in "
+ + Integer.toHexString(System.identityHashCode(this)));
return getBoolean(key, false);
}
sb.append(". The default value ");
sb.append(defaultValue);
sb.append(" was returned.");
- Log.w(LOG_TAG, sb.toString());
- Log.w(LOG_TAG, "Attempt to cast generated internal exception:", e);
+ Log.w(TAG, sb.toString());
+ Log.w(TAG, "Attempt to cast generated internal exception:", e);
}
private void typeWarning(String key, Object value, String className,
parcel.writeInt(BUNDLE_MAGIC);
parcel.appendFrom(mParcelledData, 0, length);
} else {
+ int lengthPos = parcel.dataPosition();
parcel.writeInt(-1); // dummy, will hold length
parcel.writeInt(BUNDLE_MAGIC);
- int oldPos = parcel.dataPosition();
+ int startPos = parcel.dataPosition();
parcel.writeArrayMapInternal(mMap);
- int newPos = parcel.dataPosition();
+ int endPos = parcel.dataPosition();
// Backpatch length
- parcel.setDataPosition(oldPos - 8);
- int length = newPos - oldPos;
+ parcel.setDataPosition(lengthPos);
+ int length = endPos - startPos;
parcel.writeInt(length);
- parcel.setDataPosition(newPos);
+ parcel.setDataPosition(endPos);
}
} finally {
parcel.restoreAllowFds(oldAllowFds);
Parcel p = Parcel.obtain();
p.setDataPosition(0);
p.appendFrom(parcel, offset, length);
+ if (DEBUG) Log.d(TAG, "Retrieving " + Integer.toHexString(System.identityHashCode(this))
+ + ": " + length + " bundle bytes starting at " + offset);
p.setDataPosition(0);
- if (mMap != null) {
- // It is not allowed to have a Bundle with both a map and a parcel, so if we
- // already have a map then we need to immediately unparcel into it. This also
- // lets us know we need to go through the slow path of unparceling, since the
- // map may already contains some data so the two need to be merged.
- if (mFdsKnown) {
- mHasFds |= p.hasFileDescriptors();
- }
- int N = p.readInt();
- p.readArrayMapSafelyInternal(mMap, N, mClassLoader);
- p.recycle();
- } else {
- mParcelledData = p;
- mHasFds = p.hasFileDescriptors();
- mFdsKnown = true;
- }
+ mParcelledData = p;
+ mHasFds = p.hasFileDescriptors();
+ mFdsKnown = true;
}
@Override