Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cb2cd48f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Update launch root rule to consider candidate task if needed" into...

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

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



Change-Id: Ib4c8d8a4e8b46fe8948103ecc30bf62c11b43120
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 077fa031 83fdc94d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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) {
+21 −4
Original line number Diff line number Diff line
@@ -965,7 +965,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);
@@ -1119,6 +1119,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());
@@ -1159,9 +1166,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;
+31 −0
Original line number Diff line number Diff line
@@ -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());
    }
}