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

Commit 23df1a6a authored by Louis Chang's avatar Louis Chang
Browse files

Fix creating new activity instance when launching alias activity

New activity instance was being started on existing task while
starting alias activity because we used to correct the activity
intent for aliasing. Since the task record intent can now also
save alias activity component, they were evaluated as not using
the same intent filter.

Making sure they are evaluated as the same component as long as
they are having the same real activity.

Bug: 122550967
Test: atest TaskRecordTests
Change-Id: I4fd1f7310cf18645495532ffcf900f8113b69dd1
parent da74280f
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -971,10 +971,11 @@ class TaskRecord extends ConfigurationContainer {
     */
    boolean isSameIntentFilter(ActivityRecord r) {
        final Intent intent = new Intent(r.intent);
        // Correct the activity intent for aliasing. The task record intent will always be based on
        // the real activity that will be launched not the alias, so we need to use an intent with
        // the component name pointing to the real activity not the alias in the activity record.
        intent.setComponent(r.mActivityComponent);
        // Make sure the component are the same if the input activity has the same real activity
        // as the one in the task because either one of them could be the alias activity.
        if (Objects.equals(realActivity, r.mActivityComponent) && this.intent != null) {
            intent.setComponent(this.intent.getComponent());
        }
        return intent.filterEquals(this.intent);
    }

+10 −0
Original line number Diff line number Diff line
@@ -154,6 +154,7 @@ class ActivityTestsBase {
        private final ActivityTaskManagerService mService;

        private ComponentName mComponent;
        private String mTargetActivity;
        private TaskRecord mTaskRecord;
        private int mUid;
        private boolean mCreateTask;
@@ -170,6 +171,11 @@ class ActivityTestsBase {
            return this;
        }

        ActivityBuilder setTargetActivity(String targetActivity) {
            mTargetActivity = targetActivity;
            return this;
        }

        static ComponentName getDefaultComponent() {
            return ComponentName.createRelative(DEFAULT_COMPONENT_PACKAGE_NAME,
                    DEFAULT_COMPONENT_PACKAGE_NAME);
@@ -224,6 +230,10 @@ class ActivityTestsBase {
            aInfo.applicationInfo = new ApplicationInfo();
            aInfo.applicationInfo.packageName = mComponent.getPackageName();
            aInfo.applicationInfo.uid = mUid;
            aInfo.packageName = mComponent.getPackageName();
            if (mTargetActivity != null) {
                aInfo.targetActivity = mTargetActivity;
            }
            aInfo.flags |= mActivityFlags;
            aInfo.launchMode = mLaunchMode;

+24 −5
Original line number Diff line number Diff line
@@ -184,19 +184,38 @@ public class TaskRecordTests extends ActivityTestsBase {
    /** Ensures that the alias intent won't have target component resolved. */
    @Test
    public void testTaskIntentActivityAlias() {
        final String aliasActivity = DEFAULT_COMPONENT_PACKAGE_NAME + ".aliasActivity";
        final String targetActivity = DEFAULT_COMPONENT_PACKAGE_NAME + ".targetActivity";
        final String aliasClassName = DEFAULT_COMPONENT_PACKAGE_NAME + ".aliasActivity";
        final String targetClassName = DEFAULT_COMPONENT_PACKAGE_NAME + ".targetActivity";
        final ComponentName aliasComponent =
                new ComponentName(DEFAULT_COMPONENT_PACKAGE_NAME, aliasClassName);
        final ComponentName targetComponent =
                new ComponentName(DEFAULT_COMPONENT_PACKAGE_NAME, targetClassName);

        final Intent intent = new Intent();
        intent.setComponent(new ComponentName(DEFAULT_COMPONENT_PACKAGE_NAME, aliasActivity));
        intent.setComponent(aliasComponent);
        final ActivityInfo info = new ActivityInfo();
        info.applicationInfo = new ApplicationInfo();
        info.packageName = DEFAULT_COMPONENT_PACKAGE_NAME;
        info.targetActivity = targetActivity;
        info.targetActivity = targetClassName;

        final TaskRecord task = TaskRecord.create(mService, 1 /* taskId */, info, intent,
                null /* taskDescription */);
        assertEquals("The alias activity component should be saved in task intent.", aliasActivity,
        assertEquals("The alias activity component should be saved in task intent.", aliasClassName,
                task.intent.getComponent().getClassName());

        ActivityRecord aliasActivity = new ActivityBuilder(mService).setComponent(
                aliasComponent).setTargetActivity(targetClassName).build();
        assertEquals("Should be the same intent filter.", true,
                task.isSameIntentFilter(aliasActivity));

        ActivityRecord targetActivity = new ActivityBuilder(mService).setComponent(
                targetComponent).build();
        assertEquals("Should be the same intent filter.", true,
                task.isSameIntentFilter(targetActivity));

        ActivityRecord defaultActivity = new ActivityBuilder(mService).build();
        assertEquals("Should not be the same intent filter.", false,
                task.isSameIntentFilter(defaultActivity));
    }

    private void testStackBoundsConfiguration(int windowingMode, Rect parentBounds, Rect bounds,