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

Commit 34b3da0d authored by Piotr Wilczyński's avatar Piotr Wilczyński Committed by Android (Google) Code Review
Browse files

Merge "Retain the short-term model when device state changes"

parents 54dc37bd bd748a47
Loading
Loading
Loading
Loading
+21 −9
Original line number Diff line number Diff line
@@ -249,7 +249,7 @@ class AutomaticBrightnessController {
            HysteresisLevels screenBrightnessThresholdsIdle, Context context,
            HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler,
            BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort,
            int ambientLightHorizonLong) {
            int ambientLightHorizonLong, float userLux, float userBrightness) {
        this(new Injector(), callbacks, looper, sensorManager, lightSensor,
                interactiveModeBrightnessMapper,
                lightSensorWarmUpTime, brightnessMin, brightnessMax, dozeScaleFactor,
@@ -258,7 +258,7 @@ class AutomaticBrightnessController {
                ambientBrightnessThresholds, screenBrightnessThresholds,
                ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, context,
                hbmController, brightnessThrottler, idleModeBrightnessMapper,
                ambientLightHorizonShort, ambientLightHorizonLong
                ambientLightHorizonShort, ambientLightHorizonLong, userLux, userBrightness
        );
    }

@@ -275,7 +275,7 @@ class AutomaticBrightnessController {
            HysteresisLevels screenBrightnessThresholdsIdle, Context context,
            HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler,
            BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort,
            int ambientLightHorizonLong) {
            int ambientLightHorizonLong, float userLux, float userBrightness) {
        mInjector = injector;
        mClock = injector.createClock();
        mContext = context;
@@ -322,6 +322,12 @@ class AutomaticBrightnessController {
        mIdleModeBrightnessMapper = idleModeBrightnessMapper;
        // Initialize to active (normal) screen brightness mode
        switchToInteractiveScreenBrightnessMode();

        if (userLux != BrightnessMappingStrategy.NO_USER_LUX
                && userBrightness != BrightnessMappingStrategy.NO_USER_BRIGHTNESS) {
            // Use the given short-term model
            setScreenBrightnessByUser(userLux, userBrightness);
        }
    }

    /**
@@ -384,7 +390,8 @@ class AutomaticBrightnessController {

    public void configure(int state, @Nullable BrightnessConfiguration configuration,
            float brightness, boolean userChangedBrightness, float adjustment,
            boolean userChangedAutoBrightnessAdjustment, int displayPolicy) {
            boolean userChangedAutoBrightnessAdjustment, int displayPolicy,
            boolean shouldResetShortTermModel) {
        mState = state;
        mHbmController.setAutoBrightnessEnabled(mState);
        // While dozing, the application processor may be suspended which will prevent us from
@@ -393,7 +400,7 @@ class AutomaticBrightnessController {
        // and hold onto the last computed screen auto brightness.  We save the dozing flag for
        // debugging purposes.
        boolean dozing = (displayPolicy == DisplayPowerRequest.POLICY_DOZE);
        boolean changed = setBrightnessConfiguration(configuration);
        boolean changed = setBrightnessConfiguration(configuration, shouldResetShortTermModel);
        changed |= setDisplayPolicy(displayPolicy);
        if (userChangedAutoBrightnessAdjustment) {
            changed |= setAutoBrightnessAdjustment(adjustment);
@@ -492,9 +499,13 @@ class AutomaticBrightnessController {
            // and we can't use this data to add a new control point to the short-term model.
            return false;
        }
        mCurrentBrightnessMapper.addUserDataPoint(mAmbientLux, brightness);
        return setScreenBrightnessByUser(mAmbientLux, brightness);
    }

    private boolean setScreenBrightnessByUser(float lux, float brightness) {
        mCurrentBrightnessMapper.addUserDataPoint(lux, brightness);
        mShortTermModelValid = true;
        mShortTermModelAnchor = mAmbientLux;
        mShortTermModelAnchor = lux;
        if (mLoggingEnabled) {
            Slog.d(TAG, "ShortTermModel: anchor=" + mShortTermModelAnchor);
        }
@@ -514,9 +525,10 @@ class AutomaticBrightnessController {
        mShortTermModelValid = false;
    }

    public boolean setBrightnessConfiguration(BrightnessConfiguration configuration) {
    public boolean setBrightnessConfiguration(BrightnessConfiguration configuration,
            boolean shouldResetShortTermModel) {
        if (mInteractiveModeBrightnessMapper.setBrightnessConfiguration(configuration)) {
            if (!isInIdleMode()) {
            if (!isInIdleMode() && shouldResetShortTermModel) {
                resetShortTermModel();
            }
            return true;
+34 −4
Original line number Diff line number Diff line
@@ -51,6 +51,9 @@ import java.util.Objects;
public abstract class BrightnessMappingStrategy {
    private static final String TAG = "BrightnessMappingStrategy";

    public static final float NO_USER_LUX = -1;
    public static final float NO_USER_BRIGHTNESS = -1;

    private static final float LUX_GRAD_SMOOTHING = 0.25f;
    private static final float MAX_GRAD = 1.0f;
    private static final float SHORT_TERM_MODEL_THRESHOLD_RATIO = 0.6f;
@@ -68,6 +71,7 @@ public abstract class BrightnessMappingStrategy {
     * Creates a BrightnessMappingStrategy for active (normal) mode.
     * @param resources
     * @param displayDeviceConfig
     * @param displayWhiteBalanceController
     * @return the BrightnessMappingStrategy
     */
    @Nullable
@@ -82,6 +86,7 @@ public abstract class BrightnessMappingStrategy {
     * Creates a BrightnessMappingStrategy for idle screen brightness mode.
     * @param resources
     * @param displayDeviceConfig
     * @param displayWhiteBalanceController
     * @return the BrightnessMappingStrategy
     */
    @Nullable
@@ -100,6 +105,7 @@ public abstract class BrightnessMappingStrategy {
     * @param displayDeviceConfig
     * @param isForIdleMode determines whether the configurations loaded are for idle screen
     *                      brightness mode or active screen brightness mode.
     * @param displayWhiteBalanceController
     * @return the BrightnessMappingStrategy
     */
    @Nullable
@@ -370,6 +376,10 @@ public abstract class BrightnessMappingStrategy {
     */
    public abstract boolean isForIdleMode();

    abstract float getUserLux();

    abstract float getUserBrightness();

    /**
     * Check if the short term model should be reset given the anchor lux the last
     * brightness change was made at and the current ambient lux.
@@ -604,8 +614,8 @@ public abstract class BrightnessMappingStrategy {

            mMaxGamma = maxGamma;
            mAutoBrightnessAdjustment = 0;
            mUserLux = -1;
            mUserBrightness = -1;
            mUserLux = NO_USER_LUX;
            mUserBrightness = NO_USER_BRIGHTNESS;
            if (mLoggingEnabled) {
                PLOG.start("simple mapping strategy");
            }
@@ -732,6 +742,16 @@ public abstract class BrightnessMappingStrategy {
            return false;
        }

        @Override
        float getUserLux() {
            return mUserLux;
        }

        @Override
        float getUserBrightness() {
            return mUserBrightness;
        }

        private void computeSpline() {
            Pair<float[], float[]> curve = getAdjustedCurve(mLux, mBrightness, mUserLux,
                    mUserBrightness, mAutoBrightnessAdjustment, mMaxGamma);
@@ -799,8 +819,8 @@ public abstract class BrightnessMappingStrategy {
            mIsForIdleMode = isForIdleMode;
            mMaxGamma = maxGamma;
            mAutoBrightnessAdjustment = 0;
            mUserLux = -1;
            mUserBrightness = -1;
            mUserLux = NO_USER_LUX;
            mUserBrightness = NO_USER_BRIGHTNESS;
            mDisplayWhiteBalanceController = displayWhiteBalanceController;

            mNits = nits;
@@ -972,6 +992,16 @@ public abstract class BrightnessMappingStrategy {
            return mIsForIdleMode;
        }

        @Override
        float getUserLux() {
            return mUserLux;
        }

        @Override
        float getUserBrightness() {
            return mUserBrightness;
        }

        /**
         * Prints out the default curve and how it differs from the long-term curve
         * and the current curve (in case the current curve includes short-term adjustments).
+4 −3
Original line number Diff line number Diff line
@@ -594,7 +594,7 @@ public final class DisplayManagerService extends SystemService {
                            getBrightnessConfigForDisplayWithPdsFallbackLocked(
                            logicalDisplay.getPrimaryDisplayDeviceLocked().getUniqueId(),
                            userSerial);
                    dpc.setBrightnessConfiguration(config);
                    dpc.setBrightnessConfiguration(config, /* shouldResetShortTermModel= */ true);
                }
                dpc.onSwitchUser(newUserId);
            });
@@ -1934,7 +1934,7 @@ public final class DisplayManagerService extends SystemService {
            }
            DisplayPowerControllerInterface dpc = getDpcFromUniqueIdLocked(uniqueId);
            if (dpc != null) {
                dpc.setBrightnessConfiguration(c);
                dpc.setBrightnessConfiguration(c, /* shouldResetShortTermModel= */ true);
            }
        }
    }
