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

Commit 0e7aff96 authored by Yunfan Chen's avatar Yunfan Chen
Browse files

Remove TaskWindowContainerController & TaskWindowContainerListener (44/n)

Rename the TaskWindowContainerControllerTests to TaskTests and keep the
tests still make sense after removing the container.

TaskRecord and Task hold each other as a member. TaskRecord will create
Task while constructing.

Test: atest WmTests
Test: go/wm-smoke
Bug: 80414790
Change-Id: Iac9dc9cafdbb22ddbe325f8ff178874f3790f251
parent 52fe5dd9
Loading
Loading
Loading
Loading
+5 −8
Original line number Diff line number Diff line
@@ -1035,8 +1035,6 @@ final class ActivityRecord extends ConfigurationContainer {

        inHistory = true;

        final TaskWindowContainerController taskController = task.getWindowContainerController();

        // TODO(b/36505427): Maybe this call should be moved inside updateOverrideConfiguration()
        task.updateOverrideConfigurationFromLaunchBounds();
        // Make sure override configuration is up-to-date before using to create window controller.
@@ -1048,10 +1046,9 @@ final class ActivityRecord extends ConfigurationContainer {
            // TODO: Should this throw an exception instead?
            Slog.w(TAG, "Attempted to add existing app token: " + appToken);
        } else {
            final Task container = taskController.mContainer;
            final Task container = task.getTask();
            if (container == null) {
                throw new IllegalArgumentException("AppWindowContainerController: invalid "
                        + " controller=" + taskController);
                throw new IllegalArgumentException("createAppWindowToken: invalid task =" + task);
            }
            mAppWindowToken = createAppWindow(mAtmService.mWindowManager, appToken,
                    task.voiceSession != null, container.getDisplayContent(),
@@ -1062,7 +1059,7 @@ final class ActivityRecord extends ConfigurationContainer {
                    mLaunchTaskBehind, isAlwaysFocusable());
            if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) {
                Slog.v(TAG, "addAppToken: "
                        + mAppWindowToken + " controller=" + taskController + " at "
                        + mAppWindowToken + " task=" + container + " at "
                        + Integer.MAX_VALUE);
            }
            container.addChild(mAppWindowToken, Integer.MAX_VALUE /* add on top */);
@@ -1148,7 +1145,7 @@ final class ActivityRecord extends ConfigurationContainer {
                    + " r=" + this + " (" + prevTask.getStackId() + ")");
        }

        mAppWindowToken.reparent(newTask.getWindowContainerController(), position);
        mAppWindowToken.reparent(newTask.getTask(), position);

        // Reparenting prevents informing the parent stack of activity removal in the case that
        // the new stack has the same parent. we must manually signal here if this is not the case.
@@ -2774,7 +2771,7 @@ final class ActivityRecord extends ConfigurationContainer {
            final boolean hasResizeChange = hasResizeChange(changes & ~info.getRealConfigChanged());
            if (hasResizeChange) {
                final boolean isDragResizing =
                        getTaskRecord().getWindowContainerController().isDragResizing();
                        getTaskRecord().getTask().isDragResizing();
                mRelaunchReason = isDragResizing ? RELAUNCH_REASON_FREE_RESIZE
                        : RELAUNCH_REASON_WINDOWING_MODE_RESIZE;
            } else {
+4 −4
Original line number Diff line number Diff line
@@ -911,7 +911,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
    }

    void positionChildWindowContainerAtTop(TaskRecord child) {
        mWindowContainerController.positionChildAtTop(child.getWindowContainerController(),
        mWindowContainerController.positionChildAtTop(child.getTask(),
                true /* includingParents */);
    }

@@ -921,7 +921,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        // task to bottom, the next focusable stack on the same display should be focused.
        final ActivityStack nextFocusableStack = getDisplay().getNextFocusableStack(
                child.getStack(), true /* ignoreCurrent */);
        mWindowContainerController.positionChildAtBottom(child.getWindowContainerController(),
        mWindowContainerController.positionChildAtBottom(child.getTask(),
                nextFocusableStack == null /* includingParents */);
    }

@@ -2984,7 +2984,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        position = getAdjustedPositionForTask(task, position, null /* starting */);
        mTaskHistory.remove(task);
        mTaskHistory.add(position, task);
        mWindowContainerController.positionChildAt(task.getWindowContainerController(), position);
        mWindowContainerController.positionChildAt(task.getTask(), position);
        updateTaskMovement(task, true);
    }

@@ -5349,7 +5349,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
                && !matchParentBounds() && task.isResizeable() && !isLockscreenShown) {
            task.updateOverrideConfiguration(getRequestedOverrideBounds());
        }
        task.createWindowContainer(toTop, (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0);
        task.createTask(toTop, (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0);
        return task;
    }

+1 −1
Original line number Diff line number Diff line
@@ -1868,7 +1868,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {

        stack.addTask(task, onTop, "restoreRecentTask");
        // TODO: move call for creation here and other place into Stack.addTask()
        task.createWindowContainer(onTop, true /* showForAllUsers */);
        task.createTask(onTop, true /* showForAllUsers */);
        if (DEBUG_RECENTS) Slog.v(TAG_RECENTS,
                "Added restored task=" + task + " to stack=" + stack);
        final ArrayList<ActivityRecord> activities = task.mActivities;
+4 −10
Original line number Diff line number Diff line
@@ -1175,21 +1175,14 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
        }
    }

    void reparent(TaskWindowContainerController taskController, int position) {
    void reparent(Task task, int position) {
        if (DEBUG_ADD_REMOVE) {
            Slog.i(TAG_WM, "reparent: moving app token=" + this
                    + " to task=" + taskController + " at " + position);
                    + " to task=" + task.mTaskId + " at " + position);
        }
        final Task task = taskController.mContainer;
        if (task == null) {
            throw new IllegalArgumentException("reparent: could not find task="
                    + taskController);
        }
        reparent(task, position);
        getDisplayContent().layoutAndAssignWindowLayersIfNeeded();
            throw new IllegalArgumentException("reparent: could not find task");
        }

    void reparent(Task task, int position) {
        final Task currentTask = getTask();
        if (task == currentTask) {
            throw new IllegalArgumentException(
@@ -1220,6 +1213,7 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
            onDisplayChanged(displayContent);
            prevDisplayContent.setLayoutNeeded();
        }
        getDisplayContent().layoutAndAssignWindowLayersIfNeeded();
    }

    @Override
+137 −171
Original line number Diff line number Diff line
@@ -67,7 +67,6 @@ public class StackWindowController
        mStackId = stackId;
        mHandler = new H(new WeakReference<>(this), service.mH.getLooper());

        synchronized (mGlobalLock) {
        final DisplayContent dc = mRoot.getDisplayContent(displayId);
        if (dc == null) {
            throw new IllegalArgumentException("Trying to add stackId=" + stackId
@@ -77,20 +76,16 @@ public class StackWindowController
        dc.createStack(stackId, onTop, this);
        getRawBounds(outBounds);
    }
    }

    @Override
    public void removeContainer() {
        synchronized (mGlobalLock) {
        if (mContainer != null) {
            mContainer.removeIfPossible();
            super.removeContainer();
        }
    }
    }

    public void reparent(int displayId, Rect outStackBounds, boolean onTop) {
        synchronized (mGlobalLock) {
    void reparent(int displayId, Rect outStackBounds, boolean onTop) {
        if (mContainer == null) {
            throw new IllegalArgumentException("Trying to move unknown stackId=" + mStackId
                    + " to displayId=" + displayId);
@@ -105,70 +100,55 @@ public class StackWindowController
        targetDc.moveStackToDisplay(mContainer, onTop);
        getRawBounds(outStackBounds);
    }
    }

    public void positionChildAt(TaskWindowContainerController child, int position) {
        synchronized (mGlobalLock) {
            if (DEBUG_STACK) Slog.i(TAG_WM, "positionChildAt: positioning task=" + child
                    + " at " + position);
            if (child.mContainer == null) {
                if (DEBUG_STACK) Slog.i(TAG_WM,
                        "positionChildAt: could not find task=" + this);
    void positionChildAt(Task child, int position) {
        if (DEBUG_STACK) {
            Slog.i(TAG_WM, "positionChildAt: positioning task=" + child + " at " + position);
        }
        if (child == null) {
            if (DEBUG_STACK) {
                Slog.i(TAG_WM, "positionChildAt: could not find task=" + this);
            }
            return;
        }
        if (mContainer == null) {
                if (DEBUG_STACK) Slog.i(TAG_WM,
                        "positionChildAt: could not find stack for task=" + mContainer);
            if (DEBUG_STACK) {
                Slog.i(TAG_WM, "positionChildAt: could not find stack for task=" + mContainer);
            }
            return;
        }
            child.mContainer.positionAt(position);
        child.positionAt(position);
        mContainer.getDisplayContent().layoutAndAssignWindowLayersIfNeeded();
    }
    }

    public void positionChildAtTop(TaskWindowContainerController child, boolean includingParents) {
    void positionChildAtTop(Task child, boolean includingParents) {
        if (child == null) {
            // TODO: Fix the call-points that cause this to happen.
            return;
        }

        synchronized (mGlobalLock) {
            final Task childTask = child.mContainer;
            if (childTask == null) {
                Slog.e(TAG_WM, "positionChildAtTop: task=" + child + " not found");
                return;
            }
            mContainer.positionChildAt(POSITION_TOP, childTask, includingParents);
        mContainer.positionChildAt(POSITION_TOP, child, includingParents);

        final DisplayContent displayContent = mContainer.getDisplayContent();
        if (displayContent.mAppTransition.isTransitionSet()) {
                childTask.setSendingToBottom(false);
            child.setSendingToBottom(false);
        }
        displayContent.layoutAndAssignWindowLayersIfNeeded();
    }
    }

    public void positionChildAtBottom(TaskWindowContainerController child,
            boolean includingParents) {
    void positionChildAtBottom(Task child, boolean includingParents) {
        if (child == null) {
            // TODO: Fix the call-points that cause this to happen.
            return;
        }

        synchronized (mGlobalLock) {
            final Task childTask = child.mContainer;
            if (childTask == null) {
                Slog.e(TAG_WM, "positionChildAtBottom: task=" + child + " not found");
                return;
            }
            mContainer.positionChildAt(POSITION_BOTTOM, childTask, includingParents);
        mContainer.positionChildAt(POSITION_BOTTOM, child, includingParents);

        if (mContainer.getDisplayContent().mAppTransition.isTransitionSet()) {
                childTask.setSendingToBottom(true);
            child.setSendingToBottom(true);
        }
        mContainer.getDisplayContent().layoutAndAssignWindowLayersIfNeeded();
    }
    }

    /**
     * Re-sizes a stack and its containing tasks.
@@ -179,7 +159,6 @@ public class StackWindowController
     */
    public void resize(Rect bounds, SparseArray<Rect> taskBounds,
            SparseArray<Rect> taskTempInsetBounds) {
        synchronized (mGlobalLock) {
        if (mContainer == null) {
            throw new IllegalArgumentException("resizeStack: stack " + this + " not found.");
        }
@@ -191,13 +170,10 @@ public class StackWindowController
            mService.mWindowPlacerLocked.performSurfacePlacement();
        }
    }
    }

    public void onPipAnimationEndResize() {
        synchronized (mService.mGlobalLock) {
        mContainer.onPipAnimationEndResize();
    }
    }

    /**
     * @see TaskStack.getStackDockedModeBoundsLocked(ConfigurationContainer, Rect, Rect, Rect)
@@ -205,7 +181,6 @@ public class StackWindowController
    public void getStackDockedModeBounds(Configuration parentConfig, Rect dockedBounds,
            Rect currentTempTaskBounds,
            Rect outStackBounds, Rect outTempTaskBounds) {
        synchronized (mGlobalLock) {
        if (mContainer != null) {
            mContainer.getStackDockedModeBoundsLocked(parentConfig, dockedBounds,
                    currentTempTaskBounds, outStackBounds, outTempTaskBounds);
@@ -214,37 +189,30 @@ public class StackWindowController
        outStackBounds.setEmpty();
        outTempTaskBounds.setEmpty();
    }
    }

    public void prepareFreezingTaskBounds() {
        synchronized (mGlobalLock) {
        if (mContainer == null) {
            throw new IllegalArgumentException("prepareFreezingTaskBounds: stack " + this
                    + " not found.");
        }
        mContainer.prepareFreezingTaskBounds();
    }
    }

    public void getRawBounds(Rect outBounds) {
        synchronized (mGlobalLock) {
        if (mContainer.matchParentBounds()) {
            outBounds.setEmpty();
        } else {
            mContainer.getRawBounds(outBounds);
        }
    }
    }

    public void getBounds(Rect outBounds) {
        synchronized (mGlobalLock) {
        if (mContainer != null) {
            mContainer.getBounds(outBounds);
            return;
        }
        outBounds.setEmpty();
    }
    }

    /**
     * Adjusts the screen size in dp's for the {@param config} for the given params. The provided
@@ -256,7 +224,6 @@ public class StackWindowController
            Rect nonDecorBounds, Rect stableBounds, boolean overrideWidth,
            boolean overrideHeight, float density, Configuration config,
            Configuration parentConfig, int windowingMode) {
        synchronized (mGlobalLock) {
        final TaskStack stack = mContainer;
        final DisplayContent displayContent = stack.getDisplayContent();
        final DisplayInfo di = displayContent.getDisplayInfo();
@@ -323,7 +290,6 @@ public class StackWindowController
        config.smallestScreenWidthDp = getSmallestWidthForTaskBounds(
                bounds, density, windowingMode);
    }
    }

    /**
     * Intersects the specified {@code inOutBounds} with the display frame that excludes the stable
Loading