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

Commit a862f525 authored by Lingyu Feng's avatar Lingyu Feng
Browse files

Rename TaskDisplayArea#remove()

Bug: 385263090
Test: TaskDisplayAreaTests DisplayAreaOrganizerTest
Flag: EXEMPT refactor
Change-Id: Iedc1a0c3405b653b1ba68dcd8f76327d512cb132
parent 310f7b88
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -366,10 +366,10 @@ public class DisplayAreaOrganizerController extends IDisplayAreaOrganizerControl
        taskDisplayArea.setOrganizer(null);
        mService.mRootWindowContainer.mTaskSupervisor.beginDeferResume();

        // TaskDisplayArea#remove() move the stacks to the default TaskDisplayArea.
        // TaskDisplayArea#remove() moves the stacks to the default TaskDisplayArea.
        Task lastReparentedRootTask;
        try {
            lastReparentedRootTask = taskDisplayArea.remove();
            lastReparentedRootTask = taskDisplayArea.prepareForRemoval();
        } finally {
            mService.mRootWindowContainer.mTaskSupervisor.endDeferResume();
        }
+7 −4
Original line number Diff line number Diff line
@@ -3262,7 +3262,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        mWmService.mDisplayWindowSettings.setShouldShowSystemDecorsLocked(this, shouldShow);

        if (!shouldShow) {
            clearAllTasksOnDisplay(null);
            clearAllTasksOnDisplay(null /* clearTasksCallback */, false /* isRemovingDisplay */);
        }
    }

@@ -6468,12 +6468,15 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        return mRemoving;
    }

    void clearAllTasksOnDisplay(@Nullable Runnable clearTasksCallback) {
    private void clearAllTasksOnDisplay(@Nullable Runnable clearTasksCallback,
            boolean isRemovingDisplay) {
        Task lastReparentedRootTask;
        mRootWindowContainer.mTaskSupervisor.beginDeferResume();
        try {
            lastReparentedRootTask = reduceOnAllTaskDisplayAreas((taskDisplayArea, rootTask) -> {
                final Task lastReparentedRootTaskFromArea = taskDisplayArea.remove();
                final Task lastReparentedRootTaskFromArea = isRemovingDisplay
                        ? taskDisplayArea.prepareForRemoval()
                        : taskDisplayArea.setShouldKeepNoTask(true);
                if (lastReparentedRootTaskFromArea != null) {
                    return lastReparentedRootTaskFromArea;
                }
@@ -6503,7 +6506,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
            if (mContentRecorder != null) {
                mContentRecorder.stopRecording();
            }
        });
        }, true /* isRemovingDisplay */);

        releaseSelfIfNeeded();
        mDisplayPolicy.release();
+2 −2
Original line number Diff line number Diff line
@@ -1407,8 +1407,8 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
        // When display content mode management flag is enabled, the task display area is marked as
        // removed when switching from extended display to mirroring display. We need to restart the
        // task display area before starting the home.
        if (enableDisplayContentModeManagement() && taskDisplayArea.isRemoved()) {
            taskDisplayArea.restart();
        if (enableDisplayContentModeManagement() && taskDisplayArea.shouldKeepNoTask()) {
            taskDisplayArea.setShouldKeepNoTask(false);
        }

        Intent homeIntent = null;
+33 −9
Original line number Diff line number Diff line
@@ -154,6 +154,14 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
     */
    private boolean mRemoved;

    /**
     * Whether the TaskDisplayArea has root tasks.
     * If {@code true}, the TaskDisplayArea cannot have a new task.
     *
     * TODO(b/394466501): Prevent a Task being added to the TaskDisplayArea that shouldKeepNoTask.
     */
    private boolean mShouldKeepNoTask;

    /**
     * The id of a leaf task that most recently being moved to front.
     */
@@ -1787,6 +1795,10 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
        return mRemoved;
    }

    boolean shouldKeepNoTask() {
        return mShouldKeepNoTask;
    }

    @Override
    boolean canCreateRemoteAnimationTarget() {
        // In the legacy transition system, promoting animation target from TaskFragment to
@@ -1812,12 +1824,31 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
        }
    }

    @Nullable
    Task prepareForRemoval() {
        mShouldKeepNoTask = true;
        final Task lastReparentedTask = removeAllTasks();
        mRemoved = true;
        return lastReparentedTask;
    }

    @Nullable
    Task setShouldKeepNoTask(boolean shouldKeepNoTask) {
        if (mShouldKeepNoTask == shouldKeepNoTask) {
            return null;
        }

        mShouldKeepNoTask = shouldKeepNoTask;
        return shouldKeepNoTask ? removeAllTasks() : null;
    }

    /**
     * Removes the root tasks in the node applying the content removal node from the display.
     *
     * @return last reparented root task, or {@code null} if the root tasks had to be destroyed.
     */
    Task remove() {
    @Nullable
    private Task removeAllTasks() {
        final TaskDisplayArea toDisplayArea = getReparentToTaskDisplayArea(getFocusedRootTask());
        mPreferredTopFocusableRootTask = null;
        // TODO(b/153090332): Allow setting content removal mode per task display area
@@ -1835,7 +1866,7 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
        for (int i = 0; i < numRootTasks; i++) {
            final WindowContainer child = mChildren.get(i);
            if (child.asTaskDisplayArea() != null) {
                lastReparentedRootTask = child.asTaskDisplayArea().remove();
                lastReparentedRootTask = child.asTaskDisplayArea().removeAllTasks();
                continue;
            }
            final Task task = mChildren.get(i).asTask();
@@ -1882,16 +1913,9 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
            lastReparentedRootTask.getRootTask().moveToFront("display-removed");
        }

        mRemoved = true;

        return lastReparentedRootTask;
    }

    // TODO(b/385263090): Remove this method
    void restart() {
        mRemoved = false;
    }

    /**
     * Returns the {@link TaskDisplayArea} to which root tasks should be reparented.
     *
+4 −2
Original line number Diff line number Diff line
@@ -223,9 +223,10 @@ public class DisplayAreaOrganizerTest extends WindowTestsBase {

        mOrganizerController.deleteTaskDisplayArea(newTda.mRemoteToken.toWindowContainerToken());

        verify(newTda).remove();
        verify(newTda).prepareForRemoval();
        verify(newTda).removeImmediately();
        assertThat(newTda.mOrganizer).isNull();
        assertThat(newTda.shouldKeepNoTask()).isTrue();
        assertThat(newTda.isRemoved()).isTrue();

        final TaskDisplayArea curTda = mDisplayContent.getItemFromDisplayAreas(
@@ -248,9 +249,10 @@ public class DisplayAreaOrganizerTest extends WindowTestsBase {

        mOrganizerController.unregisterOrganizer(organizer);

        verify(newTda).remove();
        verify(newTda).prepareForRemoval();
        verify(newTda).removeImmediately();
        assertThat(newTda.mOrganizer).isNull();
        assertThat(newTda.shouldKeepNoTask()).isTrue();
        assertThat(newTda.isRemoved()).isTrue();

        final TaskDisplayArea curTda = mDisplayContent.getItemFromDisplayAreas(
Loading