Merge "Do not finish activity if with taskOverlay" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-02-24 06:09:32 +00:00
committed by Android (Google) Code Review
6 changed files with 23 additions and 21 deletions

View File

@@ -2196,8 +2196,9 @@ class ActivityStarter {
// removed from calling performClearTaskLocked (For example, if it is being brought out
// of history or if it is finished immediately), thus disassociating the task. Also note
// that mReuseTask is reset as a result of {@link Task#performClearTaskLocked}
// launching another activity.
targetTask.performClearTaskLocked();
// launching another activity. Keep the task-overlay activity because the targetTask
// will be reused to launch new activity.
targetTask.performClearTaskForReuse(true /* excludingTaskOverlay*/);
targetTask.setIntent(mStartActivity);
mAddingToTask = true;
} else if ((mLaunchFlags & FLAG_ACTIVITY_CLEAR_TOP) != 0
@@ -2207,8 +2208,7 @@ class ActivityStarter {
// In this situation we want to remove all activities from the task up to the one
// being started. In most cases this means we are resetting the task to its initial
// state.
final ActivityRecord top = targetTask.performClearTaskForReuseLocked(mStartActivity,
mLaunchFlags);
final ActivityRecord top = targetTask.performClearTop(mStartActivity, mLaunchFlags);
if (top != null) {
if (top.isRootOfTask()) {

View File

@@ -1605,7 +1605,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
task.mTransitionController.requestCloseTransitionIfNeeded(task);
task.mInRemoveTask = true;
try {
task.performClearTask(reason);
task.removeActivities(reason, false /* excludingTaskOverlay */);
cleanUpRemovedTaskLocked(task, killProcess, removeFromRecents);
mService.getLockTaskController().clearLockedTask(task);
mService.getTaskChangeNotificationController().notifyTaskStackChanged();

View File

@@ -542,7 +542,7 @@ public class LockTaskController {
if (mLockTaskModeTasks.isEmpty()) {
return;
}
task.performClearTaskLocked();
task.performClearTaskForReuse(false /* excludingTaskOverlay*/);
mSupervisor.mRootWindowContainer.resumeFocusedTasksTopActivities();
}
@@ -740,7 +740,7 @@ public class LockTaskController {
ProtoLog.d(WM_DEBUG_LOCKTASK, "onLockTaskPackagesUpdated: removing %s"
+ " mLockTaskAuth()=%s", lockedTask, lockedTask.lockTaskAuthToString());
removeLockedTask(lockedTask);
lockedTask.performClearTaskLocked();
lockedTask.performClearTaskForReuse(false /* excludingTaskOverlay*/);
taskChanged = true;
}

View File

@@ -1584,19 +1584,23 @@ class Task extends TaskFragment {
}
/** Completely remove all activities associated with an existing task. */
void performClearTask(String reason) {
void removeActivities(String reason, boolean excludingTaskOverlay) {
clearPinnedTaskIfNeed();
// Broken down into to cases to avoid object create due to capturing mStack.
if (getRootTask() == null) {
forAllActivities((r) -> {
if (r.finishing) return;
if (r.finishing || (excludingTaskOverlay && r.isTaskOverlay())) {
return;
}
// Task was restored from persistent storage.
r.takeFromHistory();
removeChild(r, reason);
});
} else {
forAllActivities((r) -> {
if (r.finishing) return;
if (r.finishing || (excludingTaskOverlay && r.isTaskOverlay())) {
return;
}
// Prevent the transition from being executed too early if the top activity is
// resumed but the mVisibleRequested of any other activity is true, the transition
// should wait until next activity resumed.
@@ -1613,26 +1617,24 @@ class Task extends TaskFragment {
/**
* Completely remove all activities associated with an existing task.
*/
void performClearTaskLocked() {
void performClearTaskForReuse(boolean excludingTaskOverlay) {
mReuseTask = true;
mTaskSupervisor.beginDeferResume();
try {
performClearTask("clear-task-all");
removeActivities("clear-task-all", excludingTaskOverlay);
} finally {
mTaskSupervisor.endDeferResume();
mReuseTask = false;
}
}
ActivityRecord performClearTaskForReuseLocked(ActivityRecord newR, int launchFlags) {
mReuseTask = true;
ActivityRecord performClearTop(ActivityRecord newR, int launchFlags) {
mTaskSupervisor.beginDeferResume();
final ActivityRecord result;
try {
result = performClearTaskLocked(newR, launchFlags);
result = clearTopActivities(newR, launchFlags);
} finally {
mTaskSupervisor.endDeferResume();
mReuseTask = false;
}
return result;
}
@@ -1648,7 +1650,7 @@ class Task extends TaskFragment {
* @return Returns the old activity that should be continued to be used,
* or {@code null} if none was found.
*/
private ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
private ActivityRecord clearTopActivities(ActivityRecord newR, int launchFlags) {
final ActivityRecord r = findActivityInHistory(newR.mActivityComponent);
if (r == null) return null;
@@ -1675,7 +1677,7 @@ class Task extends TaskFragment {
// Stop operation once we reach the boundary activity.
if (r == boundaryActivity) return true;
if (!r.finishing) {
if (!r.finishing && !r.isTaskOverlay()) {
final ActivityOptions opts = r.getOptions();
if (opts != null) {
r.clearOptionsAnimation();

View File

@@ -120,7 +120,7 @@ public class AppTransitionControllerTest extends WindowTestsBase {
behind.setState(ActivityRecord.State.STARTED, "test");
behind.mVisibleRequested = true;
task.performClearTask("test");
task.removeActivities("test", false /* excludingTaskOverlay */);
assertFalse(mDisplayContent.mAppTransition.isReady());
}

View File

@@ -557,7 +557,7 @@ public class LockTaskControllerTest {
mLockTaskController.updateLockTaskPackages(TEST_USER_ID, allowlist);
// THEN the task running that package should be stopped
verify(tr2).performClearTaskLocked();
verify(tr2).performClearTaskForReuse(false /* excludingTaskOverlay*/);
assertFalse(mLockTaskController.isTaskLocked(tr2));
// THEN the other task should remain locked
assertEquals(LOCK_TASK_MODE_LOCKED, mLockTaskController.getLockTaskModeState());
@@ -569,7 +569,7 @@ public class LockTaskControllerTest {
mLockTaskController.updateLockTaskPackages(TEST_USER_ID, allowlist);
// THEN the last task should be cleared, and the system should quit LockTask mode
verify(tr1).performClearTaskLocked();
verify(tr1).performClearTaskForReuse(false /* excludingTaskOverlay*/);
assertFalse(mLockTaskController.isTaskLocked(tr1));
assertEquals(LOCK_TASK_MODE_NONE, mLockTaskController.getLockTaskModeState());
verifyLockTaskStopped(times(1));