Merge "Fixes NPE in Screen attention setting" into sc-dev
This commit is contained in:
@@ -73,7 +73,6 @@ public class AdaptiveSleepPreferenceController {
|
|||||||
* Adds the controlled preference to the provided preference screen.
|
* Adds the controlled preference to the provided preference screen.
|
||||||
*/
|
*/
|
||||||
public void addToScreen(PreferenceScreen screen) {
|
public void addToScreen(PreferenceScreen screen) {
|
||||||
initializePreference();
|
|
||||||
updatePreference();
|
updatePreference();
|
||||||
screen.addPreference(mPreference);
|
screen.addPreference(mPreference);
|
||||||
}
|
}
|
||||||
@@ -82,6 +81,7 @@ public class AdaptiveSleepPreferenceController {
|
|||||||
* Updates the appearance of the preference.
|
* Updates the appearance of the preference.
|
||||||
*/
|
*/
|
||||||
public void updatePreference() {
|
public void updatePreference() {
|
||||||
|
initializePreference();
|
||||||
final EnforcedAdmin enforcedAdmin = mRestrictionUtils.checkIfRestrictionEnforced(mContext,
|
final EnforcedAdmin enforcedAdmin = mRestrictionUtils.checkIfRestrictionEnforced(mContext,
|
||||||
UserManager.DISALLOW_CONFIG_SCREEN_TIMEOUT);
|
UserManager.DISALLOW_CONFIG_SCREEN_TIMEOUT);
|
||||||
if (enforcedAdmin != null) {
|
if (enforcedAdmin != null) {
|
||||||
@@ -93,6 +93,7 @@ public class AdaptiveSleepPreferenceController {
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void initializePreference() {
|
void initializePreference() {
|
||||||
|
if (mPreference == null) {
|
||||||
mPreference = new RestrictedSwitchPreference(mContext);
|
mPreference = new RestrictedSwitchPreference(mContext);
|
||||||
mPreference.setTitle(R.string.adaptive_sleep_title);
|
mPreference.setTitle(R.string.adaptive_sleep_title);
|
||||||
mPreference.setSummary(R.string.adaptive_sleep_description);
|
mPreference.setSummary(R.string.adaptive_sleep_description);
|
||||||
@@ -100,13 +101,15 @@ public class AdaptiveSleepPreferenceController {
|
|||||||
mPreference.setKey(PREFERENCE_KEY);
|
mPreference.setKey(PREFERENCE_KEY);
|
||||||
mPreference.setOnPreferenceChangeListener((preference, value) -> {
|
mPreference.setOnPreferenceChangeListener((preference, value) -> {
|
||||||
final boolean isChecked = (Boolean) value;
|
final boolean isChecked = (Boolean) value;
|
||||||
mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_SCREEN_ATTENTION_CHANGED,
|
mMetricsFeatureProvider.action(mContext,
|
||||||
|
SettingsEnums.ACTION_SCREEN_ATTENTION_CHANGED,
|
||||||
isChecked);
|
isChecked);
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.ADAPTIVE_SLEEP, isChecked ? 1 : DEFAULT_VALUE);
|
Settings.Secure.ADAPTIVE_SLEEP, isChecked ? 1 : DEFAULT_VALUE);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean isChecked() {
|
boolean isChecked() {
|
||||||
|
Reference in New Issue
Block a user