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

Commit 3dcd76cf authored by Fiona Campbell's avatar Fiona Campbell
Browse files

Don't pass non slider adj. as user interactions

This cl stops passing RBC on, RBC off and RBC intensity changes as
slider interactions. Normal slider interactions will be passed as a user
interaction, regardless of whether RBC is on or not. Also, ensure the
short term model (STM) is correctly reset when necessary.

                    | Old Scenario:     | New Scenario:
RBC turned on       | user initiated    | non user
                    | keep STM          | reset STM

RBC turned off      | non user          | non user
                    | reset STM         | reset STM

Change of intensity | user initiated    | non user
                    | reset STM         | reset STM

Slider interaction  | user initiated    | user initiated
 whilst RBC is on   | keep STM          | keep STM

Bug: 204298104
Bug: 202262784
Test: adb shell dumpsys display | grep -A50 mEvents
Test: manual logs and check interactions

Change-Id: I135623dc9ccca11817d5dd07d9b333b94aac30f1
parent 0effa340
Loading
Loading
Loading
Loading
+17 −40
Original line number Diff line number Diff line
@@ -446,14 +446,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    // PowerManager.BRIGHTNESS_INVALID_FLOAT when there's no temporary adjustment set.
    private float mTemporaryAutoBrightnessAdjustment;

    // 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 mPendingRbcOnOrChanged = false;

    // Animators.
    private ObjectAnimator mColorFadeOnAnimator;
    private ObjectAnimator mColorFadeOffAnimator;
@@ -572,20 +564,17 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                @Override
                public void onReduceBrightColorsActivationChanged(boolean activated,
                        boolean userInitiated) {
                    applyReduceBrightColorsSplineAdjustment(
                            /* rbcStrengthChanged= */ false, activated);
                    applyReduceBrightColorsSplineAdjustment();

                }

                @Override
                public void onReduceBrightColorsStrengthChanged(int strength) {
                    applyReduceBrightColorsSplineAdjustment(
                            /* rbcStrengthChanged= */ true, /* justActivated= */ false);
                    applyReduceBrightColorsSplineAdjustment();
                }
            });
            if (active) {
                applyReduceBrightColorsSplineAdjustment(
                        /* rbcStrengthChanged= */ false,  /* justActivated= */ false);
                applyReduceBrightColorsSplineAdjustment();
            }
        } else {
            mCdsi = null;
@@ -615,15 +604,12 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call

    }

    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();
    private void applyReduceBrightColorsSplineAdjustment() {
        mHandler.obtainMessage(MSG_UPDATE_RBC).sendToTarget();
        sendUpdatePowerState();
    }

    private void handleRbcChanged(boolean strengthChanged, boolean justActivated) {
    private void handleRbcChanged() {
        if (mAutomaticBrightnessController == null) {
            return;
        }
@@ -642,13 +628,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mAutomaticBrightnessController.recalculateSplines(mCdsi.isReduceBrightColorsActivated(),
                adjustedNits);

        mPendingRbcOnOrChanged = strengthChanged || justActivated;

        // Reset model if strength changed OR rbc is turned off
        if ((strengthChanged || !justActivated) && mAutomaticBrightnessController != null) {
        // If rbc is turned on, off or there is a change in strength, we want to reset the short
        // term model. Since the nits range at which brightness now operates has changed due to
        // RBC/strength change, any short term model based on the previous range should be
        // invalidated.
        mAutomaticBrightnessController.resetShortTermModel();
    }
    }

    /**
     * Returns true if the proximity sensor screen-off function is available.
@@ -1019,8 +1005,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call

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

@@ -2285,23 +2270,17 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    }

    // 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.
    // RBC on, off, and intensity changes will return false.
    // Slider interactions whilst in RBC will return true, just as when in non-rbc.
    private boolean updateUserSetScreenBrightness() {
        final boolean treatAsIfUserChanged = mPendingRbcOnOrChanged;
        if (treatAsIfUserChanged && !Float.isNaN(mCurrentScreenBrightnessSetting)) {
            mLastUserSetScreenBrightness = mCurrentScreenBrightnessSetting;
        }
        mPendingRbcOnOrChanged = false;

        if ((Float.isNaN(mPendingScreenBrightnessSetting)
                || mPendingScreenBrightnessSetting < 0.0f)) {
            return treatAsIfUserChanged;
            return false;
        }
        if (mCurrentScreenBrightnessSetting == mPendingScreenBrightnessSetting) {
            mPendingScreenBrightnessSetting = PowerManager.BRIGHTNESS_INVALID_FLOAT;
            mTemporaryScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
            return treatAsIfUserChanged;
            return false;
        }
        setCurrentScreenBrightness(mPendingScreenBrightnessSetting);
        mLastUserSetScreenBrightness = mPendingScreenBrightnessSetting;
@@ -2691,9 +2670,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                    break;

                case MSG_UPDATE_RBC:
                    final int strengthChanged = msg.arg1;
                    final int justActivated = msg.arg2;
                    handleRbcChanged(strengthChanged == 1, justActivated == 1);
                    handleRbcChanged();
                    break;

                case MSG_BRIGHTNESS_RAMP_DONE: