Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f09a1b88 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android Git Automerger
Browse files

am aec8fbb3: am df033aed: Merge "Fix issue #11290095: Parcel change causing...

am aec8fbb3: am df033aed: Merge "Fix issue #11290095: Parcel change causing crashing in KLP..." into klp-dev

* commit 'aec8fbb3':
  Fix issue #11290095: Parcel change causing crashing in KLP...
parents bea31576 aec8fbb3
Loading
Loading
Loading
Loading
+47 −9
Original line number Diff line number Diff line
@@ -35,10 +35,12 @@ public final class Bundle implements Parcelable, Cloneable {
    public static final Bundle EMPTY;

    static final int BUNDLE_MAGIC = 0x4C444E42; // 'B' 'N' 'D' 'L'
    static final Parcel EMPTY_PARCEL;

    static {
        EMPTY = new Bundle();
        EMPTY.mMap = ArrayMap.EMPTY;
        EMPTY_PARCEL = Parcel.obtain();
    }

    // Invariant - exactly one of mMap / mParcelledData will be null
@@ -115,9 +117,13 @@ public final class Bundle implements Parcelable, Cloneable {
     */
    public Bundle(Bundle b) {
        if (b.mParcelledData != null) {
            if (b.mParcelledData == EMPTY_PARCEL) {
                mParcelledData = EMPTY_PARCEL;
            } else {
                mParcelledData = Parcel.obtain();
                mParcelledData.appendFrom(b.mParcelledData, 0, b.mParcelledData.dataSize());
                mParcelledData.setDataPosition(0);
            }
        } else {
            mParcelledData = null;
        }
@@ -216,6 +222,18 @@ public final class Bundle implements Parcelable, Cloneable {
            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();
        if (DEBUG) Log.d(TAG, "unparcel " + Integer.toHexString(System.identityHashCode(this))
                + ": reading " + N + " maps");
@@ -1652,11 +1670,20 @@ public final class Bundle implements Parcelable, Cloneable {
        final boolean oldAllowFds = parcel.pushAllowFds(mAllowFds);
        try {
            if (mParcelledData != null) {
                if (mParcelledData == EMPTY_PARCEL) {
                    parcel.writeInt(0);
                } else {
                    int length = mParcelledData.dataSize();
                    parcel.writeInt(length);
                    parcel.writeInt(BUNDLE_MAGIC);
                    parcel.appendFrom(mParcelledData, 0, length);
                }
            } else {
                // Special case for empty bundles.
                if (mMap == null || mMap.size() <= 0) {
                    parcel.writeInt(0);
                    return;
                }
                int lengthPos = parcel.dataPosition();
                parcel.writeInt(-1); // dummy, will hold length
                parcel.writeInt(BUNDLE_MAGIC);
@@ -1690,6 +1717,13 @@ public final class Bundle implements Parcelable, Cloneable {
    }

    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();
        if (magic != BUNDLE_MAGIC) {
            //noinspection ThrowableInstanceNeverThrown
@@ -1716,9 +1750,13 @@ public final class Bundle implements Parcelable, Cloneable {
    @Override
    public synchronized String toString() {
        if (mParcelledData != null) {
            if (mParcelledData == EMPTY_PARCEL) {
                return "Bundle[EMPTY_PARCEL]";
            } else {
                return "Bundle[mParcelledData.dataSize=" +
                        mParcelledData.dataSize() + "]";
            }
        }
        return "Bundle[" + mMap.toString() + "]";
    }
}
+11 −4
Original line number Diff line number Diff line
@@ -611,11 +611,15 @@ public final class Parcel {
            here.fillInStackTrace();
            Log.d(TAG, "Writing " + N + " ArrayMap entries", here);
        }
        int startPos;
        for (int i=0; i<N; i++) {
            if (DEBUG_ARRAY_MAP) Log.d(TAG, "  Write #" + i + ": key=0x"
                    + (val.keyAt(i) != null ? val.keyAt(i).hashCode() : 0) + " " + val.keyAt(i));
            if (DEBUG_ARRAY_MAP) startPos = dataPosition();
            writeValue(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));
        }
    }

@@ -2303,11 +2307,14 @@ public final class Parcel {
            here.fillInStackTrace();
            Log.d(TAG, "Reading " + N + " ArrayMap entries", here);
        }
        int startPos;
        while (N > 0) {
            if (DEBUG_ARRAY_MAP) startPos = dataPosition();
            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);
            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--;
        }