From c2e83fdc360b6dec08db54ec90198d32e0172ec8 Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Tue, 17 Jan 2023 14:46:45 -0800 Subject: [PATCH] Fix duplicate display update upon nav mode change When changing the navigation mode with PiP present, PipController could receive multiple onDisplayChanged callbacks due to insets check added in ag/19904559, this could eventually be conflict with the DisplayInsetsController#OnInsetsChangedListener callback. Bug: 261388495 Test: repeatedly change nav mode and enter PiP Test: ensure PiP window not overlap with TaskBar (when in button nav) Change-Id: If8aeebbb26b2123f38e3abb63aa67b42aca759a8 --- .../com/android/wm/shell/common/DisplayLayout.java | 6 ++---- .../com/android/wm/shell/pip/phone/PipController.java | 11 ++++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayLayout.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayLayout.java index 96efeeb0c5ebd..84840139d1a3d 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayLayout.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayLayout.java @@ -96,8 +96,7 @@ public class DisplayLayout { /** * Different from {@link #equals(Object)}, this method compares the basic geometry properties - * of two {@link DisplayLayout} objects including width, height, rotation, density, cutout and - * insets. + * of two {@link DisplayLayout} objects including width, height, rotation, density, cutout. * @return {@code true} if the given {@link DisplayLayout} is identical geometry wise. */ public boolean isSameGeometry(@NonNull DisplayLayout other) { @@ -105,8 +104,7 @@ public class DisplayLayout { && mHeight == other.mHeight && mRotation == other.mRotation && mDensityDpi == other.mDensityDpi - && Objects.equals(mCutout, other.mCutout) - && Objects.equals(mStableInsets, other.mStableInsets); + && Objects.equals(mCutout, other.mCutout); } @Override 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 3153313de42f7..c9613abf6c44d 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 @@ -46,8 +46,6 @@ import android.content.res.Configuration; import android.graphics.Rect; import android.os.RemoteException; import android.os.SystemProperties; -import android.os.UserHandle; -import android.os.UserManager; import android.util.Pair; import android.util.Size; import android.view.DisplayInfo; @@ -618,7 +616,7 @@ public class PipController implements PipTransitionController.PipTransitionCallb return; } int oldMaxMovementBound = mPipBoundsState.getMovementBounds().bottom; - onDisplayChanged( + onDisplayChangedUncheck( mDisplayController.getDisplayLayout(mPipBoundsState.getDisplayId()), false /* saveRestoreSnapFraction */); int newMaxMovementBound = mPipBoundsState.getMovementBounds().bottom; @@ -704,9 +702,12 @@ public class PipController implements PipTransitionController.PipTransitionCallb } private void onDisplayChanged(DisplayLayout layout, boolean saveRestoreSnapFraction) { - if (mPipBoundsState.getDisplayLayout().isSameGeometry(layout)) { - return; + if (!mPipBoundsState.getDisplayLayout().isSameGeometry(layout)) { + onDisplayChangedUncheck(layout, saveRestoreSnapFraction); } + } + + private void onDisplayChangedUncheck(DisplayLayout layout, boolean saveRestoreSnapFraction) { Runnable updateDisplayLayout = () -> { final boolean fromRotation = Transitions.ENABLE_SHELL_TRANSITIONS && mPipBoundsState.getDisplayLayout().rotation() != layout.rotation();