Merge "Update launch root rule to consider candidate task if needed" into tm-dev am: 5793f436ad

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17856863

Change-Id: I56a77ceccdd3d4e2b39dc66f3142c51cd88a76b5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
TreeHugger Robot
2022-04-28 05:18:06 +00:00
committed by Automerger Merge Worker
3 changed files with 54 additions and 6 deletions

View File

@@ -1724,8 +1724,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) {

View File

@@ -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);
@@ -1117,6 +1117,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());
@@ -1157,9 +1164,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;

View File

@@ -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());
}
}