diff options
| -rw-r--r-- | services/core/java/com/android/server/display/DisplayPowerController.java | 64 |
1 files changed, 46 insertions, 18 deletions
diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index abbe13ac260f..e1a38572c32e 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -125,6 +125,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call private static final int MSG_IGNORE_PROXIMITY = 8; private static final int MSG_STOP = 9; private static final int MSG_UPDATE_BRIGHTNESS = 10; + private static final int MSG_UPDATE_RBC = 11; private static final int PROXIMITY_UNKNOWN = -1; private static final int PROXIMITY_NEGATIVE = 0; @@ -422,13 +423,13 @@ 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. + // Whether reduce bright colors (rbc) has been turned on, or a change in strength has been + // requested. 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; + private boolean mPendingRbcOnOrChanged = false; // Animators. private ObjectAnimator mColorFadeOnAnimator; @@ -564,23 +565,35 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call @Override public void onReduceBrightColorsActivationChanged(boolean activated, boolean userInitiated) { - applyReduceBrightColorsSplineAdjustment(userInitiated); + applyReduceBrightColorsSplineAdjustment( + /* rbcStrengthChanged= */ false, activated); + } @Override public void onReduceBrightColorsStrengthChanged(int strength) { - applyReduceBrightColorsSplineAdjustment(/*userInitiated*/ false); + applyReduceBrightColorsSplineAdjustment( + /* rbcStrengthChanged= */ true, /* justActivated= */ false); } }); if (active) { - applyReduceBrightColorsSplineAdjustment(/*userInitiated*/ false); + applyReduceBrightColorsSplineAdjustment( + /* rbcStrengthChanged= */ false, /* justActivated= */ false); } } else { mCdsi = null; } } - private void applyReduceBrightColorsSplineAdjustment(boolean userInitiated) { + private void applyReduceBrightColorsSplineAdjustment( + boolean rbcStrengthChanged, boolean justActivated) { + final int strengthChanged = rbcStrengthChanged ? 1 : 0; + final int activated = justActivated ? 1 : 0; + mHandler.obtainMessage(MSG_UPDATE_RBC, strengthChanged, activated).sendToTarget(); + sendUpdatePowerState(); + } + + private void handleRbcChanged(boolean strengthChanged, boolean justActivated) { if (mBrightnessMapper == null) { Log.w(TAG, "No brightness mapping available to recalculate splines"); return; @@ -591,8 +604,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call adjustedNits[i] = mCdsi.getReduceBrightColorsAdjustedBrightnessNits(mNitsRange[i]); } mBrightnessMapper.recalculateSplines(mCdsi.isReduceBrightColorsActivated(), adjustedNits); - mPendingUserRbcChange = userInitiated; - sendUpdatePowerState(); + + mPendingRbcOnOrChanged = strengthChanged || justActivated; + + // Reset model if strength changed OR rbc is turned off + if (strengthChanged || !justActivated && mAutomaticBrightnessController != null) { + mAutomaticBrightnessController.resetShortTermModel(); + } } /** @@ -926,7 +944,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call private void reloadReduceBrightColours() { if (mCdsi != null && mCdsi.isReduceBrightColorsActivated()) { - applyReduceBrightColorsSplineAdjustment(/*userInitiated*/ false); + applyReduceBrightColorsSplineAdjustment( + /* rbcStrengthChanged= */ false, /* justActivated= */ false); } } @@ -2062,21 +2081,24 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call return true; } + // We want to return true if the user has set the screen brightness. + // If they have just turned RBC on (and therefore added that interaction to the curve), + // or changed the brightness another way, then we should return true. private boolean updateUserSetScreenBrightness() { - final boolean brightnessSplineChanged = mPendingUserRbcChange; - if (mPendingUserRbcChange && !Float.isNaN(mCurrentScreenBrightnessSetting)) { + final boolean treatAsIfUserChanged = mPendingRbcOnOrChanged; + if (treatAsIfUserChanged && !Float.isNaN(mCurrentScreenBrightnessSetting)) { mLastUserSetScreenBrightness = mCurrentScreenBrightnessSetting; } - mPendingUserRbcChange = false; + mPendingRbcOnOrChanged = false; if ((Float.isNaN(mPendingScreenBrightnessSetting) || mPendingScreenBrightnessSetting < 0.0f)) { - return brightnessSplineChanged; + return treatAsIfUserChanged; } if (mCurrentScreenBrightnessSetting == mPendingScreenBrightnessSetting) { mPendingScreenBrightnessSetting = PowerManager.BRIGHTNESS_INVALID_FLOAT; mTemporaryScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; - return brightnessSplineChanged; + return treatAsIfUserChanged; } setCurrentScreenBrightness(mPendingScreenBrightnessSetting); mLastUserSetScreenBrightness = mPendingScreenBrightnessSetting; @@ -2406,6 +2428,12 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } handleSettingsChange(false /*userSwitch*/); break; + + case MSG_UPDATE_RBC: + final int strengthChanged = msg.arg1; + final int justActivated = msg.arg2; + handleRbcChanged(strengthChanged == 1, justActivated == 1); + break; } } } |