diff options
| author | 2015-02-14 02:27:19 +0000 | |
|---|---|---|
| committer | 2015-02-14 02:27:19 +0000 | |
| commit | f1df1970db523f60d6ac7850fba93ae98a46163b (patch) | |
| tree | 9cde04bfe418db39afe4727d20ab5c255d3e41f9 | |
| parent | a511eea83b0209729e4b42e219f233f818a6d9e7 (diff) | |
| parent | 88a9a2a46eb77ea340175f5d272433f4de1b6f93 (diff) | |
am 88a9a2a4: Merge "Support for faster brightness response to light changes." into lmp-mr1-modular-dev
* commit '88a9a2a46eb77ea340175f5d272433f4de1b6f93':
Support for faster brightness response to light changes.
4 files changed, 74 insertions, 23 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index f2d9de8a9ad3..fdd216906786 100755 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -861,10 +861,34 @@ <!-- Allow automatic adjusting of the screen brightness while dozing in low power state. --> <bool name="config_allowAutoBrightnessWhileDozing">false</bool> + <!-- Stability requirements in milliseconds for accepting a new brightness level. This is used + for debouncing the light sensor. Different constants are used to debounce the light sensor + 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_autoBrightnessBrighteningLightDebounce">4000</integer> + <integer name="config_autoBrightnessDarkeningLightDebounce">8000</integer> + + <!-- Light sensor event rate in milliseconds for automatic brightness control. --> + <integer name="config_autoBrightnessLightSensorRate">250</integer> + <!-- If we allow automatic adjustment of screen brightness while dozing, how many times we want to reduce it to preserve the battery. Value of 100% means no scaling. --> <fraction name="config_screenAutoBrightnessDozeScaleFactor">100%</fraction> + <!-- When the screen is turned on, the previous estimate of the ambient light level at the time + the screen was turned off is restored and is used to determine the initial screen + brightness. + + If this flag is true, then the ambient light level estimate will be promptly recomputed + after the warm-up interface and the screen brightness will be adjusted immediately. + + If this flag is false, then the ambient light level estimate will be adjusted more + gradually in the same manner that normally happens when the screen is on according to the + brightening or dimming debounce thresholds. As a result, it may take somewhat longer to + adapt to the environment. This mode may be better suited for watches. --> + <bool name="config_autoBrightnessResetAmbientLuxAfterWarmUp">true</bool> + <!-- Screen brightness used to dim the screen when the user activity timeout expires. May be less than the minimum allowed brightness setting that can be set by the user. --> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index aabddcd43185..eec989ecde00 100755 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -1569,6 +1569,7 @@ <java-symbol type="bool" name="config_useAttentionLight" /> <java-symbol type="bool" name="config_animateScreenLights" /> <java-symbol type="bool" name="config_automatic_brightness_available" /> + <java-symbol type="bool" name="config_autoBrightnessResetAmbientLuxAfterWarmUp" /> <java-symbol type="bool" name="config_dozeAfterScreenOff" /> <java-symbol type="bool" name="config_enableActivityRecognitionHardwareOverlay" /> <java-symbol type="bool" name="config_enableFusedLocationOverlay" /> @@ -1624,6 +1625,9 @@ <java-symbol type="id" name="replace_message" /> <java-symbol type="fraction" name="config_dimBehindFadeDuration" /> <java-symbol type="fraction" name="config_screenAutoBrightnessDozeScaleFactor" /> + <java-symbol type="integer" name="config_autoBrightnessBrighteningLightDebounce"/> + <java-symbol type="integer" name="config_autoBrightnessDarkeningLightDebounce"/> + <java-symbol type="integer" name="config_autoBrightnessLightSensorRate"/> <java-symbol type="integer" name="config_carDockKeepsScreenOn" /> <java-symbol type="integer" name="config_criticalBatteryWarningLevel" /> <java-symbol type="integer" name="config_datause_notification_type" /> diff --git a/services/core/java/com/android/server/display/AutomaticBrightnessController.java b/services/core/java/com/android/server/display/AutomaticBrightnessController.java index d919bf6ff8c4..93d37f1da650 100644 --- a/services/core/java/com/android/server/display/AutomaticBrightnessController.java +++ b/services/core/java/com/android/server/display/AutomaticBrightnessController.java @@ -52,20 +52,9 @@ class AutomaticBrightnessController { // auto-brightness adjustment setting. private static final float SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT_MAX_GAMMA = 3.0f; - // Light sensor event rate in milliseconds. - private static final int LIGHT_SENSOR_RATE_MILLIS = 1000; - // Period of time in which to consider light samples in milliseconds. private static final int AMBIENT_LIGHT_HORIZON = 10000; - // Stability requirements in milliseconds for accepting a new brightness level. This is used - // for debouncing the light sensor. Different constants are used to debounce the light sensor - // 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 static final long BRIGHTENING_LIGHT_DEBOUNCE = 4000; - private static final long DARKENING_LIGHT_DEBOUNCE = 8000; - // 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. @@ -121,6 +110,22 @@ class AutomaticBrightnessController { private final int mScreenBrightnessRangeMaximum; private final float mDozeScaleFactor; + // Light sensor event rate in milliseconds. + private final int mLightSensorRate; + + // Stability requirements in milliseconds for accepting a new brightness level. This is used + // for debouncing the light sensor. Different constants are used to debounce the light sensor + // 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 mBrighteningLightDebounceConfig; + private final long mDarkeningLightDebounceConfig; + + // If true immediately after the screen is turned on the controller will try to adjust the + // brightness based on the current sensor reads. If false, the controller will collect more data + // and only then decide whether to change brightness. + private final boolean mResetAmbientLuxAfterWarmUpConfig; + // 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. @@ -176,7 +181,9 @@ class AutomaticBrightnessController { public AutomaticBrightnessController(Callbacks callbacks, Looper looper, SensorManager sensorManager, Spline autoBrightnessSpline, int lightSensorWarmUpTime, - int brightnessMin, int brightnessMax, float dozeScaleFactor) { + int brightnessMin, int brightnessMax, float dozeScaleFactor, + int lightSensorRate, long brighteningLightDebounceConfig, + long darkeningLightDebounceConfig, boolean resetAmbientLuxAfterWarmUpConfig) { mCallbacks = callbacks; mTwilight = LocalServices.getService(TwilightManager.class); mSensorManager = sensorManager; @@ -185,9 +192,13 @@ class AutomaticBrightnessController { mScreenBrightnessRangeMaximum = brightnessMax; mLightSensorWarmUpTimeConfig = lightSensorWarmUpTime; mDozeScaleFactor = dozeScaleFactor; + mLightSensorRate = lightSensorRate; + mBrighteningLightDebounceConfig = brighteningLightDebounceConfig; + mDarkeningLightDebounceConfig = darkeningLightDebounceConfig; + mResetAmbientLuxAfterWarmUpConfig = resetAmbientLuxAfterWarmUpConfig; mHandler = new AutomaticBrightnessHandler(looper); - mAmbientLightRingBuffer = new AmbientLightRingBuffer(); + mAmbientLightRingBuffer = new AmbientLightRingBuffer(mLightSensorRate); if (!DEBUG_PRETEND_LIGHT_SENSOR_ABSENT) { mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); @@ -226,6 +237,9 @@ class AutomaticBrightnessController { pw.println(" mScreenBrightnessRangeMinimum=" + mScreenBrightnessRangeMinimum); pw.println(" mScreenBrightnessRangeMaximum=" + mScreenBrightnessRangeMaximum); pw.println(" mLightSensorWarmUpTimeConfig=" + mLightSensorWarmUpTimeConfig); + pw.println(" mBrighteningLightDebounceConfig=" + mBrighteningLightDebounceConfig); + pw.println(" mDarkeningLightDebounceConfig=" + mDarkeningLightDebounceConfig); + pw.println(" mResetAmbientLuxAfterWarmUpConfig=" + mResetAmbientLuxAfterWarmUpConfig); pw.println(); pw.println("Automatic Brightness Controller State:"); @@ -252,13 +266,13 @@ class AutomaticBrightnessController { mLightSensorEnabled = true; mLightSensorEnableTime = SystemClock.uptimeMillis(); mSensorManager.registerListener(mLightSensorListener, mLightSensor, - LIGHT_SENSOR_RATE_MILLIS * 1000, mHandler); + mLightSensorRate * 1000, mHandler); return true; } } else { if (mLightSensorEnabled) { mLightSensorEnabled = false; - mAmbientLuxValid = false; + mAmbientLuxValid = !mResetAmbientLuxAfterWarmUpConfig; mRecentLightSamples = 0; mAmbientLightRingBuffer.clear(); mHandler.removeMessages(MSG_UPDATE_AMBIENT_LUX); @@ -347,7 +361,7 @@ class AutomaticBrightnessController { } earliestValidTime = mAmbientLightRingBuffer.getTime(i); } - return earliestValidTime + BRIGHTENING_LIGHT_DEBOUNCE; + return earliestValidTime + mBrighteningLightDebounceConfig; } private long nextAmbientLightDarkeningTransition(long time) { @@ -359,7 +373,7 @@ class AutomaticBrightnessController { } earliestValidTime = mAmbientLightRingBuffer.getTime(i); } - return earliestValidTime + DARKENING_LIGHT_DEBOUNCE; + return earliestValidTime + mDarkeningLightDebounceConfig; } private void updateAmbientLux() { @@ -420,7 +434,7 @@ class AutomaticBrightnessController { // should be enough time to decide whether we should actually transition to the new // weighted ambient lux or not. nextTransitionTime = - nextTransitionTime > time ? nextTransitionTime : time + LIGHT_SENSOR_RATE_MILLIS; + nextTransitionTime > time ? nextTransitionTime : time + mLightSensorRate; if (DEBUG) { Slog.d(TAG, "updateAmbientLux: Scheduling ambient lux update for " + nextTransitionTime + TimeUtils.formatUptime(nextTransitionTime)); @@ -559,8 +573,6 @@ class AutomaticBrightnessController { // Proportional extra capacity of the buffer beyond the expected number of light samples // in the horizon private static final float BUFFER_SLACK = 1.5f; - private static final int DEFAULT_CAPACITY = - (int) Math.ceil(AMBIENT_LIGHT_HORIZON * BUFFER_SLACK / LIGHT_SENSOR_RATE_MILLIS); private float[] mRingLux; private long[] mRingTime; private int mCapacity; @@ -571,8 +583,8 @@ class AutomaticBrightnessController { private int mEnd; private int mCount; - public AmbientLightRingBuffer() { - this(DEFAULT_CAPACITY); + public AmbientLightRingBuffer(long lightSensorRate) { + this((int) Math.ceil(AMBIENT_LIGHT_HORIZON * BUFFER_SLACK / lightSensorRate)); } public AmbientLightRingBuffer(int initialCapacity) { diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index 78610ff71bd1..cf1f4b0f1424 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -302,6 +302,15 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mAllowAutoBrightnessWhileDozingConfig = resources.getBoolean( com.android.internal.R.bool.config_allowAutoBrightnessWhileDozing); + int lightSensorRate = resources.getInteger( + com.android.internal.R.integer.config_autoBrightnessLightSensorRate); + long brighteningLightDebounce = resources.getInteger( + com.android.internal.R.integer.config_autoBrightnessBrighteningLightDebounce); + long darkeningLightDebounce = resources.getInteger( + com.android.internal.R.integer.config_autoBrightnessDarkeningLightDebounce); + boolean autoBrightnessResetAmbientLuxAfterWarmUp = resources.getBoolean( + com.android.internal.R.bool.config_autoBrightnessResetAmbientLuxAfterWarmUp); + if (mUseSoftwareAutoBrightnessConfig) { int[] lux = resources.getIntArray( com.android.internal.R.array.config_autoBrightnessLevels); @@ -336,7 +345,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mAutomaticBrightnessController = new AutomaticBrightnessController(this, handler.getLooper(), sensorManager, screenAutoBrightnessSpline, lightSensorWarmUpTimeConfig, screenBrightnessRangeMinimum, - mScreenBrightnessRangeMaximum, dozeScaleFactor); + mScreenBrightnessRangeMaximum, dozeScaleFactor, lightSensorRate, + brighteningLightDebounce, darkeningLightDebounce, + autoBrightnessResetAmbientLuxAfterWarmUp); } } |