Retain the short-term model when device state changes

- Copy adjustment, userLux and userBrightness to new BrightnessMappingStrategy
- Don't reset the short-term model when a display changes

Bug: 238572374
Test: atest AutomaticBrightnessControllerTest
Test: atest BrightnessMappingStrategyTest
Test: atest DisplayManagerServiceTest
Change-Id: I8a8a3f265c9510bda21abdf0563c02db3e11951e
This commit is contained in:
Piotr Wilczyński
2022-12-07 16:29:59 +00:00
parent c9f75fda74
commit bd748a4787
7 changed files with 161 additions and 49 deletions

View File

@@ -249,7 +249,7 @@ class AutomaticBrightnessController {
HysteresisLevels screenBrightnessThresholdsIdle, Context context,
HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler,
BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort,
int ambientLightHorizonLong) {
int ambientLightHorizonLong, float userLux, float userBrightness) {
this(new Injector(), callbacks, looper, sensorManager, lightSensor,
interactiveModeBrightnessMapper,
lightSensorWarmUpTime, brightnessMin, brightnessMax, dozeScaleFactor,
@@ -258,7 +258,7 @@ class AutomaticBrightnessController {
ambientBrightnessThresholds, screenBrightnessThresholds,
ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, context,
hbmController, brightnessThrottler, idleModeBrightnessMapper,
ambientLightHorizonShort, ambientLightHorizonLong
ambientLightHorizonShort, ambientLightHorizonLong, userLux, userBrightness
);
}
@@ -275,7 +275,7 @@ class AutomaticBrightnessController {
HysteresisLevels screenBrightnessThresholdsIdle, Context context,
HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler,
BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort,
int ambientLightHorizonLong) {
int ambientLightHorizonLong, float userLux, float userBrightness) {
mInjector = injector;
mClock = injector.createClock();
mContext = context;
@@ -322,6 +322,12 @@ class AutomaticBrightnessController {
mIdleModeBrightnessMapper = idleModeBrightnessMapper;
// 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);
}
}
/**
@@ -384,7 +390,8 @@ class AutomaticBrightnessController {
public void configure(int state, @Nullable BrightnessConfiguration configuration,
float brightness, boolean userChangedBrightness, float adjustment,
boolean userChangedAutoBrightnessAdjustment, int displayPolicy) {
boolean userChangedAutoBrightnessAdjustment, int displayPolicy,
boolean shouldResetShortTermModel) {
mState = state;
mHbmController.setAutoBrightnessEnabled(mState);
// While dozing, the application processor may be suspended which will prevent us from
@@ -393,7 +400,7 @@ class AutomaticBrightnessController {
// and hold onto the last computed screen auto brightness. We save the dozing flag for
// debugging purposes.
boolean dozing = (displayPolicy == DisplayPowerRequest.POLICY_DOZE);
boolean changed = setBrightnessConfiguration(configuration);
boolean changed = setBrightnessConfiguration(configuration, shouldResetShortTermModel);
changed |= setDisplayPolicy(displayPolicy);
if (userChangedAutoBrightnessAdjustment) {
changed |= setAutoBrightnessAdjustment(adjustment);
@@ -492,9 +499,13 @@ class AutomaticBrightnessController {
// and we can't use this data to add a new control point to the short-term model.
return false;
}
mCurrentBrightnessMapper.addUserDataPoint(mAmbientLux, brightness);
return setScreenBrightnessByUser(mAmbientLux, brightness);
}
private boolean setScreenBrightnessByUser(float lux, float brightness) {
mCurrentBrightnessMapper.addUserDataPoint(lux, brightness);
mShortTermModelValid = true;
mShortTermModelAnchor = mAmbientLux;
mShortTermModelAnchor = lux;
if (mLoggingEnabled) {
Slog.d(TAG, "ShortTermModel: anchor=" + mShortTermModelAnchor);
}
@@ -514,9 +525,10 @@ class AutomaticBrightnessController {
mShortTermModelValid = false;
}
public boolean setBrightnessConfiguration(BrightnessConfiguration configuration) {
public boolean setBrightnessConfiguration(BrightnessConfiguration configuration,
boolean shouldResetShortTermModel) {
if (mInteractiveModeBrightnessMapper.setBrightnessConfiguration(configuration)) {
if (!isInIdleMode()) {
if (!isInIdleMode() && shouldResetShortTermModel) {
resetShortTermModel();
}
return true;

View File

@@ -51,6 +51,9 @@ import java.util.Objects;
public abstract class BrightnessMappingStrategy {
private static final String TAG = "BrightnessMappingStrategy";
public static final float NO_USER_LUX = -1;
public static final float NO_USER_BRIGHTNESS = -1;
private static final float LUX_GRAD_SMOOTHING = 0.25f;
private static final float MAX_GRAD = 1.0f;
private static final float SHORT_TERM_MODEL_THRESHOLD_RATIO = 0.6f;
@@ -68,6 +71,7 @@ public abstract class BrightnessMappingStrategy {
* Creates a BrightnessMappingStrategy for active (normal) mode.
* @param resources
* @param displayDeviceConfig
* @param displayWhiteBalanceController
* @return the BrightnessMappingStrategy
*/
@Nullable
@@ -82,6 +86,7 @@ public abstract class BrightnessMappingStrategy {
* Creates a BrightnessMappingStrategy for idle screen brightness mode.
* @param resources
* @param displayDeviceConfig
* @param displayWhiteBalanceController
* @return the BrightnessMappingStrategy
*/
@Nullable
@@ -100,6 +105,7 @@ public abstract class BrightnessMappingStrategy {
* @param displayDeviceConfig
* @param isForIdleMode determines whether the configurations loaded are for idle screen
* brightness mode or active screen brightness mode.
* @param displayWhiteBalanceController
* @return the BrightnessMappingStrategy
*/
@Nullable
@@ -370,6 +376,10 @@ public abstract class BrightnessMappingStrategy {
*/
public abstract boolean isForIdleMode();
abstract float getUserLux();
abstract float getUserBrightness();
/**
* Check if the short term model should be reset given the anchor lux the last
* brightness change was made at and the current ambient lux.
@@ -604,8 +614,8 @@ public abstract class BrightnessMappingStrategy {
mMaxGamma = maxGamma;
mAutoBrightnessAdjustment = 0;
mUserLux = -1;
mUserBrightness = -1;
mUserLux = NO_USER_LUX;
mUserBrightness = NO_USER_BRIGHTNESS;
if (mLoggingEnabled) {
PLOG.start("simple mapping strategy");
}
@@ -732,6 +742,16 @@ public abstract class BrightnessMappingStrategy {
return false;
}
@Override
float getUserLux() {
return mUserLux;
}
@Override
float getUserBrightness() {
return mUserBrightness;
}
private void computeSpline() {
Pair<float[], float[]> curve = getAdjustedCurve(mLux, mBrightness, mUserLux,
mUserBrightness, mAutoBrightnessAdjustment, mMaxGamma);
@@ -799,8 +819,8 @@ public abstract class BrightnessMappingStrategy {
mIsForIdleMode = isForIdleMode;
mMaxGamma = maxGamma;
mAutoBrightnessAdjustment = 0;
mUserLux = -1;
mUserBrightness = -1;
mUserLux = NO_USER_LUX;
mUserBrightness = NO_USER_BRIGHTNESS;
mDisplayWhiteBalanceController = displayWhiteBalanceController;
mNits = nits;
@@ -972,6 +992,16 @@ public abstract class BrightnessMappingStrategy {
return mIsForIdleMode;
}
@Override
float getUserLux() {
return mUserLux;
}
@Override
float getUserBrightness() {
return mUserBrightness;
}
/**
* Prints out the default curve and how it differs from the long-term curve
* and the current curve (in case the current curve includes short-term adjustments).

View File

@@ -594,7 +594,7 @@ public final class DisplayManagerService extends SystemService {
getBrightnessConfigForDisplayWithPdsFallbackLocked(
logicalDisplay.getPrimaryDisplayDeviceLocked().getUniqueId(),
userSerial);
dpc.setBrightnessConfiguration(config);
dpc.setBrightnessConfiguration(config, /* shouldResetShortTermModel= */ true);
}
dpc.onSwitchUser(newUserId);
});
@@ -1934,7 +1934,7 @@ public final class DisplayManagerService extends SystemService {
}
DisplayPowerControllerInterface dpc = getDpcFromUniqueIdLocked(uniqueId);
if (dpc != null) {
dpc.setBrightnessConfiguration(c);
dpc.setBrightnessConfiguration(c, /* shouldResetShortTermModel= */ true);
}
}
}
@@ -1983,7 +1983,8 @@ public final class DisplayManagerService extends SystemService {
final DisplayPowerControllerInterface dpc = mDisplayPowerControllers.get(
logicalDisplay.getDisplayIdLocked());
if (dpc != null) {
dpc.setBrightnessConfiguration(config);
dpc.setBrightnessConfiguration(config,
/* shouldResetShortTermModel= */ false);
}
}
});

