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

Commit cb329ca9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Avoid full unparcelling where possible in Bundle" am: 3ad4ecc2 am: 3aaf9849

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1842226

Change-Id: I598b562401860e5e838f891eb2944e49becc2fe6
parents 104767cc 3aaf9849
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -3887,7 +3887,6 @@ public final class ActivityThread extends ClientTransactionHandler
                        Intent intent = new Intent(activityIntent);
                        intent.setFlags(intent.getFlags() & ~(Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION));
                        intent.removeUnsafeExtras();
                        content.setDefaultIntent(intent);
                    }
                } else {
+0 −10
Original line number Diff line number Diff line
@@ -8834,16 +8834,6 @@ public class Intent implements Parcelable, Cloneable {
                : null;
    }

    /**
     * Filter extras to only basic types.
     * @hide
     */
    public void removeUnsafeExtras() {
        if (mExtras != null) {
            mExtras = mExtras.filterValues();
        }
    }

    /**
     * @return Whether {@link #maybeStripForHistory} will return an lightened intent or
     * return itself as-is.
+12 −4
Original line number Diff line number Diff line
@@ -395,8 +395,16 @@ public class BaseBundle {
        }
    }

    /** @hide */
    ArrayMap<String, Object> getMap() {
    /**
     * Returns the backing map of this bundle after deserializing every item.
     *
     * <p><b>Warning:</b> This method will deserialize every item on the bundle, including custom
     * types such as {@link Parcelable} and {@link Serializable}, so only use this when you trust
     * the source. Specifically don't use this method on app-provided bundles.
     *
     * @hide
     */
    ArrayMap<String, Object> getItemwiseMap() {
        unparcel(/* itemwise */ true);
        return mMap;
    }
@@ -519,7 +527,7 @@ public class BaseBundle {
                    final int N = fromMap.size();
                    mMap = new ArrayMap<>(N);
                    for (int i = 0; i < N; i++) {
                        mMap.append(fromMap.keyAt(i), deepCopyValue(from.getValueAt(i)));
                        mMap.append(fromMap.keyAt(i), deepCopyValue(fromMap.valueAt(i)));
                    }
                }
            } else {
@@ -1791,7 +1799,7 @@ public class BaseBundle {
            pw.println("[null]");
            return;
        }
        final ArrayMap<String, Object> map = bundle.getMap();
        final ArrayMap<String, Object> map = bundle.getItemwiseMap();
        for (int i = 0; i < map.size(); i++) {
            dumpStats(pw, map.keyAt(i), map.valueAt(i));
        }
+0 −50
Original line number Diff line number Diff line
@@ -348,56 +348,6 @@ public final class Bundle extends BaseBundle implements Cloneable, Parcelable {
        return (mFlags & FLAG_HAS_FDS) != 0;
    }

    /**
     * Filter values in Bundle to only basic types.
     * @hide
     */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public Bundle filterValues() {
        unparcel(/* itemwise */ true);
        Bundle bundle = this;
        if (mMap != null) {
            ArrayMap<String, Object> map = mMap;
            for (int i = map.size() - 1; i >= 0; i--) {
                Object value = map.valueAt(i);
                if (PersistableBundle.isValidType(value)) {
                    continue;
                }
                if (value instanceof Bundle) {
                    Bundle newBundle = ((Bundle)value).filterValues();
                    if (newBundle != value) {
                        if (map == mMap) {
                            // The filter had to generate a new bundle, but we have not yet
                            // created a new one here.  Do that now.
                            bundle = new Bundle(this);
                            // Note the ArrayMap<> constructor is guaranteed to generate
                            // a new object with items in the same order as the original.
                            map = bundle.mMap;
                        }
                        // Replace this current entry with the new child bundle.
                        map.setValueAt(i, newBundle);
                    }
                    continue;
                }
                if (value.getClass().getName().startsWith("android.")) {
                    continue;
                }
                if (map == mMap) {
                    // This is the first time we have had to remove something, that means we
                    // need to switch to a new Bundle.
                    bundle = new Bundle(this);
                    // Note the ArrayMap<> constructor is guaranteed to generate
                    // a new object with items in the same order as the original.
                    map = bundle.mMap;
                }
                map.removeAt(i);
            }
        }
        mFlags |= FLAG_HAS_FDS_KNOWN;
        mFlags &= ~FLAG_HAS_FDS;
        return bundle;
    }

    /** {@hide} */
    @Override
    public void putObject(@Nullable String key, @Nullable Object value) {
+10 −7
Original line number Diff line number Diff line
@@ -3573,6 +3573,8 @@ public final class Parcel {
            Parcel source = mSource;
            if (source != null) {
                synchronized (source) {
                    // Check mSource != null guarantees callers won't ever see different objects.
                    if (mSource != null) {
                        int restore = source.dataPosition();
                        try {
                            source.setDataPosition(mPosition);
@@ -3583,6 +3585,7 @@ public final class Parcel {
                        mSource = null;
                    }
                }
            }
            return mObject;
        }

Loading