|
|
|
|
@@ -49,23 +49,12 @@ class AutomaticBrightnessController {
|
|
|
|
|
// If true, enables the use of the screen auto-brightness adjustment setting.
|
|
|
|
|
private static final boolean USE_SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT = true;
|
|
|
|
|
|
|
|
|
|
// The maximum range of gamma adjustment possible using the screen
|
|
|
|
|
// auto-brightness adjustment setting.
|
|
|
|
|
private static final float SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT_MAX_GAMMA = 3.0f;
|
|
|
|
|
|
|
|
|
|
// Period of time in which to consider light samples in milliseconds.
|
|
|
|
|
private static final int AMBIENT_LIGHT_HORIZON = 10000;
|
|
|
|
|
|
|
|
|
|
// Hysteresis constraints for brightening or darkening.
|
|
|
|
|
// The recent lux must have changed by at least this fraction relative to the
|
|
|
|
|
// current ambient lux before a change will be considered.
|
|
|
|
|
private static final float BRIGHTENING_LIGHT_HYSTERESIS = 0.10f;
|
|
|
|
|
private static final float DARKENING_LIGHT_HYSTERESIS = 0.20f;
|
|
|
|
|
|
|
|
|
|
// The intercept used for the weighting calculation. This is used in order to keep all possible
|
|
|
|
|
// weighting values positive.
|
|
|
|
|
private static final int WEIGHTING_INTERCEPT = AMBIENT_LIGHT_HORIZON;
|
|
|
|
|
|
|
|
|
|
// How long the current sensor reading is assumed to be valid beyond the current time.
|
|
|
|
|
// This provides a bit of prediction, as well as ensures that the weight for the last sample is
|
|
|
|
|
// non-zero, which in turn ensures that the total weight is non-zero.
|
|
|
|
|
@@ -132,6 +121,13 @@ class AutomaticBrightnessController {
|
|
|
|
|
// and only then decide whether to change brightness.
|
|
|
|
|
private final boolean mResetAmbientLuxAfterWarmUpConfig;
|
|
|
|
|
|
|
|
|
|
// Period of time in which to consider light samples in milliseconds.
|
|
|
|
|
private final int mAmbientLightHorizon;
|
|
|
|
|
|
|
|
|
|
// The intercept used for the weighting calculation. This is used in order to keep all possible
|
|
|
|
|
// weighting values positive.
|
|
|
|
|
private final int mWeightingIntercept;
|
|
|
|
|
|
|
|
|
|
// Amount of time to delay auto-brightness after screen on while waiting for
|
|
|
|
|
// the light sensor to warm-up in milliseconds.
|
|
|
|
|
// May be 0 if no warm-up is required.
|
|
|
|
|
@@ -179,6 +175,10 @@ class AutomaticBrightnessController {
|
|
|
|
|
// The screen auto-brightness adjustment factor in the range -1 (dimmer) to 1 (brighter)
|
|
|
|
|
private float mScreenAutoBrightnessAdjustment = 0.0f;
|
|
|
|
|
|
|
|
|
|
// The maximum range of gamma adjustment possible using the screen
|
|
|
|
|
// auto-brightness adjustment setting.
|
|
|
|
|
private float mScreenAutoBrightnessAdjustmentMaxGamma;
|
|
|
|
|
|
|
|
|
|
// The last screen auto-brightness gamma. (For printing in dump() only.)
|
|
|
|
|
private float mLastScreenAutoBrightnessGamma = 1.0f;
|
|
|
|
|
|
|
|
|
|
@@ -197,7 +197,8 @@ class AutomaticBrightnessController {
|
|
|
|
|
SensorManager sensorManager, Spline autoBrightnessSpline, int lightSensorWarmUpTime,
|
|
|
|
|
int brightnessMin, int brightnessMax, float dozeScaleFactor,
|
|
|
|
|
int lightSensorRate, long brighteningLightDebounceConfig,
|
|
|
|
|
long darkeningLightDebounceConfig, boolean resetAmbientLuxAfterWarmUpConfig) {
|
|
|
|
|
long darkeningLightDebounceConfig, boolean resetAmbientLuxAfterWarmUpConfig,
|
|
|
|
|
int ambientLightHorizon, float autoBrightnessAdjustmentMaxGamma ) {
|
|
|
|
|
mCallbacks = callbacks;
|
|
|
|
|
mTwilight = LocalServices.getService(TwilightManager.class);
|
|
|
|
|
mSensorManager = sensorManager;
|
|
|
|
|
@@ -210,9 +211,12 @@ class AutomaticBrightnessController {
|
|
|
|
|
mBrighteningLightDebounceConfig = brighteningLightDebounceConfig;
|
|
|
|
|
mDarkeningLightDebounceConfig = darkeningLightDebounceConfig;
|
|
|
|
|
mResetAmbientLuxAfterWarmUpConfig = resetAmbientLuxAfterWarmUpConfig;
|
|
|
|
|
mAmbientLightHorizon = ambientLightHorizon;
|
|
|
|
|
mWeightingIntercept = ambientLightHorizon;
|
|
|
|
|
mScreenAutoBrightnessAdjustmentMaxGamma = autoBrightnessAdjustmentMaxGamma;
|
|
|
|
|
|
|
|
|
|
mHandler = new AutomaticBrightnessHandler(looper);
|
|
|
|
|
mAmbientLightRingBuffer = new AmbientLightRingBuffer(mLightSensorRate);
|
|
|
|
|
mAmbientLightRingBuffer = new AmbientLightRingBuffer(mLightSensorRate, mAmbientLightHorizon);
|
|
|
|
|
|
|
|
|
|
if (!DEBUG_PRETEND_LIGHT_SENSOR_ABSENT) {
|
|
|
|
|
mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
|
|
|
|
|
@@ -266,6 +270,7 @@ class AutomaticBrightnessController {
|
|
|
|
|
pw.println(" mLightSensorEnabled=" + mLightSensorEnabled);
|
|
|
|
|
pw.println(" mLightSensorEnableTime=" + TimeUtils.formatUptime(mLightSensorEnableTime));
|
|
|
|
|
pw.println(" mAmbientLux=" + mAmbientLux);
|
|
|
|
|
pw.println(" mAmbientLightHorizon=" + mAmbientLightHorizon);
|
|
|
|
|
pw.println(" mBrighteningLuxThreshold=" + mBrighteningLuxThreshold);
|
|
|
|
|
pw.println(" mDarkeningLuxThreshold=" + mDarkeningLuxThreshold);
|
|
|
|
|
pw.println(" mLastObservedLux=" + mLastObservedLux);
|
|
|
|
|
@@ -274,6 +279,7 @@ class AutomaticBrightnessController {
|
|
|
|
|
pw.println(" mAmbientLightRingBuffer=" + mAmbientLightRingBuffer);
|
|
|
|
|
pw.println(" mScreenAutoBrightness=" + mScreenAutoBrightness);
|
|
|
|
|
pw.println(" mScreenAutoBrightnessAdjustment=" + mScreenAutoBrightnessAdjustment);
|
|
|
|
|
pw.println(" mScreenAutoBrightnessAdjustmentMaxGamma=" + mScreenAutoBrightnessAdjustmentMaxGamma);
|
|
|
|
|
pw.println(" mLastScreenAutoBrightnessGamma=" + mLastScreenAutoBrightnessGamma);
|
|
|
|
|
pw.println(" mDozing=" + mDozing);
|
|
|
|
|
}
|
|
|
|
|
@@ -309,7 +315,7 @@ class AutomaticBrightnessController {
|
|
|
|
|
|
|
|
|
|
private void applyLightSensorMeasurement(long time, float lux) {
|
|
|
|
|
mRecentLightSamples++;
|
|
|
|
|
mAmbientLightRingBuffer.prune(time - AMBIENT_LIGHT_HORIZON);
|
|
|
|
|
mAmbientLightRingBuffer.prune(time - mAmbientLightHorizon);
|
|
|
|
|
mAmbientLightRingBuffer.push(time, lux);
|
|
|
|
|
|
|
|
|
|
// Remember this sample value.
|
|
|
|
|
@@ -360,14 +366,14 @@ class AutomaticBrightnessController {
|
|
|
|
|
return sum / totalWeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static float calculateWeight(long startDelta, long endDelta) {
|
|
|
|
|
private float calculateWeight(long startDelta, long endDelta) {
|
|
|
|
|
return weightIntegral(endDelta) - weightIntegral(startDelta);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Evaluates the integral of y = x + WEIGHTING_INTERCEPT. This is always positive for the
|
|
|
|
|
// Evaluates the integral of y = x + mWeightingIntercept. This is always positive for the
|
|
|
|
|
// horizon we're looking at and provides a non-linear weighting for light samples.
|
|
|
|
|
private static float weightIntegral(long x) {
|
|
|
|
|
return x * (x * 0.5f + WEIGHTING_INTERCEPT);
|
|
|
|
|
private float weightIntegral(long x) {
|
|
|
|
|
return x * (x * 0.5f + mWeightingIntercept);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private long nextAmbientLightBrighteningTransition(long time) {
|
|
|
|
|
@@ -396,7 +402,7 @@ class AutomaticBrightnessController {
|
|
|
|
|
|
|
|
|
|
private void updateAmbientLux() {
|
|
|
|
|
long time = SystemClock.uptimeMillis();
|
|
|
|
|
mAmbientLightRingBuffer.prune(time - AMBIENT_LIGHT_HORIZON);
|
|
|
|
|
mAmbientLightRingBuffer.prune(time - mAmbientLightHorizon);
|
|
|
|
|
updateAmbientLux(time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -470,7 +476,7 @@ class AutomaticBrightnessController {
|
|
|
|
|
|
|
|
|
|
if (USE_SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT
|
|
|
|
|
&& mScreenAutoBrightnessAdjustment != 0.0f) {
|
|
|
|
|
final float adjGamma = MathUtils.pow(SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT_MAX_GAMMA,
|
|
|
|
|
final float adjGamma = MathUtils.pow(mScreenAutoBrightnessAdjustmentMaxGamma,
|
|
|
|
|
Math.min(1.0f, Math.max(-1.0f, -mScreenAutoBrightnessAdjustment)));
|
|
|
|
|
gamma *= adjGamma;
|
|
|
|
|
if (DEBUG) {
|
|
|
|
|
@@ -653,8 +659,8 @@ class AutomaticBrightnessController {
|
|
|
|
|
private int mEnd;
|
|
|
|
|
private int mCount;
|
|
|
|
|
|
|
|
|
|
public AmbientLightRingBuffer(long lightSensorRate) {
|
|
|
|
|
mCapacity = (int) Math.ceil(AMBIENT_LIGHT_HORIZON * BUFFER_SLACK / lightSensorRate);
|
|
|
|
|
public AmbientLightRingBuffer(long lightSensorRate, int ambientLightHorizon) {
|
|
|
|
|
mCapacity = (int) Math.ceil(ambientLightHorizon * BUFFER_SLACK / lightSensorRate);
|
|
|
|
|
mRingLux = new float[mCapacity];
|
|
|
|
|
mRingTime = new long[mCapacity];
|
|
|
|
|
}
|
|
|
|
|
|