Merge "Fix the hidden task was removed before starting home" into udc-dev

This commit is contained in:
Louis Chang
2023-03-10 00:59:09 +00:00
committed by Android (Google) Code Review
5 changed files with 21 additions and 11 deletions

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -5332,7 +5332,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;

View File

@@ -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();

View File

@@ -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());