Update launch root rule to consider candidate task if needed
Bbcd34357, changed the rule for evaluating the root task while
dealing with the candidate task. The source task of the
created-by-organizer parent is considered as the default root task.
The rule changes the behavior in split-screen cases.
This CL considers the candidate task in priority for split-screen as
before.
Bug: 227473044
Test: atest MultiWindowTests
atest TaskDisplayAreaTests
Change-Id: Ibb75ab0311550d1093c878500e4671f569977753
This commit is contained in:
@@ -1718,8 +1718,8 @@ class Task extends TaskFragment {
|
||||
/** Returns {@code true} if this task is currently in split-screen. */
|
||||
boolean inSplitScreen() {
|
||||
return getWindowingMode() == WINDOWING_MODE_MULTI_WINDOW
|
||||
&& getRootTask() != null
|
||||
&& getRootTask().getAdjacentTaskFragment() != null;
|
||||
&& getCreatedByOrganizerTask() != null
|
||||
&& getCreatedByOrganizerTask().getAdjacentTaskFragment() != null;
|
||||
}
|
||||
|
||||
private boolean supportsSplitScreenWindowingModeInner(@Nullable TaskDisplayArea tda) {
|
||||
|
||||
@@ -963,7 +963,7 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
|
||||
} else if (candidateTask != null) {
|
||||
final int position = onTop ? POSITION_TOP : POSITION_BOTTOM;
|
||||
final Task launchRootTask = getLaunchRootTask(resolvedWindowingMode, activityType,
|
||||
options, sourceTask, launchFlags);
|
||||
options, sourceTask, launchFlags, candidateTask);
|
||||
if (launchRootTask != null) {
|
||||
if (candidateTask.getParent() == null) {
|
||||
launchRootTask.addChild(candidateTask, position);
|
||||
@@ -1112,6 +1112,13 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
|
||||
@Nullable
|
||||
Task getLaunchRootTask(int windowingMode, int activityType, @Nullable ActivityOptions options,
|
||||
@Nullable Task sourceTask, int launchFlags) {
|
||||
return getLaunchRootTask(windowingMode, activityType, options, sourceTask, launchFlags,
|
||||
null /* candidateTask */);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
Task getLaunchRootTask(int windowingMode, int activityType, @Nullable ActivityOptions options,
|
||||
@Nullable Task sourceTask, int launchFlags, @Nullable Task candidateTask) {
|
||||
// Try to use the launch root task in options if available.
|
||||
if (options != null) {
|
||||
final Task launchRootTask = Task.fromWindowContainerToken(options.getLaunchRootTask());
|
||||
@@ -1152,9 +1159,19 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
|
||||
}
|
||||
|
||||
// For a better split UX, If a task is launching from a created-by-organizer task, it should
|
||||
// be launched into the same created-by-organizer task as well.
|
||||
if (sourceTask != null) {
|
||||
return sourceTask.getCreatedByOrganizerTask();
|
||||
// be launched into the same created-by-organizer task as well. Unless, the candidate task
|
||||
// is already positioned in the split.
|
||||
Task preferredRootInSplit = sourceTask != null && sourceTask.inSplitScreen()
|
||||
? sourceTask.getCreatedByOrganizerTask() : null;
|
||||
if (preferredRootInSplit != null) {
|
||||
if (candidateTask != null) {
|
||||
final Task candidateRoot = candidateTask.getCreatedByOrganizerTask();
|
||||
if (candidateRoot != null && candidateRoot != preferredRootInSplit
|
||||
&& preferredRootInSplit == candidateRoot.getAdjacentTaskFragment()) {
|
||||
preferredRootInSplit = candidateRoot;
|
||||
}
|
||||
}
|
||||
return preferredRootInSplit;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -741,4 +741,35 @@ public class TaskDisplayAreaTests extends WindowTestsBase {
|
||||
assertEquals(isAssistantOnTop ? topPosition : topPosition - 4,
|
||||
getTaskIndexOf(taskDisplayArea, assistRootTask));
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verifies proper launch root based on source and candidate task for split screen.
|
||||
* If a task is launching from a created-by-organizer task, it should be launched into the
|
||||
* same created-by-organizer task as well. Unless, the candidate task is already positioned in
|
||||
* the split.
|
||||
*/
|
||||
@Test
|
||||
public void getLaunchRootTaskInSplit() {
|
||||
final Task rootTask = createTask(
|
||||
mDisplayContent, WINDOWING_MODE_MULTI_WINDOW, ACTIVITY_TYPE_STANDARD);
|
||||
rootTask.mCreatedByOrganizer = true;
|
||||
final Task adjacentRootTask = createTask(
|
||||
mDisplayContent, WINDOWING_MODE_MULTI_WINDOW, ACTIVITY_TYPE_STANDARD);
|
||||
adjacentRootTask.mCreatedByOrganizer = true;
|
||||
final Task candidateTask = createTaskInRootTask(rootTask, 0 /* userId*/);
|
||||
final TaskDisplayArea taskDisplayArea = rootTask.getDisplayArea();
|
||||
adjacentRootTask.setAdjacentTaskFragment(rootTask, false /* moveTogether */);
|
||||
|
||||
// Verify the launch root with candidate task
|
||||
Task actualRootTask = taskDisplayArea.getLaunchRootTask(WINDOWING_MODE_UNDEFINED,
|
||||
ACTIVITY_TYPE_STANDARD, null /* options */, adjacentRootTask /* sourceTask */,
|
||||
0 /* launchFlags */, candidateTask);
|
||||
assertSame(rootTask, actualRootTask.getRootTask());
|
||||
|
||||
// Verify the launch root task without candidate task
|
||||
actualRootTask = taskDisplayArea.getLaunchRootTask(WINDOWING_MODE_UNDEFINED,
|
||||
ACTIVITY_TYPE_STANDARD, null /* options */, adjacentRootTask /* sourceTask */,
|
||||
0 /* launchFlags */);
|
||||
assertSame(adjacentRootTask, actualRootTask.getRootTask());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user