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

Commit d4e34a26 authored by Oleg Petsjonkin's avatar Oleg Petsjonkin Committed by Oleg Petšjonkin
Browse files

Brightness key control: apply linear increment instead of gamma

Test: manual testing
Bug: b/261699041
Change-Id: Idb7d9d48ebbc02ca3a499b381b81c6633714ea4f
parent 75aabd93
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -275,7 +275,6 @@ public class AccessibilityMenuService extends AccessibilityService
                info.brightnessMinimum,
                info.brightnessMaximum
        );
        mDisplayManager.setTemporaryBrightness(getDisplayId(), brightness);
        mDisplayManager.setBrightness(getDisplayId(), brightness);
        mA11yMenuLayout.showSnackbar(
                getString(R.string.brightness_percentage_label,
+16 −11
Original line number Diff line number Diff line
@@ -161,6 +161,7 @@ import android.service.vr.IPersistentVrStateCallbacks;
import android.speech.RecognizerIntent;
import android.telecom.TelecomManager;
import android.util.Log;
import android.util.MathUtils;
import android.util.MutableBoolean;
import android.util.PrintWriterPrinter;
import android.util.Slog;
@@ -210,6 +211,7 @@ import com.android.server.GestureLauncherService;
import com.android.server.LocalServices;
import com.android.server.SystemServiceManager;
import com.android.server.UiThread;
import com.android.server.display.BrightnessUtils;
import com.android.server.input.InputManagerInternal;
import com.android.server.inputmethod.InputMethodManagerInternal;
import com.android.server.policy.KeyCombinationManager.TwoKeysCombinationRule;
@@ -3081,19 +3083,22 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
                                UserHandle.USER_CURRENT_OR_SELF);
                    }
                    float min = mPowerManager.getBrightnessConstraint(
                            PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM);
                    float max = mPowerManager.getBrightnessConstraint(
                            PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MAXIMUM);
                    float step = (max - min) / BRIGHTNESS_STEPS * direction;
                    int screenDisplayId = displayId < 0 ? DEFAULT_DISPLAY : displayId;
                    float brightness = mDisplayManager.getBrightness(screenDisplayId);
                    brightness += step;
                    // Make sure we don't go beyond the limits.
                    brightness = Math.min(max, brightness);
                    brightness = Math.max(min, brightness);

                    mDisplayManager.setBrightness(screenDisplayId, brightness);
                    float linearBrightness = mDisplayManager.getBrightness(screenDisplayId);

                    float gammaBrightness = BrightnessUtils.convertLinearToGamma(linearBrightness);
                    float adjustedGammaBrightness =
                            gammaBrightness + 1f / BRIGHTNESS_STEPS * direction;

                    float adjustedLinearBrightness = BrightnessUtils.convertGammaToLinear(
                            adjustedGammaBrightness);

                    adjustedLinearBrightness = MathUtils.constrain(adjustedLinearBrightness, 0f,
                            1f);

                    mDisplayManager.setBrightness(screenDisplayId, adjustedLinearBrightness);

                    startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
                            UserHandle.CURRENT_OR_SELF);
                }