Declare "searchable" attribute for preferences.

Now we can easily mark a preference nonIndexable in xml instead of
adding key into searchIndexProvider.

Bug: 112608186
Test: robotests
Change-Id: I0ff16d44bb7b6ad148d3d35f09ca0da0163f73f4
This commit is contained in:
Fan Zhang
2018-08-14 16:25:54 -07:00
parent 097cfa7251
commit a79c377fbc
28 changed files with 201 additions and 148 deletions

View File

@@ -169,4 +169,24 @@ public class BaseSearchIndexProviderTest {
assertThat(nonIndexableKeys).contains("status_header");
}
@Test
@Config(qualifiers = "mcc999")
public void getNonIndexableKeys_hasSearchableAttributeInXml_shouldSuppressUnsearchable() {
final BaseSearchIndexProvider provider = new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.display_settings;
return Collections.singletonList(sir);
}
};
final List<String> nonIndexableKeys =
provider.getNonIndexableKeys(RuntimeEnvironment.application);
assertThat(nonIndexableKeys).contains("pref_key_5");
}
}