Merge "Update launch root rule to consider candidate task if needed" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
5793f436ad
@@ -1724,8 +1724,8 @@ class Task extends TaskFragment {
|
|||||||
/** Returns {@code true} if this task is currently in split-screen. */
|
/** Returns {@code true} if this task is currently in split-screen. */
|
||||||
boolean inSplitScreen() {
|
boolean inSplitScreen() {
|
||||||
return getWindowingMode() == WINDOWING_MODE_MULTI_WINDOW
|
return getWindowingMode() == WINDOWING_MODE_MULTI_WINDOW
|
||||||
&& getRootTask() != null
|
&& getCreatedByOrganizerTask() != null
|
||||||
&& getRootTask().getAdjacentTaskFragment() != null;
|
&& getCreatedByOrganizerTask().getAdjacentTaskFragment() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean supportsSplitScreenWindowingModeInner(@Nullable TaskDisplayArea tda) {
|
private boolean supportsSplitScreenWindowingModeInner(@Nullable TaskDisplayArea tda) {
|
||||||
|
|||||||
@@ -963,7 +963,7 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
|
|||||||
} else if (candidateTask != null) {
|
} else if (candidateTask != null) {
|
||||||
final int position = onTop ? POSITION_TOP : POSITION_BOTTOM;
|
final int position = onTop ? POSITION_TOP : POSITION_BOTTOM;
|
||||||
final Task launchRootTask = getLaunchRootTask(resolvedWindowingMode, activityType,
|
final Task launchRootTask = getLaunchRootTask(resolvedWindowingMode, activityType,
|
||||||
options, sourceTask, launchFlags);
|
options, sourceTask, launchFlags, candidateTask);
|
||||||
if (launchRootTask != null) {
|
if (launchRootTask != null) {
|
||||||
if (candidateTask.getParent() == null) {
|
if (candidateTask.getParent() == null) {
|
||||||
launchRootTask.addChild(candidateTask, position);
|
launchRootTask.addChild(candidateTask, position);
|
||||||
@@ -1117,6 +1117,13 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
|
|||||||
@Nullable
|
@Nullable
|
||||||
Task getLaunchRootTask(int windowingMode, int activityType, @Nullable ActivityOptions options,
|
Task getLaunchRootTask(int windowingMode, int activityType, @Nullable ActivityOptions options,
|
||||||
@Nullable Task sourceTask, int launchFlags) {
|
@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.
|
// Try to use the launch root task in options if available.
|
||||||
if (options != null) {
|
if (options != null) {
|
||||||
final Task launchRootTask = Task.fromWindowContainerToken(options.getLaunchRootTask());
|
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
|
// 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.
|
// be launched into the same created-by-organizer task as well. Unless, the candidate task
|
||||||
if (sourceTask != null) {
|
// is already positioned in the split.
|
||||||
return sourceTask.getCreatedByOrganizerTask();
|
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;
|
return null;
|
||||||
|
|||||||
@@ -741,4 +741,35 @@ public class TaskDisplayAreaTests extends WindowTestsBase {
|
|||||||
assertEquals(isAssistantOnTop ? topPosition : topPosition - 4,
|
assertEquals(isAssistantOnTop ? topPosition : topPosition - 4,
|
||||||
getTaskIndexOf(taskDisplayArea, assistRootTask));
|
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