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:
@@ -274,6 +274,14 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
|
||||
public void updateRawDataToIndex(List<SearchIndexableRaw> rawData) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates dynamic raw data for search provider.
|
||||
*
|
||||
* Called by SearchIndexProvider#getDynamicRawDataToIndex
|
||||
*/
|
||||
public void updateDynamicRawDataToIndex(List<SearchIndexableRaw> rawData) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set {@link UiBlockListener}
|
||||
*
|
||||
|
@@ -18,8 +18,8 @@ package com.android.settings.core;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settingslib.search.SearchIndexableRaw;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.search.SearchIndexableRaw;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -62,4 +62,12 @@ public interface PreferenceControllerMixin {
|
||||
*/
|
||||
default void updateRawDataToIndex(List<SearchIndexableRaw> rawData) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates dynamic raw data for search provider.
|
||||
*
|
||||
* Called by SearchIndexProvider#getDynamicRawDataToIndex
|
||||
*/
|
||||
default void updateDynamicRawDataToIndex(List<SearchIndexableRaw> rawData) {
|
||||
}
|
||||
}
|
||||
|
@@ -77,8 +77,25 @@ public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
public List<SearchIndexableRaw> getDynamicRawDataToIndex(Context context, boolean enabled) {
|
||||
return null;
|
||||
final List<SearchIndexableRaw> dynamicRaws = new ArrayList<>();
|
||||
final List<AbstractPreferenceController> controllers = getPreferenceControllers(context);
|
||||
if (controllers == null || controllers.isEmpty()) {
|
||||
return dynamicRaws;
|
||||
}
|
||||
for (AbstractPreferenceController controller : controllers) {
|
||||
if (controller instanceof PreferenceControllerMixin) {
|
||||
((PreferenceControllerMixin) controller).updateDynamicRawDataToIndex(dynamicRaws);
|
||||
} else if (controller instanceof BasePreferenceController) {
|
||||
((BasePreferenceController) controller).updateDynamicRawDataToIndex(dynamicRaws);
|
||||
} else {
|
||||
Log.e(TAG, controller.getClass().getName()
|
||||
+ " must implement " + PreferenceControllerMixin.class.getName()
|
||||
+ " treating the dynamic indexable");
|
||||
}
|
||||
}
|
||||
return dynamicRaws;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user