summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2013-10-03 17:23:04 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-10-03 17:23:04 +0000
commitd585f95406f8b12e36ca436faea7113ecd8704fd (patch)
treea41924b2af3007f07d8f9173e9bf8a95bb2fa730
parent0a660528374f0cf4fc24eb610ea048c99cbd27a1 (diff)
parent4a7d824c3b41eafc4ff91d3253ff8a9ebd60a454 (diff)
downloadframeworks_base-d585f95406f8b12e36ca436faea7113ecd8704fd.zip
frameworks_base-d585f95406f8b12e36ca436faea7113ecd8704fd.tar.gz
frameworks_base-d585f95406f8b12e36ca436faea7113ecd8704fd.tar.bz2
Merge "Fix issue #10921903: CTS: android.os.cts.ParcelTest#testReadBundle..." into klp-dev
-rw-r--r--core/java/android/os/Bundle.java49
-rw-r--r--core/java/android/os/Parcel.java1
-rw-r--r--core/java/android/util/ArrayMap.java1
3 files changed, 26 insertions, 25 deletions
diff --git a/core/java/android/os/Bundle.java b/core/java/android/os/Bundle.java
index f47ac4e..5a919fb 100644
--- a/core/java/android/os/Bundle.java
+++ b/core/java/android/os/Bundle.java
@@ -30,7 +30,8 @@ import java.util.Set;
*
*/
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'
@@ -157,7 +158,7 @@ public final class Bundle implements Parcelable, Cloneable {
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;
@@ -210,10 +211,14 @@ public final class Bundle implements Parcelable, Cloneable {
*/
/* 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;
}
@@ -226,6 +231,8 @@ public final class Bundle implements Parcelable, Cloneable {
mParcelledData.readArrayMapInternal(mMap, N, mClassLoader);
mParcelledData.recycle();
mParcelledData = null;
+ if (DEBUG) Log.d(TAG, "unparcel " + Integer.toHexString(System.identityHashCode(this))
+ + " final map: " + mMap);
}
/**
@@ -794,6 +801,8 @@ public final class Bundle implements Parcelable, Cloneable {
*/
public boolean getBoolean(String key) {
unparcel();
+ if (DEBUG) Log.d(TAG, "Getting boolean in "
+ + Integer.toHexString(System.identityHashCode(this)));
return getBoolean(key, false);
}
@@ -810,8 +819,8 @@ public final class Bundle implements Parcelable, Cloneable {
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,
@@ -1648,18 +1657,19 @@ public final class Bundle implements Parcelable, Cloneable {
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);
@@ -1694,24 +1704,13 @@ public final class Bundle implements Parcelable, Cloneable {
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
diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java
index 5f3a81c..02b1998 100644
--- a/core/java/android/os/Parcel.java
+++ b/core/java/android/os/Parcel.java
@@ -1610,6 +1610,7 @@ public final class Parcel {
public final Bundle readBundle(ClassLoader loader) {
int length = readInt();
if (length < 0) {
+ if (Bundle.DEBUG) Log.d(TAG, "null bundle: length=" + length);
return null;
}
diff --git a/core/java/android/util/ArrayMap.java b/core/java/android/util/ArrayMap.java
index fa534cc..df1d4cd 100644
--- a/core/java/android/util/ArrayMap.java
+++ b/core/java/android/util/ArrayMap.java
@@ -292,6 +292,7 @@ public final class ArrayMap<K, V> implements Map<K, V> {
for (int i=0; i<N; i++) {
array[i] = null;
}
+ mSize = 0;
}
}