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
This commit is contained in:
Hongwei Wang
2023-01-17 14:46:45 -08:00
parent a59b096a67
commit c2e83fdc36
2 changed files with 8 additions and 9 deletions

View File

@@ -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

View File

@@ -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();