Instantiate pref controllers from xml if it's defined.

- If a <preference> tag also defines a controller, we will try to
  instantiate it before displaying the UI. The same logic is shared by
  BaseSearchIndexProvider so it also drives search suppression.

- If user also defines a list of controllers programatically, the
  programatically created ones takes precedence.

Bug: 73668763
Test: WIP
Change-Id: I7aecec270bcd3af261e012ef1f6995d2a523cfa1
This commit is contained in:
Fan Zhang
2018-02-21 15:22:25 -08:00
parent fc520ee38a
commit 917f101899
28 changed files with 496 additions and 267 deletions

View File

@@ -18,9 +18,8 @@ package com.android.settings.search;
import static android.provider.SearchIndexablesContract.COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE;
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.fail;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -36,6 +35,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -67,7 +67,7 @@ public class SearchIndexableResourcesTest {
final int beforeCount =
mSearchProvider.getSearchIndexableResources().getProviderValues().size();
( (SearchIndexableResourcesImpl) mSearchProvider.getSearchIndexableResources())
((SearchIndexableResourcesImpl) mSearchProvider.getSearchIndexableResources())
.addIndex(java.lang.String.class);
assertThat(mSearchProvider.getSearchIndexableResources().getProviderValues())
@@ -86,11 +86,13 @@ public class SearchIndexableResourcesTest {
@Test
public void testNonIndexableKeys_GetsKeyFromProvider() {
mSearchProvider.getSearchIndexableResources().getProviderValues().clear();
( (SearchIndexableResourcesImpl) mSearchProvider.getSearchIndexableResources())
((SearchIndexableResourcesImpl) mSearchProvider.getSearchIndexableResources())
.addIndex(FakeIndexProvider.class);
SettingsSearchIndexablesProvider provider = spy(new SettingsSearchIndexablesProvider());
doReturn(RuntimeEnvironment.application).when(provider).getContext();
Cursor cursor = provider.queryNonIndexableKeys(null);
boolean hasTestKey = false;
while (cursor.moveToNext()) {
@@ -106,8 +108,8 @@ public class SearchIndexableResourcesTest {
@Test
public void testAllClassNamesHaveProviders() {
for (Class clazz: mSearchProvider.getSearchIndexableResources().getProviderValues()) {
if(DatabaseIndexingUtils.getSearchIndexProvider(clazz) == null) {
for (Class clazz : mSearchProvider.getSearchIndexableResources().getProviderValues()) {
if (DatabaseIndexingUtils.getSearchIndexProvider(clazz) == null) {
fail(clazz.getName() + "is not an index provider");
}
}