Suppress rawData settings from indexing when page is disabled for search
Test: robotest, manual Fix: 324424783 Change-Id: Ie8423d16df387f13cf35c03005640cfd08a5b492
This commit is contained in:
@@ -45,6 +45,7 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A basic SearchIndexProvider that returns no data to index.
|
* A basic SearchIndexProvider that returns no data to index.
|
||||||
@@ -117,11 +118,18 @@ public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider {
|
|||||||
@Override
|
@Override
|
||||||
@CallSuper
|
@CallSuper
|
||||||
public List<String> getNonIndexableKeys(Context context) {
|
public List<String> getNonIndexableKeys(Context context) {
|
||||||
|
final List<String> nonIndexableKeys = new ArrayList<>();
|
||||||
if (!isPageSearchEnabled(context)) {
|
if (!isPageSearchEnabled(context)) {
|
||||||
// Entire page should be suppressed, mark all keys from this page as non-indexable.
|
// Entire page should be suppressed, mark all keys from this page as non-indexable.
|
||||||
return getNonIndexableKeysFromXml(context, true /* suppressAllPage */);
|
nonIndexableKeys.addAll(
|
||||||
|
getNonIndexableKeysFromXml(context, true /* suppressAllPage */));
|
||||||
|
nonIndexableKeys.addAll(
|
||||||
|
getRawDataToIndex(context, true /* enabled */)
|
||||||
|
.stream()
|
||||||
|
.map(data -> data.key)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
return nonIndexableKeys;
|
||||||
}
|
}
|
||||||
final List<String> nonIndexableKeys = new ArrayList<>();
|
|
||||||
nonIndexableKeys.addAll(getNonIndexableKeysFromXml(context, false /* suppressAllPage */));
|
nonIndexableKeys.addAll(getNonIndexableKeysFromXml(context, false /* suppressAllPage */));
|
||||||
final List<AbstractPreferenceController> controllers = getPreferenceControllers(context);
|
final List<AbstractPreferenceController> controllers = getPreferenceControllers(context);
|
||||||
if (controllers != null && !controllers.isEmpty()) {
|
if (controllers != null && !controllers.isEmpty()) {
|
||||||
|
|||||||
@@ -166,6 +166,16 @@ public class BaseSearchIndexProviderTest {
|
|||||||
return Collections.singletonList(sir);
|
return Collections.singletonList(sir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
|
||||||
|
List<SearchIndexableRaw> rawData = super.getRawDataToIndex(context, enabled);
|
||||||
|
SearchIndexableRaw raw = new SearchIndexableRaw(context);
|
||||||
|
raw.key = TEST_PREF_KEY;
|
||||||
|
raw.title = "title";
|
||||||
|
rawData.add(raw);
|
||||||
|
return rawData;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isPageSearchEnabled(Context context) {
|
protected boolean isPageSearchEnabled(Context context) {
|
||||||
return false;
|
return false;
|
||||||
@@ -176,6 +186,7 @@ public class BaseSearchIndexProviderTest {
|
|||||||
provider.getNonIndexableKeys(RuntimeEnvironment.application);
|
provider.getNonIndexableKeys(RuntimeEnvironment.application);
|
||||||
|
|
||||||
assertThat(nonIndexableKeys).contains("status_header");
|
assertThat(nonIndexableKeys).contains("status_header");
|
||||||
|
assertThat(nonIndexableKeys).contains(TEST_PREF_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user