diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index 555add4b027f2..6376c10f2f1de 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -393,7 +393,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 @@ -424,6 +424,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; @@ -555,24 +563,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; @@ -583,6 +592,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call adjustedNits[i] = mCdsi.getReduceBrightColorsAdjustedBrightnessNits(mNitsRange[i]); } mBrightnessMapper.recalculateSplines(mCdsi.isReduceBrightColorsActivated(), adjustedNits); + mPendingUserRbcChange = userInitiated; + sendUpdatePowerState(); } /** @@ -914,7 +925,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call private void reloadReduceBrightColours() { if (mCdsi != null && mCdsi.isReduceBrightColorsActivated()) { - applyReduceBrightColorsSplineAdjustment(); + applyReduceBrightColorsSplineAdjustment(/*userInitiated*/ false); } } @@ -2040,15 +2051,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; diff --git a/services/core/java/com/android/server/display/color/ColorDisplayService.java b/services/core/java/com/android/server/display/color/ColorDisplayService.java index 7fa0b21d166f5..bccd4c42ff125 100644 --- a/services/core/java/com/android/server/display/color/ColorDisplayService.java +++ b/services/core/java/com/android/server/display/color/ColorDisplayService.java @@ -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.