Merge changes I05beec7d,Iad4e9fc2
* changes: Remove "platform_slice" attribute from Settings. Use slice uri from slice index db directly.
This commit is contained in:
@@ -70,8 +70,6 @@
|
|||||||
<attr name="searchable" format="boolean" />
|
<attr name="searchable" format="boolean" />
|
||||||
<!-- Classname of a PreferenceController corresponding to the preference -->
|
<!-- Classname of a PreferenceController corresponding to the preference -->
|
||||||
<attr name="controller" format="string" />
|
<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 -->
|
<!-- customized subtitle if it's an unavailable slice -->
|
||||||
<attr name="unavailableSliceSubtitle" format="string" />
|
<attr name="unavailableSliceSubtitle" format="string" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|||||||
@@ -41,7 +41,6 @@
|
|||||||
android:summary="@string/battery_saver_turn_on_summary"
|
android:summary="@string/battery_saver_turn_on_summary"
|
||||||
settings:textOn="@string/battery_saver_button_turn_on"
|
settings:textOn="@string/battery_saver_button_turn_on"
|
||||||
settings:textOff="@string/battery_saver_button_turn_off"
|
settings:textOff="@string/battery_saver_button_turn_off"
|
||||||
settings:platform_slice="true"
|
|
||||||
settings:controller="com.android.settings.fuelgauge.batterysaver.BatterySaverButtonPreferenceController" />
|
settings:controller="com.android.settings.fuelgauge.batterysaver.BatterySaverButtonPreferenceController" />
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
|
|||||||
@@ -70,7 +70,6 @@
|
|||||||
android:disableDependentsState="true"
|
android:disableDependentsState="true"
|
||||||
android:order="5"
|
android:order="5"
|
||||||
settings:controller="com.android.settings.network.AirplaneModePreferenceController"
|
settings:controller="com.android.settings.network.AirplaneModePreferenceController"
|
||||||
settings:platform_slice="true"
|
|
||||||
settings:userRestriction="no_airplane_mode"/>
|
settings:userRestriction="no_airplane_mode"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
|
|||||||
@@ -59,7 +59,6 @@
|
|||||||
android:disableDependentsState="true"
|
android:disableDependentsState="true"
|
||||||
android:order="-5"
|
android:order="-5"
|
||||||
settings:controller="com.android.settings.network.AirplaneModePreferenceController"
|
settings:controller="com.android.settings.network.AirplaneModePreferenceController"
|
||||||
settings:platform_slice="true"
|
|
||||||
settings:userRestriction="no_airplane_mode"/>
|
settings:userRestriction="no_airplane_mode"/>
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedPreference
|
<com.android.settingslib.RestrictedPreference
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ public class PreferenceXmlParserUtils {
|
|||||||
int FLAG_NEED_PREF_TITLE = 1 << 4;
|
int FLAG_NEED_PREF_TITLE = 1 << 4;
|
||||||
int FLAG_NEED_PREF_SUMMARY = 1 << 5;
|
int FLAG_NEED_PREF_SUMMARY = 1 << 5;
|
||||||
int FLAG_NEED_PREF_ICON = 1 << 6;
|
int FLAG_NEED_PREF_ICON = 1 << 6;
|
||||||
int FLAG_NEED_PLATFORM_SLICE_FLAG = 1 << 7;
|
|
||||||
int FLAG_NEED_KEYWORDS = 1 << 8;
|
int FLAG_NEED_KEYWORDS = 1 << 8;
|
||||||
int FLAG_NEED_SEARCHABLE = 1 << 9;
|
int FLAG_NEED_SEARCHABLE = 1 << 9;
|
||||||
int FLAG_NEED_PREF_APPEND = 1 << 10;
|
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_TITLE = "title";
|
||||||
public static final String METADATA_SUMMARY = "summary";
|
public static final String METADATA_SUMMARY = "summary";
|
||||||
public static final String METADATA_ICON = "icon";
|
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_KEYWORDS = "keywords";
|
||||||
public static final String METADATA_SEARCHABLE = "searchable";
|
public static final String METADATA_SEARCHABLE = "searchable";
|
||||||
public static final String METADATA_APPEND = "staticPreferenceLocation";
|
public static final String METADATA_APPEND = "staticPreferenceLocation";
|
||||||
@@ -231,10 +229,6 @@ public class PreferenceXmlParserUtils {
|
|||||||
if (hasFlag(flags, MetadataFlag.FLAG_NEED_PREF_ICON)) {
|
if (hasFlag(flags, MetadataFlag.FLAG_NEED_PREF_ICON)) {
|
||||||
preferenceMetadata.putInt(METADATA_ICON, getIcon(preferenceAttributes));
|
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)) {
|
if (hasFlag(flags, MetadataFlag.FLAG_NEED_KEYWORDS)) {
|
||||||
preferenceMetadata.putString(METADATA_KEYWORDS, getKeywords(preferenceAttributes));
|
preferenceMetadata.putString(METADATA_KEYWORDS, getKeywords(preferenceAttributes));
|
||||||
}
|
}
|
||||||
@@ -318,10 +312,6 @@ public class PreferenceXmlParserUtils {
|
|||||||
return styledAttributes.getResourceId(com.android.internal.R.styleable.Icon_icon, 0);
|
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) {
|
private static boolean isSearchable(TypedArray styledAttributes) {
|
||||||
return styledAttributes.getBoolean(R.styleable.Preference_searchable, true /* default */);
|
return styledAttributes.getBoolean(R.styleable.Preference_searchable, true /* default */);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import static android.Manifest.permission.READ_SEARCH_INDEXABLES;
|
|||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.slice.SliceManager;
|
import android.app.slice.SliceManager;
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
@@ -57,6 +56,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link SliceProvider} for Settings to enabled inline results in system apps.
|
* A {@link SliceProvider} for Settings to enabled inline results in system apps.
|
||||||
@@ -70,7 +70,7 @@ import java.util.WeakHashMap;
|
|||||||
* return an stub {@link Slice} with the correct {@link Uri} immediately. In the background, the
|
* 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
|
* 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
|
* 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 Slice} displayed by the Slice-presenter will re-query this Slice-provider and find
|
||||||
* the {@link SliceData} cached to build the full {@link Slice}.
|
* the {@link SliceData} cached to build the full {@link Slice}.
|
||||||
*
|
*
|
||||||
@@ -113,10 +113,19 @@ public class SettingsSliceProvider extends SliceProvider {
|
|||||||
public static final String EXTRA_SLICE_KEY = "com.android.settings.slice.extra.key";
|
public static final String EXTRA_SLICE_KEY = "com.android.settings.slice.extra.key";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boolean extra to indicate if the Slice is platform-defined.
|
* 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
|
||||||
|
* permission can use them.
|
||||||
*/
|
*/
|
||||||
public static final String EXTRA_SLICE_PLATFORM_DEFINED =
|
private static final List<Uri> PUBLICLY_SUPPORTED_CUSTOM_SLICE_URIS =
|
||||||
"com.android.settings.slice.extra.platform";
|
Arrays.asList(
|
||||||
|
CustomSliceRegistry.BLUETOOTH_URI,
|
||||||
|
CustomSliceRegistry.FLASHLIGHT_SLICE_URI,
|
||||||
|
CustomSliceRegistry.LOCATION_SLICE_URI,
|
||||||
|
CustomSliceRegistry.MOBILE_DATA_SLICE_URI,
|
||||||
|
CustomSliceRegistry.WIFI_SLICE_URI,
|
||||||
|
CustomSliceRegistry.ZEN_MODE_SLICE_URI
|
||||||
|
);
|
||||||
|
|
||||||
private static final KeyValueListParser KEY_VALUE_LIST_PARSER = new KeyValueListParser(',');
|
private static final KeyValueListParser KEY_VALUE_LIST_PARSER = new KeyValueListParser(',');
|
||||||
|
|
||||||
@@ -264,37 +273,30 @@ public class SettingsSliceProvider extends SliceProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String authority = uri.getAuthority();
|
final String authority = uri.getAuthority();
|
||||||
final String pathPrefix = uri.getPath();
|
final String path = uri.getPath();
|
||||||
final boolean isPathEmpty = pathPrefix.isEmpty();
|
final boolean isPathEmpty = path.isEmpty();
|
||||||
|
|
||||||
// No path nor authority. Return all possible Uris.
|
|
||||||
if (isPathEmpty && TextUtils.isEmpty(authority)) {
|
|
||||||
final List<String> platformKeys = mSlicesDatabaseAccessor.getSliceKeys(
|
|
||||||
true /* isPlatformSlice */);
|
|
||||||
final List<String> oemKeys = mSlicesDatabaseAccessor.getSliceKeys(
|
|
||||||
false /* isPlatformSlice */);
|
|
||||||
descendants.addAll(buildUrisFromKeys(platformKeys, SettingsSlicesContract.AUTHORITY));
|
|
||||||
descendants.addAll(buildUrisFromKeys(oemKeys, SettingsSliceProvider.SLICE_AUTHORITY));
|
|
||||||
descendants.addAll(getSpecialCaseUris(true /* isPlatformSlice */));
|
|
||||||
descendants.addAll(getSpecialCaseUris(false /* isPlatformSlice */));
|
|
||||||
|
|
||||||
return descendants;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Path is anything but empty, "action", or "intent". Return empty list.
|
// Path is anything but empty, "action", or "intent". Return empty list.
|
||||||
if (!isPathEmpty
|
if (!isPathEmpty
|
||||||
&& !TextUtils.equals(pathPrefix, "/" + SettingsSlicesContract.PATH_SETTING_ACTION)
|
&& !TextUtils.equals(path, "/" + SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||||
&& !TextUtils.equals(pathPrefix,
|
&& !TextUtils.equals(path, "/" + SettingsSlicesContract.PATH_SETTING_INTENT)) {
|
||||||
"/" + SettingsSlicesContract.PATH_SETTING_INTENT)) {
|
|
||||||
// Invalid path prefix, there are no valid Uri descendants.
|
// Invalid path prefix, there are no valid Uri descendants.
|
||||||
return descendants;
|
return descendants;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can assume authority belongs to the provider. Return all Uris for the authority.
|
// Add all descendants from db with matching authority.
|
||||||
final boolean isPlatformUri = TextUtils.equals(authority, SettingsSlicesContract.AUTHORITY);
|
descendants.addAll(mSlicesDatabaseAccessor.getSliceUris(authority));
|
||||||
final List<String> keys = mSlicesDatabaseAccessor.getSliceKeys(isPlatformUri);
|
|
||||||
descendants.addAll(buildUrisFromKeys(keys, authority));
|
if (isPathEmpty && TextUtils.isEmpty(authority)) {
|
||||||
descendants.addAll(getSpecialCaseUris(isPlatformUri));
|
// No path nor authority. Return all possible Uris by adding all special slice uri
|
||||||
|
descendants.addAll(PUBLICLY_SUPPORTED_CUSTOM_SLICE_URIS);
|
||||||
|
} else {
|
||||||
|
// Can assume authority belongs to the provider. Return all Uris for the authority.
|
||||||
|
final List<Uri> customSlices = PUBLICLY_SUPPORTED_CUSTOM_SLICE_URIS.stream()
|
||||||
|
.filter(sliceUri -> TextUtils.equals(authority, sliceUri.getAuthority()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
descendants.addAll(customSlices);
|
||||||
|
}
|
||||||
grantWhitelistedPackagePermissions(getContext(), descendants);
|
grantWhitelistedPackagePermissions(getContext(), descendants);
|
||||||
return descendants;
|
return descendants;
|
||||||
}
|
}
|
||||||
@@ -332,32 +334,6 @@ public class SettingsSliceProvider extends SliceProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startBackgroundWorker(Sliceable sliceable, Uri uri) {
|
|
||||||
final Class workerClass = sliceable.getBackgroundWorkerClass();
|
|
||||||
if (workerClass == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mPinnedWorkers.containsKey(uri)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.d(TAG, "Starting background worker for: " + uri);
|
|
||||||
final SliceBackgroundWorker worker = SliceBackgroundWorker.getInstance(
|
|
||||||
getContext(), sliceable, uri);
|
|
||||||
mPinnedWorkers.put(uri, worker);
|
|
||||||
worker.onSlicePinned();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void stopBackgroundWorker(Uri uri) {
|
|
||||||
final SliceBackgroundWorker worker = mPinnedWorkers.get(uri);
|
|
||||||
if (worker != null) {
|
|
||||||
Log.d(TAG, "Stopping background worker for: " + uri);
|
|
||||||
worker.onSliceUnpinned();
|
|
||||||
mPinnedWorkers.remove(uri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
ThreadUtils.postOnMainThread(() -> {
|
ThreadUtils.postOnMainThread(() -> {
|
||||||
@@ -365,23 +341,6 @@ public class SettingsSliceProvider extends SliceProvider {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Uri> buildUrisFromKeys(List<String> keys, String authority) {
|
|
||||||
final List<Uri> descendants = new ArrayList<>();
|
|
||||||
|
|
||||||
final Uri.Builder builder = new Uri.Builder()
|
|
||||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
|
||||||
.authority(authority)
|
|
||||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION);
|
|
||||||
|
|
||||||
final String newUriPathPrefix = SettingsSlicesContract.PATH_SETTING_ACTION + "/";
|
|
||||||
for (String key : keys) {
|
|
||||||
builder.path(newUriPathPrefix + key);
|
|
||||||
descendants.add(builder.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
return descendants;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void loadSlice(Uri uri) {
|
void loadSlice(Uri uri) {
|
||||||
long startBuildTime = System.currentTimeMillis();
|
long startBuildTime = System.currentTimeMillis();
|
||||||
@@ -416,38 +375,6 @@ public class SettingsSliceProvider extends SliceProvider {
|
|||||||
ThreadUtils.postOnBackgroundThread(() -> loadSlice(uri));
|
ThreadUtils.postOnBackgroundThread(() -> loadSlice(uri));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return an empty {@link Slice} with {@param uri} to be used as a stub while the real
|
|
||||||
* {@link SliceData} is loaded from {@link SlicesDatabaseHelper.Tables#TABLE_SLICES_INDEX}.
|
|
||||||
*/
|
|
||||||
private Slice getSliceStub(Uri uri) {
|
|
||||||
// TODO: Switch back to ListBuilder when slice loading states are fixed.
|
|
||||||
return new Slice.Builder(uri).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Uri> getSpecialCaseUris(boolean isPlatformUri) {
|
|
||||||
if (isPlatformUri) {
|
|
||||||
return getSpecialCasePlatformUris();
|
|
||||||
}
|
|
||||||
return getSpecialCaseOemUris();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Uri> getSpecialCasePlatformUris() {
|
|
||||||
return Arrays.asList(
|
|
||||||
CustomSliceRegistry.WIFI_SLICE_URI,
|
|
||||||
CustomSliceRegistry.BLUETOOTH_URI,
|
|
||||||
CustomSliceRegistry.LOCATION_SLICE_URI
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Uri> getSpecialCaseOemUris() {
|
|
||||||
return Arrays.asList(
|
|
||||||
CustomSliceRegistry.FLASHLIGHT_SLICE_URI,
|
|
||||||
CustomSliceRegistry.MOBILE_DATA_SLICE_URI,
|
|
||||||
CustomSliceRegistry.ZEN_MODE_SLICE_URI
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
/**
|
/**
|
||||||
* Registers an IntentFilter in SysUI to notify changes to {@param sliceUri} when broadcasts to
|
* Registers an IntentFilter in SysUI to notify changes to {@param sliceUri} when broadcasts to
|
||||||
@@ -476,7 +403,42 @@ public class SettingsSliceProvider extends SliceProvider {
|
|||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] parseStringArray(String value) {
|
private void startBackgroundWorker(Sliceable sliceable, Uri uri) {
|
||||||
|
final Class workerClass = sliceable.getBackgroundWorkerClass();
|
||||||
|
if (workerClass == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mPinnedWorkers.containsKey(uri)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.d(TAG, "Starting background worker for: " + uri);
|
||||||
|
final SliceBackgroundWorker worker = SliceBackgroundWorker.getInstance(
|
||||||
|
getContext(), sliceable, uri);
|
||||||
|
mPinnedWorkers.put(uri, worker);
|
||||||
|
worker.onSlicePinned();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopBackgroundWorker(Uri uri) {
|
||||||
|
final SliceBackgroundWorker worker = mPinnedWorkers.get(uri);
|
||||||
|
if (worker != null) {
|
||||||
|
Log.d(TAG, "Stopping background worker for: " + uri);
|
||||||
|
worker.onSliceUnpinned();
|
||||||
|
mPinnedWorkers.remove(uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return an empty {@link Slice} with {@param uri} to be used as a stub while the real
|
||||||
|
* {@link SliceData} is loaded from {@link SlicesDatabaseHelper.Tables#TABLE_SLICES_INDEX}.
|
||||||
|
*/
|
||||||
|
private static Slice getSliceStub(Uri uri) {
|
||||||
|
// TODO: Switch back to ListBuilder when slice loading states are fixed.
|
||||||
|
return new Slice.Builder(uri).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String[] parseStringArray(String value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
String[] parts = value.split(":");
|
String[] parts = value.split(":");
|
||||||
if (parts.length > 0) {
|
if (parts.length > 0) {
|
||||||
|
|||||||
@@ -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_SLIDER_CHANGED;
|
||||||
import static com.android.settings.slices.SettingsSliceProvider.ACTION_TOGGLE_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_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_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_CELLULAR_PREFERRED;
|
||||||
import static com.android.settings.wifi.calling.WifiCallingSliceHelper.ACTION_WIFI_CALLING_PREFERENCE_WIFI_ONLY;
|
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.settings.SettingsEnums;
|
||||||
import android.app.slice.Slice;
|
import android.app.slice.Slice;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.SettingsSlicesContract;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -58,8 +55,6 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
|||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
final String action = intent.getAction();
|
final String action = intent.getAction();
|
||||||
final String key = intent.getStringExtra(EXTRA_SLICE_KEY);
|
final String key = intent.getStringExtra(EXTRA_SLICE_KEY);
|
||||||
final boolean isPlatformSlice = intent.getBooleanExtra(EXTRA_SLICE_PLATFORM_DEFINED,
|
|
||||||
false /* default */);
|
|
||||||
|
|
||||||
if (CustomSliceRegistry.isValidAction(action)) {
|
if (CustomSliceRegistry.isValidAction(action)) {
|
||||||
final CustomSliceable sliceable =
|
final CustomSliceable sliceable =
|
||||||
@@ -68,15 +63,16 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
|||||||
sliceable.onNotifyChange(intent);
|
sliceable.onNotifyChange(intent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
final Uri sliceUri = intent.getData();
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ACTION_TOGGLE_CHANGED:
|
case ACTION_TOGGLE_CHANGED:
|
||||||
final boolean isChecked = intent.getBooleanExtra(Slice.EXTRA_TOGGLE_STATE, false);
|
final boolean isChecked = intent.getBooleanExtra(Slice.EXTRA_TOGGLE_STATE, false);
|
||||||
handleToggleAction(context, key, isChecked, isPlatformSlice);
|
handleToggleAction(context, sliceUri, key, isChecked);
|
||||||
break;
|
break;
|
||||||
case ACTION_SLIDER_CHANGED:
|
case ACTION_SLIDER_CHANGED:
|
||||||
final int newPosition = intent.getIntExtra(Slice.EXTRA_RANGE_VALUE, -1);
|
final int newPosition = intent.getIntExtra(Slice.EXTRA_RANGE_VALUE, -1);
|
||||||
handleSliderAction(context, key, newPosition, isPlatformSlice);
|
handleSliderAction(context, sliceUri, key, newPosition);
|
||||||
break;
|
break;
|
||||||
case ACTION_BLUETOOTH_SLICE_CHANGED:
|
case ACTION_BLUETOOTH_SLICE_CHANGED:
|
||||||
BluetoothSliceBuilder.handleUriChange(context, intent);
|
BluetoothSliceBuilder.handleUriChange(context, intent);
|
||||||
@@ -105,13 +101,12 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
|||||||
.handleWifiCallingPreferenceChanged(intent);
|
.handleWifiCallingPreferenceChanged(intent);
|
||||||
break;
|
break;
|
||||||
case ACTION_COPY:
|
case ACTION_COPY:
|
||||||
handleCopyAction(context, key, isPlatformSlice);
|
handleCopyAction(context, sliceUri, key);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleToggleAction(Context context, String key, boolean isChecked,
|
private void handleToggleAction(Context context, Uri sliceUri, String key, boolean isChecked) {
|
||||||
boolean isPlatformSlice) {
|
|
||||||
if (TextUtils.isEmpty(key)) {
|
if (TextUtils.isEmpty(key)) {
|
||||||
throw new IllegalStateException("No key passed to Intent for toggle controller");
|
throw new IllegalStateException("No key passed to Intent for toggle controller");
|
||||||
}
|
}
|
||||||
@@ -125,7 +120,7 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
|||||||
if (!controller.isAvailable()) {
|
if (!controller.isAvailable()) {
|
||||||
Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
|
Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
|
||||||
if (!controller.hasAsyncUpdate()) {
|
if (!controller.hasAsyncUpdate()) {
|
||||||
updateUri(context, key, isPlatformSlice);
|
context.getContentResolver().notifyChange(sliceUri, null /* observer */);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -136,12 +131,11 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
|||||||
toggleController.setChecked(isChecked);
|
toggleController.setChecked(isChecked);
|
||||||
logSliceValueChange(context, key, isChecked ? 1 : 0);
|
logSliceValueChange(context, key, isChecked ? 1 : 0);
|
||||||
if (!controller.hasAsyncUpdate()) {
|
if (!controller.hasAsyncUpdate()) {
|
||||||
updateUri(context, key, isPlatformSlice);
|
context.getContentResolver().notifyChange(sliceUri, null /* observer */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleSliderAction(Context context, String key, int newPosition,
|
private void handleSliderAction(Context context, Uri sliceUri, String key, int newPosition) {
|
||||||
boolean isPlatformSlice) {
|
|
||||||
if (TextUtils.isEmpty(key)) {
|
if (TextUtils.isEmpty(key)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"No key passed to Intent for slider controller. Use extra: " + EXTRA_SLICE_KEY);
|
"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()) {
|
if (!controller.isAvailable()) {
|
||||||
Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
|
Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
|
||||||
updateUri(context, key, isPlatformSlice);
|
context.getContentResolver().notifyChange(sliceUri, null /* observer */);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,10 +168,10 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
|||||||
|
|
||||||
sliderController.setSliderPosition(newPosition);
|
sliderController.setSliderPosition(newPosition);
|
||||||
logSliceValueChange(context, key, 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)) {
|
if (TextUtils.isEmpty(key)) {
|
||||||
throw new IllegalArgumentException("No key passed to Intent for controller");
|
throw new IllegalArgumentException("No key passed to Intent for controller");
|
||||||
}
|
}
|
||||||
@@ -192,7 +186,7 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
|||||||
if (!controller.isAvailable()) {
|
if (!controller.isAvailable()) {
|
||||||
Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
|
Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
|
||||||
if (!controller.hasAsyncUpdate()) {
|
if (!controller.hasAsyncUpdate()) {
|
||||||
updateUri(context, key, isPlatformSlice);
|
context.getContentResolver().notifyChange(sliceUri, null /* observer */);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -217,17 +211,4 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
|||||||
final SliceData sliceData = accessor.getSliceDataFromKey(key);
|
final SliceData sliceData = accessor.getSliceDataFromKey(key);
|
||||||
return SliceBuilderUtils.getPreferenceController(context, sliceData);
|
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.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
|
||||||
import static com.android.settings.slices.SettingsSliceProvider.EXTRA_SLICE_KEY;
|
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.annotation.ColorInt;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
@@ -158,8 +157,7 @@ public class SliceBuilderUtils {
|
|||||||
final Intent intent = new Intent(action)
|
final Intent intent = new Intent(action)
|
||||||
.setData(data.getUri())
|
.setData(data.getUri())
|
||||||
.setClass(context, SliceBroadcastReceiver.class)
|
.setClass(context, SliceBroadcastReceiver.class)
|
||||||
.putExtra(EXTRA_SLICE_KEY, data.getKey())
|
.putExtra(EXTRA_SLICE_KEY, data.getKey());
|
||||||
.putExtra(EXTRA_SLICE_PLATFORM_DEFINED, data.isPlatformDefined());
|
|
||||||
return PendingIntent.getBroadcast(context, 0 /* requestCode */, intent,
|
return PendingIntent.getBroadcast(context, 0 /* requestCode */, intent,
|
||||||
PendingIntent.FLAG_CANCEL_CURRENT);
|
PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,8 +71,6 @@ public class SliceData {
|
|||||||
@SliceType
|
@SliceType
|
||||||
private final int mSliceType;
|
private final int mSliceType;
|
||||||
|
|
||||||
private final boolean mIsPlatformDefined;
|
|
||||||
|
|
||||||
private final String mUnavailableSliceSubtitle;
|
private final String mUnavailableSliceSubtitle;
|
||||||
|
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
@@ -115,10 +113,6 @@ public class SliceData {
|
|||||||
return mSliceType;
|
return mSliceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlatformDefined() {
|
|
||||||
return mIsPlatformDefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUnavailableSliceSubtitle() {
|
public String getUnavailableSliceSubtitle() {
|
||||||
return mUnavailableSliceSubtitle;
|
return mUnavailableSliceSubtitle;
|
||||||
}
|
}
|
||||||
@@ -134,7 +128,6 @@ public class SliceData {
|
|||||||
mUri = builder.mUri;
|
mUri = builder.mUri;
|
||||||
mPreferenceController = builder.mPrefControllerClassName;
|
mPreferenceController = builder.mPrefControllerClassName;
|
||||||
mSliceType = builder.mSliceType;
|
mSliceType = builder.mSliceType;
|
||||||
mIsPlatformDefined = builder.mIsPlatformDefined;
|
|
||||||
mUnavailableSliceSubtitle = builder.mUnavailableSliceSubtitle;
|
mUnavailableSliceSubtitle = builder.mUnavailableSliceSubtitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,8 +166,6 @@ public class SliceData {
|
|||||||
|
|
||||||
private int mSliceType;
|
private int mSliceType;
|
||||||
|
|
||||||
private boolean mIsPlatformDefined;
|
|
||||||
|
|
||||||
private String mUnavailableSliceSubtitle;
|
private String mUnavailableSliceSubtitle;
|
||||||
|
|
||||||
public Builder setKey(String key) {
|
public Builder setKey(String key) {
|
||||||
@@ -227,11 +218,6 @@ public class SliceData {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setPlatformDefined(boolean isPlatformDefined) {
|
|
||||||
mIsPlatformDefined = isPlatformDefined;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setUnavailableSliceSubtitle(
|
public Builder setUnavailableSliceSubtitle(
|
||||||
String unavailableSliceSubtitle) {
|
String unavailableSliceSubtitle) {
|
||||||
mUnavailableSliceSubtitle = 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_CONTROLLER;
|
||||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_ICON;
|
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_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_SUMMARY;
|
||||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_TITLE;
|
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_TITLE;
|
||||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_UNAVAILABLE_SLICE_SUBTITLE;
|
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_TITLE
|
||||||
| MetadataFlag.FLAG_NEED_PREF_ICON
|
| MetadataFlag.FLAG_NEED_PREF_ICON
|
||||||
| MetadataFlag.FLAG_NEED_PREF_SUMMARY
|
| MetadataFlag.FLAG_NEED_PREF_SUMMARY
|
||||||
| MetadataFlag.FLAG_NEED_PLATFORM_SLICE_FLAG
|
|
||||||
| MetadataFlag.FLAG_UNAVAILABLE_SLICE_SUBTITLE);
|
| MetadataFlag.FLAG_UNAVAILABLE_SLICE_SUBTITLE);
|
||||||
|
|
||||||
for (Bundle bundle : metadata) {
|
for (Bundle bundle : metadata) {
|
||||||
@@ -213,7 +211,6 @@ class SliceDataConverter {
|
|||||||
final int iconResId = bundle.getInt(METADATA_ICON);
|
final int iconResId = bundle.getInt(METADATA_ICON);
|
||||||
|
|
||||||
final int sliceType = controller.getSliceType();
|
final int sliceType = controller.getSliceType();
|
||||||
final boolean isPlatformSlice = bundle.getBoolean(METADATA_PLATFORM_SLICE_FLAG);
|
|
||||||
final String unavailableSliceSubtitle = bundle.getString(
|
final String unavailableSliceSubtitle = bundle.getString(
|
||||||
METADATA_UNAVAILABLE_SLICE_SUBTITLE);
|
METADATA_UNAVAILABLE_SLICE_SUBTITLE);
|
||||||
|
|
||||||
@@ -227,7 +224,6 @@ class SliceDataConverter {
|
|||||||
.setPreferenceControllerClassName(controllerClassName)
|
.setPreferenceControllerClassName(controllerClassName)
|
||||||
.setFragmentName(fragmentName)
|
.setFragmentName(fragmentName)
|
||||||
.setSliceType(sliceType)
|
.setSliceType(sliceType)
|
||||||
.setPlatformDefined(isPlatformSlice)
|
|
||||||
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
|
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import android.database.Cursor;
|
|||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
import androidx.slice.Slice;
|
import androidx.slice.Slice;
|
||||||
@@ -47,14 +48,10 @@ public class SlicesDatabaseAccessor {
|
|||||||
IndexColumns.ICON_RESOURCE,
|
IndexColumns.ICON_RESOURCE,
|
||||||
IndexColumns.FRAGMENT,
|
IndexColumns.FRAGMENT,
|
||||||
IndexColumns.CONTROLLER,
|
IndexColumns.CONTROLLER,
|
||||||
IndexColumns.PLATFORM_SLICE,
|
|
||||||
IndexColumns.SLICE_TYPE,
|
IndexColumns.SLICE_TYPE,
|
||||||
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Cursor value for boolean true
|
|
||||||
private static final int TRUE = 1;
|
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final SlicesDatabaseHelper mHelper;
|
private final SlicesDatabaseHelper mHelper;
|
||||||
|
|
||||||
@@ -91,34 +88,29 @@ public class SlicesDatabaseAccessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a list of keys in the Slices database matching on {@param isPlatformSlice}.
|
* @return a list of Slice {@link Uri}s matching {@param authority}.
|
||||||
*/
|
*/
|
||||||
public List<String> getSliceKeys(boolean isPlatformSlice) {
|
public List<Uri> getSliceUris(String authority) {
|
||||||
verifyIndexing();
|
verifyIndexing();
|
||||||
final String whereClause;
|
final List<Uri> uris = new ArrayList<>();
|
||||||
|
|
||||||
if (isPlatformSlice) {
|
|
||||||
whereClause = IndexColumns.PLATFORM_SLICE + " = 1";
|
|
||||||
} else {
|
|
||||||
whereClause = IndexColumns.PLATFORM_SLICE + " = 0";
|
|
||||||
}
|
|
||||||
|
|
||||||
final SQLiteDatabase database = mHelper.getReadableDatabase();
|
final SQLiteDatabase database = mHelper.getReadableDatabase();
|
||||||
final String[] columns = new String[]{IndexColumns.KEY};
|
final String[] columns = new String[]{IndexColumns.SLICE_URI};
|
||||||
final List<String> keys = new ArrayList<>();
|
try (final Cursor resultCursor = database.query(TABLE_SLICES_INDEX, columns,
|
||||||
|
null /* where */, null /* selection */, null /* groupBy */, null /* having */,
|
||||||
try (final Cursor resultCursor = database.query(TABLE_SLICES_INDEX, columns, whereClause,
|
null /* orderBy */)) {
|
||||||
null /* selection */, null /* groupBy */, null /* having */, null /* orderBy */)) {
|
|
||||||
if (!resultCursor.moveToFirst()) {
|
if (!resultCursor.moveToFirst()) {
|
||||||
return keys;
|
return uris;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
keys.add(resultCursor.getString(0 /* key index */));
|
final Uri uri = Uri.parse(resultCursor.getString(0 /* SLICE_URI */));
|
||||||
|
if (TextUtils.isEmpty(authority)
|
||||||
|
|| TextUtils.equals(authority, uri.getAuthority())) {
|
||||||
|
uris.add(uri);
|
||||||
|
}
|
||||||
} while (resultCursor.moveToNext());
|
} while (resultCursor.moveToNext());
|
||||||
}
|
}
|
||||||
|
return uris;
|
||||||
return keys;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Cursor getIndexedSliceData(String path) {
|
private Cursor getIndexedSliceData(String path) {
|
||||||
@@ -163,8 +155,6 @@ public class SlicesDatabaseAccessor {
|
|||||||
cursor.getColumnIndex(IndexColumns.FRAGMENT));
|
cursor.getColumnIndex(IndexColumns.FRAGMENT));
|
||||||
final String controllerClassName = cursor.getString(
|
final String controllerClassName = cursor.getString(
|
||||||
cursor.getColumnIndex(IndexColumns.CONTROLLER));
|
cursor.getColumnIndex(IndexColumns.CONTROLLER));
|
||||||
final boolean isPlatformDefined = cursor.getInt(
|
|
||||||
cursor.getColumnIndex(IndexColumns.PLATFORM_SLICE)) == TRUE;
|
|
||||||
int sliceType = cursor.getInt(
|
int sliceType = cursor.getInt(
|
||||||
cursor.getColumnIndex(IndexColumns.SLICE_TYPE));
|
cursor.getColumnIndex(IndexColumns.SLICE_TYPE));
|
||||||
final String unavailableSliceSubtitle = cursor.getString(
|
final String unavailableSliceSubtitle = cursor.getString(
|
||||||
@@ -184,7 +174,6 @@ public class SlicesDatabaseAccessor {
|
|||||||
.setFragmentName(fragmentClassName)
|
.setFragmentName(fragmentClassName)
|
||||||
.setPreferenceControllerClassName(controllerClassName)
|
.setPreferenceControllerClassName(controllerClassName)
|
||||||
.setUri(uri)
|
.setUri(uri)
|
||||||
.setPlatformDefined(isPlatformDefined)
|
|
||||||
.setSliceType(sliceType)
|
.setSliceType(sliceType)
|
||||||
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
|
.setUnavailableSliceSubtitle(unavailableSliceSubtitle)
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
private static final String DATABASE_NAME = "slices_index.db";
|
private static final String DATABASE_NAME = "slices_index.db";
|
||||||
private static final String SHARED_PREFS_TAG = "slices_shared_prefs";
|
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 {
|
public interface Tables {
|
||||||
String TABLE_SLICES_INDEX = "slices_index";
|
String TABLE_SLICES_INDEX = "slices_index";
|
||||||
@@ -84,11 +84,6 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
*/
|
*/
|
||||||
String CONTROLLER = "controller";
|
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.
|
* {@link SliceData.SliceType} representing the inline type of the result.
|
||||||
*/
|
*/
|
||||||
@@ -126,8 +121,6 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
", " +
|
", " +
|
||||||
IndexColumns.CONTROLLER +
|
IndexColumns.CONTROLLER +
|
||||||
", " +
|
", " +
|
||||||
IndexColumns.PLATFORM_SLICE +
|
|
||||||
", " +
|
|
||||||
IndexColumns.SLICE_TYPE +
|
IndexColumns.SLICE_TYPE +
|
||||||
", " +
|
", " +
|
||||||
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE +
|
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE +
|
||||||
|
|||||||
@@ -109,7 +109,6 @@ class SlicesIndexer implements Runnable {
|
|||||||
values.put(IndexColumns.ICON_RESOURCE, dataRow.getIconResource());
|
values.put(IndexColumns.ICON_RESOURCE, dataRow.getIconResource());
|
||||||
values.put(IndexColumns.FRAGMENT, dataRow.getFragmentClassName());
|
values.put(IndexColumns.FRAGMENT, dataRow.getFragmentClassName());
|
||||||
values.put(IndexColumns.CONTROLLER, dataRow.getPreferenceController());
|
values.put(IndexColumns.CONTROLLER, dataRow.getPreferenceController());
|
||||||
values.put(IndexColumns.PLATFORM_SLICE, dataRow.isPlatformDefined());
|
|
||||||
values.put(IndexColumns.SLICE_TYPE, dataRow.getSliceType());
|
values.put(IndexColumns.SLICE_TYPE, dataRow.getSliceType());
|
||||||
values.put(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
values.put(IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||||
dataRow.getUnavailableSliceSubtitle());
|
dataRow.getUnavailableSliceSubtitle());
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
android:summary="summary"
|
android:summary="summary"
|
||||||
settings:controller="com.android.settings.slices.FakePreferenceController"
|
settings:controller="com.android.settings.slices.FakePreferenceController"
|
||||||
settings:keywords="a, b, c"
|
settings:keywords="a, b, c"
|
||||||
settings:platform_slice="true"
|
|
||||||
settings:unavailableSliceSubtitle="subtitleOfUnavailableSlice"/>
|
settings:unavailableSliceSubtitle="subtitleOfUnavailableSlice"/>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
@@ -27,8 +27,7 @@
|
|||||||
android:icon="@drawable/ic_android"
|
android:icon="@drawable/ic_android"
|
||||||
android:summary="summary"
|
android:summary="summary"
|
||||||
settings:controller="com.android.settings.slices.FakePreferenceController"
|
settings:controller="com.android.settings.slices.FakePreferenceController"
|
||||||
settings:keywords="keyword"
|
settings:keywords="keyword"/>
|
||||||
settings:platform_slice="true"/>
|
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="key2"
|
android:key="key2"
|
||||||
@@ -37,7 +36,6 @@
|
|||||||
android:summary="summary"
|
android:summary="summary"
|
||||||
settings:controller="com.android.settings.slices.FakePreferenceController"
|
settings:controller="com.android.settings.slices.FakePreferenceController"
|
||||||
settings:keywords="keyword"
|
settings:keywords="keyword"
|
||||||
settings:platform_slice="true"
|
|
||||||
settings:unavailableSliceSubtitle="subtitleOfUnavailable"/>
|
settings:unavailableSliceSubtitle="subtitleOfUnavailable"/>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
@@ -34,10 +34,8 @@ import static org.mockito.Mockito.when;
|
|||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.slice.SliceManager;
|
import android.app.slice.SliceManager;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.ContentValues;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -49,7 +47,6 @@ import androidx.slice.Slice;
|
|||||||
import androidx.slice.SliceProvider;
|
import androidx.slice.SliceProvider;
|
||||||
import androidx.slice.widget.SliceLiveData;
|
import androidx.slice.widget.SliceLiveData;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.testutils.DatabaseTestUtils;
|
import com.android.settings.testutils.DatabaseTestUtils;
|
||||||
import com.android.settings.testutils.FakeToggleController;
|
import com.android.settings.testutils.FakeToggleController;
|
||||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||||
@@ -108,13 +105,8 @@ public class SettingsSliceProviderTest {
|
|||||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||||
.appendPath(KEY)
|
.appendPath(KEY)
|
||||||
.build();
|
.build();
|
||||||
private static final String TITLE = "title";
|
|
||||||
private static final String SUMMARY = "summary";
|
|
||||||
private static final String SCREEN_TITLE = "screen title";
|
|
||||||
private static final String FRAGMENT_NAME = "fragment name";
|
|
||||||
private static final int ICON = R.drawable.ic_settings_accent;
|
|
||||||
private static final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
private static final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||||
private static final String PREF_CONTROLLER = FakeToggleController.class.getName();
|
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private SettingsSliceProvider mProvider;
|
private SettingsSliceProvider mProvider;
|
||||||
@@ -164,7 +156,7 @@ public class SettingsSliceProviderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInitialSliceReturned_emptySlice() {
|
public void testInitialSliceReturned_emptySlice() {
|
||||||
insertSpecialCase(KEY);
|
SliceTestUtils.insertSliceToDb(mContext, KEY);
|
||||||
Slice slice = mProvider.onBindSlice(INTENT_SLICE_URI);
|
Slice slice = mProvider.onBindSlice(INTENT_SLICE_URI);
|
||||||
|
|
||||||
assertThat(slice.getUri()).isEqualTo(INTENT_SLICE_URI);
|
assertThat(slice.getUri()).isEqualTo(INTENT_SLICE_URI);
|
||||||
@@ -173,18 +165,18 @@ public class SettingsSliceProviderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadSlice_returnsSliceFromAccessor() {
|
public void testLoadSlice_returnsSliceFromAccessor() {
|
||||||
insertSpecialCase(KEY);
|
SliceTestUtils.insertSliceToDb(mContext, KEY);
|
||||||
|
|
||||||
mProvider.loadSlice(INTENT_SLICE_URI);
|
mProvider.loadSlice(INTENT_SLICE_URI);
|
||||||
SliceData data = mProvider.mSliceWeakDataCache.get(INTENT_SLICE_URI);
|
SliceData data = mProvider.mSliceWeakDataCache.get(INTENT_SLICE_URI);
|
||||||
|
|
||||||
assertThat(data.getKey()).isEqualTo(KEY);
|
assertThat(data.getKey()).isEqualTo(KEY);
|
||||||
assertThat(data.getTitle()).isEqualTo(TITLE);
|
assertThat(data.getTitle()).isEqualTo(SliceTestUtils.FAKE_TITLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loadSlice_registersIntentFilter() {
|
public void loadSlice_registersIntentFilter() {
|
||||||
insertSpecialCase(KEY);
|
SliceTestUtils.insertSliceToDb(mContext, KEY);
|
||||||
|
|
||||||
mProvider.loadSlice(INTENT_SLICE_URI);
|
mProvider.loadSlice(INTENT_SLICE_URI);
|
||||||
|
|
||||||
@@ -194,7 +186,7 @@ public class SettingsSliceProviderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loadSlice_registersBackgroundListener() {
|
public void loadSlice_registersBackgroundListener() {
|
||||||
insertSpecialCase(KEY);
|
SliceTestUtils.insertSliceToDb(mContext, KEY);
|
||||||
|
|
||||||
mProvider.loadSlice(INTENT_SLICE_URI);
|
mProvider.loadSlice(INTENT_SLICE_URI);
|
||||||
|
|
||||||
@@ -210,7 +202,7 @@ public class SettingsSliceProviderTest {
|
|||||||
SliceData data = getDummyData();
|
SliceData data = getDummyData();
|
||||||
mProvider.mSliceWeakDataCache.put(data.getUri(), data);
|
mProvider.mSliceWeakDataCache.put(data.getUri(), data);
|
||||||
mProvider.onBindSlice(data.getUri());
|
mProvider.onBindSlice(data.getUri());
|
||||||
insertSpecialCase(data.getKey());
|
SliceTestUtils.insertSliceToDb(mContext, data.getKey());
|
||||||
|
|
||||||
SliceData cachedData = mProvider.mSliceWeakDataCache.get(data.getUri());
|
SliceData cachedData = mProvider.mSliceWeakDataCache.get(data.getUri());
|
||||||
|
|
||||||
@@ -291,7 +283,7 @@ public class SettingsSliceProviderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getDescendantUris_invalidPath_returnsEmpty() {
|
public void getDescendantUris_invalidPath_returnsEmpty() {
|
||||||
final String key = "platform_key";
|
final String key = "platform_key";
|
||||||
insertSpecialCase(key, true /* isPlatformSlice */);
|
SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */);
|
||||||
final Uri uri = new Uri.Builder()
|
final Uri uri = new Uri.Builder()
|
||||||
.scheme(SCHEME_CONTENT)
|
.scheme(SCHEME_CONTENT)
|
||||||
.authority(SettingsSlicesContract.AUTHORITY)
|
.authority(SettingsSlicesContract.AUTHORITY)
|
||||||
@@ -306,7 +298,7 @@ public class SettingsSliceProviderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDescendantUris_platformSlice_doesNotReturnOEMSlice() {
|
public void getDescendantUris_platformSlice_doesNotReturnOEMSlice() {
|
||||||
insertSpecialCase("oem_key", false /* isPlatformSlice */);
|
SliceTestUtils.insertSliceToDb(mContext, "oem_key", false /* isPlatformSlice */);
|
||||||
final Uri uri = new Uri.Builder()
|
final Uri uri = new Uri.Builder()
|
||||||
.scheme(SCHEME_CONTENT)
|
.scheme(SCHEME_CONTENT)
|
||||||
.authority(SettingsSlicesContract.AUTHORITY)
|
.authority(SettingsSlicesContract.AUTHORITY)
|
||||||
@@ -320,7 +312,7 @@ public class SettingsSliceProviderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDescendantUris_oemSlice_doesNotReturnPlatformSlice() {
|
public void getDescendantUris_oemSlice_doesNotReturnPlatformSlice() {
|
||||||
insertSpecialCase("platform_key", true /* isPlatformSlice */);
|
SliceTestUtils.insertSliceToDb(mContext, "platform_key", true /* isPlatformSlice */);
|
||||||
final Uri uri = new Uri.Builder()
|
final Uri uri = new Uri.Builder()
|
||||||
.scheme(SCHEME_CONTENT)
|
.scheme(SCHEME_CONTENT)
|
||||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||||
@@ -335,7 +327,7 @@ public class SettingsSliceProviderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getDescendantUris_oemSlice_returnsOEMUriDescendant() {
|
public void getDescendantUris_oemSlice_returnsOEMUriDescendant() {
|
||||||
final String key = "oem_key";
|
final String key = "oem_key";
|
||||||
insertSpecialCase(key, false /* isPlatformSlice */);
|
SliceTestUtils.insertSliceToDb(mContext, key, false /* isPlatformSlice */);
|
||||||
final Uri uri = new Uri.Builder()
|
final Uri uri = new Uri.Builder()
|
||||||
.scheme(SCHEME_CONTENT)
|
.scheme(SCHEME_CONTENT)
|
||||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||||
@@ -358,7 +350,7 @@ public class SettingsSliceProviderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getDescendantUris_oemSliceNoPath_returnsOEMUriDescendant() {
|
public void getDescendantUris_oemSliceNoPath_returnsOEMUriDescendant() {
|
||||||
final String key = "oem_key";
|
final String key = "oem_key";
|
||||||
insertSpecialCase(key, false /* isPlatformSlice */);
|
SliceTestUtils.insertSliceToDb(mContext, key, false /* isPlatformSlice */);
|
||||||
final Uri uri = new Uri.Builder()
|
final Uri uri = new Uri.Builder()
|
||||||
.scheme(SCHEME_CONTENT)
|
.scheme(SCHEME_CONTENT)
|
||||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||||
@@ -380,7 +372,7 @@ public class SettingsSliceProviderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getDescendantUris_platformSlice_returnsPlatformUriDescendant() {
|
public void getDescendantUris_platformSlice_returnsPlatformUriDescendant() {
|
||||||
final String key = "platform_key";
|
final String key = "platform_key";
|
||||||
insertSpecialCase(key, true /* isPlatformSlice */);
|
SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */);
|
||||||
final Uri uri = new Uri.Builder()
|
final Uri uri = new Uri.Builder()
|
||||||
.scheme(SCHEME_CONTENT)
|
.scheme(SCHEME_CONTENT)
|
||||||
.authority(SettingsSlicesContract.AUTHORITY)
|
.authority(SettingsSlicesContract.AUTHORITY)
|
||||||
@@ -403,7 +395,7 @@ public class SettingsSliceProviderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getDescendantUris_platformSliceNoPath_returnsPlatformUriDescendant() {
|
public void getDescendantUris_platformSliceNoPath_returnsPlatformUriDescendant() {
|
||||||
final String key = "platform_key";
|
final String key = "platform_key";
|
||||||
insertSpecialCase(key, true /* isPlatformSlice */);
|
SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */);
|
||||||
final Uri uri = new Uri.Builder()
|
final Uri uri = new Uri.Builder()
|
||||||
.scheme(SCHEME_CONTENT)
|
.scheme(SCHEME_CONTENT)
|
||||||
.authority(SettingsSlicesContract.AUTHORITY)
|
.authority(SettingsSlicesContract.AUTHORITY)
|
||||||
@@ -426,8 +418,8 @@ public class SettingsSliceProviderTest {
|
|||||||
public void getDescendantUris_noAuthorityNorPath_returnsAllUris() {
|
public void getDescendantUris_noAuthorityNorPath_returnsAllUris() {
|
||||||
final String platformKey = "platform_key";
|
final String platformKey = "platform_key";
|
||||||
final String oemKey = "oemKey";
|
final String oemKey = "oemKey";
|
||||||
insertSpecialCase(platformKey, true /* isPlatformSlice */);
|
SliceTestUtils.insertSliceToDb(mContext, platformKey, true /* isPlatformSlice */);
|
||||||
insertSpecialCase(oemKey, false /* isPlatformSlice */);
|
SliceTestUtils.insertSliceToDb(mContext, oemKey, false /* isPlatformSlice */);
|
||||||
final Uri uri = new Uri.Builder()
|
final Uri uri = new Uri.Builder()
|
||||||
.scheme(SCHEME_CONTENT)
|
.scheme(SCHEME_CONTENT)
|
||||||
.build();
|
.build();
|
||||||
@@ -492,31 +484,6 @@ public class SettingsSliceProviderTest {
|
|||||||
mProvider.onSlicePinned(uri);
|
mProvider.onSlicePinned(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Implements(WifiScanWorker.class)
|
|
||||||
public static class ShadowWifiScanWorker {
|
|
||||||
private static WifiTracker mWifiTracker;
|
|
||||||
|
|
||||||
@Implementation
|
|
||||||
protected void onSlicePinned() {
|
|
||||||
mWifiTracker = mock(WifiTracker.class);
|
|
||||||
mWifiTracker.onStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Implementation
|
|
||||||
protected void onSliceUnpinned() {
|
|
||||||
mWifiTracker.onStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Implementation
|
|
||||||
protected void close() {
|
|
||||||
mWifiTracker.onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
static WifiTracker getWifiTracker() {
|
|
||||||
return mWifiTracker;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onSlicePinned_backgroundWorker_started() {
|
public void onSlicePinned_backgroundWorker_started() {
|
||||||
mProvider.onSlicePinned(CustomSliceRegistry.WIFI_SLICE_URI);
|
mProvider.onSlicePinned(CustomSliceRegistry.WIFI_SLICE_URI);
|
||||||
@@ -563,45 +530,44 @@ public class SettingsSliceProviderTest {
|
|||||||
.grantSlicePermission("com.android.settings.slice_whitelist_package", uris.get(0));
|
.grantSlicePermission("com.android.settings.slice_whitelist_package", uris.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertSpecialCase(String key) {
|
|
||||||
insertSpecialCase(key, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void insertSpecialCase(String key, boolean isPlatformSlice) {
|
|
||||||
final ContentValues values = new ContentValues();
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.KEY, key);
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.TITLE, TITLE);
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.SUMMARY, "s");
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.SCREENTITLE, "s");
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.ICON_RESOURCE, R.drawable.ic_settings_accent);
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.FRAGMENT, "test");
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.CONTROLLER, PREF_CONTROLLER);
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.PLATFORM_SLICE, isPlatformSlice);
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.SLICE_TYPE, SliceData.SliceType.INTENT);
|
|
||||||
final SQLiteDatabase db = SlicesDatabaseHelper.getInstance(mContext).getWritableDatabase();
|
|
||||||
db.beginTransaction();
|
|
||||||
try {
|
|
||||||
db.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
|
|
||||||
db.setTransactionSuccessful();
|
|
||||||
} finally {
|
|
||||||
db.endTransaction();
|
|
||||||
}
|
|
||||||
db.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static SliceData getDummyData() {
|
private static SliceData getDummyData() {
|
||||||
return new SliceData.Builder()
|
return new SliceData.Builder()
|
||||||
.setKey(KEY)
|
.setKey(KEY)
|
||||||
.setTitle(TITLE)
|
|
||||||
.setSummary(SUMMARY)
|
|
||||||
.setScreenTitle(SCREEN_TITLE)
|
|
||||||
.setIcon(ICON)
|
|
||||||
.setFragmentName(FRAGMENT_NAME)
|
|
||||||
.setUri(URI)
|
.setUri(URI)
|
||||||
.setPreferenceControllerClassName(PREF_CONTROLLER)
|
.setTitle(SliceTestUtils.FAKE_TITLE)
|
||||||
|
.setSummary(SliceTestUtils.FAKE_SUMMARY)
|
||||||
|
.setScreenTitle(SliceTestUtils.FAKE_SCREEN_TITLE)
|
||||||
|
.setIcon(SliceTestUtils.FAKE_ICON)
|
||||||
|
.setFragmentName(SliceTestUtils.FAKE_FRAGMENT_NAME)
|
||||||
|
.setPreferenceControllerClassName(SliceTestUtils.FAKE_CONTROLLER_NAME)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Implements(WifiScanWorker.class)
|
||||||
|
public static class ShadowWifiScanWorker {
|
||||||
|
private static WifiTracker mWifiTracker;
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
protected void onSlicePinned() {
|
||||||
|
mWifiTracker = mock(WifiTracker.class);
|
||||||
|
mWifiTracker.onStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
protected void onSliceUnpinned() {
|
||||||
|
mWifiTracker.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
protected void close() {
|
||||||
|
mWifiTracker.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
static WifiTracker getWifiTracker() {
|
||||||
|
return mWifiTracker;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Implements(value = StrictMode.class)
|
@Implements(value = StrictMode.class)
|
||||||
public static class ShadowStrictMode {
|
public static class ShadowStrictMode {
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ import com.android.settings.search.SearchFeatureProvider;
|
|||||||
import com.android.settings.search.SearchFeatureProviderImpl;
|
import com.android.settings.search.SearchFeatureProviderImpl;
|
||||||
import com.android.settings.testutils.DatabaseTestUtils;
|
import com.android.settings.testutils.DatabaseTestUtils;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.FakeIndexProvider;
|
|
||||||
import com.android.settings.testutils.FakeSliderController;
|
import com.android.settings.testutils.FakeSliderController;
|
||||||
import com.android.settings.testutils.FakeToggleController;
|
import com.android.settings.testutils.FakeToggleController;
|
||||||
|
|
||||||
@@ -57,13 +56,6 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class SliceBroadcastReceiverTest {
|
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 Context mContext;
|
||||||
private SQLiteDatabase mDb;
|
private SQLiteDatabase mDb;
|
||||||
private SliceBroadcastReceiver mReceiver;
|
private SliceBroadcastReceiver mReceiver;
|
||||||
@@ -90,21 +82,18 @@ public class SliceBroadcastReceiverTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onReceive_toggleChanged() {
|
public void onReceive_toggleChanged() {
|
||||||
final String key = "key";
|
final String key = "key";
|
||||||
final Uri uri = new Uri.Builder()
|
final Uri uri = buildUri(key);
|
||||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
|
||||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
|
||||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
|
||||||
.appendPath(key)
|
|
||||||
.build();
|
|
||||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||||
insertSpecialCase(key);
|
insertSpecialCase(key);
|
||||||
final ContentResolver resolver = mock(ContentResolver.class);
|
final ContentResolver resolver = mock(ContentResolver.class);
|
||||||
doReturn(resolver).when(mContext).getContentResolver();
|
doReturn(resolver).when(mContext).getContentResolver();
|
||||||
// Turn on toggle setting
|
// Turn on toggle setting
|
||||||
FakeToggleController fakeToggleController = new FakeToggleController(mContext, key);
|
final FakeToggleController fakeToggleController = new FakeToggleController(mContext, key);
|
||||||
fakeToggleController.setChecked(true);
|
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();
|
assertThat(fakeToggleController.isChecked()).isTrue();
|
||||||
|
|
||||||
@@ -128,6 +117,8 @@ public class SliceBroadcastReceiverTest {
|
|||||||
doReturn(resolver).when(mContext).getContentResolver();
|
doReturn(resolver).when(mContext).getContentResolver();
|
||||||
|
|
||||||
final String key = "key";
|
final String key = "key";
|
||||||
|
final Uri expectedUri = buildUri(key);
|
||||||
|
|
||||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||||
insertSpecialCase(key);
|
insertSpecialCase(key);
|
||||||
|
|
||||||
@@ -135,8 +126,9 @@ public class SliceBroadcastReceiverTest {
|
|||||||
fakeToggleController.setChecked(true);
|
fakeToggleController.setChecked(true);
|
||||||
// Set the toggle setting update synchronously.
|
// Set the toggle setting update synchronously.
|
||||||
fakeToggleController.setAsyncUpdate(false);
|
fakeToggleController.setAsyncUpdate(false);
|
||||||
Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED);
|
final Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED)
|
||||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key)
|
||||||
|
.setData(expectedUri);
|
||||||
|
|
||||||
assertThat(fakeToggleController.isChecked()).isTrue();
|
assertThat(fakeToggleController.isChecked()).isTrue();
|
||||||
|
|
||||||
@@ -145,12 +137,6 @@ public class SliceBroadcastReceiverTest {
|
|||||||
|
|
||||||
assertThat(fakeToggleController.isChecked()).isFalse();
|
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);
|
verify(resolver).notifyChange(expectedUri, null);
|
||||||
}
|
}
|
||||||
@@ -163,16 +149,11 @@ public class SliceBroadcastReceiverTest {
|
|||||||
|
|
||||||
final String key = "key";
|
final String key = "key";
|
||||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||||
insertSpecialCase(key);
|
insertSpecialCase(AsyncToggleController.class.getName(), key);
|
||||||
|
|
||||||
FakeToggleController fakeToggleController = new FakeToggleController(mContext, key);
|
final Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED)
|
||||||
fakeToggleController.setChecked(true);
|
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key)
|
||||||
// Set the toggle setting update asynchronously.
|
.setData(buildUri(key));
|
||||||
fakeToggleController.setAsyncUpdate(true);
|
|
||||||
Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED);
|
|
||||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
|
||||||
|
|
||||||
assertThat(fakeToggleController.isChecked()).isTrue();
|
|
||||||
|
|
||||||
// Toggle setting
|
// Toggle setting
|
||||||
mReceiver.onReceive(mContext, intent);
|
mReceiver.onReceive(mContext, intent);
|
||||||
@@ -183,26 +164,22 @@ public class SliceBroadcastReceiverTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onReceive_sliderChanged() {
|
public void onReceive_sliderChanged() {
|
||||||
final String key = "key";
|
final String key = "key";
|
||||||
final Uri uri = new Uri.Builder()
|
final Uri uri = buildUri(key);
|
||||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
|
||||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
|
||||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
|
||||||
.appendPath(key)
|
|
||||||
.build();
|
|
||||||
final ContentResolver resolver = mock(ContentResolver.class);
|
final ContentResolver resolver = mock(ContentResolver.class);
|
||||||
doReturn(resolver).when(mContext).getContentResolver();
|
doReturn(resolver).when(mContext).getContentResolver();
|
||||||
final int position = FakeSliderController.MAX_VALUE - 1;
|
final int position = FakeSliderController.MAX_VALUE - 1;
|
||||||
final int oldPosition = FakeSliderController.MAX_VALUE;
|
final int oldPosition = FakeSliderController.MAX_VALUE;
|
||||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||||
insertSpecialCase(FakeSliderController.class, key);
|
insertSpecialCase(FakeSliderController.class.getName(), key);
|
||||||
|
|
||||||
// Set slider setting
|
// Set slider setting
|
||||||
FakeSliderController fakeSliderController = new FakeSliderController(mContext, key);
|
FakeSliderController fakeSliderController = new FakeSliderController(mContext, key);
|
||||||
fakeSliderController.setSliderPosition(oldPosition);
|
fakeSliderController.setSliderPosition(oldPosition);
|
||||||
// Build action
|
// Build action
|
||||||
Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED);
|
final Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED)
|
||||||
intent.putExtra(Slice.EXTRA_RANGE_VALUE, position);
|
.putExtra(Slice.EXTRA_RANGE_VALUE, position)
|
||||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key)
|
||||||
|
.setData(uri);
|
||||||
|
|
||||||
assertThat(fakeSliderController.getSliderPosition()).isEqualTo(oldPosition);
|
assertThat(fakeSliderController.getSliderPosition()).isEqualTo(oldPosition);
|
||||||
|
|
||||||
@@ -225,12 +202,12 @@ public class SliceBroadcastReceiverTest {
|
|||||||
final String key = "key";
|
final String key = "key";
|
||||||
final int position = 0;
|
final int position = 0;
|
||||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||||
insertSpecialCase(FakeToggleController.class, key);
|
insertSpecialCase(key);
|
||||||
|
|
||||||
// Build action
|
// Build action
|
||||||
Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED);
|
final Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED)
|
||||||
intent.putExtra(Slice.EXTRA_RANGE_VALUE, position);
|
.putExtra(Slice.EXTRA_RANGE_VALUE, position)
|
||||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
||||||
|
|
||||||
// Trigger the exception.
|
// Trigger the exception.
|
||||||
mReceiver.onReceive(mContext, intent);
|
mReceiver.onReceive(mContext, intent);
|
||||||
@@ -272,29 +249,25 @@ public class SliceBroadcastReceiverTest {
|
|||||||
|
|
||||||
// Insert Fake Toggle into Database
|
// Insert Fake Toggle into Database
|
||||||
final String key = "key";
|
final String key = "key";
|
||||||
|
final Uri expectedUri = buildUri(key);
|
||||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||||
insertSpecialCase(FakeToggleController.class, key);
|
insertSpecialCase(key);
|
||||||
|
|
||||||
// Turn on toggle setting
|
// Turn on toggle setting
|
||||||
final FakeToggleController fakeToggleController = new FakeToggleController(mContext, key);
|
final FakeToggleController fakeToggleController = new FakeToggleController(mContext, key);
|
||||||
fakeToggleController.setChecked(true);
|
fakeToggleController.setChecked(true);
|
||||||
|
|
||||||
// Build Action
|
// Build Action
|
||||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED);
|
final Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED)
|
||||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key)
|
||||||
|
.setData(expectedUri);
|
||||||
|
|
||||||
// Trigger Slice change
|
// Trigger Slice change
|
||||||
mReceiver.onReceive(mContext, intent);
|
mReceiver.onReceive(mContext, intent);
|
||||||
|
|
||||||
// Check the value is the same and the Uri has been notified.
|
// Check the value is the same and the Uri has been notified.
|
||||||
assertThat(fakeToggleController.isChecked()).isTrue();
|
assertThat(fakeToggleController.isChecked()).isTrue();
|
||||||
final Uri expectedUri = new Uri.Builder()
|
verify(resolver).notifyChange(expectedUri, null);
|
||||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
|
||||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
|
||||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
|
||||||
.appendPath(key)
|
|
||||||
.build();
|
|
||||||
verify(resolver).notifyChange(eq(expectedUri), eq(null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -310,47 +283,65 @@ public class SliceBroadcastReceiverTest {
|
|||||||
|
|
||||||
// Insert Fake Slider into Database
|
// Insert Fake Slider into Database
|
||||||
final String key = "key";
|
final String key = "key";
|
||||||
|
final Uri expectedUri = buildUri(key);
|
||||||
|
|
||||||
final int position = FakeSliderController.MAX_VALUE - 1;
|
final int position = FakeSliderController.MAX_VALUE - 1;
|
||||||
final int oldPosition = FakeSliderController.MAX_VALUE;
|
final int oldPosition = FakeSliderController.MAX_VALUE;
|
||||||
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
|
||||||
insertSpecialCase(FakeSliderController.class, key);
|
insertSpecialCase(FakeSliderController.class.getName(), key);
|
||||||
|
|
||||||
// Set slider setting
|
// Set slider setting
|
||||||
final FakeSliderController fakeSliderController = new FakeSliderController(mContext, key);
|
final FakeSliderController fakeSliderController = new FakeSliderController(mContext, key);
|
||||||
fakeSliderController.setSliderPosition(oldPosition);
|
fakeSliderController.setSliderPosition(oldPosition);
|
||||||
|
|
||||||
// Build action
|
// Build action
|
||||||
final Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED);
|
final Intent intent = new Intent(SettingsSliceProvider.ACTION_SLIDER_CHANGED)
|
||||||
intent.putExtra(Slice.EXTRA_RANGE_VALUE, position);
|
.putExtra(Slice.EXTRA_RANGE_VALUE, position)
|
||||||
intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
|
.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key)
|
||||||
|
.setData(expectedUri);
|
||||||
|
|
||||||
// Trigger Slice change
|
// Trigger Slice change
|
||||||
mReceiver.onReceive(mContext, intent);
|
mReceiver.onReceive(mContext, intent);
|
||||||
|
|
||||||
// Check position is the same and the Uri has been notified.
|
// Check position is the same and the Uri has been notified.
|
||||||
assertThat(fakeSliderController.getSliderPosition()).isEqualTo(oldPosition);
|
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)
|
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||||
.appendPath(key)
|
.appendPath(key)
|
||||||
.build();
|
.build();
|
||||||
verify(resolver).notifyChange(eq(expectedUri), eq(null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertSpecialCase(String key) {
|
public static class AsyncToggleController extends FakeToggleController {
|
||||||
insertSpecialCase(fakeControllerName, key);
|
public AsyncToggleController(Context context, String preferenceKey) {
|
||||||
}
|
super(context, preferenceKey);
|
||||||
|
}
|
||||||
|
|
||||||
private void insertSpecialCase(Class controllerClass, String key) {
|
@Override
|
||||||
ContentValues values = new ContentValues();
|
public boolean hasAsyncUpdate() {
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.KEY, key);
|
return true;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,7 +124,6 @@ public class SliceDataConverterTest {
|
|||||||
assertThat(fakeSlice.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_CLASSNAME);
|
assertThat(fakeSlice.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_CLASSNAME);
|
||||||
assertThat(fakeSlice.getPreferenceController()).isEqualTo(FAKE_CONTROLLER_NAME);
|
assertThat(fakeSlice.getPreferenceController()).isEqualTo(FAKE_CONTROLLER_NAME);
|
||||||
assertThat(fakeSlice.getSliceType()).isEqualTo(SliceData.SliceType.SLIDER);
|
assertThat(fakeSlice.getSliceType()).isEqualTo(SliceData.SliceType.SLIDER);
|
||||||
assertThat(fakeSlice.isPlatformDefined()).isTrue(); // from XML
|
|
||||||
assertThat(fakeSlice.getUnavailableSliceSubtitle()).isEqualTo(
|
assertThat(fakeSlice.getUnavailableSliceSubtitle()).isEqualTo(
|
||||||
"subtitleOfUnavailableSlice"); // from XML
|
"subtitleOfUnavailableSlice"); // from XML
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ public class SliceDataTest {
|
|||||||
private final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
private final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||||
private final String PREF_CONTROLLER = "com.android.settings.slices.tester";
|
private final String PREF_CONTROLLER = "com.android.settings.slices.tester";
|
||||||
private final int SLICE_TYPE = SliceData.SliceType.SWITCH;
|
private final int SLICE_TYPE = SliceData.SliceType.SWITCH;
|
||||||
private final boolean IS_PLATFORM_DEFINED = true;
|
|
||||||
private final String UNAVAILABLE_SLICE_SUBTITLE = "subtitleOfUnavailableSlice";
|
private final String UNAVAILABLE_SLICE_SUBTITLE = "subtitleOfUnavailableSlice";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -53,7 +52,6 @@ public class SliceDataTest {
|
|||||||
.setUri(URI)
|
.setUri(URI)
|
||||||
.setPreferenceControllerClassName(PREF_CONTROLLER)
|
.setPreferenceControllerClassName(PREF_CONTROLLER)
|
||||||
.setSliceType(SLICE_TYPE)
|
.setSliceType(SLICE_TYPE)
|
||||||
.setPlatformDefined(IS_PLATFORM_DEFINED)
|
|
||||||
.setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE);
|
.setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE);
|
||||||
|
|
||||||
SliceData data = builder.build();
|
SliceData data = builder.build();
|
||||||
@@ -68,7 +66,6 @@ public class SliceDataTest {
|
|||||||
assertThat(data.getUri()).isEqualTo(URI);
|
assertThat(data.getUri()).isEqualTo(URI);
|
||||||
assertThat(data.getPreferenceController()).isEqualTo(PREF_CONTROLLER);
|
assertThat(data.getPreferenceController()).isEqualTo(PREF_CONTROLLER);
|
||||||
assertThat(data.getSliceType()).isEqualTo(SLICE_TYPE);
|
assertThat(data.getSliceType()).isEqualTo(SLICE_TYPE);
|
||||||
assertThat(data.isPlatformDefined()).isEqualTo(IS_PLATFORM_DEFINED);
|
|
||||||
assertThat(data.getUnavailableSliceSubtitle()).isEqualTo(UNAVAILABLE_SLICE_SUBTITLE);
|
assertThat(data.getUnavailableSliceSubtitle()).isEqualTo(UNAVAILABLE_SLICE_SUBTITLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.slices;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.provider.SettingsSlicesContract;
|
||||||
|
|
||||||
|
import com.android.settings.testutils.FakeIndexProvider;
|
||||||
|
import com.android.settings.testutils.FakeToggleController;
|
||||||
|
|
||||||
|
class SliceTestUtils {
|
||||||
|
|
||||||
|
public static final String FAKE_TITLE = "title";
|
||||||
|
public static final String FAKE_SUMMARY = "summary";
|
||||||
|
public static final String FAKE_SCREEN_TITLE = "screen_title";
|
||||||
|
public static final String FAKE_KEYWORDS = "a, b, c";
|
||||||
|
public static final int FAKE_ICON = 1234;
|
||||||
|
public static final String FAKE_FRAGMENT_NAME = FakeIndexProvider.class.getName();
|
||||||
|
public static final String FAKE_CONTROLLER_NAME = FakeToggleController.class.getName();
|
||||||
|
|
||||||
|
|
||||||
|
public static void insertSliceToDb(Context context, String key) {
|
||||||
|
insertSliceToDb(context, key, true /* isPlatformSlice */);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void insertSliceToDb(Context context, String key, boolean isPlatformSlice) {
|
||||||
|
insertSliceToDb(context, key, isPlatformSlice, null /*customizedUnavailableSliceSubtitle*/);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void insertSliceToDb(Context context, String key, boolean isPlatformSlice,
|
||||||
|
String customizedUnavailableSliceSubtitle) {
|
||||||
|
final SQLiteDatabase db = SlicesDatabaseHelper.getInstance(context).getWritableDatabase();
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(SlicesDatabaseHelper.IndexColumns.KEY, key);
|
||||||
|
values.put(SlicesDatabaseHelper.IndexColumns.SLICE_URI,
|
||||||
|
new Uri.Builder()
|
||||||
|
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||||
|
.authority(isPlatformSlice
|
||||||
|
? SettingsSlicesContract.AUTHORITY
|
||||||
|
: SettingsSliceProvider.SLICE_AUTHORITY)
|
||||||
|
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||||
|
.appendPath(key)
|
||||||
|
.build().toSafeString());
|
||||||
|
values.put(SlicesDatabaseHelper.IndexColumns.TITLE, FAKE_TITLE);
|
||||||
|
values.put(SlicesDatabaseHelper.IndexColumns.SUMMARY, FAKE_SUMMARY);
|
||||||
|
values.put(SlicesDatabaseHelper.IndexColumns.SCREENTITLE, FAKE_SCREEN_TITLE);
|
||||||
|
values.put(SlicesDatabaseHelper.IndexColumns.KEYWORDS, FAKE_KEYWORDS);
|
||||||
|
values.put(SlicesDatabaseHelper.IndexColumns.ICON_RESOURCE, FAKE_ICON);
|
||||||
|
values.put(SlicesDatabaseHelper.IndexColumns.FRAGMENT, FAKE_FRAGMENT_NAME);
|
||||||
|
values.put(SlicesDatabaseHelper.IndexColumns.CONTROLLER, FAKE_CONTROLLER_NAME);
|
||||||
|
values.put(SlicesDatabaseHelper.IndexColumns.SLICE_TYPE, SliceData.SliceType.INTENT);
|
||||||
|
values.put(SlicesDatabaseHelper.IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||||
|
customizedUnavailableSliceSubtitle);
|
||||||
|
|
||||||
|
db.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ import android.content.ContentValues;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.provider.SettingsSlicesContract;
|
||||||
import android.view.accessibility.AccessibilityManager;
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
|
||||||
import com.android.settings.search.SearchFeatureProvider;
|
import com.android.settings.search.SearchFeatureProvider;
|
||||||
@@ -62,16 +63,8 @@ import java.util.Locale;
|
|||||||
ShadowBluetoothAdapter.class, ShadowLockPatternUtils.class})
|
ShadowBluetoothAdapter.class, ShadowLockPatternUtils.class})
|
||||||
public class SlicesDatabaseAccessorTest {
|
public class SlicesDatabaseAccessorTest {
|
||||||
|
|
||||||
private final String FAKE_TITLE = "title";
|
|
||||||
private final String FAKE_SUMMARY = "summary";
|
|
||||||
private final String FAKE_SCREEN_TITLE = "screen_title";
|
|
||||||
private final String FAKE_KEYWORDS = "a, b, c";
|
|
||||||
private final int FAKE_ICON = 1234;
|
|
||||||
private final String FAKE_FRAGMENT_NAME = FakeIndexProvider.class.getName();
|
|
||||||
private final String FAKE_CONTROLLER_NAME = FakePreferenceController.class.getName();
|
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private SQLiteDatabase mDb;
|
|
||||||
private SlicesDatabaseAccessor mAccessor;
|
private SlicesDatabaseAccessor mAccessor;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -79,7 +72,6 @@ public class SlicesDatabaseAccessorTest {
|
|||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
ShadowUserManager.getShadow().setIsAdminUser(true);
|
ShadowUserManager.getShadow().setIsAdminUser(true);
|
||||||
mAccessor = spy(new SlicesDatabaseAccessor(mContext));
|
mAccessor = spy(new SlicesDatabaseAccessor(mContext));
|
||||||
mDb = SlicesDatabaseHelper.getInstance(mContext).getWritableDatabase();
|
|
||||||
SlicesDatabaseHelper.getInstance(mContext).setIndexedState();
|
SlicesDatabaseHelper.getInstance(mContext).setIndexedState();
|
||||||
|
|
||||||
// Register the fake a11y Service
|
// Register the fake a11y Service
|
||||||
@@ -96,39 +88,39 @@ public class SlicesDatabaseAccessorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetSliceDataFromKey_validKey_validSliceReturned() {
|
public void testGetSliceDataFromKey_validKey_validSliceReturned() {
|
||||||
String key = "key";
|
String key = "key";
|
||||||
insertSpecialCase(key);
|
SliceTestUtils.insertSliceToDb(mContext, key);
|
||||||
|
|
||||||
SliceData data = mAccessor.getSliceDataFromKey(key);
|
SliceData data = mAccessor.getSliceDataFromKey(key);
|
||||||
|
|
||||||
assertThat(data.getKey()).isEqualTo(key);
|
assertThat(data.getKey()).isEqualTo(key);
|
||||||
assertThat(data.getTitle()).isEqualTo(FAKE_TITLE);
|
assertThat(data.getTitle()).isEqualTo(SliceTestUtils.FAKE_TITLE);
|
||||||
assertThat(data.getSummary()).isEqualTo(FAKE_SUMMARY);
|
assertThat(data.getSummary()).isEqualTo(SliceTestUtils.FAKE_SUMMARY);
|
||||||
assertThat(data.getScreenTitle()).isEqualTo(FAKE_SCREEN_TITLE);
|
assertThat(data.getScreenTitle()).isEqualTo(SliceTestUtils.FAKE_SCREEN_TITLE);
|
||||||
assertThat(data.getKeywords()).isEqualTo(FAKE_KEYWORDS);
|
assertThat(data.getKeywords()).isEqualTo(SliceTestUtils.FAKE_KEYWORDS);
|
||||||
assertThat(data.getIconResource()).isEqualTo(FAKE_ICON);
|
assertThat(data.getIconResource()).isEqualTo(SliceTestUtils.FAKE_ICON);
|
||||||
assertThat(data.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_NAME);
|
assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||||
assertThat(data.getUri()).isNull();
|
assertThat(data.getUri()).isNull();
|
||||||
assertThat(data.getPreferenceController()).isEqualTo(FAKE_CONTROLLER_NAME);
|
assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME);
|
||||||
assertThat(data.getUnavailableSliceSubtitle()).isNull();
|
assertThat(data.getUnavailableSliceSubtitle()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetSliceDataFromKey_allowDynamicSummary_validSliceReturned() {
|
public void testGetSliceDataFromKey_allowDynamicSummary_validSliceReturned() {
|
||||||
String key = "key";
|
String key = "key";
|
||||||
insertSpecialCase(key, true /* isPlatformSlice */,
|
SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */,
|
||||||
null /* customizedUnavailableSliceSubtitle */);
|
null /* customizedUnavailableSliceSubtitle */);
|
||||||
|
|
||||||
SliceData data = mAccessor.getSliceDataFromKey(key);
|
SliceData data = mAccessor.getSliceDataFromKey(key);
|
||||||
|
|
||||||
assertThat(data.getKey()).isEqualTo(key);
|
assertThat(data.getKey()).isEqualTo(key);
|
||||||
assertThat(data.getTitle()).isEqualTo(FAKE_TITLE);
|
assertThat(data.getTitle()).isEqualTo(SliceTestUtils.FAKE_TITLE);
|
||||||
assertThat(data.getSummary()).isEqualTo(FAKE_SUMMARY);
|
assertThat(data.getSummary()).isEqualTo(SliceTestUtils.FAKE_SUMMARY);
|
||||||
assertThat(data.getScreenTitle()).isEqualTo(FAKE_SCREEN_TITLE);
|
assertThat(data.getScreenTitle()).isEqualTo(SliceTestUtils.FAKE_SCREEN_TITLE);
|
||||||
assertThat(data.getKeywords()).isEqualTo(FAKE_KEYWORDS);
|
assertThat(data.getKeywords()).isEqualTo(SliceTestUtils.FAKE_KEYWORDS);
|
||||||
assertThat(data.getIconResource()).isEqualTo(FAKE_ICON);
|
assertThat(data.getIconResource()).isEqualTo(SliceTestUtils.FAKE_ICON);
|
||||||
assertThat(data.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_NAME);
|
assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||||
assertThat(data.getUri()).isNull();
|
assertThat(data.getUri()).isNull();
|
||||||
assertThat(data.getPreferenceController()).isEqualTo(FAKE_CONTROLLER_NAME);
|
assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
@Test(expected = IllegalStateException.class)
|
||||||
@@ -141,7 +133,7 @@ public class SlicesDatabaseAccessorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetSliceFromUri_validUri_validSliceReturned() {
|
public void testGetSliceFromUri_validUri_validSliceReturned() {
|
||||||
final String key = "key";
|
final String key = "key";
|
||||||
insertSpecialCase(key);
|
SliceTestUtils.insertSliceToDb(mContext, key);
|
||||||
|
|
||||||
final Uri uri = new Uri.Builder()
|
final Uri uri = new Uri.Builder()
|
||||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||||
@@ -153,14 +145,14 @@ public class SlicesDatabaseAccessorTest {
|
|||||||
SliceData data = mAccessor.getSliceDataFromUri(uri);
|
SliceData data = mAccessor.getSliceDataFromUri(uri);
|
||||||
|
|
||||||
assertThat(data.getKey()).isEqualTo(key);
|
assertThat(data.getKey()).isEqualTo(key);
|
||||||
assertThat(data.getTitle()).isEqualTo(FAKE_TITLE);
|
assertThat(data.getTitle()).isEqualTo(SliceTestUtils.FAKE_TITLE);
|
||||||
assertThat(data.getSummary()).isEqualTo(FAKE_SUMMARY);
|
assertThat(data.getSummary()).isEqualTo(SliceTestUtils.FAKE_SUMMARY);
|
||||||
assertThat(data.getScreenTitle()).isEqualTo(FAKE_SCREEN_TITLE);
|
assertThat(data.getScreenTitle()).isEqualTo(SliceTestUtils.FAKE_SCREEN_TITLE);
|
||||||
assertThat(data.getKeywords()).isEqualTo(FAKE_KEYWORDS);
|
assertThat(data.getKeywords()).isEqualTo(SliceTestUtils.FAKE_KEYWORDS);
|
||||||
assertThat(data.getIconResource()).isEqualTo(FAKE_ICON);
|
assertThat(data.getIconResource()).isEqualTo(SliceTestUtils.FAKE_ICON);
|
||||||
assertThat(data.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_NAME);
|
assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||||
assertThat(data.getUri()).isEqualTo(uri);
|
assertThat(data.getUri()).isEqualTo(uri);
|
||||||
assertThat(data.getPreferenceController()).isEqualTo(FAKE_CONTROLLER_NAME);
|
assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
@Test(expected = IllegalStateException.class)
|
||||||
@@ -177,9 +169,8 @@ public class SlicesDatabaseAccessorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getDescendantUris_platformSlice_doesNotReturnOEMSlice() {
|
public void getDescendantUris_platformSlice_doesNotReturnOEMSlice() {
|
||||||
final String key = "oem_key";
|
final String key = "oem_key";
|
||||||
final boolean isPlatformSlice = false;
|
SliceTestUtils.insertSliceToDb(mContext, key, false /* isPlatformSlice */);
|
||||||
insertSpecialCase(key, isPlatformSlice);
|
final List<Uri> keys = mAccessor.getSliceUris(SettingsSlicesContract.AUTHORITY);
|
||||||
final List<String> keys = mAccessor.getSliceKeys(!isPlatformSlice);
|
|
||||||
|
|
||||||
assertThat(keys).isEmpty();
|
assertThat(keys).isEmpty();
|
||||||
}
|
}
|
||||||
@@ -187,9 +178,8 @@ public class SlicesDatabaseAccessorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getDescendantUris_oemSlice_doesNotReturnPlatformSlice() {
|
public void getDescendantUris_oemSlice_doesNotReturnPlatformSlice() {
|
||||||
final String key = "platform_key";
|
final String key = "platform_key";
|
||||||
final boolean isPlatformSlice = true;
|
SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */);
|
||||||
insertSpecialCase(key, isPlatformSlice);
|
final List<Uri> keys = mAccessor.getSliceUris(SettingsSliceProvider.SLICE_AUTHORITY);
|
||||||
final List<String> keys = mAccessor.getSliceKeys(!isPlatformSlice);
|
|
||||||
|
|
||||||
assertThat(keys).isEmpty();
|
assertThat(keys).isEmpty();
|
||||||
}
|
}
|
||||||
@@ -197,21 +187,21 @@ public class SlicesDatabaseAccessorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getDescendantUris_oemSlice_returnsOEMUriDescendant() {
|
public void getDescendantUris_oemSlice_returnsOEMUriDescendant() {
|
||||||
final String key = "oem_key";
|
final String key = "oem_key";
|
||||||
final boolean isPlatformSlice = false;
|
SliceTestUtils.insertSliceToDb(mContext, key, false /* isPlatformSlice */);
|
||||||
insertSpecialCase(key, isPlatformSlice);
|
final List<Uri> keys = mAccessor.getSliceUris(SettingsSliceProvider.SLICE_AUTHORITY);
|
||||||
final List<String> keys = mAccessor.getSliceKeys(isPlatformSlice);
|
|
||||||
|
|
||||||
assertThat(keys).containsExactly(key);
|
assertThat(keys).containsExactly(
|
||||||
|
Uri.parse("content://com.android.settings.slices/action/oem_key"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDescendantUris_platformSlice_returnsPlatformUriDescendant() {
|
public void getDescendantUris_platformSlice_returnsPlatformUriDescendant() {
|
||||||
final String key = "platform_key";
|
final String key = "platform_key";
|
||||||
final boolean isPlatformSlice = true;
|
SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */);
|
||||||
insertSpecialCase(key, isPlatformSlice);
|
final List<Uri> keys = mAccessor.getSliceUris(SettingsSlicesContract.AUTHORITY);
|
||||||
final List<String> keys = mAccessor.getSliceKeys(isPlatformSlice);
|
|
||||||
|
|
||||||
assertThat(keys).containsExactly(key);
|
assertThat(keys).containsExactly(
|
||||||
|
Uri.parse("content://android.settings.slices/action/platform_key"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -220,7 +210,7 @@ public class SlicesDatabaseAccessorTest {
|
|||||||
// Force new indexing
|
// Force new indexing
|
||||||
Locale.setDefault(new Locale("ca"));
|
Locale.setDefault(new Locale("ca"));
|
||||||
final SearchFeatureProvider provider = new SearchFeatureProviderImpl();
|
final SearchFeatureProvider provider = new SearchFeatureProviderImpl();
|
||||||
final SlicesFeatureProvider sliceProvider = spy(new SlicesFeatureProviderImpl());
|
final SlicesFeatureProvider sliceProvider = new SlicesFeatureProviderImpl();
|
||||||
final FakeFeatureFactory factory = FakeFeatureFactory.setupForTest();
|
final FakeFeatureFactory factory = FakeFeatureFactory.setupForTest();
|
||||||
factory.searchFeatureProvider = provider;
|
factory.searchFeatureProvider = provider;
|
||||||
factory.slicesFeatureProvider = sliceProvider;
|
factory.slicesFeatureProvider = sliceProvider;
|
||||||
@@ -230,7 +220,7 @@ public class SlicesDatabaseAccessorTest {
|
|||||||
FakeIndexProvider.class);
|
FakeIndexProvider.class);
|
||||||
|
|
||||||
final SlicesDatabaseAccessor accessor = new SlicesDatabaseAccessor(mContext);
|
final SlicesDatabaseAccessor accessor = new SlicesDatabaseAccessor(mContext);
|
||||||
final List<String> keys = accessor.getSliceKeys(true);
|
final List<Uri> keys = accessor.getSliceUris(SettingsSliceProvider.SLICE_AUTHORITY);
|
||||||
|
|
||||||
assertThat(keys).isNotEmpty();
|
assertThat(keys).isNotEmpty();
|
||||||
}
|
}
|
||||||
@@ -238,20 +228,20 @@ public class SlicesDatabaseAccessorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetSliceDataFromKey_defaultUnavailableSlice_validSliceReturned() {
|
public void testGetSliceDataFromKey_defaultUnavailableSlice_validSliceReturned() {
|
||||||
String key = "key";
|
String key = "key";
|
||||||
insertSpecialCase(key, true /* isPlatformSlice */,
|
SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */,
|
||||||
null /* customizedUnavailableSliceSubtitle */);
|
null /* customizedUnavailableSliceSubtitle */);
|
||||||
|
|
||||||
SliceData data = mAccessor.getSliceDataFromKey(key);
|
SliceData data = mAccessor.getSliceDataFromKey(key);
|
||||||
|
|
||||||
assertThat(data.getKey()).isEqualTo(key);
|
assertThat(data.getKey()).isEqualTo(key);
|
||||||
assertThat(data.getTitle()).isEqualTo(FAKE_TITLE);
|
assertThat(data.getTitle()).isEqualTo(SliceTestUtils.FAKE_TITLE);
|
||||||
assertThat(data.getSummary()).isEqualTo(FAKE_SUMMARY);
|
assertThat(data.getSummary()).isEqualTo(SliceTestUtils.FAKE_SUMMARY);
|
||||||
assertThat(data.getScreenTitle()).isEqualTo(FAKE_SCREEN_TITLE);
|
assertThat(data.getScreenTitle()).isEqualTo(SliceTestUtils.FAKE_SCREEN_TITLE);
|
||||||
assertThat(data.getKeywords()).isEqualTo(FAKE_KEYWORDS);
|
assertThat(data.getKeywords()).isEqualTo(SliceTestUtils.FAKE_KEYWORDS);
|
||||||
assertThat(data.getIconResource()).isEqualTo(FAKE_ICON);
|
assertThat(data.getIconResource()).isEqualTo(SliceTestUtils.FAKE_ICON);
|
||||||
assertThat(data.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_NAME);
|
assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||||
assertThat(data.getUri()).isNull();
|
assertThat(data.getUri()).isNull();
|
||||||
assertThat(data.getPreferenceController()).isEqualTo(FAKE_CONTROLLER_NAME);
|
assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME);
|
||||||
assertThat(data.getUnavailableSliceSubtitle()).isNull();
|
assertThat(data.getUnavailableSliceSubtitle()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,49 +249,22 @@ public class SlicesDatabaseAccessorTest {
|
|||||||
public void testGetSliceDataFromKey_customizeSubtitleOfUnavailableSlice_validSliceReturned() {
|
public void testGetSliceDataFromKey_customizeSubtitleOfUnavailableSlice_validSliceReturned() {
|
||||||
String key = "key";
|
String key = "key";
|
||||||
String subtitle = "subtitle";
|
String subtitle = "subtitle";
|
||||||
insertSpecialCase(key, true /* isPlatformSlice */, subtitle);
|
SliceTestUtils.insertSliceToDb(mContext, key, true /* isPlatformSlice */, subtitle);
|
||||||
|
|
||||||
SliceData data = mAccessor.getSliceDataFromKey(key);
|
SliceData data = mAccessor.getSliceDataFromKey(key);
|
||||||
|
|
||||||
assertThat(data.getKey()).isEqualTo(key);
|
assertThat(data.getKey()).isEqualTo(key);
|
||||||
assertThat(data.getTitle()).isEqualTo(FAKE_TITLE);
|
assertThat(data.getTitle()).isEqualTo(SliceTestUtils.FAKE_TITLE);
|
||||||
assertThat(data.getSummary()).isEqualTo(FAKE_SUMMARY);
|
assertThat(data.getSummary()).isEqualTo(SliceTestUtils.FAKE_SUMMARY);
|
||||||
assertThat(data.getScreenTitle()).isEqualTo(FAKE_SCREEN_TITLE);
|
assertThat(data.getScreenTitle()).isEqualTo(SliceTestUtils.FAKE_SCREEN_TITLE);
|
||||||
assertThat(data.getKeywords()).isEqualTo(FAKE_KEYWORDS);
|
assertThat(data.getKeywords()).isEqualTo(SliceTestUtils.FAKE_KEYWORDS);
|
||||||
assertThat(data.getIconResource()).isEqualTo(FAKE_ICON);
|
assertThat(data.getIconResource()).isEqualTo(SliceTestUtils.FAKE_ICON);
|
||||||
assertThat(data.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_NAME);
|
assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||||
assertThat(data.getUri()).isNull();
|
assertThat(data.getUri()).isNull();
|
||||||
assertThat(data.getPreferenceController()).isEqualTo(FAKE_CONTROLLER_NAME);
|
assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME);
|
||||||
assertThat(data.getUnavailableSliceSubtitle()).isEqualTo(subtitle);
|
assertThat(data.getUnavailableSliceSubtitle()).isEqualTo(subtitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertSpecialCase(String key) {
|
|
||||||
insertSpecialCase(key, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void insertSpecialCase(String key, boolean isPlatformSlice) {
|
|
||||||
insertSpecialCase(key, isPlatformSlice, null /*customizedUnavailableSliceSubtitle*/);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void insertSpecialCase(String key, boolean isPlatformSlice,
|
|
||||||
String customizedUnavailableSliceSubtitle) {
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.KEY, key);
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.TITLE, FAKE_TITLE);
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.SUMMARY, FAKE_SUMMARY);
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.SCREENTITLE, FAKE_SCREEN_TITLE);
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.KEYWORDS, FAKE_KEYWORDS);
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.ICON_RESOURCE, FAKE_ICON);
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.FRAGMENT, FAKE_FRAGMENT_NAME);
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.CONTROLLER, FAKE_CONTROLLER_NAME);
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.PLATFORM_SLICE, isPlatformSlice);
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.SLICE_TYPE, SliceData.SliceType.INTENT);
|
|
||||||
values.put(SlicesDatabaseHelper.IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
|
||||||
customizedUnavailableSliceSubtitle);
|
|
||||||
|
|
||||||
mDb.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Implements(ApplicationPackageManager.class)
|
@Implements(ApplicationPackageManager.class)
|
||||||
public static class ShadowApplicationPackageManager extends
|
public static class ShadowApplicationPackageManager extends
|
||||||
org.robolectric.shadows.ShadowApplicationPackageManager {
|
org.robolectric.shadows.ShadowApplicationPackageManager {
|
||||||
|
|||||||
@@ -73,7 +73,6 @@ public class SlicesDatabaseHelperTest {
|
|||||||
IndexColumns.ICON_RESOURCE,
|
IndexColumns.ICON_RESOURCE,
|
||||||
IndexColumns.FRAGMENT,
|
IndexColumns.FRAGMENT,
|
||||||
IndexColumns.CONTROLLER,
|
IndexColumns.CONTROLLER,
|
||||||
IndexColumns.PLATFORM_SLICE,
|
|
||||||
IndexColumns.SLICE_TYPE,
|
IndexColumns.SLICE_TYPE,
|
||||||
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ public class SlicesIndexerTest {
|
|||||||
private final int ICON = 1234; // I declare a thumb war
|
private final int ICON = 1234; // I declare a thumb war
|
||||||
private final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
private final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||||
private final String PREF_CONTROLLER = "com.android.settings.slices.tester";
|
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 int SLICE_TYPE = SliceData.SliceType.SLIDER;
|
||||||
private final String UNAVAILABLE_SLICE_SUBTITLE = "subtitleOfUnavailableSlice";
|
private final String UNAVAILABLE_SLICE_SUBTITLE = "subtitleOfUnavailableSlice";
|
||||||
|
|
||||||
@@ -136,9 +135,6 @@ public class SlicesIndexerTest {
|
|||||||
assertThat(
|
assertThat(
|
||||||
cursor.getString(cursor.getColumnIndex(IndexColumns.CONTROLLER)))
|
cursor.getString(cursor.getColumnIndex(IndexColumns.CONTROLLER)))
|
||||||
.isEqualTo(PREF_CONTROLLER);
|
.isEqualTo(PREF_CONTROLLER);
|
||||||
assertThat(cursor.getInt(
|
|
||||||
cursor.getColumnIndex(IndexColumns.PLATFORM_SLICE)))
|
|
||||||
.isEqualTo(1 /* true */);
|
|
||||||
assertThat(cursor.getInt(cursor.getColumnIndex(IndexColumns.SLICE_TYPE)))
|
assertThat(cursor.getInt(cursor.getColumnIndex(IndexColumns.SLICE_TYPE)))
|
||||||
.isEqualTo(SLICE_TYPE);
|
.isEqualTo(SLICE_TYPE);
|
||||||
assertThat(cursor.getString(
|
assertThat(cursor.getString(
|
||||||
@@ -176,7 +172,6 @@ public class SlicesIndexerTest {
|
|||||||
.setIcon(ICON)
|
.setIcon(ICON)
|
||||||
.setUri(URI)
|
.setUri(URI)
|
||||||
.setPreferenceControllerClassName(PREF_CONTROLLER)
|
.setPreferenceControllerClassName(PREF_CONTROLLER)
|
||||||
.setPlatformDefined(PLATFORM_DEFINED)
|
|
||||||
.setSliceType(SLICE_TYPE)
|
.setSliceType(SLICE_TYPE)
|
||||||
.setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE);
|
.setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE);
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class FakeToggleController extends TogglePreferenceController {
|
|||||||
@Override
|
@Override
|
||||||
public boolean isChecked() {
|
public boolean isChecked() {
|
||||||
return Settings.System.getInt(mContext.getContentResolver(),
|
return Settings.System.getInt(mContext.getContentResolver(),
|
||||||
SETTING_KEY, OFF) == ON;
|
SETTING_KEY, OFF) == ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -103,7 +103,7 @@ public class FakeToggleController extends TogglePreferenceController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user