Add keywords to Slices
Attach the keywords used for Settings search to Slices. Their primary use is helping match synonyms for presenters which display slices without explicit Uri requests, like a launcher. This changes: - Updates database scheme - Adds to SliceData object - Grab keywords in the SliceDataConverter - Set keywords on all slices Test: robotests Change-Id: I16c40d2380ffddaf0a87fb1b9cd58e95573b308f Fixes: 78306195
This commit is contained in:
@@ -19,8 +19,7 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:key="auto_brightness_detail"
|
||||
android:title="@string/auto_brightness_title"
|
||||
settings:keywords="@string/keywords_display_auto_brightness">
|
||||
android:title="@string/auto_brightness_title">
|
||||
|
||||
<com.android.settings.widget.VideoPreference
|
||||
android:key="auto_brightness_video"
|
||||
@@ -31,6 +30,7 @@
|
||||
<com.android.settingslib.RestrictedSwitchPreference
|
||||
android:key="auto_brightness"
|
||||
android:title="@string/auto_brightness_title"
|
||||
settings:keywords="@string/keywords_display_auto_brightness"
|
||||
settings:controller="com.android.settings.display.AutoBrightnessPreferenceController"
|
||||
settings:useAdminDisabledSummary="true"
|
||||
settings:userRestriction="no_config_brightness" />
|
||||
|
@@ -77,6 +77,7 @@ public class PreferenceXmlParserUtils {
|
||||
int FLAG_NEED_PREF_SUMMARY = 1 << 5;
|
||||
int FLAG_NEED_PREF_ICON = 1 << 6;
|
||||
int FLAG_NEED_PLATFORM_SLICE_FLAG = 1 << 7;
|
||||
int FLAG_NEED_KEYWORDS = 1 << 8;
|
||||
}
|
||||
|
||||
public static final String METADATA_PREF_TYPE = "type";
|
||||
@@ -86,6 +87,7 @@ public class PreferenceXmlParserUtils {
|
||||
public static final String METADATA_SUMMARY = "summary";
|
||||
public static final String METADATA_ICON = "icon";
|
||||
public static final String METADATA_PLATFORM_SLICE_FLAG = "platform_slice";
|
||||
public static final String METADATA_KEYWORDS = "keywords";
|
||||
|
||||
private static final String ENTRIES_SEPARATOR = "|";
|
||||
|
||||
@@ -226,6 +228,9 @@ public class PreferenceXmlParserUtils {
|
||||
preferenceMetadata.putBoolean(METADATA_PLATFORM_SLICE_FLAG,
|
||||
getPlatformSlice(preferenceAttributes));
|
||||
}
|
||||
if (hasFlag(flags, MetadataFlag.FLAG_NEED_KEYWORDS)) {
|
||||
preferenceMetadata.putString(METADATA_KEYWORDS, getKeywords(preferenceAttributes));
|
||||
}
|
||||
metadata.add(preferenceMetadata);
|
||||
|
||||
preferenceAttributes.recycle();
|
||||
@@ -305,4 +310,8 @@ public class PreferenceXmlParserUtils {
|
||||
private static boolean getPlatformSlice(TypedArray styledAttributes) {
|
||||
return styledAttributes.getBoolean(R.styleable.Preference_platform_slice, false /* def */);
|
||||
}
|
||||
|
||||
private static String getKeywords(TypedArray styleAttributes) {
|
||||
return styleAttributes.getString(R.styleable.Preference_keywords);
|
||||
}
|
||||
}
|
||||
|
@@ -47,6 +47,10 @@ import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import android.support.v4.graphics.drawable.IconCompat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.slice.Slice;
|
||||
import androidx.slice.builders.ListBuilder;
|
||||
import androidx.slice.builders.SliceAction;
|
||||
@@ -231,6 +235,7 @@ public class SliceBuilderUtils {
|
||||
(TogglePreferenceController) controller;
|
||||
final SliceAction sliceAction = getToggleAction(context, sliceData,
|
||||
toggleController.isChecked());
|
||||
final List<String> keywords = buildSliceKeywords(sliceData.getKeywords());
|
||||
|
||||
return new ListBuilder(context, sliceData.getUri(), SLICE_TTL_MILLIS)
|
||||
.addRow(rowBuilder -> rowBuilder
|
||||
@@ -239,6 +244,7 @@ public class SliceBuilderUtils {
|
||||
.setPrimaryAction(
|
||||
new SliceAction(contentIntent, icon, sliceData.getTitle()))
|
||||
.addEndItem(sliceAction))
|
||||
.setKeywords(keywords)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -247,6 +253,7 @@ public class SliceBuilderUtils {
|
||||
final PendingIntent contentIntent = getContentPendingIntent(context, sliceData);
|
||||
final IconCompat icon = IconCompat.createWithResource(context, sliceData.getIconResource());
|
||||
final CharSequence subtitleText = getSubtitleText(context, controller, sliceData);
|
||||
final List<String> keywords = buildSliceKeywords(sliceData.getKeywords());
|
||||
|
||||
return new ListBuilder(context, sliceData.getUri(), SLICE_TTL_MILLIS)
|
||||
.addRow(rowBuilder -> rowBuilder
|
||||
@@ -254,6 +261,7 @@ public class SliceBuilderUtils {
|
||||
.setSubtitle(subtitleText)
|
||||
.setPrimaryAction(
|
||||
new SliceAction(contentIntent, icon, sliceData.getTitle())))
|
||||
.setKeywords(keywords)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -265,6 +273,7 @@ public class SliceBuilderUtils {
|
||||
final IconCompat icon = IconCompat.createWithResource(context, sliceData.getIconResource());
|
||||
final SliceAction primaryAction = new SliceAction(contentIntent, icon,
|
||||
sliceData.getTitle());
|
||||
final List<String> keywords = buildSliceKeywords(sliceData.getKeywords());
|
||||
|
||||
return new ListBuilder(context, sliceData.getUri(), SLICE_TTL_MILLIS)
|
||||
.addInputRange(builder -> builder
|
||||
@@ -273,6 +282,7 @@ public class SliceBuilderUtils {
|
||||
.setValue(sliderController.getSliderPosition())
|
||||
.setInputAction(actionIntent)
|
||||
.setPrimaryAction(primaryAction))
|
||||
.setKeywords(keywords)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -311,9 +321,19 @@ public class SliceBuilderUtils {
|
||||
|| TextUtils.equals(summary, doublePlaceHolder));
|
||||
}
|
||||
|
||||
private static List<String> buildSliceKeywords(String keywordString) {
|
||||
if (keywordString == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
final String[] keywords = keywordString.split(",");
|
||||
return Arrays.asList(keywords);
|
||||
}
|
||||
|
||||
private static Slice buildUnavailableSlice(Context context, SliceData data,
|
||||
BasePreferenceController controller) {
|
||||
final String title = data.getTitle();
|
||||
final List<String> keywords = buildSliceKeywords(data.getKeywords());
|
||||
final String summary;
|
||||
final SliceAction primaryAction;
|
||||
final IconCompat icon = IconCompat.createWithResource(context, data.getIconResource());
|
||||
@@ -344,6 +364,7 @@ public class SliceBuilderUtils {
|
||||
.setTitle(title)
|
||||
.setSubtitle(summary)
|
||||
.setPrimaryAction(primaryAction))
|
||||
.setKeywords(keywords)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ import android.text.TextUtils;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Data class representing a slice stored by {@link SlicesIndexer}.
|
||||
@@ -59,6 +60,8 @@ public class SliceData {
|
||||
|
||||
private final CharSequence mScreenTitle;
|
||||
|
||||
private final String mKeywords;
|
||||
|
||||
private final int mIconResource;
|
||||
|
||||
private final String mFragmentClassName;
|
||||
@@ -88,6 +91,10 @@ public class SliceData {
|
||||
return mScreenTitle;
|
||||
}
|
||||
|
||||
public String getKeywords() {
|
||||
return mKeywords;
|
||||
}
|
||||
|
||||
public int getIconResource() {
|
||||
return mIconResource;
|
||||
}
|
||||
@@ -117,6 +124,7 @@ public class SliceData {
|
||||
mTitle = builder.mTitle;
|
||||
mSummary = builder.mSummary;
|
||||
mScreenTitle = builder.mScreenTitle;
|
||||
mKeywords = builder.mKeywords;
|
||||
mIconResource = builder.mIconResource;
|
||||
mFragmentClassName = builder.mFragmentClassName;
|
||||
mUri = builder.mUri;
|
||||
@@ -148,6 +156,8 @@ public class SliceData {
|
||||
|
||||
private CharSequence mScreenTitle;
|
||||
|
||||
private String mKeywords;
|
||||
|
||||
private int mIconResource;
|
||||
|
||||
private String mFragmentClassName;
|
||||
@@ -180,6 +190,11 @@ public class SliceData {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setKeywords(String keywords) {
|
||||
mKeywords = keywords;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setIcon(int iconResource) {
|
||||
mIconResource = iconResource;
|
||||
return this;
|
||||
|
@@ -19,6 +19,7 @@ package com.android.settings.slices;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_CONTROLLER;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_ICON;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEY;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEYWORDS;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_PLATFORM_SLICE_FLAG;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_SUMMARY;
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_TITLE;
|
||||
@@ -184,6 +185,7 @@ class SliceDataConverter {
|
||||
| MetadataFlag.FLAG_NEED_PREF_TITLE
|
||||
| MetadataFlag.FLAG_NEED_PREF_ICON
|
||||
| MetadataFlag.FLAG_NEED_PREF_SUMMARY
|
||||
| MetadataFlag.FLAG_NEED_KEYWORDS
|
||||
| MetadataFlag.FLAG_NEED_PLATFORM_SLICE_FLAG);
|
||||
|
||||
for (Bundle bundle : metadata) {
|
||||
@@ -196,6 +198,7 @@ class SliceDataConverter {
|
||||
final String key = bundle.getString(METADATA_KEY);
|
||||
final String title = bundle.getString(METADATA_TITLE);
|
||||
final String summary = bundle.getString(METADATA_SUMMARY);
|
||||
final String keywords = bundle.getString(METADATA_KEYWORDS);
|
||||
final int iconResId = bundle.getInt(METADATA_ICON);
|
||||
final int sliceType = SliceBuilderUtils.getSliceType(mContext, controllerClassName,
|
||||
key);
|
||||
@@ -207,6 +210,7 @@ class SliceDataConverter {
|
||||
.setSummary(summary)
|
||||
.setIcon(iconResId)
|
||||
.setScreenTitle(screenTitle)
|
||||
.setKeywords(keywords)
|
||||
.setPreferenceControllerClassName(controllerClassName)
|
||||
.setFragmentName(fragmentName)
|
||||
.setSliceType(sliceType)
|
||||
|
@@ -44,6 +44,7 @@ public class SlicesDatabaseAccessor {
|
||||
IndexColumns.TITLE,
|
||||
IndexColumns.SUMMARY,
|
||||
IndexColumns.SCREENTITLE,
|
||||
IndexColumns.KEYWORDS,
|
||||
IndexColumns.ICON_RESOURCE,
|
||||
IndexColumns.FRAGMENT,
|
||||
IndexColumns.CONTROLLER,
|
||||
@@ -150,6 +151,7 @@ public class SlicesDatabaseAccessor {
|
||||
final String summary = cursor.getString(cursor.getColumnIndex(IndexColumns.SUMMARY));
|
||||
final String screenTitle = cursor.getString(
|
||||
cursor.getColumnIndex(IndexColumns.SCREENTITLE));
|
||||
final String keywords = cursor.getString(cursor.getColumnIndex(IndexColumns.KEYWORDS));
|
||||
final int iconResource = cursor.getInt(cursor.getColumnIndex(IndexColumns.ICON_RESOURCE));
|
||||
final String fragmentClassName = cursor.getString(
|
||||
cursor.getColumnIndex(IndexColumns.FRAGMENT));
|
||||
@@ -169,6 +171,7 @@ public class SlicesDatabaseAccessor {
|
||||
.setTitle(title)
|
||||
.setSummary(summary)
|
||||
.setScreenTitle(screenTitle)
|
||||
.setKeywords(keywords)
|
||||
.setIcon(iconResource)
|
||||
.setFragmentName(fragmentClassName)
|
||||
.setPreferenceControllerClassName(controllerClassName)
|
||||
|
@@ -36,7 +36,7 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
private static final String DATABASE_NAME = "slices_index.db";
|
||||
private static final String SHARED_PREFS_TAG = "slices_shared_prefs";
|
||||
|
||||
private static final int DATABASE_VERSION = 1;
|
||||
private static final int DATABASE_VERSION = 2;
|
||||
|
||||
public interface Tables {
|
||||
String TABLE_SLICES_INDEX = "slices_index";
|
||||
@@ -63,6 +63,11 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
*/
|
||||
String SCREENTITLE = "screentitle";
|
||||
|
||||
/**
|
||||
* String with a comma separated list of keywords relating to the Slice.
|
||||
*/
|
||||
String KEYWORDS = "keywords";
|
||||
|
||||
/**
|
||||
* Resource ID for the icon of the setting. Should be 0 for no icon.
|
||||
*/
|
||||
@@ -101,6 +106,8 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
", " +
|
||||
IndexColumns.SCREENTITLE +
|
||||
", " +
|
||||
IndexColumns.KEYWORDS +
|
||||
", " +
|
||||
IndexColumns.ICON_RESOURCE +
|
||||
", " +
|
||||
IndexColumns.FRAGMENT +
|
||||
@@ -109,7 +116,7 @@ public class SlicesDatabaseHelper extends SQLiteOpenHelper {
|
||||
", " +
|
||||
IndexColumns.PLATFORM_SLICE +
|
||||
", " +
|
||||
IndexColumns.SLICE_TYPE+
|
||||
IndexColumns.SLICE_TYPE +
|
||||
");";
|
||||
|
||||
private final Context mContext;
|
||||
|
@@ -105,6 +105,7 @@ class SlicesIndexer implements Runnable {
|
||||
values.put(IndexColumns.TITLE, dataRow.getTitle());
|
||||
values.put(IndexColumns.SUMMARY, dataRow.getSummary());
|
||||
values.put(IndexColumns.SCREENTITLE, dataRow.getScreenTitle().toString());
|
||||
values.put(IndexColumns.KEYWORDS, dataRow.getKeywords());
|
||||
values.put(IndexColumns.ICON_RESOURCE, dataRow.getIconResource());
|
||||
values.put(IndexColumns.FRAGMENT, dataRow.getFragmentClassName());
|
||||
values.put(IndexColumns.CONTROLLER, dataRow.getPreferenceController());
|
||||
|
@@ -25,6 +25,7 @@
|
||||
android:icon="@drawable/ic_android"
|
||||
android:summary="summary"
|
||||
settings:controller="com.android.settings.slices.FakePreferenceController"
|
||||
settings:keywords="a, b, c"
|
||||
settings:platform_slice="true"/>
|
||||
|
||||
</PreferenceScreen>
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.core;
|
||||
|
||||
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEYWORDS;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -244,6 +246,21 @@ public class PreferenceXmlParserUtilsTest {
|
||||
assertThat(hasPreferenceScreen).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "mcc999")
|
||||
public void extractMetadata_requestIncludesKeywords_shouldContainKeywords()
|
||||
throws IOException, XmlPullParserException {
|
||||
final String expectedKeywords = "a, b, c";
|
||||
final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
|
||||
R.xml.location_settings,
|
||||
MetadataFlag.FLAG_NEED_PREF_TYPE | MetadataFlag.FLAG_NEED_KEYWORDS);
|
||||
final Bundle bundle = metadata.get(0);
|
||||
|
||||
final String keywords = bundle.getString(METADATA_KEYWORDS);
|
||||
|
||||
assertThat(keywords).isEqualTo(expectedKeywords);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resId the ID for the XML preference
|
||||
* @return an XML resource parser that points to the start tag
|
||||
|
@@ -60,6 +60,7 @@ public class SliceBuilderUtilsTest {
|
||||
private final String TITLE = "title";
|
||||
private final String SUMMARY = "summary";
|
||||
private final String SCREEN_TITLE = "screen title";
|
||||
private final String KEYWORDS = "a, b, c";
|
||||
private final String FRAGMENT_NAME = "fragment name";
|
||||
private final int ICON = 1234; // I declare a thumb war
|
||||
private final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||
@@ -422,6 +423,7 @@ public class SliceBuilderUtilsTest {
|
||||
.setTitle(TITLE)
|
||||
.setSummary(summary)
|
||||
.setScreenTitle(SCREEN_TITLE)
|
||||
.setKeywords(KEYWORDS)
|
||||
.setIcon(ICON)
|
||||
.setFragmentName(FRAGMENT_NAME)
|
||||
.setUri(URI)
|
||||
|
@@ -52,21 +52,21 @@ import java.util.List;
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class SliceDataConverterTest {
|
||||
|
||||
private final String FAKE_KEY = "key";
|
||||
private final String FAKE_TITLE = "title";
|
||||
private final String FAKE_SUMMARY = "summary";
|
||||
private final String FAKE_SCREEN_TITLE = "screen_title";
|
||||
private final String FAKE_FRAGMENT_CLASSNAME = FakeIndexProvider.class.getName();
|
||||
private final String FAKE_CONTROLLER_NAME = FakePreferenceController.class.getName();
|
||||
|
||||
private final String ACCESSIBILITY_FRAGMENT = AccessibilitySettings.class.getName();
|
||||
private final String A11Y_CONTROLLER_NAME =
|
||||
private static final String FAKE_KEY = "key";
|
||||
private static final String FAKE_TITLE = "title";
|
||||
private static final String FAKE_SUMMARY = "summary";
|
||||
private static final String FAKE_SCREEN_TITLE = "screen_title";
|
||||
private static final String FAKE_KEYWORDS = "a, b, c";
|
||||
private static final String FAKE_FRAGMENT_CLASSNAME = FakeIndexProvider.class.getName();
|
||||
private static final String FAKE_CONTROLLER_NAME = FakePreferenceController.class.getName();
|
||||
private static final String ACCESSIBILITY_FRAGMENT = AccessibilitySettings.class.getName();
|
||||
private static final String A11Y_CONTROLLER_NAME =
|
||||
AccessibilitySlicePreferenceController.class.getName();
|
||||
private final String FAKE_SERVICE_NAME = "fake_service";
|
||||
private final String FAKE_ACCESSIBILITY_PACKAGE = "fake_package";
|
||||
private final String FAKE_A11Y_SERVICE_NAME =
|
||||
private static final String FAKE_SERVICE_NAME = "fake_service";
|
||||
private static final String FAKE_ACCESSIBILITY_PACKAGE = "fake_package";
|
||||
private static final String FAKE_A11Y_SERVICE_NAME =
|
||||
FAKE_ACCESSIBILITY_PACKAGE + "/" + FAKE_SERVICE_NAME;
|
||||
private final int FAKE_ICON = 1234;
|
||||
private static final int FAKE_ICON = 1234;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -118,6 +118,7 @@ public class SliceDataConverterTest {
|
||||
assertThat(fakeSlice.getTitle()).isEqualTo(FAKE_TITLE);
|
||||
assertThat(fakeSlice.getSummary()).isEqualTo(FAKE_SUMMARY);
|
||||
assertThat(fakeSlice.getScreenTitle()).isEqualTo(FAKE_SCREEN_TITLE);
|
||||
assertThat(fakeSlice.getKeywords()).isEqualTo(FAKE_KEYWORDS);
|
||||
assertThat(fakeSlice.getIconResource()).isNotNull();
|
||||
assertThat(fakeSlice.getUri()).isNull();
|
||||
assertThat(fakeSlice.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_CLASSNAME);
|
||||
|
@@ -32,6 +32,7 @@ public class SliceDataTest {
|
||||
private final String TITLE = "title";
|
||||
private final String SUMMARY = "summary";
|
||||
private final String SCREEN_TITLE = "screen title";
|
||||
private final String KEYWORDS = "a, b, c";
|
||||
private final String FRAGMENT_NAME = "fragment name";
|
||||
private final int ICON = 1234; // I declare a thumb war
|
||||
private final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||
@@ -46,6 +47,7 @@ public class SliceDataTest {
|
||||
.setTitle(TITLE)
|
||||
.setSummary(SUMMARY)
|
||||
.setScreenTitle(SCREEN_TITLE)
|
||||
.setKeywords(KEYWORDS)
|
||||
.setIcon(ICON)
|
||||
.setFragmentName(FRAGMENT_NAME)
|
||||
.setUri(URI)
|
||||
@@ -59,6 +61,7 @@ public class SliceDataTest {
|
||||
assertThat(data.getTitle()).isEqualTo(TITLE);
|
||||
assertThat(data.getSummary()).isEqualTo(SUMMARY);
|
||||
assertThat(data.getScreenTitle()).isEqualTo(SCREEN_TITLE);
|
||||
assertThat(data.getKeywords()).isEqualTo(KEYWORDS);
|
||||
assertThat(data.getIconResource()).isEqualTo(ICON);
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(FRAGMENT_NAME);
|
||||
assertThat(data.getUri()).isEqualTo(URI);
|
||||
|
@@ -44,6 +44,7 @@ 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();
|
||||
@@ -76,6 +77,7 @@ public class SlicesDatabaseAccessorTest {
|
||||
assertThat(data.getTitle()).isEqualTo(FAKE_TITLE);
|
||||
assertThat(data.getSummary()).isEqualTo(FAKE_SUMMARY);
|
||||
assertThat(data.getScreenTitle()).isEqualTo(FAKE_SCREEN_TITLE);
|
||||
assertThat(data.getKeywords()).isEqualTo(FAKE_KEYWORDS);
|
||||
assertThat(data.getIconResource()).isEqualTo(FAKE_ICON);
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getUri()).isNull();
|
||||
@@ -102,6 +104,7 @@ public class SlicesDatabaseAccessorTest {
|
||||
assertThat(data.getTitle()).isEqualTo(FAKE_TITLE);
|
||||
assertThat(data.getSummary()).isEqualTo(FAKE_SUMMARY);
|
||||
assertThat(data.getScreenTitle()).isEqualTo(FAKE_SCREEN_TITLE);
|
||||
assertThat(data.getKeywords()).isEqualTo(FAKE_KEYWORDS);
|
||||
assertThat(data.getIconResource()).isEqualTo(FAKE_ICON);
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getUri()).isEqualTo(uri);
|
||||
@@ -164,13 +167,13 @@ public class SlicesDatabaseAccessorTest {
|
||||
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);
|
||||
|
||||
|
||||
mDb.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
|
||||
}
|
||||
}
|
||||
|
@@ -66,6 +66,7 @@ public class SlicesDatabaseHelperTest {
|
||||
IndexColumns.TITLE,
|
||||
IndexColumns.SUMMARY,
|
||||
IndexColumns.SCREENTITLE,
|
||||
IndexColumns.KEYWORDS,
|
||||
IndexColumns.ICON_RESOURCE,
|
||||
IndexColumns.FRAGMENT,
|
||||
IndexColumns.CONTROLLER,
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.slices;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
@@ -46,6 +47,7 @@ public class SlicesIndexerTest {
|
||||
private final String[] TITLES = new String[]{"title1", "title2", "title3"};
|
||||
private final String SUMMARY = "subtitle";
|
||||
private final String SCREEN_TITLE = "screen title";
|
||||
private final String KEYWORDS = "a, b, c";
|
||||
private final String FRAGMENT_NAME = "fragment name";
|
||||
private final int ICON = 1234; // I declare a thumb war
|
||||
private final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||
@@ -119,6 +121,8 @@ public class SlicesIndexerTest {
|
||||
FRAGMENT_NAME);
|
||||
assertThat(cursor.getString(cursor.getColumnIndex(IndexColumns.SCREENTITLE))).isEqualTo(
|
||||
SCREEN_TITLE);
|
||||
assertThat(cursor.getString(cursor.getColumnIndex(IndexColumns.KEYWORDS))).isEqualTo(
|
||||
KEYWORDS);
|
||||
assertThat(cursor.getInt(cursor.getColumnIndex(IndexColumns.ICON_RESOURCE))).isEqualTo(
|
||||
ICON);
|
||||
assertThat(cursor.getString(cursor.getColumnIndex(IndexColumns.CONTROLLER))).isEqualTo(
|
||||
@@ -144,6 +148,7 @@ public class SlicesIndexerTest {
|
||||
final SliceData.Builder builder = new SliceData.Builder()
|
||||
.setSummary(SUMMARY)
|
||||
.setScreenTitle(SCREEN_TITLE)
|
||||
.setKeywords(KEYWORDS)
|
||||
.setFragmentName(FRAGMENT_NAME)
|
||||
.setIcon(ICON)
|
||||
.setUri(URI)
|
||||
|
@@ -29,6 +29,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.slice.Slice;
|
||||
@@ -55,6 +56,7 @@ public class SliceTester {
|
||||
* - No toggles
|
||||
* - Correct intent
|
||||
* - Correct title
|
||||
* - Correct keywords
|
||||
*/
|
||||
public static void testSettingsIntentSlice(Context context, Slice slice, SliceData sliceData) {
|
||||
final SliceMetadata metadata = SliceMetadata.from(context, slice);
|
||||
@@ -68,6 +70,8 @@ public class SliceTester {
|
||||
|
||||
final List<SliceItem> sliceItems = slice.getItems();
|
||||
assertTitle(sliceItems, sliceData.getTitle());
|
||||
|
||||
assertKeywords(metadata, sliceData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,6 +80,7 @@ public class SliceTester {
|
||||
* - Correct toggle intent
|
||||
* - Correct content intent
|
||||
* - Correct title
|
||||
* - Correct keywords
|
||||
*/
|
||||
public static void testSettingsToggleSlice(Context context, Slice slice, SliceData sliceData) {
|
||||
final SliceMetadata metadata = SliceMetadata.from(context, slice);
|
||||
@@ -101,12 +106,15 @@ public class SliceTester {
|
||||
|
||||
final List<SliceItem> sliceItems = slice.getItems();
|
||||
assertTitle(sliceItems, sliceData.getTitle());
|
||||
|
||||
assertKeywords(metadata, sliceData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the contents of an slider based slice, including:
|
||||
* - No intent
|
||||
* - Correct title
|
||||
* - Correct keywords
|
||||
*/
|
||||
public static void testSettingsSliderSlice(Context context, Slice slice, SliceData sliceData) {
|
||||
final SliceMetadata metadata = SliceMetadata.from(context, slice);
|
||||
@@ -121,6 +129,8 @@ public class SliceTester {
|
||||
|
||||
final List<SliceItem> sliceItems = slice.getItems();
|
||||
assertTitle(sliceItems, sliceData.getTitle());
|
||||
|
||||
assertKeywords(metadata, sliceData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,6 +138,7 @@ public class SliceTester {
|
||||
* - No toggles
|
||||
* - Correct title
|
||||
* - Correct intent
|
||||
* - Correct keywords
|
||||
*/
|
||||
public static void testSettingsUnavailableSlice(Context context, Slice slice,
|
||||
SliceData sliceData) {
|
||||
@@ -154,6 +165,8 @@ public class SliceTester {
|
||||
|
||||
final List<SliceItem> sliceItems = slice.getItems();
|
||||
assertTitle(sliceItems, sliceData.getTitle());
|
||||
|
||||
assertKeywords(metadata, sliceData);
|
||||
}
|
||||
|
||||
private static void assertTitle(List<SliceItem> sliceItems, String title) {
|
||||
@@ -172,4 +185,10 @@ public class SliceTester {
|
||||
}
|
||||
assertThat(hasTitle).isTrue();
|
||||
}
|
||||
|
||||
private static void assertKeywords(SliceMetadata metadata, SliceData data) {
|
||||
final List<String> keywords = metadata.getSliceKeywords();
|
||||
final List<String> expectedKeywords = Arrays.asList(data.getKeywords().split(","));
|
||||
assertThat(keywords).containsExactlyElementsIn(expectedKeywords);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user