Merge "Maybe fix issue #28457907: Pebble app crash + reboot" into nyc-dev am: 6eb119c7cb

am: 5081e36897

* commit '5081e368978e00353c5968f0f7656ca28e963b4a':
  Maybe fix issue #28457907: Pebble app crash + reboot

Change-Id: I0db52017c4a351341b0823381e7b85b0c641a16d
This commit is contained in:
Dianne Hackborn
2016-05-04 22:57:53 +00:00
committed by android-build-merger

View File

@@ -169,7 +169,7 @@ public class BaseBundle {
} }
if (b.mMap != null) { if (b.mMap != null) {
mMap = new ArrayMap<String, Object>(b.mMap); mMap = new ArrayMap<>(b.mMap);
} else { } else {
mMap = null; mMap = null;
} }
@@ -226,8 +226,11 @@ public class BaseBundle {
* using the currently assigned class loader. * using the currently assigned class loader.
*/ */
/* package */ synchronized void unparcel() { /* package */ synchronized void unparcel() {
if (mParcelledData == null) { synchronized (this) {
if (DEBUG) Log.d(TAG, "unparcel " + Integer.toHexString(System.identityHashCode(this)) final Parcel parcelledData = mParcelledData;
if (parcelledData == null) {
if (DEBUG) Log.d(TAG, "unparcel "
+ Integer.toHexString(System.identityHashCode(this))
+ ": no parcelled data"); + ": no parcelled data");
return; return;
} }
@@ -238,10 +241,10 @@ public class BaseBundle {
} }
if (isEmptyParcel()) { if (isEmptyParcel()) {
if (DEBUG) Log.d(TAG, "unparcel " + Integer.toHexString(System.identityHashCode(this)) if (DEBUG) Log.d(TAG, "unparcel "
+ ": empty"); + Integer.toHexString(System.identityHashCode(this)) + ": empty");
if (mMap == null) { if (mMap == null) {
mMap = new ArrayMap<String, Object>(1); mMap = new ArrayMap<>(1);
} else { } else {
mMap.erase(); mMap.erase();
} }
@@ -249,34 +252,37 @@ public class BaseBundle {
return; return;
} }
int N = mParcelledData.readInt(); int N = parcelledData.readInt();
if (DEBUG) Log.d(TAG, "unparcel " + Integer.toHexString(System.identityHashCode(this)) if (DEBUG) Log.d(TAG, "unparcel " + Integer.toHexString(System.identityHashCode(this))
+ ": reading " + N + " maps"); + ": reading " + N + " maps");
if (N < 0) { if (N < 0) {
return; return;
} }
if (mMap == null) { ArrayMap<String, Object> map = mMap;
mMap = new ArrayMap<String, Object>(N); if (map == null) {
map = new ArrayMap<>(N);
} else { } else {
mMap.erase(); map.erase();
mMap.ensureCapacity(N); map.ensureCapacity(N);
} }
try { try {
mParcelledData.readArrayMapInternal(mMap, N, mClassLoader); parcelledData.readArrayMapInternal(map, N, mClassLoader);
} catch (BadParcelableException e) { } catch (BadParcelableException e) {
if (sShouldDefuse) { if (sShouldDefuse) {
Log.w(TAG, "Failed to parse Bundle, but defusing quietly", e); Log.w(TAG, "Failed to parse Bundle, but defusing quietly", e);
mMap.erase(); map.erase();
} else { } else {
throw e; throw e;
} }
} finally { } finally {
mParcelledData.recycle(); mMap = map;
parcelledData.recycle();
mParcelledData = null; mParcelledData = null;
} }
if (DEBUG) Log.d(TAG, "unparcel " + Integer.toHexString(System.identityHashCode(this)) if (DEBUG) Log.d(TAG, "unparcel " + Integer.toHexString(System.identityHashCode(this))
+ " final map: " + mMap); + " final map: " + mMap);
} }
}
/** /**
* @hide * @hide
@@ -1375,14 +1381,18 @@ public class BaseBundle {
void writeToParcelInner(Parcel parcel, int flags) { void writeToParcelInner(Parcel parcel, int flags) {
// Keep implementation in sync with writeToParcel() in // Keep implementation in sync with writeToParcel() in
// frameworks/native/libs/binder/PersistableBundle.cpp. // frameworks/native/libs/binder/PersistableBundle.cpp.
if (mParcelledData != null) { final Parcel parcelledData;
synchronized (this) {
parcelledData = mParcelledData;
}
if (parcelledData != null) {
if (isEmptyParcel()) { if (isEmptyParcel()) {
parcel.writeInt(0); parcel.writeInt(0);
} else { } else {
int length = mParcelledData.dataSize(); int length = parcelledData.dataSize();
parcel.writeInt(length); parcel.writeInt(length);
parcel.writeInt(BUNDLE_MAGIC); parcel.writeInt(BUNDLE_MAGIC);
parcel.appendFrom(mParcelledData, 0, length); parcel.appendFrom(parcelledData, 0, length);
} }
} else { } else {
// Special case for empty bundles. // Special case for empty bundles.