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

Commit 98d98dba authored by Louis Chang's avatar Louis Chang
Browse files

Fix the hidden task was removed before starting home

The home activity idle event could be calls after switching
to other tasks. In that case, it can unexpectedly remove the
hidden tasks that were added after leaving home.

Now, we remove the hidden tasks if home is idle and resumed
to ensure the hidden tasks are safe to be removed.

Also fixing an issue that the task affinity of the
singleInstance activity should be unique.

Bug: 264602067
Test: atest RecentTasksTest
Change-Id: Idb4c71ebbc54b3b37197e0b0c1c049dd85fd6f44
parent 6bed003b
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -2098,7 +2098,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        mTaskSupervisor = supervisor;

        info.taskAffinity = computeTaskAffinity(info.taskAffinity, info.applicationInfo.uid,
                launchMode);
                info.launchMode, mActivityComponent);
        taskAffinity = info.taskAffinity;
        final String uid = Integer.toString(info.applicationInfo.uid);
        if (info.windowLayout != null && info.windowLayout.windowLayoutAffinity != null
@@ -2199,12 +2199,18 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
     * @param affinity The affinity of the activity.
     * @param uid The user-ID that has been assigned to this application.
     * @param launchMode The activity launch mode
     * @param componentName The activity component name. This is only useful when the given
     *                      launchMode is {@link ActivityInfo#LAUNCH_SINGLE_INSTANCE}
     * @return The task affinity
     */
    static String computeTaskAffinity(String affinity, int uid, int launchMode) {
    static String computeTaskAffinity(String affinity, int uid, int launchMode,
            ComponentName componentName) {
        final String uidStr = Integer.toString(uid);
        if (affinity != null && !affinity.startsWith(uidStr)) {
            affinity = uidStr + (launchMode == LAUNCH_SINGLE_INSTANCE ? "-si:" : ":") + affinity;
            affinity = uidStr + ":" + affinity;
            if (launchMode == LAUNCH_SINGLE_INSTANCE && componentName != null) {
                affinity += ":" + componentName.hashCode();
            }
        }
        return affinity;
    }
+2 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;

import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_TASKS;
import static com.android.server.wm.ActivityRecord.State.RESUMED;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RECENTS;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RECENTS_TRIM_TASKS;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RECENTS;
@@ -1221,7 +1222,7 @@ class RecentTasks {
    void onActivityIdle(ActivityRecord r) {
        // Clean up the hidden tasks when going to home because the user may not be unable to return
        // to the task from recents.
        if (!mHiddenTasks.isEmpty() && r.isActivityTypeHome()) {
        if (!mHiddenTasks.isEmpty() && r.isActivityTypeHome() && r.isState(RESUMED)) {
            removeUnreachableHiddenTasks(r.getWindowingMode());
        }
        if (mCheckTrimmableTasksOnIdle) {
+1 −1
Original line number Diff line number Diff line
@@ -5329,7 +5329,7 @@ class Task extends TaskFragment {
        // the task if the affinity has changed.

        final String affinity = ActivityRecord.computeTaskAffinity(destAffinity, srec.getUid(),
                srec.launchMode);
                srec.launchMode, srec.mActivityComponent);
        if (srec == null || srec.getTask().affinity == null
                || !srec.getTask().affinity.equals(affinity)) {
            return true;
+3 −3
Original line number Diff line number Diff line
@@ -1728,7 +1728,7 @@ public class ActivityStarterTests extends WindowTestsBase {
        final ActivityInfo info = new ActivityInfo();
        info.applicationInfo = new ApplicationInfo();
        info.taskAffinity = ActivityRecord.computeTaskAffinity("test", DEFAULT_FAKE_UID,
                0 /* launchMode */);
                0 /* launchMode */, null /* componentName */);
        info.requiredDisplayCategory = "automotive";
        final Task task = new TaskBuilder(mSupervisor).setCreateActivity(true).setActivityInfo(info)
                .build();
@@ -1754,7 +1754,7 @@ public class ActivityStarterTests extends WindowTestsBase {
        final ActivityInfo info = new ActivityInfo();
        info.applicationInfo = new ApplicationInfo();
        info.taskAffinity = ActivityRecord.computeTaskAffinity("test", DEFAULT_FAKE_UID,
                0 /* launchMode */);
                0 /* launchMode */, null /* componentName */);
        info.requiredDisplayCategory = "automotive";
        final Task task = new TaskBuilder(mSupervisor).setCreateActivity(true).setActivityInfo(info)
                .build();
@@ -1780,7 +1780,7 @@ public class ActivityStarterTests extends WindowTestsBase {
        final ActivityInfo info = new ActivityInfo();
        info.applicationInfo = new ApplicationInfo();
        info.taskAffinity = ActivityRecord.computeTaskAffinity("test", DEFAULT_FAKE_UID,
                0 /* launchMode */);
                0 /* launchMode */, null /* componentName */);
        info.requiredDisplayCategory = "automotive";
        final Task task = new TaskBuilder(mSupervisor).setCreateActivity(true).setActivityInfo(info)
                .build();
+6 −3
Original line number Diff line number Diff line
@@ -448,12 +448,15 @@ public class RecentTasksTest extends WindowTestsBase {
        final String taskAffinity = "affinity";
        final int uid = 10123;
        final Task task1 = createTaskBuilder(".Task1").build();
        task1.affinity = ActivityRecord.computeTaskAffinity(taskAffinity, uid, LAUNCH_MULTIPLE);
        final ComponentName componentName = getUniqueComponentName();
        task1.affinity = ActivityRecord.computeTaskAffinity(taskAffinity, uid, LAUNCH_MULTIPLE,
                componentName);
        mRecentTasks.add(task1);

        // Add another task to recents, and make sure the previous task was removed.
        final Task task2 = createTaskBuilder(".Task2").build();
        task2.affinity = ActivityRecord.computeTaskAffinity(taskAffinity, uid, LAUNCH_MULTIPLE);
        task2.affinity = ActivityRecord.computeTaskAffinity(taskAffinity, uid, LAUNCH_MULTIPLE,
                componentName);
        mRecentTasks.add(task2);
        assertEquals(1, mRecentTasks.getRecentTasks(MAX_VALUE, 0 /* flags */,
                true /* getTasksAllowed */, TEST_USER_0_ID, 0).getList().size());
@@ -461,7 +464,7 @@ public class RecentTasksTest extends WindowTestsBase {
        // Add another single-instance task to recents, and make sure no task is removed.
        final Task task3 = createTaskBuilder(".Task3").build();
        task3.affinity = ActivityRecord.computeTaskAffinity(taskAffinity, uid,
                LAUNCH_SINGLE_INSTANCE);
                LAUNCH_SINGLE_INSTANCE, componentName);
        mRecentTasks.add(task3);
        assertEquals(2, mRecentTasks.getRecentTasks(MAX_VALUE, 0 /* flags */,
                true /* getTasksAllowed */, TEST_USER_0_ID, 0).getList().size());