@@ -1983,7 +1983,8 @@ public final class DisplayManagerService extends SystemService {
                    final DisplayPowerControllerInterface dpc = mDisplayPowerControllers.get(
                            logicalDisplay.getDisplayIdLocked());
                    if (dpc != null) {
                        dpc.setBrightnessConfiguration(config);
                        dpc.setBrightnessConfiguration(config,
                                /* shouldResetShortTermModel= */ false);
                    }
                }
            });
+19 −4
Original line number Diff line number Diff line
@@ -225,6 +225,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    // True if should use light sensor to automatically determine doze screen brightness.
    private final boolean mAllowAutoBrightnessWhileDozingConfig;

    // True if the brightness config has changed and the short-term model needs to be reset
    private boolean mShouldResetShortTermModel;

    // Whether or not the color fade on screen on / off is enabled.
    private final boolean mColorFadeEnabled;

@@ -951,6 +954,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            return;
        }

        float userLux = BrightnessMappingStrategy.NO_USER_LUX;
        float userBrightness = BrightnessMappingStrategy.NO_USER_BRIGHTNESS;
        if (mInteractiveModeBrightnessMapper != null) {
            userLux = mInteractiveModeBrightnessMapper.getUserLux();
            userBrightness = mInteractiveModeBrightnessMapper.getUserBrightness();
        }

        final boolean isIdleScreenBrightnessEnabled = resources.getBoolean(
                R.bool.config_enableIdleScreenBrightnessMode);
        mInteractiveModeBrightnessMapper = BrightnessMappingStrategy.create(resources,
@@ -1078,7 +1088,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                    ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, mContext,
                    mHbmController, mBrightnessThrottler, mIdleModeBrightnessMapper,
                    mDisplayDeviceConfig.getAmbientHorizonShort(),
                    mDisplayDeviceConfig.getAmbientHorizonLong());
                    mDisplayDeviceConfig.getAmbientHorizonLong(), userLux, userBrightness);

            mBrightnessEventRingBuffer =
                    new RingBuffer<>(BrightnessEvent.class, RINGBUFFER_MAX);
