Merge "Persist screen brightness setting through upgrade" am: 2a747f002f am: a333c1fb5e
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1517740 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I762a6db2c61952d2a8f4fbda511bcc81a870fe81
This commit is contained in:
@@ -36,7 +36,7 @@ import java.util.Queue;
|
|||||||
* (new) system for storing the brightness. It has methods to convert between the two and also
|
* (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.
|
* 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_FLOAT = 1;
|
||||||
private static final int MSG_UPDATE_INT = 2;
|
private static final int MSG_UPDATE_INT = 2;
|
||||||
@@ -78,6 +78,26 @@ public class BrightnessSynchronizer{
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mBrightnessSyncObserver = new BrightnessSyncObserver(mHandler);
|
mBrightnessSyncObserver = new BrightnessSyncObserver(mHandler);
|
||||||
mBrightnessSyncObserver.startObserving();
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -166,7 +186,8 @@ public class BrightnessSynchronizer{
|
|||||||
|
|
||||||
private static int getScreenBrightnessInt(Context context) {
|
private static int getScreenBrightnessInt(Context context) {
|
||||||
return Settings.System.getIntForUser(context.getContentResolver(),
|
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;
|
private float mPreferredSettingValue;
|
||||||
|
|||||||
Reference in New Issue
Block a user