From 8d917f9e7eb6be1a44ac4741eed346dd657770b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Ciche=C5=84ski?= Date: Tue, 29 Nov 2022 06:35:32 +0000 Subject: [PATCH] Fix the regression of PiP position in fixed rotation This also fixes issue with rotating on tablets where PiP might go out of bounds. What happens is sometimes the rotation of screen has not issued the callback yet and onInsetsChanged gets called causing regression and mixing up all calculations based on the configuration change that is being applied too early. Basically ordering issue of callbacks. Bug: 254869973 Test: manually, tried with logs statements that confirmed it works as expected regardless of the order in which the events callbacks are received Change-Id: Ie1ac5e94559643028229c7829b35905b175425d2 --- .../com/android/wm/shell/pip/phone/PipController.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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 d28a9f3cf8ff2..efe938f0a2746 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 @@ -612,12 +612,21 @@ public class PipController implements PipTransitionController.PipTransitionCallb new DisplayInsetsController.OnInsetsChangedListener() { @Override public void insetsChanged(InsetsState insetsState) { + DisplayLayout pendingLayout = + mDisplayController.getDisplayLayout(mPipBoundsState.getDisplayId()); + if (mIsInFixedRotation + || pendingLayout.rotation() + != mPipBoundsState.getDisplayLayout().rotation()) { + // bail out if there is a pending rotation or fixed rotation change + return; + } int oldMaxMovementBound = mPipBoundsState.getMovementBounds().bottom; onDisplayChanged( mDisplayController.getDisplayLayout(mPipBoundsState.getDisplayId()), false /* saveRestoreSnapFraction */); int newMaxMovementBound = mPipBoundsState.getMovementBounds().bottom; if (!mEnablePipKeepClearAlgorithm) { + // offset PiP to adjust for bottom inset change int pipTop = mPipBoundsState.getBounds().top; int diff = newMaxMovementBound - oldMaxMovementBound; if (diff < 0 && pipTop > newMaxMovementBound) {