diff --git a/services/core/java/com/android/server/display/LocalDisplayAdapter.java b/services/core/java/com/android/server/display/LocalDisplayAdapter.java index c7c0fab6140df..7701bc6271aee 100644 --- a/services/core/java/com/android/server/display/LocalDisplayAdapter.java +++ b/services/core/java/com/android/server/display/LocalDisplayAdapter.java @@ -701,11 +701,15 @@ final class LocalDisplayAdapter extends DisplayAdapter { maxDisplayMode == null ? mInfo.width : maxDisplayMode.getPhysicalWidth(); final int maxHeight = maxDisplayMode == null ? mInfo.height : maxDisplayMode.getPhysicalHeight(); - mInfo.displayCutout = DisplayCutout.fromResourcesRectApproximation(res, - mInfo.uniqueId, maxWidth, maxHeight, mInfo.width, mInfo.height); - mInfo.roundedCorners = RoundedCorners.fromResources( - res, mInfo.uniqueId, maxWidth, maxHeight, mInfo.width, mInfo.height); + // We cannot determine cutouts and rounded corners of external displays. + if (mStaticDisplayInfo.isInternal) { + mInfo.displayCutout = DisplayCutout.fromResourcesRectApproximation(res, + mInfo.uniqueId, maxWidth, maxHeight, mInfo.width, mInfo.height); + mInfo.roundedCorners = RoundedCorners.fromResources( + res, mInfo.uniqueId, maxWidth, maxHeight, mInfo.width, mInfo.height); + } + mInfo.installOrientation = mStaticDisplayInfo.installOrientation; mInfo.displayShape = DisplayShape.fromResources( diff --git a/services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java b/services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java index b7dbaf93b9e20..f89f73c98cfde 100644 --- a/services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/display/LocalDisplayAdapterTest.java @@ -37,6 +37,7 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; +import android.graphics.Rect; import android.os.Binder; import android.os.Handler; import android.os.IBinder; @@ -1009,6 +1010,72 @@ public class LocalDisplayAdapterTest { 0.001f); } + @Test + public void test_getDisplayDeviceInfoLocked_internalDisplay_usesCutoutAndCorners() + throws Exception { + setupCutoutAndRoundedCorners(); + FakeDisplay display = new FakeDisplay(PORT_A); + display.info.isInternal = true; + setUpDisplay(display); + updateAvailableDisplays(); + mAdapter.registerLocked(); + waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS); + assertThat(mListener.addedDisplays.size()).isEqualTo(1); + DisplayDevice displayDevice = mListener.addedDisplays.get(0); + + // Turn on / initialize + Runnable changeStateRunnable = displayDevice.requestDisplayStateLocked(Display.STATE_ON, 0, + 0); + changeStateRunnable.run(); + waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS); + mListener.changedDisplays.clear(); + + DisplayDeviceInfo info = displayDevice.getDisplayDeviceInfoLocked(); + + assertThat(info.displayCutout).isNotNull(); + assertThat(info.displayCutout.getBoundingRectTop()).isEqualTo(new Rect(507, 33, 573, 99)); + assertThat(info.roundedCorners).isNotNull(); + assertThat(info.roundedCorners.getRoundedCorner(0).getRadius()).isEqualTo(5); + } + + @Test public void test_getDisplayDeviceInfoLocked_externalDisplay_doesNotUseCutoutOrCorners() + throws Exception { + setupCutoutAndRoundedCorners(); + FakeDisplay display = new FakeDisplay(PORT_A); + display.info.isInternal = false; + setUpDisplay(display); + updateAvailableDisplays(); + mAdapter.registerLocked(); + waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS); + assertThat(mListener.addedDisplays.size()).isEqualTo(1); + DisplayDevice displayDevice = mListener.addedDisplays.get(0); + + // Turn on / initialize + Runnable changeStateRunnable = displayDevice.requestDisplayStateLocked(Display.STATE_ON, 0, + 0); + changeStateRunnable.run(); + waitForHandlerToComplete(mHandler, HANDLER_WAIT_MS); + mListener.changedDisplays.clear(); + + DisplayDeviceInfo info = displayDevice.getDisplayDeviceInfoLocked(); + + assertThat(info.displayCutout).isNull(); + assertThat(info.roundedCorners).isNull(); + } + + private void setupCutoutAndRoundedCorners() { + String sampleCutout = "M 507,66\n" + + "a 33,33 0 1 0 66,0 33,33 0 1 0 -66,0\n" + + "Z\n" + + "@left\n"; + // Setup some default cutout + when(mMockedResources.getString( + com.android.internal.R.string.config_mainBuiltInDisplayCutout)) + .thenReturn(sampleCutout); + when(mMockedResources.getDimensionPixelSize( + com.android.internal.R.dimen.rounded_corner_radius)).thenReturn(5); + } + private void assertDisplayDpi(DisplayDeviceInfo info, int expectedPort, float expectedXdpi, float expectedYDpi,