summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chen Bai <chenbai@google.com> 2024-09-24 20:53:13 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-09-24 20:53:13 +0000
commitdcbe9fbb24f9765b856a4992ef3bed1944ace66b (patch)
tree8fe2a70849cad49f8dd8dc0066b5d29b6422b3e9
parent4e4b677baff8b23e7c8e85022b468816dddea774 (diff)
parent7842c143f37a002cfc696e7a71461732e752597a (diff)
Merge "brightness: fix conditions for using doze brightness" into main
-rw-r--r--services/core/java/com/android/server/display/AutomaticBrightnessController.java5
-rw-r--r--services/core/java/com/android/server/display/DisplayPowerController.java13
-rw-r--r--services/core/java/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategy.java6
-rw-r--r--services/tests/displayservicetests/src/com/android/server/display/DisplayPowerControllerTest.java42
-rw-r--r--services/tests/displayservicetests/src/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategyTest.java10
5 files changed, 62 insertions, 14 deletions
diff --git a/services/core/java/com/android/server/display/AutomaticBrightnessController.java b/services/core/java/com/android/server/display/AutomaticBrightnessController.java
index 86015acc232f..774041152d3e 100644
--- a/services/core/java/com/android/server/display/AutomaticBrightnessController.java
+++ b/services/core/java/com/android/server/display/AutomaticBrightnessController.java
@@ -1279,8 +1279,9 @@ public class AutomaticBrightnessController {
private boolean shouldApplyDozeScaleFactor() {
// We don't apply the doze scale factor if we have a designated brightness curve for doze.
return (mDisplayManagerFlags.isNormalBrightnessForDozeParameterEnabled()
- ? !mUseNormalBrightnessForDoze && mDisplayPolicy == POLICY_DOZE
- : Display.isDozeState(mDisplayState)) && getMode() != AUTO_BRIGHTNESS_MODE_DOZE;
+ ? (!mUseNormalBrightnessForDoze && mDisplayPolicy == POLICY_DOZE)
+ || Display.isDozeState(mDisplayState) : Display.isDozeState(mDisplayState))
+ && getMode() != AUTO_BRIGHTNESS_MODE_DOZE;
}
private class ShortTermModel {
diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java
index 04573f4b7514..711bc7972091 100644
--- a/services/core/java/com/android/server/display/DisplayPowerController.java
+++ b/services/core/java/com/android/server/display/DisplayPowerController.java
@@ -1357,6 +1357,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
mDisplayStateController.shouldPerformScreenOffTransition());
state = mPowerState.getScreenState();
+ // Use doze brightness if one of following is true:
+ // 1. The target `state` isDozeState.
+ // 2. Doze power request(POLICY_DOZE) if there's no exception(useNormalBrightnessForDoze).
+ final boolean useDozeBrightness = mFlags.isNormalBrightnessForDozeParameterEnabled()
+ ? (!mPowerRequest.useNormalBrightnessForDoze && mPowerRequest.policy == POLICY_DOZE)
+ || Display.isDozeState(state) : Display.isDozeState(state);
+
DisplayBrightnessState displayBrightnessState = mDisplayBrightnessController
.updateBrightness(mPowerRequest, state, mDisplayOffloadSession);
float brightnessState = displayBrightnessState.getBrightness();
@@ -1399,7 +1406,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
&& !mAutomaticBrightnessController.isInIdleMode()) {
// Set sendUpdate to false, we're already in updatePowerState() so there's no need
// to trigger it again
- mAutomaticBrightnessController.switchMode(Display.isDozeState(state)
+ mAutomaticBrightnessController.switchMode(useDozeBrightness
? AUTO_BRIGHTNESS_MODE_DOZE : AUTO_BRIGHTNESS_MODE_DEFAULT,
/* sendUpdate= */ false);
}
@@ -1472,9 +1479,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
brightnessState = clampScreenBrightness(brightnessState);
}
- if (mFlags.isNormalBrightnessForDozeParameterEnabled()
- ? !mPowerRequest.useNormalBrightnessForDoze && mPowerRequest.policy == POLICY_DOZE
- : Display.isDozeState(state)) {
+ if (useDozeBrightness) {
// TODO(b/329676661): Introduce a config property to choose between this brightness
// strategy and DOZE_DEFAULT
// On some devices, when auto-brightness is disabled and the device is dozing, we use
diff --git a/services/core/java/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategy.java b/services/core/java/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategy.java
index bf01f2d9c749..2fdec78bbbda 100644
--- a/services/core/java/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategy.java
+++ b/services/core/java/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategy.java
@@ -510,10 +510,10 @@ public class AutomaticBrightnessStrategy extends AutomaticBrightnessStrategy2
&& mAutomaticBrightnessController != null
&& !mAutomaticBrightnessController.isInIdleMode()) {
- boolean shouldUseDozeMode =
+ final boolean shouldUseDozeMode =
mDisplayManagerFlags.isNormalBrightnessForDozeParameterEnabled()
- ? !useNormalBrightnessForDoze && policy == POLICY_DOZE
- : Display.isDozeState(state);
+ ? (!useNormalBrightnessForDoze && policy == POLICY_DOZE)
+ || Display.isDozeState(state) : Display.isDozeState(state);
mAutomaticBrightnessController.switchMode(shouldUseDozeMode
? AUTO_BRIGHTNESS_MODE_DOZE : AUTO_BRIGHTNESS_MODE_DEFAULT, sendUpdate);
}
diff --git a/services/tests/displayservicetests/src/com/android/server/display/DisplayPowerControllerTest.java b/services/tests/displayservicetests/src/com/android/server/display/DisplayPowerControllerTest.java
index bf5a692ef8ca..c70bf8abaef6 100644
--- a/services/tests/displayservicetests/src/com/android/server/display/DisplayPowerControllerTest.java
+++ b/services/tests/displayservicetests/src/com/android/server/display/DisplayPowerControllerTest.java
@@ -2127,6 +2127,48 @@ public final class DisplayPowerControllerTest {
}
@Test
+ public void testManualBrightness_stateDozePolicyOnUseNormalBrightnessForDozeTrue_brightnessDoze() {
+ when(mDisplayManagerFlagsMock.isDisplayOffloadEnabled()).thenReturn(true);
+ when(mDisplayManagerFlagsMock.isNormalBrightnessForDozeParameterEnabled()).thenReturn(true);
+ mHolder.dpc.setDisplayOffloadSession(mDisplayOffloadSession);
+ Settings.System.putInt(mContext.getContentResolver(),
+ Settings.System.SCREEN_BRIGHTNESS_MODE,
+ Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
+ float brightness = 0.277f;
+ when(mHolder.displayPowerState.getColorFadeLevel()).thenReturn(1.0f);
+ when(mHolder.brightnessSetting.getBrightness()).thenReturn(brightness);
+ when(mHolder.hbmController.getCurrentBrightnessMax())
+ .thenReturn(PowerManager.BRIGHTNESS_MAX);
+ when(mHolder.displayPowerState.getScreenState()).thenReturn(Display.STATE_ON);
+ // Start with state=DOZE.
+ when(mHolder.displayPowerState.getScreenState()).thenReturn(Display.STATE_DOZE);
+ DisplayPowerRequest dprInit = new DisplayPowerRequest();
+ dprInit.policy = DisplayPowerRequest.POLICY_DOZE;
+ mHolder.dpc.requestPowerState(dprInit, /* waitForNegativeProximity= */ false);
+ advanceTime(1); // Run updatePowerState; initialize to DOZE
+ // Go to state=ON. But state change would be blocked. so, state=DOZE.
+ when(mDisplayOffloadSession.blockScreenOn(any())).thenReturn(true);
+ DisplayPowerRequest dpr = new DisplayPowerRequest();
+ dpr.dozeScreenState = Display.STATE_ON;
+ dpr.policy = DisplayPowerRequest.POLICY_BRIGHT;
+ dpr.useNormalBrightnessForDoze = true;
+ mHolder.dpc.requestPowerState(dpr, /* waitForNegativeProximity= */ false);
+ advanceTime(1); // Run updatePowerState; process turning on.
+
+ ArgumentCaptor<BrightnessSetting.BrightnessSettingListener> listenerCaptor =
+ ArgumentCaptor.forClass(BrightnessSetting.BrightnessSettingListener.class);
+ verify(mHolder.brightnessSetting).registerListener(listenerCaptor.capture());
+ BrightnessSetting.BrightnessSettingListener listener = listenerCaptor.getValue();
+ listener.onBrightnessChanged(brightness);
+ advanceTime(1); // Send messages, run updatePowerState
+
+ // When state=DOZE, force doze brightness regardless the requested policy.
+ verify(mHolder.animator).animateTo(eq(brightness * DOZE_SCALE_FACTOR),
+ /* linearSecondTarget= */ anyFloat(), /* rate= */ anyFloat(),
+ /* ignoreAnimationLimits= */ anyBoolean());
+ }
+
+ @Test
public void testDozeManualBrightness_AbcIsNull() {
when(mDisplayManagerFlagsMock.isDisplayOffloadEnabled()).thenReturn(true);
mHolder = createDisplayPowerController(DISPLAY_ID, UNIQUE_ID, /* isEnabled= */ true,
diff --git a/services/tests/displayservicetests/src/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategyTest.java b/services/tests/displayservicetests/src/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategyTest.java
index 50f814da6488..efa8b3ef775f 100644
--- a/services/tests/displayservicetests/src/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategyTest.java
+++ b/services/tests/displayservicetests/src/com/android/server/display/brightness/strategy/AutomaticBrightnessStrategyTest.java
@@ -397,9 +397,9 @@ public class AutomaticBrightnessStrategyTest {
mAutomaticBrightnessStrategy.setAutoBrightnessState(Display.STATE_DOZE,
allowAutoBrightnessWhileDozing, brightnessReason, policy,
useNormalBrightnessForDoze, lastUserSetBrightness, userSetBrightnessChanged);
- // 1st AUTO_BRIGHTNESS_MODE_DEFAULT
- verify(mAutomaticBrightnessController).switchMode(
- AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_DEFAULT,
+ // 3rd AUTO_BRIGHTNESS_MODE_DOZE
+ verify(mAutomaticBrightnessController, times(3)).switchMode(
+ AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_DOZE,
/* sendUpdate= */ false);
// Validate interaction when automaticBrightnessController is in non-idle mode, display
@@ -407,8 +407,8 @@ public class AutomaticBrightnessStrategyTest {
mAutomaticBrightnessStrategy.setAutoBrightnessState(Display.STATE_ON,
allowAutoBrightnessWhileDozing, brightnessReason, policy,
useNormalBrightnessForDoze, lastUserSetBrightness, userSetBrightnessChanged);
- // 2nd AUTO_BRIGHTNESS_MODE_DEFAULT
- verify(mAutomaticBrightnessController, times(2)).switchMode(
+ // AUTO_BRIGHTNESS_MODE_DEFAULT
+ verify(mAutomaticBrightnessController).switchMode(
AutomaticBrightnessController.AUTO_BRIGHTNESS_MODE_DEFAULT,
/* sendUpdate= */ false);
}