Add default value to inline payloads
If we try to set an inline result when it has not yet been accessed in settings, nothing is read from Settings. Thus, include a default value for a fallback. Change-Id: I8a593d9ff3308b2d0cd5bc65658d160abf55b07e Fixes: 63955012 Test: robotests
This commit is contained in:
@@ -85,6 +85,7 @@ public class AmbientDisplayAlwaysOnPreferenceController extends PreferenceContro
|
||||
mContext.getString(R.string.ambient_display_screen_title));
|
||||
|
||||
return new InlineSwitchPayload(Settings.Secure.DOZE_ALWAYS_ON,
|
||||
ResultPayload.SettingsSource.SECURE, ON, intent, isAvailable());
|
||||
ResultPayload.SettingsSource.SECURE, ON /* onValue */, intent, isAvailable(),
|
||||
ON /* defaultValue */);
|
||||
}
|
||||
}
|
||||
|
@@ -36,6 +36,9 @@ public class AutoBrightnessPreferenceController extends PreferenceController imp
|
||||
|
||||
private final String mAutoBrightnessKey;
|
||||
|
||||
private final String SYSTEM_KEY = SCREEN_BRIGHTNESS_MODE;
|
||||
private final int DEFAULT_VALUE = SCREEN_BRIGHTNESS_MODE_MANUAL;
|
||||
|
||||
public AutoBrightnessPreferenceController(Context context, String key) {
|
||||
super(context);
|
||||
mAutoBrightnessKey = key;
|
||||
@@ -55,15 +58,15 @@ public class AutoBrightnessPreferenceController extends PreferenceController imp
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
int brightnessMode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL);
|
||||
((SwitchPreference) preference).setChecked(brightnessMode != SCREEN_BRIGHTNESS_MODE_MANUAL);
|
||||
SYSTEM_KEY, DEFAULT_VALUE);
|
||||
((SwitchPreference) preference).setChecked(brightnessMode != DEFAULT_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
boolean auto = (Boolean) newValue;
|
||||
Settings.System.putInt(mContext.getContentResolver(), SCREEN_BRIGHTNESS_MODE,
|
||||
auto ? SCREEN_BRIGHTNESS_MODE_AUTOMATIC : SCREEN_BRIGHTNESS_MODE_MANUAL);
|
||||
Settings.System.putInt(mContext.getContentResolver(), SYSTEM_KEY,
|
||||
auto ? SCREEN_BRIGHTNESS_MODE_AUTOMATIC : DEFAULT_VALUE);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -73,8 +76,8 @@ public class AutoBrightnessPreferenceController extends PreferenceController imp
|
||||
DisplaySettings.class.getName(), mAutoBrightnessKey,
|
||||
mContext.getString(R.string.display_settings));
|
||||
|
||||
return new InlineSwitchPayload(SCREEN_BRIGHTNESS_MODE,
|
||||
return new InlineSwitchPayload(SYSTEM_KEY,
|
||||
ResultPayload.SettingsSource.SYSTEM, SCREEN_BRIGHTNESS_MODE_AUTOMATIC, intent,
|
||||
isAvailable());
|
||||
isAvailable(), DEFAULT_VALUE);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user