From aa32a564298e9e4a57f5592f76de73ed344a687a Mon Sep 17 00:00:00 2001 From: Shawn Lin Date: Tue, 1 Nov 2022 17:25:22 +0800 Subject: [PATCH] Fix cutout not updating when switching cutout emulation The root cause is that we didn't update the config for cutout change only case. Add detection for cutout change in updateConfiguration(). Bug: 256652639 Test: switch between different cutout emulation and observe the result. Change-Id: Ic169d8d9f305ae2158a6a9f88f7bc5683426a56c --- .../src/com/android/systemui/DisplayCutoutBaseView.kt | 2 +- .../src/com/android/systemui/ScreenDecorations.java | 10 ++++++++-- .../com/android/systemui/DisplayCutoutBaseViewTest.kt | 6 +++++- .../com/android/systemui/ScreenDecorHwcLayerTest.kt | 5 ++++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/DisplayCutoutBaseView.kt b/packages/SystemUI/src/com/android/systemui/DisplayCutoutBaseView.kt index 5d52056d8b170..90ecb466b5d00 100644 --- a/packages/SystemUI/src/com/android/systemui/DisplayCutoutBaseView.kt +++ b/packages/SystemUI/src/com/android/systemui/DisplayCutoutBaseView.kt @@ -169,7 +169,7 @@ open class DisplayCutoutBaseView : View, RegionInterceptableView { return } cutoutPath.reset() - display.getDisplayInfo(displayInfo) + context.display?.getDisplayInfo(displayInfo) displayInfo.displayCutout?.cutoutPath?.let { path -> cutoutPath.set(path) } invalidate() } diff --git a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java index 11d579d481c18..45f9385a26208 100644 --- a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java +++ b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java @@ -170,6 +170,7 @@ public class ScreenDecorations implements CoreStartable, Tunable , Dumpable { private Display.Mode mDisplayMode; @VisibleForTesting protected DisplayInfo mDisplayInfo = new DisplayInfo(); + private DisplayCutout mDisplayCutout; @VisibleForTesting protected void showCameraProtection(@NonNull Path protectionPath, @NonNull Rect bounds) { @@ -384,6 +385,7 @@ public class ScreenDecorations implements CoreStartable, Tunable , Dumpable { mRotation = mDisplayInfo.rotation; mDisplayMode = mDisplayInfo.getMode(); mDisplayUniqueId = mDisplayInfo.uniqueId; + mDisplayCutout = mDisplayInfo.displayCutout; mRoundedCornerResDelegate = new RoundedCornerResDelegate(mContext.getResources(), mDisplayUniqueId); mRoundedCornerResDelegate.setPhysicalPixelDisplaySizeRatio( @@ -1022,7 +1024,8 @@ public class ScreenDecorations implements CoreStartable, Tunable , Dumpable { mRoundedCornerResDelegate.dump(pw, args); } - private void updateConfiguration() { + @VisibleForTesting + void updateConfiguration() { Preconditions.checkState(mHandler.getLooper().getThread() == Thread.currentThread(), "must call on " + mHandler.getLooper().getThread() + ", but was " + Thread.currentThread()); @@ -1033,11 +1036,14 @@ public class ScreenDecorations implements CoreStartable, Tunable , Dumpable { mDotViewController.setNewRotation(newRotation); } final Display.Mode newMod = mDisplayInfo.getMode(); + final DisplayCutout newCutout = mDisplayInfo.displayCutout; if (!mPendingConfigChange - && (newRotation != mRotation || displayModeChanged(mDisplayMode, newMod))) { + && (newRotation != mRotation || displayModeChanged(mDisplayMode, newMod) + || !Objects.equals(newCutout, mDisplayCutout))) { mRotation = newRotation; mDisplayMode = newMod; + mDisplayCutout = newCutout; mRoundedCornerResDelegate.setPhysicalPixelDisplaySizeRatio( getPhysicalPixelDisplaySizeRatio()); if (mScreenDecorHwcLayer != null) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/DisplayCutoutBaseViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/DisplayCutoutBaseViewTest.kt index a4e0825360dfe..588620646b73a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/DisplayCutoutBaseViewTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/DisplayCutoutBaseViewTest.kt @@ -16,6 +16,7 @@ package com.android.systemui +import android.content.Context import android.graphics.Canvas import android.graphics.Insets import android.graphics.Path @@ -48,6 +49,7 @@ class DisplayCutoutBaseViewTest : SysuiTestCase() { @Mock private lateinit var mockCanvas: Canvas @Mock private lateinit var mockRootView: View @Mock private lateinit var mockDisplay: Display + @Mock private lateinit var mockContext: Context private lateinit var cutoutBaseView: DisplayCutoutBaseView private val cutout: DisplayCutout = DisplayCutout.Builder() @@ -168,7 +170,9 @@ class DisplayCutoutBaseViewTest : SysuiTestCase() { R.bool.config_fillMainBuiltInDisplayCutout, fillCutout) cutoutBaseView = spy(DisplayCutoutBaseView(mContext)) - whenever(cutoutBaseView.display).thenReturn(mockDisplay) + + whenever(cutoutBaseView.context).thenReturn(mockContext) + whenever(mockContext.display).thenReturn(mockDisplay) whenever(mockDisplay.uniqueId).thenReturn("mockDisplayUniqueId") whenever(cutoutBaseView.rootView).thenReturn(mockRootView) whenever(cutoutBaseView.getPhysicalPixelDisplaySizeRatio()).thenReturn(1f) diff --git a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorHwcLayerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorHwcLayerTest.kt index 054650bb8a75a..8207fa6958f33 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorHwcLayerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorHwcLayerTest.kt @@ -16,6 +16,7 @@ package com.android.systemui +import android.content.Context import android.graphics.Insets import android.graphics.PixelFormat import android.graphics.Rect @@ -44,6 +45,7 @@ class ScreenDecorHwcLayerTest : SysuiTestCase() { @Mock private lateinit var mockDisplay: Display @Mock private lateinit var mockRootView: View + @Mock private lateinit var mockContext: Context private val displayWidth = 100 private val displayHeight = 200 @@ -75,7 +77,8 @@ class ScreenDecorHwcLayerTest : SysuiTestCase() { decorHwcLayer = Mockito.spy(ScreenDecorHwcLayer(mContext, decorationSupport)) whenever(decorHwcLayer.width).thenReturn(displayWidth) whenever(decorHwcLayer.height).thenReturn(displayHeight) - whenever(decorHwcLayer.display).thenReturn(mockDisplay) + whenever(decorHwcLayer.context).thenReturn(mockContext) + whenever(mockContext.display).thenReturn(mockDisplay) whenever(decorHwcLayer.rootView).thenReturn(mockRootView) whenever(mockRootView.left).thenReturn(0) whenever(mockRootView.top).thenReturn(0)