summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2021-10-06 12:25:47 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2021-10-06 12:25:47 +0000
commit3aaf98490850c4ff9ad5dca1eb3a75770a467de3 (patch)
treef160fa457949fb7a18b4ed7502f85a6e329a07fd
parent3f3c3a02c2df55a269b52cbc6a48c0a82b44d14b (diff)
parent3ad4ecc2967906db398607ab7f8f2e0bd9899265 (diff)
Merge "Avoid full unparcelling where possible in Bundle" am: 3ad4ecc296
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1842226 Change-Id: I0aef93d99d83f20b22753e8e1d41cfb5c4b5cdce
-rw-r--r--core/java/android/app/ActivityThread.java1
-rw-r--r--core/java/android/content/Intent.java10
-rw-r--r--core/java/android/os/BaseBundle.java16
-rw-r--r--core/java/android/os/Bundle.java50
-rw-r--r--core/java/android/os/Parcel.java17
-rw-r--r--core/java/android/os/PersistableBundle.java7
6 files changed, 28 insertions, 73 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 8210baf40983..6c3795d7c607 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -3891,7 +3891,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 {
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 9e35a32638a8..d811040b6bb2 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -8835,16 +8835,6 @@ public class Intent implements Parcelable, Cloneable {
}
/**
- * 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.
* @hide
diff --git a/core/java/android/os/BaseBundle.java b/core/java/android/os/BaseBundle.java
index 8dde64d8af43..2a344f6c2b6b 100644
--- a/core/java/android/os/BaseBundle.java
+++ b/core/java/android/os/BaseBundle.java
@@ -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));
}
diff --git a/core/java/android/os/Bundle.java b/core/java/android/os/Bundle.java
index b6163f1105c6..f215325f6be2 100644
--- a/core/java/android/os/Bundle.java
+++ b/core/java/android/os/Bundle.java
@@ -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) {
diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java
index 6c3470ca653a..44d51db80f86 100644
--- a/core/java/android/os/Parcel.java
+++ b/core/java/android/os/Parcel.java
@@ -3573,14 +3573,17 @@ public final class Parcel {
Parcel source = mSource;
if (source != null) {
synchronized (source) {
- int restore = source.dataPosition();
- try {
- source.setDataPosition(mPosition);
- mObject = source.readValue(mLoader);
- } finally {
- source.setDataPosition(restore);
+ // Check mSource != null guarantees callers won't ever see different objects.
+ if (mSource != null) {
+ int restore = source.dataPosition();
+ try {
+ source.setDataPosition(mPosition);
+ mObject = source.readValue(mLoader);
+ } finally {
+ source.setDataPosition(restore);
+ }
+ mSource = null;
}
- mSource = null;
}
}
return mObject;
diff --git a/core/java/android/os/PersistableBundle.java b/core/java/android/os/PersistableBundle.java
index cad6e66888d9..76b88a3399d8 100644
--- a/core/java/android/os/PersistableBundle.java
+++ b/core/java/android/os/PersistableBundle.java
@@ -35,6 +35,7 @@ import org.xmlpull.v1.XmlSerializer;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.Serializable;
import java.util.ArrayList;
/**
@@ -103,6 +104,10 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
/**
* Constructs a PersistableBundle from a Bundle. Does only a shallow copy of the Bundle.
*
+ * <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.
+ *
* @param b a Bundle to be copied.
*
* @throws IllegalArgumentException if any element of {@code b} cannot be persisted.
@@ -110,7 +115,7 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
* @hide
*/
public PersistableBundle(Bundle b) {
- this(b.getMap());
+ this(b.getItemwiseMap());
}
/**