From 3dfe3448c0f4ef48dfeab1c8178e4a0736c10f9b Mon Sep 17 00:00:00 2001 From: Fiona Campbell Date: Tue, 26 May 2020 13:08:53 +0100 Subject: [PATCH] Remove precision loss on brightness slider. Replacing this check with an equivalent float one allows all backlight values to be used. Previously, each slider change was being ignored if the int values were equivalent. Int values have a range of 1 to 255, however, the hardware can have more precision than this, so its more precise to do the comparison using floats, not ints. Bug: 157454239 Test: Manual, `ROBOTEST_FILTER=BrightnessLevelPreferenceControllerTest m -j RunSettingsRoboTests`, `cat /sys/class/backlight/panel0-backlight/brightness`. Change-Id: I15eab92b465652fc0024ed92045cc731492d88ba --- .../systemui/settings/BrightnessController.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java b/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java index 821144a7f12d8..71e788375d5e6 100644 --- a/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java +++ b/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java @@ -443,14 +443,10 @@ public class BrightnessController implements ToggleSlider.Listener { max = mMaximumBacklight; } // convertGammaToLinearFloat returns 0-1 - if (BrightnessSynchronizer.brightnessFloatToInt(mContext, brightnessValue) - == BrightnessSynchronizer.brightnessFloatToInt(mContext, + if (BrightnessSynchronizer.floatEquals(brightnessValue, convertGammaToLinearFloat(mControl.getValue(), min, max))) { - // If we have more resolution on the slider than we do in the actual setting, then - // multiple slider positions will map to the same setting value. Thus, if we see a - // setting value here that maps to the current slider position, we don't bother to - // calculate the new slider position since it may differ and look like a brightness - // change to the user even though it isn't one. + // If the value in the slider is equal to the value on the current brightness + // then the slider does not need to animate, since the brightness will not change. return; } // Returns GAMMA_SPACE_MIN - GAMMA_SPACE_MAX