summaryrefslogtreecommitdiffstats
path: root/services/java
diff options
context:
space:
mode:
authorMichael Wright <michaelwr@google.com>2013-11-04 19:07:49 -0800
committerMichael Wright <michaelwr@google.com>2013-11-05 15:49:52 -0800
commit65031a29132e50a7e233d61c1fedc99b88604c6e (patch)
tree117288a0168bd843f8a7764bff89ef1458f8fbbd /services/java
parent5f48dc7409669c78ad923b370c885e1d01919cfb (diff)
downloadframeworks_base-65031a29132e50a7e233d61c1fedc99b88604c6e.zip
frameworks_base-65031a29132e50a7e233d61c1fedc99b88604c6e.tar.gz
frameworks_base-65031a29132e50a7e233d61c1fedc99b88604c6e.tar.bz2
Continue synthesizing data even after brightness adjustment
Bug: 11337887 Change-Id: I80adb330c4e9250965030626634002a1b9c999cf
Diffstat (limited to 'services/java')
-rw-r--r--services/java/com/android/server/power/DisplayPowerController.java122
1 files changed, 65 insertions, 57 deletions
diff --git a/services/java/com/android/server/power/DisplayPowerController.java b/services/java/com/android/server/power/DisplayPowerController.java
index 976a328..60d44c7 100644
--- a/services/java/com/android/server/power/DisplayPowerController.java
+++ b/services/java/com/android/server/power/DisplayPowerController.java
@@ -298,6 +298,10 @@ final class DisplayPowerController {
// True if mAmbientLux holds a valid value.
private boolean mAmbientLuxValid;
+ // The ambient light level threshold at which to brighten or darken the screen.
+ private float mBrighteningLuxThreshold;
+ private float mDarkeningLuxThreshold;
+
// The most recent light sample.
private float mLastObservedLux;
@@ -945,12 +949,24 @@ final class DisplayPowerController {
mLastObservedLuxTime = time;
}
+ private void setAmbientLux(float lux) {
+ mAmbientLux = lux;
+ mBrighteningLuxThreshold = mAmbientLux * (1.0f + BRIGHTENING_LIGHT_HYSTERESIS);
+ mDarkeningLuxThreshold = mAmbientLux * (1.0f - DARKENING_LIGHT_HYSTERESIS);
+ }
+
private void updateAmbientLux(long time) {
// If the light sensor was just turned on then immediately update our initial
// estimate of the current ambient light level.
- if (!mAmbientLuxValid
- || (time - mLightSensorEnableTime) < mLightSensorWarmUpTimeConfig) {
- mAmbientLux = mRecentShortTermAverageLux;
+ if (!mAmbientLuxValid) {
+ final long timeWhenSensorWarmedUp =
+ mLightSensorWarmUpTimeConfig + mLightSensorEnableTime;
+ if (time < timeWhenSensorWarmedUp) {
+ mHandler.sendEmptyMessageAtTime(MSG_LIGHT_SENSOR_DEBOUNCED,
+ timeWhenSensorWarmedUp);
+ return;
+ }
+ setAmbientLux(mRecentShortTermAverageLux);
mAmbientLuxValid = true;
mDebounceLuxDirection = 0;
mDebounceLuxTime = time;
@@ -961,98 +977,90 @@ final class DisplayPowerController {
+ ", mAmbientLux=" + mAmbientLux);
}
updateAutoBrightness(true);
- return;
- }
-
- // Determine whether the ambient environment appears to be brightening.
- float brighteningLuxThreshold = mAmbientLux * (1.0f + BRIGHTENING_LIGHT_HYSTERESIS);
- if (mRecentShortTermAverageLux > brighteningLuxThreshold
- && mRecentLongTermAverageLux > brighteningLuxThreshold) {
+ } else if (mRecentShortTermAverageLux > mBrighteningLuxThreshold
+ && mRecentLongTermAverageLux > mBrighteningLuxThreshold) {
+ // The ambient environment appears to be brightening.
if (mDebounceLuxDirection <= 0) {
mDebounceLuxDirection = 1;
mDebounceLuxTime = time;
if (DEBUG) {
Slog.d(TAG, "updateAmbientLux: Possibly brightened, waiting for "
+ BRIGHTENING_LIGHT_DEBOUNCE + " ms: "
- + "brighteningLuxThreshold=" + brighteningLuxThreshold
+ + "mBrighteningLuxThreshold=" + mBrighteningLuxThreshold
+ ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
+ ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
+ ", mAmbientLux=" + mAmbientLux);
}
}
long debounceTime = mDebounceLuxTime + BRIGHTENING_LIGHT_DEBOUNCE;
- if (time >= debounceTime) {
- mAmbientLux = mRecentShortTermAverageLux;
- if (DEBUG) {
- Slog.d(TAG, "updateAmbientLux: Brightened: "
- + "brighteningLuxThreshold=" + brighteningLuxThreshold
- + ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
- + ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
- + ", mAmbientLux=" + mAmbientLux);
- }
- updateAutoBrightness(true);
- } else {
+ if (time < debounceTime) {
mHandler.sendEmptyMessageAtTime(MSG_LIGHT_SENSOR_DEBOUNCED, debounceTime);
+ return;
}
- return;
- }
-
- // Determine whether the ambient environment appears to be darkening.
- float darkeningLuxThreshold = mAmbientLux * (1.0f - DARKENING_LIGHT_HYSTERESIS);
- if (mRecentShortTermAverageLux < darkeningLuxThreshold
- && mRecentLongTermAverageLux < darkeningLuxThreshold) {
+ setAmbientLux(mRecentShortTermAverageLux);
+ if (DEBUG) {
+ Slog.d(TAG, "updateAmbientLux: Brightened: "
+ + "mBrighteningLuxThreshold=" + mBrighteningLuxThreshold
+ + ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
+ + ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
+ + ", mAmbientLux=" + mAmbientLux);
+ }
+ updateAutoBrightness(true);
+ } else if (mRecentShortTermAverageLux < mDarkeningLuxThreshold
+ && mRecentLongTermAverageLux < mDarkeningLuxThreshold) {
+ // The ambient environment appears to be darkening.
if (mDebounceLuxDirection >= 0) {
mDebounceLuxDirection = -1;
mDebounceLuxTime = time;
if (DEBUG) {
Slog.d(TAG, "updateAmbientLux: Possibly darkened, waiting for "
+ DARKENING_LIGHT_DEBOUNCE + " ms: "
- + "darkeningLuxThreshold=" + darkeningLuxThreshold
+ + "mDarkeningLuxThreshold=" + mDarkeningLuxThreshold
+ ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
+ ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
+ ", mAmbientLux=" + mAmbientLux);
}
}
long debounceTime = mDebounceLuxTime + DARKENING_LIGHT_DEBOUNCE;
- if (time >= debounceTime) {
- // Be conservative about reducing the brightness, only reduce it a little bit
- // at a time to avoid having to bump it up again soon.
- mAmbientLux = Math.max(mRecentShortTermAverageLux, mRecentLongTermAverageLux);
- if (DEBUG) {
- Slog.d(TAG, "updateAmbientLux: Darkened: "
- + "darkeningLuxThreshold=" + darkeningLuxThreshold
- + ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
- + ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
- + ", mAmbientLux=" + mAmbientLux);
- }
- updateAutoBrightness(true);
- } else {
+ if (time < debounceTime) {
mHandler.sendEmptyMessageAtTime(MSG_LIGHT_SENSOR_DEBOUNCED, debounceTime);
+ return;
}
- return;
- }
-
- // No change or change is within the hysteresis thresholds.
- if (mDebounceLuxDirection != 0) {
+ // Be conservative about reducing the brightness, only reduce it a little bit
+ // at a time to avoid having to bump it up again soon.
+ setAmbientLux(Math.max(mRecentShortTermAverageLux, mRecentLongTermAverageLux));
+ if (DEBUG) {
+ Slog.d(TAG, "updateAmbientLux: Darkened: "
+ + "mDarkeningLuxThreshold=" + mDarkeningLuxThreshold
+ + ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
+ + ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
+ + ", mAmbientLux=" + mAmbientLux);
+ }
+ updateAutoBrightness(true);
+ } else if (mDebounceLuxDirection != 0) {
+ // No change or change is within the hysteresis thresholds.
mDebounceLuxDirection = 0;
mDebounceLuxTime = time;
if (DEBUG) {
Slog.d(TAG, "updateAmbientLux: Canceled debounce: "
- + "brighteningLuxThreshold=" + brighteningLuxThreshold
- + ", darkeningLuxThreshold=" + darkeningLuxThreshold
+ + "mBrighteningLuxThreshold=" + mBrighteningLuxThreshold
+ + ", mDarkeningLuxThreshold=" + mDarkeningLuxThreshold
+ ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
+ ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
+ ", mAmbientLux=" + mAmbientLux);
}
}
- // If the light level does not change, then the sensor may not report
- // a new value. This can cause problems for the auto-brightness algorithm
- // because the filters might not be updated. To work around it, we want to
- // make sure to update the filters whenever the observed light level could
- // possibly exceed one of the hysteresis thresholds.
- if (mLastObservedLux > brighteningLuxThreshold
- || mLastObservedLux < darkeningLuxThreshold) {
+ // Now that we've done all of that, we haven't yet posted a debounce
+ // message. So consider the case where current lux is beyond the
+ // threshold. It's possible that the light sensor may not report values
+ // if the light level does not change, so we need to occasionally
+ // synthesize sensor readings in order to make sure the brightness is
+ // adjusted accordingly. Note these thresholds may have changed since
+ // we entered the function because we called setAmbientLux and
+ // updateAutoBrightness along the way.
+ if (mLastObservedLux > mBrighteningLuxThreshold
+ || mLastObservedLux < mDarkeningLuxThreshold) {
mHandler.sendEmptyMessageAtTime(MSG_LIGHT_SENSOR_DEBOUNCED,
time + SYNTHETIC_LIGHT_SENSOR_RATE_MILLIS);
}