Loading services/core/java/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategy.java +13 −6 Original line number Diff line number Diff line Loading @@ -165,9 +165,8 @@ public class AutomaticBrightnessStrategy extends AutomaticBrightnessStrategy2 public boolean isAutoBrightnessValid() { boolean isValid = false; if (isAutoBrightnessEnabled()) { float brightness = (mAutomaticBrightnessController != null) ? mAutomaticBrightnessController.getAutomaticScreenBrightness(null) : PowerManager.BRIGHTNESS_INVALID_FLOAT; float brightness = getAutomaticScreenBrightness(null, /* isAutomaticBrightnessAdjusted = */ false); if (BrightnessUtils.isValidBrightnessValue(brightness) || brightness == PowerManager.BRIGHTNESS_OFF_FLOAT) { isValid = true; Loading Loading @@ -274,7 +273,12 @@ public class AutomaticBrightnessStrategy extends AutomaticBrightnessStrategy2 BrightnessReason brightnessReason = new BrightnessReason(); brightnessReason.setReason(BrightnessReason.REASON_AUTOMATIC); BrightnessEvent brightnessEvent = mInjector.getBrightnessEvent(mDisplayId); float brightness = getAutomaticScreenBrightness(brightnessEvent); // AutoBrightness adjustments were already applied while checking the validity of this // strategy. Reapplying them again will result in incorrect adjustment reason flags as we // might end up assuming no adjustments are applied float brightness = getAutomaticScreenBrightness(brightnessEvent, /* isAutomaticBrightnessAdjusted = */ true); return new DisplayBrightnessState.Builder() .setBrightness(brightness) .setSdrBrightness(brightness) Loading Loading @@ -355,11 +359,14 @@ public class AutomaticBrightnessStrategy extends AutomaticBrightnessStrategy2 * @param brightnessEvent Event object to populate with details about why the specific * brightness was chosen. */ public float getAutomaticScreenBrightness(BrightnessEvent brightnessEvent) { public float getAutomaticScreenBrightness(BrightnessEvent brightnessEvent, boolean isAutomaticBrightnessAdjusted) { float brightness = (mAutomaticBrightnessController != null) ? mAutomaticBrightnessController.getAutomaticScreenBrightness(brightnessEvent) : PowerManager.BRIGHTNESS_INVALID_FLOAT; if (!isAutomaticBrightnessAdjusted) { adjustAutomaticBrightnessStateIfValid(brightness); } return brightness; } Loading services/tests/displayservicetests/src/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategyTest.java +26 −2 Original line number Diff line number Diff line Loading @@ -395,7 +395,7 @@ public class AutomaticBrightnessStrategyTest { automaticBrightnessController); assertEquals(automaticScreenBrightness, mAutomaticBrightnessStrategy.getAutomaticScreenBrightness( new BrightnessEvent(DISPLAY_ID)), 0.0f); new BrightnessEvent(DISPLAY_ID), false), 0.0f); assertEquals(automaticScreenBrightness, mAutomaticBrightnessStrategy.getAutomaticScreenBrightnessBasedOnLastUsedLux( new BrightnessEvent(DISPLAY_ID)), 0.0f); Loading Loading @@ -461,8 +461,12 @@ public class AutomaticBrightnessStrategyTest { } @Test public void isAutoBrightnessValid_returnsTrueWhenBrightnessIsValid() { public void isAutoBrightnessValid_returnsTrueWhenBrightnessIsValid_adjustsAutoBrightness() throws Settings.SettingNotFoundException { float adjustment = 0.1f; mAutomaticBrightnessStrategy.setUseAutoBrightness(true); when(mAutomaticBrightnessController.getAutomaticScreenBrightnessAdjustment()) .thenReturn(0.1f); mAutomaticBrightnessStrategy.setAutoBrightnessState(Display.STATE_ON, true, BrightnessReason.REASON_UNKNOWN, DisplayManagerInternal.DisplayPowerRequest.POLICY_BRIGHT, 0.1f, Loading @@ -470,6 +474,11 @@ public class AutomaticBrightnessStrategyTest { when(mAutomaticBrightnessController.getAutomaticScreenBrightness(null)) .thenReturn(0.2f); assertTrue(mAutomaticBrightnessStrategy.isAutoBrightnessValid()); assertEquals(adjustment, mAutomaticBrightnessStrategy.getAutoBrightnessAdjustment(), 0.0f); assertEquals(adjustment, Settings.System.getFloatForUser( mContext.getContentResolver(), Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, UserHandle.USER_CURRENT), 0.0f); } @Test Loading @@ -486,6 +495,15 @@ public class AutomaticBrightnessStrategyTest { when(mAutomaticBrightnessController.getAutomaticScreenBrightness(brightnessEvent)) .thenReturn(brightness); // We do this to apply the automatic brightness adjustments when(mAutomaticBrightnessController.getAutomaticScreenBrightnessAdjustment()).thenReturn( 0.25f); when(mAutomaticBrightnessController.getAutomaticScreenBrightness(null)) .thenReturn(brightness); assertEquals(brightness, mAutomaticBrightnessStrategy .getAutomaticScreenBrightness(null, false), 0.0f); DisplayManagerInternal.DisplayPowerRequest displayPowerRequest = mock(DisplayManagerInternal.DisplayPowerRequest.class); DisplayBrightnessState expectedDisplayBrightnessState = new DisplayBrightnessState.Builder() Loading Loading @@ -529,6 +547,12 @@ public class AutomaticBrightnessStrategyTest { when(mAutomaticBrightnessController.getAutomaticScreenBrightnessAdjustment()).thenReturn( autoBrightnessAdjustment); // We do this to apply the automatic brightness adjustments when(mAutomaticBrightnessController.getAutomaticScreenBrightness(null)) .thenReturn(brightness); assertEquals(brightness, mAutomaticBrightnessStrategy .getAutomaticScreenBrightness(null, false), 0.0f); DisplayBrightnessState expectedDisplayBrightnessState = new DisplayBrightnessState.Builder() .setBrightness(brightness) .setSdrBrightness(brightness) Loading Loading
services/core/java/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategy.java +13 −6 Original line number Diff line number Diff line Loading @@ -165,9 +165,8 @@ public class AutomaticBrightnessStrategy extends AutomaticBrightnessStrategy2 public boolean isAutoBrightnessValid() { boolean isValid = false; if (isAutoBrightnessEnabled()) { float brightness = (mAutomaticBrightnessController != null) ? mAutomaticBrightnessController.getAutomaticScreenBrightness(null) : PowerManager.BRIGHTNESS_INVALID_FLOAT; float brightness = getAutomaticScreenBrightness(null, /* isAutomaticBrightnessAdjusted = */ false); if (BrightnessUtils.isValidBrightnessValue(brightness) || brightness == PowerManager.BRIGHTNESS_OFF_FLOAT) { isValid = true; Loading Loading @@ -274,7 +273,12 @@ public class AutomaticBrightnessStrategy extends AutomaticBrightnessStrategy2 BrightnessReason brightnessReason = new BrightnessReason(); brightnessReason.setReason(BrightnessReason.REASON_AUTOMATIC); BrightnessEvent brightnessEvent = mInjector.getBrightnessEvent(mDisplayId); float brightness = getAutomaticScreenBrightness(brightnessEvent); // AutoBrightness adjustments were already applied while checking the validity of this // strategy. Reapplying them again will result in incorrect adjustment reason flags as we // might end up assuming no adjustments are applied float brightness = getAutomaticScreenBrightness(brightnessEvent, /* isAutomaticBrightnessAdjusted = */ true); return new DisplayBrightnessState.Builder() .setBrightness(brightness) .setSdrBrightness(brightness) Loading Loading @@ -355,11 +359,14 @@ public class AutomaticBrightnessStrategy extends AutomaticBrightnessStrategy2 * @param brightnessEvent Event object to populate with details about why the specific * brightness was chosen. */ public float getAutomaticScreenBrightness(BrightnessEvent brightnessEvent) { public float getAutomaticScreenBrightness(BrightnessEvent brightnessEvent, boolean isAutomaticBrightnessAdjusted) { float brightness = (mAutomaticBrightnessController != null) ? mAutomaticBrightnessController.getAutomaticScreenBrightness(brightnessEvent) : PowerManager.BRIGHTNESS_INVALID_FLOAT; if (!isAutomaticBrightnessAdjusted) { adjustAutomaticBrightnessStateIfValid(brightness); } return brightness; } Loading
services/tests/displayservicetests/src/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategyTest.java +26 −2 Original line number Diff line number Diff line Loading @@ -395,7 +395,7 @@ public class AutomaticBrightnessStrategyTest { automaticBrightnessController); assertEquals(automaticScreenBrightness, mAutomaticBrightnessStrategy.getAutomaticScreenBrightness( new BrightnessEvent(DISPLAY_ID)), 0.0f); new BrightnessEvent(DISPLAY_ID), false), 0.0f); assertEquals(automaticScreenBrightness, mAutomaticBrightnessStrategy.getAutomaticScreenBrightnessBasedOnLastUsedLux( new BrightnessEvent(DISPLAY_ID)), 0.0f); Loading Loading @@ -461,8 +461,12 @@ public class AutomaticBrightnessStrategyTest { } @Test public void isAutoBrightnessValid_returnsTrueWhenBrightnessIsValid() { public void isAutoBrightnessValid_returnsTrueWhenBrightnessIsValid_adjustsAutoBrightness() throws Settings.SettingNotFoundException { float adjustment = 0.1f; mAutomaticBrightnessStrategy.setUseAutoBrightness(true); when(mAutomaticBrightnessController.getAutomaticScreenBrightnessAdjustment()) .thenReturn(0.1f); mAutomaticBrightnessStrategy.setAutoBrightnessState(Display.STATE_ON, true, BrightnessReason.REASON_UNKNOWN, DisplayManagerInternal.DisplayPowerRequest.POLICY_BRIGHT, 0.1f, Loading @@ -470,6 +474,11 @@ public class AutomaticBrightnessStrategyTest { when(mAutomaticBrightnessController.getAutomaticScreenBrightness(null)) .thenReturn(0.2f); assertTrue(mAutomaticBrightnessStrategy.isAutoBrightnessValid()); assertEquals(adjustment, mAutomaticBrightnessStrategy.getAutoBrightnessAdjustment(), 0.0f); assertEquals(adjustment, Settings.System.getFloatForUser( mContext.getContentResolver(), Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, UserHandle.USER_CURRENT), 0.0f); } @Test Loading @@ -486,6 +495,15 @@ public class AutomaticBrightnessStrategyTest { when(mAutomaticBrightnessController.getAutomaticScreenBrightness(brightnessEvent)) .thenReturn(brightness); // We do this to apply the automatic brightness adjustments when(mAutomaticBrightnessController.getAutomaticScreenBrightnessAdjustment()).thenReturn( 0.25f); when(mAutomaticBrightnessController.getAutomaticScreenBrightness(null)) .thenReturn(brightness); assertEquals(brightness, mAutomaticBrightnessStrategy .getAutomaticScreenBrightness(null, false), 0.0f); DisplayManagerInternal.DisplayPowerRequest displayPowerRequest = mock(DisplayManagerInternal.DisplayPowerRequest.class); DisplayBrightnessState expectedDisplayBrightnessState = new DisplayBrightnessState.Builder() Loading Loading @@ -529,6 +547,12 @@ public class AutomaticBrightnessStrategyTest { when(mAutomaticBrightnessController.getAutomaticScreenBrightnessAdjustment()).thenReturn( autoBrightnessAdjustment); // We do this to apply the automatic brightness adjustments when(mAutomaticBrightnessController.getAutomaticScreenBrightness(null)) .thenReturn(brightness); assertEquals(brightness, mAutomaticBrightnessStrategy .getAutomaticScreenBrightness(null, false), 0.0f); DisplayBrightnessState expectedDisplayBrightnessState = new DisplayBrightnessState.Builder() .setBrightness(brightness) .setSdrBrightness(brightness) Loading