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:
Matthew Fritze
2017-07-24 14:58:36 -07:00
parent 2b689e63ca
commit 73056522b3
17 changed files with 87 additions and 66 deletions

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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;
}