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

Commit 1cce0c2f authored by Fiona Campbell's avatar Fiona Campbell Committed by Android (Google) Code Review
Browse files

Merge "Persist screen brightness setting through upgrade"

parents 44a9520d af6cd6dc
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -78,6 +78,26 @@ public class BrightnessSynchronizer{
        mContext = context;
        mBrightnessSyncObserver = new BrightnessSyncObserver(mHandler);
        mBrightnessSyncObserver.startObserving();

        // It is possible for the system to start up with the int and float values not
        // synchronized. So we force an update to the int value, since float is the source
        // of truth. Fallback to int value, if float is invalid. If both are invalid, use default
        // float value from config.
        final float currentFloatBrightness = getScreenBrightnessFloat(context);
        final int currentIntBrightness = getScreenBrightnessInt(context);

        if (!Float.isNaN(currentFloatBrightness)) {
            updateBrightnessIntFromFloat(currentFloatBrightness);
        } else if (currentIntBrightness != -1) {
            updateBrightnessFloatFromInt(currentIntBrightness);
        } else {
            final float defaultBrightness = mContext.getResources().getFloat(
                    com.android.internal.R.dimen.config_screenBrightnessSettingDefaultFloat);
            Settings.System.putFloatForUser(mContext.getContentResolver(),
                    Settings.System.SCREEN_BRIGHTNESS_FLOAT, defaultBrightness,
                    UserHandle.USER_CURRENT);

        }
    }

    /**
@@ -132,7 +152,8 @@ public class BrightnessSynchronizer{

    private static int getScreenBrightnessInt(Context context) {
        return Settings.System.getIntForUser(context.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS, 0, UserHandle.USER_CURRENT);
                Settings.System.SCREEN_BRIGHTNESS, PowerManager.BRIGHTNESS_INVALID,
                UserHandle.USER_CURRENT);
    }

    private float mPreferredSettingValue;