Search in sources :

Example 1 with SearchIndexableResources

use of com.android.settingslib.search.SearchIndexableResources in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PreferenceControllerContractTest method controllersInSearchShouldImplementPreferenceControllerMixin.

@Test
@Presubmit
public void controllersInSearchShouldImplementPreferenceControllerMixin() {
    // Required by AutofillLoggingLevelPreferenceController
    Looper.prepare();
    final Set<String> errorClasses = new ArraySet<>();
    final SearchIndexableResources resources = FeatureFactory.getFactory(mContext).getSearchFeatureProvider().getSearchIndexableResources();
    for (Class<?> clazz : resources.getProviderValues()) {
        final Indexable.SearchIndexProvider provider = DatabaseIndexingUtils.getSearchIndexProvider(clazz);
        if (provider == null) {
            continue;
        }
        final List<AbstractPreferenceController> controllers = provider.getPreferenceControllers(mContext);
        if (controllers == null) {
            continue;
        }
        for (AbstractPreferenceController controller : controllers) {
            if (!(controller instanceof PreferenceControllerMixin) && !(controller instanceof BasePreferenceController)) {
                errorClasses.add(controller.getClass().getName());
            }
        }
    }
    if (!errorClasses.isEmpty()) {
        final StringBuilder errorMessage = new StringBuilder().append("Each preference must implement PreferenceControllerMixin ").append("or extend BasePreferenceController, ").append("the following classes don't:\n");
        for (String c : errorClasses) {
            errorMessage.append(c).append("\n");
        }
        fail(errorMessage.toString());
    }
}
Also used : ArraySet(android.util.ArraySet) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) Indexable(com.android.settings.search.Indexable) SearchIndexableResources(com.android.settingslib.search.SearchIndexableResources) Presubmit(android.platform.test.annotations.Presubmit) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test)

Example 2 with SearchIndexableResources

use of com.android.settingslib.search.SearchIndexableResources in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SliceDataContractTest method preferenceWithControllerMustHaveNonEmptyTitle.

@Test
@Presubmit
public void preferenceWithControllerMustHaveNonEmptyTitle() throws IOException, XmlPullParserException {
    final Set<String> nullTitleFragments = new HashSet<>();
    final SearchIndexableResources resources = FeatureFactory.getFactory(mContext).getSearchFeatureProvider().getSearchIndexableResources();
    for (Class<?> clazz : resources.getProviderValues()) {
        verifyPreferenceTitle(nullTitleFragments, clazz);
    }
    if (!nullTitleFragments.isEmpty()) {
        final StringBuilder error = new StringBuilder("All preferences with a controller must have a non-empty title by default, " + "found empty title in the following fragments\n");
        for (String c : nullTitleFragments) {
            error.append(c).append("\n");
        }
        fail(error.toString());
    }
}
Also used : SearchIndexableResources(com.android.settingslib.search.SearchIndexableResources) HashSet(java.util.HashSet) Presubmit(android.platform.test.annotations.Presubmit) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test)

Example 3 with SearchIndexableResources

use of com.android.settingslib.search.SearchIndexableResources in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class UniquePreferenceTest method allPreferencesShouldHaveUniqueKey.

/**
 * All preferences should have their unique key. It's especially important for many parts of
 * Settings to work properly: we assume pref keys are unique in displaying, search ranking,\
 * search result suppression, and many other areas.
 * <p/>
 * So in this test we are checking preferences participating in search.
 * <p/>
 * Note: Preference is not limited to just <Preference/> object. Everything in preference xml
 * should have a key.
 */
@Test
@Presubmit
public void allPreferencesShouldHaveUniqueKey() throws IOException, XmlPullParserException, Resources.NotFoundException {
    final Set<String> uniqueKeys = new HashSet<>();
    final Set<String> nullKeyClasses = new HashSet<>();
    final Set<String> duplicatedKeys = new HashSet<>();
    final SearchIndexableResources resources = FeatureFactory.getFactory(mContext).getSearchFeatureProvider().getSearchIndexableResources();
    for (Class<?> clazz : resources.getProviderValues()) {
        verifyPreferenceKeys(uniqueKeys, duplicatedKeys, nullKeyClasses, clazz);
    }
    if (!nullKeyClasses.isEmpty()) {
        final StringBuilder nullKeyErrors = new StringBuilder().append("Each preference/SearchIndexableData must have a key, ").append("the following classes have null keys:\n");
        for (String c : nullKeyClasses) {
            nullKeyErrors.append(c).append("\n");
        }
        fail(nullKeyErrors.toString());
    }
    if (!duplicatedKeys.isEmpty()) {
        final StringBuilder dupeKeysError = new StringBuilder("The following keys are not unique\n");
        for (String c : duplicatedKeys) {
            dupeKeysError.append(c).append("\n");
        }
        fail(dupeKeysError.toString());
    }
}
Also used : SearchIndexableResources(com.android.settingslib.search.SearchIndexableResources) HashSet(java.util.HashSet) Presubmit(android.platform.test.annotations.Presubmit) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test)

Aggregations

Presubmit (android.platform.test.annotations.Presubmit)3 MediumTest (androidx.test.filters.MediumTest)3 SearchIndexableResources (com.android.settingslib.search.SearchIndexableResources)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 ArraySet (android.util.ArraySet)1 Indexable (com.android.settings.search.Indexable)1 AbstractPreferenceController (com.android.settingslib.core.AbstractPreferenceController)1