@@ -1428,7 +1438,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                    mBrightnessConfiguration,
                    mLastUserSetScreenBrightness,
                    userSetBrightnessChanged, autoBrightnessAdjustment,
                    autoBrightnessAdjustmentChanged, mPowerRequest.policy);
                    autoBrightnessAdjustmentChanged, mPowerRequest.policy,
                    mShouldResetShortTermModel);
            mShouldResetShortTermModel = false;
        }

        if (mBrightnessTracker != null) {
@@ -1840,8 +1852,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    }

    @Override
    public void setBrightnessConfiguration(BrightnessConfiguration c) {
        Message msg = mHandler.obtainMessage(MSG_CONFIGURE_BRIGHTNESS, c);
    public void setBrightnessConfiguration(BrightnessConfiguration c,
            boolean shouldResetShortTermModel) {
        Message msg = mHandler.obtainMessage(MSG_CONFIGURE_BRIGHTNESS,
                shouldResetShortTermModel ? 1 : 0, /* unused */ 0, c);
        msg.sendToTarget();
    }

@@ -2892,6 +2906,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                    break;
                case MSG_CONFIGURE_BRIGHTNESS:
                    mBrightnessConfiguration = (BrightnessConfiguration) msg.obj;
                    mShouldResetShortTermModel = msg.arg1 == 1;
                    updatePowerState();
                    break;

+19 −4
Original line number Diff line number Diff line
@@ -202,6 +202,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
    // True if auto-brightness should be used.
    private boolean mUseSoftwareAutoBrightnessConfig;

    // True if the brightness config has changed and the short-term model needs to be reset
    private boolean mShouldResetShortTermModel;

    // Whether or not the color fade on screen on / off is enabled.
    private final boolean mColorFadeEnabled;

@@ -868,6 +871,13 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
            return;
        }

        float userLux = BrightnessMappingStrategy.NO_USER_LUX;
        float userBrightness = BrightnessMappingStrategy.NO_USER_BRIGHTNESS;
        if (mInteractiveModeBrightnessMapper != null) {
            userLux = mInteractiveModeBrightnessMapper.getUserLux();
            userBrightness = mInteractiveModeBrightnessMapper.getUserBrightness();
        }

        final boolean isIdleScreenBrightnessEnabled = resources.getBoolean(
                R.bool.config_enableIdleScreenBrightnessMode);
        mInteractiveModeBrightnessMapper = BrightnessMappingStrategy.create(resources,
@@ -995,7 +1005,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
                    ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, mContext,
                    mHbmController, mBrightnessThrottler, mIdleModeBrightnessMapper,
                    mDisplayDeviceConfig.getAmbientHorizonShort(),
                    mDisplayDeviceConfig.getAmbientHorizonLong());
                    mDisplayDeviceConfig.getAmbientHorizonLong(), userLux, userBrightness);

            mBrightnessEventRingBuffer =
                    new RingBuffer<>(BrightnessEvent.class, RINGBUFFER_MAX);
