Merge "Fix search indexing for encryption_and_credential page" into oc-dr1-dev

am: 6ef56e43ee

Change-Id: I162d479851065017806cb82a16eb8fba7ad5aca7
This commit is contained in:
Fan Zhang
2017-07-25 21:30:57 +00:00
committed by android-build-merger
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;
@@ -101,18 +103,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;
}