OSDN Git Service

Increase brightness faster if ambient light is brightening quickly.
authorDanny Baumann <dannybaumann@web.de>
Wed, 1 Apr 2015 06:44:37 +0000 (08:44 +0200)
committerSteve Kondik <shade@chemlab.org>
Tue, 20 Sep 2016 08:39:02 +0000 (01:39 -0700)
The point of doing this is when going from indoors to bright sunlight,
the brightness adjustment currently leaves one with looking at an
unreadable display for a couple of seconds. Increase responsiveness in
that scenario to ramp up brightness faster.

Change-Id: Idf8ca8ebcdcea06746b0c4f3ab94d2ddddafb32e

core/res/res/values/cm_symbols.xml
core/res/res/values/config.xml
services/core/java/com/android/server/display/AutomaticBrightnessController.java
services/core/java/com/android/server/display/DisplayPowerController.java

index 48d83e3..47644a6 100644 (file)
@@ -68,4 +68,8 @@
 
     <!-- Screen unpinning -->
     <java-symbol type="string" name="lock_to_app_toast_no_navbar" />
+
+    <!-- Automatic brightness enhancements -->
+    <java-symbol type="integer" name="config_autoBrightnessBrighteningLightFastDebounce"/>
+
 </resources>
index c00182e..1f5faf4 100755 (executable)
          when adapting to brighter or darker environments.  This parameter controls how quickly
          brightness changes occur in response to an observed change in light level that exceeds the
          hysteresis threshold. -->
+    <integer name="config_autoBrightnessBrighteningLightFastDebounce">500</integer>
     <integer name="config_autoBrightnessBrighteningLightDebounce">4000</integer>
     <integer name="config_autoBrightnessDarkeningLightDebounce">8000</integer>
 
