Remove "platform_slice" attribute from Settings.
Bug: 126222433 Test: robo Change-Id: I05beec7d3e3ec713c40740a1adbcacaee88237b5
This commit is contained in:
@@ -70,8 +70,6 @@
|
||||
<attr name="searchable" format="boolean" />
|
||||
<!-- Classname of a PreferenceController corresponding to the preference -->
|
||||
<attr name="controller" format="string" />
|
||||
<!-- {@code true} when the controller declared represents a slice from {@link android.app.SettingsSliceContract} -->
|
||||
<attr name="platform_slice" format="boolean" />
|
||||
<!-- customized subtitle if it's an unavailable slice -->
|
||||
<attr name="unavailableSliceSubtitle" format="string" />
|
||||
</declare-styleable>
|
||||
|
@@ -41,7 +41,6 @@
|
||||
android:summary="@string/battery_saver_turn_on_summary"
|
||||
settings:textOn="@string/battery_saver_button_turn_on"
|
||||
settings:textOff="@string/battery_saver_button_turn_off"
|
||||
settings:platform_slice="true"
|
||||
settings:controller="com.android.settings.fuelgauge.batterysaver.BatterySaverButtonPreferenceController" />
|
||||
|
||||
<PreferenceCategory
|
||||
|
@@ -70,7 +70,6 @@
|
||||
android:disableDependentsState="true"
|
||||
android:order="5"
|
||||
settings:controller="com.android.settings.network.AirplaneModePreferenceController"
|
||||
settings:platform_slice="true"
|
||||
settings:userRestriction="no_airplane_mode"/>
|
||||
|
||||
<Preference
|
||||
|
@@ -59,7 +59,6 @@
|
||||
android:disableDependentsState="true"
|
||||
android:order="-5"
|
||||
settings:controller="com.android.settings.network.AirplaneModePreferenceController"
|
||||
settings:platform_slice="true"
|
||||
settings:userRestriction="no_airplane_mode"/>
|
||||
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
|
@@ -83,7 +83,6 @@ public class PreferenceXmlParserUtils {
|
||||
int FLAG_NEED_PREF_TITLE = 1 << 4;
|
||||
int FLAG_NEED_PREF_SUMMARY = 1 << 5;
|
||||
int FLAG_NEED_PREF_ICON = 1 << 6;
|
||||
int FLAG_NEED_PLATFORM_SLICE_FLAG = 1 << 7;
|
||||
int FLAG_NEED_KEYWORDS = 1 << 8;
|
||||
int FLAG_NEED_SEARCHABLE = 1 << 9;
|
||||
int FLAG_NEED_PREF_APPEND = 1 << 10;
|
||||
@@ -96,7 +95,6 @@ public class PreferenceXmlParserUtils {
|
||||
public static final String METADATA_TITLE = "title";
|
||||
public static final String METADATA_SUMMARY = "summary";
|
||||
public static final String METADATA_ICON = "icon";
|
||||
public static final String METADATA_PLATFORM_SLICE_FLAG = "platform_slice";
|
||||
public static final String METADATA_KEYWORDS = "keywords";
|
||||
public static final String METADATA_SEARCHABLE = "searchable";
|
||||
public static final String METADATA_APPEND = "staticPreferenceLocation";
|
||||
@@ -231,10 +229,6 @@ public class PreferenceXmlParserUtils {
|
||||
if (hasFlag(flags, MetadataFlag.FLAG_NEED_PREF_ICON)) {
|
||||
preferenceMetadata.putInt(METADATA_ICON, getIcon(preferenceAttributes));
|
||||
}
|
||||
if (hasFlag(flags, MetadataFlag.FLAG_NEED_PLATFORM_SLICE_FLAG)) {
|
||||
preferenceMetadata.putBoolean(METADATA_PLATFORM_SLICE_FLAG,
|
||||
getPlatformSlice(preferenceAttributes));
|
||||
}
|
||||
if (hasFlag(flags, MetadataFlag.FLAG_NEED_KEYWORDS)) {
|
||||
preferenceMetadata.putString(METADATA_KEYWORDS, getKeywords(preferenceAttributes));
|
||||
}
|
||||
@@ -318,10 +312,6 @@ public class PreferenceXmlParserUtils {
|
||||
return styledAttributes.getResourceId(com.android.internal.R.styleable.Icon_icon, 0);
|
||||
}
|
||||
|
||||
private static boolean getPlatformSlice(TypedArray styledAttributes) {
|
||||
return styledAttributes.getBoolean(R.styleable.Preference_platform_slice, false /* def */);
|
||||
}
|
||||
|
||||
private static boolean isSearchable(TypedArray styledAttributes) {
|
||||
return styledAttributes.getBoolean(R.styleable.Preference_searchable, true /* default */);
|
||||
}
|
||||
|
@@ -70,7 +70,7 @@ import java.util.stream.Collectors;
|
||||
* return an stub {@link Slice} with the correct {@link Uri} immediately. In the background, the
|
||||
* data corresponding to the key in the {@link Uri} is read by {@link SlicesDatabaseAccessor}, and
|
||||
* the entire row is converted into a {@link SliceData}. Once complete, it is stored in
|
||||
* {@link #mSliceDataCache}, and then an update sent via the Slice framework to the Slice.
|
||||
* {@link #mSliceWeakDataCache}, and then an update sent via the Slice framework to the Slice.
|
||||
* The {@link Slice} displayed by the Slice-presenter will re-query this Slice-provider and find
|
||||
* the {@link SliceData} cached to build the full {@link Slice}.
|
||||
*
|
||||
@@ -112,13 +112,6 @@ public class SettingsSliceProvider extends SliceProvider {
|
||||
*/
|
||||
public static final String EXTRA_SLICE_KEY = "com.android.settings.slice.extra.key";
|
||||
|
||||
/**
|
||||
* Boolean extra to indicate if the Slice is platform-defined.
|
||||
*/
|
||||
public static final String EXTRA_SLICE_PLATFORM_DEFINED =
|
||||
"com.android.settings.slice.extra.platform";
|
||||
|
||||
|
||||
/**
|
||||
* A list of custom slice uris that are supported publicly. This is a subset of slices defined
|
||||
* in {@link CustomSliceRegistry}. Things here are exposed publicly so all clients with proper
|
||||
|
@@ -23,7 +23,6 @@ import static com.android.settings.slices.SettingsSliceProvider.ACTION_COPY;
|
||||
import static com.android.settings.slices.SettingsSliceProvider.ACTION_SLIDER_CHANGED;
|
||||
import static com.android.settings.slices.SettingsSliceProvider.ACTION_TOGGLE_CHANGED;
|
||||
import static com.android.settings.slices.SettingsSliceProvider.EXTRA_SLICE_KEY;
|
||||
import static com.android.settings.slices.SettingsSliceProvider.EXTRA_SLICE_PLATFORM_DEFINED;
|
||||
import static com.android.settings.wifi.calling.WifiCallingSliceHelper.ACTION_WIFI_CALLING_CHANGED;
|
||||
import static com.android.settings.wifi.calling.WifiCallingSliceHelper.ACTION_WIFI_CALLING_PREFERENCE_CELLULAR_PREFERRED;
|
||||
import static com.android.settings.wifi.calling.WifiCallingSliceHelper.ACTION_WIFI_CALLING_PREFERENCE_WIFI_ONLY;
|
||||
@@ -32,11 +31,9 @@ import static com.android.settings.wifi.calling.WifiCallingSliceHelper.ACTION_WI
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.app.slice.Slice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -58,8 +55,6 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
final String key = intent.getStringExtra(EXTRA_SLICE_KEY);
|
||||
final boolean isPlatformSlice = intent.getBooleanExtra(EXTRA_SLICE_PLATFORM_DEFINED,
|
||||
false /* default */);
|
||||
|
||||
if (CustomSliceRegistry.isValidAction(action)) {
|
||||
final CustomSliceable sliceable =
|
||||
@@ -68,15 +63,16 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
sliceable.onNotifyChange(intent);
|
||||
return;
|
||||
}
|
||||
final Uri sliceUri = intent.getData();
|
||||
|
||||
switch (action) {
|
||||
case ACTION_TOGGLE_CHANGED:
|
||||
final boolean isChecked = intent.getBooleanExtra(Slice.EXTRA_TOGGLE_STATE, false);
|
||||
handleToggleAction(context, key, isChecked, isPlatformSlice);
|
||||
handleToggleAction(context, sliceUri, key, isChecked);
|
||||
break;
|
||||
case ACTION_SLIDER_CHANGED:
|
||||
final int newPosition = intent.getIntExtra(Slice.EXTRA_RANGE_VALUE, -1);
|
||||
handleSliderAction(context, key, newPosition, isPlatformSlice);
|
||||
handleSliderAction(context, sliceUri, key, newPosition);
|
||||
break;
|
||||
case ACTION_BLUETOOTH_SLICE_CHANGED:
|
||||
BluetoothSliceBuilder.handleUriChange(context, intent);
|
||||
@@ -105,13 +101,12 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
.handleWifiCallingPreferenceChanged(intent);
|
||||
break;
|
||||
case ACTION_COPY:
|
||||
handleCopyAction(context, key, isPlatformSlice);
|
||||
handleCopyAction(context, sliceUri, key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleToggleAction(Context context, String key, boolean isChecked,
|
||||
boolean isPlatformSlice) {
|
||||
private void handleToggleAction(Context context, Uri sliceUri, String key, boolean isChecked) {
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
throw new IllegalStateException("No key passed to Intent for toggle controller");
|
||||
}
|
||||
@@ -125,7 +120,7 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
if (!controller.isAvailable()) {
|
||||
Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
|
||||
if (!controller.hasAsyncUpdate()) {
|
||||
updateUri(context, key, isPlatformSlice);
|
||||
context.getContentResolver().notifyChange(sliceUri, null /* observer */);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -136,12 +131,11 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
toggleController.setChecked(isChecked);
|
||||
logSliceValueChange(context, key, isChecked ? 1 : 0);
|
||||
if (!controller.hasAsyncUpdate()) {
|
||||
updateUri(context, key, isPlatformSlice);
|
||||
context.getContentResolver().notifyChange(sliceUri, null /* observer */);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleSliderAction(Context context, String key, int newPosition,
|
||||
boolean isPlatformSlice) {
|
||||
private void handleSliderAction(Context context, Uri sliceUri, String key, int newPosition) {
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
throw new IllegalArgumentException(
|
||||
"No key passed to Intent for slider controller. Use extra: " + EXTRA_SLICE_KEY);
|
||||
@@ -159,7 +153,7 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
if (!controller.isAvailable()) {
|
||||
Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
|
||||
updateUri(context, key, isPlatformSlice);
|
||||
context.getContentResolver().notifyChange(sliceUri, null /* observer */);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -174,10 +168,10 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
sliderController.setSliderPosition(newPosition);
|
||||
logSliceValueChange(context, key, newPosition);
|
||||
updateUri(context, key, isPlatformSlice);
|
||||
context.getContentResolver().notifyChange(sliceUri, null /* observer */);
|
||||
}
|
||||
|
||||
private void handleCopyAction(Context context, String key, boolean isPlatformSlice) {
|
||||
private void handleCopyAction(Context context, Uri sliceUri, String key) {
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
throw new IllegalArgumentException("No key passed to Intent for controller");
|
||||
}
|
||||
@@ -192,7 +186,7 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
if (!controller.isAvailable()) {
|
||||
Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
|
||||
if (!controller.hasAsyncUpdate()) {
|
||||
updateUri(context, key, isPlatformSlice);
|
||||
context.getContentResolver().notifyChange(sliceUri, null /* observer */);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -217,17 +211,4 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
final SliceData sliceData = accessor.getSliceDataFromKey(key);
|
||||
return SliceBuilderUtils.getPreferenceController(context, sliceData);
|
||||
}
|
||||
|
||||
private void updateUri(Context context, String key, boolean isPlatformDefined) {
|
||||
final String authority = isPlatformDefined
|
||||
? SettingsSlicesContract.AUTHORITY
|
||||
: SettingsSliceProvider.SLICE_AUTHORITY;
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(authority)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
context.getContentResolver().notifyChange(uri, null /* observer */);
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,6 @@ package com.android.settings.slices;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
|
||||
import static com.android.settings.slices.SettingsSliceProvider.EXTRA_SLICE_KEY;
|
||||
import static com.android.settings.slices.SettingsSliceProvider.EXTRA_SLICE_PLATFORM_DEFINED;
|
||||
|
||||
import android.annotation.ColorInt;
|
||||
import android.app.PendingIntent;
|
||||
@@ -158,8 +157,7 @@ public class SliceBuilderUtils {
|
||||
final Intent intent = new Intent(action)
|
||||
.setData(data.getUri())
|
||||
.setClass(context, SliceBroadcastReceiver.class)
|
||||
.putExtra(EXTRA_SLICE_KEY, data.getKey())
|
||||
.putExtra(EXTRA_SLICE_PLATFORM_DEFINED, data.isPlatformDefined());
|
||||
.putExtra(EXTRA_SLICE_KEY, data.getKey());
|
||||
return PendingIntent.getBroadcast(context, 0 /* requestCode */, intent,
|
||||
PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
}
|
||||
|
@@ -71,8 +71,6 @@ public class SliceData {
|
||||
@SliceType
|
||||
private final int mSliceType;
|
||||
|
||||
private final boolean mIsPlatformDefined;
|
||||
|
||||
private final String mUnavailableSliceSubtitle;
|
||||
|
||||
public String getKey() {
|
||||
@@ -115,10 +113,6 @@ public class SliceData {
|
||||
return mSliceType;
|
||||
}
|
||||
|
||||
public boolean isPlatformDefined() {
|
||||
return mIsPlatformDefined;
|
||||
}
|
||||
|
||||
public String getUnavailableSliceSubtitle() {
|
||||
return mUnavailableSliceSubtitle;
|
||||
}
|
||||
@@ -134,7 +128,6 @@ public class SliceData {
|
||||
mUri = builder.mUri;
|
||||
mPreferenceController = builder.mPrefControllerClassName;
|
||||
mSliceType = builder.mSliceType;
|
||||
mIsPlatformDefined = builder.mIsPlatformDefined;
|
||||
mUnavailableSliceSubtitle = builder.mUnavailableSliceSubtitle;
|
||||
}
|
||||
|
||||
@@ -173,8 +166,6 @@ public class SliceData {
|
||||
|
||||
private int mSliceType;
|
||||
|
||||
private boolean mIsPlatformDefined;
|
||||
|
||||
private String mUnavailableSliceSubtitle;
|
||||
|
||||
public Builder setKey(String key) {
|
||||
@@ -227,11 +218,6 @@ public class SliceData {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setPlatformDefined(boolean isPlatformDefined) {
|
||||
mIsPlatformDefined = isPlatformDefined;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setUnavailableSliceSubtitle(
|
||||
String unavailableSliceSubtitle) {
|
||||
mUnavailableSliceSubtitle = unavailableSliceSubtitle;
|
||||
|
@@ -19,7 +19,6 @@ package com.android.settings.slices;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_CONTROLLER;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_ICON;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEY;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_PLATFORM_SLICE_FLAG;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_SUMMARY;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_TITLE;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_UNAVAILABLE_SLICE_SUBTITLE;
|
||||
@@ -190,7 +189,6 @@ class SliceDataConverter {
|
||||
| MetadataFlag.FLAG_NEED_PREF_TITLE
|
||||
| MetadataFlag.FLAG_NEED_PREF_ICON
|
||||
| MetadataFlag.FLAG_NEED_PREF_SUMMARY
|
||||
| MetadataFlag.FLAG_NEED_PLATFORM_SLICE_FLAG
|
||||
| MetadataFlag.FLAG_UNAVAILABLE_SLICE_SUBTITLE);
|
||||
|
||||
for (Bundle bundle : metadata) {
|
||||
@@ -213,7 +211,6 @@ class SliceDataConverter {
|
||||
final int iconResId = bundle.getInt(METADATA_ICON);
|
||||
|
||||
final int sliceType = controller.getSliceType();
|
||||
final boolean isPlatformSlice = bundle.getBoolean(METADATA_PLATFORM_SLICE_FLAG);
|
||||
final String unavailableSliceSubtitle = bundle.getString(
|
||||
METADATA_UNAVAILABLE_SLICE_SUBTITLE);
|
||||
|
||||
@@ -227,7 +224,6 @@ class SliceDataConverter {
|
||||
.setPreferenceControllerClassName(controllerClassName)
|
||||
.setFragmentName(fragmentName)
|
||||
.setSliceType(sliceType)
|
||||
.setPlatformDefined(isPlatformSlice)
|
||||
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
|
||||
.build();
|
||||
|
||||
|
@@ -48,14 +48,10 @@ public class SlicesDatabaseAccessor {
|
||||
IndexColumns.ICON_RESOURCE,
|
||||
IndexColumns.FRAGMENT,
|
||||
IndexColumns.CONTROLLER,
|
||||
IndexColumns.PLATFORM_SLICE,
|
||||
IndexColumns.SLICE_TYPE,
|
||||
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||
};
|
||||
|
||||
// Cursor value for boolean true
|
||||
private static final int TRUE = 1;
|
||||
|
||||
private final Context mContext;
|
||||
private final SlicesDatabaseHelper mHelper;
|
||||
|
||||
@@ -159,8 +155,6 @@ public class SlicesDatabaseAccessor {
|
||||
cursor.getColumnIndex(IndexColumns.FRAGMENT));
|
||||
final String controllerClassName = cursor.getString(
|
||||
cursor.getColumnIndex(IndexColumns.CONTROLLER));
|
||||
final boolean isPlatformDefined = cursor.getInt(
|
||||
cursor.getColumnIndex(IndexColumns.PLATFORM_SLICE)) == TRUE;
|
||||
int sliceType = cursor.getInt(
|
||||
cursor.getColumnIndex(IndexColumns.SLICE_TYPE));
|
||||
final String unavailableSliceSubtitle = cursor.getString(
|
||||
@@ -180,7 +174,6 @@ public class SlicesDatabaseAccessor {
|
||||
.setFragmentName(fragmentClassName)
|
||||
.setPreferenceControllerClassName(controllerClassName)
|
||||
.setUri(uri)
|
||||
.setPlatformDefined(isPlatformDefined)
|
||||
.setSliceType(sliceType)
|
||||
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
|
||||
.build();
|
||||
|
@@ -36,7 +36,7 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
private static final String DATABASE_NAME = "slices_index.db";
|
||||
private static final String SHARED_PREFS_TAG = "slices_shared_prefs";
|
||||
|
||||
private static final int DATABASE_VERSION = 6;
|
||||
private static final int DATABASE_VERSION = 7;
|
||||
|
||||
public interface Tables {
|
||||
String TABLE_SLICES_INDEX = "slices_index";
|
||||
@@ -84,11 +84,6 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
*/
|
||||
String CONTROLLER = "controller";
|
||||
|
||||
/**
|
||||
* Boolean flag, {@code true} when the Slice is officially platform-supported.
|
||||
*/
|
||||
String PLATFORM_SLICE = "platform_slice";
|
||||
|
||||
/**
|
||||
* {@link SliceData.SliceType} representing the inline type of the result.
|
||||
*/
|
||||
@@ -126,8 +121,6 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
", " +
|
||||
IndexColumns.CONTROLLER +
|
||||
", " +
|
||||
IndexColumns.PLATFORM_SLICE +
|
||||
", " +
|
||||
IndexColumns.SLICE_TYPE +
|
||||
", " +
|
||||
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE +
|
||||
|
@@ -109,7 +109,6 @@ class SlicesIndexer implements Runnable {
|
||||
values.put(IndexColumns.ICON_RESOURCE, dataRow.getIconResource());
|
||||
values.put(IndexColumns.FRAGMENT, dataRow.getFragmentClassName());
|
||||
values.put(IndexColumns.CONTROLLER, dataRow.getPreferenceController());
|
||||
values.put(IndexColumns.PLATFORM_SLICE, dataRow.isPlatformDefined());
|
||||
values.put(IndexColumns.SLICE_TYPE, dataRow.getSliceType());
|
||||
values.put(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||
dataRow.getUnavailableSliceSubtitle());
|
||||
|
@@ -26,7 +26,6 @@
|
||||
android:summary="summary"
|
||||
settings:controller="com.android.settings.slices.FakePreferenceController"
|
||||
settings:keywords="a, b, c"
|
||||
settings:platform_slice="true"
|
||||
settings:unavailableSliceSubtitle="subtitleOfUnavailableSlice"/>
|
||||
|
||||
</PreferenceScreen>
|
@@ -27,8 +27,7 @@
|
||||
android:icon="@drawable/ic_android"
|
||||
android:summary="summary"
|
||||
settings:controller="com.android.settings.slices.FakePreferenceController"
|
||||
settings:keywords="keyword"
|
||||
settings:platform_slice="true"/>
|
||||
settings:keywords="keyword"/>
|
||||
|
||||
<Preference
|
||||
android:key="key2"
|
||||
@@ -37,7 +36,6 @@
|
||||
android:summary="summary"
|
||||
settings:controller="com.android.settings.slices.FakePreferenceController"
|
||||
settings:keywords="keyword"
|
||||
settings:platform_slice="true"
|
||||
settings:unavailableSliceSubtitle="subtitleOfUnavailable"/>
|
||||
|
||||
</PreferenceScreen>
|
@@ -34,10 +34,8 @@ import static org.mockito.Mockito.when;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.slice.SliceManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.Uri;
|
||||
import android.os.StrictMode;
|
||||
import android.provider.Settings;
|
||||
@@ -49,7 +47,6 @@ import androidx.slice.Slice;
|
||||
import androidx.slice.SliceProvider;
|
||||
import androidx.slice.widget.SliceLiveData;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.DatabaseTestUtils;
|
||||
import com.android.settings.testutils.FakeToggleController;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
|
@@ -43,7 +43,6 @@ import com.android.settings.search.SearchFeatureProvider;
|
||||
import com.android.settings.search.SearchFeatureProviderImpl;
|
||||
import com.android.settings.testutils.DatabaseTestUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.FakeIndexProvider;
|
||||
import com.android.settings.testutils.FakeSliderController;
|
||||
import com.android.settings.testutils.FakeToggleController;
|
||||
|
||||
@@ -57,13 +56,6 @@ import org.robolectric.RuntimeEnvironment;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SliceBroadcastReceiverTest {
|
||||
|
||||
private final String fakeTitle = "title";
|
||||
private final String fakeSummary = "summary";
|
||||
private final String fakeScreenTitle = "screen_title";
|
||||
private final int fakeIcon = 1234;
|
||||
private final String fakeFragmentClassName = FakeIndexProvider.class.getName();
|
||||
private final Class fakeControllerName = FakeToggleController.class;
|
||||
|
||||
private Context mContext;
|
||||
private SQLiteDatabase mDb;
|
||||
private SliceBroadcastReceiver mReceiver;
|
||||
@@ -90,21 +82,18 @@ public class SliceBroadcastReceiverTest {
|
||||
@Test
|
||||
public void onReceive_toggleChanged() {
|
||||
final String key = "key";
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
final Uri uri = buildUri(key);
|
||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||
insertSpecialCase(key);
|
||||
final ContentResolver resolver = mock(ContentResolver.class);
|
||||
doReturn(resolver).when(mContext).getContentResolver();
|
||||
// Turn on toggle setting
|
||||
FakeToggleController fakeToggleController = new FakeToggleController(mContext, key);
|
||||
final FakeToggleController fakeToggleController = new FakeToggleController(mContext, key);
|
||||
fakeToggleController.setChecked(true);
|
||||
Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED);
|
||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
||||
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED)
|
||||
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key)
|
||||
.setData(uri);
|
||||
|
||||
assertThat(fakeToggleController.isChecked()).isTrue();
|
||||
|
||||
@@ -128,6 +117,8 @@ public class SliceBroadcastReceiverTest {
|
||||
doReturn(resolver).when(mContext).getContentResolver();
|
||||
|
||||
final String key = "key";
|
||||
final Uri expectedUri = buildUri(key);
|
||||
|
||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||
insertSpecialCase(key);
|
||||
|
||||
@@ -135,8 +126,9 @@ public class SliceBroadcastReceiverTest {
|
||||
fakeToggleController.setChecked(true);
|
||||
// Set the toggle setting update synchronously.
|
||||
fakeToggleController.setAsyncUpdate(false);
|
||||
Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED);
|
||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED)
|
||||
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key)
|
||||
.setData(expectedUri);
|
||||
|
||||
assertThat(fakeToggleController.isChecked()).isTrue();
|
||||
|
||||
@@ -145,12 +137,6 @@ public class SliceBroadcastReceiverTest {
|
||||
|
||||
assertThat(fakeToggleController.isChecked()).isFalse();
|
||||
|
||||
final Uri expectedUri = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
|
||||
verify(resolver).notifyChange(expectedUri, null);
|
||||
}
|
||||
@@ -163,16 +149,11 @@ public class SliceBroadcastReceiverTest {
|
||||
|
||||
final String key = "key";
|
||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||
insertSpecialCase(key);
|
||||
insertSpecialCase(AsyncToggleController.class.getName(), key);
|
||||
|
||||
FakeToggleController fakeToggleController = new FakeToggleController(mContext, key);
|
||||
fakeToggleController.setChecked(true);
|
||||
// Set the toggle setting update asynchronously.
|
||||
fakeToggleController.setAsyncUpdate(true);
|
||||
Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED);
|
||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
||||
|
||||
assertThat(fakeToggleController.isChecked()).isTrue();
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED)
|
||||
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key)
|
||||
.setData(buildUri(key));
|
||||
|
||||
// Toggle setting
|
||||
mReceiver.onReceive(mContext, intent);
|
||||
@@ -183,26 +164,22 @@ public class SliceBroadcastReceiverTest {
|
||||
@Test
|
||||
public void onReceive_sliderChanged() {
|
||||
final String key = "key";
|
||||
final Uri uri = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
final Uri uri = buildUri(key);
|
||||
final ContentResolver resolver = mock(ContentResolver.class);
|
||||
doReturn(resolver).when(mContext).getContentResolver();
|
||||
final int position = FakeSliderController.MAX_VALUE - 1;
|
||||
final int oldPosition = FakeSliderController.MAX_VALUE;
|
||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||
insertSpecialCase(FakeSliderController.class, key);
|
||||
insertSpecialCase(FakeSliderController.class.getName(), key);
|
||||
|
||||
// Set slider setting
|
||||
FakeSliderController fakeSliderController = new FakeSliderController(mContext, key);
|
||||
fakeSliderController.setSliderPosition(oldPosition);
|
||||
// Build action
|
||||
Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED);
|
||||
intent.putExtra(Slice.EXTRA_RANGE_VALUE, position);
|
||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED)
|
||||
.putExtra(Slice.EXTRA_RANGE_VALUE, position)
|
||||
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key)
|
||||
.setData(uri);
|
||||
|
||||
assertThat(fakeSliderController.getSliderPosition()).isEqualTo(oldPosition);
|
||||
|
||||
@@ -225,12 +202,12 @@ public class SliceBroadcastReceiverTest {
|
||||
final String key = "key";
|
||||
final int position = 0;
|
||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||
insertSpecialCase(FakeToggleController.class, key);
|
||||
insertSpecialCase(key);
|
||||
|
||||
// Build action
|
||||
Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED);
|
||||
intent.putExtra(Slice.EXTRA_RANGE_VALUE, position);
|
||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED)
|
||||
.putExtra(Slice.EXTRA_RANGE_VALUE, position)
|
||||
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
||||
|
||||
// Trigger the exception.
|
||||
mReceiver.onReceive(mContext, intent);
|
||||
@@ -272,29 +249,25 @@ public class SliceBroadcastReceiverTest {
|
||||
|
||||
// Insert Fake Toggle into Database
|
||||
final String key = "key";
|
||||
final Uri expectedUri = buildUri(key);
|
||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||
insertSpecialCase(FakeToggleController.class, key);
|
||||
insertSpecialCase(key);
|
||||
|
||||
// Turn on toggle setting
|
||||
final FakeToggleController fakeToggleController = new FakeToggleController(mContext, key);
|
||||
fakeToggleController.setChecked(true);
|
||||
|
||||
// Build Action
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED);
|
||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED)
|
||||
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key)
|
||||
.setData(expectedUri);
|
||||
|
||||
// Trigger Slice change
|
||||
mReceiver.onReceive(mContext, intent);
|
||||
|
||||
// Check the value is the same and the Uri has been notified.
|
||||
assertThat(fakeToggleController.isChecked()).isTrue();
|
||||
final Uri expectedUri = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
verify(resolver).notifyChange(eq(expectedUri), eq(null));
|
||||
verify(resolver).notifyChange(expectedUri, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -310,47 +283,65 @@ public class SliceBroadcastReceiverTest {
|
||||
|
||||
// Insert Fake Slider into Database
|
||||
final String key = "key";
|
||||
final Uri expectedUri = buildUri(key);
|
||||
|
||||
final int position = FakeSliderController.MAX_VALUE - 1;
|
||||
final int oldPosition = FakeSliderController.MAX_VALUE;
|
||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||
insertSpecialCase(FakeSliderController.class, key);
|
||||
insertSpecialCase(FakeSliderController.class.getName(), key);
|
||||
|
||||
// Set slider setting
|
||||
final FakeSliderController fakeSliderController = new FakeSliderController(mContext, key);
|
||||
fakeSliderController.setSliderPosition(oldPosition);
|
||||
|
||||
// Build action
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED);
|
||||
intent.putExtra(Slice.EXTRA_RANGE_VALUE, position);
|
||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED)
|
||||
.putExtra(Slice.EXTRA_RANGE_VALUE, position)
|
||||
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key)
|
||||
.setData(expectedUri);
|
||||
|
||||
// Trigger Slice change
|
||||
mReceiver.onReceive(mContext, intent);
|
||||
|
||||
// Check position is the same and the Uri has been notified.
|
||||
assertThat(fakeSliderController.getSliderPosition()).isEqualTo(oldPosition);
|
||||
final Uri expectedUri = new Uri.Builder()
|
||||
verify(resolver).notifyChange(eq(expectedUri), eq(null));
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String key) {
|
||||
insertSpecialCase(SliceTestUtils.FAKE_CONTROLLER_NAME, key);
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String controllerClass, String key) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.KEY, key);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.TITLE, SliceTestUtils.FAKE_TITLE);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SUMMARY, SliceTestUtils.FAKE_SUMMARY);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SCREENTITLE, SliceTestUtils.FAKE_SCREEN_TITLE);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.ICON_RESOURCE, SliceTestUtils.FAKE_ICON);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.FRAGMENT, SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.CONTROLLER, controllerClass);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SLICE_URI, buildUri(key).toSafeString());
|
||||
mDb.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
|
||||
}
|
||||
|
||||
private static Uri buildUri(String key) {
|
||||
return new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(key)
|
||||
.build();
|
||||
verify(resolver).notifyChange(eq(expectedUri), eq(null));
|
||||
}
|
||||
|
||||
private void insertSpecialCase(String key) {
|
||||
insertSpecialCase(fakeControllerName, key);
|
||||
}
|
||||
public static class AsyncToggleController extends FakeToggleController {
|
||||
public AsyncToggleController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
private void insertSpecialCase(Class controllerClass, String key) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.KEY, key);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.TITLE, fakeTitle);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SUMMARY, fakeSummary);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SCREENTITLE, fakeScreenTitle);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.ICON_RESOURCE, fakeIcon);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.FRAGMENT, fakeFragmentClassName);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.CONTROLLER, controllerClass.getName());
|
||||
mDb.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
|
||||
@Override
|
||||
public boolean hasAsyncUpdate() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@@ -124,7 +124,6 @@ public class SliceDataConverterTest {
|
||||
assertThat(fakeSlice.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_CLASSNAME);
|
||||
assertThat(fakeSlice.getPreferenceController()).isEqualTo(FAKE_CONTROLLER_NAME);
|
||||
assertThat(fakeSlice.getSliceType()).isEqualTo(SliceData.SliceType.SLIDER);
|
||||
assertThat(fakeSlice.isPlatformDefined()).isTrue(); // from XML
|
||||
assertThat(fakeSlice.getUnavailableSliceSubtitle()).isEqualTo(
|
||||
"subtitleOfUnavailableSlice"); // from XML
|
||||
}
|
||||
|
@@ -37,7 +37,6 @@ public class SliceDataTest {
|
||||
private final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||
private final String PREF_CONTROLLER = "com.android.settings.slices.tester";
|
||||
private final int SLICE_TYPE = SliceData.SliceType.SWITCH;
|
||||
private final boolean IS_PLATFORM_DEFINED = true;
|
||||
private final String UNAVAILABLE_SLICE_SUBTITLE = "subtitleOfUnavailableSlice";
|
||||
|
||||
@Test
|
||||
@@ -53,7 +52,6 @@ public class SliceDataTest {
|
||||
.setUri(URI)
|
||||
.setPreferenceControllerClassName(PREF_CONTROLLER)
|
||||
.setSliceType(SLICE_TYPE)
|
||||
.setPlatformDefined(IS_PLATFORM_DEFINED)
|
||||
.setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE);
|
||||
|
||||
SliceData data = builder.build();
|
||||
@@ -68,7 +66,6 @@ public class SliceDataTest {
|
||||
assertThat(data.getUri()).isEqualTo(URI);
|
||||
assertThat(data.getPreferenceController()).isEqualTo(PREF_CONTROLLER);
|
||||
assertThat(data.getSliceType()).isEqualTo(SLICE_TYPE);
|
||||
assertThat(data.isPlatformDefined()).isEqualTo(IS_PLATFORM_DEFINED);
|
||||
assertThat(data.getUnavailableSliceSubtitle()).isEqualTo(UNAVAILABLE_SLICE_SUBTITLE);
|
||||
}
|
||||
|
||||
|
@@ -73,5 +73,4 @@ class SliceTestUtils {
|
||||
db.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
|
||||
db.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -73,7 +73,6 @@ public class SlicesDatabaseHelperTest {
|
||||
IndexColumns.ICON_RESOURCE,
|
||||
IndexColumns.FRAGMENT,
|
||||
IndexColumns.CONTROLLER,
|
||||
IndexColumns.PLATFORM_SLICE,
|
||||
IndexColumns.SLICE_TYPE,
|
||||
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||
};
|
||||
|
@@ -52,7 +52,6 @@ public class SlicesIndexerTest {
|
||||
private final int ICON = 1234; // I declare a thumb war
|
||||
private final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||
private final String PREF_CONTROLLER = "com.android.settings.slices.tester";
|
||||
private final boolean PLATFORM_DEFINED = true;
|
||||
private final int SLICE_TYPE = SliceData.SliceType.SLIDER;
|
||||
private final String UNAVAILABLE_SLICE_SUBTITLE = "subtitleOfUnavailableSlice";
|
||||
|
||||
@@ -136,9 +135,6 @@ public class SlicesIndexerTest {
|
||||
assertThat(
|
||||
cursor.getString(cursor.getColumnIndex(IndexColumns.CONTROLLER)))
|
||||
.isEqualTo(PREF_CONTROLLER);
|
||||
assertThat(cursor.getInt(
|
||||
cursor.getColumnIndex(IndexColumns.PLATFORM_SLICE)))
|
||||
.isEqualTo(1 /* true */);
|
||||
assertThat(cursor.getInt(cursor.getColumnIndex(IndexColumns.SLICE_TYPE)))
|
||||
.isEqualTo(SLICE_TYPE);
|
||||
assertThat(cursor.getString(
|
||||
@@ -176,7 +172,6 @@ public class SlicesIndexerTest {
|
||||
.setIcon(ICON)
|
||||
.setUri(URI)
|
||||
.setPreferenceControllerClassName(PREF_CONTROLLER)
|
||||
.setPlatformDefined(PLATFORM_DEFINED)
|
||||
.setSliceType(SLICE_TYPE)
|
||||
.setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE);
|
||||
|
||||
|
@@ -49,7 +49,7 @@ public class FakeToggleController extends TogglePreferenceController {
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return Settings.System.getInt(mContext.getContentResolver(),
|
||||
SETTING_KEY, OFF) == ON;
|
||||
SETTING_KEY, OFF) == ON;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,7 +103,7 @@ public class FakeToggleController extends TogglePreferenceController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
public void close() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user