Merge "Pass the raw brightness value to the followers"

This commit is contained in:
Piotr Wilczyński
2023-01-25 11:39:16 +00:00
committed by Android (Google) Code Review
4 changed files with 45 additions and 10 deletions

View File

@@ -196,6 +196,11 @@ class AutomaticBrightnessController {
// available.
private float mScreenAutoBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
// The screen brightness level before clamping and throttling. This value needs to be stored
// for concurrent displays mode and passed to the additional displays which will do their own
// clamping and throttling.
private float mRawScreenAutoBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
// The current display policy. This is useful, for example, for knowing when we're dozing,
// where the light sensor may not be available.
private int mDisplayPolicy = DisplayPowerRequest.POLICY_OFF;
@@ -380,6 +385,10 @@ class AutomaticBrightnessController {
return mScreenAutoBrightness;
}
float getRawAutomaticScreenBrightness() {
return mRawScreenAutoBrightness;
}
public boolean hasValidAmbientLux() {
return mAmbientLuxValid;
}
@@ -653,6 +662,7 @@ class AutomaticBrightnessController {
mPreThresholdLux = PowerManager.BRIGHTNESS_INVALID_FLOAT;
}
mScreenAutoBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
mRawScreenAutoBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
mPreThresholdBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
mRecentLightSamples = 0;
mAmbientLightRingBuffer.clear();
@@ -915,6 +925,7 @@ class AutomaticBrightnessController {
float value = mCurrentBrightnessMapper.getBrightness(mAmbientLux, mForegroundAppPackageName,
mForegroundAppCategory);
mRawScreenAutoBrightness = value;
float newScreenAutoBrightness = clampScreenBrightness(value);
// The min/max range can change for brightness due to HBM. See if the current brightness

View File

@@ -1160,6 +1160,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
}
loadScreenOffBrightnessSensor();
int[] sensorValueToLux = mDisplayDeviceConfig.getScreenOffBrightnessSensorValueToLux();
// TODO (b/265793751): Don't instantiate ScreenOffBrightnessSensorController if this is
// a complementary display
if (mScreenOffBrightnessSensor != null && sensorValueToLux != null) {
mScreenOffBrightnessSensorController = new ScreenOffBrightnessSensorController(
mSensorManager,
@@ -1452,7 +1454,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
final boolean autoBrightnessEnabled = mUseAutoBrightness
&& (state == Display.STATE_ON || autoBrightnessEnabledInDoze)
&& Float.isNaN(brightnessState)
&& mAutomaticBrightnessController != null;
&& mAutomaticBrightnessController != null
&& mBrightnessReasonTemp.getReason() != BrightnessReason.REASON_FOLLOWER;
final boolean autoBrightnessDisabledDueToDisplayOff = mUseAutoBrightness
&& !(state == Display.STATE_ON || autoBrightnessEnabledInDoze);
final int autoBrightnessState = autoBrightnessEnabled
@@ -1521,12 +1524,15 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
}
boolean updateScreenBrightnessSetting = false;
float rawBrightnessState = brightnessState;
// Apply auto-brightness.
boolean slowChange = false;
if (Float.isNaN(brightnessState)) {
float newAutoBrightnessAdjustment = autoBrightnessAdjustment;
if (autoBrightnessEnabled) {
rawBrightnessState = mAutomaticBrightnessController
.getRawAutomaticScreenBrightness();
brightnessState = mAutomaticBrightnessController.getAutomaticScreenBrightness(
mTempBrightnessEvent);
newAutoBrightnessAdjustment =
@@ -1568,7 +1574,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
// Use default brightness when dozing unless overridden.
if ((Float.isNaN(brightnessState))
&& Display.isDozeState(state)) {
brightnessState = clampScreenBrightness(mScreenBrightnessDozeConfig);
rawBrightnessState = mScreenBrightnessDozeConfig;
brightnessState = clampScreenBrightness(rawBrightnessState);
mBrightnessReasonTemp.setReason(BrightnessReason.REASON_DOZE_DEFAULT);
}
@@ -1576,7 +1583,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
// brightness
if (Float.isNaN(brightnessState) && autoBrightnessEnabled
&& mScreenOffBrightnessSensorController != null) {
brightnessState = mScreenOffBrightnessSensorController.getAutomaticScreenBrightness();
rawBrightnessState =
mScreenOffBrightnessSensorController.getAutomaticScreenBrightness();
brightnessState = rawBrightnessState;
if (isValidBrightnessValue(brightnessState)) {
brightnessState = clampScreenBrightness(brightnessState);
updateScreenBrightnessSetting = mCurrentScreenBrightnessSetting != brightnessState;
@@ -1587,7 +1596,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
// Apply manual brightness.
if (Float.isNaN(brightnessState)) {
brightnessState = clampScreenBrightness(mCurrentScreenBrightnessSetting);
rawBrightnessState = mCurrentScreenBrightnessSetting;
brightnessState = clampScreenBrightness(rawBrightnessState);
if (brightnessState != mCurrentScreenBrightnessSetting) {
// The manually chosen screen brightness is outside of the currently allowed
// range (i.e., high-brightness-mode), make sure we tell the rest of the system
@@ -1621,7 +1631,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
for (int i = 0; i < displayBrightnessFollowers.size(); i++) {
DisplayPowerControllerInterface follower = displayBrightnessFollowers.valueAt(i);
follower.setBrightnessToFollow(brightnessState, convertToNits(brightnessState));
follower.setBrightnessToFollow(rawBrightnessState, convertToNits(rawBrightnessState));
}
if (updateScreenBrightnessSetting) {

View File

@@ -999,6 +999,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
loadScreenOffBrightnessSensor();
int[] sensorValueToLux = mDisplayDeviceConfig.getScreenOffBrightnessSensorValueToLux();
// TODO (b/265793751): Don't instantiate ScreenOffBrightnessSensorController if this is
// a complementary display
if (mScreenOffBrightnessSensor != null && sensorValueToLux != null) {
mScreenOffBrightnessSensorController = new ScreenOffBrightnessSensorController(
mSensorManager,
@@ -1175,6 +1177,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
DisplayBrightnessState displayBrightnessState = mDisplayBrightnessController
.updateBrightness(mPowerRequest, state);
float brightnessState = displayBrightnessState.getBrightness();
float rawBrightnessState = displayBrightnessState.getBrightness();
mBrightnessReasonTemp.set(displayBrightnessState.getBrightnessReason());
final boolean autoBrightnessEnabledInDoze =
@@ -1185,7 +1188,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
&& (Float.isNaN(brightnessState)
|| mBrightnessReasonTemp.getReason() == BrightnessReason.REASON_TEMPORARY
|| mBrightnessReasonTemp.getReason() == BrightnessReason.REASON_BOOST)
&& mAutomaticBrightnessController != null;
&& mAutomaticBrightnessController != null
&& mBrightnessReasonTemp.getReason() != BrightnessReason.REASON_FOLLOWER;
final boolean autoBrightnessDisabledDueToDisplayOff = mUseAutoBrightness
&& !(state == Display.STATE_ON || autoBrightnessEnabledInDoze);
final int autoBrightnessState = autoBrightnessEnabled
@@ -1239,6 +1243,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
if (Float.isNaN(brightnessState)) {
float newAutoBrightnessAdjustment = autoBrightnessAdjustment;
if (autoBrightnessEnabled) {
rawBrightnessState = mAutomaticBrightnessController
.getRawAutomaticScreenBrightness();
brightnessState = mAutomaticBrightnessController.getAutomaticScreenBrightness(
mTempBrightnessEvent);
newAutoBrightnessAdjustment =
@@ -1280,7 +1286,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
// Use default brightness when dozing unless overridden.
if ((Float.isNaN(brightnessState))
&& Display.isDozeState(state)) {
brightnessState = clampScreenBrightness(mScreenBrightnessDozeConfig);
rawBrightnessState = mScreenBrightnessDozeConfig;
brightnessState = clampScreenBrightness(rawBrightnessState);
mBrightnessReasonTemp.setReason(BrightnessReason.REASON_DOZE_DEFAULT);
}
@@ -1288,7 +1295,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
// brightness
if (Float.isNaN(brightnessState) && autoBrightnessEnabled
&& mScreenOffBrightnessSensorController != null) {
brightnessState = mScreenOffBrightnessSensorController.getAutomaticScreenBrightness();
rawBrightnessState =
mScreenOffBrightnessSensorController.getAutomaticScreenBrightness();
brightnessState = rawBrightnessState;
if (BrightnessUtils.isValidBrightnessValue(brightnessState)) {
brightnessState = clampScreenBrightness(brightnessState);
updateScreenBrightnessSetting = mDisplayBrightnessController.getCurrentBrightness()
@@ -1300,7 +1309,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
// Apply manual brightness.
if (Float.isNaN(brightnessState)) {
brightnessState = clampScreenBrightness(currentBrightnessSetting);
rawBrightnessState = currentBrightnessSetting;
brightnessState = clampScreenBrightness(rawBrightnessState);
if (brightnessState != currentBrightnessSetting) {
// The manually chosen screen brightness is outside of the currently allowed
// range (i.e., high-brightness-mode), make sure we tell the rest of the system
@@ -1334,7 +1344,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
for (int i = 0; i < displayBrightnessFollowers.size(); i++) {
DisplayPowerControllerInterface follower = displayBrightnessFollowers.valueAt(i);
follower.setBrightnessToFollow(brightnessState, convertToNits(brightnessState));
follower.setBrightnessToFollow(rawBrightnessState, convertToNits(rawBrightnessState));
}
if (updateScreenBrightnessSetting) {

View File

@@ -484,6 +484,7 @@ public class AutomaticBrightnessControllerTest {
// Sensor reads 100 lux. We should get max brightness.
listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, (int) lux));
assertEquals(BRIGHTNESS_MAX_FLOAT, mController.getAutomaticScreenBrightness(), 0.0f);
assertEquals(BRIGHTNESS_MAX_FLOAT, mController.getRawAutomaticScreenBrightness(), 0.0f);
// Apply throttling and notify ABC (simulates DisplayPowerController#updatePowerState())
final float throttledBrightness = 0.123f;
@@ -494,6 +495,8 @@ public class AutomaticBrightnessControllerTest {
0 /* adjustment= */, false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
/* shouldResetShortTermModel= */ true);
assertEquals(throttledBrightness, mController.getAutomaticScreenBrightness(), 0.0f);
// The raw brightness value should not have throttling applied
assertEquals(BRIGHTNESS_MAX_FLOAT, mController.getRawAutomaticScreenBrightness(), 0.0f);
// Remove throttling and notify ABC again
when(mBrightnessThrottler.getBrightnessCap()).thenReturn(BRIGHTNESS_MAX_FLOAT);
@@ -503,6 +506,7 @@ public class AutomaticBrightnessControllerTest {
0 /* adjustment= */, false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
/* shouldResetShortTermModel= */ true);
assertEquals(BRIGHTNESS_MAX_FLOAT, mController.getAutomaticScreenBrightness(), 0.0f);
assertEquals(BRIGHTNESS_MAX_FLOAT, mController.getRawAutomaticScreenBrightness(), 0.0f);
}
@Test