Skip to content

Commit e663975

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "Improve auto-brightness debounce." into jb-mr1-dev
2 parents 2289167 + 06565b6 commit e663975

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

services/java/com/android/server/power/DisplayPowerController.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,20 @@ final class DisplayPowerController {
9696

9797
// Filter time constant in milliseconds for computing a moving
9898
// average of light samples. Different constants are used
99-
// to adapt to brighter or dimmer environments.
100-
private static final long BRIGHTENING_LIGHT_TIME_CONSTANT = 2500; // 2.5 sec
101-
private static final long DIMMING_LIGHT_TIME_CONSTANT = 10000; // 10 sec
99+
// to calculate the average light level when adapting to brighter or
100+
// dimmer environments.
101+
// This parameter only controls the averaging of light samples.
102+
private static final long BRIGHTENING_LIGHT_TIME_CONSTANT = 1500;
103+
private static final long DIMMING_LIGHT_TIME_CONSTANT = 3000;
104+
105+
// Stability requirements in milliseconds for accepting a new brightness
106+
// level. This is used for debouncing the light sensor. Different constants
107+
// are used to debounce the light sensor when adapting to brighter or dimmer
108+
// environments.
109+
// This parameter controls how quickly brightness changes occur in response to
110+
// an observed change in light level.
111+
private static final long BRIGHTENING_LIGHT_DEBOUNCE = 2500;
112+
private static final long DIMMING_LIGHT_DEBOUNCE = 10000;
102113

103114
private final Object mLock = new Object();
104115

@@ -233,6 +244,9 @@ final class DisplayPowerController {
233244
// The time of the most light recent sample.
234245
private long mLastLightSampleTime;
235246

247+
// The time when we accumulated the first recent light sample into mRecentLightSamples.
248+
private long mFirstRecentLightSampleTime;
249+
236250
// The upcoming debounce light sensor time.
237251
// This is only valid when mLightMeasurementValue && mRecentLightSamples >= 1.
238252
private long mPendingLightSensorDebounceTime;
@@ -664,7 +678,6 @@ private void handleLightSensorEvent(long time, float lux) {
664678
// If the newest light sample doesn't seem to be going in the
665679
// same general direction as recent samples, then start over.
666680
setRecentLight(time, lux, lux > mLightMeasurement);
667-
mPendingLightSensorDebounceTime = time + mRecentLightTimeConstant;
668681
} else if (mRecentLightSamples >= 1) {
669682
// Add the newest light sample to the moving average.
670683
accumulateRecentLight(time, lux);
@@ -677,6 +690,8 @@ private void handleLightSensorEvent(long time, float lux) {
677690
+ ", mRecentLightAverage=" + mRecentLightAverage
678691
+ ", mRecentLightBrightening=" + mRecentLightBrightening
679692
+ ", mRecentLightTimeConstant=" + mRecentLightTimeConstant
693+
+ ", mFirstRecentLightSampleTime="
694+
+ TimeUtils.formatUptime(mFirstRecentLightSampleTime)
680695
+ ", mPendingLightSensorDebounceTime="
681696
+ TimeUtils.formatUptime(mPendingLightSensorDebounceTime));
682697
}
@@ -694,6 +709,9 @@ private void setRecentLight(long time, float lux, boolean brightening) {
694709
mRecentLightAverage = lux;
695710
mLastLightSample = lux;
696711
mLastLightSampleTime = time;
712+
mFirstRecentLightSampleTime = time;
713+
mPendingLightSensorDebounceTime = time + (brightening ?
714+
BRIGHTENING_LIGHT_DEBOUNCE : DIMMING_LIGHT_DEBOUNCE);
697715
}
698716

699717
private void accumulateRecentLight(long time, float lux) {
@@ -715,8 +733,7 @@ private void debounceLightSensor() {
715733
if (DEBUG) {
716734
Slog.d(TAG, "debounceLightSensor: Accepted new measurement "
717735
+ mLightMeasurement + " after "
718-
+ (now - mPendingLightSensorDebounceTime
719-
+ mRecentLightTimeConstant) + " ms based on "
736+
+ (now - mFirstRecentLightSampleTime) + " ms based on "
720737
+ mRecentLightSamples + " recent samples.");
721738
}
722739

@@ -885,6 +902,8 @@ private void dumpLocal(PrintWriter pw) {
885902
pw.println(" mRecentLightAverage=" + mRecentLightAverage);
886903
pw.println(" mRecentLightBrightening=" + mRecentLightBrightening);
887904
pw.println(" mRecentLightTimeConstant=" + mRecentLightTimeConstant);
905+
pw.println(" mFirstRecentLightSampleTime="
906+
+ TimeUtils.formatUptime(mFirstRecentLightSampleTime));
888907
pw.println(" mPendingLightSensorDebounceTime="
889908
+ TimeUtils.formatUptime(mPendingLightSensorDebounceTime));
890909
pw.println(" mScreenAutoBrightness=" + mScreenAutoBrightness);

0 commit comments

Comments
 (0)