Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 58efe25c authored by Julius D'souza's avatar Julius D'souza Committed by android-build-merger
Browse files

DO NOT MERGE: Add initial ambient light sensor rate am: 82b9aff0

am: 4d3af804

Change-Id: Ia54da3fd528bc62c74f607af1e8d45a51bf11918
parents f2c9eea7 4d3af804
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1056,6 +1056,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 0 to disable this feature. -->
    <integer name="config_autoBrightnessInitialLightSensorRate">0</integer>

    <!-- Light sensor event rate in milliseconds for automatic brightness control. -->
    <integer name="config_autoBrightnessLightSensorRate">250</integer>

+1 −0
Original line number Diff line number Diff line
@@ -1734,6 +1734,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" />
+37 −8
Original line number Diff line number Diff line
@@ -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
@@ -188,7 +194,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,
            LuxLevels luxLevels) {
@@ -200,7 +206,9 @@ class AutomaticBrightnessController {
        mScreenBrightnessRangeMaximum = brightnessMax;
        mLightSensorWarmUpTimeConfig = lightSensorWarmUpTime;
        mDozeScaleFactor = dozeScaleFactor;
        mLightSensorRate = lightSensorRate;
        mNormalLightSensorRate = lightSensorRate;
        mInitialLightSensorRate = initialLightSensorRate;
        mCurrentLightSensorRate = mNormalLightSensorRate;
        mBrighteningLightDebounceConfig = brighteningLightDebounceConfig;
        mDarkeningLightDebounceConfig = darkeningLightDebounceConfig;
        mResetAmbientLuxAfterWarmUpConfig = resetAmbientLuxAfterWarmUpConfig;
@@ -211,9 +219,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);
@@ -313,13 +321,16 @@ class AutomaticBrightnessController {
                mAmbientLuxValid = !mResetAmbientLuxAfterWarmUpConfig;
                mLightSensorEnableTime = SystemClock.uptimeMillis();
                mSensorManager.registerListener(mLightSensorListener, mLightSensor,
                        mLightSensorRate * 1000, mHandler);
                        mCurrentLightSensorRate * 1000, mHandler);
                return true;
            }
        } else {
            if (mLightSensorEnabled) {
                mLightSensorEnabled = false;
                mRecentLightSamples = 0;
                if (mInitialLightSensorRate > 0) {
                    mCurrentLightSensorRate = mInitialLightSensorRate;
                }
                mHandler.removeMessages(MSG_UPDATE_AMBIENT_LUX);
                mSensorManager.unregisterListener(mLightSensorListener);
            }
@@ -330,6 +341,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);
        if (mActiveDozeLightSensor) {
@@ -354,6 +369,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;
@@ -489,7 +518,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));
+3 −1
Original line number Diff line number Diff line
@@ -313,6 +313,8 @@ 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);
        long brighteningLightDebounce = resources.getInteger(
                com.android.internal.R.integer.config_autoBrightnessBrighteningLightDebounce);
        long darkeningLightDebounce = resources.getInteger(
@@ -378,7 +380,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                        handler.getLooper(), sensorManager, screenAutoBrightnessSpline,
                        lightSensorWarmUpTimeConfig, screenBrightnessRangeMinimum,
                        mScreenBrightnessRangeMaximum, dozeScaleFactor, lightSensorRate,
                        brighteningLightDebounce, darkeningLightDebounce,
                        initialLightSensorRate, brighteningLightDebounce, darkeningLightDebounce,
                        autoBrightnessResetAmbientLuxAfterWarmUp, ambientLightHorizon,
                        autoBrightnessAdjustmentMaxGamma, luxLevels);
            }