From c2bae89e368945aa89cec484bc45cc297699ba29 Mon Sep 17 00:00:00 2001 From: Evan Laird Date: Wed, 1 Jul 2020 20:33:27 -0400 Subject: [PATCH] Cache Display.Mode so we can ignore refresh rate changes DisplayCutoutView calls #update() when `onDisplayChanged` is called, but if that were to be called _only_ because the refresh rate changes, then we redraw the displaycutoutview (with no meaningful changes) and this causes the display to change refresh rate again, starting the loop over. Fixes: 155155363 Test: manual Change-Id: Ic885cf24a9f4cc45970a3388653789abb3f592bb --- .../android/systemui/ScreenDecorations.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java index 6c06553a84a6c..ad11d71eb132a 100644 --- a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java +++ b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java @@ -62,6 +62,7 @@ import android.os.UserHandle; import android.provider.Settings.Secure; import android.util.DisplayMetrics; import android.util.Log; +import android.view.Display; import android.view.DisplayCutout; import android.view.DisplayCutout.BoundsPosition; import android.view.DisplayInfo; @@ -820,6 +821,7 @@ public class ScreenDecorations extends SystemUI implements Tunable { private static final float HIDDEN_CAMERA_PROTECTION_SCALE = 0.5f; + private Display.Mode mDisplayMode = null; private final DisplayInfo mInfo = new DisplayInfo(); private final Paint mPaint = new Paint(); private final List mBounds = new ArrayList(); @@ -904,11 +906,33 @@ public class ScreenDecorations extends SystemUI implements Tunable { @Override public void onDisplayChanged(int displayId) { + Display.Mode oldMode = mDisplayMode; + mDisplayMode = getDisplay().getMode(); + + // Display mode hasn't meaningfully changed, we can ignore it + if (!modeChanged(oldMode, mDisplayMode)) { + return; + } + if (displayId == getDisplay().getDisplayId()) { update(); } } + private boolean modeChanged(Display.Mode oldMode, Display.Mode newMode) { + if (oldMode == null) { + return true; + } + + boolean changed = false; + changed |= oldMode.getPhysicalHeight() != newMode.getPhysicalHeight(); + changed |= oldMode.getPhysicalWidth() != newMode.getPhysicalWidth(); + // We purposely ignore refresh rate and id changes here, because we don't need to + // invalidate for those, and they can trigger the refresh rate to increase + + return changed; + } + public void setRotation(int rotation) { mRotation = rotation; update();