From 12199ddbdf3ab7f857e4e8268571b3dcccc1cab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Ciche=C5=84ski?= Date: Mon, 12 Sep 2022 18:19:34 +0000 Subject: [PATCH] Delay PiP movement in response to keep clear areas changed. This prevents erratic movements caused by animations that update layout each frame, effectively reporting new keep clear area bounds every frame and triggerring the movement multiple times. This will now wait for the keep clear areas to stabilize before moving away. Can be customized via system property. Video before: http://recall/-/g8x7ZkgdfbqscttAA9wzl9/hwr0OrO4Pq8cvLw9bgwLff Video after: http://recall/-/g8x7ZkgdfbqscttAA9wzl9/bGTKo0oqCKUwtvBdBYOB9w Bug: 183746978 Test: manually, e.g. open PiP and slowly swipe up to go to overview, which causes Hotseat to animate away triggering keep clear areas changed multiple times, but the PiP moves only once Change-Id: I2214e2250fb3cace8fee117285fd8ffbd27a3870 --- .../wm/shell/pip/phone/PipController.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) 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 6c9a6b64c8647..2a2f09298a08c 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 @@ -112,6 +112,9 @@ public class PipController implements PipTransitionController.PipTransitionCallb UserChangeListener { private static final String TAG = "PipController"; + private static final long PIP_KEEP_CLEAR_AREAS_DELAY = + SystemProperties.getLong("persist.wm.debug.pip_keep_clear_areas_delay", 200); + private boolean mEnablePipKeepClearAlgorithm = SystemProperties.getBoolean("persist.wm.debug.enable_pip_keep_clear_algorithm", false); @@ -143,6 +146,8 @@ public class PipController implements PipTransitionController.PipTransitionCallb private final Rect mTmpInsetBounds = new Rect(); private final int mEnterAnimationDuration; + private final Runnable mMovePipInResponseToKeepClearAreasChangeCallback; + private boolean mIsInFixedRotation; private PipAnimationListener mPinnedStackAnimationRecentsCallback; @@ -274,14 +279,12 @@ public class PipController implements PipTransitionController.PipTransitionCallb if (mPipBoundsState.getDisplayId() == displayId) { if (mEnablePipKeepClearAlgorithm) { mPipBoundsState.setKeepClearAreas(restricted, unrestricted); - // only move if already in pip, other transitions account for keep clear - // areas - if (mPipTransitionState.hasEnteredPip()) { - Rect destBounds = mPipKeepClearAlgorithm.adjust(mPipBoundsState, - mPipBoundsAlgorithm); - mPipTaskOrganizer.scheduleAnimateResizePip(destBounds, - mEnterAnimationDuration, null); - } + + mMainExecutor.removeCallbacks( + mMovePipInResponseToKeepClearAreasChangeCallback); + mMainExecutor.executeDelayed( + mMovePipInResponseToKeepClearAreasChangeCallback, + PIP_KEEP_CLEAR_AREAS_DELAY); } } } @@ -406,6 +409,15 @@ public class PipController implements PipTransitionController.PipTransitionCallb mEnterAnimationDuration = mContext.getResources() .getInteger(R.integer.config_pipEnterAnimationDuration); + mMovePipInResponseToKeepClearAreasChangeCallback = () -> { + // only move if already in pip, other transitions account for keep clear areas + if (mPipTransitionState.hasEnteredPip()) { + Rect destBounds = mPipKeepClearAlgorithm.adjust(mPipBoundsState, + mPipBoundsAlgorithm); + mPipTaskOrganizer.scheduleAnimateResizePip(destBounds, + mEnterAnimationDuration, null); + } + }; mPipParamsChangedForwarder = pipParamsChangedForwarder; shellInit.addInitCallback(this::onInit, this);