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

Commit 47f2bf60 authored by Winson Chung's avatar Winson Chung
Browse files

Fix PiP being out of bounds when launched into forced orientation

- Ensure that we use the right bounds when calculating the post-rotation
  bounds (it should always be the target bounds)
- Ensure that we update the controller when the task stack bounds change

Bug: 35402420
Test: android.server.cts.ActivityManagerPinnedStackTests
Test: #testEnterPipToOtherOrientation
Change-Id: Ie0e3fc6a93b4eb6250c60584e80afb029b3c599a
parent eba6e6c7
Loading
Loading
Loading
Loading
+29 −24
Original line number Diff line number Diff line
@@ -230,32 +230,37 @@ class PinnedStackController {
    }

    /**
     * @param preChangeTargetBounds The final bounds of the stack if it is currently animating
     * @return the repositioned PIP bounds given it's pre-change bounds, and the new display
     *         content.
     * Updates the display info, calculating and returning the new stack and movement bounds in the
     * new orientation of the device if necessary.
     */
    Rect onDisplayChanged(Rect preChangeStackBounds, Rect preChangeTargetBounds,
            DisplayContent displayContent) {
        final Rect postChangeStackBounds = new Rect(preChangeTargetBounds);
        final DisplayInfo displayInfo = displayContent.getDisplayInfo();
        if (!mDisplayInfo.equals(displayInfo)) {
            // Calculate the snap fraction of the current stack along the old movement bounds, and
            // then update the stack bounds to the same fraction along the rotated movement bounds.
            final Rect preChangeMovementBounds = getMovementBounds(preChangeStackBounds);
            final float snapFraction = mSnapAlgorithm.getSnapFraction(preChangeStackBounds,
    void onTaskStackBoundsChanged(Rect targetBounds, Rect outBounds) {
        final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
        if (mDisplayInfo.equals(displayInfo)) {
            return;
        }

        mTmpRect.set(targetBounds);
        final Rect postChangeStackBounds = mTmpRect;

        // Calculate the snap fraction of the current stack along the old movement bounds
        final Rect preChangeMovementBounds = getMovementBounds(postChangeStackBounds);
        final float snapFraction = mSnapAlgorithm.getSnapFraction(postChangeStackBounds,
                preChangeMovementBounds);
        mDisplayInfo.copyFrom(displayInfo);

            final Rect postChangeMovementBounds = getMovementBounds(preChangeStackBounds,
        // Calculate the stack bounds in the new orientation to the same same fraction along the
        // rotated movement bounds.
        final Rect postChangeMovementBounds = getMovementBounds(postChangeStackBounds,
                false /* adjustForIme */);
        mSnapAlgorithm.applySnapFraction(postChangeStackBounds, postChangeMovementBounds,
                snapFraction);
        if (mIsMinimized) {
            applyMinimizedOffset(postChangeStackBounds, postChangeMovementBounds);
        }

        notifyMovementBoundsChanged(false /* fromImeAdjustment */);
        }
        return postChangeStackBounds;

        outBounds.set(postChangeStackBounds);
    }

    /**
+15 −16
Original line number Diff line number Diff line
@@ -262,6 +262,12 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye

        if (mDisplayContent != null) {
            mDisplayContent.mDimLayerController.updateDimLayer(this);
            if (mStackId == PINNED_STACK_ID) {
                // Update the bounds based on any changes to the display info
                getAnimatingBounds(mTmpRect2);
                mDisplayContent.mPinnedStackControllerLocked.onTaskStackBoundsChanged(mTmpRect2,
                        bounds);
            }
            mAnimationBackgroundSurface.setBounds(bounds);
        }

@@ -391,15 +397,18 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
            return false;
        }

        if (StackId.tasksAreFloating(mStackId)) {
            // Update stack bounds again since the display info has changed since updateDisplayInfo,
            // however, for floating tasks, we don't need to apply the new rotation to the bounds,
            // we can just update and return them here
            setBounds(mBounds);
            mBoundsAfterRotation.set(mBounds);
            return true;
        }

        mTmpRect2.set(mBounds);
        mDisplayContent.rotateBounds(mRotation, newRotation, mTmpRect2);
        switch (mStackId) {
            case PINNED_STACK_ID:
                Rect targetBounds = new Rect();
                getAnimatingBounds(targetBounds);
                mTmpRect2 = mDisplayContent.getPinnedStackController().onDisplayChanged(mBounds,
                        targetBounds, mDisplayContent);
                break;
            case DOCKED_STACK_ID:
                repositionDockedStackAfterRotation(mTmpRect2);
                snapDockedStackAfterRotation(mTmpRect2);
@@ -651,7 +660,6 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
        mAnimationBackgroundSurface = new DimLayer(mService, this, mDisplayContent.getDisplayId(),
                "animation background stackId=" + mStackId);

        final Rect oldBounds = new Rect(mBounds);
        Rect bounds = null;
        final TaskStack dockedStack = dc.getDockedStackIgnoringVisibility();
        if (mStackId == DOCKED_STACK_ID
@@ -675,15 +683,6 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
        }

        updateDisplayInfo(bounds);

        // Update the pinned stack controller after the display info is updated
        if (mStackId == PINNED_STACK_ID) {
            Rect targetBounds = new Rect();
            getAnimatingBounds(targetBounds);
            mDisplayContent.getPinnedStackController().onDisplayChanged(oldBounds, targetBounds,
                    mDisplayContent);
        }

        super.onDisplayChanged(dc);
    }