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

Commit 20b22979 authored by Nan Wu's avatar Nan Wu
Browse files

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
parent 3b75ae35
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -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<NestedIntentKey> 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<Intent> visited, NestedIntentKey key) {
        visited.add(intent);
        if (mCreatorTokenInfo == null) {
            mCreatorTokenInfo = new CreatorTokenInfo();
        }
@@ -12447,8 +12446,11 @@ public class Intent implements Parcelable, Cloneable {
            mCreatorTokenInfo.mNestedIntentKeys = new ArraySet<>();
        }
        mCreatorTokenInfo.mNestedIntentKeys.add(key);
        if (!visited.contains(intent)) {
            visited.add(intent);
            intent.collectNestedIntentKeysRecur(visited);
        }
    }
    private void handleParcelableArray(Parcelable[] parcelables, String key, Set<Intent> visited) {
        for (int i = 0; i < parcelables.length; i++) {