Merge "Retain current position and expand state on `next video`" into rvc-dev
diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java b/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java
index a10972e..0d3a16e 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java
@@ -250,10 +250,19 @@
     }
 
     /**
-     * @return {@link Rect} of the destination PiP window bounds.
+     * See {@link #getDestinationBounds(ComponentName, float, Rect, Size, boolean)}
      */
     Rect getDestinationBounds(ComponentName componentName, float aspectRatio, Rect bounds,
             Size minimalSize) {
+        return getDestinationBounds(componentName, aspectRatio, bounds, minimalSize,
+                false /* useCurrentMinEdgeSize */);
+    }
+
+    /**
+     * @return {@link Rect} of the destination PiP window bounds.
+     */
+    Rect getDestinationBounds(ComponentName componentName, float aspectRatio, Rect bounds,
+            Size minimalSize, boolean useCurrentMinEdgeSize) {
         if (!componentName.equals(mLastPipComponentName)) {
             onResetReentryBoundsUnchecked();
             mLastPipComponentName = componentName;
@@ -269,8 +278,7 @@
             destinationBounds = new Rect(bounds);
         }
         if (isValidPictureInPictureAspectRatio(aspectRatio)) {
-            transformBoundsToAspectRatio(destinationBounds, aspectRatio,
-                    false /* useCurrentMinEdgeSize */);
+            transformBoundsToAspectRatio(destinationBounds, aspectRatio, useCurrentMinEdgeSize);
         }
         mAspectRatio = aspectRatio;
         return destinationBounds;
diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java b/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java
index e30eb54..c6f144a 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java
@@ -459,7 +459,8 @@
         }
         final Rect destinationBounds = mPipBoundsHandler.getDestinationBounds(
                 info.topActivity, getAspectRatioOrDefault(newParams),
-                null /* bounds */, getMinimalSize(info.topActivityInfo));
+                mLastReportedBounds, getMinimalSize(info.topActivityInfo),
+                true /* userCurrentMinEdgeSize */);
         Objects.requireNonNull(destinationBounds, "Missing destination bounds");
         scheduleAnimateResizePip(destinationBounds, mEnterExitAnimationDuration,
                 null /* updateBoundsCallback */);