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

Commit dd7b69d3 authored by Kazuki Takise's avatar Kazuki Takise Committed by Android (Google) Code Review
Browse files

Merge "Position stack at top when always on top flag is set"

parents 05e554db f85197be
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -488,7 +488,7 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
                + " mAppBounds=" + mAppBounds
                + " mWindowingMode=" + windowingModeToString(mWindowingMode)
                + " mActivityType=" + activityTypeToString(mActivityType)
                + " mAlwaysOnTop=" + activityTypeToString(mAlwaysOnTop)
                + " mAlwaysOnTop=" + alwaysOnTopToString(mAlwaysOnTop)
                + "}";
    }

@@ -652,4 +652,14 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
        }
        return String.valueOf(applicationType);
    }

    /** @hide */
    public static String alwaysOnTopToString(@AlwaysOnTop int alwaysOnTop) {
        switch (alwaysOnTop) {
            case ALWAYS_ON_TOP_UNDEFINED: return "undefined";
            case ALWAYS_ON_TOP_ON: return "on";
            case ALWAYS_ON_TOP_OFF: return "off";
        }
        return String.valueOf(alwaysOnTop);
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -5279,6 +5279,20 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        }
    }

    public void setAlwaysOnTop(boolean alwaysOnTop) {
        if (isAlwaysOnTop() == alwaysOnTop) {
            return;
        }
        super.setAlwaysOnTop(alwaysOnTop);
        final ActivityDisplay display = getDisplay();
        // positionChildAtTop() must be called even when always on top gets turned off because we
        // need to make sure that the stack is moved from among always on top windows to below other
        // always on top windows. Since the position the stack should be inserted into is calculated
        // properly in {@link ActivityDisplay#getTopInsertPosition()} in both cases, we can just
        // request that the stack is put at top here.
        display.positionChildAtTop(this);
    }

    void moveToFrontAndResumeStateIfNeeded(ActivityRecord r, boolean moveToFront, boolean setResume,
            boolean setPause, String reason) {
        if (!moveToFront) {
+39 −36
Original line number Diff line number Diff line
@@ -3427,48 +3427,51 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
         * @return The proper position for the stack.
         */
        private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
            final int topChildPosition = mChildren.size() - 1;
            boolean toTop = requestedPosition == POSITION_TOP;
            toTop |= adding ? requestedPosition >= topChildPosition + 1
                    : requestedPosition >= topChildPosition;

            if (stack.inPinnedWindowingMode()) {
                // Stack in pinned windowing mode is z-ordered on-top of all other stacks so okay to
                // just return the candidate position.
                return requestedPosition;
            }

            // We might call mChildren.get() with targetPosition below, but targetPosition might be
            // POSITION_TOP (INTEGER_MAX). We need to adjust the value to the actual index in the
            // array.
            int targetPosition = toTop ? topChildPosition : requestedPosition;
            // Note that the index we should return varies depending on the value of adding.
            // When we're adding a new stack the index is the current target position.
            // When we're positioning an existing stack the index is the position below the target
            // stack, because WindowContainer#positionAt() first removes element and then adds
            // it to specified place.
            if (toTop && adding) {
                targetPosition++;
                return POSITION_TOP;
            }

            // Note we might have multiple always on top windows.
            while (targetPosition >= 0) {
                int adjustedTargetStackId = adding ? targetPosition - 1 : targetPosition;
                if (adjustedTargetStackId < 0 || adjustedTargetStackId > topChildPosition) {
            final int topChildPosition = mChildren.size() - 1;
            int belowAlwaysOnTopPosition = POSITION_BOTTOM;
            for (int i = topChildPosition; i >= 0; --i) {
                if (getStacks().get(i) != stack && !getStacks().get(i).isAlwaysOnTop()) {
                    belowAlwaysOnTopPosition = i;
                    break;
                }
                TaskStack targetStack = mChildren.get(adjustedTargetStackId);
                if (!targetStack.isAlwaysOnTop()) {
                    // We reached a stack that isn't always-on-top.
                    break;
            }
                if (stack.isAlwaysOnTop() && !targetStack.inPinnedWindowingMode()) {
                    // Always on-top non-pinned windowing mode stacks can go anywhere below pinned
                    // stack.
                    break;

            // The max possible position we can insert the stack at.
            int maxPosition = POSITION_TOP;
            // The min possible position we can insert the stack at.
            int minPosition = POSITION_BOTTOM;

            if (stack.isAlwaysOnTop()) {
                if (hasPinnedStack()) {
                    // Always-on-top stacks go below the pinned stack.
                    maxPosition = getStacks().indexOf(mPinnedStack) - 1;
                }
                // We go one level down, looking for the place on which the new stack can be put.
                targetPosition--;
                // Always-on-top stacks need to be above all other stacks.
                minPosition = belowAlwaysOnTopPosition !=
                        POSITION_BOTTOM ? belowAlwaysOnTopPosition : topChildPosition;
            } else {
                // Other stacks need to be below the always-on-top stacks.
                maxPosition = belowAlwaysOnTopPosition !=
                        POSITION_BOTTOM ? belowAlwaysOnTopPosition : topChildPosition;
            }

            int targetPosition = requestedPosition;
            targetPosition = Math.min(targetPosition, maxPosition);
            targetPosition = Math.max(targetPosition, minPosition);

            int prevPosition = getStacks().indexOf(stack);
            // The positions we calculated above (maxPosition, minPosition) do not take into
            // consideration the following edge cases.
            // 1) We need to adjust the position depending on the value "adding".
            // 2) When we are moving a stack to another position, we also need to adjust the
            //    position depending on whether the stack is moving to a higher or lower position.
            if ((targetPosition != requestedPosition) &&
                    (adding || targetPosition < prevPosition)) {
                targetPosition++;
            }

            return targetPosition;
+18 −3
Original line number Diff line number Diff line
@@ -726,20 +726,35 @@ public class TaskStack extends WindowContainer<Task> implements
    @Override
    public void onConfigurationChanged(Configuration newParentConfig) {
        final int prevWindowingMode = getWindowingMode();
        final boolean prevIsAlwaysOnTop = isAlwaysOnTop();
        super.onConfigurationChanged(newParentConfig);

        // Only need to update surface size here since the super method will handle updating
        // surface position.
        updateSurfaceSize(getPendingTransaction());
        final int windowingMode = getWindowingMode();
        final boolean isAlwaysOnTop = isAlwaysOnTop();

        if (mDisplayContent == null || prevWindowingMode == windowingMode) {
        if (mDisplayContent == null) {
            return;
        }

        if (prevWindowingMode != windowingMode) {
            mDisplayContent.onStackWindowingModeChanged(this);
            updateBoundsForWindowModeChange();
        }

        if (prevIsAlwaysOnTop != isAlwaysOnTop) {
            // positionStackAt(POSITION_TOP, this) must be called even when always on top gets
            // turned off because we need to make sure that the stack is moved from among always on
            // top windows to below other always on top windows. Since the position the stack should
            // be inserted into is calculated properly in
            // {@link DisplayContent#findPositionForStack()} in both cases, we can just request that
            // the stack is put at top here.
            mDisplayContent.positionStackAt(POSITION_TOP, this);
        }
    }

    private void updateSurfaceBounds() {
        updateSurfaceSize(getPendingTransaction());
        updateSurfacePosition();
+13 −0
Original line number Diff line number Diff line
@@ -246,6 +246,19 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
                    + " is already a child of container=" + child.getParent().getName()
                    + " can't add to container=" + getName());
        }

        if ((index < 0 && index != POSITION_BOTTOM)
                || (index > mChildren.size() && index != POSITION_TOP)) {
            throw new IllegalArgumentException("addChild: invalid position=" + index
                    + ", children number=" + mChildren.size());
        }

        if (index == POSITION_TOP) {
            index = mChildren.size();
        } else if (index == POSITION_BOTTOM) {
            index = 0;
        }

        mChildren.add(index, child);
        onChildAdded(child);

Loading