From 98e7fb1d55bdac1a5ddf7126044b83c4cc3dd6f5 Mon Sep 17 00:00:00 2001 From: "jorgegil@google.com" Date: Fri, 10 Jul 2020 11:58:49 -0700 Subject: [PATCH] Use reentry size to calculate PIP entry bounds Use the saved reentry size when restoring the PIP bounds if available. Note: this CL doesn't actually change the size of the bounds we restore to because the saved reentry size is always the normal bounds. It does however make it so that if the saved reentry size were to be changed to something other than the normal bounds then it would actually restore to it on reentry. Bug: 160799929 Test: atest SystemUITests Test: in an environment where the saved reentry size is changed, the PIP window is restored to that size when re-entering PIP Change-Id: I0bbb4725c249d9d81b80b46d1bff5d6cd11981c3 Merged-In: I0bbb4725c249d9d81b80b46d1bff5d6cd11981c3 (cherry picked from commit 4177a5ee62fe548d3c90963eb8b78e29f7bda707) --- .../systemui/pip/PipBoundsHandler.java | 17 +++++----- .../systemui/pip/PipBoundsHandlerTest.java | 31 +++++++++++++++++++ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java b/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java index 8bbd15babf199..583953ce34af5 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java +++ b/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java @@ -177,7 +177,7 @@ public class PipBoundsHandler { } if (isValidPictureInPictureAspectRatio(mAspectRatio)) { transformBoundsToAspectRatio(normalBounds, mAspectRatio, - false /* useCurrentMinEdgeSize */); + false /* useCurrentMinEdgeSize */, false /* useCurrentSize */); } displayInfo.copyFrom(mDisplayInfo); } @@ -278,7 +278,9 @@ public class PipBoundsHandler { destinationBounds = new Rect(bounds); } if (isValidPictureInPictureAspectRatio(aspectRatio)) { - transformBoundsToAspectRatio(destinationBounds, aspectRatio, useCurrentMinEdgeSize); + boolean useCurrentSize = bounds == null && mReentrySize != null; + transformBoundsToAspectRatio(destinationBounds, aspectRatio, useCurrentMinEdgeSize, + useCurrentSize); } mAspectRatio = aspectRatio; return destinationBounds; @@ -384,7 +386,8 @@ public class PipBoundsHandler { * @param stackBounds */ public void transformBoundsToAspectRatio(Rect stackBounds) { - transformBoundsToAspectRatio(stackBounds, mAspectRatio, true); + transformBoundsToAspectRatio(stackBounds, mAspectRatio, true /* useCurrentMinEdgeSize */, + true /* useCurrentSize */); } /** @@ -392,18 +395,16 @@ public class PipBoundsHandler { * specified aspect ratio. */ private void transformBoundsToAspectRatio(Rect stackBounds, float aspectRatio, - boolean useCurrentMinEdgeSize) { + boolean useCurrentMinEdgeSize, boolean useCurrentSize) { // Save the snap fraction and adjust the size based on the new aspect ratio. final float snapFraction = mSnapAlgorithm.getSnapFraction(stackBounds, getMovementBounds(stackBounds)); - final int minEdgeSize; + final int minEdgeSize = useCurrentMinEdgeSize ? mCurrentMinSize : mDefaultMinSize; final Size size; - if (useCurrentMinEdgeSize) { - minEdgeSize = mCurrentMinSize; + if (useCurrentMinEdgeSize || useCurrentSize) { size = mSnapAlgorithm.getSizeForAspectRatio( new Size(stackBounds.width(), stackBounds.height()), aspectRatio, minEdgeSize); } else { - minEdgeSize = mDefaultMinSize; size = mSnapAlgorithm.getSizeForAspectRatio(aspectRatio, minEdgeSize, mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/pip/PipBoundsHandlerTest.java b/packages/SystemUI/tests/src/com/android/systemui/pip/PipBoundsHandlerTest.java index f404f0489e016..70c2bba040a00 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/pip/PipBoundsHandlerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/pip/PipBoundsHandlerTest.java @@ -269,6 +269,21 @@ public class PipBoundsHandlerTest extends SysuiTestCase { assertBoundsInclusionWithMargin("restoreLastPosition", oldPosition, newPosition); } + @Test + public void onSaveReentryBounds_restoreLastSize() { + final Rect oldSize = mPipBoundsHandler.getDestinationBounds(mTestComponentName1, + DEFAULT_ASPECT_RATIO, EMPTY_CURRENT_BOUNDS, EMPTY_MINIMAL_SIZE); + + oldSize.scale(1.25f); + mPipBoundsHandler.onSaveReentryBounds(mTestComponentName1, oldSize); + + final Rect newSize = mPipBoundsHandler.getDestinationBounds(mTestComponentName1, + DEFAULT_ASPECT_RATIO, EMPTY_CURRENT_BOUNDS, EMPTY_MINIMAL_SIZE); + + assertEquals(oldSize.width(), newSize.width()); + assertEquals(oldSize.height(), newSize.height()); + } + @Test public void onResetReentryBounds_useDefaultBounds() { final Rect defaultBounds = mPipBoundsHandler.getDestinationBounds(mTestComponentName1, @@ -299,6 +314,22 @@ public class PipBoundsHandlerTest extends SysuiTestCase { assertBoundsInclusionWithMargin("restoreLastPosition", newBounds, actualBounds); } + @Test + public void onSaveReentryBounds_componentMismatch_restoreLastSize() { + final Rect oldSize = mPipBoundsHandler.getDestinationBounds(mTestComponentName1, + DEFAULT_ASPECT_RATIO, EMPTY_CURRENT_BOUNDS, EMPTY_MINIMAL_SIZE); + + oldSize.scale(1.25f); + mPipBoundsHandler.onSaveReentryBounds(mTestComponentName1, oldSize); + + mPipBoundsHandler.onResetReentryBounds(mTestComponentName2); + final Rect newSize = mPipBoundsHandler.getDestinationBounds(mTestComponentName1, + DEFAULT_ASPECT_RATIO, EMPTY_CURRENT_BOUNDS, EMPTY_MINIMAL_SIZE); + + assertEquals(oldSize.width(), newSize.width()); + assertEquals(oldSize.height(), newSize.height()); + } + private void assertBoundsInclusionWithMargin(String from, Rect expected, Rect actual) { final Rect expectedWithMargin = new Rect(expected); expectedWithMargin.inset(-ROUNDING_ERROR_MARGIN, -ROUNDING_ERROR_MARGIN);