Merge "Fix issue #11290095: Parcel change causing crashing in KLP..." into klp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
df033aed9d
@@ -35,10 +35,12 @@ public final class Bundle implements Parcelable, Cloneable {
|
|||||||
public static final Bundle EMPTY;
|
public static final Bundle EMPTY;
|
||||||
|
|
||||||
static final int BUNDLE_MAGIC = 0x4C444E42; // 'B' 'N' 'D' 'L'
|
static final int BUNDLE_MAGIC = 0x4C444E42; // 'B' 'N' 'D' 'L'
|
||||||
|
static final Parcel EMPTY_PARCEL;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
EMPTY = new Bundle();
|
EMPTY = new Bundle();
|
||||||
EMPTY.mMap = ArrayMap.EMPTY;
|
EMPTY.mMap = ArrayMap.EMPTY;
|
||||||
|
EMPTY_PARCEL = Parcel.obtain();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invariant - exactly one of mMap / mParcelledData will be null
|
// Invariant - exactly one of mMap / mParcelledData will be null
|
||||||
@@ -115,9 +117,13 @@ public final class Bundle implements Parcelable, Cloneable {
|
|||||||
*/
|
*/
|
||||||
public Bundle(Bundle b) {
|
public Bundle(Bundle b) {
|
||||||
if (b.mParcelledData != null) {
|
if (b.mParcelledData != null) {
|
||||||
mParcelledData = Parcel.obtain();
|
if (b.mParcelledData == EMPTY_PARCEL) {
|
||||||
mParcelledData.appendFrom(b.mParcelledData, 0, b.mParcelledData.dataSize());
|
mParcelledData = EMPTY_PARCEL;
|
||||||
mParcelledData.setDataPosition(0);
|
} else {
|
||||||
|
mParcelledData = Parcel.obtain();
|
||||||
|
mParcelledData.appendFrom(b.mParcelledData, 0, b.mParcelledData.dataSize());
|
||||||
|
mParcelledData.setDataPosition(0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mParcelledData = null;
|
mParcelledData = null;
|
||||||
}
|
}
|
||||||
@@ -216,6 +222,18 @@ public final class Bundle implements Parcelable, Cloneable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mParcelledData == EMPTY_PARCEL) {
|
||||||
|
if (DEBUG) Log.d(TAG, "unparcel " + Integer.toHexString(System.identityHashCode(this))
|
||||||
|
+ ": empty");
|
||||||
|
if (mMap == null) {
|
||||||
|
mMap = new ArrayMap<String, Object>(1);
|
||||||
|
} else {
|
||||||
|
mMap.erase();
|
||||||
|
}
|
||||||
|
mParcelledData = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int N = mParcelledData.readInt();
|
int N = mParcelledData.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");
|
||||||
@@ -1652,11 +1670,20 @@ public final class Bundle implements Parcelable, Cloneable {
|
|||||||
final boolean oldAllowFds = parcel.pushAllowFds(mAllowFds);
|
final boolean oldAllowFds = parcel.pushAllowFds(mAllowFds);
|
||||||
try {
|
try {
|
||||||
if (mParcelledData != null) {
|
if (mParcelledData != null) {
|
||||||
int length = mParcelledData.dataSize();
|
if (mParcelledData == EMPTY_PARCEL) {
|
||||||
parcel.writeInt(length);
|
parcel.writeInt(0);
|
||||||
parcel.writeInt(BUNDLE_MAGIC);
|
} else {
|
||||||
parcel.appendFrom(mParcelledData, 0, length);
|
int length = mParcelledData.dataSize();
|
||||||
|
parcel.writeInt(length);
|
||||||
|
parcel.writeInt(BUNDLE_MAGIC);
|
||||||
|
parcel.appendFrom(mParcelledData, 0, length);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Special case for empty bundles.
|
||||||
|
if (mMap == null || mMap.size() <= 0) {
|
||||||
|
parcel.writeInt(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
int lengthPos = parcel.dataPosition();
|
int lengthPos = parcel.dataPosition();
|
||||||
parcel.writeInt(-1); // dummy, will hold length
|
parcel.writeInt(-1); // dummy, will hold length
|
||||||
parcel.writeInt(BUNDLE_MAGIC);
|
parcel.writeInt(BUNDLE_MAGIC);
|
||||||
@@ -1690,6 +1717,13 @@ public final class Bundle implements Parcelable, Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void readFromParcelInner(Parcel parcel, int length) {
|
void readFromParcelInner(Parcel parcel, int length) {
|
||||||
|
if (length == 0) {
|
||||||
|
// Empty Bundle or end of data.
|
||||||
|
mParcelledData = EMPTY_PARCEL;
|
||||||
|
mHasFds = false;
|
||||||
|
mFdsKnown = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
int magic = parcel.readInt();
|
int magic = parcel.readInt();
|
||||||
if (magic != BUNDLE_MAGIC) {
|
if (magic != BUNDLE_MAGIC) {
|
||||||
//noinspection ThrowableInstanceNeverThrown
|
//noinspection ThrowableInstanceNeverThrown
|
||||||
@@ -1716,8 +1750,12 @@ public final class Bundle implements Parcelable, Cloneable {
|
|||||||
@Override
|
@Override
|
||||||
public synchronized String toString() {
|
public synchronized String toString() {
|
||||||
if (mParcelledData != null) {
|
if (mParcelledData != null) {
|
||||||
return "Bundle[mParcelledData.dataSize=" +
|
if (mParcelledData == EMPTY_PARCEL) {
|
||||||
mParcelledData.dataSize() + "]";
|
return "Bundle[EMPTY_PARCEL]";
|
||||||
|
} else {
|
||||||
|
return "Bundle[mParcelledData.dataSize=" +
|
||||||
|
mParcelledData.dataSize() + "]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return "Bundle[" + mMap.toString() + "]";
|
return "Bundle[" + mMap.toString() + "]";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -611,11 +611,15 @@ public final class Parcel {
|
|||||||
here.fillInStackTrace();
|
here.fillInStackTrace();
|
||||||
Log.d(TAG, "Writing " + N + " ArrayMap entries", here);
|
Log.d(TAG, "Writing " + N + " ArrayMap entries", here);
|
||||||
}
|
}
|
||||||
|
int startPos;
|
||||||
for (int i=0; i<N; i++) {
|
for (int i=0; i<N; i++) {
|
||||||
if (DEBUG_ARRAY_MAP) Log.d(TAG, " Write #" + i + ": key=0x"
|
if (DEBUG_ARRAY_MAP) startPos = dataPosition();
|
||||||
+ (val.keyAt(i) != null ? val.keyAt(i).hashCode() : 0) + " " + val.keyAt(i));
|
|
||||||
writeValue(val.keyAt(i));
|
writeValue(val.keyAt(i));
|
||||||
writeValue(val.valueAt(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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2303,11 +2307,14 @@ public final class Parcel {
|
|||||||
here.fillInStackTrace();
|
here.fillInStackTrace();
|
||||||
Log.d(TAG, "Reading " + N + " ArrayMap entries", here);
|
Log.d(TAG, "Reading " + N + " ArrayMap entries", here);
|
||||||
}
|
}
|
||||||
|
int startPos;
|
||||||
while (N > 0) {
|
while (N > 0) {
|
||||||
|
if (DEBUG_ARRAY_MAP) startPos = dataPosition();
|
||||||
Object key = readValue(loader);
|
Object key = readValue(loader);
|
||||||
if (DEBUG_ARRAY_MAP) Log.d(TAG, " Read #" + (N-1) + ": key=0x"
|
|
||||||
+ (key != null ? key.hashCode() : 0) + " " + key);
|
|
||||||
Object value = readValue(loader);
|
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);
|
outVal.append(key, value);
|
||||||
N--;
|
N--;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user