diff options
| author | 2016-11-07 18:52:05 +0000 | |
|---|---|---|
| committer | 2016-11-07 18:52:12 +0000 | |
| commit | 132a23b11f9a10ba22c063afe8cc985c765761f5 (patch) | |
| tree | 427aee47e4cf2e32daa16c117412c0b5a825e0da | |
| parent | cd041490fe8bafd7040cefc70342606ccb77df7b (diff) | |
| parent | 5d7170963ac0cfa30400292841c3673b8cdea5b5 (diff) | |
Merge "Add initial ambient light sensor rate"
4 files changed, 53 insertions, 9 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 6dc3f3eb1614..ff1d383ac3d7 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -1059,6 +1059,12 @@      <integer name="config_autoBrightnessBrighteningLightDebounce">4000</integer>      <integer name="config_autoBrightnessDarkeningLightDebounce">8000</integer> +    <!-- Initial light sensor event rate in milliseconds for automatic brightness control. This is +         used for obtaining the first light sample when the device stops dozing. + +         Set this to -1 to disable this feature. --> +    <integer name="config_autoBrightnessInitialLightSensorRate">-1</integer> +      <!-- Light sensor event rate in milliseconds for automatic brightness control. -->      <integer name="config_autoBrightnessLightSensorRate">250</integer> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 0073f5325c34..92fff65efac8 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -1736,6 +1736,7 @@    <java-symbol type="integer" name="config_autoBrightnessAmbientLightHorizon"/>    <java-symbol type="integer" name="config_autoBrightnessBrighteningLightDebounce"/>    <java-symbol type="integer" name="config_autoBrightnessDarkeningLightDebounce"/> +  <java-symbol type="integer" name="config_autoBrightnessInitialLightSensorRate"/>    <java-symbol type="integer" name="config_autoBrightnessLightSensorRate"/>    <java-symbol type="integer" name="config_carDockKeepsScreenOn" />    <java-symbol type="integer" name="config_criticalBatteryWarningLevel" /> diff --git a/services/core/java/com/android/server/display/AutomaticBrightnessController.java b/services/core/java/com/android/server/display/AutomaticBrightnessController.java index fa6a7e7aca2a..3da49d8e13fb 100644 --- a/services/core/java/com/android/server/display/AutomaticBrightnessController.java +++ b/services/core/java/com/android/server/display/AutomaticBrightnessController.java @@ -86,8 +86,14 @@ class AutomaticBrightnessController {      private final int mScreenBrightnessRangeMaximum;      private final float mDozeScaleFactor; -    // Light sensor event rate in milliseconds. -    private final int mLightSensorRate; +    // Initial light sensor event rate in milliseconds. +    private final int mInitialLightSensorRate; + +    // Steady-state light sensor event rate in milliseconds. +    private final int mNormalLightSensorRate; + +    // The current light sensor event rate in milliseconds. +    private int mCurrentLightSensorRate;      // 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 @@ -185,7 +191,7 @@ class AutomaticBrightnessController {      public AutomaticBrightnessController(Callbacks callbacks, Looper looper,              SensorManager sensorManager, Spline autoBrightnessSpline, int lightSensorWarmUpTime,              int brightnessMin, int brightnessMax, float dozeScaleFactor, -            int lightSensorRate, long brighteningLightDebounceConfig, +            int lightSensorRate, int initialLightSensorRate, long brighteningLightDebounceConfig,              long darkeningLightDebounceConfig, boolean resetAmbientLuxAfterWarmUpConfig,              int ambientLightHorizon, float autoBrightnessAdjustmentMaxGamma,              HysteresisLevels dynamicHysteresis) { @@ -197,7 +203,9 @@ class AutomaticBrightnessController {          mScreenBrightnessRangeMaximum = brightnessMax;          mLightSensorWarmUpTimeConfig = lightSensorWarmUpTime;          mDozeScaleFactor = dozeScaleFactor; -        mLightSensorRate = lightSensorRate; +        mNormalLightSensorRate = lightSensorRate; +        mInitialLightSensorRate = initialLightSensorRate; +        mCurrentLightSensorRate = -1;          mBrighteningLightDebounceConfig = brighteningLightDebounceConfig;          mDarkeningLightDebounceConfig = darkeningLightDebounceConfig;          mResetAmbientLuxAfterWarmUpConfig = resetAmbientLuxAfterWarmUpConfig; @@ -208,9 +216,9 @@ class AutomaticBrightnessController {          mHandler = new AutomaticBrightnessHandler(looper);          mAmbientLightRingBuffer = -            new AmbientLightRingBuffer(mLightSensorRate, mAmbientLightHorizon); +            new AmbientLightRingBuffer(mNormalLightSensorRate, mAmbientLightHorizon);          mInitialHorizonAmbientLightRingBuffer = -            new AmbientLightRingBuffer(mLightSensorRate, mAmbientLightHorizon); +            new AmbientLightRingBuffer(mNormalLightSensorRate, mAmbientLightHorizon);          if (!DEBUG_PRETEND_LIGHT_SENSOR_ABSENT) {              mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); @@ -293,8 +301,9 @@ class AutomaticBrightnessController {              if (!mLightSensorEnabled) {                  mLightSensorEnabled = true;                  mLightSensorEnableTime = SystemClock.uptimeMillis(); +                mCurrentLightSensorRate = mInitialLightSensorRate;                  mSensorManager.registerListener(mLightSensorListener, mLightSensor, -                        mLightSensorRate * 1000, mHandler); +                        mCurrentLightSensorRate * 1000, mHandler);                  return true;              }          } else { @@ -304,6 +313,7 @@ class AutomaticBrightnessController {                  mRecentLightSamples = 0;                  mAmbientLightRingBuffer.clear();                  mInitialHorizonAmbientLightRingBuffer.clear(); +                mCurrentLightSensorRate = -1;                  mHandler.removeMessages(MSG_UPDATE_AMBIENT_LUX);                  mSensorManager.unregisterListener(mLightSensorListener);              } @@ -314,6 +324,10 @@ class AutomaticBrightnessController {      private void handleLightSensorEvent(long time, float lux) {          mHandler.removeMessages(MSG_UPDATE_AMBIENT_LUX); +        if (mAmbientLightRingBuffer.size() == 0) { +            // switch to using the steady-state sample rate after grabbing the initial light sample +            adjustLightSensorRate(mNormalLightSensorRate); +        }          applyLightSensorMeasurement(time, lux);          updateAmbientLux(time);      } @@ -333,6 +347,20 @@ class AutomaticBrightnessController {          mLastObservedLuxTime = time;      } +    private void adjustLightSensorRate(int lightSensorRate) { +        // if the light sensor rate changed, update the sensor listener +        if (lightSensorRate != mCurrentLightSensorRate) { +            if (DEBUG) { +                Slog.d(TAG, "adjustLightSensorRate: previousRate=" + mCurrentLightSensorRate +                    + ", currentRate=" + lightSensorRate); +            } +            mCurrentLightSensorRate = lightSensorRate; +            mSensorManager.unregisterListener(mLightSensorListener); +            mSensorManager.registerListener(mLightSensorListener, mLightSensor, +                    lightSensorRate * 1000, mHandler); +        } +    } +      private boolean setScreenAutoBrightnessAdjustment(float adjustment) {          if (adjustment != mScreenAutoBrightnessAdjustment) {              mScreenAutoBrightnessAdjustment = adjustment; @@ -468,7 +496,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 + mLightSensorRate; +                nextTransitionTime > time ? nextTransitionTime : time + mNormalLightSensorRate;          if (DEBUG) {              Slog.d(TAG, "updateAmbientLux: Scheduling ambient lux update for "                      + nextTransitionTime + TimeUtils.formatUptime(nextTransitionTime)); diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index 3b2dc344d390..477ecdf60c48 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -310,6 +310,15 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call          int lightSensorRate = resources.getInteger(                  com.android.internal.R.integer.config_autoBrightnessLightSensorRate); +        int initialLightSensorRate = resources.getInteger( +                com.android.internal.R.integer.config_autoBrightnessInitialLightSensorRate); +        if (initialLightSensorRate == -1) { +          initialLightSensorRate = lightSensorRate; +        } else if (initialLightSensorRate > lightSensorRate) { +          Slog.w(TAG, "Expected config_autoBrightnessInitialLightSensorRate (" +                  + initialLightSensorRate + ") to be less than or equal to " +                  + "config_autoBrightnessLightSensorRate (" + lightSensorRate + ")."); +        }          long brighteningLightDebounce = resources.getInteger(                  com.android.internal.R.integer.config_autoBrightnessBrighteningLightDebounce);          long darkeningLightDebounce = resources.getInteger( @@ -366,7 +375,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call                          handler.getLooper(), sensorManager, screenAutoBrightnessSpline,                          lightSensorWarmUpTimeConfig, screenBrightnessRangeMinimum,                          mScreenBrightnessRangeMaximum, dozeScaleFactor, lightSensorRate, -                        brighteningLightDebounce, darkeningLightDebounce, +                        initialLightSensorRate, brighteningLightDebounce, darkeningLightDebounce,                          autoBrightnessResetAmbientLuxAfterWarmUp, ambientLightHorizon,                          autoBrightnessAdjustmentMaxGamma, dynamicHysteresis);              }  |