From aede04193fec7a498e73814dd41bb455a1cf0715 Mon Sep 17 00:00:00 2001 From: Milton Wu Date: Wed, 18 May 2022 17:44:16 +0800 Subject: [PATCH] Fix punch hole wrong position during rotation 1. Updating front camera protection info as super class of DisplayCutoutBaseView during rotation changed. 2. Fix incorrect comparing inside onPreDraw() 3. Use getDisplayInfo() to get real-time updated rotation info. Bug: 233011725 Test: atest ScreenDecorationsTest Test: Enable front camera, and check punch hole during rotating device Change-Id: I2b8ef62ec2e815c649b35bbad1cb4c4fc8f7eeb7 --- .../android/systemui/ScreenDecorations.java | 37 +++++++++++-------- .../systemui/ScreenDecorationsTest.java | 12 +++--- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java index 685c585a52bef..088dfb41900e1 100644 --- a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java +++ b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java @@ -159,6 +159,8 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab @VisibleForTesting protected DisplayDecorationSupport mHwcScreenDecorationSupport; private Display.Mode mDisplayMode; + @VisibleForTesting + protected DisplayInfo mDisplayInfo = new DisplayInfo(); private CameraAvailabilityListener.CameraTransitionCallback mCameraTransitionCallback = new CameraAvailabilityListener.CameraTransitionCallback() { @@ -325,9 +327,10 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab private void startOnScreenDecorationsThread() { mWindowManager = mContext.getSystemService(WindowManager.class); mDisplayManager = mContext.getSystemService(DisplayManager.class); - mRotation = mContext.getDisplay().getRotation(); - mDisplayMode = mContext.getDisplay().getMode(); - mDisplayUniqueId = mContext.getDisplay().getUniqueId(); + mContext.getDisplay().getDisplayInfo(mDisplayInfo); + mRotation = mDisplayInfo.rotation; + mDisplayMode = mDisplayInfo.getMode(); + mDisplayUniqueId = mDisplayInfo.uniqueId; mRoundedCornerResDelegate = new RoundedCornerResDelegate(mContext.getResources(), mDisplayUniqueId); mRoundedCornerResDelegate.setPhysicalPixelDisplaySizeRatio( @@ -351,8 +354,9 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab @Override public void onDisplayChanged(int displayId) { - final int newRotation = mContext.getDisplay().getRotation(); - final Display.Mode newDisplayMode = mContext.getDisplay().getMode(); + mContext.getDisplay().getDisplayInfo(mDisplayInfo); + final int newRotation = mDisplayInfo.rotation; + final Display.Mode newDisplayMode = mDisplayInfo.getMode(); if ((mOverlays != null || mScreenDecorHwcWindow != null) && (mRotation != newRotation || displayModeChanged(mDisplayMode, newDisplayMode))) { @@ -398,7 +402,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab } } - final String newUniqueId = mContext.getDisplay().getUniqueId(); + final String newUniqueId = mDisplayInfo.uniqueId; if (!Objects.equals(newUniqueId, mDisplayUniqueId)) { mDisplayUniqueId = newUniqueId; final DisplayDecorationSupport newScreenDecorationSupport = @@ -923,11 +927,10 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab @VisibleForTesting float getPhysicalPixelDisplaySizeRatio() { final Point stableDisplaySize = mDisplayManager.getStableDisplaySize(); - final DisplayInfo displayInfo = new DisplayInfo(); - mContext.getDisplay().getDisplayInfo(displayInfo); + mContext.getDisplay().getDisplayInfo(mDisplayInfo); return DisplayUtils.getPhysicalPixelDisplaySizeRatio( - stableDisplaySize.x, stableDisplaySize.y, displayInfo.getNaturalWidth(), - displayInfo.getNaturalHeight()); + stableDisplaySize.x, stableDisplaySize.y, mDisplayInfo.getNaturalWidth(), + mDisplayInfo.getNaturalHeight()); } @Override @@ -1004,11 +1007,12 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab "must call on " + mHandler.getLooper().getThread() + ", but was " + Thread.currentThread()); - int newRotation = mContext.getDisplay().getRotation(); + mContext.getDisplay().getDisplayInfo(mDisplayInfo); + final int newRotation = mDisplayInfo.rotation; if (mRotation != newRotation) { mDotViewController.setNewRotation(newRotation); } - final Display.Mode newMod = mContext.getDisplay().getMode(); + final Display.Mode newMod = mDisplayInfo.getMode(); if (!mPendingConfigChange && (newRotation != mRotation || displayModeChanged(mDisplayMode, newMod))) { @@ -1220,7 +1224,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab @Override public void updateRotation(int rotation) { mRotation = rotation; - updateCutout(); + super.updateRotation(rotation); } @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) @@ -1431,9 +1435,10 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab @Override public boolean onPreDraw() { - final int displayRotation = mContext.getDisplay().getRotation(); - final Display.Mode displayMode = mContext.getDisplay().getMode(); - if (displayRotation != mRotation && displayModeChanged(mDisplayMode, displayMode) + mContext.getDisplay().getDisplayInfo(mDisplayInfo); + final int displayRotation = mDisplayInfo.rotation; + final Display.Mode displayMode = mDisplayInfo.getMode(); + if ((displayRotation != mRotation || displayModeChanged(mDisplayMode, displayMode)) && !mPendingConfigChange) { if (DEBUG) { if (displayRotation != mRotation) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java index 57253af57f0e2..92e49473927fd 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java @@ -63,6 +63,7 @@ import android.util.RotationUtils; import android.util.Size; import android.view.Display; import android.view.DisplayCutout; +import android.view.DisplayInfo; import android.view.Surface; import android.view.View; import android.view.ViewGroup; @@ -136,6 +137,8 @@ public class ScreenDecorationsTest extends SysuiTestCase { private CornerDecorProvider mPrivacyDotBottomRightDecorProvider; @Mock private Display.Mode mDisplayMode; + @Mock + private DisplayInfo mDisplayInfo; private PrivacyDotViewController.ShowingListener mPrivacyDotShowingListener; @Before @@ -159,7 +162,7 @@ public class ScreenDecorationsTest extends SysuiTestCase { when(mContext.getDisplay()).thenReturn(mDisplay); // Not support hwc layer by default doReturn(null).when(mDisplay).getDisplayDecorationSupport(); - doReturn(mDisplayMode).when(mDisplay).getMode(); + doReturn(mDisplayMode).when(mDisplayInfo).getMode(); when(mMockTypedArray.length()).thenReturn(0); mPrivacyDotTopLeftDecorProvider = spy(new PrivacyDotCornerDecorProviderImpl( @@ -214,6 +217,7 @@ public class ScreenDecorationsTest extends SysuiTestCase { mExecutor.runAllReady(); } }); + mScreenDecorations.mDisplayInfo = mDisplayInfo; doReturn(1f).when(mScreenDecorations).getPhysicalPixelDisplaySizeRatio(); reset(mTunerService); @@ -977,7 +981,7 @@ public class ScreenDecorationsTest extends SysuiTestCase { getTestsDrawable(com.android.systemui.tests.R.drawable.rounded4px) /* roundedBottomDrawable */, 0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */); - doReturn(Surface.ROTATION_0).when(mDisplay).getRotation(); + mDisplayInfo.rotation = Surface.ROTATION_0; mScreenDecorations.start(); @@ -991,7 +995,7 @@ public class ScreenDecorationsTest extends SysuiTestCase { getTestsDrawable(com.android.systemui.tests.R.drawable.rounded5px) /* roundedBottomDrawable */, 0 /* roundedPadding */, false /* fillCutout */, true /* privacyDot */); - doReturn(Surface.ROTATION_270).when(mDisplay).getRotation(); + mDisplayInfo.rotation = Surface.ROTATION_270; mScreenDecorations.onConfigurationChanged(null); @@ -1274,7 +1278,6 @@ public class ScreenDecorationsTest extends SysuiTestCase { final ScreenDecorHwcLayer hwcLayer = mScreenDecorations.mScreenDecorHwcLayer; spyOn(hwcLayer); doReturn(mDisplay).when(hwcLayer).getDisplay(); - doReturn(mDisplayMode).when(mDisplay).getMode(); mScreenDecorations.mDisplayListener.onDisplayChanged(1); @@ -1298,7 +1301,6 @@ public class ScreenDecorationsTest extends SysuiTestCase { mScreenDecorations.mCutoutViews[BOUNDS_POSITION_TOP]; spyOn(cutoutView); doReturn(mDisplay).when(cutoutView).getDisplay(); - doReturn(mDisplayMode).when(mDisplay).getMode(); mScreenDecorations.mDisplayListener.onDisplayChanged(1);