diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipBoundsState.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipBoundsState.java index 8b6c7b663f82e3f544391db5e2941668e1c3bf1b..68d26da2002f7084d737f50eb20c1fa4a5d242e1 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipBoundsState.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipBoundsState.java @@ -140,7 +140,7 @@ public class PipBoundsState { // spec takes the aspect ratio of the bounds into account, so both width and height // scale by the same factor. addPipExclusionBoundsChangeCallback((bounds) -> { - mBoundsScale = Math.min((float) bounds.width() / mMaxSize.x, 1.0f); + updateBoundsScale(); }); } @@ -152,6 +152,11 @@ public class PipBoundsState { mSizeSpecSource.onConfigurationChanged(); } + /** Update the bounds scale percentage value. */ + public void updateBoundsScale() { + mBoundsScale = Math.min((float) mBounds.width() / mMaxSize.x, 1.0f); + } + private void reloadResources() { mStashOffset = mContext.getResources().getDimensionPixelSize(R.dimen.pip_stash_offset); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java index 896ca96477200e8df4fecea96d67b3f43f2e894c..e018ecc0f7e37cd6e93716a0cb622d04b5d67a0c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java @@ -286,12 +286,6 @@ public class PipTransition extends PipTransitionController { // For transition that we don't animate, but contains the PIP leash, we need to update the // PIP surface, otherwise it will be reset after the transition. if (currentPipTaskChange != null) { - // Set the "end" bounds of pip. The default setup uses the start bounds. Since this is - // changing the *finish*Transaction, we need to use the end bounds. This will also - // make sure that the fade-in animation (below) uses the end bounds as well. - if (!currentPipTaskChange.getEndAbsBounds().isEmpty()) { - mPipBoundsState.setBounds(currentPipTaskChange.getEndAbsBounds()); - } updatePipForUnhandledTransition(currentPipTaskChange, startTransaction, finishTransaction); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java index c5a01025dcdd402384bb500944daf50b80b5d7e8..05d4f53986b89726ef0f45e4961b41974d4e625e 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java @@ -244,6 +244,9 @@ public class PipController implements PipTransitionController.PipTransitionCallb // The same rotation may have been set by auto PiP-able or fixed rotation. So notify // the change with fromRotation=false to apply the rotated destination bounds from // PipTaskOrganizer#onMovementBoundsChanged. + // We need to update the bounds scale in case this was from fixed rotation, as the + // current proportion was computed using the previous orientation max size and is wrong. + mPipBoundsState.updateBoundsScale(); updateMovementBounds(null, false /* fromRotation */, false /* fromImeAdjustment */, false /* fromShelfAdjustment */, t); return; @@ -797,21 +800,15 @@ public class PipController implements PipTransitionController.PipTransitionCallb mPipBoundsAlgorithm.getMovementBounds(postChangeBounds), mPipBoundsState.getStashedState()); - // Scale PiP on density dpi change, so it appears to be the same size physically. - final boolean densityDpiChanged = - mPipDisplayLayoutState.getDisplayLayout().densityDpi() != 0 - && (mPipDisplayLayoutState.getDisplayLayout().densityDpi() - != layout.densityDpi()); - if (densityDpiChanged) { - final float scale = (float) layout.densityDpi() - / mPipDisplayLayoutState.getDisplayLayout().densityDpi(); - postChangeBounds.set(0, 0, - (int) (postChangeBounds.width() * scale), - (int) (postChangeBounds.height() * scale)); - } - updateDisplayLayout.run(); + // Resize the PiP bounds to be at the same scale relative to the new size spec. For + // example, if PiP was resized to 90% of the maximum size on the previous layout, + // make sure it is 90% of the new maximum size spec. + postChangeBounds.set(0, 0, + (int) (mPipBoundsState.getMaxSize().x * mPipBoundsState.getBoundsScale()), + (int) (mPipBoundsState.getMaxSize().y * mPipBoundsState.getBoundsScale())); + // Calculate the PiP bounds in the new orientation based on same fraction along the // rotated movement bounds. final Rect postChangeMovementBounds = mPipBoundsAlgorithm.getMovementBounds( @@ -827,6 +824,10 @@ public class PipController implements PipTransitionController.PipTransitionCallb mPipBoundsState.setHasUserResizedPip(true); mTouchHandler.setUserResizeBounds(postChangeBounds); + final boolean densityDpiChanged = + mPipDisplayLayoutState.getDisplayLayout().densityDpi() != 0 + && (mPipDisplayLayoutState.getDisplayLayout().densityDpi() + != layout.densityDpi()); if (densityDpiChanged) { // Using PipMotionHelper#movePip directly here may cause race condition since // the app content in PiP mode may or may not be updated for the new density dpi. @@ -1146,6 +1147,11 @@ public class PipController implements PipTransitionController.PipTransitionCallb // Update the display layout mPipDisplayLayoutState.rotateTo(toRotation); + mTouchHandler.updateMinMaxSize(mPipBoundsState.getAspectRatio()); + + postChangeStackBounds.set(0, 0, + (int) (mPipBoundsState.getMaxSize().x * mPipBoundsState.getBoundsScale()), + (int) (mPipBoundsState.getMaxSize().y * mPipBoundsState.getBoundsScale())); // Calculate the stack bounds in the new orientation based on same fraction along the // rotated movement bounds. diff --git a/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/EnterPipToOtherOrientation.kt b/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/EnterPipToOtherOrientation.kt index 8207b85c3e0c9af5f430489c6741d1f8c6dfd6e7..07cd682610838130744e45562cf5deed53d20860 100644 --- a/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/EnterPipToOtherOrientation.kt +++ b/libs/WindowManager/Shell/tests/flicker/pip/src/com/android/wm/shell/flicker/pip/EnterPipToOtherOrientation.kt @@ -86,6 +86,8 @@ class EnterPipToOtherOrientation(flicker: LegacyFlickerTest) : PipTransition(fli .withNavOrTaskBarVisible() .withStatusBarVisible() .waitForAndVerify() + + pipApp.tapPipToShowMenu(wmHelper) } } @@ -194,6 +196,16 @@ class EnterPipToOtherOrientation(flicker: LegacyFlickerTest) : PipTransition(fli } } + @Postsubmit + @Test + fun menuOverlayMatchesTaskSurface() { + flicker.assertLayersEnd { + val pipAppRegion = visibleRegion(pipApp) + val pipMenuRegion = visibleRegion(ComponentNameMatcher.PIP_MENU_OVERLAY) + pipAppRegion.coversExactly(pipMenuRegion.region) + } + } + /** {@inheritDoc} */ @FlakyTest(bugId = 267424412) @Test diff --git a/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/PipAppHelper.kt b/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/PipAppHelper.kt index 73cc2f2b4d184b8529387d61e1d75958b21cbf7e..f628af14a0b94932f7dc7ed5f6be2b1248e1c799 100644 --- a/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/PipAppHelper.kt +++ b/tests/FlickerTests/test-apps/app-helpers/src/com/android/server/wm/flicker/helpers/PipAppHelper.kt @@ -340,6 +340,14 @@ open class PipAppHelper(instrumentation: Instrumentation) : wmHelper.StateSyncBuilder().withPipGone().withHomeActivityVisible().waitForAndVerify() } + open fun tapPipToShowMenu(wmHelper: WindowManagerStateHelper) { + val windowRect = getWindowRect(wmHelper) + uiDevice.click(windowRect.centerX(), windowRect.centerY()) + // search and interact with the dismiss button + val dismissSelector = By.res(SYSTEMUI_PACKAGE, "dismiss") + uiDevice.wait(Until.hasObject(dismissSelector), FIND_TIMEOUT) + } + /** Close the pip window by pressing the expand button */ fun expandPipWindowToApp(wmHelper: WindowManagerStateHelper) { val windowRect = getWindowRect(wmHelper)