Search in sources :

Example 11 with SearchIndexableData

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;
}
Also used : SearchIndexableResource(android.provider.SearchIndexableResource) SearchIndexableData(com.android.settingslib.search.SearchIndexableData) ArrayList(java.util.ArrayList) Indexable(com.android.settingslib.search.Indexable)

Example 12 with SearchIndexableData

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);
}
Also used : SearchIndexableData(com.android.settingslib.search.SearchIndexableData) Test(org.junit.Test)

Example 13 with SearchIndexableData

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();
}
Also used : SearchIndexableData(com.android.settingslib.search.SearchIndexableData) Cursor(android.database.Cursor) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 14 with SearchIndexableData

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);
}
Also used : ArraySet(android.util.ArraySet) SettingsPreferenceFragment(com.android.settings.SettingsPreferenceFragment) SearchIndexableData(com.android.settingslib.search.SearchIndexableData)

Aggregations

SearchIndexableData (com.android.settingslib.search.SearchIndexableData)14 Indexable (com.android.settingslib.search.Indexable)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 SearchIndexableResource (android.provider.SearchIndexableResource)3 Config (org.robolectric.annotation.Config)3 FakeIndexProvider (com.android.settings.testutils.FakeIndexProvider)2 SearchIndexableRaw (com.android.settingslib.search.SearchIndexableRaw)2 Context (android.content.Context)1 ActivityInfo (android.content.pm.ActivityInfo)1 ProviderInfo (android.content.pm.ProviderInfo)1 Cursor (android.database.Cursor)1 MatrixCursor (android.database.MatrixCursor)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 ArraySet (android.util.ArraySet)1 Nullable (androidx.annotation.Nullable)1 SettingsPreferenceFragment (com.android.settings.SettingsPreferenceFragment)1 SearchFeatureProvider (com.android.settings.search.SearchFeatureProvider)1 SearchFeatureProviderImpl (com.android.settings.search.SearchFeatureProviderImpl)1