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

Commit b12c7e10 authored by Santos Cordon's avatar Santos Cordon
Browse files

Make VR brightness adjustable again.

After some code adjustment, changes to VR's brightness setting
were not respected.  Add code to listen for the changes and clamping
code to support the min & max values for VR brightness.

Bug: 73090564

Test: while in VR mode, verify that the following command updates
brightness: 'adb shell system put screen_brightness_for_vr
<VALUE>'

Change-Id: I1ce411c5b5fff11c40d1a6ac0b20588b69d2e64e
parent 73abd271
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -174,6 +174,12 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    // The default screen brightness.
    private final int mScreenBrightnessDefault;

    // The minimum allowed brightness while in VR.
    private final int mScreenBrightnessForVrRangeMinimum;

    // The maximum allowed brightness while in VR.
    private final int mScreenBrightnessForVrRangeMaximum;

    // The default screen brightness for VR.
    private final int mScreenBrightnessForVrDefault;

@@ -386,6 +392,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                    com.android.internal.R.integer.config_screenBrightnessSettingMaximum));
        mScreenBrightnessDefault = clampAbsoluteBrightness(resources.getInteger(
                    com.android.internal.R.integer.config_screenBrightnessSettingDefault));

        mScreenBrightnessForVrRangeMinimum = clampAbsoluteBrightness(resources.getInteger(
                    com.android.internal.R.integer.config_screenBrightnessForVrSettingMinimum));
        mScreenBrightnessForVrRangeMaximum = clampAbsoluteBrightness(resources.getInteger(
                    com.android.internal.R.integer.config_screenBrightnessForVrSettingMaximum));
        mScreenBrightnessForVrDefault = clampAbsoluteBrightness(resources.getInteger(
                    com.android.internal.R.integer.config_screenBrightnessForVrSettingDefault));

@@ -621,6 +632,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mContext.getContentResolver().registerContentObserver(
                Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS),
                false /*notifyForDescendants*/, mSettingsObserver, UserHandle.USER_ALL);
        mContext.getContentResolver().registerContentObserver(
                Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_FOR_VR),
                false /*notifyForDescendants*/, mSettingsObserver, UserHandle.USER_ALL);
        mContext.getContentResolver().registerContentObserver(
                Settings.System.getUriFor(Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ),
                false /*notifyForDescendants*/, mSettingsObserver, UserHandle.USER_ALL);
@@ -1146,6 +1160,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mReportedScreenStateToPolicy = state;
    }

    private int clampScreenBrightnessForVr(int value) {
        return MathUtils.constrain(
                value, mScreenBrightnessForVrRangeMinimum, mScreenBrightnessForVrRangeMaximum);
    }

    private int clampScreenBrightness(int value) {
        return MathUtils.constrain(
                value, mScreenBrightnessRangeMinimum, mScreenBrightnessRangeMaximum);
@@ -1458,7 +1477,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        final int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_FOR_VR, mScreenBrightnessForVrDefault,
                UserHandle.USER_CURRENT);
        return clampAbsoluteBrightness(brightness);
        return clampScreenBrightnessForVr(brightness);
    }

    private void putScreenBrightnessSetting(int brightness) {