diff options
5 files changed, 74 insertions, 58 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 6a46954d0985..7849e56f0d2e 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -1089,6 +1089,26 @@ <!-- Period of time in which to consider light samples in milliseconds. --> <integer name="config_autoBrightnessAmbientLightHorizon">10000</integer> + <!-- This flag enables light sensor sampling while dozing. A single sample is taken upon + entering doze mode, and another sample is taken every time the display enters STATE_DOZE + or STATE_DOZE_SUSPEND. It is recommended that config_dozeSensorLuxLevels and + config_dozeBrightnessBacklightValues have entries so that the doze mode brightness can be + determined dynamically. + --> + <bool name="config_allowAutoBrightnessActiveDozeLightSensor">false</bool> + + <!-- This flag should be used with config_allowAutoBrightnessActiveDozeLightSensor set to true. + + The screen brightness of a device is based off of a ring buffer of the last n seconds of + ambient light sensor sample readings. + + If this flag is true, then this buffer is cleared every time a new sample is taken in doze + mode and the screen brightness is based off the new reading. This mode may be better suited + for watches. + + If this flag is false, then this buffer is untouched. --> + <bool name="config_useNewSensorSamplesForDoze">false</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. --> @@ -1184,21 +1204,6 @@ <integer-array name="config_dynamicHysteresisLuxLevels"> </integer-array> - <!-- This flag requires config_dozeBrightnessBacklightValues to have two or more entries; it is - recommended that config_screenBrightnessDoze be greater than or equal to all these entries - since this value is used as the doze screen brightness until a new sensor sample is - acquired. This flag only affects the screen brightness while dozing. - - The screen brightness of a device is based off of a ring buffer of the last n seconds of - ambient light sensor sample readings. - - If this flag is true, then this buffer is cleared and the screen brightness is based off of - ambient light sensor readings that are obtained while the device is dozing. This mode may - be better suited for watches. - - If this flag is false, then this buffer is untouched. --> - <bool name="config_useNewSensorSamplesForDoze">false</bool> - <!-- Array of ambient light sensor lux threshold values for determining screen brightness for devices that have both an ambient light sensor and the screen on while dozing. This is used to determine the screen brightness while dozing by calculating the index to use for diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 17c88b9a0797..a9f81eb4408c 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -1669,6 +1669,7 @@ <java-symbol type="array" name="config_notificationFallbackVibePattern" /> <java-symbol type="array" name="config_onlySingleDcAllowed" /> <java-symbol type="bool" name="config_useNewSensorSamplesForDoze" /> + <java-symbol type="bool" name="config_allowAutoBrightnessActiveDozeLightSensor" /> <java-symbol type="bool" name="config_useAttentionLight" /> <java-symbol type="bool" name="config_animateScreenLights" /> <java-symbol type="bool" name="config_automatic_brightness_available" /> diff --git a/services/core/java/com/android/server/display/AutomaticBrightnessController.java b/services/core/java/com/android/server/display/AutomaticBrightnessController.java index 8bfa7d715022..f75766687e2b 100644 --- a/services/core/java/com/android/server/display/AutomaticBrightnessController.java +++ b/services/core/java/com/android/server/display/AutomaticBrightnessController.java @@ -178,8 +178,13 @@ class AutomaticBrightnessController { // Are we going to adjust brightness while dozing. private boolean mDozing; - // True if we are collecting one last light sample when dozing to set the screen brightness - private boolean mActiveDozeLightSensor = false; + // True if we are collecting light samples when dozing to set the screen brightness. A single + // light sample is collected when entering doze mode. If autobrightness is enabled, calls to + // DisplayPowerController#updatePowerState in doze mode will also collect light samples. + private final boolean mUseActiveDozeLightSensorConfig; + + // True if the ambient light sensor ring buffer should be cleared when entering doze mode. + private final boolean mUseNewSensorSamplesForDoze; // True if we are collecting a brightness adjustment sample, along with some data // for the initial state of the sample. @@ -197,6 +202,7 @@ class AutomaticBrightnessController { int lightSensorRate, int initialLightSensorRate, long brighteningLightDebounceConfig, long darkeningLightDebounceConfig, boolean resetAmbientLuxAfterWarmUpConfig, int ambientLightHorizon, float autoBrightnessAdjustmentMaxGamma, + boolean activeDozeLightSensor, boolean useNewSensorSamplesForDoze, LuxLevels luxLevels) { mCallbacks = callbacks; mTwilight = LocalServices.getService(TwilightManager.class); @@ -215,6 +221,8 @@ class AutomaticBrightnessController { mAmbientLightHorizon = ambientLightHorizon; mWeightingIntercept = ambientLightHorizon; mScreenAutoBrightnessAdjustmentMaxGamma = autoBrightnessAdjustmentMaxGamma; + mUseNewSensorSamplesForDoze = useNewSensorSamplesForDoze; + mUseActiveDozeLightSensorConfig = activeDozeLightSensor; mLuxLevels = luxLevels; mHandler = new AutomaticBrightnessHandler(looper); @@ -242,20 +250,18 @@ class AutomaticBrightnessController { // switch to a wake-up light sensor instead but for now we will simply disable the sensor // and hold onto the last computed screen auto brightness. We save the dozing flag for // debugging purposes. - mDozing = dozing; - boolean enableSensor = enable && !dozing; - if (enableSensor && !mLightSensorEnabled && mActiveDozeLightSensor) { - mActiveDozeLightSensor = false; - } else if (!enableSensor && mLightSensorEnabled && mLuxLevels.hasDynamicDozeBrightness()) { - // keep the light sensor active until another light sample is taken in doze mode - mActiveDozeLightSensor = true; - if (mLuxLevels.useNewSensorSamplesForDoze()) { - mAmbientLightRingBuffer.clear(); - mInitialHorizonAmbientLightRingBuffer.clear(); - mAmbientLuxValid = false; - return; + boolean enableSensor = enable && (dozing ? mUseActiveDozeLightSensorConfig : true); + if (enableSensor && dozing && !mDozing && mLightSensorEnabled + && mUseNewSensorSamplesForDoze) { + mAmbientLightRingBuffer.clear(); + mInitialHorizonAmbientLightRingBuffer.clear(); + if (DEBUG) { + Slog.d(TAG, "configure: Clearing ambient light ring buffers when entering doze."); } + mAmbientLuxValid = false; + adjustLightSensorRate(mInitialLightSensorRate); } + mDozing = dozing; boolean changed = setLightSensorEnabled(enableSensor); changed |= setScreenAutoBrightnessAdjustment(adjustment); changed |= setUseTwilight(useTwilight); @@ -315,6 +321,9 @@ class AutomaticBrightnessController { private boolean setLightSensorEnabled(boolean enable) { if (enable) { if (!mLightSensorEnabled) { + if (DEBUG) { + Slog.d(TAG, "setLightSensorEnabled: sensor enabled"); + } mLightSensorEnabled = true; mAmbientLightRingBuffer.clear(); mInitialHorizonAmbientLightRingBuffer.clear(); @@ -327,6 +336,9 @@ class AutomaticBrightnessController { } } else { if (mLightSensorEnabled) { + if (DEBUG) { + Slog.d(TAG, "setLightSensorEnabled: sensor disabled"); + } mLightSensorEnabled = false; mRecentLightSamples = 0; mCurrentLightSensorRate = -1; @@ -346,8 +358,11 @@ class AutomaticBrightnessController { } applyLightSensorMeasurement(time, lux); updateAmbientLux(time); - if (mActiveDozeLightSensor) { + if (mUseActiveDozeLightSensorConfig && mDozing) { // disable the ambient light sensor and update the screen brightness + if (DEBUG) { + Slog.d(TAG, "handleLightSensorEvent: doze ambient light sensor reading: " + lux); + } setLightSensorEnabled(false); updateAutoBrightness(true /*sendUpdate*/); } @@ -566,7 +581,7 @@ class AutomaticBrightnessController { } int newScreenAutoBrightness; - if (mActiveDozeLightSensor) { + if (mUseActiveDozeLightSensorConfig && mDozing) { newScreenAutoBrightness = mLuxLevels.getDozeBrightness(mAmbientLux); } else { newScreenAutoBrightness = diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index de5bffda424f..c10331268557 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -153,8 +153,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call // True if should use light sensor to automatically determine doze screen brightness. private final boolean mAllowAutoBrightnessWhileDozingConfig; - // True if using only new sensor samples to automatically determine doze screen brightness. - private boolean mUseNewSensorSamplesForDoze; + // True if collecting light sensor samples in doze mode. + private boolean mUseActiveDozeLightSensorConfig; // True if we should fade the screen while turning it off, false if we should play // a stylish color fade animation instead. @@ -357,11 +357,12 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call com.android.internal.R.array.config_dozeSensorLuxLevels); int[] dozeBrightnessBacklightValues = resources.getIntArray( com.android.internal.R.array.config_dozeBrightnessBacklightValues); - mUseNewSensorSamplesForDoze = resources.getBoolean( + boolean useNewSensorSamplesForDoze = resources.getBoolean( com.android.internal.R.bool.config_useNewSensorSamplesForDoze); + mUseActiveDozeLightSensorConfig = resources.getBoolean( + com.android.internal.R.bool.config_allowAutoBrightnessActiveDozeLightSensor); LuxLevels luxLevels = new LuxLevels(brightHysteresisLevels, darkHysteresisLevels, - luxHysteresisLevels, mUseNewSensorSamplesForDoze, dozeSensorLuxLevels, - dozeBrightnessBacklightValues); + luxHysteresisLevels, dozeSensorLuxLevels, dozeBrightnessBacklightValues); Spline screenAutoBrightnessSpline = createAutoBrightnessSpline(lux, screenBrightness); if (screenAutoBrightnessSpline == null) { @@ -389,7 +390,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mScreenBrightnessRangeMaximum, dozeScaleFactor, lightSensorRate, initialLightSensorRate, brighteningLightDebounce, darkeningLightDebounce, autoBrightnessResetAmbientLuxAfterWarmUp, ambientLightHorizon, - autoBrightnessAdjustmentMaxGamma, luxLevels); + autoBrightnessAdjustmentMaxGamma, mUseActiveDozeLightSensorConfig, + useNewSensorSamplesForDoze, luxLevels); } } @@ -643,8 +645,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call if (mAutomaticBrightnessController != null) { final boolean autoBrightnessEnabledInDoze = mAllowAutoBrightnessWhileDozingConfig && (state == Display.STATE_DOZE || state == Display.STATE_DOZE_SUSPEND); - autoBrightnessEnabled = mPowerRequest.useAutoBrightness + autoBrightnessEnabled = (mPowerRequest.useAutoBrightness && (state == Display.STATE_ON || autoBrightnessEnabledInDoze) + || mUseActiveDozeLightSensorConfig && autoBrightnessEnabledInDoze) && brightness < 0; final boolean userInitiatedChange = autoBrightnessAdjustmentChanged && mPowerRequest.brightnessSetByUser; @@ -687,8 +690,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call if (state == Display.STATE_DOZE || state == Display.STATE_DOZE_SUSPEND) { if (brightness < 0) { brightness = mScreenBrightnessDozeConfig; - } else if (mUseNewSensorSamplesForDoze) { + } else if (mUseActiveDozeLightSensorConfig) { brightness = Math.min(brightness, mScreenBrightnessDozeConfig); + if (DEBUG) { + Slog.d(TAG, "updatePowerState: ALS-based doze brightness: " + brightness); + } } } diff --git a/services/core/java/com/android/server/display/LuxLevels.java b/services/core/java/com/android/server/display/LuxLevels.java index a13626d8f820..a796871874c4 100644 --- a/services/core/java/com/android/server/display/LuxLevels.java +++ b/services/core/java/com/android/server/display/LuxLevels.java @@ -26,12 +26,10 @@ final class LuxLevels { private static final boolean DEBUG = true; - private final boolean mUseNewSensorSamplesForDoze; - private final float[] mBrightLevels; private final float[] mDarkLevels; private final float[] mLuxHysteresisLevels; - private final float[] mDozeBacklightLevels; + private final float[] mDozeBrightnessBacklightValues; private final float[] mDozeSensorLuxLevels; /** @@ -41,31 +39,29 @@ final class LuxLevels { * {@code luxLevels} has length n+1. * * {@code dozeSensorLuxLevels} has length r. - * {@code dozeBacklightLevels} has length r+1. + * {@code dozeBrightnessBacklightValues} has length r+1. * * @param brightLevels an array of brightening hysteresis constraint constants * @param darkLevels an array of darkening hysteresis constraint constants * @param luxHysteresisLevels a monotonically increasing array of illuminance thresholds in lux * @param dozeSensorLuxLevels a monotonically increasing array of ALS thresholds in lux - * @param dozeBacklightLevels an array of screen brightness values for doze mode in lux + * @param dozeBrightnessBacklightValues an array of screen brightness values for doze mode in lux */ public LuxLevels(int[] brightLevels, int[] darkLevels, int[] luxHysteresisLevels, - boolean useNewSensorSamplesForDoze, int[] dozeSensorLuxLevels, - int[] dozeBacklightLevels) { + int[] dozeSensorLuxLevels, int[] dozeBrightnessBacklightValues) { if (brightLevels.length != darkLevels.length || darkLevels.length !=luxHysteresisLevels.length + 1) { throw new IllegalArgumentException("Mismatch between hysteresis array lengths."); } - if (dozeBacklightLevels.length > 0 && dozeSensorLuxLevels.length > 0 - && dozeBacklightLevels.length != dozeSensorLuxLevels.length + 1) { + if (dozeBrightnessBacklightValues.length > 0 && dozeSensorLuxLevels.length > 0 + && dozeBrightnessBacklightValues.length != dozeSensorLuxLevels.length + 1) { throw new IllegalArgumentException("Mismatch between doze lux array lengths."); } mBrightLevels = setArrayFormat(brightLevels, 1000.0f); mDarkLevels = setArrayFormat(darkLevels, 1000.0f); mLuxHysteresisLevels = setArrayFormat(luxHysteresisLevels, 1.0f); - mUseNewSensorSamplesForDoze = useNewSensorSamplesForDoze; mDozeSensorLuxLevels = setArrayFormat(dozeSensorLuxLevels, 1.0f); - mDozeBacklightLevels = setArrayFormat(dozeBacklightLevels, 1.0f); + mDozeBrightnessBacklightValues = setArrayFormat(dozeBrightnessBacklightValues, 1.0f); } /** @@ -98,7 +94,7 @@ final class LuxLevels { * Return the doze backlight brightness level for the given ambient sensor lux level. */ public int getDozeBrightness(float lux) { - int dozeBrightness = (int) getReferenceLevel(lux, mDozeBacklightLevels, + int dozeBrightness = (int) getReferenceLevel(lux, mDozeBrightnessBacklightValues, mDozeSensorLuxLevels); if (DEBUG) { Slog.d(TAG, "doze brightness: " + dozeBrightness + ", lux=" + lux); @@ -126,13 +122,6 @@ final class LuxLevels { } /** - * Return if new ALS samples should be used for determining screen brightness while dozing. - */ - public boolean useNewSensorSamplesForDoze() { - return mUseNewSensorSamplesForDoze; - } - - /** * Return a float array where each i-th element equals {@code configArray[i]/divideFactor}. */ private float[] setArrayFormat(int[] configArray, float divideFactor) { |