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

Commit 039349e3 authored by Jiaming Liu's avatar Jiaming Liu
Browse files

Exclude embedded activities from updateHomeProcess

When the -1 activity is embedded in the home task, we should not update
the home process to be the -1 activity. We perform this check by
comparing the package name of the Task base intent and the activity.

Bug: 293789001
Test: atest ActivityRecordTests TaskTests ActivityTaskSupervisorTests
Change-Id: Ia097766ef6ea87407ae18b6fe67b8fe1a13431f0
parent 3cdc3abc
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -6501,9 +6501,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
        newIntents = null;

        if (isActivityTypeHome()) {
            mTaskSupervisor.updateHomeProcess(task.getBottomMostActivity().app);
        }
        mTaskSupervisor.updateHomeProcessIfNeeded(this);

        if (nowVisible) {
            mTaskSupervisor.stopWaitingForActivityVisible(this);
+11 −4
Original line number Diff line number Diff line
@@ -902,10 +902,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
                                + " andResume=" + andResume);
                EventLogTags.writeWmRestartActivity(r.mUserId, System.identityHashCode(r),
                        task.mTaskId, r.shortComponentName);
                if (r.isActivityTypeHome()) {
                    // Home process is the root process of the task.
                    updateHomeProcess(task.getBottomMostActivity().app);
                }
                updateHomeProcessIfNeeded(r);
                mService.getPackageManagerInternalLocked().notifyPackageUse(
                        r.intent.getComponent().getPackageName(), NOTIFY_PACKAGE_USE_ACTIVITY);
                mService.getAppWarningsLocked().onStartActivity(r);
@@ -1050,6 +1047,16 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
        return true;
    }

    void updateHomeProcessIfNeeded(@NonNull ActivityRecord r) {
        if (!r.isActivityTypeHome()) return;
        // Make sure that we use the bottom most activity from the same package, because the home
        // task can also embed third-party -1 activities.
        final ActivityRecord bottom = r.getTask().getBottomMostActivityInSamePackage();
        if (bottom != null) {
            updateHomeProcess(bottom.app);
        }
    }

    void updateHomeProcess(WindowProcessController app) {
        if (app != null && mService.mHomeProcess != app) {
            scheduleStartHome("homeChanged");
+9 −0
Original line number Diff line number Diff line
@@ -6797,6 +6797,15 @@ class Task extends TaskFragment {
        }
    }

    @Nullable
    ActivityRecord getBottomMostActivityInSamePackage() {
        if (realActivity == null) {
            return null;
        }
        return getActivity(ar -> ar.packageName.equals(
                realActivity.getPackageName()), false /* traverseTopToBottom */);
    }

    /**
     * Associates the decor surface with the given TF, or create one if there
     * isn't one in the Task yet. The surface will be removed with the TF,
+21 −0
Original line number Diff line number Diff line
@@ -1960,6 +1960,27 @@ public class TaskTests extends WindowTestsBase {
        verify(task).startPausing(eq(true) /* userLeaving */, anyBoolean(), any(), any());
    }

    @Test
    public void testGetBottomMostActivityInSamePackage() {
        final String packageName = "homePackage";
        final TaskFragmentOrganizer organizer = new TaskFragmentOrganizer(Runnable::run);
        final Task task = new TaskBuilder(mSupervisor).setCreateActivity(false).build();
        task.realActivity = new ComponentName(packageName, packageName + ".root_activity");
        doNothing().when(task).sendTaskFragmentParentInfoChangedIfNeeded();

        final TaskFragment fragment1 = createTaskFragmentWithEmbeddedActivity(task, organizer);
        final ActivityRecord activityDifferentPackage =
                new ActivityBuilder(mAtm).setTask(task).build();
        final ActivityRecord activitySamePackage =
                new ActivityBuilder(mAtm)
                        .setComponent(new ComponentName(packageName, packageName + ".activity2"))
                        .setTask(task).build();

        assertEquals(fragment1.getChildAt(0), task.getBottomMostActivity());
        assertEquals(activitySamePackage, task.getBottomMostActivityInSamePackage());
        assertNotEquals(activityDifferentPackage, task.getBottomMostActivityInSamePackage());
    }

    private Task getTestTask() {
        return new TaskBuilder(mSupervisor).setCreateActivity(true).build();
    }