From de507114822f4b158e0da135c4d8b67736d0d90f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Ciche=C5=84ski?= Date: Fri, 17 Feb 2023 01:14:32 +0000 Subject: [PATCH] Make sure PiP appears on screen when folding the device Folding triggers onDisplayChanged callback that will update the display layout used to compute PiP position. However, due to race condition of the setShelfHeight handler, sometimes the new bounds for PiP are set by using the bounds in animator from previous display layout. That value is used as a reference when we call onMovementBoundsChanged in PipTaskOrganizer, and thus results sometimes in displacing PiP outside of the visible screen bounds when folding. Test: manually, via temporary log statement in the "if" body to verify the trigger condition Test: before http://recall/-/fj1xzZpuaq8SChahfwQ86e/dXk0Qq0aeOSbqoiMSoazIm Test: after http://recall/-/fj1xzZpuaq8SChahfwQ86e/eHOB8F62DUS9d284FpWk7R Bug: 263211281 Change-Id: Ibfa68f94bc81797d55c33c0aafcc937e04079a53 --- .../com/android/wm/shell/pip/PipAnimationController.java | 2 +- .../src/com/android/wm/shell/pip/phone/PipController.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java index d9ac76e833d87..23f73f6142945 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java @@ -209,7 +209,7 @@ public class PipAnimationController { /** * Quietly cancel the animator by removing the listeners first. */ - static void quietCancel(@NonNull ValueAnimator animator) { + public static void quietCancel(@NonNull ValueAnimator animator) { animator.removeAllUpdateListeners(); animator.removeAllListeners(); animator.cancel(); 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 ec34f73126fbd..fa3efeb51bd0d 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 @@ -715,6 +715,12 @@ public class PipController implements PipTransitionController.PipTransitionCallb private void onDisplayChanged(DisplayLayout layout, boolean saveRestoreSnapFraction) { if (!mPipBoundsState.getDisplayLayout().isSameGeometry(layout)) { + PipAnimationController.PipTransitionAnimator animator = + mPipAnimationController.getCurrentAnimator(); + if (animator != null && animator.isRunning()) { + // cancel any running animator, as it is using stale display layout information + PipAnimationController.quietCancel(animator); + } onDisplayChangedUncheck(layout, saveRestoreSnapFraction); } }