Merge "Ensure invalid brightness values aren't used" into udc-dev

This commit is contained in:
TreeHugger Robot
2023-05-26 16:45:49 +00:00
committed by Android (Google) Code Review
2 changed files with 48 additions and 11 deletions

View File

@@ -333,11 +333,8 @@ public class AutomaticBrightnessController {
// Initialize to active (normal) screen brightness mode
switchToInteractiveScreenBrightnessMode();
if (userLux != BrightnessMappingStrategy.NO_USER_LUX
&& userBrightness != BrightnessMappingStrategy.NO_USER_BRIGHTNESS) {
// Use the given short-term model
setScreenBrightnessByUser(userLux, userBrightness);
}
// Use the given short-term model
setScreenBrightnessByUser(userLux, userBrightness);
}
/**
@@ -520,6 +517,10 @@ public class AutomaticBrightnessController {
}
private boolean setScreenBrightnessByUser(float lux, float brightness) {
if (lux == BrightnessMappingStrategy.NO_USER_LUX
|| brightness == BrightnessMappingStrategy.NO_USER_BRIGHTNESS) {
return false;
}
mCurrentBrightnessMapper.addUserDataPoint(lux, brightness);
mShortTermModel.setUserBrightness(lux, brightness);
return true;
@@ -1234,14 +1235,14 @@ public class AutomaticBrightnessController {
// light.
// The anchor determines what were the light levels when the user has set their preference,
// and we use a relative threshold to determine when to revert to the OEM curve.
private float mAnchor = -1f;
private float mBrightness;
private boolean mIsValid = true;
private float mAnchor = BrightnessMappingStrategy.NO_USER_LUX;
private float mBrightness = BrightnessMappingStrategy.NO_USER_BRIGHTNESS;
private boolean mIsValid = false;
private void reset() {
mAnchor = -1f;
mBrightness = -1f;
mIsValid = true;
mAnchor = BrightnessMappingStrategy.NO_USER_LUX;
mBrightness = BrightnessMappingStrategy.NO_USER_BRIGHTNESS;
mIsValid = false;
}
private void invalidate() {

View File

@@ -472,6 +472,42 @@ public class AutomaticBrightnessControllerTest {
.addUserDataPoint(anyFloat(), anyFloat());
}
@Test
public void testSwitchBetweenModesNoUserInteractions() throws Exception {
ArgumentCaptor<SensorEventListener> listenerCaptor =
ArgumentCaptor.forClass(SensorEventListener.class);
verify(mSensorManager).registerListener(listenerCaptor.capture(), eq(mLightSensor),
eq(INITIAL_LIGHT_SENSOR_RATE * 1000), any(Handler.class));
SensorEventListener listener = listenerCaptor.getValue();
// Sensor reads 123 lux,
listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 123));
when(mBrightnessMappingStrategy.getShortTermModelTimeout()).thenReturn(2000L);
when(mBrightnessMappingStrategy.getUserBrightness()).thenReturn(-1.0f);
when(mBrightnessMappingStrategy.getUserLux()).thenReturn(-1.0f);
// No user brightness interaction.
mController.switchToIdleMode();
when(mIdleBrightnessMappingStrategy.isForIdleMode()).thenReturn(true);
when(mIdleBrightnessMappingStrategy.getUserBrightness()).thenReturn(-1.0f);
when(mIdleBrightnessMappingStrategy.getUserLux()).thenReturn(-1.0f);
// Sensor reads 1000 lux,
listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1000));
// Do not fast-forward time.
mTestLooper.dispatchAll();
mController.switchToInteractiveScreenBrightnessMode();
// Do not fast-forward time
mTestLooper.dispatchAll();
// Ensure that there are no data points added, since the user has never adjusted the
// brightness
verify(mBrightnessMappingStrategy, times(0))
.addUserDataPoint(anyFloat(), anyFloat());
}
@Test
public void testSwitchToIdleMappingStrategy() throws Exception {
ArgumentCaptor<SensorEventListener> listenerCaptor =