View File

@@ -225,6 +225,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
// True if should use light sensor to automatically determine doze screen brightness.
private final boolean mAllowAutoBrightnessWhileDozingConfig;
// True if the brightness config has changed and the short-term model needs to be reset
private boolean mShouldResetShortTermModel;
// Whether or not the color fade on screen on / off is enabled.
private final boolean mColorFadeEnabled;
@@ -946,6 +949,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
return;
}
float userLux = BrightnessMappingStrategy.NO_USER_LUX;
float userBrightness = BrightnessMappingStrategy.NO_USER_BRIGHTNESS;
if (mInteractiveModeBrightnessMapper != null) {
userLux = mInteractiveModeBrightnessMapper.getUserLux();
userBrightness = mInteractiveModeBrightnessMapper.getUserBrightness();
}
final boolean isIdleScreenBrightnessEnabled = resources.getBoolean(
R.bool.config_enableIdleScreenBrightnessMode);
mInteractiveModeBrightnessMapper = BrightnessMappingStrategy.create(resources,
@@ -1073,7 +1083,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, mContext,
mHbmController, mBrightnessThrottler, mIdleModeBrightnessMapper,
mDisplayDeviceConfig.getAmbientHorizonShort(),
mDisplayDeviceConfig.getAmbientHorizonLong());
mDisplayDeviceConfig.getAmbientHorizonLong(), userLux, userBrightness);
mBrightnessEventRingBuffer =
new RingBuffer<>(BrightnessEvent.class, RINGBUFFER_MAX);
@@ -1404,7 +1414,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
mBrightnessConfiguration,
mLastUserSetScreenBrightness,
userSetBrightnessChanged, autoBrightnessAdjustment,
autoBrightnessAdjustmentChanged, mPowerRequest.policy);
autoBrightnessAdjustmentChanged, mPowerRequest.policy,
mShouldResetShortTermModel);
mShouldResetShortTermModel = false;
}
if (mBrightnessTracker != null) {
@@ -1800,8 +1812,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
}
@Override
public void setBrightnessConfiguration(BrightnessConfiguration c) {
Message msg = mHandler.obtainMessage(MSG_CONFIGURE_BRIGHTNESS, c);
public void setBrightnessConfiguration(BrightnessConfiguration c,
boolean shouldResetShortTermModel) {
Message msg = mHandler.obtainMessage(MSG_CONFIGURE_BRIGHTNESS,
shouldResetShortTermModel ? 1 : 0, /* unused */ 0, c);
msg.sendToTarget();
}
@@ -2844,6 +2858,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
break;
case MSG_CONFIGURE_BRIGHTNESS:
mBrightnessConfiguration = (BrightnessConfiguration) msg.obj;
mShouldResetShortTermModel = msg.arg1 == 1;
updatePowerState();
break;

View File

@@ -202,6 +202,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
// True if auto-brightness should be used.
private boolean mUseSoftwareAutoBrightnessConfig;
// True if the brightness config has changed and the short-term model needs to be reset
private boolean mShouldResetShortTermModel;
// Whether or not the color fade on screen on / off is enabled.
private final boolean mColorFadeEnabled;
@@ -863,6 +866,13 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
return;
}
float userLux = BrightnessMappingStrategy.NO_USER_LUX;
float userBrightness = BrightnessMappingStrategy.NO_USER_BRIGHTNESS;
if (mInteractiveModeBrightnessMapper != null) {
userLux = mInteractiveModeBrightnessMapper.getUserLux();
userBrightness = mInteractiveModeBrightnessMapper.getUserBrightness();
}
final boolean isIdleScreenBrightnessEnabled = resources.getBoolean(
R.bool.config_enableIdleScreenBrightnessMode);
mInteractiveModeBrightnessMapper = BrightnessMappingStrategy.create(resources,
@@ -990,7 +1000,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, mContext,
mHbmController, mBrightnessThrottler, mIdleModeBrightnessMapper,
mDisplayDeviceConfig.getAmbientHorizonShort(),
mDisplayDeviceConfig.getAmbientHorizonLong());
mDisplayDeviceConfig.getAmbientHorizonLong(), userLux, userBrightness);
mBrightnessEventRingBuffer =
new RingBuffer<>(BrightnessEvent.class, RINGBUFFER_MAX);
@@ -1195,7 +1205,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
mBrightnessConfiguration,
mLastUserSetScreenBrightness,
userSetBrightnessChanged, autoBrightnessAdjustment,
autoBrightnessAdjustmentChanged, mPowerRequest.policy);
autoBrightnessAdjustmentChanged, mPowerRequest.policy,
mShouldResetShortTermModel);
mShouldResetShortTermModel = false;
}
if (mBrightnessTracker != null) {
@@ -1585,8 +1597,10 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
}
@Override
public void setBrightnessConfiguration(BrightnessConfiguration c) {
Message msg = mHandler.obtainMessage(MSG_CONFIGURE_BRIGHTNESS, c);
public void setBrightnessConfiguration(BrightnessConfiguration c,
boolean shouldResetShortTermModel) {
Message msg = mHandler.obtainMessage(MSG_CONFIGURE_BRIGHTNESS,
shouldResetShortTermModel ? 1 : 0, /* unused */ 0, c);
msg.sendToTarget();
}
@@ -2436,6 +2450,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
break;
case MSG_CONFIGURE_BRIGHTNESS:
mBrightnessConfiguration = (BrightnessConfiguration) msg.obj;
mShouldResetShortTermModel = msg.arg1 == 1;
updatePowerState();
break;

View File

@@ -48,7 +48,8 @@ public interface DisplayPowerControllerInterface {
* Used to update the display's BrightnessConfiguration
* @param config The new BrightnessConfiguration
*/
void setBrightnessConfiguration(BrightnessConfiguration config);
void setBrightnessConfiguration(BrightnessConfiguration config,
boolean shouldResetShortTermModel);
/**
* Used to set the ambient color temperature of the Display

View File

@@ -26,6 +26,7 @@ import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyFloat;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -95,7 +96,8 @@ public class AutomaticBrightnessControllerTest {
mLightSensor = TestUtils.createSensor(Sensor.TYPE_LIGHT, "Light Sensor");
mContext = InstrumentationRegistry.getContext();
mController = setupController(mLightSensor);
mController = setupController(mLightSensor, BrightnessMappingStrategy.NO_USER_LUX,
BrightnessMappingStrategy.NO_USER_BRIGHTNESS);
}
@After
@@ -107,7 +109,8 @@ public class AutomaticBrightnessControllerTest {
}
}
private AutomaticBrightnessController setupController(Sensor lightSensor) {
private AutomaticBrightnessController setupController(Sensor lightSensor, float userLux,
float userBrightness) {
mClock = new OffsettableClock.Stopped();
mTestLooper = new TestLooper(mClock::now);
@@ -132,7 +135,7 @@ public class AutomaticBrightnessControllerTest {
mAmbientBrightnessThresholds, mScreenBrightnessThresholds,
mAmbientBrightnessThresholdsIdle, mScreenBrightnessThresholdsIdle,
mContext, mHbmController, mBrightnessThrottler, mIdleBrightnessMappingStrategy,
AMBIENT_LIGHT_HORIZON_SHORT, AMBIENT_LIGHT_HORIZON_LONG
AMBIENT_LIGHT_HORIZON_SHORT, AMBIENT_LIGHT_HORIZON_LONG, userLux, userBrightness
);
when(mHbmController.getCurrentBrightnessMax()).thenReturn(BRIGHTNESS_MAX_FLOAT);
@@ -143,9 +146,10 @@ public class AutomaticBrightnessControllerTest {
// Configure the brightness controller and grab an instance of the sensor listener,
// through which we can deliver fake (for test) sensor values.
controller.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration */,
0 /* brightness */, false /* userChangedBrightness */, 0 /* adjustment */,
false /* userChanged */, DisplayPowerRequest.POLICY_BRIGHT);
controller.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration= */,
0 /* brightness= */, false /* userChangedBrightness= */, 0 /* adjustment= */,
false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
/* shouldResetShortTermModel= */ true);
return controller;
}
@@ -250,9 +254,10 @@ public class AutomaticBrightnessControllerTest {
listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1000));
// User sets brightness to 100
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration */,
0.5f /* brightness */, true /* userChangedBrightness */, 0 /* adjustment */,
false /* userChanged */, DisplayPowerRequest.POLICY_BRIGHT);
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration= */,
0.5f /* brightness= */, true /* userChangedBrightness= */, 0 /* adjustment= */,
false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
/* shouldResetShortTermModel= */ true);
// There should be a user data point added to the mapper.
verify(mBrightnessMappingStrategy).addUserDataPoint(1000f, 0.5f);
@@ -272,9 +277,10 @@ public class AutomaticBrightnessControllerTest {
// User sets brightness to 0.5f
when(mBrightnessMappingStrategy.getBrightness(currentLux,
null, ApplicationInfo.CATEGORY_UNDEFINED)).thenReturn(0.5f);
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration */,
0.5f /* brightness */, true /* userChangedBrightness */, 0 /* adjustment */,
false /* userChanged */, DisplayPowerRequest.POLICY_BRIGHT);
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration= */,
0.5f /* brightness= */, true /* userChangedBrightness= */, 0 /* adjustment= */,
false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
/* shouldResetShortTermModel= */ true);
//Recalculating the spline with RBC enabled, verifying that the short term model is reset,
//and the interaction is learnt in short term model
@@ -305,9 +311,10 @@ public class AutomaticBrightnessControllerTest {
listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1000));
// User sets brightness to 100
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration */,
0.5f /* brightness */, true /* userChangedBrightness */, 0 /* adjustment */,
false /* userChanged */, DisplayPowerRequest.POLICY_BRIGHT);
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration= */,
0.5f /* brightness= */, true /* userChangedBrightness= */, 0 /* adjustment= */,
false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
/* shouldResetShortTermModel= */ true);
// There should be a user data point added to the mapper.
verify(mBrightnessMappingStrategy, times(1)).addUserDataPoint(1000f, 0.5f);
@@ -323,9 +330,10 @@ public class AutomaticBrightnessControllerTest {
verifyNoMoreInteractions(mBrightnessMappingStrategy);
// User sets idle brightness to 0.5
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration */,
0.5f /* brightness */, true /* userChangedBrightness */, 0 /* adjustment */,
false /* userChanged */, DisplayPowerRequest.POLICY_BRIGHT);
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration= */,
0.5f /* brightness= */, true /* userChangedBrightness= */, 0 /* adjustment= */,
false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
/* shouldResetShortTermModel= */ true);
// Ensure we use the correct mapping strategy
verify(mIdleBrightnessMappingStrategy, times(1)).addUserDataPoint(1000f, 0.5f);
@@ -481,17 +489,19 @@ public class AutomaticBrightnessControllerTest {
final float throttledBrightness = 0.123f;
when(mBrightnessThrottler.getBrightnessCap()).thenReturn(throttledBrightness);
when(mBrightnessThrottler.isThrottled()).thenReturn(true);
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration */,
BRIGHTNESS_MAX_FLOAT /* brightness */, false /* userChangedBrightness */,
0 /* adjustment */, false /* userChanged */, DisplayPowerRequest.POLICY_BRIGHT);
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration= */,
BRIGHTNESS_MAX_FLOAT /* brightness= */, false /* userChangedBrightness= */,
0 /* adjustment= */, false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
/* shouldResetShortTermModel= */ true);
assertEquals(throttledBrightness, mController.getAutomaticScreenBrightness(), 0.0f);
// Remove throttling and notify ABC again
when(mBrightnessThrottler.getBrightnessCap()).thenReturn(BRIGHTNESS_MAX_FLOAT);
when(mBrightnessThrottler.isThrottled()).thenReturn(false);
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration */,
BRIGHTNESS_MAX_FLOAT /* brightness */, false /* userChangedBrightness */,
0 /* adjustment */, false /* userChanged */, DisplayPowerRequest.POLICY_BRIGHT);
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration= */,
BRIGHTNESS_MAX_FLOAT /* brightness= */, false /* userChangedBrightness= */,
0 /* adjustment= */, false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
/* shouldResetShortTermModel= */ true);
assertEquals(BRIGHTNESS_MAX_FLOAT, mController.getAutomaticScreenBrightness(), 0.0f);
}
@@ -582,4 +592,32 @@ public class AutomaticBrightnessControllerTest {
assertEquals(lux, sensorValues[0], EPSILON);
assertEquals(mClock.now() - AMBIENT_LIGHT_HORIZON_LONG, sensorTimestamps[0]);
}
@Test
public void testResetShortTermModelWhenConfigChanges() {
when(mBrightnessMappingStrategy.isForIdleMode()).thenReturn(false);
when(mBrightnessMappingStrategy.setBrightnessConfiguration(any())).thenReturn(true);
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration= */,
BRIGHTNESS_MAX_FLOAT /* brightness= */, false /* userChangedBrightness= */,
0 /* adjustment= */, false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
/* shouldResetShortTermModel= */ false);
verify(mBrightnessMappingStrategy, never()).clearUserDataPoints();
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration= */,
BRIGHTNESS_MAX_FLOAT /* brightness= */, false /* userChangedBrightness= */,
0 /* adjustment= */, false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
/* shouldResetShortTermModel= */ true);
verify(mBrightnessMappingStrategy).clearUserDataPoints();
}
@Test
public void testUseProvidedShortTermModel() {
verify(mBrightnessMappingStrategy, never()).addUserDataPoint(anyFloat(), anyFloat());
float userLux = 1000;
float userBrightness = 0.3f;
setupController(mLightSensor, userLux, userBrightness);
verify(mBrightnessMappingStrategy).addUserDataPoint(userLux, userBrightness);
}
}