Merge "Check task switch by comparing the previous top task" into sc-v2-dev

This commit is contained in:
Riddle Hsu
2021-08-02 06:10:45 +00:00
committed by Android (Google) Code Review
4 changed files with 26 additions and 28 deletions

View File

@@ -194,7 +194,6 @@ class ActivityStarter {
private Task mTargetTask; private Task mTargetTask;
private boolean mMovedToFront; private boolean mMovedToFront;
private boolean mNoAnimation; private boolean mNoAnimation;
private boolean mKeepCurTransition;
private boolean mAvoidMoveToFront; private boolean mAvoidMoveToFront;
private boolean mFrozeTaskList; private boolean mFrozeTaskList;
private boolean mTransientLaunch; private boolean mTransientLaunch;
@@ -593,7 +592,6 @@ class ActivityStarter {
mTargetRootTask = starter.mTargetRootTask; mTargetRootTask = starter.mTargetRootTask;
mMovedToFront = starter.mMovedToFront; mMovedToFront = starter.mMovedToFront;
mNoAnimation = starter.mNoAnimation; mNoAnimation = starter.mNoAnimation;
mKeepCurTransition = starter.mKeepCurTransition;
mAvoidMoveToFront = starter.mAvoidMoveToFront; mAvoidMoveToFront = starter.mAvoidMoveToFront;
mFrozeTaskList = starter.mFrozeTaskList; mFrozeTaskList = starter.mFrozeTaskList;
@@ -1708,6 +1706,8 @@ class ActivityStarter {
mIntent.setFlags(mLaunchFlags); 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(); final Task reusedTask = getReusableTask();
// If requested, freeze the task list // If requested, freeze the task list
@@ -1787,24 +1787,23 @@ class ActivityStarter {
UserHandle.getAppId(mStartActivity.info.applicationInfo.uid) /*recipient*/, UserHandle.getAppId(mStartActivity.info.applicationInfo.uid) /*recipient*/,
resultToUid /*visible*/, true /*direct*/); resultToUid /*visible*/, true /*direct*/);
} }
final Task startedTask = mStartActivity.getTask();
if (newTask) { if (newTask) {
EventLogTags.writeWmCreateTask(mStartActivity.mUserId, EventLogTags.writeWmCreateTask(mStartActivity.mUserId, startedTask.mTaskId);
mStartActivity.getTask().mTaskId);
} }
mStartActivity.logStartActivity( mStartActivity.logStartActivity(EventLogTags.WM_CREATE_ACTIVITY, startedTask);
EventLogTags.WM_CREATE_ACTIVITY, mStartActivity.getTask());
mStartActivity.getTaskFragment().clearLastPausedActivity(); mStartActivity.getTaskFragment().clearLastPausedActivity();
mRootWindowContainer.startPowerModeLaunchIfNeeded( mRootWindowContainer.startPowerModeLaunchIfNeeded(
false /* forceSend */, mStartActivity); false /* forceSend */, mStartActivity);
final boolean isTaskSwitch = startedTask != prevTopTask;
mTargetRootTask.startActivityLocked(mStartActivity, mTargetRootTask.startActivityLocked(mStartActivity,
topRootTask != null ? topRootTask.getTopNonFinishingActivity() : null, newTask, topRootTask != null ? topRootTask.getTopNonFinishingActivity() : null, newTask,
mKeepCurTransition, mOptions, sourceRecord); isTaskSwitch, mOptions, sourceRecord);
if (mDoResume) { if (mDoResume) {
final ActivityRecord topTaskActivity = final ActivityRecord topTaskActivity = startedTask.topRunningActivityLocked();
mStartActivity.getTask().topRunningActivityLocked();
if (!mTargetRootTask.isTopActivityFocusable() if (!mTargetRootTask.isTopActivityFocusable()
|| (topTaskActivity != null && topTaskActivity.isTaskOverlay() || (topTaskActivity != null && topTaskActivity.isTaskOverlay()
&& mStartActivity != topTaskActivity)) { && mStartActivity != topTaskActivity)) {
@@ -1838,8 +1837,8 @@ class ActivityStarter {
mRootWindowContainer.updateUserRootTask(mStartActivity.mUserId, mTargetRootTask); mRootWindowContainer.updateUserRootTask(mStartActivity.mUserId, mTargetRootTask);
// Update the recent tasks list immediately when the activity starts // Update the recent tasks list immediately when the activity starts
mSupervisor.mRecentTasks.add(mStartActivity.getTask()); mSupervisor.mRecentTasks.add(startedTask);
mSupervisor.handleNonResizableTaskIfNeeded(mStartActivity.getTask(), mSupervisor.handleNonResizableTaskIfNeeded(startedTask,
mPreferredWindowingMode, mPreferredTaskDisplayArea, mTargetRootTask); mPreferredWindowingMode, mPreferredTaskDisplayArea, mTargetRootTask);
return START_SUCCESS; return START_SUCCESS;
@@ -2278,7 +2277,6 @@ class ActivityStarter {
mTargetTask = null; mTargetTask = null;
mMovedToFront = false; mMovedToFront = false;
mNoAnimation = false; mNoAnimation = false;
mKeepCurTransition = false;
mAvoidMoveToFront = false; mAvoidMoveToFront = false;
mFrozeTaskList = false; mFrozeTaskList = false;
mTransientLaunch = false; mTransientLaunch = false;

View File

@@ -5058,7 +5058,7 @@ class Task extends TaskFragment {
} }
void startActivityLocked(ActivityRecord r, @Nullable ActivityRecord focusedTopActivity, void startActivityLocked(ActivityRecord r, @Nullable ActivityRecord focusedTopActivity,
boolean newTask, boolean keepCurTransition, ActivityOptions options, boolean newTask, boolean isTaskSwitch, ActivityOptions options,
@Nullable ActivityRecord sourceRecord) { @Nullable ActivityRecord sourceRecord) {
Task rTask = r.getTask(); Task rTask = r.getTask();
final boolean allowMoveToFront = options == null || !options.getAvoidMoveToFront(); 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); true /* startActivity */, sourceRecord);
} }
} else { } else {
@@ -5213,10 +5213,6 @@ class Task extends TaskFragment {
return true; 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 * 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 * reparenting the activities that have different affinityies out of the task, while these

View File

@@ -2600,7 +2600,7 @@ public class ActivityRecordTests extends WindowTestsBase {
// Make mVisibleSetFromTransferredStartingWindow true. // Make mVisibleSetFromTransferredStartingWindow true.
final ActivityRecord middle = new ActivityBuilder(mAtm).setTask(task).build(); final ActivityRecord middle = new ActivityBuilder(mAtm).setTask(task).build();
task.startActivityLocked(middle, null /* focusedTopActivity */, task.startActivityLocked(middle, null /* focusedTopActivity */,
false /* newTask */, false /* keepCurTransition */, null /* options */, false /* newTask */, false /* isTaskSwitch */, null /* options */,
null /* sourceRecord */); null /* sourceRecord */);
middle.makeFinishingLocked(); middle.makeFinishingLocked();
@@ -2613,7 +2613,7 @@ public class ActivityRecordTests extends WindowTestsBase {
top.setVisible(false); top.setVisible(false);
// The finishing middle should be able to transfer starting window to top. // The finishing middle should be able to transfer starting window to top.
task.startActivityLocked(top, null /* focusedTopActivity */, task.startActivityLocked(top, null /* focusedTopActivity */,
false /* newTask */, false /* keepCurTransition */, null /* options */, false /* newTask */, false /* isTaskSwitch */, null /* options */,
null /* sourceRecord */); null /* sourceRecord */);
assertNull(middle.mStartingWindow); assertNull(middle.mStartingWindow);

View File

@@ -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_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; 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_LAUNCH_ADJACENT;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED; 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 * This test ensures that {@link ActivityStarter#setTargetRootTaskIfNeeded} will
* move the existing task to front if the current focused stack doesn't have running task. * move the existing task to front if the current focused root task doesn't have running task.
*/ */
@Test @Test
public void testBringTaskToFrontWhenFocusedStackIsFinising() { public void testBringTaskToFrontWhenFocusedTaskIsFinishing() {
// Put 2 tasks in the same stack (simulate the behavior of home stack). // Put 2 tasks in the same root task (simulate the behavior of home root task).
final Task rootTask = new TaskBuilder(mSupervisor).build(); final Task rootTask = new TaskBuilder(mSupervisor).build();
final ActivityRecord activity = new ActivityBuilder(mAtm) final ActivityRecord activity = new ActivityBuilder(mAtm)
.setParentTask(rootTask) .setParentTask(rootTask)
@@ -777,13 +778,16 @@ public class ActivityStarterTests extends WindowTestsBase {
assertEquals(finishingTopActivity, mRootWindowContainer.topRunningActivity()); assertEquals(finishingTopActivity, mRootWindowContainer.topRunningActivity());
finishingTopActivity.finishing = true; 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 */) prepareStarter(FLAG_ACTIVITY_NEW_TASK, false /* mockGetLaunchStack */)
.setReason("testBringTaskToFrontWhenTopStackIsFinising") .setReason("testBringTaskToFrontWhenFocusedTaskIsFinishing")
.setIntent(activity.intent) .setIntent(activity.intent.addFlags(
FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK))
.execute(); .execute();
verify(activity.getRootTask()).startActivityLocked(any(), any(), anyBoolean(),
eq(true) /* isTaskSwitch */, any(), any());
// The hierarchies of the activity should move to front. // The hierarchies of the activity should move to front.
assertEquals(activity, mRootWindowContainer.topRunningActivity()); assertEquals(activity.getTask(), mRootWindowContainer.topRunningActivity().getTask());
} }
/** /**