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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 */));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user