diff options
| author | Riddle Hsu <riddlehsu@google.com> | 2020-03-13 18:47:17 +0800 |
|---|---|---|
| committer | Riddle Hsu <riddlehsu@google.com> | 2020-03-13 19:25:44 +0800 |
| commit | 8be3b9f7dd77fe23d53620e2a3908efd9b831740 (patch) | |
| tree | 929a769cd054e622800519be38e161732a02dcb2 | |
| parent | 34e727ec7f7ae4dec72bde969fcddfbe3c0b6f42 (diff) | |
Use target component to find existing single instance activity
Otherwise the alias name in the intent cannot match the target
component, then a new activity will always be created.
Bug: 149538962
Test: RootWindowContainerTests#testFindActivityByTargetComponent
Change-Id: Ieb25fb925bf247ac88115623209ea46aa7ccce31
| -rw-r--r-- | services/core/java/com/android/server/wm/RootWindowContainer.java | 4 | ||||
| -rw-r--r-- | services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java | 24 |
2 files changed, 27 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java index 0fa135b47efb..36f4df701f71 100644 --- a/services/core/java/com/android/server/wm/RootWindowContainer.java +++ b/services/core/java/com/android/server/wm/RootWindowContainer.java @@ -2709,7 +2709,9 @@ class RootWindowContainer extends WindowContainer<DisplayContent> return true; } } else { - if (r.intent.getComponent().equals(cls)) { + // Compare the target component instead of intent component so we don't miss if the + // activity uses alias. + if (r.mActivityComponent.equals(cls)) { return true; } } diff --git a/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java b/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java index 277bc41cf34e..67b1dacbb47b 100644 --- a/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java @@ -27,6 +27,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import android.app.WindowConfiguration; +import android.content.ComponentName; +import android.content.pm.ActivityInfo; import android.platform.test.annotations.Presubmit; import androidx.test.filters.SmallTest; @@ -109,5 +111,27 @@ public class RootWindowContainerTests extends WindowTestsBase { assertEquals(WindowConfiguration.WINDOWING_MODE_FREEFORM, mWm.getDefaultDisplayContentLocked().getWindowingMode()); } + + /** + * This test ensures that an existing single instance activity with alias name can be found by + * the same activity info. So {@link ActivityStarter#getReusableTask} won't miss it that leads + * to create an unexpected new instance. + */ + @Test + public void testFindActivityByTargetComponent() { + final ComponentName aliasComponent = ComponentName.createRelative( + ActivityTestsBase.DEFAULT_COMPONENT_PACKAGE_NAME, ".AliasActivity"); + final ComponentName targetComponent = ComponentName.createRelative( + aliasComponent.getPackageName(), ".TargetActivity"); + final ActivityRecord activity = new ActivityTestsBase.ActivityBuilder(mWm.mAtmService) + .setComponent(aliasComponent) + .setTargetActivity(targetComponent.getClassName()) + .setLaunchMode(ActivityInfo.LAUNCH_SINGLE_INSTANCE) + .setCreateTask(true) + .build(); + + assertEquals(activity, mWm.mRoot.findActivity(activity.intent, activity.info, + false /* compareIntentFilters */)); + } } |
