diff --git a/core/java/com/android/internal/policy/PipSnapAlgorithm.java b/core/java/com/android/internal/policy/PipSnapAlgorithm.java index 4dd3360bcacd4..6d13743583212 100644 --- a/core/java/com/android/internal/policy/PipSnapAlgorithm.java +++ b/core/java/com/android/internal/policy/PipSnapAlgorithm.java @@ -128,11 +128,14 @@ public class PipSnapAlgorithm { /** * Applies the offset to the {@param stackBounds} to adjust it to a minimized state. */ - public void applyMinimizedOffset(Rect stackBounds, Rect movementBounds, Point displaySize) { + public void applyMinimizedOffset(Rect stackBounds, Rect movementBounds, Point displaySize, + Rect stableInsets) { if (stackBounds.left <= movementBounds.centerX()) { - stackBounds.offsetTo(-stackBounds.width() + mMinimizedVisibleSize, stackBounds.top); + stackBounds.offsetTo(stableInsets.left + mMinimizedVisibleSize - stackBounds.width(), + stackBounds.top); } else { - stackBounds.offsetTo(displaySize.x - mMinimizedVisibleSize, stackBounds.top); + stackBounds.offsetTo(displaySize.x - stableInsets.right - mMinimizedVisibleSize, + stackBounds.top); } } diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java index 18ae3cf90017a..1476110384fbb 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java @@ -87,6 +87,7 @@ public class PipTouchHandler implements TunerService.Tunable { // Allow the PIP to be "docked" slightly offscreen private boolean mEnableMinimizing = true; + private final Rect mStableInsets = new Rect(); private final Rect mPinnedStackBounds = new Rect(); private final Rect mBoundedPinnedStackBounds = new Rect(); private ValueAnimator mPinnedStackBoundsAnimator = null; @@ -421,7 +422,8 @@ public class PipTouchHandler implements TunerService.Tunable { mContext.getDisplay().getRealSize(displaySize); Rect toBounds = mSnapAlgorithm.findClosestSnapBounds(mBoundedPinnedStackBounds, mPinnedStackBounds); - mSnapAlgorithm.applyMinimizedOffset(toBounds, mBoundedPinnedStackBounds, displaySize); + mSnapAlgorithm.applyMinimizedOffset(toBounds, mBoundedPinnedStackBounds, displaySize, + mStableInsets); mPinnedStackBoundsAnimator = mMotionHelper.createAnimationToBounds(mPinnedStackBounds, toBounds, MINIMIZE_STACK_MAX_DURATION, LINEAR_OUT_SLOW_IN, mUpdatePinnedStackBoundsListener); @@ -528,6 +530,7 @@ public class PipTouchHandler implements TunerService.Tunable { if (updatePinnedStackBounds) { mPinnedStackBounds.set(info.bounds); } + mWindowManager.getStableInsets(info.displayId, mStableInsets); mBoundedPinnedStackBounds.set(mWindowManager.getPictureInPictureMovementBounds( info.displayId)); } diff --git a/services/core/java/com/android/server/wm/PinnedStackController.java b/services/core/java/com/android/server/wm/PinnedStackController.java index 34633c243d657..bfb4269f7806e 100644 --- a/services/core/java/com/android/server/wm/PinnedStackController.java +++ b/services/core/java/com/android/server/wm/PinnedStackController.java @@ -82,6 +82,7 @@ class PinnedStackController { // Used to calculate stack bounds across rotations private final DisplayInfo mDisplayInfo = new DisplayInfo(); + private final Rect mStableInsets = new Rect(); // The size and position information that describes where the pinned stack will go by default. private int mDefaultStackGravity; @@ -250,10 +251,12 @@ class PinnedStackController { } /** - * @return the repositioned PIP bounds given it's pre-change bounds, and the new display info. + * @return the repositioned PIP bounds given it's pre-change bounds, and the new display + * content. */ - Rect onDisplayChanged(Rect preChangeStackBounds, DisplayInfo displayInfo) { + Rect onDisplayChanged(Rect preChangeStackBounds, DisplayContent displayContent) { final Rect postChangeStackBounds = new Rect(preChangeStackBounds); + final DisplayInfo displayInfo = displayContent.getDisplayInfo(); if (!mDisplayInfo.equals(displayInfo)) { // Calculate the snap fraction of the current stack along the old movement bounds, and // then update the stack bounds to the same fraction along the rotated movement bounds. @@ -269,8 +272,9 @@ class PinnedStackController { if (mIsMinimized) { final Point displaySize = new Point(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight); + mService.getStableInsetsLocked(displayContent.getDisplayId(), mStableInsets); mSnapAlgorithm.applyMinimizedOffset(postChangeStackBounds, postChangeMovementBounds, - displaySize); + displaySize, mStableInsets); } } return postChangeStackBounds; diff --git a/services/core/java/com/android/server/wm/TaskStack.java b/services/core/java/com/android/server/wm/TaskStack.java index eeea532858f13..0f31188d36eba 100644 --- a/services/core/java/com/android/server/wm/TaskStack.java +++ b/services/core/java/com/android/server/wm/TaskStack.java @@ -413,7 +413,7 @@ public class TaskStack extends WindowContainer implements DimLayer.DimLaye switch (mStackId) { case PINNED_STACK_ID: mTmpRect2 = mDisplayContent.getPinnedStackController().onDisplayChanged(mBounds, - getDisplayInfo()); + mDisplayContent); break; case DOCKED_STACK_ID: repositionDockedStackAfterRotation(mTmpRect2); @@ -684,7 +684,7 @@ public class TaskStack extends WindowContainer implements DimLayer.DimLaye // Update the pinned stack controller after the display info is updated if (mStackId == PINNED_STACK_ID) { mDisplayContent.getPinnedStackController().onDisplayChanged(oldBounds, - getDisplayInfo()); + mDisplayContent); } super.onDisplayChanged(dc);