summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Piotr WilczyƄski <wilczynskip@google.com> 2022-12-19 16:43:29 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-12-19 16:43:29 +0000
commit34b3da0df197e89d5941d54291081deede16b3a8 (patch)
treea3f3718706ce50caebff06abd27b4a9ef13a7832
parent54dc37bd6e7f3ead10f4ec36b753248ea794a02b (diff)
parentbd748a4787f614e38cffc9e14bfa6b793d7f2883 (diff)
Merge "Retain the short-term model when device state changes"
-rw-r--r--services/core/java/com/android/server/display/AutomaticBrightnessController.java30
-rw-r--r--services/core/java/com/android/server/display/BrightnessMappingStrategy.java38
-rw-r--r--services/core/java/com/android/server/display/DisplayManagerService.java7
-rw-r--r--services/core/java/com/android/server/display/DisplayPowerController.java23
-rw-r--r--services/core/java/com/android/server/display/DisplayPowerController2.java23
-rw-r--r--services/core/java/com/android/server/display/DisplayPowerControllerInterface.java3
-rw-r--r--services/tests/servicestests/src/com/android/server/display/AutomaticBrightnessControllerTest.java86
7 files changed, 161 insertions, 49 deletions
diff --git a/services/core/java/com/android/server/display/AutomaticBrightnessController.java b/services/core/java/com/android/server/display/AutomaticBrightnessController.java
index 197c64ecd03f..4f008357d151 100644
--- a/services/core/java/com/android/server/display/AutomaticBrightnessController.java
+++ b/services/core/java/com/android/server/display/AutomaticBrightnessController.java
@@ -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;
diff --git a/services/core/java/com/android/server/display/BrightnessMappingStrategy.java b/services/core/java/com/android/server/display/BrightnessMappingStrategy.java
index 25d0752844fd..3fc50c4edf6d 100644
--- a/services/core/java/com/android/server/display/BrightnessMappingStrategy.java
+++ b/services/core/java/com/android/server/display/BrightnessMappingStrategy.java
@@ -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).
diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java
index 329e3ca0d5b9..5e9f0e7bf5bd 100644
--- a/services/core/java/com/android/server/display/DisplayManagerService.java
+++ b/services/core/java/com/android/server/display/DisplayManagerService.java
@@ -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);
}
}
});
diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java
index e4fcdbd07188..f4eed2b47ec4 100644
--- a/services/core/java/com/android/server/display/DisplayPowerController.java
+++ b/services/core/java/com/android/server/display/DisplayPowerController.java
@@ -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;
@@ -951,6 +954,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,
@@ -1078,7 +1088,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);
@@ -1428,7 +1438,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
mBrightnessConfiguration,
mLastUserSetScreenBrightness,
userSetBrightnessChanged, autoBrightnessAdjustment,
- autoBrightnessAdjustmentChanged, mPowerRequest.policy);
+ autoBrightnessAdjustmentChanged, mPowerRequest.policy,
+ mShouldResetShortTermModel);
+ mShouldResetShortTermModel = false;
}
if (mBrightnessTracker != null) {
@@ -1840,8 +1852,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();
}
@@ -2892,6 +2906,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
break;
case MSG_CONFIGURE_BRIGHTNESS:
mBrightnessConfiguration = (BrightnessConfiguration) msg.obj;
+ mShouldResetShortTermModel = msg.arg1 == 1;
updatePowerState();
break;
diff --git a/services/core/java/com/android/server/display/DisplayPowerController2.java b/services/core/java/com/android/server/display/DisplayPowerController2.java
index 81011dcb5bc7..09136b096653 100644
--- a/services/core/java/com/android/server/display/DisplayPowerController2.java
+++ b/services/core/java/com/android/server/display/DisplayPowerController2.java
@@ -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;
@@ -868,6 +871,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,
@@ -995,7 +1005,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);
@@ -1220,7 +1230,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
mBrightnessConfiguration,
mLastUserSetScreenBrightness,
userSetBrightnessChanged, autoBrightnessAdjustment,
- autoBrightnessAdjustmentChanged, mPowerRequest.policy);
+ autoBrightnessAdjustmentChanged, mPowerRequest.policy,
+ mShouldResetShortTermModel);
+ mShouldResetShortTermModel = false;
}
if (mBrightnessTracker != null) {
@@ -1626,8 +1638,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();
}
@@ -2485,6 +2499,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
break;
case MSG_CONFIGURE_BRIGHTNESS:
mBrightnessConfiguration = (BrightnessConfiguration) msg.obj;
+ mShouldResetShortTermModel = msg.arg1 == 1;
updatePowerState();
break;
diff --git a/services/core/java/com/android/server/display/DisplayPowerControllerInterface.java b/services/core/java/com/android/server/display/DisplayPowerControllerInterface.java
index 46f1343ceeb8..e750ee281413 100644
--- a/services/core/java/com/android/server/display/DisplayPowerControllerInterface.java
+++ b/services/core/java/com/android/server/display/DisplayPowerControllerInterface.java
@@ -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
diff --git a/services/tests/servicestests/src/com/android/server/display/AutomaticBrightnessControllerTest.java b/services/tests/servicestests/src/com/android/server/display/AutomaticBrightnessControllerTest.java
index ae368716526a..ddde3855aebf 100644
--- a/services/tests/servicestests/src/com/android/server/display/AutomaticBrightnessControllerTest.java
+++ b/services/tests/servicestests/src/com/android/server/display/AutomaticBrightnessControllerTest.java
@@ -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);
+ }
}