Merge "Allow page to suppress all of its content from search."
This commit is contained in:
committed by
Android (Google) Code Review
commit
0ef2a55b08
@@ -64,6 +64,7 @@ import com.android.settings.core.instrumentation.SharedPreferencesLogger;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardSummary;
|
||||
import com.android.settings.dashboard.SearchResultsSummary;
|
||||
import com.android.settings.enterprise.EnterprisePrivacySettings;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.DynamicIndexableContentMonitor;
|
||||
import com.android.settings.search2.SearchFeatureProvider;
|
||||
@@ -945,8 +946,7 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
|
||||
setTileEnabled(new ComponentName(packageName,
|
||||
Settings.EnterprisePrivacySettingsActivity.class.getName()),
|
||||
FeatureFactory.getFactory(this).getEnterprisePrivacyFeatureProvider(this)
|
||||
.hasDeviceOwner(), isAdmin);
|
||||
EnterprisePrivacySettings.isPageEnabled(this), isAdmin);
|
||||
|
||||
setTileEnabled(new ComponentName(packageName,
|
||||
Settings.WifiDisplaySettingsActivity.class.getName()),
|
||||
|
@@ -23,6 +23,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -71,14 +72,25 @@ public class EnterprisePrivacySettings extends DashboardFragment {
|
||||
return controllers;
|
||||
}
|
||||
|
||||
public static boolean isPageEnabled(Context context) {
|
||||
return FeatureFactory.getFactory(context)
|
||||
.getEnterprisePrivacyFeatureProvider(context)
|
||||
.hasDeviceOwner();
|
||||
}
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.enterprise_privacy_settings;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
};
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return isPageEnabled(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.enterprise_privacy_settings;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -17,10 +17,20 @@
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.Xml;
|
||||
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.search2.XmlParserUtils;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -30,6 +40,7 @@ import java.util.List;
|
||||
*/
|
||||
public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider {
|
||||
|
||||
private static final String TAG = "BaseSearchIndex";
|
||||
private static final List<String> EMPTY_LIST = Collections.emptyList();
|
||||
|
||||
public BaseSearchIndexProvider() {
|
||||
@@ -47,6 +58,10 @@ public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider {
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
if (!isPageSearchEnabled(context)) {
|
||||
// Entire page should be suppressed, mark all keys from this page as non-indexable.
|
||||
return getNonIndexableKeysFromXml(context);
|
||||
}
|
||||
final List<PreferenceController> controllers = getPreferenceControllers(context);
|
||||
if (controllers != null && !controllers.isEmpty()) {
|
||||
final List<String> nonIndexableKeys = new ArrayList<>();
|
||||
@@ -63,4 +78,37 @@ public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider {
|
||||
public List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the page should be considered in search query. If return false, entire page
|
||||
* will be suppressed during search query.
|
||||
*/
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private List<String> getNonIndexableKeysFromXml(Context context) {
|
||||
final List<SearchIndexableResource> resources = getXmlResourcesToIndex(
|
||||
context, true /* not used*/);
|
||||
if (resources == null || resources.isEmpty()) {
|
||||
return EMPTY_LIST;
|
||||
}
|
||||
final List<String> nonIndexableKeys = new ArrayList<>();
|
||||
for (SearchIndexableResource res : resources) {
|
||||
final XmlResourceParser parser = context.getResources().getXml(res.xmlResId);
|
||||
final AttributeSet attrs = Xml.asAttributeSet(parser);
|
||||
try {
|
||||
while (parser.next() != XmlPullParser.END_DOCUMENT) {
|
||||
final String key = XmlParserUtils.getDataKey(context, attrs);
|
||||
if (!TextUtils.isEmpty(key)) {
|
||||
nonIndexableKeys.add(key);
|
||||
}
|
||||
}
|
||||
} catch (IOException | XmlPullParserException e) {
|
||||
Log.w(TAG, "Error parsing non-indexable from xml " + res.xmlResId);
|
||||
}
|
||||
}
|
||||
return nonIndexableKeys;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user