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

This commit is contained in:
Fiona Campbell
2021-07-06 12:24:32 +00:00
committed by Android (Google) Code Review
2 changed files with 32 additions and 14 deletions

View File

@@ -390,7 +390,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
// The last brightness that was set by the user and not temporary. Set to // 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. // 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 // 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 // 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. // PowerManager.BRIGHTNESS_INVALID_FLOAT when there's no temporary adjustment set.
private float mTemporaryAutoBrightnessAdjustment; 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. // Animators.
private ObjectAnimator mColorFadeOnAnimator; private ObjectAnimator mColorFadeOnAnimator;
private ObjectAnimator mColorFadeOffAnimator; private ObjectAnimator mColorFadeOffAnimator;
@@ -552,24 +560,25 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
mCdsi = LocalServices.getService(ColorDisplayServiceInternal.class); mCdsi = LocalServices.getService(ColorDisplayServiceInternal.class);
boolean active = mCdsi.setReduceBrightColorsListener(new ReduceBrightColorsListener() { boolean active = mCdsi.setReduceBrightColorsListener(new ReduceBrightColorsListener() {
@Override @Override
public void onReduceBrightColorsActivationChanged(boolean activated) { public void onReduceBrightColorsActivationChanged(boolean activated,
applyReduceBrightColorsSplineAdjustment(); boolean userInitiated) {
applyReduceBrightColorsSplineAdjustment(userInitiated);
} }
@Override @Override
public void onReduceBrightColorsStrengthChanged(int strength) { public void onReduceBrightColorsStrengthChanged(int strength) {
applyReduceBrightColorsSplineAdjustment(); applyReduceBrightColorsSplineAdjustment(/*userInitiated*/ false);
} }
}); });
if (active) { if (active) {
applyReduceBrightColorsSplineAdjustment(); applyReduceBrightColorsSplineAdjustment(/*userInitiated*/ false);
} }
} else { } else {
mCdsi = null; mCdsi = null;
} }
} }
private void applyReduceBrightColorsSplineAdjustment() { private void applyReduceBrightColorsSplineAdjustment(boolean userInitiated) {
if (mBrightnessMapper == null) { if (mBrightnessMapper == null) {
Log.w(TAG, "No brightness mapping available to recalculate splines"); Log.w(TAG, "No brightness mapping available to recalculate splines");
return; return;
@@ -580,6 +589,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
adjustedNits[i] = mCdsi.getReduceBrightColorsAdjustedBrightnessNits(mNitsRange[i]); adjustedNits[i] = mCdsi.getReduceBrightColorsAdjustedBrightnessNits(mNitsRange[i]);
} }
mBrightnessMapper.recalculateSplines(mCdsi.isReduceBrightColorsActivated(), adjustedNits); mBrightnessMapper.recalculateSplines(mCdsi.isReduceBrightColorsActivated(), adjustedNits);
mPendingUserRbcChange = userInitiated;
sendUpdatePowerState();
} }
/** /**
@@ -911,7 +922,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
private void reloadReduceBrightColours() { private void reloadReduceBrightColours() {
if (mCdsi != null && mCdsi.isReduceBrightColorsActivated()) { if (mCdsi != null && mCdsi.isReduceBrightColorsActivated()) {
applyReduceBrightColorsSplineAdjustment(); applyReduceBrightColorsSplineAdjustment(/*userInitiated*/ false);
} }
} }
@@ -2039,15 +2050,21 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
} }
private boolean updateUserSetScreenBrightness() { private boolean updateUserSetScreenBrightness() {
final boolean brightnessSplineChanged = mPendingUserRbcChange;
if (mPendingUserRbcChange && !Float.isNaN(mCurrentScreenBrightnessSetting)) {
mLastUserSetScreenBrightness = mCurrentScreenBrightnessSetting;
}
mPendingUserRbcChange = false;
if ((Float.isNaN(mPendingScreenBrightnessSetting) if ((Float.isNaN(mPendingScreenBrightnessSetting)
|| mPendingScreenBrightnessSetting < 0.0f)) { || mPendingScreenBrightnessSetting < 0.0f)) {
return false; return brightnessSplineChanged;
} }
if (BrightnessSynchronizer.floatEquals( if (BrightnessSynchronizer.floatEquals(
mCurrentScreenBrightnessSetting, mPendingScreenBrightnessSetting)) { mCurrentScreenBrightnessSetting, mPendingScreenBrightnessSetting)) {
mPendingScreenBrightnessSetting = PowerManager.BRIGHTNESS_INVALID_FLOAT; mPendingScreenBrightnessSetting = PowerManager.BRIGHTNESS_INVALID_FLOAT;
mTemporaryScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; mTemporaryScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
return false; return brightnessSplineChanged;
} }
setCurrentScreenBrightness(mPendingScreenBrightnessSetting); setCurrentScreenBrightness(mPendingScreenBrightnessSetting);
mLastUserSetScreenBrightness = mPendingScreenBrightnessSetting; mLastUserSetScreenBrightness = mPendingScreenBrightnessSetting;

View File

@@ -355,7 +355,7 @@ public final class ColorDisplayService extends SystemService {
updateDisplayWhiteBalanceStatus(); updateDisplayWhiteBalanceStatus();
break; break;
case Secure.REDUCE_BRIGHT_COLORS_ACTIVATED: case Secure.REDUCE_BRIGHT_COLORS_ACTIVATED:
onReduceBrightColorsActivationChanged(); onReduceBrightColorsActivationChanged(/*userInitiated*/ true);
mHandler.sendEmptyMessage(MSG_APPLY_REDUCE_BRIGHT_COLORS); mHandler.sendEmptyMessage(MSG_APPLY_REDUCE_BRIGHT_COLORS);
break; break;
case Secure.REDUCE_BRIGHT_COLORS_LEVEL: case Secure.REDUCE_BRIGHT_COLORS_LEVEL:
@@ -437,7 +437,7 @@ public final class ColorDisplayService extends SystemService {
onReduceBrightColorsStrengthLevelChanged(); onReduceBrightColorsStrengthLevelChanged();
final boolean reset = resetReduceBrightColors(); final boolean reset = resetReduceBrightColors();
if (!reset) { if (!reset) {
onReduceBrightColorsActivationChanged(); onReduceBrightColorsActivationChanged(/*userInitiated*/ false);
mHandler.sendEmptyMessage(MSG_APPLY_REDUCE_BRIGHT_COLORS); mHandler.sendEmptyMessage(MSG_APPLY_REDUCE_BRIGHT_COLORS);
} }
} }
@@ -614,7 +614,7 @@ public final class ColorDisplayService extends SystemService {
isAccessiblityInversionEnabled() ? MATRIX_INVERT_COLOR : null); isAccessiblityInversionEnabled() ? MATRIX_INVERT_COLOR : null);
} }
private void onReduceBrightColorsActivationChanged() { private void onReduceBrightColorsActivationChanged(boolean userInitiated) {
if (mCurrentUser == UserHandle.USER_NULL) { if (mCurrentUser == UserHandle.USER_NULL) {
return; return;
} }
@@ -622,7 +622,8 @@ public final class ColorDisplayService extends SystemService {
Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0, mCurrentUser) == 1; Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0, mCurrentUser) == 1;
mReduceBrightColorsTintController.setActivated(activated); mReduceBrightColorsTintController.setActivated(activated);
if (mReduceBrightColorsListener != null) { 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. * 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. * Notify that the reduce bright colors strength has changed.