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

Commit 63537674 authored by Louis Chang's avatar Louis Chang
Browse files

Merge #positionStackAt() into #positionChildAt()

Remove several #positionStackAt..() methods and use
#positionChildAt() instead.

Bug: 160655575
Test: existing test pass
Change-Id: Ic1d6d77b0d71b212a6e7a2ed47b39a9b74e00c22
parent bde58d21
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2829,7 +2829,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        }

        if (toTop) {
            taskDisplayArea.positionStackAt(POSITION_TOP, primarySplitTask,
            taskDisplayArea.positionChildAt(POSITION_TOP, primarySplitTask,
                    false /* includingParents */);
        }
        WindowContainerTransaction wct = new WindowContainerTransaction();
+1 −1
Original line number Diff line number Diff line
@@ -368,7 +368,7 @@ public abstract class ConfigurationContainer<E extends ConfigurationContainer> {
    /** Sets the always on top flag for this configuration container.
     *  When you call this function, make sure that the following functions are called as well to
     *  keep proper z-order.
     *  - {@Link DisplayContent#positionStackAt(POSITION_TOP, TaskStack)};
     *  - {@link TaskDisplayArea#positionChildAt(int POSITION_TOP, Task, boolean)};
     * */
    public void setAlwaysOnTop(boolean alwaysOnTop) {
        mRequestsTmpConfig.setTo(getRequestedOverrideConfiguration());
+7 −5
Original line number Diff line number Diff line
@@ -2459,7 +2459,7 @@ class Task extends WindowContainer<WindowContainer> {
            // Since always on top is only on when the stack is freeform or pinned, the state
            // can be toggled when the windowing mode changes. We must make sure the stack is
            // placed properly when always on top state changes.
            taskDisplayArea.positionStackAtTop(this, false /* includingParents */);
            taskDisplayArea.positionChildAt(POSITION_TOP, this, false /* includingParents */);
        }
    }

@@ -5340,7 +5340,8 @@ class Task extends WindowContainer<WindowContainer> {
        }

        if (isRootTask()) {
            taskDisplayArea.positionStackAtTop(this, false /* includingParents */, reason);
            taskDisplayArea.positionChildAt(POSITION_TOP, this, false /* includingParents */,
                    reason);
        }
        if (task == null) {
            task = this;
@@ -5368,7 +5369,8 @@ class Task extends WindowContainer<WindowContainer> {
            if (parentTask != null) {
                parentTask.moveToBack(reason, this);
            } else {
                displayArea.positionStackAtBottom(this, reason);
                displayArea.positionChildAt(POSITION_BOTTOM, this, false /*includingParents*/,
                        reason);
            }
            if (task != null && task != this) {
                positionChildAtBottom(task);
@@ -7448,7 +7450,7 @@ class Task extends WindowContainer<WindowContainer> {
        // always on top windows. Since the position the stack should be inserted into is calculated
        // properly in {@link DisplayContent#getTopInsertPosition()} in both cases, we can just
        // request that the stack is put at top here.
        taskDisplayArea.positionStackAtTop(this, false /* includingParents */);
        taskDisplayArea.positionChildAt(POSITION_TOP, this, false /* includingParents */);
    }

    /** NOTE: Should only be called from {@link Task#reparent}. */
@@ -7493,7 +7495,7 @@ class Task extends WindowContainer<WindowContainer> {
            final Task task = getBottomMostTask();
            setWindowingMode(WINDOWING_MODE_UNDEFINED);

            getDisplayArea().positionStackAtTop(this, false /* includingParents */);
            getDisplayArea().positionChildAt(POSITION_TOP, this, false /* includingParents */);

            mStackSupervisor.scheduleUpdatePictureInPictureModeIfNeeded(task, this);
            MetricsLoggerWrapper.logPictureInPictureFullScreen(mAtmService.mContext,
+47 −89
Original line number Diff line number Diff line
@@ -303,15 +303,18 @@ final class TaskDisplayArea extends DisplayArea<Task> {
    }

    @Override
    void addChild(Task stack, int position) {
        if (DEBUG_STACK) Slog.d(TAG_WM, "Set stack=" + stack + " on taskDisplayArea=" + this);
        addStackReferenceIfNeeded(stack);
        position = findPositionForStack(position, stack, true /* adding */);
    void addChild(Task task, int position) {
        if (DEBUG_STACK) Slog.d(TAG_WM, "Set task=" + task + " on taskDisplayArea=" + this);
        if (mDisplayContent.mSingleTaskInstance && getStackCount() == 1) {
            throw new IllegalStateException("addChild: Can only have one task on display=" + this);
        }

        super.addChild(stack, position);
        mAtmService.updateSleepIfNeededLocked();
        addStackReferenceIfNeeded(task);
        position = findPositionForStack(position, task, true /* adding */);

        positionStackAt(stack, position);
        super.addChild(task, position);
        mAtmService.updateSleepIfNeededLocked();
        onStackOrderChanged(task);
    }

    @Override
@@ -328,19 +331,42 @@ final class TaskDisplayArea extends DisplayArea<Task> {
        return true;
    }

    void positionChildAt(int position, Task child, boolean includingParents,
            String updateLastFocusedTaskReason) {
        final Task prevFocusedTask = updateLastFocusedTaskReason != null ? getFocusedStack() : null;

        positionChildAt(position, child, includingParents);

        if (updateLastFocusedTaskReason == null) {
            return;
        }

        final Task currentFocusedStack = getFocusedStack();
        if (currentFocusedStack == prevFocusedTask) {
            return;
        }

        mLastFocusedStack = prevFocusedTask;
        EventLogTags.writeWmFocusedStack(mRootWindowContainer.mCurrentUser,
                mDisplayContent.mDisplayId,
                currentFocusedStack == null ? -1 : currentFocusedStack.getRootTaskId(),
                mLastFocusedStack == null ? -1 : mLastFocusedStack.getRootTaskId(),
                updateLastFocusedTaskReason);
    }

    @Override
    void positionChildAt(int position, Task child, boolean includingParents) {
        final boolean moveToTop = position >= getChildCount() - 1;
        final boolean moveToBottom = position <= 0;

        final int oldPosition = mChildren.indexOf(child);
        if (child.getWindowConfiguration().isAlwaysOnTop() && !moveToTop) {
            // This stack is always-on-top, override the default behavior.
            Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");

            // Moving to its current position, as we must call super but we don't want to
            // perform any meaningful action.
            final int currentPosition = mChildren.indexOf(child);
            super.positionChildAt(currentPosition, child, false /* includingParents */);
            super.positionChildAt(oldPosition, child, false /* includingParents */);
            return;
        }
        // We don't allow untrusted display to top when task stack moves to top,
@@ -358,7 +384,7 @@ final class TaskDisplayArea extends DisplayArea<Task> {

        child.updateTaskMovement(moveToTop);

        mDisplayContent.setLayoutNeeded();
        mDisplayContent.layoutAndAssignWindowLayersIfNeeded();

        // The insert position may be adjusted to non-top when there is always-on-top stack. Since
        // the original position is preferred to be top, the stack should have higher priority when
@@ -373,6 +399,10 @@ final class TaskDisplayArea extends DisplayArea<Task> {

        // Update the top resumed activity because the preferred top focusable task may be changed.
        mAtmService.mStackSupervisor.updateTopResumedActivityIfNeeded();

        if (mChildren.indexOf(child) != oldPosition) {
            onStackOrderChanged(child);
        }
    }

    @Override
@@ -800,66 +830,6 @@ final class TaskDisplayArea extends DisplayArea<Task> {
        }
    }

    void positionStackAt(int position, Task child, boolean includingParents) {
        positionChildAt(position, child, includingParents);
        mDisplayContent.layoutAndAssignWindowLayersIfNeeded();
    }

    void positionStackAtTop(Task stack, boolean includingParents) {
        positionStackAtTop(stack, includingParents, null /* updateLastFocusedStackReason */);
    }

    void positionStackAtTop(Task stack, boolean includingParents,
            String updateLastFocusedStackReason) {
        positionStackAt(stack, getStackCount(), includingParents,
                updateLastFocusedStackReason);
    }

    void positionStackAtBottom(Task stack) {
        positionStackAtBottom(stack, null /* updateLastFocusedStackReason */);
    }

    void positionStackAtBottom(Task stack, String updateLastFocusedStackReason) {
        positionStackAt(stack, 0, false /* includingParents */,
                updateLastFocusedStackReason);
    }

    void positionStackAt(Task stack, int position) {
        positionStackAt(stack, position, false /* includingParents */,
                null /* updateLastFocusedStackReason */);
    }

    void positionStackAt(Task stack, int position, boolean includingParents,
            String updateLastFocusedStackReason) {
        // TODO: Keep in sync with WindowContainer.positionChildAt(), once we change that to adjust
        //       the position internally, also update the logic here
        final Task prevFocusedStack = updateLastFocusedStackReason != null
                ? getFocusedStack() : null;
        final boolean wasContained = mChildren.contains(stack);
        if (mDisplayContent.mSingleTaskInstance && getStackCount() == 1 && !wasContained) {
            throw new IllegalStateException(
                    "positionStackAt: Can only have one task on display=" + this);
        }

        // Since positionChildAt() is called during the creation process of pinned stacks,
        // ActivityStack#getStack() can be null.
        positionStackAt(position, stack, includingParents);

        if (updateLastFocusedStackReason != null) {
            final Task currentFocusedStack = getFocusedStack();
            if (currentFocusedStack != prevFocusedStack) {
                mLastFocusedStack = prevFocusedStack;
                EventLogTags.writeWmFocusedStack(mRootWindowContainer.mCurrentUser,
                        mDisplayContent.mDisplayId,
                        currentFocusedStack == null ? -1 : currentFocusedStack.getRootTaskId(),
                        mLastFocusedStack == null ? -1 : mLastFocusedStack.getRootTaskId(),
                        updateLastFocusedStackReason);
            }
        }

        onStackOrderChanged(stack);
    }

    /**
     * Moves/reparents `task` to the back of whatever container the home stack is in. This is for
     * when we just want to move a task to "the back" vs. a specific place. The primary use-case
@@ -872,7 +842,7 @@ final class TaskDisplayArea extends DisplayArea<Task> {
        if (homeParentTask == null) {
            // reparent throws if parent didn't change...
            if (task.getParent() == this) {
                positionStackAtBottom(task);
                positionChildAt(POSITION_BOTTOM, task, false /*includingParents*/);
            } else {
                task.reparent(this, false /* onTop */);
            }
@@ -1091,7 +1061,7 @@ final class TaskDisplayArea extends DisplayArea<Task> {
        if (launchRootTask != null) {
            launchRootTask.addChild(stack, onTop ? POSITION_TOP : POSITION_BOTTOM);
            if (onTop) {
                positionStackAtTop(launchRootTask, false /* includingParents */);
                positionChildAt(POSITION_TOP, launchRootTask, false /* includingParents */);
            }
        } else {
            addChild(stack, onTop ? POSITION_TOP : POSITION_BOTTOM);
@@ -1666,15 +1636,11 @@ final class TaskDisplayArea extends DisplayArea<Task> {
            return;
        }

        final boolean isRootTask = stack.isRootTask();
        if (isRootTask) {
        // Move the stack to the bottom to not affect the following visibility checks
            positionStackAtBottom(stack);
        } else {
        stack.getParent().positionChildAt(POSITION_BOTTOM, stack, false /* includingParents */);
        }

        // Find the next position where the stack should be placed
        final boolean isRootTask = stack.isRootTask();
        final int numStacks = isRootTask ? getStackCount() : stack.getParent().getChildCount();
        for (int stackNdx = 0; stackNdx < numStacks; stackNdx++) {
            final Task s = isRootTask ? getStackAt(stackNdx)
@@ -1688,11 +1654,7 @@ final class TaskDisplayArea extends DisplayArea<Task> {
            if (s.shouldBeVisible(null) && isValidWindowingMode) {
                // Move the provided stack to behind this stack
                final int position = Math.max(0, stackNdx - 1);
                if (isRootTask) {
                    positionStackAt(stack, position);
                } else {
                stack.getParent().positionChildAt(position, stack, false /*includingParents */);
                }
                break;
            }
        }
@@ -1722,12 +1684,8 @@ final class TaskDisplayArea extends DisplayArea<Task> {
        final int insertIndex = stackIndex <= behindStackIndex
                ? behindStackIndex - 1 : behindStackIndex;
        final int position = Math.max(0, insertIndex);
        if (stack.isRootTask()) {
            positionStackAt(stack, position);
        } else {
        parent.positionChildAt(position, stack, false /* includingParents */);
    }
    }

    boolean hasPinnedTask() {
        return getRootPinnedTask() != null;
+6 −18
Original line number Diff line number Diff line
@@ -345,30 +345,18 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
                    final Task rootTask = (Task) (
                            (newParent != null && !(newParent instanceof TaskDisplayArea))
                                    ? newParent : task.getRootTask());
                    if (hop.getToTop()) {
                        as.getDisplayArea().positionStackAtTop(rootTask,
                    as.getDisplayArea().positionChildAt(
                            hop.getToTop() ? POSITION_TOP : POSITION_BOTTOM, rootTask,
                            false /* includingParents */);
                    } else {
                        as.getDisplayArea().positionStackAtBottom(rootTask);
                    }
                }
            } else {
                throw new RuntimeException("Reparenting leaf Tasks is not supported now. " + task);
            }
        } else {
            // Ugh, of course ActivityStack has its own special reorder logic...
            if (task.isRootTask()) {
                if (hop.getToTop()) {
                    as.getDisplayArea().positionStackAtTop(as, false /* includingParents */);
                } else {
                    as.getDisplayArea().positionStackAtBottom(as);
                }
        } else {
            task.getParent().positionChildAt(
                    hop.getToTop() ? POSITION_TOP : POSITION_BOTTOM,
                    task, false /* includingParents */);
        }
        }
        return TRANSACT_EFFECTS_LIFECYCLE;
    }

Loading