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

Commit 8f0fb929 authored by Daniel Solomon's avatar Daniel Solomon
Browse files

Cancel brightness slider animation before checking its value

One of the checks that occurs before initiating a brightness slider
animation is a comparison of the current slider value versus the current
display brightness value.

There is a race condition wherein,
1. There's an outstanding animation that is about to move the slider to
a stale brightness value, but hasn't started yet.
2. A new animation to the current display brightness value is being
considered. During this time, the slider value (which hasn't been moved
yet by the outstanding animation) is being compared against the current
display brightness value. They match, and a new animation isn't started.
3. The animation from step #1 proceeds, and moves the slider to a
location that no longer matches the current display brightness value.

To fix this, we first cancel any outstanding slider animation, and only
then compare the slider's position to display brightness.

Bug: 202873446
Bug: 214849040
Test: Manual, sliding the brightness slider around and ensuring it stays
    in place after the user lets go of it.
Test: atest QuickQSBrightnessControllerTest BrightnessSliderTest
Change-Id: I036638561bef6c5f10a11f5e50957c39cd792705
parent 2f53619f
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -398,6 +398,11 @@ public class BrightnessController implements ToggleSlider.Listener, MirroredBrig
            min = mBrightnessMin;
            max = mBrightnessMax;
        }

        // Ensure the slider is in a fixed position first, then check if we should animate.
        if (mSliderAnimator != null && mSliderAnimator.isStarted()) {
            mSliderAnimator.cancel();
        }
        // convertGammaToLinearFloat returns 0-1
        if (BrightnessSynchronizer.floatEquals(brightnessValue,
                convertGammaToLinearFloat(mControl.getValue(), min, max))) {
@@ -420,9 +425,6 @@ public class BrightnessController implements ToggleSlider.Listener, MirroredBrig
            mControl.setValue(target);
            mControlValueInitialized = true;
        }
        if (mSliderAnimator != null && mSliderAnimator.isStarted()) {
            mSliderAnimator.cancel();
        }
        mSliderAnimator = ValueAnimator.ofInt(mControl.getValue(), target);
        mSliderAnimator.addUpdateListener((ValueAnimator animation) -> {
            mExternalChange = true;