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

Commit d585f954 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Fix issue #10921903: CTS: android.os.cts.ParcelTest#testReadBundle..." into klp-dev

parents 0a660528 4a7d824c
Loading
Loading
Loading
Loading
+24 −25
Original line number Diff line number Diff line
@@ -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,25 +1704,14 @@ 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;
    }
    }

    @Override
    public synchronized String toString() {
+1 −0
Original line number Diff line number Diff line
@@ -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;
        }
        
+1 −0
Original line number Diff line number Diff line
@@ -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;
        }
    }