diff options
| author | 2020-09-17 15:53:37 +0100 | |
|---|---|---|
| committer | 2020-09-23 13:06:39 +0100 | |
| commit | af6cd6dc30be6ca86bc584a5715dff271c7c671e (patch) | |
| tree | 7beba268fc7bcd1dcc80de8de913878f042bfcfe | |
| parent | f189798351336961bcd67bdb64cd4360d32e37fa (diff) | |
Persist screen brightness setting through upgrade
The screen brightness float setting initially did not exist when upgrading the device software. This change ensures the float and int values are synchronised on the system start-up.
Bug: 167651957
Test: manual - set autobrightness off, upgrade from Q to R, and check brightness value in settings.
Change-Id: I2a3b996c8747e3c5f1d181bbdd438c70bf23d08b
(cherry picked from commit 96f43f21b3a3021762c2d213d8958590127cae36)
| -rw-r--r-- | core/java/com/android/internal/BrightnessSynchronizer.java | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/core/java/com/android/internal/BrightnessSynchronizer.java b/core/java/com/android/internal/BrightnessSynchronizer.java index f08d0ef8c052..6b8cf6361e91 100644 --- a/core/java/com/android/internal/BrightnessSynchronizer.java +++ b/core/java/com/android/internal/BrightnessSynchronizer.java @@ -36,7 +36,7 @@ import java.util.Queue; * (new) system for storing the brightness. It has methods to convert between the two and also * observes for when one of the settings is changed and syncs this with the other. */ -public class BrightnessSynchronizer{ +public class BrightnessSynchronizer { private static final int MSG_UPDATE_FLOAT = 1; private static final int MSG_UPDATE_INT = 2; @@ -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; |