Merge "Brightness key control: apply linear increment instead of gamma" into udc-dev

This commit is contained in:
Oleg Petšjonkin
2023-02-23 13:51:39 +00:00
committed by Android (Google) Code Review
2 changed files with 16 additions and 12 deletions

View File

@@ -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,

View File

@@ -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);
}