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
This commit is contained in:
Fiona Campbell
2023-06-12 16:04:38 +00:00
parent 614ed9e0e9
commit b31a5b6234

View File

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