use of com.android.settingslib.search.SearchIndexableData in project android_packages_apps_Settings by omnirom.
the class SettingsSearchIndexablesProvider method getSearchIndexableResourcesFromProvider.
private List<SearchIndexableResource> getSearchIndexableResourcesFromProvider(Context context) {
final Collection<SearchIndexableData> bundles = FeatureFactory.getFactory(context).getSearchFeatureProvider().getSearchIndexableResources().getProviderValues();
List<SearchIndexableResource> resourceList = new ArrayList<>();
for (SearchIndexableData bundle : bundles) {
Indexable.SearchIndexProvider provider = bundle.getSearchIndexProvider();
final List<SearchIndexableResource> resList = provider.getXmlResourcesToIndex(context, true);
if (resList == null) {
continue;
}
for (SearchIndexableResource item : resList) {
item.className = TextUtils.isEmpty(item.className) ? bundle.getTargetClass().getName() : item.className;
}
resourceList.addAll(resList);
}
return resourceList;
}
use of com.android.settingslib.search.SearchIndexableData in project android_packages_apps_Settings by omnirom.
the class SearchIndexableResourcesTest method testAddIndex.
@Test
public void testAddIndex() {
// Confirms that String.class isn't contained in SearchIndexableResources.
assertThat(mSearchProvider.getSearchIndexableResources().getProviderValues()).doesNotContain(String.class);
final int beforeCount = mSearchProvider.getSearchIndexableResources().getProviderValues().size();
final SearchIndexableData testBundle = new SearchIndexableData(null, null);
mSearchProvider.getSearchIndexableResources().addIndex(testBundle);
assertThat(mSearchProvider.getSearchIndexableResources().getProviderValues()).contains(testBundle);
final int afterCount = mSearchProvider.getSearchIndexableResources().getProviderValues().size();
assertThat(afterCount).isEqualTo(beforeCount + 1);
}
use of com.android.settingslib.search.SearchIndexableData in project android_packages_apps_Settings by omnirom.
the class SearchIndexableResourcesTest method testNonIndexableKeys_GetsKeyFromProvider.
@Test
@Config(qualifiers = "mcc999")
public void testNonIndexableKeys_GetsKeyFromProvider() {
mSearchProvider.getSearchIndexableResources().getProviderValues().clear();
mSearchProvider.getSearchIndexableResources().addIndex(new SearchIndexableData(null, FakeIndexProvider.SEARCH_INDEX_DATA_PROVIDER));
SettingsSearchIndexablesProvider provider = spy(new SettingsSearchIndexablesProvider());
when(provider.getContext()).thenReturn(RuntimeEnvironment.application);
Cursor cursor = provider.queryNonIndexableKeys(null);
boolean hasTestKey = false;
while (cursor.moveToNext()) {
String key = cursor.getString(COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE);
if (TextUtils.equals(key, FakeIndexProvider.KEY)) {
hasTestKey = true;
break;
}
}
assertThat(hasTestKey).isTrue();
}
use of com.android.settingslib.search.SearchIndexableData in project android_packages_apps_Settings by omnirom.
the class SearchIndexProviderCodeInspector method run.
@Override
public void run() {
final Set<String> notImplementingIndexProvider = new ArraySet<>();
final Set<String> notInSearchProviderRegistry = new ArraySet<>();
final Set<String> notSharingPreferenceControllers = new ArraySet<>();
final Set<String> notProvidingValidResource = new ArraySet<>();
final Set<Class> providerClasses = new ArraySet<>();
final SearchFeatureProvider provider = new SearchFeatureProviderImpl();
for (SearchIndexableData bundle : provider.getSearchIndexableResources().getProviderValues()) {
providerClasses.add(bundle.getTargetClass());
}
for (Class clazz : mClasses) {
if (!isConcreteSettingsClass(clazz)) {
continue;
}
final String className = clazz.getName();
// Skip fragments if it's not SettingsPreferenceFragment.
if (!SettingsPreferenceFragment.class.isAssignableFrom(clazz)) {
continue;
}
final boolean hasSearchIndexProvider = hasSearchIndexProvider(clazz);
// If it implements Indexable, it must also implement the index provider field.
if (!hasSearchIndexProvider) {
if (!mNotImplementingIndexProviderExemptList.remove(className)) {
notImplementingIndexProvider.add(className);
}
continue;
}
// If it implements index provider field AND it's a DashboardFragment, its fragment and
// search provider must share the same set of PreferenceControllers.
final boolean isSharingPrefControllers = DashboardFragmentSearchIndexProviderInspector.isSharingPreferenceControllers(clazz);
if (!isSharingPrefControllers) {
if (!mNotSharingPrefControllersExemptList.remove(className)) {
notSharingPreferenceControllers.add(className);
}
continue;
}
// Must be in SearchProviderRegistry
if (!providerClasses.contains(clazz)) {
if (!mNotInSearchIndexableRegistryExemptList.remove(className)) {
notInSearchProviderRegistry.add(className);
}
}
// Search provider must either don't provider resource xml, or provide valid ones.
if (!hasValidResourceFromProvider(clazz)) {
notProvidingValidResource.add(className);
}
}
// Build error messages
final String indexProviderError = buildErrorMessage(NOT_CONTAINING_PROVIDER_OBJECT_ERROR, notImplementingIndexProvider);
final String notSharingPrefControllerError = buildErrorMessage(NOT_SHARING_PREF_CONTROLLERS_BETWEEN_FRAG_AND_PROVIDER, notSharingPreferenceControllers);
final String notInProviderRegistryError = buildErrorMessage(NOT_IN_INDEXABLE_PROVIDER_REGISTRY, notInSearchProviderRegistry);
final String notProvidingValidResourceError = buildErrorMessage(NOT_PROVIDING_VALID_RESOURCE_ERROR, notProvidingValidResource);
assertWithMessage(indexProviderError).that(notImplementingIndexProvider).isEmpty();
assertWithMessage(notSharingPrefControllerError).that(notSharingPreferenceControllers).isEmpty();
assertWithMessage(notInProviderRegistryError).that(notInSearchProviderRegistry).isEmpty();
assertWithMessage(notProvidingValidResourceError).that(notProvidingValidResource).isEmpty();
assertNoObsoleteInExemptList("exempt_not_implementing_index_provider", mNotImplementingIndexProviderExemptList);
assertNoObsoleteInExemptList("exempt_not_in_search_index_provider_registry", mNotInSearchIndexableRegistryExemptList);
assertNoObsoleteInExemptList("exempt_not_sharing_pref_controllers_with_search_provider", mNotSharingPrefControllersExemptList);
}
Aggregations