Add new method to preference controller base for dynamic index.

- Add updateDynamicRawDataToIndex method.
- Implement preference controller index in BaseSearchIndexProvider.

Fixes: 144545478
Test: make RunSettingsGoogleRoboTests -j
      make RunSettingsRoboTests ROBOTEST_FILTER=
      com.android.settings.search.BaseSearchIndexProviderTest
Change-Id: Ibb11002227b280102b45d7c0610eae48ecf4c0f3
This commit is contained in:
Stanley Wang
2019-11-18 16:11:53 +08:00
parent cad7ff1653
commit 4a08fc1c59
4 changed files with 57 additions and 3 deletions

View File

@@ -28,6 +28,7 @@ import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.search.SearchIndexableRaw;
import org.junit.Before;
import org.junit.Test;
@@ -77,6 +78,12 @@ public class BaseSearchIndexProviderTest {
public String getPreferenceKey() {
return TEST_PREF_KEY;
}
@Override
public void updateDynamicRawDataToIndex(List<SearchIndexableRaw> rawData) {
final SearchIndexableRaw raw = new SearchIndexableRaw(this.mContext);
rawData.add(raw);
}
}
@Test
@@ -190,4 +197,18 @@ public class BaseSearchIndexProviderTest {
assertThat(nonIndexableKeys).contains("pref_key_5");
}
@Test
public void getDynamicRawDataToIndex_noPreferenceController_shouldReturnEmptyList() {
assertThat(mIndexProvider.getDynamicRawDataToIndex(mContext, true)).isEmpty();
}
@Test
public void getDynamicRawDataToIndex_hasDynamicRaw_shouldNotEmpty() {
List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new AvailablePreferenceController(mContext));
doReturn(controllers).when(mIndexProvider).createPreferenceControllers(mContext);
assertThat(mIndexProvider.getDynamicRawDataToIndex(mContext, true)).isNotEmpty();
}
}