Fix search indexing for encryption_and_credential page

- Rewrite search index provider to include all possible keys through
  getXmlResourcesToIndex()
- Add isPageSearchEnabled() to disable all keys if user is not admin
- Add getNonIndexableKeys to suppress unrelated keys based on current
  device state

Change-Id: I2c6943483789bf4c9f3931d344cf279fec0edaee
Fix: 37650170
Test: robotests
This commit is contained in:
Fan Zhang
2017-07-21 17:51:47 -07:00
parent 6666bf5605
commit a4a3833a08
7 changed files with 149 additions and 90 deletions

View File

@@ -16,10 +16,12 @@
package com.android.settings.search;
import android.annotation.XmlRes;
import android.content.Context;
import android.content.res.XmlResourceParser;
import android.provider.SearchIndexableResource;
import android.support.annotation.CallSuper;
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
@@ -94,18 +96,25 @@ public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider {
}
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);
}
nonIndexableKeys.addAll(getNonIndexableKeysFromXml(context, res.xmlResId));
}
return nonIndexableKeys;
}
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
public List<String> getNonIndexableKeysFromXml(Context context, @XmlRes int xmlResId) {
final List<String> nonIndexableKeys = new ArrayList<>();
final XmlResourceParser parser = context.getResources().getXml(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);
}
} catch (IOException | XmlPullParserException e) {
Log.w(TAG, "Error parsing non-indexable from xml " + xmlResId);
}
return nonIndexableKeys;
}