Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c2e83fdc authored by Hongwei Wang's avatar Hongwei Wang
Browse files

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
parent a59b096a
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -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
+6 −5
Original line number Diff line number Diff line
@@ -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();