From 87a79d3a1ded943bea738c73a82b11d3b48bc012 Mon Sep 17 00:00:00 2001 From: Jeff Chang Date: Wed, 17 Mar 2021 14:21:16 +0800 Subject: [PATCH] Start activity with focus root task for staged split During the start activity process, the system will get a launch root task to launch activity. The root tasks are created as a direct child of a TDA, unless there is a launch-root-task set where the created task would be a child task of the launch-root-task. This CL make activity can start with a focus root task which is created by the task organizer and has an adjacent task. For legacy split screens, this CL doesn't change the original behavior. Bug: 180079028 Test: atest MultiWindowTests atest TaskDisplayAreaTests Change-Id: Idf62ec2489eb1f05baddd3b527a0afc868426251 --- .../android/server/wm/TaskDisplayArea.java | 10 +++++++- .../server/wm/TaskDisplayAreaTests.java | 23 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wm/TaskDisplayArea.java b/services/core/java/com/android/server/wm/TaskDisplayArea.java index cda8c4b78b0cd..87f685e95fe13 100644 --- a/services/core/java/com/android/server/wm/TaskDisplayArea.java +++ b/services/core/java/com/android/server/wm/TaskDisplayArea.java @@ -1274,7 +1274,15 @@ final class TaskDisplayArea extends DisplayArea { for (int i = mLaunchRootTasks.size() - 1; i >= 0; --i) { if (mLaunchRootTasks.get(i).contains(windowingMode, activityType)) { - return mLaunchRootTasks.get(i).task; + final Task launchRootTask = mLaunchRootTasks.get(i).task; + // Return the focusable root task for improving the UX with staged split screen. + final Task adjacentRootTask = launchRootTask != null + ? launchRootTask.mAdjacentTask : null; + if (adjacentRootTask != null && adjacentRootTask.isFocusedRootTaskOnDisplay()) { + return adjacentRootTask; + } else { + return launchRootTask; + } } } return null; diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskDisplayAreaTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskDisplayAreaTests.java index 9289ce41cd1e4..67b273a5a82d1 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TaskDisplayAreaTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/TaskDisplayAreaTests.java @@ -100,6 +100,29 @@ public class TaskDisplayAreaTests extends WindowTestsBase { assertNull(actualRootTask); } + @Test + public void getLaunchRootTask_checksFocusedRootTask() { + final TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea(); + final Task rootTask = createTaskWithActivity( + taskDisplayArea, + WINDOWING_MODE_MULTI_WINDOW, ACTIVITY_TYPE_STANDARD, ON_TOP, true); + rootTask.mCreatedByOrganizer = true; + + final Task adjacentRootTask = createTask( + mDisplayContent, WINDOWING_MODE_MULTI_WINDOW, ACTIVITY_TYPE_STANDARD); + adjacentRootTask.mCreatedByOrganizer = true; + adjacentRootTask.mAdjacentTask = rootTask; + rootTask.mAdjacentTask = adjacentRootTask; + + taskDisplayArea.setLaunchRootTask(rootTask, + new int[]{WINDOWING_MODE_MULTI_WINDOW}, new int[]{ACTIVITY_TYPE_STANDARD}); + + Task actualRootTask = taskDisplayArea.getLaunchRootTask( + WINDOWING_MODE_MULTI_WINDOW, ACTIVITY_TYPE_STANDARD, null /* options */, + null /* sourceTask */, 0 /*launchFlags*/); + assertTrue(actualRootTask.isFocusedRootTaskOnDisplay()); + } + @Test public void getLaunchRootTask_fromLaunchAdjacentFlagRoot_checksAdjacentRoot() { final ActivityRecord activity = createNonAttachedActivityRecord(mDisplayContent);