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
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user