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

Commit 535c86be authored by Chris Li's avatar Chris Li
Browse files

Remove TaskDisplayArea#getTaskIndexOf()

Fix: 175832855
Test: pass existing tests
Change-Id: I95a613e9c187a638dcb7359befefa1901fd2395f
parent 85b5b041
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -2422,12 +2422,27 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
    }

    private RootTaskInfo getRootTaskInfo(Task task) {
        final TaskDisplayArea taskDisplayArea = task.getDisplayArea();
        RootTaskInfo info = new RootTaskInfo();
        task.fillTaskInfo(info);

        final DisplayContent displayContent = task.getDisplayContent();
        if (displayContent == null) {
            // A task might be not attached to a display.
        info.position = taskDisplayArea != null ? taskDisplayArea.getTaskIndexOf(task) : 0;
            info.position = -1;
        } else {
            // Find the task z-order among all root tasks on the display from bottom to top.
            final int[] taskIndex = new int[1];
            final boolean[] hasFound = new boolean[1];
            displayContent.forAllRootTasks(rootTask -> {
                if (task == rootTask) {
                    hasFound[0] = true;
                    return true;
                }
                taskIndex[0]++;
                return false;
            }, false /* traverseTopToBottom */);
            info.position = hasFound[0] ? taskIndex[0] : -1;
        }
        info.visible = task.shouldBeVisible(null);
        task.getBounds(info.bounds);

+13 −8
Original line number Diff line number Diff line
@@ -6734,15 +6734,20 @@ class Task extends WindowContainer<WindowContainer> {
        if (taskDisplayArea == null) {
            return false;
        }
        final int index = taskDisplayArea.getTaskIndexOf(this);
        if (index == 0) {
            return false;
        }
        final int[] indexCount = new int[1];
        final boolean[] hasFound = new boolean[1];
        final Task rootTaskBehind = taskDisplayArea.getRootTask(
                // From bottom to top, find the one behind this Task.
                task -> ++indexCount[0] == index, false /* traverseTopToBottom */);
        return rootTaskBehind.isActivityTypeStandard();
                // From top to bottom, find the one behind this Task.
                task -> {
                    if (hasFound[0]) {
                        return true;
                    }
                    if (task == this) {
                        // The next one is our target.
                        hasFound[0] = true;
                    }
                    return false;
                });
        return rootTaskBehind != null && rootTaskBehind.isActivityTypeStandard();
    }

    boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) {
+0 −28
Original line number Diff line number Diff line
@@ -212,34 +212,6 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
        return getRootTask(t -> true);
    }

    // TODO(b/175832855): Figure-out a way to remove since it might be a source of confusion.
    /**
     * Gets the order of the given {@link Task} as its z-order in the hierarchy below this TDA.
     * The Task can be a direct child of a child TaskDisplayArea. {@code -1} if not found.
     */
    int getTaskIndexOf(Task task) {
        int index = 0;
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final WindowContainer wc = getChildAt(i);
            if (wc.asTask() != null) {
                if (wc.asTask() == task) {
                    return index;
                }
                index++;
            } else {
                final TaskDisplayArea tda = wc.asTaskDisplayArea();
                final int subIndex = tda.getTaskIndexOf(task);
                if (subIndex > -1) {
                    return index + subIndex;
                } else {
                    index += tda.getRootTaskCount();
                }
            }
        }
        return -1;
    }

    @Nullable
    Task getRootHomeTask() {
        return mRootHomeTask;
+2 −2
Original line number Diff line number Diff line
@@ -1677,13 +1677,13 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
        int count = mChildren.size();
        if (traverseTopToBottom) {
            for (int i = count - 1; i >= 0; --i) {
                if (mChildren.get(i).forAllRootTasks(callback)) {
                if (mChildren.get(i).forAllRootTasks(callback, traverseTopToBottom)) {
                    return true;
                }
            }
        } else {
            for (int i = 0; i < count; i++) {
                if (mChildren.get(i).forAllRootTasks(callback)) {
                if (mChildren.get(i).forAllRootTasks(callback, traverseTopToBottom)) {
                    return true;
                }
                // Root tasks may be removed from this display. Ensure each task will be processed
+7 −7
Original line number Diff line number Diff line
@@ -248,7 +248,7 @@ public class ActivityDisplayTests extends WindowTestsBase {
        int topPosition = taskDisplayArea.getRootTaskCount() - 1;
        // Ensure the new alwaysOnTop stack is put below the pinned stack, but on top of the
        // existing alwaysOnTop stack.
        assertEquals(topPosition - 1, taskDisplayArea.getTaskIndexOf(anotherAlwaysOnTopStack));
        assertEquals(topPosition - 1, getTaskIndexOf(taskDisplayArea, anotherAlwaysOnTopStack));

        final Task nonAlwaysOnTopStack = taskDisplayArea.createRootTask(
                WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD, true /* onTop */);
@@ -256,7 +256,7 @@ public class ActivityDisplayTests extends WindowTestsBase {
        topPosition = taskDisplayArea.getRootTaskCount() - 1;
        // Ensure the non-alwaysOnTop stack is put below the three alwaysOnTop stacks, but above the
        // existing other non-alwaysOnTop stacks.
        assertEquals(topPosition - 3, taskDisplayArea.getTaskIndexOf(nonAlwaysOnTopStack));
        assertEquals(topPosition - 3, getTaskIndexOf(taskDisplayArea, nonAlwaysOnTopStack));

        anotherAlwaysOnTopStack.setAlwaysOnTop(false);
        taskDisplayArea.positionChildAt(POSITION_TOP, anotherAlwaysOnTopStack,
@@ -264,16 +264,16 @@ public class ActivityDisplayTests extends WindowTestsBase {
        assertFalse(anotherAlwaysOnTopStack.isAlwaysOnTop());
        // Ensure, when always on top is turned off for a stack, the stack is put just below all
        // other always on top stacks.
        assertEquals(topPosition - 2, taskDisplayArea.getTaskIndexOf(anotherAlwaysOnTopStack));
        assertEquals(topPosition - 2, getTaskIndexOf(taskDisplayArea, anotherAlwaysOnTopStack));
        anotherAlwaysOnTopStack.setAlwaysOnTop(true);

        // Ensure always on top state changes properly when windowing mode changes.
        anotherAlwaysOnTopStack.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
        assertFalse(anotherAlwaysOnTopStack.isAlwaysOnTop());
        assertEquals(topPosition - 2, taskDisplayArea.getTaskIndexOf(anotherAlwaysOnTopStack));
        assertEquals(topPosition - 2, getTaskIndexOf(taskDisplayArea, anotherAlwaysOnTopStack));
        anotherAlwaysOnTopStack.setWindowingMode(WINDOWING_MODE_FREEFORM);
        assertTrue(anotherAlwaysOnTopStack.isAlwaysOnTop());
        assertEquals(topPosition - 1, taskDisplayArea.getTaskIndexOf(anotherAlwaysOnTopStack));
        assertEquals(topPosition - 1, getTaskIndexOf(taskDisplayArea, anotherAlwaysOnTopStack));

        final Task dreamStack = taskDisplayArea.createRootTask(
                WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_DREAM, true /* onTop */);
@@ -282,7 +282,7 @@ public class ActivityDisplayTests extends WindowTestsBase {
        topPosition = taskDisplayArea.getRootTaskCount() - 1;
        // Ensure dream shows above all activities, including PiP
        assertEquals(dreamStack, taskDisplayArea.getTopRootTask());
        assertEquals(topPosition - 1, taskDisplayArea.getTaskIndexOf(pinnedStack));
        assertEquals(topPosition - 1, getTaskIndexOf(taskDisplayArea, pinnedStack));

        final Task assistStack = taskDisplayArea.createRootTask(
                WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_ASSISTANT, true /* onTop */);
@@ -295,7 +295,7 @@ public class ActivityDisplayTests extends WindowTestsBase {
        final boolean isAssistantOnTop = mContext.getResources()
                .getBoolean(com.android.internal.R.bool.config_assistantOnTopOfDream);
        assertEquals(isAssistantOnTop ? topPosition : topPosition - 4,
                taskDisplayArea.getTaskIndexOf(assistStack));
                getTaskIndexOf(taskDisplayArea, assistStack));
    }

    @Test
Loading