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:
@@ -249,7 +249,7 @@ class AutomaticBrightnessController {
|
|||||||
HysteresisLevels screenBrightnessThresholdsIdle, Context context,
|
HysteresisLevels screenBrightnessThresholdsIdle, Context context,
|
||||||
HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler,
|
HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler,
|
||||||
BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort,
|
BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort,
|
||||||
int ambientLightHorizonLong) {
|
int ambientLightHorizonLong, float userLux, float userBrightness) {
|
||||||
this(new Injector(), callbacks, looper, sensorManager, lightSensor,
|
this(new Injector(), callbacks, looper, sensorManager, lightSensor,
|
||||||
interactiveModeBrightnessMapper,
|
interactiveModeBrightnessMapper,
|
||||||
lightSensorWarmUpTime, brightnessMin, brightnessMax, dozeScaleFactor,
|
lightSensorWarmUpTime, brightnessMin, brightnessMax, dozeScaleFactor,
|
||||||
@@ -258,7 +258,7 @@ class AutomaticBrightnessController {
|
|||||||
ambientBrightnessThresholds, screenBrightnessThresholds,
|
ambientBrightnessThresholds, screenBrightnessThresholds,
|
||||||
ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, context,
|
ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, context,
|
||||||
hbmController, brightnessThrottler, idleModeBrightnessMapper,
|
hbmController, brightnessThrottler, idleModeBrightnessMapper,
|
||||||
ambientLightHorizonShort, ambientLightHorizonLong
|
ambientLightHorizonShort, ambientLightHorizonLong, userLux, userBrightness
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +275,7 @@ class AutomaticBrightnessController {
|
|||||||
HysteresisLevels screenBrightnessThresholdsIdle, Context context,
|
HysteresisLevels screenBrightnessThresholdsIdle, Context context,
|
||||||
HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler,
|
HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler,
|
||||||
BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort,
|
BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort,
|
||||||
int ambientLightHorizonLong) {
|
int ambientLightHorizonLong, float userLux, float userBrightness) {
|
||||||
mInjector = injector;
|
mInjector = injector;
|
||||||
mClock = injector.createClock();
|
mClock = injector.createClock();
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -322,6 +322,12 @@ class AutomaticBrightnessController {
|
|||||||
mIdleModeBrightnessMapper = idleModeBrightnessMapper;
|
mIdleModeBrightnessMapper = idleModeBrightnessMapper;
|
||||||
// Initialize to active (normal) screen brightness mode
|
// Initialize to active (normal) screen brightness mode
|
||||||
switchToInteractiveScreenBrightnessMode();
|
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,
|
public void configure(int state, @Nullable BrightnessConfiguration configuration,
|
||||||
float brightness, boolean userChangedBrightness, float adjustment,
|
float brightness, boolean userChangedBrightness, float adjustment,
|
||||||
boolean userChangedAutoBrightnessAdjustment, int displayPolicy) {
|
boolean userChangedAutoBrightnessAdjustment, int displayPolicy,
|
||||||
|
boolean shouldResetShortTermModel) {
|
||||||
mState = state;
|
mState = state;
|
||||||
mHbmController.setAutoBrightnessEnabled(mState);
|
mHbmController.setAutoBrightnessEnabled(mState);
|
||||||
// While dozing, the application processor may be suspended which will prevent us from
|
// 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
|
// and hold onto the last computed screen auto brightness. We save the dozing flag for
|
||||||
// debugging purposes.
|
// debugging purposes.
|
||||||
boolean dozing = (displayPolicy == DisplayPowerRequest.POLICY_DOZE);
|
boolean dozing = (displayPolicy == DisplayPowerRequest.POLICY_DOZE);
|
||||||
boolean changed = setBrightnessConfiguration(configuration);
|
boolean changed = setBrightnessConfiguration(configuration, shouldResetShortTermModel);
|
||||||
changed |= setDisplayPolicy(displayPolicy);
|
changed |= setDisplayPolicy(displayPolicy);
|
||||||
if (userChangedAutoBrightnessAdjustment) {
|
if (userChangedAutoBrightnessAdjustment) {
|
||||||
changed |= setAutoBrightnessAdjustment(adjustment);
|
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.
|
// and we can't use this data to add a new control point to the short-term model.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mCurrentBrightnessMapper.addUserDataPoint(mAmbientLux, brightness);
|
return setScreenBrightnessByUser(mAmbientLux, brightness);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean setScreenBrightnessByUser(float lux, float brightness) {
|
||||||
|
mCurrentBrightnessMapper.addUserDataPoint(lux, brightness);
|
||||||
mShortTermModelValid = true;
|
mShortTermModelValid = true;
|
||||||
mShortTermModelAnchor = mAmbientLux;
|
mShortTermModelAnchor = lux;
|
||||||
if (mLoggingEnabled) {
|
if (mLoggingEnabled) {
|
||||||
Slog.d(TAG, "ShortTermModel: anchor=" + mShortTermModelAnchor);
|
Slog.d(TAG, "ShortTermModel: anchor=" + mShortTermModelAnchor);
|
||||||
}
|
}
|
||||||
@@ -514,9 +525,10 @@ class AutomaticBrightnessController {
|
|||||||
mShortTermModelValid = false;
|
mShortTermModelValid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setBrightnessConfiguration(BrightnessConfiguration configuration) {
|
public boolean setBrightnessConfiguration(BrightnessConfiguration configuration,
|
||||||
|
boolean shouldResetShortTermModel) {
|
||||||
if (mInteractiveModeBrightnessMapper.setBrightnessConfiguration(configuration)) {
|
if (mInteractiveModeBrightnessMapper.setBrightnessConfiguration(configuration)) {
|
||||||
if (!isInIdleMode()) {
|
if (!isInIdleMode() && shouldResetShortTermModel) {
|
||||||
resetShortTermModel();
|
resetShortTermModel();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ import java.util.Objects;
|
|||||||
public abstract class BrightnessMappingStrategy {
|
public abstract class BrightnessMappingStrategy {
|
||||||
private static final String TAG = "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 LUX_GRAD_SMOOTHING = 0.25f;
|
||||||
private static final float MAX_GRAD = 1.0f;
|
private static final float MAX_GRAD = 1.0f;
|
||||||
private static final float SHORT_TERM_MODEL_THRESHOLD_RATIO = 0.6f;
|
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.
|
* Creates a BrightnessMappingStrategy for active (normal) mode.
|
||||||
* @param resources
|
* @param resources
|
||||||
* @param displayDeviceConfig
|
* @param displayDeviceConfig
|
||||||
|
* @param displayWhiteBalanceController
|
||||||
* @return the BrightnessMappingStrategy
|
* @return the BrightnessMappingStrategy
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -82,6 +86,7 @@ public abstract class BrightnessMappingStrategy {
|
|||||||
* Creates a BrightnessMappingStrategy for idle screen brightness mode.
|
* Creates a BrightnessMappingStrategy for idle screen brightness mode.
|
||||||
* @param resources
|
* @param resources
|
||||||
* @param displayDeviceConfig
|
* @param displayDeviceConfig
|
||||||
|
* @param displayWhiteBalanceController
|
||||||
* @return the BrightnessMappingStrategy
|
* @return the BrightnessMappingStrategy
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -100,6 +105,7 @@ public abstract class BrightnessMappingStrategy {
|
|||||||
* @param displayDeviceConfig
|
* @param displayDeviceConfig
|
||||||
* @param isForIdleMode determines whether the configurations loaded are for idle screen
|
* @param isForIdleMode determines whether the configurations loaded are for idle screen
|
||||||
* brightness mode or active screen brightness mode.
|
* brightness mode or active screen brightness mode.
|
||||||
|
* @param displayWhiteBalanceController
|
||||||
* @return the BrightnessMappingStrategy
|
* @return the BrightnessMappingStrategy
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -370,6 +376,10 @@ public abstract class BrightnessMappingStrategy {
|
|||||||
*/
|
*/
|
||||||
public abstract boolean isForIdleMode();
|
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
|
* 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.
|
* brightness change was made at and the current ambient lux.
|
||||||
@@ -604,8 +614,8 @@ public abstract class BrightnessMappingStrategy {
|
|||||||
|
|
||||||
mMaxGamma = maxGamma;
|
mMaxGamma = maxGamma;
|
||||||
mAutoBrightnessAdjustment = 0;
|
mAutoBrightnessAdjustment = 0;
|
||||||
mUserLux = -1;
|
mUserLux = NO_USER_LUX;
|
||||||
mUserBrightness = -1;
|
mUserBrightness = NO_USER_BRIGHTNESS;
|
||||||
if (mLoggingEnabled) {
|
if (mLoggingEnabled) {
|
||||||
PLOG.start("simple mapping strategy");
|
PLOG.start("simple mapping strategy");
|
||||||
}
|
}
|
||||||
@@ -732,6 +742,16 @@ public abstract class BrightnessMappingStrategy {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
float getUserLux() {
|
||||||
|
return mUserLux;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
float getUserBrightness() {
|
||||||
|
return mUserBrightness;
|
||||||
|
}
|
||||||
|
|
||||||
private void computeSpline() {
|
private void computeSpline() {
|
||||||
Pair<float[], float[]> curve = getAdjustedCurve(mLux, mBrightness, mUserLux,
|
Pair<float[], float[]> curve = getAdjustedCurve(mLux, mBrightness, mUserLux,
|
||||||
mUserBrightness, mAutoBrightnessAdjustment, mMaxGamma);
|
mUserBrightness, mAutoBrightnessAdjustment, mMaxGamma);
|
||||||
@@ -799,8 +819,8 @@ public abstract class BrightnessMappingStrategy {
|
|||||||
mIsForIdleMode = isForIdleMode;
|
mIsForIdleMode = isForIdleMode;
|
||||||
mMaxGamma = maxGamma;
|
mMaxGamma = maxGamma;
|
||||||
mAutoBrightnessAdjustment = 0;
|
mAutoBrightnessAdjustment = 0;
|
||||||
mUserLux = -1;
|
mUserLux = NO_USER_LUX;
|
||||||
mUserBrightness = -1;
|
mUserBrightness = NO_USER_BRIGHTNESS;
|
||||||
mDisplayWhiteBalanceController = displayWhiteBalanceController;
|
mDisplayWhiteBalanceController = displayWhiteBalanceController;
|
||||||
|
|
||||||
mNits = nits;
|
mNits = nits;
|
||||||
@@ -972,6 +992,16 @@ public abstract class BrightnessMappingStrategy {
|
|||||||
return mIsForIdleMode;
|
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
|
* 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).
|
* and the current curve (in case the current curve includes short-term adjustments).
|
||||||
|
|||||||
@@ -594,7 +594,7 @@ public final class DisplayManagerService extends SystemService {
|
|||||||
getBrightnessConfigForDisplayWithPdsFallbackLocked(
|
getBrightnessConfigForDisplayWithPdsFallbackLocked(
|
||||||
logicalDisplay.getPrimaryDisplayDeviceLocked().getUniqueId(),
|
logicalDisplay.getPrimaryDisplayDeviceLocked().getUniqueId(),
|
||||||
userSerial);
|
userSerial);
|
||||||
dpc.setBrightnessConfiguration(config);
|
dpc.setBrightnessConfiguration(config, /* shouldResetShortTermModel= */ true);
|
||||||
}
|
}
|
||||||
dpc.onSwitchUser(newUserId);
|
dpc.onSwitchUser(newUserId);
|
||||||
});
|
});
|
||||||
@@ -1934,7 +1934,7 @@ public final class DisplayManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
DisplayPowerControllerInterface dpc = getDpcFromUniqueIdLocked(uniqueId);
|
DisplayPowerControllerInterface dpc = getDpcFromUniqueIdLocked(uniqueId);
|
||||||
if (dpc != null) {
|
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(
|
final DisplayPowerControllerInterface dpc = mDisplayPowerControllers.get(
|
||||||
logicalDisplay.getDisplayIdLocked());
|
logicalDisplay.getDisplayIdLocked());
|
||||||
if (dpc != null) {
|
if (dpc != null) {
|
||||||
dpc.setBrightnessConfiguration(config);
|
dpc.setBrightnessConfiguration(config,
|
||||||
|
/* shouldResetShortTermModel= */ false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -225,6 +225,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
|||||||
// True if should use light sensor to automatically determine doze screen brightness.
|
// True if should use light sensor to automatically determine doze screen brightness.
|
||||||
private final boolean mAllowAutoBrightnessWhileDozingConfig;
|
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.
|
// Whether or not the color fade on screen on / off is enabled.
|
||||||
private final boolean mColorFadeEnabled;
|
private final boolean mColorFadeEnabled;
|
||||||
|
|
||||||
@@ -946,6 +949,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
|||||||
return;
|
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(
|
final boolean isIdleScreenBrightnessEnabled = resources.getBoolean(
|
||||||
R.bool.config_enableIdleScreenBrightnessMode);
|
R.bool.config_enableIdleScreenBrightnessMode);
|
||||||
mInteractiveModeBrightnessMapper = BrightnessMappingStrategy.create(resources,
|
mInteractiveModeBrightnessMapper = BrightnessMappingStrategy.create(resources,
|
||||||
@@ -1073,7 +1083,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
|||||||
ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, mContext,
|
ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, mContext,
|
||||||
mHbmController, mBrightnessThrottler, mIdleModeBrightnessMapper,
|
mHbmController, mBrightnessThrottler, mIdleModeBrightnessMapper,
|
||||||
mDisplayDeviceConfig.getAmbientHorizonShort(),
|
mDisplayDeviceConfig.getAmbientHorizonShort(),
|
||||||
mDisplayDeviceConfig.getAmbientHorizonLong());
|
mDisplayDeviceConfig.getAmbientHorizonLong(), userLux, userBrightness);
|
||||||
|
|
||||||
mBrightnessEventRingBuffer =
|
mBrightnessEventRingBuffer =
|
||||||
new RingBuffer<>(BrightnessEvent.class, RINGBUFFER_MAX);
|
new RingBuffer<>(BrightnessEvent.class, RINGBUFFER_MAX);
|
||||||
@@ -1404,7 +1414,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
|||||||
mBrightnessConfiguration,
|
mBrightnessConfiguration,
|
||||||
mLastUserSetScreenBrightness,
|
mLastUserSetScreenBrightness,
|
||||||
userSetBrightnessChanged, autoBrightnessAdjustment,
|
userSetBrightnessChanged, autoBrightnessAdjustment,
|
||||||
autoBrightnessAdjustmentChanged, mPowerRequest.policy);
|
autoBrightnessAdjustmentChanged, mPowerRequest.policy,
|
||||||
|
mShouldResetShortTermModel);
|
||||||
|
mShouldResetShortTermModel = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mBrightnessTracker != null) {
|
if (mBrightnessTracker != null) {
|
||||||
@@ -1800,8 +1812,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBrightnessConfiguration(BrightnessConfiguration c) {
|
public void setBrightnessConfiguration(BrightnessConfiguration c,
|
||||||
Message msg = mHandler.obtainMessage(MSG_CONFIGURE_BRIGHTNESS, c);
|
boolean shouldResetShortTermModel) {
|
||||||
|
Message msg = mHandler.obtainMessage(MSG_CONFIGURE_BRIGHTNESS,
|
||||||
|
shouldResetShortTermModel ? 1 : 0, /* unused */ 0, c);
|
||||||
msg.sendToTarget();
|
msg.sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2844,6 +2858,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
|||||||
break;
|
break;
|
||||||
case MSG_CONFIGURE_BRIGHTNESS:
|
case MSG_CONFIGURE_BRIGHTNESS:
|
||||||
mBrightnessConfiguration = (BrightnessConfiguration) msg.obj;
|
mBrightnessConfiguration = (BrightnessConfiguration) msg.obj;
|
||||||
|
mShouldResetShortTermModel = msg.arg1 == 1;
|
||||||
updatePowerState();
|
updatePowerState();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -202,6 +202,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
|||||||
// True if auto-brightness should be used.
|
// True if auto-brightness should be used.
|
||||||
private boolean mUseSoftwareAutoBrightnessConfig;
|
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.
|
// Whether or not the color fade on screen on / off is enabled.
|
||||||
private final boolean mColorFadeEnabled;
|
private final boolean mColorFadeEnabled;
|
||||||
|
|
||||||
@@ -863,6 +866,13 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
|||||||
return;
|
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(
|
final boolean isIdleScreenBrightnessEnabled = resources.getBoolean(
|
||||||
R.bool.config_enableIdleScreenBrightnessMode);
|
R.bool.config_enableIdleScreenBrightnessMode);
|
||||||
mInteractiveModeBrightnessMapper = BrightnessMappingStrategy.create(resources,
|
mInteractiveModeBrightnessMapper = BrightnessMappingStrategy.create(resources,
|
||||||
@@ -990,7 +1000,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
|||||||
ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, mContext,
|
ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, mContext,
|
||||||
mHbmController, mBrightnessThrottler, mIdleModeBrightnessMapper,
|
mHbmController, mBrightnessThrottler, mIdleModeBrightnessMapper,
|
||||||
mDisplayDeviceConfig.getAmbientHorizonShort(),
|
mDisplayDeviceConfig.getAmbientHorizonShort(),
|
||||||
mDisplayDeviceConfig.getAmbientHorizonLong());
|
mDisplayDeviceConfig.getAmbientHorizonLong(), userLux, userBrightness);
|
||||||
|
|
||||||
mBrightnessEventRingBuffer =
|
mBrightnessEventRingBuffer =
|
||||||
new RingBuffer<>(BrightnessEvent.class, RINGBUFFER_MAX);
|
new RingBuffer<>(BrightnessEvent.class, RINGBUFFER_MAX);
|
||||||
@@ -1195,7 +1205,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
|||||||
mBrightnessConfiguration,
|
mBrightnessConfiguration,
|
||||||
mLastUserSetScreenBrightness,
|
mLastUserSetScreenBrightness,
|
||||||
userSetBrightnessChanged, autoBrightnessAdjustment,
|
userSetBrightnessChanged, autoBrightnessAdjustment,
|
||||||
autoBrightnessAdjustmentChanged, mPowerRequest.policy);
|
autoBrightnessAdjustmentChanged, mPowerRequest.policy,
|
||||||
|
mShouldResetShortTermModel);
|
||||||
|
mShouldResetShortTermModel = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mBrightnessTracker != null) {
|
if (mBrightnessTracker != null) {
|
||||||
@@ -1585,8 +1597,10 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBrightnessConfiguration(BrightnessConfiguration c) {
|
public void setBrightnessConfiguration(BrightnessConfiguration c,
|
||||||
Message msg = mHandler.obtainMessage(MSG_CONFIGURE_BRIGHTNESS, c);
|
boolean shouldResetShortTermModel) {
|
||||||
|
Message msg = mHandler.obtainMessage(MSG_CONFIGURE_BRIGHTNESS,
|
||||||
|
shouldResetShortTermModel ? 1 : 0, /* unused */ 0, c);
|
||||||
msg.sendToTarget();
|
msg.sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2436,6 +2450,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
|||||||
break;
|
break;
|
||||||
case MSG_CONFIGURE_BRIGHTNESS:
|
case MSG_CONFIGURE_BRIGHTNESS:
|
||||||
mBrightnessConfiguration = (BrightnessConfiguration) msg.obj;
|
mBrightnessConfiguration = (BrightnessConfiguration) msg.obj;
|
||||||
|
mShouldResetShortTermModel = msg.arg1 == 1;
|
||||||
updatePowerState();
|
updatePowerState();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ public interface DisplayPowerControllerInterface {
|
|||||||
* Used to update the display's BrightnessConfiguration
|
* Used to update the display's BrightnessConfiguration
|
||||||
* @param config The new 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
|
* Used to set the ambient color temperature of the Display
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.any;
|
|||||||
import static org.mockito.Mockito.anyFloat;
|
import static org.mockito.Mockito.anyFloat;
|
||||||
import static org.mockito.Mockito.anyInt;
|
import static org.mockito.Mockito.anyInt;
|
||||||
import static org.mockito.Mockito.clearInvocations;
|
import static org.mockito.Mockito.clearInvocations;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
@@ -95,7 +96,8 @@ public class AutomaticBrightnessControllerTest {
|
|||||||
|
|
||||||
mLightSensor = TestUtils.createSensor(Sensor.TYPE_LIGHT, "Light Sensor");
|
mLightSensor = TestUtils.createSensor(Sensor.TYPE_LIGHT, "Light Sensor");
|
||||||
mContext = InstrumentationRegistry.getContext();
|
mContext = InstrumentationRegistry.getContext();
|
||||||
mController = setupController(mLightSensor);
|
mController = setupController(mLightSensor, BrightnessMappingStrategy.NO_USER_LUX,
|
||||||
|
BrightnessMappingStrategy.NO_USER_BRIGHTNESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@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();
|
mClock = new OffsettableClock.Stopped();
|
||||||
mTestLooper = new TestLooper(mClock::now);
|
mTestLooper = new TestLooper(mClock::now);
|
||||||
|
|
||||||
@@ -132,7 +135,7 @@ public class AutomaticBrightnessControllerTest {
|
|||||||
mAmbientBrightnessThresholds, mScreenBrightnessThresholds,
|
mAmbientBrightnessThresholds, mScreenBrightnessThresholds,
|
||||||
mAmbientBrightnessThresholdsIdle, mScreenBrightnessThresholdsIdle,
|
mAmbientBrightnessThresholdsIdle, mScreenBrightnessThresholdsIdle,
|
||||||
mContext, mHbmController, mBrightnessThrottler, mIdleBrightnessMappingStrategy,
|
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);
|
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,
|
// Configure the brightness controller and grab an instance of the sensor listener,
|
||||||
// through which we can deliver fake (for test) sensor values.
|
// through which we can deliver fake (for test) sensor values.
|
||||||
controller.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration */,
|
controller.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration= */,
|
||||||
0 /* brightness */, false /* userChangedBrightness */, 0 /* adjustment */,
|
0 /* brightness= */, false /* userChangedBrightness= */, 0 /* adjustment= */,
|
||||||
false /* userChanged */, DisplayPowerRequest.POLICY_BRIGHT);
|
false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
|
||||||
|
/* shouldResetShortTermModel= */ true);
|
||||||
|
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
@@ -250,9 +254,10 @@ public class AutomaticBrightnessControllerTest {
|
|||||||
listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1000));
|
listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1000));
|
||||||
|
|
||||||
// User sets brightness to 100
|
// User sets brightness to 100
|
||||||
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration */,
|
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration= */,
|
||||||
0.5f /* brightness */, true /* userChangedBrightness */, 0 /* adjustment */,
|
0.5f /* brightness= */, true /* userChangedBrightness= */, 0 /* adjustment= */,
|
||||||
false /* userChanged */, DisplayPowerRequest.POLICY_BRIGHT);
|
false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
|
||||||
|
/* shouldResetShortTermModel= */ true);
|
||||||
|
|
||||||
// There should be a user data point added to the mapper.
|
// There should be a user data point added to the mapper.
|
||||||
verify(mBrightnessMappingStrategy).addUserDataPoint(1000f, 0.5f);
|
verify(mBrightnessMappingStrategy).addUserDataPoint(1000f, 0.5f);
|
||||||
@@ -272,9 +277,10 @@ public class AutomaticBrightnessControllerTest {
|
|||||||
// User sets brightness to 0.5f
|
// User sets brightness to 0.5f
|
||||||
when(mBrightnessMappingStrategy.getBrightness(currentLux,
|
when(mBrightnessMappingStrategy.getBrightness(currentLux,
|
||||||
null, ApplicationInfo.CATEGORY_UNDEFINED)).thenReturn(0.5f);
|
null, ApplicationInfo.CATEGORY_UNDEFINED)).thenReturn(0.5f);
|
||||||
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration */,
|
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration= */,
|
||||||
0.5f /* brightness */, true /* userChangedBrightness */, 0 /* adjustment */,
|
0.5f /* brightness= */, true /* userChangedBrightness= */, 0 /* adjustment= */,
|
||||||
false /* userChanged */, DisplayPowerRequest.POLICY_BRIGHT);
|
false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
|
||||||
|
/* shouldResetShortTermModel= */ true);
|
||||||
|
|
||||||
//Recalculating the spline with RBC enabled, verifying that the short term model is reset,
|
//Recalculating the spline with RBC enabled, verifying that the short term model is reset,
|
||||||
//and the interaction is learnt in short term model
|
//and the interaction is learnt in short term model
|
||||||
@@ -305,9 +311,10 @@ public class AutomaticBrightnessControllerTest {
|
|||||||
listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1000));
|
listener.onSensorChanged(TestUtils.createSensorEvent(mLightSensor, 1000));
|
||||||
|
|
||||||
// User sets brightness to 100
|
// User sets brightness to 100
|
||||||
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration */,
|
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration= */,
|
||||||
0.5f /* brightness */, true /* userChangedBrightness */, 0 /* adjustment */,
|
0.5f /* brightness= */, true /* userChangedBrightness= */, 0 /* adjustment= */,
|
||||||
false /* userChanged */, DisplayPowerRequest.POLICY_BRIGHT);
|
false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
|
||||||
|
/* shouldResetShortTermModel= */ true);
|
||||||
|
|
||||||
// There should be a user data point added to the mapper.
|
// There should be a user data point added to the mapper.
|
||||||
verify(mBrightnessMappingStrategy, times(1)).addUserDataPoint(1000f, 0.5f);
|
verify(mBrightnessMappingStrategy, times(1)).addUserDataPoint(1000f, 0.5f);
|
||||||
@@ -323,9 +330,10 @@ public class AutomaticBrightnessControllerTest {
|
|||||||
verifyNoMoreInteractions(mBrightnessMappingStrategy);
|
verifyNoMoreInteractions(mBrightnessMappingStrategy);
|
||||||
|
|
||||||
// User sets idle brightness to 0.5
|
// User sets idle brightness to 0.5
|
||||||
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration */,
|
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration= */,
|
||||||
0.5f /* brightness */, true /* userChangedBrightness */, 0 /* adjustment */,
|
0.5f /* brightness= */, true /* userChangedBrightness= */, 0 /* adjustment= */,
|
||||||
false /* userChanged */, DisplayPowerRequest.POLICY_BRIGHT);
|
false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
|
||||||
|
/* shouldResetShortTermModel= */ true);
|
||||||
|
|
||||||
// Ensure we use the correct mapping strategy
|
// Ensure we use the correct mapping strategy
|
||||||
verify(mIdleBrightnessMappingStrategy, times(1)).addUserDataPoint(1000f, 0.5f);
|
verify(mIdleBrightnessMappingStrategy, times(1)).addUserDataPoint(1000f, 0.5f);
|
||||||
@@ -481,17 +489,19 @@ public class AutomaticBrightnessControllerTest {
|
|||||||
final float throttledBrightness = 0.123f;
|
final float throttledBrightness = 0.123f;
|
||||||
when(mBrightnessThrottler.getBrightnessCap()).thenReturn(throttledBrightness);
|
when(mBrightnessThrottler.getBrightnessCap()).thenReturn(throttledBrightness);
|
||||||
when(mBrightnessThrottler.isThrottled()).thenReturn(true);
|
when(mBrightnessThrottler.isThrottled()).thenReturn(true);
|
||||||
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration */,
|
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration= */,
|
||||||
BRIGHTNESS_MAX_FLOAT /* brightness */, false /* userChangedBrightness */,
|
BRIGHTNESS_MAX_FLOAT /* brightness= */, false /* userChangedBrightness= */,
|
||||||
0 /* adjustment */, false /* userChanged */, DisplayPowerRequest.POLICY_BRIGHT);
|
0 /* adjustment= */, false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
|
||||||
|
/* shouldResetShortTermModel= */ true);
|
||||||
assertEquals(throttledBrightness, mController.getAutomaticScreenBrightness(), 0.0f);
|
assertEquals(throttledBrightness, mController.getAutomaticScreenBrightness(), 0.0f);
|
||||||
|
|
||||||
// Remove throttling and notify ABC again
|
// Remove throttling and notify ABC again
|
||||||
when(mBrightnessThrottler.getBrightnessCap()).thenReturn(BRIGHTNESS_MAX_FLOAT);
|
when(mBrightnessThrottler.getBrightnessCap()).thenReturn(BRIGHTNESS_MAX_FLOAT);
|
||||||
when(mBrightnessThrottler.isThrottled()).thenReturn(false);
|
when(mBrightnessThrottler.isThrottled()).thenReturn(false);
|
||||||
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration */,
|
mController.configure(AUTO_BRIGHTNESS_ENABLED, null /* configuration= */,
|
||||||
BRIGHTNESS_MAX_FLOAT /* brightness */, false /* userChangedBrightness */,
|
BRIGHTNESS_MAX_FLOAT /* brightness= */, false /* userChangedBrightness= */,
|
||||||
0 /* adjustment */, false /* userChanged */, DisplayPowerRequest.POLICY_BRIGHT);
|
0 /* adjustment= */, false /* userChanged= */, DisplayPowerRequest.POLICY_BRIGHT,
|
||||||
|
/* shouldResetShortTermModel= */ true);
|
||||||
assertEquals(BRIGHTNESS_MAX_FLOAT, mController.getAutomaticScreenBrightness(), 0.0f);
|
assertEquals(BRIGHTNESS_MAX_FLOAT, mController.getAutomaticScreenBrightness(), 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -582,4 +592,32 @@ public class AutomaticBrightnessControllerTest {
|
|||||||
assertEquals(lux, sensorValues[0], EPSILON);
|
assertEquals(lux, sensorValues[0], EPSILON);
|
||||||
assertEquals(mClock.now() - AMBIENT_LIGHT_HORIZON_LONG, sensorTimestamps[0]);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user