Search in sources :

Example 6 with SearchIndexableData

use of com.android.settingslib.search.SearchIndexableData in project android_packages_apps_Settings by omnirom.

the class SearchIndexableResourcesTest method testIndexHasWifiSettings.

@Test
public void testIndexHasWifiSettings() {
    boolean hasWifi = false;
    for (SearchIndexableData bundle : mSearchProvider.getSearchIndexableResources().getProviderValues()) {
        if (bundle.getTargetClass().getName().equals(WifiSettings.class.getName())) {
            hasWifi = true;
            break;
        }
    }
    assertThat(hasWifi).isTrue();
}
Also used : WifiSettings(com.android.settings.wifi.WifiSettings) SearchIndexableData(com.android.settingslib.search.SearchIndexableData) Test(org.junit.Test)

Example 7 with SearchIndexableData

use of com.android.settingslib.search.SearchIndexableData in project android_packages_apps_Settings by omnirom.

the class SliceDataConverter method getSliceData.

/**
 * @return a list of {@link SliceData} to be indexed and later referenced as a Slice.
 *
 * The collection works as follows:
 * - Collects a list of Fragments from
 * {@link FeatureFactory#getSearchFeatureProvider()}.
 * - From each fragment, grab a {@link SearchIndexProvider}.
 * - For each provider, collect XML resource layout and a list of
 * {@link com.android.settings.core.BasePreferenceController}.
 */
public List<SliceData> getSliceData() {
    List<SliceData> sliceData = new ArrayList<>();
    final Collection<SearchIndexableData> bundles = FeatureFactory.getFactory(mContext).getSearchFeatureProvider().getSearchIndexableResources().getProviderValues();
    for (SearchIndexableData bundle : bundles) {
        final String fragmentName = bundle.getTargetClass().getName();
        final SearchIndexProvider provider = bundle.getSearchIndexProvider();
        // CodeInspection test guards against the null check. Keep check in case of bad actors.
        if (provider == null) {
            Log.e(TAG, fragmentName + " dose not implement Search Index Provider");
            continue;
        }
        final List<SliceData> providerSliceData = getSliceDataFromProvider(provider, fragmentName);
        sliceData.addAll(providerSliceData);
    }
    final List<SliceData> a11ySliceData = getAccessibilitySliceData();
    sliceData.addAll(a11ySliceData);
    return sliceData;
}
Also used : ArrayList(java.util.ArrayList) SearchIndexableData(com.android.settingslib.search.SearchIndexableData) SearchIndexProvider(com.android.settingslib.search.Indexable.SearchIndexProvider)

Example 8 with SearchIndexableData

use of com.android.settingslib.search.SearchIndexableData in project android_packages_apps_Settings by omnirom.

the class XmlControllerAttributeTest method getIndexableXml.

private Set<Integer> getIndexableXml() {
    Set<Integer> xmlResSet = new HashSet<>();
    Collection<SearchIndexableData> SearchIndexableDatas = mSearchProvider.getSearchIndexableResources().getProviderValues();
    for (SearchIndexableData bundle : SearchIndexableDatas) {
        Indexable.SearchIndexProvider provider = bundle.getSearchIndexProvider();
        if (provider == null) {
            continue;
        }
        List<SearchIndexableResource> resources = provider.getXmlResourcesToIndex(mContext, true);
        if (resources == null) {
            continue;
        }
        for (SearchIndexableResource resource : resources) {
            // Add '0's anyway. It won't break the test.
            xmlResSet.add(resource.xmlResId);
        }
    }
    return xmlResSet;
}
Also used : SearchIndexableResource(android.provider.SearchIndexableResource) SearchIndexableData(com.android.settingslib.search.SearchIndexableData) Indexable(com.android.settingslib.search.Indexable) HashSet(java.util.HashSet)

Example 9 with SearchIndexableData

use of com.android.settingslib.search.SearchIndexableData in project android_packages_apps_Settings by omnirom.

the class SettingsSearchIndexablesProvider method getNonIndexableKeysFromProvider.

private List<String> getNonIndexableKeysFromProvider(Context context) {
    final Collection<SearchIndexableData> bundles = FeatureFactory.getFactory(context).getSearchFeatureProvider().getSearchIndexableResources().getProviderValues();
    final List<String> nonIndexableKeys = new ArrayList<>();
    for (SearchIndexableData bundle : bundles) {
        final long startTime = System.currentTimeMillis();
        Indexable.SearchIndexProvider provider = bundle.getSearchIndexProvider();
        List<String> providerNonIndexableKeys;
        try {
            providerNonIndexableKeys = provider.getNonIndexableKeys(context);
        } catch (Exception e) {
            // non-indexable keys, but we can still find specific crashes in development.
            if (System.getProperty(SYSPROP_CRASH_ON_ERROR) != null) {
                throw new RuntimeException(e);
            }
            Log.e(TAG, "Error trying to get non-indexable keys from: " + bundle.getTargetClass().getName(), e);
            continue;
        }
        if (providerNonIndexableKeys == null || providerNonIndexableKeys.isEmpty()) {
            if (DEBUG) {
                final long totalTime = System.currentTimeMillis() - startTime;
                Log.d(TAG, "No indexable, total time " + totalTime);
            }
            continue;
        }
        if (providerNonIndexableKeys.removeAll(INVALID_KEYS)) {
            Log.v(TAG, provider + " tried to add an empty non-indexable key");
        }
        if (DEBUG) {
            final long totalTime = System.currentTimeMillis() - startTime;
            Log.d(TAG, "Non-indexables " + providerNonIndexableKeys.size() + ", total time " + totalTime);
        }
        nonIndexableKeys.addAll(providerNonIndexableKeys);
    }
    return nonIndexableKeys;
}
Also used : SearchIndexableData(com.android.settingslib.search.SearchIndexableData) ArrayList(java.util.ArrayList) Indexable(com.android.settingslib.search.Indexable)

Example 10 with SearchIndexableData

use of com.android.settingslib.search.SearchIndexableData in project android_packages_apps_Settings by omnirom.

the class SettingsSearchIndexablesProvider method getSearchIndexableRawFromProvider.

private List<SearchIndexableRaw> getSearchIndexableRawFromProvider(Context context) {
    final Collection<SearchIndexableData> bundles = FeatureFactory.getFactory(context).getSearchFeatureProvider().getSearchIndexableResources().getProviderValues();
    final List<SearchIndexableRaw> rawList = new ArrayList<>();
    for (SearchIndexableData bundle : bundles) {
        Indexable.SearchIndexProvider provider = bundle.getSearchIndexProvider();
        final List<SearchIndexableRaw> providerRaws = provider.getRawDataToIndex(context, true);
        if (providerRaws == null) {
            continue;
        }
        for (SearchIndexableRaw raw : providerRaws) {
            // The classname and intent information comes from the PreIndexData
            // This will be more clear when provider conversion is done at PreIndex time.
            raw.className = bundle.getTargetClass().getName();
        }
        rawList.addAll(providerRaws);
    }
    return rawList;
}
Also used : SearchIndexableData(com.android.settingslib.search.SearchIndexableData) ArrayList(java.util.ArrayList) SearchIndexableRaw(com.android.settingslib.search.SearchIndexableRaw) Indexable(com.android.settingslib.search.Indexable)

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