diff options
| author | 2021-07-29 23:00:45 +0800 | |
|---|---|---|
| committer | 2021-07-29 23:28:19 +0800 | |
| commit | a55c81d1de273af8b37fc517c2ca7d01cd194a75 (patch) | |
| tree | d96950b836aa809fb1801033b506303c84332dfd | |
| parent | 23ba83b769a59a801cbeb64eea938d4886ee4322 (diff) | |
Check task switch by comparing the previous top task
Previously, the top task used for checking task switch is
obtained after reusing existing task. So the existing target
task may have been moved to front, that causes misleading
that there is no task switch, and no starting window.
This change gets top task at the beginning of the start request,
so it can get the actual previous task.
This also makes commit 60f9c97 effective again for the common
cases to back-transfer the starting window.
Also remove unused mKeepCurTransition.
Bug: 195007725
Test: ActivityStarterTests
Test: There should be a starting window when launching new activity
on an existing task from different task.
Change-Id: Ic402ec83be47e6a5e12eee2c700f9d8079e89389
4 files changed, 26 insertions, 28 deletions
diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java index c881359f7d68..757ba9ce6208 100644 --- a/services/core/java/com/android/server/wm/ActivityStarter.java +++ b/services/core/java/com/android/server/wm/ActivityStarter.java @@ -193,7 +193,6 @@ class ActivityStarter { private Task mTargetTask; private boolean mMovedToFront; private boolean mNoAnimation; - private boolean mKeepCurTransition; private boolean mAvoidMoveToFront; private boolean mFrozeTaskList; private boolean mTransientLaunch; @@ -592,7 +591,6 @@ class ActivityStarter { mTargetRootTask = starter.mTargetRootTask; mMovedToFront = starter.mMovedToFront; mNoAnimation = starter.mNoAnimation; - mKeepCurTransition = starter.mKeepCurTransition; mAvoidMoveToFront = starter.mAvoidMoveToFront; mFrozeTaskList = starter.mFrozeTaskList; @@ -1707,6 +1705,8 @@ class ActivityStarter { mIntent.setFlags(mLaunchFlags); + // Get top task at beginning because the order may be changed when reusing existing task. + final Task prevTopTask = mPreferredTaskDisplayArea.getFocusedRootTask(); final Task reusedTask = getReusableTask(); // If requested, freeze the task list @@ -1786,24 +1786,23 @@ class ActivityStarter { UserHandle.getAppId(mStartActivity.info.applicationInfo.uid) /*recipient*/, resultToUid /*visible*/, true /*direct*/); } + final Task startedTask = mStartActivity.getTask(); if (newTask) { - EventLogTags.writeWmCreateTask(mStartActivity.mUserId, - mStartActivity.getTask().mTaskId); + EventLogTags.writeWmCreateTask(mStartActivity.mUserId, startedTask.mTaskId); } - mStartActivity.logStartActivity( - EventLogTags.WM_CREATE_ACTIVITY, mStartActivity.getTask()); + mStartActivity.logStartActivity(EventLogTags.WM_CREATE_ACTIVITY, startedTask); mStartActivity.getTaskFragment().clearLastPausedActivity(); mRootWindowContainer.startPowerModeLaunchIfNeeded( false /* forceSend */, mStartActivity); + final boolean isTaskSwitch = startedTask != prevTopTask; mTargetRootTask.startActivityLocked(mStartActivity, topRootTask != null ? topRootTask.getTopNonFinishingActivity() : null, newTask, - mKeepCurTransition, mOptions, sourceRecord); + isTaskSwitch, mOptions, sourceRecord); if (mDoResume) { - final ActivityRecord topTaskActivity = - mStartActivity.getTask().topRunningActivityLocked(); + final ActivityRecord topTaskActivity = startedTask.topRunningActivityLocked(); if (!mTargetRootTask.isTopActivityFocusable() || (topTaskActivity != null && topTaskActivity.isTaskOverlay() && mStartActivity != topTaskActivity)) { @@ -1837,8 +1836,8 @@ class ActivityStarter { mRootWindowContainer.updateUserRootTask(mStartActivity.mUserId, mTargetRootTask); // Update the recent tasks list immediately when the activity starts - mSupervisor.mRecentTasks.add(mStartActivity.getTask()); - mSupervisor.handleNonResizableTaskIfNeeded(mStartActivity.getTask(), + mSupervisor.mRecentTasks.add(startedTask); + mSupervisor.handleNonResizableTaskIfNeeded(startedTask, mPreferredWindowingMode, mPreferredTaskDisplayArea, mTargetRootTask); return START_SUCCESS; @@ -2246,7 +2245,6 @@ class ActivityStarter { mTargetTask = null; mMovedToFront = false; mNoAnimation = false; - mKeepCurTransition = false; mAvoidMoveToFront = false; mFrozeTaskList = false; mTransientLaunch = false; diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index 2355dde0486e..5996083c09f4 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -5058,7 +5058,7 @@ class Task extends TaskFragment { } void startActivityLocked(ActivityRecord r, @Nullable ActivityRecord focusedTopActivity, - boolean newTask, boolean keepCurTransition, ActivityOptions options, + boolean newTask, boolean isTaskSwitch, ActivityOptions options, @Nullable ActivityRecord sourceRecord) { Task rTask = r.getTask(); final boolean allowMoveToFront = options == null || !options.getAvoidMoveToFront(); @@ -5179,7 +5179,7 @@ class Task extends TaskFragment { } } - r.showStartingWindow(prev, newTask, isTaskSwitch(r, focusedTopActivity), + r.showStartingWindow(prev, newTask, isTaskSwitch, true /* startActivity */, sourceRecord); } } else { @@ -5213,10 +5213,6 @@ class Task extends TaskFragment { return true; } - private boolean isTaskSwitch(ActivityRecord r, ActivityRecord topFocusedActivity) { - return topFocusedActivity != null && r.getTask() != topFocusedActivity.getTask(); - } - /** * Reset the task by reparenting the activities that have same affinity to the task or * reparenting the activities that have different affinityies out of the task, while these diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java index 488875b61752..2c3586093717 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java @@ -2600,7 +2600,7 @@ public class ActivityRecordTests extends WindowTestsBase { // Make mVisibleSetFromTransferredStartingWindow true. final ActivityRecord middle = new ActivityBuilder(mAtm).setTask(task).build(); task.startActivityLocked(middle, null /* focusedTopActivity */, - false /* newTask */, false /* keepCurTransition */, null /* options */, + false /* newTask */, false /* isTaskSwitch */, null /* options */, null /* sourceRecord */); middle.makeFinishingLocked(); @@ -2613,7 +2613,7 @@ public class ActivityRecordTests extends WindowTestsBase { top.setVisible(false); // The finishing middle should be able to transfer starting window to top. task.startActivityLocked(top, null /* focusedTopActivity */, - false /* newTask */, false /* keepCurTransition */, null /* options */, + false /* newTask */, false /* isTaskSwitch */, null /* options */, null /* sourceRecord */); assertNull(middle.mStartingWindow); diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java index 2df9a8df3a99..1b4d0a4ab5a4 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java @@ -32,6 +32,7 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; +import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK; import static android.content.Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static android.content.Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED; @@ -755,12 +756,12 @@ public class ActivityStarterTests extends WindowTestsBase { } /** - * This test ensures that {@link ActivityStarter#setTargetStackAndMoveToFrontIfNeeded} will - * move the existing task to front if the current focused stack doesn't have running task. + * This test ensures that {@link ActivityStarter#setTargetRootTaskIfNeeded} will + * move the existing task to front if the current focused root task doesn't have running task. */ @Test - public void testBringTaskToFrontWhenFocusedStackIsFinising() { - // Put 2 tasks in the same stack (simulate the behavior of home stack). + public void testBringTaskToFrontWhenFocusedTaskIsFinishing() { + // Put 2 tasks in the same root task (simulate the behavior of home root task). final Task rootTask = new TaskBuilder(mSupervisor).build(); final ActivityRecord activity = new ActivityBuilder(mAtm) .setParentTask(rootTask) @@ -777,13 +778,16 @@ public class ActivityStarterTests extends WindowTestsBase { assertEquals(finishingTopActivity, mRootWindowContainer.topRunningActivity()); finishingTopActivity.finishing = true; - // Launch the bottom task of the target stack. + // Launch the bottom task of the target root task. prepareStarter(FLAG_ACTIVITY_NEW_TASK, false /* mockGetLaunchStack */) - .setReason("testBringTaskToFrontWhenTopStackIsFinising") - .setIntent(activity.intent) + .setReason("testBringTaskToFrontWhenFocusedTaskIsFinishing") + .setIntent(activity.intent.addFlags( + FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK)) .execute(); + verify(activity.getRootTask()).startActivityLocked(any(), any(), anyBoolean(), + eq(true) /* isTaskSwitch */, any(), any()); // The hierarchies of the activity should move to front. - assertEquals(activity, mRootWindowContainer.topRunningActivity()); + assertEquals(activity.getTask(), mRootWindowContainer.topRunningActivity().getTask()); } /** |