From b31a5b62343d240a7161fbb89f2b1cbd1d4484d7 Mon Sep 17 00:00:00 2001 From: Fiona Campbell Date: Mon, 12 Jun 2023 16:04:38 +0000 Subject: [PATCH] Fix ScreenOffBrightnessControllerTest This test was failing on devices where the configuration for config_allowAutoBrightnessWhileDozing defaulted or was set to true. The config should be true, when allowing full automatic screen brightness when in doze, and therefore, screenoffbrightnesssensor should be enabled, only when this value is false, since it is used as a fallback sensor. The timings of the setting the return value of this testable resource needs to come before the variable is actually set when creating the DPC, which is why the DPC needed to be re-initialised in this test. Bug: 286860986 Test: atest DisplayPowerController2Test Change-Id: Ieea7b056f6858e606b5039735e3f0ba729c94646 --- .../android/server/display/DisplayPowerController2Test.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/tests/mockingservicestests/src/com/android/server/display/DisplayPowerController2Test.java b/services/tests/mockingservicestests/src/com/android/server/display/DisplayPowerController2Test.java index 8dc0ac6515cd0..170076098b7d5 100644 --- a/services/tests/mockingservicestests/src/com/android/server/display/DisplayPowerController2Test.java +++ b/services/tests/mockingservicestests/src/com/android/server/display/DisplayPowerController2Test.java @@ -646,14 +646,16 @@ public final class DisplayPowerController2Test { @Test public void testSetScreenOffBrightnessSensorEnabled_DisplayIsInDoze() { + mContext.getOrCreateTestableResources().addOverride( + com.android.internal.R.bool.config_allowAutoBrightnessWhileDozing, false); + mHolder = createDisplayPowerController(DISPLAY_ID, UNIQUE_ID); + Settings.System.putInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC); DisplayPowerRequest dpr = new DisplayPowerRequest(); dpr.policy = DisplayPowerRequest.POLICY_DOZE; - mContext.getOrCreateTestableResources().addOverride( - com.android.internal.R.bool.config_allowAutoBrightnessWhileDozing, true); mHolder.dpc.requestPowerState(dpr, /* waitForNegativeProximity= */ false); advanceTime(1); // Run updatePowerState