Simplify InlineSwitchPayloads and generalize get/set method
InlineSwitchPayload now assumes that all switches will be stored as 1 or 0, which simplifies the code. Moves Availability into ResultPayload, so that custom payloads can be created to set/get values which are more complicated than stotring ints (like bluetooth or DnD), and give more expressive reasons when unavailable. Bug: 62022517 Test: make RunSettingsRoboTests Change-Id: I87e6fc041bfd398e7daf6e6e479d502930d36f0f
This commit is contained in:
@@ -19,30 +19,93 @@ package com.android.settings.search;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
|
||||
/**
|
||||
* Abstract Payload for inline settings results.
|
||||
*/
|
||||
public abstract class InlinePayload extends ResultPayload {
|
||||
|
||||
public static final int FALSE = 0;
|
||||
public static final int TRUE = 1;
|
||||
|
||||
/**
|
||||
* Defines the URI to access and store the Setting the inline result represents
|
||||
* Defines the key to access and store the Setting the inline result represents.
|
||||
*/
|
||||
public String settingsUri;
|
||||
@VisibleForTesting
|
||||
final String mSettingKey;
|
||||
|
||||
/**
|
||||
* The UI type for the inline result.
|
||||
*/
|
||||
@PayloadType public int inlineType;
|
||||
@PayloadType final int mInlineType;
|
||||
|
||||
/**
|
||||
* Defines where the Setting is stored.
|
||||
*/
|
||||
@SettingsSource public int settingSource;
|
||||
@SettingsSource final int mSettingSource;
|
||||
|
||||
public InlinePayload(String uri, @PayloadType int type, @SettingsSource int source,
|
||||
Intent intent) {
|
||||
/**
|
||||
* True when the setting is available for the device.
|
||||
*/
|
||||
final boolean mIsDeviceSupported;
|
||||
|
||||
/**
|
||||
* @param key uniquely identifies the stored setting.
|
||||
* @param payloadType of the setting being stored.
|
||||
* @param source of the setting. Used to determine where to get and set the setting.
|
||||
* @param intent to the setting page.
|
||||
* @param isDeviceSupported is true when the setting is valid for the given device.
|
||||
*/
|
||||
public InlinePayload(String key, @PayloadType int payloadType, @SettingsSource int source,
|
||||
Intent intent, boolean isDeviceSupported) {
|
||||
super(intent);
|
||||
settingsUri = uri;
|
||||
inlineType = type;
|
||||
settingSource = source;
|
||||
mSettingKey = key;
|
||||
mInlineType = payloadType;
|
||||
mSettingSource = source;
|
||||
mIsDeviceSupported = isDeviceSupported;
|
||||
}
|
||||
}
|
||||
|
||||
InlinePayload(Parcel parcel) {
|
||||
super((Intent) parcel.readParcelable(Intent.class.getClassLoader()));
|
||||
mSettingKey = parcel.readString();
|
||||
mInlineType = parcel.readInt();
|
||||
mSettingSource = parcel.readInt();
|
||||
mIsDeviceSupported = parcel.readInt() == TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeString(mSettingKey);
|
||||
dest.writeInt(mInlineType);
|
||||
dest.writeInt(mSettingSource);
|
||||
dest.writeInt(mIsDeviceSupported ? TRUE : FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns the status of the underlying setting. See {@link ResultPayload.Availability} for
|
||||
* possible values.
|
||||
*/
|
||||
@Availability public int getAvailability() {
|
||||
if (mIsDeviceSupported) {
|
||||
return Availability.AVAILABLE;
|
||||
}
|
||||
return Availability.DISABLED_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns the current value of the setting.
|
||||
*/
|
||||
public abstract int getValue(Context context);
|
||||
|
||||
/**
|
||||
* Attempts to set the setting value.
|
||||
*
|
||||
* @param newValue is the requested new value for the setting.
|
||||
* @returns true when the setting was changed, and false otherwise.
|
||||
*/
|
||||
public abstract boolean setValue(Context context, int newValue);
|
||||
}
|
||||
Reference in New Issue
Block a user