index c16dac2..94df50f 100644 (file)
@@ -55,6 +55,11 @@ class AutomaticBrightnessController {
     private static final float BRIGHTENING_LIGHT_HYSTERESIS = 0.10f;
     private static final float DARKENING_LIGHT_HYSTERESIS = 0.20f;
 
+    // Threshold (in lux) to select between normal and fast debounce time.
+    // If the difference between last sample and weighted value is larger than this value,
+    // fast debounce is used.
+    private static final float BRIGHTENING_FAST_THRESHOLD = 1000f;
+
     // 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.
@@ -99,6 +104,7 @@ class AutomaticBrightnessController {
     // when adapting to brighter or darker environments.  This parameter controls how quickly
     // brightness changes occur in response to an observed change in light level that exceeds the
     // hysteresis threshold.
+    private final long mBrighteningLightFastDebounceConfig;
     private final long mBrighteningLightDebounceConfig;
     private final long mDarkeningLightDebounceConfig;
 
@@ -188,6 +194,7 @@ class AutomaticBrightnessController {
             SensorManager sensorManager, Spline autoBrightnessSpline, int lightSensorWarmUpTime,
             int brightnessMin, int brightnessMax, float dozeScaleFactor,
             int lightSensorRate, long brighteningLightDebounceConfig,
+            long brighteningLightFastDebounceConfig,
             long darkeningLightDebounceConfig, boolean resetAmbientLuxAfterWarmUpConfig,
             int ambientLightHorizon, float autoBrightnessAdjustmentMaxGamma ) {
         mCallbacks = callbacks;
@@ -200,6 +207,7 @@ class AutomaticBrightnessController {
         mDozeScaleFactor = dozeScaleFactor;
         mLightSensorRate = lightSensorRate;
         mBrighteningLightDebounceConfig = brighteningLightDebounceConfig;
+        mBrighteningLightFastDebounceConfig = brighteningLightFastDebounceConfig;
         mDarkeningLightDebounceConfig = darkeningLightDebounceConfig;
         mResetAmbientLuxAfterWarmUpConfig = resetAmbientLuxAfterWarmUpConfig;
         mAmbientLightHorizon = ambientLightHorizon;
@@ -262,6 +270,7 @@ class AutomaticBrightnessController {
         pw.println("  mScreenBrightnessRangeMaximum=" + mScreenBrightnessRangeMaximum);
         pw.println("  mLightSensorWarmUpTimeConfig=" + mLightSensorWarmUpTimeConfig);
         pw.println("  mBrighteningLightDebounceConfig=" + mBrighteningLightDebounceConfig);
+        pw.println("  mBrighteningLightFastDebounceConfig=" + mBrighteningLightFastDebounceConfig);
         pw.println("  mDarkeningLightDebounceConfig=" + mDarkeningLightDebounceConfig);
         pw.println("  mResetAmbientLuxAfterWarmUpConfig=" + mResetAmbientLuxAfterWarmUpConfig);
 
@@ -314,6 +323,7 @@ class AutomaticBrightnessController {
     private void handleLightSensorEvent(long time, float lux) {
         mHandler.removeMessages(MSG_UPDATE_AMBIENT_LUX);
 
+        if (DEBUG) Slog.d(TAG, "handleLightSensorEvent: time=" + time + ", lux=" + lux);
         applyLightSensorMeasurement(time, lux);
         updateAmbientLux(time);
     }
@@ -386,7 +396,7 @@ class AutomaticBrightnessController {
         return x * (x * 0.5f + mWeightingIntercept);
     }
 
-    private long nextAmbientLightBrighteningTransition(long time) {
+    private long nextAmbientLightBrighteningTransition(long time, float ambientLux) {
         final int N = mAmbientLightRingBuffer.size();
         long earliestValidTime = time;
         for (int i = N - 1; i >= 0; i--) {
@@ -395,10 +405,13 @@ class AutomaticBrightnessController {
             }
             earliestValidTime = mAmbientLightRingBuffer.getTime(i);
         }
-        return earliestValidTime + mBrighteningLightDebounceConfig;
+
+        long debounceDelay = mLastObservedLux - ambientLux > BRIGHTENING_FAST_THRESHOLD
+                ? mBrighteningLightFastDebounceConfig : mBrighteningLightDebounceConfig;
+        return earliestValidTime + debounceDelay;
     }
 
-    private long nextAmbientLightDarkeningTransition(long time) {
+    private long nextAmbientLightDarkeningTransition(long time, float ambientLux) {
         final int N = mAmbientLightRingBuffer.size();
         long earliestValidTime = time;
         for (int i = N - 1; i >= 0; i--) {
@@ -442,13 +455,12 @@ class AutomaticBrightnessController {
             updateAutoBrightness(true);
         }
 
-        long nextBrightenTransition = nextAmbientLightBrighteningTransition(time);
-        long nextDarkenTransition = nextAmbientLightDarkeningTransition(time);
         float ambientLux = calculateAmbientLux(time);
+        long nextBrightenTransition = nextAmbientLightBrighteningTransition(time, ambientLux);
+        long nextDarkenTransition = nextAmbientLightDarkeningTransition(time, ambientLux);
 
         if (ambientLux >= mBrighteningLuxThreshold && nextBrightenTransition <= time
                 || ambientLux <= mDarkeningLuxThreshold && nextDarkenTransition <= time) {
-            setAmbientLux(ambientLux);
             if (DEBUG) {
                 Slog.d(TAG, "updateAmbientLux: "
                         + ((ambientLux > mAmbientLux) ? "Brightened" : "Darkened") + ": "
@@ -456,9 +468,10 @@ class AutomaticBrightnessController {
                         + ", mAmbientLightRingBuffer=" + mAmbientLightRingBuffer
                         + ", mAmbientLux=" + mAmbientLux);
             }
+            setAmbientLux(ambientLux);
             updateAutoBrightness(true);
-            nextBrightenTransition = nextAmbientLightBrighteningTransition(time);
-            nextDarkenTransition = nextAmbientLightDarkeningTransition(time);
+            nextBrightenTransition = nextAmbientLightBrighteningTransition(time, ambientLux);
+            nextDarkenTransition = nextAmbientLightDarkeningTransition(time, ambientLux);
         }
         long nextTransitionTime = Math.min(nextDarkenTransition, nextBrightenTransition);
         // If one of the transitions is ready to occur, but the total weighted ambient lux doesn't
index 7922dfb..944b577 100644 (file)
@@ -317,6 +317,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                 com.android.internal.R.integer.config_autoBrightnessLightSensorRate);
         long brighteningLightDebounce = resources.getInteger(
                 com.android.internal.R.integer.config_autoBrightnessBrighteningLightDebounce);
+        long brighteningLightFastDebounce = resources.getInteger(
+                com.android.internal.R.integer.config_autoBrightnessBrighteningLightFastDebounce);
         long darkeningLightDebounce = resources.getInteger(
                 com.android.internal.R.integer.config_autoBrightnessDarkeningLightDebounce);
         boolean autoBrightnessResetAmbientLuxAfterWarmUp = resources.getBoolean(
@@ -362,8 +364,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                         handler.getLooper(), sensorManager, screenAutoBrightnessSpline,
                         lightSensorWarmUpTimeConfig, screenBrightnessRangeMinimum,
                         mScreenBrightnessRangeMaximum, dozeScaleFactor, lightSensorRate,
-                        brighteningLightDebounce, darkeningLightDebounce,
-                        autoBrightnessResetAmbientLuxAfterWarmUp,
+                        brighteningLightDebounce, brighteningLightFastDebounce,
+                        darkeningLightDebounce, autoBrightnessResetAmbientLuxAfterWarmUp,
                         ambientLightHorizon, autoBrightnessAdjustmentMaxGamma);
             }
         }