Correct the cutout of external displays

Also correct the rounded corners.

Test: atest LogicalDisplayTest
Test: Present on an external display and observe (see bug)
Fix: 273995115
Change-Id: Ia01f8100ccff398194de9cc53a4edf31b7e74bf8
This commit is contained in:
Pierre Barbier de Reuille
2023-05-24 11:00:18 +01:00
parent 05b23ee478
commit d4a3e12c73
2 changed files with 75 additions and 4 deletions

View File

@@ -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(

View File

@@ -36,6 +36,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;
@@ -1007,6 +1008,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,