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

Commit 83fdc94d 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 tm-dev am: 5793f436

parents d14a09fc 5793f436
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
@@ -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;
+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());
    }
}