Merge "Deprecate min/max size in PipResizeGestureHandler" into main
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipController.java
index 1ce24f7..d16c578 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipController.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipController.java
@@ -345,7 +345,6 @@
             return;
         }
 
-        mPipTouchHandler.updateMinMaxSize(mPipBoundsState.getAspectRatio());
         mPipMenuController.hideMenu();
 
         if (mPipTransitionState.isInFixedRotation()) {
@@ -366,6 +365,8 @@
             mPipBoundsState.setBounds(toBounds);
         }
         t.setBounds(mPipTransitionState.getPipTaskToken(), mPipBoundsState.getBounds());
+        // Update the size spec in PipBoundsState afterwards.
+        mPipBoundsState.updateMinMaxSize(mPipBoundsState.getAspectRatio());
     }
 
     private void setDisplayLayout(DisplayLayout layout) {
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipResizeGestureHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipResizeGestureHandler.java
index af1e98a..d53365a 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipResizeGestureHandler.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipResizeGestureHandler.java
@@ -81,8 +81,6 @@
     private final PointF mDownSecondPoint = new PointF();
     private final PointF mLastPoint = new PointF();
     private final PointF mLastSecondPoint = new PointF();
-    private final Point mMaxSize = new Point();
-    private final Point mMinSize = new Point();
     private final Rect mLastResizeBounds = new Rect();
     private final Rect mUserResizeBounds = new Rect();
     private final Rect mDownBounds = new Rect();
@@ -95,7 +93,6 @@
     private boolean mIsEnabled;
     private boolean mEnablePinchResize;
     private boolean mEnableDragCornerResize;
-    private boolean mIsSysUiStateValid;
     private boolean mThresholdCrossed;
     private boolean mOngoingPinchToResize = false;
     private boolean mWaitingForBoundsChangeTransition = false;
@@ -152,7 +149,6 @@
     }
 
     void init() {
-        mContext.getDisplay().getRealSize(mMaxSize);
         reloadResources();
 
         final Resources res = mContext.getResources();
@@ -163,15 +159,6 @@
         reloadResources();
     }
 
-    /**
-     * Called when SysUI state changed.
-     *
-     * @param isSysUiStateValid Is SysUI valid or not.
-     */
-    public void onSystemUiStateChanged(boolean isSysUiStateValid) {
-        mIsSysUiStateValid = isSysUiStateValid;
-    }
-
     private void reloadResources() {
         mPipDragToResizeHandler.reloadResources();
         mTouchSlop = ViewConfiguration.get(mContext).getScaledTouchSlop();
@@ -287,13 +274,15 @@
                 }
             }
 
+            final Point minSize = mPipBoundsState.getMinSize();
+            final Point maxSize = mPipBoundsState.getMaxSize();
             if (mOngoingPinchToResize) {
                 mPipPinchToResizeHandler.onPinchResize(mv, mDownPoint, mDownSecondPoint,
                         mDownBounds, mLastPoint, mLastSecondPoint, mLastResizeBounds, mTouchSlop,
-                        mMinSize, mMaxSize);
+                        minSize, maxSize);
             } else if (mEnableDragCornerResize) {
                 mPipDragToResizeHandler.onDragCornerResize(mv, mLastResizeBounds, mDownPoint,
-                        mDownBounds, mMinSize, mMaxSize, mTouchSlop);
+                        mDownBounds, minSize, maxSize, mTouchSlop);
             }
         }
     }
@@ -327,7 +316,7 @@
                 if (mEnablePinchResize && ev.getPointerCount() == 2) {
                     mPipPinchToResizeHandler.onPinchResize(ev, mDownPoint, mDownSecondPoint,
                             mDownBounds, mLastPoint, mLastSecondPoint, mLastResizeBounds,
-                            mTouchSlop, mMinSize, mMaxSize);
+                            mTouchSlop, mPipBoundsState.getMinSize(), mPipBoundsState.getMaxSize());
                     mOngoingPinchToResize = mAllowGesture;
                     return mAllowGesture;
                 }
@@ -407,16 +396,19 @@
             return;
         }
 
+        final Point minSize = mPipBoundsState.getMinSize();
+        final Point maxSize = mPipBoundsState.getMaxSize();
+
         // If user resize is pretty close to max size, just auto resize to max.
