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. Manual merge for: ag/2588219/ Change-Id: I3b8eea4f82764852cea642db4455ba57f10a7d37 Fixes: 63955012 Test: robotests
This commit is contained in:
@@ -16,8 +16,8 @@ public class InlineListPayload extends InlinePayload {
|
||||
private int mNumOptions;
|
||||
|
||||
public InlineListPayload(String key, @PayloadType int payloadType, Intent intent,
|
||||
boolean isDeviceSupported, int numOptions) {
|
||||
super(key, payloadType, intent, isDeviceSupported);
|
||||
boolean isDeviceSupported, int numOptions, int defaultValue) {
|
||||
super(key, payloadType, intent, isDeviceSupported, defaultValue);
|
||||
mNumOptions = numOptions;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,11 @@ public abstract class InlinePayload extends ResultPayload {
|
||||
*/
|
||||
final boolean mIsDeviceSupported;
|
||||
|
||||
/**
|
||||
* The default value for the setting.
|
||||
*/
|
||||
final int mDefaultvalue;
|
||||
|
||||
/**
|
||||
* @param key uniquely identifies the stored setting.
|
||||
* @param source of the setting. Used to determine where to get and set the setting.
|
||||
@@ -55,18 +60,20 @@ public abstract class InlinePayload extends ResultPayload {
|
||||
* @param isDeviceSupported is true when the setting is valid for the given device.
|
||||
*/
|
||||
public InlinePayload(String key, @SettingsSource int source, Intent intent,
|
||||
boolean isDeviceSupported) {
|
||||
boolean isDeviceSupported, int defaultValue) {
|
||||
super(intent);
|
||||
mSettingKey = key;
|
||||
mSettingSource = source;
|
||||
mIsDeviceSupported = isDeviceSupported;
|
||||
mDefaultvalue = defaultValue;
|
||||
}
|
||||
|
||||
InlinePayload(Parcel parcel) {
|
||||
super((Intent) parcel.readParcelable(Intent.class.getClassLoader()));
|
||||
super(parcel.readParcelable(Intent.class.getClassLoader()));
|
||||
mSettingKey = parcel.readString();
|
||||
mSettingSource = parcel.readInt();
|
||||
mIsDeviceSupported = parcel.readInt() == TRUE;
|
||||
mDefaultvalue = parcel.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,6 +82,7 @@ public abstract class InlinePayload extends ResultPayload {
|
||||
dest.writeString(mSettingKey);
|
||||
dest.writeInt(mSettingSource);
|
||||
dest.writeInt(mIsDeviceSupported ? TRUE : FALSE);
|
||||
dest.writeInt(mDefaultvalue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -108,24 +116,19 @@ public abstract class InlinePayload extends ResultPayload {
|
||||
switch(mSettingSource) {
|
||||
case SettingsSource.SECURE:
|
||||
settingsValue = Settings.Secure.getInt(context.getContentResolver(),
|
||||
mSettingKey, -1);
|
||||
mSettingKey, mDefaultvalue);
|
||||
break;
|
||||
case SettingsSource.SYSTEM:
|
||||
settingsValue = Settings.System.getInt(context.getContentResolver(),
|
||||
mSettingKey, -1);
|
||||
mSettingKey, mDefaultvalue);
|
||||
break;
|
||||
|
||||
case SettingsSource.GLOBAL:
|
||||
settingsValue = Settings.Global.getInt(context.getContentResolver(),
|
||||
mSettingKey, -1);
|
||||
mSettingKey, mDefaultvalue);
|
||||
break;
|
||||
}
|
||||
|
||||
if (settingsValue == -1) {
|
||||
throw new IllegalStateException("Unable to find setting from uri: "
|
||||
+ mSettingKey.toString());
|
||||
}
|
||||
|
||||
return standardizeInput(settingsValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,8 +45,8 @@ public class InlineSwitchPayload extends InlinePayload {
|
||||
* @param isDeviceSupported is true when the setting is valid for the given device.
|
||||
*/
|
||||
public InlineSwitchPayload(String key, @SettingsSource int source,
|
||||
int onValue, Intent intent, boolean isDeviceSupported) {
|
||||
super(key, source, intent, isDeviceSupported);
|
||||
int onValue, Intent intent, boolean isDeviceSupported, int defaultValue) {
|
||||
super(key, source, intent, isDeviceSupported, defaultValue);
|
||||
// If on is stored as TRUE then the switch is standard.
|
||||
mIsStandard = onValue == TRUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user