From 20b229794ace3f58d5ec791a57e48362da319dd1 Mon Sep 17 00:00:00 2001 From: Nan Wu Date: Sun, 8 Dec 2024 02:44:31 +0000 Subject: Fix missing creator token issue due to same intent added twice as extra intent If the same object is added more than one time to a top level intent as extra intent, but with different keys, collectExtraIntentKeys() method would only collect one of the keys because it considers the second intent as a duplicate and not handling it again. If later, the app retrieves the intent through the second key and tries to launch it, this would result as a failure due to missing token error. To fix it, we should still collect the key even if the intent is a duplicate; we just have to not handle the intent recursively when we detect it as a duplicate. Bug: 382863447 Test: manual Flag: EXEMPT bug fix Change-Id: Id3cbf15ef1902167ef52068b27765b4aa942ab8b --- core/java/android/content/Intent.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index a6492d36cf8f..3d75423edfa9 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -12291,7 +12291,6 @@ public class Intent implements Parcelable, Cloneable { private IBinder mCreatorToken; // Stores all extra keys whose values are intents for a top level intent. private ArraySet mNestedIntentKeys; - } /** @@ -12353,6 +12352,7 @@ public class Intent implements Parcelable, Cloneable { public int hashCode() { return Objects.hash(mType, mKey, mIndex); } + } private @Nullable CreatorTokenInfo mCreatorTokenInfo; @@ -12416,7 +12416,7 @@ public class Intent implements Parcelable, Cloneable { // removeLaunchSecurityProtection() is called before it is launched. value = null; } - if (value instanceof Intent intent && !visited.contains(intent)) { + if (value instanceof Intent intent) { handleNestedIntent(intent, visited, new NestedIntentKey( NestedIntentKey.NESTED_INTENT_KEY_TYPE_EXTRA_PARCEL, key, 0)); } else if (value instanceof Parcelable[] parcelables) { @@ -12439,7 +12439,6 @@ public class Intent implements Parcelable, Cloneable { } private void handleNestedIntent(Intent intent, Set visited, NestedIntentKey key) { - visited.add(intent); if (mCreatorTokenInfo == null) { mCreatorTokenInfo = new CreatorTokenInfo(); } @@ -12447,7 +12446,10 @@ public class Intent implements Parcelable, Cloneable { mCreatorTokenInfo.mNestedIntentKeys = new ArraySet<>(); } mCreatorTokenInfo.mNestedIntentKeys.add(key); - intent.collectNestedIntentKeysRecur(visited); + if (!visited.contains(intent)) { + visited.add(intent); + intent.collectNestedIntentKeysRecur(visited); + } } private void handleParcelableArray(Parcelable[] parcelables, String key, Set visited) { -- cgit v1.2.3-59-g8ed1b