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

Commit 2ae003c5 authored by Danny Baumann's avatar Danny Baumann
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 15dab3c3
Loading
Loading
Loading
Loading
+20 −8
Original line number Diff line number Diff line
@@ -65,6 +65,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 static final long BRIGHTENING_LIGHT_FAST_DEBOUNCE = 500;
    private static final long BRIGHTENING_LIGHT_DEBOUNCE = 4000;
    private static final long DARKENING_LIGHT_DEBOUNCE = 8000;

@@ -74,6 +75,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;

    // The intercept used for the weighting calculation. This is used in order to keep all possible
    // weighting values positive.
    private static final int WEIGHTING_INTERCEPT = AMBIENT_LIGHT_HORIZON;
@@ -261,6 +267,7 @@ class AutomaticBrightnessController {
            if (!mLightSensorEnabled) {
                mLightSensorEnabled = true;
                mLightSensorEnableTime = SystemClock.uptimeMillis();

                mSensorManager.registerListener(mLightSensorListener, mLightSensor,
                        LIGHT_SENSOR_RATE_MILLIS * 1000, mHandler);
                return true;
@@ -281,6 +288,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);
    }
@@ -348,7 +356,7 @@ class AutomaticBrightnessController {
        return x * (x * 0.5f + WEIGHTING_INTERCEPT);
    }

    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--) {
@@ -357,10 +365,13 @@ class AutomaticBrightnessController {
            }
            earliestValidTime = mAmbientLightRingBuffer.getTime(i);
        }
        return earliestValidTime + BRIGHTENING_LIGHT_DEBOUNCE;

        long debounceDelay = mLastObservedLux - ambientLux > BRIGHTENING_FAST_THRESHOLD
                ? BRIGHTENING_LIGHT_FAST_DEBOUNCE : BRIGHTENING_LIGHT_DEBOUNCE;
        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--) {
@@ -369,6 +380,7 @@ class AutomaticBrightnessController {
            }
            earliestValidTime = mAmbientLightRingBuffer.getTime(i);
        }

        return earliestValidTime + DARKENING_LIGHT_DEBOUNCE;
    }

@@ -404,13 +416,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") + ": "
@@ -418,9 +429,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