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

Commit a71febe2 authored by Winson Chung's avatar Winson Chung
Browse files

Fix issue with aspect ratio not applying correctly when PIP is expanded

- The current code always used the default min edge size to calculate the
  PIP bounds when the aspect ratio changes, so if a PIP app sets the aspect
  ratio in response to the an action, the bounds would be resized down
  incorrectly.
- This CL fixes the issue with current aspect ratio not being initialized
  correctly, and also ensures that SystemUI always updates the min edge
  size when expanding the PIP.

Bug: 38324839
Test: android.server.cts.ActivityManagerPinnedStackTests
Test: go/wm-smoke

Change-Id: Ida0f68b2f8f93f9bf1915dda8762a156704d4709
parent aa051df3
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -29,6 +29,14 @@ interface IPinnedStackController {
     */
    oneway void setIsMinimized(boolean isMinimized);

    /**
     * Notifies the controller of the current min edge size, this is needed to allow the system to
     * properly calculate the aspect ratio of the expanded PIP.  The given {@param minEdgeSize} is
     * always bounded to be larger than the default minEdgeSize, so the caller can call this method
     * with 0 to reset to the default size.
     */
    oneway void setMinEdgeSize(int minEdgeSize);

    /**
     * @return what WM considers to be the current device rotation.
     */
+7 −1
Original line number Diff line number Diff line
@@ -716,9 +716,15 @@ public class PipTouchHandler {
     * Updates the current movement bounds based on whether the menu is currently visible.
     */
    private void updateMovementBounds(int menuState) {
        mMovementBounds = menuState == MENU_STATE_FULL
        boolean isMenuExpanded = menuState == MENU_STATE_FULL;
        mMovementBounds = isMenuExpanded
                ? mExpandedMovementBounds
                : mNormalMovementBounds;
        try {
            mPinnedStackController.setMinEdgeSize(isMenuExpanded ? mExpandedShortestEdgeSize : 0);
        } catch (RemoteException e) {
            Log.e(TAG, "Could not set minimized state", e);
        }
    }

    /**
+2 −2
Original line number Diff line number Diff line
@@ -2989,8 +2989,8 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
        // Calculate the default bounds (don't use existing stack bounds as we may have just created
        // the stack, and schedule the start of the animation into PiP (the bounds animator that
        // is triggered by this is posted on another thread)
        final Rect destBounds = stack.getPictureInPictureBounds(aspectRatio,
                false /* useExistingStackBounds */);
        final Rect destBounds = stack.getDefaultPictureInPictureBounds(aspectRatio);

        stack.animateResizePinnedStack(sourceHintBounds, destBounds, -1 /* animationDuration */,
                true /* fromFullscreen */);

+2 −2
Original line number Diff line number Diff line
@@ -44,9 +44,9 @@ class PinnedActivityStack extends ActivityStack<PinnedStackWindowController>
        return new PinnedStackWindowController(mStackId, this, displayId, onTop, outBounds);
    }

    Rect getPictureInPictureBounds(float aspectRatio, boolean useExistingStackBounds) {
    Rect getDefaultPictureInPictureBounds(float aspectRatio) {
        return getWindowContainerController().getPictureInPictureBounds(aspectRatio,
                useExistingStackBounds);
                null /* currentStackBounds */);
    }

    void animateResizePinnedStack(Rect sourceHintBounds, Rect toBounds, int animationDuration,
+22 −18
Original line number Diff line number Diff line
@@ -92,17 +92,16 @@ class PinnedStackController {
    private final Rect mStableInsets = new Rect();

    // The size and position information that describes where the pinned stack will go by default.
    private int mDefaultMinSize;
    private int mDefaultStackGravity;
    private float mDefaultAspectRatio;
    private Point mScreenEdgeInsets;
    private int mCurrentMinSize;

    // The aspect ratio bounds of the PIP.
    private float mMinAspectRatio;
    private float mMaxAspectRatio;

    // The minimum edge size of the normal PiP bounds.
    private int mMinSize;

    // Temp vars for calculation
    private final DisplayMetrics mTmpMetrics = new DisplayMetrics();
    private final Rect mTmpInsets = new Rect();
@@ -123,6 +122,13 @@ class PinnedStackController {
            });
        }

        @Override
        public void setMinEdgeSize(int minEdgeSize) {
            mHandler.post(() -> {
                mCurrentMinSize = Math.max(mDefaultMinSize, minEdgeSize);
            });
        }

        @Override
        public int getDisplayRotation() {
            synchronized (mService.mWindowMap) {
@@ -160,10 +166,12 @@ class PinnedStackController {
     */
    private void reloadResources() {
        final Resources res = mService.mContext.getResources();
        mMinSize = res.getDimensionPixelSize(
        mDefaultMinSize = res.getDimensionPixelSize(
                com.android.internal.R.dimen.default_minimal_size_pip_resizable_task);
        mCurrentMinSize = mDefaultMinSize;
        mDefaultAspectRatio = res.getFloat(
                com.android.internal.R.dimen.config_pictureInPictureDefaultAspectRatio);
        mAspectRatio = mDefaultAspectRatio;
        final String screenEdgeInsetsDpString = res.getString(
                com.android.internal.R.string.config_defaultPictureInPictureScreenEdgeInsets);
        final Size screenEdgeInsetsDp = !screenEdgeInsetsDpString.isEmpty()
@@ -212,11 +220,15 @@ class PinnedStackController {
     * Returns the current bounds (or the default bounds if there are no current bounds) with the
     * specified aspect ratio.
     */
    Rect transformBoundsToAspectRatio(Rect stackBounds, float aspectRatio) {
    Rect transformBoundsToAspectRatio(Rect stackBounds, float aspectRatio,
            boolean useCurrentMinEdgeSize) {
        // Save the snap fraction, calculate the aspect ratio based on screen size
        final float snapFraction = mSnapAlgorithm.getSnapFraction(stackBounds,
                getMovementBounds(stackBounds));
        final Size size = getSize(aspectRatio);

        final int minEdgeSize = useCurrentMinEdgeSize ? mCurrentMinSize : mDefaultMinSize;
        final Size size = mSnapAlgorithm.getSizeForAspectRatio(aspectRatio, minEdgeSize,
                mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight);
        final int left = (int) (stackBounds.centerX() - size.getWidth() / 2f);
        final int top = (int) (stackBounds.centerY() - size.getHeight() / 2f);
        stackBounds.set(left, top, left + size.getWidth(), top + size.getHeight());
@@ -227,16 +239,6 @@ class PinnedStackController {
        return stackBounds;
    }

    /**
     * @return the size of the PIP based on the given {@param aspectRatio}.
     */
    Size getSize(float aspectRatio) {
        synchronized (mService.mWindowMap) {
            return mSnapAlgorithm.getSizeForAspectRatio(aspectRatio, mMinSize,
                    mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight);
        }
    }

    /**
     * @return the default bounds to show the PIP when there is no active PIP.
     */
@@ -246,7 +248,8 @@ class PinnedStackController {
            getInsetBounds(insetBounds);

            final Rect defaultBounds = new Rect();
            final Size size = getSize(mDefaultAspectRatio);
            final Size size = mSnapAlgorithm.getSizeForAspectRatio(mDefaultAspectRatio,
                    mDefaultMinSize, mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight);
            Gravity.apply(mDefaultStackGravity, size.getWidth(), size.getHeight(), insetBounds,
                    0, mIsImeShowing ? mImeHeight : 0, defaultBounds);
            return defaultBounds;
@@ -401,7 +404,8 @@ class PinnedStackController {
                    getInsetBounds(insetBounds);
                    final Rect normalBounds = getDefaultBounds();
                    if (isValidPictureInPictureAspectRatio(mAspectRatio)) {
                        transformBoundsToAspectRatio(normalBounds, mAspectRatio);
                        transformBoundsToAspectRatio(normalBounds, mAspectRatio,
                                false /* useCurrentMinEdgeSize */);
                    }
                    final Rect animatingBounds = mTmpAnimatingBoundsRect;
                    final TaskStack pinnedStack = mDisplayContent.getStackById(PINNED_STACK_ID);
Loading