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

Unverified Commit 2aba41cd authored by Danny Baumann's avatar Danny Baumann Committed by Michael Bestas
Browse files

Increase brightness faster if ambient light is brightening quickly.

The point of doing this is when going from indoors to bright sunlight,
the brightness adjustment currently leaves one with looking at an
unreadable display for a couple of seconds. Increase responsiveness in
that scenario to ramp up brightness faster.

Change-Id: Idf8ca8ebcdcea06746b0c4f3ab94d2ddddafb32e
parent b695c398
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -68,4 +68,8 @@

    <!-- Screen unpinning -->
    <java-symbol type="string" name="lock_to_app_toast_no_navbar" />

    <!-- Automatic brightness enhancements -->
    <java-symbol type="integer" name="config_autoBrightnessBrighteningLightFastDebounce"/>

</resources>
+1 −0
Original line number Diff line number Diff line
@@ -1134,6 +1134,7 @@
         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_autoBrightnessBrighteningLightFastDebounce">500</integer>
    <integer name="config_autoBrightnessBrighteningLightDebounce">4000</integer>
    <integer name="config_autoBrightnessDarkeningLightDebounce">8000</integer>

+21 −8
Original line number Diff line number Diff line
@@ -56,6 +56,11 @@ class AutomaticBrightnessController {
    private static final float BRIGHTENING_LIGHT_HYSTERESIS = 0.10f;
    private static final float DARKENING_LIGHT_HYSTERESIS = 0.20f;

    // Threshold (in lux) to select between normal and fast debounce time.
    // If the difference between last sample and weighted value is larger than this value,
    // fast debounce is used.
    private static final float BRIGHTENING_FAST_THRESHOLD = 1000f;

    // How long the current sensor reading is assumed to be valid beyond the current time.
    // This provides a bit of prediction, as well as ensures that the weight for the last sample is
    // non-zero, which in turn ensures that the total weight is non-zero.
@@ -100,6 +105,7 @@ class AutomaticBrightnessController {
    // 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 mBrighteningLightFastDebounceConfig;
    private final long mBrighteningLightDebounceConfig;
    private final long mDarkeningLightDebounceConfig;

@@ -189,6 +195,7 @@ class AutomaticBrightnessController {
            SensorManager sensorManager, Spline autoBrightnessSpline, int lightSensorWarmUpTime,
            int brightnessMin, int brightnessMax, float dozeScaleFactor,
            int lightSensorRate, long brighteningLightDebounceConfig,
            long brighteningLightFastDebounceConfig,
            long darkeningLightDebounceConfig, boolean resetAmbientLuxAfterWarmUpConfig,
            int ambientLightHorizon, float autoBrightnessAdjustmentMaxGamma ) {
        mCallbacks = callbacks;
@@ -201,6 +208,7 @@ class AutomaticBrightnessController {
        mDozeScaleFactor = dozeScaleFactor;
        mLightSensorRate = lightSensorRate;
        mBrighteningLightDebounceConfig = brighteningLightDebounceConfig;
        mBrighteningLightFastDebounceConfig = brighteningLightFastDebounceConfig;
        mDarkeningLightDebounceConfig = darkeningLightDebounceConfig;
        mResetAmbientLuxAfterWarmUpConfig = resetAmbientLuxAfterWarmUpConfig;
        mAmbientLightHorizon = ambientLightHorizon;
@@ -263,6 +271,7 @@ class AutomaticBrightnessController {
        pw.println("  mScreenBrightnessRangeMaximum=" + mScreenBrightnessRangeMaximum);
        pw.println("  mLightSensorWarmUpTimeConfig=" + mLightSensorWarmUpTimeConfig);
        pw.println("  mBrighteningLightDebounceConfig=" + mBrighteningLightDebounceConfig);
        pw.println("  mBrighteningLightFastDebounceConfig=" + mBrighteningLightFastDebounceConfig);
        pw.println("  mDarkeningLightDebounceConfig=" + mDarkeningLightDebounceConfig);
        pw.println("  mResetAmbientLuxAfterWarmUpConfig=" + mResetAmbientLuxAfterWarmUpConfig);

@@ -315,6 +324,7 @@ class AutomaticBrightnessController {
    private void handleLightSensorEvent(long time, float lux) {
        mHandler.removeMessages(MSG_UPDATE_AMBIENT_LUX);

        if (DEBUG) Slog.d(TAG, "handleLightSensorEvent: time=" + time + ", lux=" + lux);
        applyLightSensorMeasurement(time, lux);
        updateAmbientLux(time);
    }
@@ -387,7 +397,7 @@ class AutomaticBrightnessController {
        return x * (x * 0.5f + mWeightingIntercept);
    }

    private long nextAmbientLightBrighteningTransition(long time) {
    private long nextAmbientLightBrighteningTransition(long time, float ambientLux) {
        final int N = mAmbientLightRingBuffer.size();
        long earliestValidTime = time;
        for (int i = N - 1; i >= 0; i--) {
@@ -396,10 +406,13 @@ class AutomaticBrightnessController {
            }
            earliestValidTime = mAmbientLightRingBuffer.getTime(i);
        }
        return earliestValidTime + mBrighteningLightDebounceConfig;

        long debounceDelay = mLastObservedLux - ambientLux > BRIGHTENING_FAST_THRESHOLD
                ? mBrighteningLightFastDebounceConfig : mBrighteningLightDebounceConfig;
        return earliestValidTime + debounceDelay;
    }

    private long nextAmbientLightDarkeningTransition(long time) {
    private long nextAmbientLightDarkeningTransition(long time, float ambientLux) {
        final int N = mAmbientLightRingBuffer.size();
        long earliestValidTime = time;
        for (int i = N - 1; i >= 0; i--) {
@@ -443,13 +456,12 @@ class AutomaticBrightnessController {
            updateAutoBrightness(true);
        }

        long nextBrightenTransition = nextAmbientLightBrighteningTransition(time);
        long nextDarkenTransition = nextAmbientLightDarkeningTransition(time);
        float ambientLux = calculateAmbientLux(time);
        long nextBrightenTransition = nextAmbientLightBrighteningTransition(time, ambientLux);
        long nextDarkenTransition = nextAmbientLightDarkeningTransition(time, ambientLux);

        if (ambientLux >= mBrighteningLuxThreshold && nextBrightenTransition <= time
                || ambientLux <= mDarkeningLuxThreshold && nextDarkenTransition <= time) {
            setAmbientLux(ambientLux);
            if (DEBUG) {
                Slog.d(TAG, "updateAmbientLux: "
                        + ((ambientLux > mAmbientLux) ? "Brightened" : "Darkened") + ": "
@@ -457,9 +469,10 @@ class AutomaticBrightnessController {
                        + ", mAmbientLightRingBuffer=" + mAmbientLightRingBuffer
                        + ", mAmbientLux=" + mAmbientLux);
            }
            setAmbientLux(ambientLux);
            updateAutoBrightness(true);
            nextBrightenTransition = nextAmbientLightBrighteningTransition(time);
            nextDarkenTransition = nextAmbientLightDarkeningTransition(time);
            nextBrightenTransition = nextAmbientLightBrighteningTransition(time, ambientLux);
            nextDarkenTransition = nextAmbientLightDarkeningTransition(time, ambientLux);
        }
        long nextTransitionTime = Math.min(nextDarkenTransition, nextBrightenTransition);
        // If one of the transitions is ready to occur, but the total weighted ambient lux doesn't
+4 −2
Original line number Diff line number Diff line
@@ -317,6 +317,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                com.android.internal.R.integer.config_autoBrightnessLightSensorRate);
        long brighteningLightDebounce = resources.getInteger(
                com.android.internal.R.integer.config_autoBrightnessBrighteningLightDebounce);
        long brighteningLightFastDebounce = resources.getInteger(
                com.android.internal.R.integer.config_autoBrightnessBrighteningLightFastDebounce);
        long darkeningLightDebounce = resources.getInteger(
                com.android.internal.R.integer.config_autoBrightnessDarkeningLightDebounce);
        boolean autoBrightnessResetAmbientLuxAfterWarmUp = resources.getBoolean(
@@ -362,8 +364,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                        handler.getLooper(), sensorManager, screenAutoBrightnessSpline,
                        lightSensorWarmUpTimeConfig, screenBrightnessRangeMinimum,
                        mScreenBrightnessRangeMaximum, dozeScaleFactor, lightSensorRate,
                        brighteningLightDebounce, darkeningLightDebounce,
                        autoBrightnessResetAmbientLuxAfterWarmUp,
                        brighteningLightDebounce, brighteningLightFastDebounce,
                        darkeningLightDebounce, autoBrightnessResetAmbientLuxAfterWarmUp,
                        ambientLightHorizon, autoBrightnessAdjustmentMaxGamma);
            }
        }