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

Commit fbdb7a3f authored by Fiona Campbell's avatar Fiona Campbell Committed by Automerger Merge Worker
Browse files

Merge "Ensure backlight doesn't change when rbc is toggled" into sc-dev am: 5fa180d6

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15108421

Change-Id: Id9733ff024ce74f60092a1ae6328c5fd61ca3311
parents ee37f56c 5fa180d6
Loading
Loading
Loading
Loading
+26 −9
Original line number Diff line number Diff line
@@ -390,7 +390,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call

    // The last brightness that was set by the user and not temporary. Set to
    // PowerManager.BRIGHTNESS_INVALID_FLOAT when a brightness has yet to be recorded.
    private float mLastUserSetScreenBrightness;
    private float mLastUserSetScreenBrightness = Float.NaN;

    // The screen brightness setting has changed but not taken effect yet. If this is different
    // from the current screen brightness setting then this is coming from something other than us
@@ -421,6 +421,14 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    // PowerManager.BRIGHTNESS_INVALID_FLOAT when there's no temporary adjustment set.
    private float mTemporaryAutoBrightnessAdjustment;

    // Whether a reduce bright colors (rbc) change has been initiated by the user. We want to
    // retain the current backlight level when rbc is toggled, since rbc additionally makes the
    // screen appear dimmer using screen colors rather than backlight levels, and therefore we
    // don't actually want to compensate for this by then in/decreasing the backlight when
    // toggling this feature.
    // This should be false during system start up.
    private boolean mPendingUserRbcChange;

    // Animators.
    private ObjectAnimator mColorFadeOnAnimator;
    private ObjectAnimator mColorFadeOffAnimator;
@@ -552,24 +560,25 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            mCdsi = LocalServices.getService(ColorDisplayServiceInternal.class);
            boolean active = mCdsi.setReduceBrightColorsListener(new ReduceBrightColorsListener() {
                @Override
                public void onReduceBrightColorsActivationChanged(boolean activated) {
                    applyReduceBrightColorsSplineAdjustment();
                public void onReduceBrightColorsActivationChanged(boolean activated,
                        boolean userInitiated) {
                    applyReduceBrightColorsSplineAdjustment(userInitiated);
                }

                @Override
                public void onReduceBrightColorsStrengthChanged(int strength) {
                    applyReduceBrightColorsSplineAdjustment();
                    applyReduceBrightColorsSplineAdjustment(/*userInitiated*/ false);
                }
            });
            if (active) {
                applyReduceBrightColorsSplineAdjustment();
                applyReduceBrightColorsSplineAdjustment(/*userInitiated*/ false);
            }
        } else {
            mCdsi = null;
        }
    }

    private void applyReduceBrightColorsSplineAdjustment() {
    private void applyReduceBrightColorsSplineAdjustment(boolean userInitiated) {
        if (mBrightnessMapper == null) {
            Log.w(TAG, "No brightness mapping available to recalculate splines");
            return;
@@ -580,6 +589,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            adjustedNits[i] = mCdsi.getReduceBrightColorsAdjustedBrightnessNits(mNitsRange[i]);
        }
        mBrightnessMapper.recalculateSplines(mCdsi.isReduceBrightColorsActivated(), adjustedNits);
        mPendingUserRbcChange = userInitiated;
        sendUpdatePowerState();
    }

    /**
@@ -911,7 +922,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call

    private void reloadReduceBrightColours() {
        if (mCdsi != null && mCdsi.isReduceBrightColorsActivated()) {
            applyReduceBrightColorsSplineAdjustment();
            applyReduceBrightColorsSplineAdjustment(/*userInitiated*/ false);
        }
    }

@@ -2039,15 +2050,21 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    }

    private boolean updateUserSetScreenBrightness() {
        final boolean brightnessSplineChanged = mPendingUserRbcChange;
        if (mPendingUserRbcChange && !Float.isNaN(mCurrentScreenBrightnessSetting)) {
            mLastUserSetScreenBrightness = mCurrentScreenBrightnessSetting;
        }
        mPendingUserRbcChange = false;

        if ((Float.isNaN(mPendingScreenBrightnessSetting)
                || mPendingScreenBrightnessSetting < 0.0f)) {
            return false;
            return brightnessSplineChanged;
        }
        if (BrightnessSynchronizer.floatEquals(
                mCurrentScreenBrightnessSetting, mPendingScreenBrightnessSetting)) {
            mPendingScreenBrightnessSetting = PowerManager.BRIGHTNESS_INVALID_FLOAT;
            mTemporaryScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
            return false;
            return brightnessSplineChanged;
        }
        setCurrentScreenBrightness(mPendingScreenBrightnessSetting);
        mLastUserSetScreenBrightness = mPendingScreenBrightnessSetting;
+6 −5
Original line number Diff line number Diff line
@@ -355,7 +355,7 @@ public final class ColorDisplayService extends SystemService {
                                updateDisplayWhiteBalanceStatus();
                                break;
                            case Secure.REDUCE_BRIGHT_COLORS_ACTIVATED:
                                onReduceBrightColorsActivationChanged();
                                onReduceBrightColorsActivationChanged(/*userInitiated*/ true);
                                mHandler.sendEmptyMessage(MSG_APPLY_REDUCE_BRIGHT_COLORS);
                                break;
                            case Secure.REDUCE_BRIGHT_COLORS_LEVEL:
@@ -437,7 +437,7 @@ public final class ColorDisplayService extends SystemService {
            onReduceBrightColorsStrengthLevelChanged();
            final boolean reset = resetReduceBrightColors();
            if (!reset) {
                onReduceBrightColorsActivationChanged();
                onReduceBrightColorsActivationChanged(/*userInitiated*/ false);
                mHandler.sendEmptyMessage(MSG_APPLY_REDUCE_BRIGHT_COLORS);
            }
        }
@@ -614,7 +614,7 @@ public final class ColorDisplayService extends SystemService {
                isAccessiblityInversionEnabled() ? MATRIX_INVERT_COLOR : null);
    }

    private void onReduceBrightColorsActivationChanged() {
    private void onReduceBrightColorsActivationChanged(boolean userInitiated) {
        if (mCurrentUser == UserHandle.USER_NULL) {
            return;
        }
@@ -622,7 +622,8 @@ public final class ColorDisplayService extends SystemService {
                Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0, mCurrentUser) == 1;
        mReduceBrightColorsTintController.setActivated(activated);
        if (mReduceBrightColorsListener != null) {
            mReduceBrightColorsListener.onReduceBrightColorsActivationChanged(activated);
            mReduceBrightColorsListener.onReduceBrightColorsActivationChanged(activated,
                    userInitiated);
        }
    }

@@ -1551,7 +1552,7 @@ public final class ColorDisplayService extends SystemService {
        /**
         * Notify that the reduce bright colors activation status has changed.
         */
        void onReduceBrightColorsActivationChanged(boolean activated);
        void onReduceBrightColorsActivationChanged(boolean activated, boolean userInitiated);

        /**
         * Notify that the reduce bright colors strength has changed.