Ensure Display Settings Overrides Do Not Impact TestDisplayContent
Display overrides such as width, height, and density
should not override values set in TestDisplayContent.
Otherwise, test conditions are not consistent and can
lead to test failures on some devices.
To prevent this, set the uniqueId of the DisplayInfo
of the TestDisplayContent to a value different from
that of the actual device displays. This ensures that
DisplayWindowSettingsProvider does not apply override
settings by comparing against uniqueId.
Bug: b/182499175
Test: atest DisplayContentTests
Change-Id: I0ad10c2b3dc30849373a938bfd06533731f1a6dc
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
index 67fe7bf..ed4b954 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
@@ -1925,6 +1925,81 @@
assertEquals(new Rect(500, 0, 2000, 700), rotateBounds);
}
+ /**
+ * Creates a TestDisplayContent using the constructor that takes in display width and height as
+ * parameters and validates that the newly-created TestDisplayContent's DisplayInfo and
+ * WindowConfiguration match the parameters passed into the constructor. Additionally, this test
+ * checks that device-specific overrides are not applied.
+ */
+ @Test
+ public void testCreateTestDisplayContentFromDimensions() {
+ final int displayWidth = 1000;
+ final int displayHeight = 2000;
+ final int windowingMode = WINDOWING_MODE_FULLSCREEN;
+ final boolean ignoreOrientationRequests = false;
+ final float fixedOrientationLetterboxRatio = 0;
+ final DisplayContent testDisplayContent = new TestDisplayContent.Builder(mAtm, displayWidth,
+ displayHeight).build();
+
+ // test display info
+ final DisplayInfo di = testDisplayContent.getDisplayInfo();
+ assertEquals(displayWidth, di.logicalWidth);
+ assertEquals(displayHeight, di.logicalHeight);
+ assertEquals(TestDisplayContent.DEFAULT_LOGICAL_DISPLAY_DENSITY, di.logicalDensityDpi);
+
+ // test configuration
+ final WindowConfiguration windowConfig = testDisplayContent.getConfiguration()
+ .windowConfiguration;
+ assertEquals(displayWidth, windowConfig.getBounds().width());
+ assertEquals(displayHeight, windowConfig.getBounds().height());
+ assertEquals(windowingMode, windowConfig.getWindowingMode());
+
+ // test misc display overrides
+ assertEquals(ignoreOrientationRequests, testDisplayContent.mIgnoreOrientationRequest);
+ assertEquals(fixedOrientationLetterboxRatio, mWm.getFixedOrientationLetterboxAspectRatio(),
+ 0 /* delta */);
+ }
+
+ /**
+ * Creates a TestDisplayContent using the constructor that takes in a DisplayInfo as a parameter
+ * and validates that the newly-created TestDisplayContent's DisplayInfo and WindowConfiguration
+ * match the width, height, and density values set in the DisplayInfo passed as a parameter.
+ * Additionally, this test checks that device-specific overrides are not applied.
+ */
+ @Test
+ public void testCreateTestDisplayContentFromDisplayInfo() {
+ final int displayWidth = 1000;
+ final int displayHeight = 2000;
+ final int windowingMode = WINDOWING_MODE_FULLSCREEN;
+ final boolean ignoreOrientationRequests = false;
+ final float fixedOrientationLetterboxRatio = 0;
+ final DisplayInfo testDisplayInfo = new DisplayInfo();
+ mContext.getDisplay().getDisplayInfo(testDisplayInfo);
+ testDisplayInfo.logicalWidth = displayWidth;
+ testDisplayInfo.logicalHeight = displayHeight;
+ testDisplayInfo.logicalDensityDpi = TestDisplayContent.DEFAULT_LOGICAL_DISPLAY_DENSITY;
+ final DisplayContent testDisplayContent = new TestDisplayContent.Builder(mAtm,
+ testDisplayInfo).build();
+
+ // test display info
+ final DisplayInfo di = testDisplayContent.getDisplayInfo();
+ assertEquals(displayWidth, di.logicalWidth);
+ assertEquals(displayHeight, di.logicalHeight);
+ assertEquals(TestDisplayContent.DEFAULT_LOGICAL_DISPLAY_DENSITY, di.logicalDensityDpi);
+
+ // test configuration
+ final WindowConfiguration windowConfig = testDisplayContent.getConfiguration()
+ .windowConfiguration;
+ assertEquals(displayWidth, windowConfig.getBounds().width());
+ assertEquals(displayHeight, windowConfig.getBounds().height());
+ assertEquals(windowingMode, windowConfig.getWindowingMode());
+
+ // test misc display overrides
+ assertEquals(ignoreOrientationRequests, testDisplayContent.mIgnoreOrientationRequest);
+ assertEquals(fixedOrientationLetterboxRatio, mWm.getFixedOrientationLetterboxAspectRatio(),
+ 0 /* delta */);
+ }
+
private boolean isOptionsPanelAtRight(int displayId) {
return (mWm.getPreferredOptionsPanelGravity(displayId) & Gravity.RIGHT) == Gravity.RIGHT;
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayWindowSettingsProviderTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayWindowSettingsProviderTests.java
index 3e05c86..18a1caa 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayWindowSettingsProviderTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayWindowSettingsProviderTests.java
@@ -102,7 +102,7 @@
SettingsEntry expectedSettings = new SettingsEntry();
expectedSettings.mWindowingMode = WINDOWING_MODE_PINNED;
- readAndAssertExpectedSettings(mPrimaryDisplay, expectedSettings);
+ readAndAssertExpectedSettings(mSecondaryDisplay, expectedSettings);
}
@Test
@@ -176,17 +176,17 @@
// Expected settings should be empty because the default is to read from the primary vendor
// settings location.
SettingsEntry expectedSettings = new SettingsEntry();
- assertEquals(expectedSettings, provider.getSettings(mPrimaryDisplay.getDisplayInfo()));
+ assertEquals(expectedSettings, provider.getSettings(mSecondaryDisplay.getDisplayInfo()));
// Now switch to secondary vendor settings and assert proper settings.
provider.setBaseSettingsStorage(mSecondaryVendorSettingsStorage);
expectedSettings.mWindowingMode = WINDOWING_MODE_FULLSCREEN;
- assertEquals(expectedSettings, provider.getSettings(mPrimaryDisplay.getDisplayInfo()));
+ assertEquals(expectedSettings, provider.getSettings(mSecondaryDisplay.getDisplayInfo()));
// Switch back to primary and assert settings are empty again.
provider.setBaseSettingsStorage(mDefaultVendorSettingsStorage);
expectedSettings.mWindowingMode = WINDOWING_MODE_UNDEFINED;
- assertEquals(expectedSettings, provider.getSettings(mPrimaryDisplay.getDisplayInfo()));
+ assertEquals(expectedSettings, provider.getSettings(mSecondaryDisplay.getDisplayInfo()));
}
@Test
@@ -204,7 +204,7 @@
// take precedence over the vendor provided settings.
SettingsEntry expectedSettings = new SettingsEntry();
expectedSettings.mWindowingMode = WINDOWING_MODE_PINNED;
- assertEquals(expectedSettings, provider.getSettings(mPrimaryDisplay.getDisplayInfo()));
+ assertEquals(expectedSettings, provider.getSettings(mSecondaryDisplay.getDisplayInfo()));
}
@Test
diff --git a/services/tests/wmtests/src/com/android/server/wm/TestDisplayContent.java b/services/tests/wmtests/src/com/android/server/wm/TestDisplayContent.java
index 21536a6..777149b 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TestDisplayContent.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TestDisplayContent.java
@@ -37,6 +37,8 @@
class TestDisplayContent extends DisplayContent {
+ public static final int DEFAULT_LOGICAL_DISPLAY_DENSITY = 300;
+
/** Please use the {@link Builder} to create, visible for use in test builder overrides only. */
TestDisplayContent(RootWindowContainer rootWindowContainer, Display display) {
super(display, rootWindowContainer);
@@ -82,12 +84,21 @@
mService.mContext.getDisplay().getDisplayInfo(mInfo);
mInfo.logicalWidth = width;
mInfo.logicalHeight = height;
- mInfo.logicalDensityDpi = 300;
+ mInfo.logicalDensityDpi = DEFAULT_LOGICAL_DISPLAY_DENSITY;
mInfo.displayCutout = null;
+ // Set unique ID so physical display overrides are not inheritted from
+ // DisplayWindowSettings.
+ mInfo.uniqueId = generateUniqueId();
}
Builder(ActivityTaskManagerService service, DisplayInfo info) {
mService = service;
mInfo = info;
+ // Set unique ID so physical display overrides are not inheritted from
+ // DisplayWindowSettings.
+ mInfo.uniqueId = generateUniqueId();
+ }
+ private String generateUniqueId() {
+ return "TEST_DISPLAY_CONTENT_" + System.currentTimeMillis();
}
Builder setSystemDecorations(boolean yes) {
mSystemDecorations = yes;