-        if (mLastResizeBounds.width() >= PINCH_RESIZE_AUTO_MAX_RATIO * mMaxSize.x
-                || mLastResizeBounds.height() >= PINCH_RESIZE_AUTO_MAX_RATIO * mMaxSize.y) {
-            resizeRectAboutCenter(mLastResizeBounds, mMaxSize.x, mMaxSize.y);
+        if (mLastResizeBounds.width() >= PINCH_RESIZE_AUTO_MAX_RATIO * maxSize.x
+                || mLastResizeBounds.height() >= PINCH_RESIZE_AUTO_MAX_RATIO * maxSize.y) {
+            resizeRectAboutCenter(mLastResizeBounds, maxSize.x, maxSize.y);
         }
 
         // If user resize is smaller than min size, auto resize to min
-        if (mLastResizeBounds.width() < mMinSize.x
-                || mLastResizeBounds.height() < mMinSize.y) {
-            resizeRectAboutCenter(mLastResizeBounds, mMinSize.x, mMinSize.y);
+        if (mLastResizeBounds.width() < minSize.x
+                || mLastResizeBounds.height() < minSize.y) {
+            resizeRectAboutCenter(mLastResizeBounds, minSize.x, minSize.y);
         }
 
         // get the current movement bounds
@@ -472,15 +464,6 @@
         mInputMonitor.pilferPointers();
     }
 
-
-    void updateMaxSize(int maxX, int maxY) {
-        mMaxSize.set(maxX, maxY);
-    }
-
-    void updateMinSize(int minX, int minY) {
-        mMinSize.set(minX, minY);
-    }
-
     void setOhmOffset(int offset) {
         mOhmOffset = offset;
     }
@@ -568,8 +551,6 @@
         pw.println(innerPrefix + "mEnableDragCornerResize=" + mEnableDragCornerResize);
         pw.println(innerPrefix + "mThresholdCrossed=" + mThresholdCrossed);
         pw.println(innerPrefix + "mOhmOffset=" + mOhmOffset);
-        pw.println(innerPrefix + "mMinSize=" + mMinSize);
-        pw.println(innerPrefix + "mMaxSize=" + mMaxSize);
     }
 
     class PipResizeInputEventReceiver extends BatchedInputEventReceiver {
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipTouchHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipTouchHandler.java
index 72346b3..6fdfeca 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipTouchHandler.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipTouchHandler.java
@@ -230,10 +230,7 @@
                 pipBoundsState, mTouchState, mPipScheduler, mPipTransitionState, pipUiEventLogger,
                 menuController, this::getMovementBounds, mPipDisplayLayoutState, pipDesktopState,
                 mainExecutor, mPipPerfHintController);
-        mPipBoundsState.addOnAspectRatioChangedCallback(aspectRatio -> {
-            updateMinMaxSize(aspectRatio);
-            onAspectRatioChanged();
-        });
+        mPipBoundsState.addOnAspectRatioChangedCallback(aspectRatio -> onAspectRatioChanged());
 
         mMoveOnShelVisibilityChanged = () -> {
             if (mIsImeShowing && mImeHeight > mShelfHeight) {
@@ -418,15 +415,6 @@
         mMainExecutor.executeDelayed(mMoveOnShelVisibilityChanged, PIP_KEEP_CLEAR_AREAS_DELAY);
     }
 
-    /**
-     * Called when SysUI state changed.
-     *
-     * @param isSysUiStateValid Is SysUI valid or not.
-     */
-    public void onSystemUiStateChanged(boolean isSysUiStateValid) {
-        mPipResizeGestureHandler.onSystemUiStateChanged(isSysUiStateValid);
-    }
-
     void adjustBoundsForRotation(Rect outBounds, Rect curBounds, Rect insetBounds) {
         final Rect toMovementBounds = new Rect();
         mPipBoundsAlgorithm.getMovementBounds(outBounds, insetBounds, toMovementBounds, 0);
@@ -480,8 +468,6 @@
                 mPipBoundsState.getExpandedBounds(), insetBounds, expandedMovementBounds,
                 bottomOffset);
 
-        updatePipSizeConstraints(normalBounds, aspectRatio);
-
         // The extra offset does not really affect the movement bounds, but are applied based on the
         // current state (ime showing, or shelf offset) when we need to actually shift
         int extraOffset = Math.max(
@@ -507,35 +493,6 @@
     }
 
     /**
-     * Update the values for min/max allowed size of picture in picture window based on the aspect
-     * ratio.
-     * @param aspectRatio aspect ratio to use for the calculation of min/max size
-     */
-    public void updateMinMaxSize(float aspectRatio) {
-        updatePipSizeConstraints(mPipBoundsState.getNormalBounds(),
-                aspectRatio);
-    }
-
-    private void updatePipSizeConstraints(Rect normalBounds,
-            float aspectRatio) {
-        if (mPipResizeGestureHandler.isUsingPinchToZoom()) {
-            updatePinchResizeSizeConstraints(aspectRatio);
-        } else {
-            mPipResizeGestureHandler.updateMinSize(normalBounds.width(), normalBounds.height());
-            mPipResizeGestureHandler.updateMaxSize(mPipBoundsState.getExpandedBounds().width(),
-                    mPipBoundsState.getExpandedBounds().height());
-        }
-    }
-
-    private void updatePinchResizeSizeConstraints(float aspectRatio) {
-        mPipBoundsState.updateMinMaxSize(aspectRatio);
-        mPipResizeGestureHandler.updateMinSize(mPipBoundsState.getMinSize().x,
-                mPipBoundsState.getMinSize().y);
-        mPipResizeGestureHandler.updateMaxSize(mPipBoundsState.getMaxSize().x,
-                mPipBoundsState.getMaxSize().y);
-    }
-
-    /**
      * TODO Add appropriate description
      */
     public void onRegistrationChanged(boolean isRegistered) {