Search in sources :

Example 1 with SearchIndexableData

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

the class SliceDataConverterTest method testFakeProvider_convertsFakeData.

@Test
@Config(qualifiers = "mcc999")
public void testFakeProvider_convertsFakeData() {
    mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().clear();
    mSearchFeatureProvider.getSearchIndexableResources().getProviderValues().add(new SearchIndexableData(FakeIndexProvider.class, FakeIndexProvider.SEARCH_INDEX_DATA_PROVIDER));
    doReturn(getFakeService()).when(mSliceDataConverter).getAccessibilityServiceInfoList();
    List<SliceData> sliceDataList = mSliceDataConverter.getSliceData();
    assertThat(sliceDataList).hasSize(2);
    SliceData fakeSlice0 = sliceDataList.get(0);
    SliceData fakeSlice1 = sliceDataList.get(1);
    // Should not assume the order of the data list.
    if (TextUtils.equals(fakeSlice0.getKey(), FAKE_KEY)) {
        assertFakeSlice(fakeSlice0);
        assertFakeA11ySlice(fakeSlice1);
    } else {
        assertFakeSlice(fakeSlice1);
        assertFakeA11ySlice(fakeSlice0);
    }
}
Also used : SearchIndexableData(com.android.settingslib.search.SearchIndexableData) FakeIndexProvider(com.android.settings.testutils.FakeIndexProvider) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 2 with SearchIndexableData

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

the class SliceControllerInXmlCodeInspector method getIndexableXml.

private List<Integer> getIndexableXml() {
    final List<Integer> xmlResSet = new ArrayList<>();
    final Collection<SearchIndexableData> bundles = FeatureFactory.getFactory(mContext).getSearchFeatureProvider().getSearchIndexableResources().getProviderValues();
    for (SearchIndexableData bundle : bundles) {
        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) ArrayList(java.util.ArrayList) SearchIndexableData(com.android.settingslib.search.SearchIndexableData) Indexable(com.android.settingslib.search.Indexable)

Example 3 with SearchIndexableData

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

the class SettingsSearchIndexablesProvider method queryDynamicRawData.

/**
 * Gets a Cursor of dynamic Raw data similar to queryRawData. We use those data in search query
 * time
 */
@Nullable
@Override
public Cursor queryDynamicRawData(String[] projection) {
    final Context context = getContext();
    final List<SearchIndexableRaw> rawList = new ArrayList<>();
    final Collection<SearchIndexableData> bundles = FeatureFactory.getFactory(context).getSearchFeatureProvider().getSearchIndexableResources().getProviderValues();
    for (SearchIndexableData bundle : bundles) {
        rawList.addAll(getDynamicSearchIndexableRawData(context, bundle));
        // Refresh the search enabled state for indexing injection raw data
        final Indexable.SearchIndexProvider provider = bundle.getSearchIndexProvider();
        if (provider instanceof BaseSearchIndexProvider) {
            refreshSearchEnabledState(context, (BaseSearchIndexProvider) provider);
        }
    }
    rawList.addAll(getInjectionIndexableRawData(context));
    final MatrixCursor cursor = new MatrixCursor(INDEXABLES_RAW_COLUMNS);
    for (SearchIndexableRaw raw : rawList) {
        cursor.addRow(createIndexableRawColumnObjects(raw));
    }
    return cursor;
}
Also used : Context(android.content.Context) ArrayList(java.util.ArrayList) SearchIndexableData(com.android.settingslib.search.SearchIndexableData) SearchIndexableRaw(com.android.settingslib.search.SearchIndexableRaw) Indexable(com.android.settingslib.search.Indexable) MatrixCursor(android.database.MatrixCursor) Nullable(androidx.annotation.Nullable)

Example 4 with SearchIndexableData

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

the class SettingsSearchIndexablesProviderTest method setUp.

@Before
public void setUp() {
    mContext = RuntimeEnvironment.application;
    mProvider = spy(new SettingsSearchIndexablesProvider());
    ProviderInfo info = new ProviderInfo();
    info.exported = true;
    info.grantUriPermissions = true;
    info.authority = PACKAGE_NAME;
    info.readPermission = Manifest.permission.READ_SEARCH_INDEXABLES;
    mProvider.attachInfo(RuntimeEnvironment.application, info);
    final SearchFeatureProvider featureProvider = new SearchFeatureProviderImpl();
    featureProvider.getSearchIndexableResources().getProviderValues().clear();
    featureProvider.getSearchIndexableResources().getProviderValues().add(new SearchIndexableData(FakeSettingsFragment.class, FakeSettingsFragment.SEARCH_INDEX_DATA_PROVIDER));
    mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
    mFakeFeatureFactory.searchFeatureProvider = featureProvider;
    final ActivityInfo activityInfo = new ActivityInfo();
    activityInfo.packageName = "pkg";
    activityInfo.name = "class";
    activityInfo.metaData = new Bundle();
    activityInfo.metaData.putString(META_DATA_PREFERENCE_TITLE, "title");
    final DashboardCategory category = new DashboardCategory("key");
    when(mFakeFeatureFactory.dashboardFeatureProvider.getAllCategories()).thenReturn(Arrays.asList(category));
    category.addTile(new ActivityTile(activityInfo, category.key));
    ShadowCategoryManager.setDashboardCategory(category);
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) ActivityInfo(android.content.pm.ActivityInfo) ProviderInfo(android.content.pm.ProviderInfo) Bundle(android.os.Bundle) SearchIndexableData(com.android.settingslib.search.SearchIndexableData) ActivityTile(com.android.settingslib.drawer.ActivityTile) Before(org.junit.Before)

Example 5 with SearchIndexableData

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

the class SlicesDatabaseAccessorTest method getSliceKeys_indexesDatabase.

@Test
@Config(qualifiers = "mcc999")
public void getSliceKeys_indexesDatabase() {
    // Force new indexing
    Locale.setDefault(new Locale("ca"));
    final SearchFeatureProvider provider = new SearchFeatureProviderImpl();
    final SlicesFeatureProvider sliceProvider = new SlicesFeatureProviderImpl();
    final FakeFeatureFactory factory = FakeFeatureFactory.setupForTest();
    factory.searchFeatureProvider = provider;
    factory.slicesFeatureProvider = sliceProvider;
    // Fake the indexable list.
    provider.getSearchIndexableResources().getProviderValues().clear();
    provider.getSearchIndexableResources().getProviderValues().add(new SearchIndexableData(FakeIndexProvider.class, FakeIndexProvider.SEARCH_INDEX_DATA_PROVIDER));
    final SlicesDatabaseAccessor accessor = new SlicesDatabaseAccessor(mContext);
    final List<Uri> keys = accessor.getSliceUris(SettingsSliceProvider.SLICE_AUTHORITY, true);
    assertThat(keys).isNotEmpty();
}
Also used : Locale(java.util.Locale) SearchFeatureProviderImpl(com.android.settings.search.SearchFeatureProviderImpl) SearchIndexableData(com.android.settingslib.search.SearchIndexableData) SearchFeatureProvider(com.android.settings.search.SearchFeatureProvider) FakeFeatureFactory(com.android.settings.testutils.FakeFeatureFactory) Uri(android.net.Uri) FakeIndexProvider(com.android.settings.testutils.FakeIndexProvider) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

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