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
// 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;

View File

@@ -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.