DO NOT MERGE: Add initial ambient light sensor rate am: 82b9aff0a9
am: 4d3af80494
Change-Id: Ia54da3fd528bc62c74f607af1e8d45a51bf11918
This commit is contained in:
@@ -1056,6 +1056,12 @@
|
|||||||
<integer name="config_autoBrightnessBrighteningLightDebounce">4000</integer>
|
<integer name="config_autoBrightnessBrighteningLightDebounce">4000</integer>
|
||||||
<integer name="config_autoBrightnessDarkeningLightDebounce">8000</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 0 to disable this feature. -->
|
||||||
|
<integer name="config_autoBrightnessInitialLightSensorRate">0</integer>
|
||||||
|
|
||||||
<!-- Light sensor event rate in milliseconds for automatic brightness control. -->
|
<!-- Light sensor event rate in milliseconds for automatic brightness control. -->
|
||||||
<integer name="config_autoBrightnessLightSensorRate">250</integer>
|
<integer name="config_autoBrightnessLightSensorRate">250</integer>
|
||||||
|
|
||||||
|
|||||||
@@ -1734,6 +1734,7 @@
|
|||||||
<java-symbol type="integer" name="config_autoBrightnessAmbientLightHorizon"/>
|
<java-symbol type="integer" name="config_autoBrightnessAmbientLightHorizon"/>
|
||||||
<java-symbol type="integer" name="config_autoBrightnessBrighteningLightDebounce"/>
|
<java-symbol type="integer" name="config_autoBrightnessBrighteningLightDebounce"/>
|
||||||
<java-symbol type="integer" name="config_autoBrightnessDarkeningLightDebounce"/>
|
<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_autoBrightnessLightSensorRate"/>
|
||||||
<java-symbol type="integer" name="config_carDockKeepsScreenOn" />
|
<java-symbol type="integer" name="config_carDockKeepsScreenOn" />
|
||||||
<java-symbol type="integer" name="config_criticalBatteryWarningLevel" />
|
<java-symbol type="integer" name="config_criticalBatteryWarningLevel" />
|
||||||
|
|||||||
@@ -86,8 +86,14 @@ class AutomaticBrightnessController {
|
|||||||
private final int mScreenBrightnessRangeMaximum;
|
private final int mScreenBrightnessRangeMaximum;
|
||||||
private final float mDozeScaleFactor;
|
private final float mDozeScaleFactor;
|
||||||
|
|
||||||
// Light sensor event rate in milliseconds.
|
// Initial light sensor event rate in milliseconds.
|
||||||
private final int mLightSensorRate;
|
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
|
// 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
|
// for debouncing the light sensor. Different constants are used to debounce the light sensor
|
||||||
@@ -188,7 +194,7 @@ class AutomaticBrightnessController {
|
|||||||
public AutomaticBrightnessController(Callbacks callbacks, Looper looper,
|
public AutomaticBrightnessController(Callbacks callbacks, Looper looper,
|
||||||
SensorManager sensorManager, Spline autoBrightnessSpline, int lightSensorWarmUpTime,
|
SensorManager sensorManager, Spline autoBrightnessSpline, int lightSensorWarmUpTime,
|
||||||
int brightnessMin, int brightnessMax, float dozeScaleFactor,
|
int brightnessMin, int brightnessMax, float dozeScaleFactor,
|
||||||
int lightSensorRate, long brighteningLightDebounceConfig,
|
int lightSensorRate, int initialLightSensorRate, long brighteningLightDebounceConfig,
|
||||||
long darkeningLightDebounceConfig, boolean resetAmbientLuxAfterWarmUpConfig,
|
long darkeningLightDebounceConfig, boolean resetAmbientLuxAfterWarmUpConfig,
|
||||||
int ambientLightHorizon, float autoBrightnessAdjustmentMaxGamma,
|
int ambientLightHorizon, float autoBrightnessAdjustmentMaxGamma,
|
||||||
LuxLevels luxLevels) {
|
LuxLevels luxLevels) {
|
||||||
@@ -200,7 +206,9 @@ class AutomaticBrightnessController {
|
|||||||
mScreenBrightnessRangeMaximum = brightnessMax;
|
mScreenBrightnessRangeMaximum = brightnessMax;
|
||||||
mLightSensorWarmUpTimeConfig = lightSensorWarmUpTime;
|
mLightSensorWarmUpTimeConfig = lightSensorWarmUpTime;
|
||||||
mDozeScaleFactor = dozeScaleFactor;
|
mDozeScaleFactor = dozeScaleFactor;
|
||||||
mLightSensorRate = lightSensorRate;
|
mNormalLightSensorRate = lightSensorRate;
|
||||||
|
mInitialLightSensorRate = initialLightSensorRate;
|
||||||
|
mCurrentLightSensorRate = mNormalLightSensorRate;
|
||||||
mBrighteningLightDebounceConfig = brighteningLightDebounceConfig;
|
mBrighteningLightDebounceConfig = brighteningLightDebounceConfig;
|
||||||
mDarkeningLightDebounceConfig = darkeningLightDebounceConfig;
|
mDarkeningLightDebounceConfig = darkeningLightDebounceConfig;
|
||||||
mResetAmbientLuxAfterWarmUpConfig = resetAmbientLuxAfterWarmUpConfig;
|
mResetAmbientLuxAfterWarmUpConfig = resetAmbientLuxAfterWarmUpConfig;
|
||||||
@@ -211,9 +219,9 @@ class AutomaticBrightnessController {
|
|||||||
|
|
||||||
mHandler = new AutomaticBrightnessHandler(looper);
|
mHandler = new AutomaticBrightnessHandler(looper);
|
||||||
mAmbientLightRingBuffer =
|
mAmbientLightRingBuffer =
|
||||||
new AmbientLightRingBuffer(mLightSensorRate, mAmbientLightHorizon);
|
new AmbientLightRingBuffer(mNormalLightSensorRate, mAmbientLightHorizon);
|
||||||
mInitialHorizonAmbientLightRingBuffer =
|
mInitialHorizonAmbientLightRingBuffer =
|
||||||
new AmbientLightRingBuffer(mLightSensorRate, mAmbientLightHorizon);
|
new AmbientLightRingBuffer(mNormalLightSensorRate, mAmbientLightHorizon);
|
||||||
|
|
||||||
if (!DEBUG_PRETEND_LIGHT_SENSOR_ABSENT) {
|
if (!DEBUG_PRETEND_LIGHT_SENSOR_ABSENT) {
|
||||||
mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
|
mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
|
||||||
@@ -313,13 +321,16 @@ class AutomaticBrightnessController {
|
|||||||
mAmbientLuxValid = !mResetAmbientLuxAfterWarmUpConfig;
|
mAmbientLuxValid = !mResetAmbientLuxAfterWarmUpConfig;
|
||||||
mLightSensorEnableTime = SystemClock.uptimeMillis();
|
mLightSensorEnableTime = SystemClock.uptimeMillis();
|
||||||
mSensorManager.registerListener(mLightSensorListener, mLightSensor,
|
mSensorManager.registerListener(mLightSensorListener, mLightSensor,
|
||||||
mLightSensorRate * 1000, mHandler);
|
mCurrentLightSensorRate * 1000, mHandler);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mLightSensorEnabled) {
|
if (mLightSensorEnabled) {
|
||||||
mLightSensorEnabled = false;
|
mLightSensorEnabled = false;
|
||||||
mRecentLightSamples = 0;
|
mRecentLightSamples = 0;
|
||||||
|
if (mInitialLightSensorRate > 0) {
|
||||||
|
mCurrentLightSensorRate = mInitialLightSensorRate;
|
||||||
|
}
|
||||||
mHandler.removeMessages(MSG_UPDATE_AMBIENT_LUX);
|
mHandler.removeMessages(MSG_UPDATE_AMBIENT_LUX);
|
||||||
mSensorManager.unregisterListener(mLightSensorListener);
|
mSensorManager.unregisterListener(mLightSensorListener);
|
||||||
}
|
}
|
||||||
@@ -330,6 +341,10 @@ class AutomaticBrightnessController {
|
|||||||
private void handleLightSensorEvent(long time, float lux) {
|
private void handleLightSensorEvent(long time, float lux) {
|
||||||
mHandler.removeMessages(MSG_UPDATE_AMBIENT_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);
|
applyLightSensorMeasurement(time, lux);
|
||||||
updateAmbientLux(time);
|
updateAmbientLux(time);
|
||||||
if (mActiveDozeLightSensor) {
|
if (mActiveDozeLightSensor) {
|
||||||
@@ -354,6 +369,20 @@ class AutomaticBrightnessController {
|
|||||||
mLastObservedLuxTime = time;
|
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) {
|
private boolean setScreenAutoBrightnessAdjustment(float adjustment) {
|
||||||
if (adjustment != mScreenAutoBrightnessAdjustment) {
|
if (adjustment != mScreenAutoBrightnessAdjustment) {
|
||||||
mScreenAutoBrightnessAdjustment = adjustment;
|
mScreenAutoBrightnessAdjustment = adjustment;
|
||||||
@@ -489,7 +518,7 @@ class AutomaticBrightnessController {
|
|||||||
// should be enough time to decide whether we should actually transition to the new
|
// should be enough time to decide whether we should actually transition to the new
|
||||||
// weighted ambient lux or not.
|
// weighted ambient lux or not.
|
||||||
nextTransitionTime =
|
nextTransitionTime =
|
||||||
nextTransitionTime > time ? nextTransitionTime : time + mLightSensorRate;
|
nextTransitionTime > time ? nextTransitionTime : time + mNormalLightSensorRate;
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "updateAmbientLux: Scheduling ambient lux update for "
|
Slog.d(TAG, "updateAmbientLux: Scheduling ambient lux update for "
|
||||||
+ nextTransitionTime + TimeUtils.formatUptime(nextTransitionTime));
|
+ nextTransitionTime + TimeUtils.formatUptime(nextTransitionTime));
|
||||||
|
|||||||
@@ -313,6 +313,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
|||||||
|
|
||||||
int lightSensorRate = resources.getInteger(
|
int lightSensorRate = resources.getInteger(
|
||||||
com.android.internal.R.integer.config_autoBrightnessLightSensorRate);
|
com.android.internal.R.integer.config_autoBrightnessLightSensorRate);
|
||||||
|
int initialLightSensorRate = resources.getInteger(
|
||||||
|
com.android.internal.R.integer.config_autoBrightnessInitialLightSensorRate);
|
||||||
long brighteningLightDebounce = resources.getInteger(
|
long brighteningLightDebounce = resources.getInteger(
|
||||||
com.android.internal.R.integer.config_autoBrightnessBrighteningLightDebounce);
|
com.android.internal.R.integer.config_autoBrightnessBrighteningLightDebounce);
|
||||||
long darkeningLightDebounce = resources.getInteger(
|
long darkeningLightDebounce = resources.getInteger(
|
||||||
@@ -378,7 +380,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
|
|||||||
handler.getLooper(), sensorManager, screenAutoBrightnessSpline,
|
handler.getLooper(), sensorManager, screenAutoBrightnessSpline,
|
||||||
lightSensorWarmUpTimeConfig, screenBrightnessRangeMinimum,
|
lightSensorWarmUpTimeConfig, screenBrightnessRangeMinimum,
|
||||||
mScreenBrightnessRangeMaximum, dozeScaleFactor, lightSensorRate,
|
mScreenBrightnessRangeMaximum, dozeScaleFactor, lightSensorRate,
|
||||||
brighteningLightDebounce, darkeningLightDebounce,
|
initialLightSensorRate, brighteningLightDebounce, darkeningLightDebounce,
|
||||||
autoBrightnessResetAmbientLuxAfterWarmUp, ambientLightHorizon,
|
autoBrightnessResetAmbientLuxAfterWarmUp, ambientLightHorizon,
|
||||||
autoBrightnessAdjustmentMaxGamma, luxLevels);
|
autoBrightnessAdjustmentMaxGamma, luxLevels);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user