@@ -1220,7 +1230,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
                    mBrightnessConfiguration,
                    mLastUserSetScreenBrightness,
                    userSetBrightnessChanged, autoBrightnessAdjustment,
                    autoBrightnessAdjustmentChanged, mPowerRequest.policy);
                    autoBrightnessAdjustmentChanged, mPowerRequest.policy,
                    mShouldResetShortTermModel);
            mShouldResetShortTermModel = false;
        }

        if (mBrightnessTracker != null) {
@@ -1626,8 +1638,10 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
    }

    @Override
    public void setBrightnessConfiguration(BrightnessConfiguration c) {
        Message msg = mHandler.obtainMessage(MSG_CONFIGURE_BRIGHTNESS, c);
    public void setBrightnessConfiguration(BrightnessConfiguration c,
            boolean shouldResetShortTermModel) {
        Message msg = mHandler.obtainMessage(MSG_CONFIGURE_BRIGHTNESS,
                shouldResetShortTermModel ? 1 : 0, /* unused */ 0, c);
        msg.sendToTarget();
    }

@@ -2485,6 +2499,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
                    break;
                case MSG_CONFIGURE_BRIGHTNESS:
                    mBrightnessConfiguration = (BrightnessConfiguration) msg.obj;
                    mShouldResetShortTermModel = msg.arg1 == 1;
                    updatePowerState();
                    break;

Loading