Blocks resources from adding headers that match settings

Certain Xml resources have a single setting for the page
which often means the header and setting have the same
title. This CL stops the header from being indexed in
that case.

Bug: 33701673
Test: make RunSettingsRoboTests
Change-Id: Ie617414010e654c41fd014aa2fe297e6d2088ca5
This commit is contained in:
Matthew Fritze
2017-02-15 10:03:41 -08:00
parent c65e3a19a1
commit 04615bc1b6
2 changed files with 38 additions and 13 deletions

View File

@@ -33,6 +33,7 @@ import android.os.AsyncTask;
import android.provider.SearchIndexableData;
import android.provider.SearchIndexableResource;
import android.provider.SearchIndexablesContract;
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
@@ -545,7 +546,8 @@ public class DatabaseIndexingManager {
}
}
private void indexFromResource(SQLiteDatabase database, String localeStr,
@VisibleForTesting
void indexFromResource(SQLiteDatabase database, String localeStr,
SearchIndexableResource sir, List<String> nonIndexableKeys) {
final Context context = sir.context;
XmlResourceParser parser = null;
@@ -573,8 +575,11 @@ public class DatabaseIndexingManager {
String key = XmlParserUtils.getDataKey(context, attrs);
String title;
String headerTitle;
String summary;
String headerSummary;
String keywords;
String headerKeywords;
String childFragment;
ResultPayload payload;
boolean enabled;
@@ -595,13 +600,13 @@ public class DatabaseIndexingManager {
// Insert rows for the main PreferenceScreen node. Rewrite the data for removing
// hyphens.
title = XmlParserUtils.getDataTitle(context, attrs);
summary = XmlParserUtils.getDataSummary(context, attrs);
keywords = XmlParserUtils.getDataKeywords(context, attrs);
headerTitle = XmlParserUtils.getDataTitle(context, attrs);
headerSummary = XmlParserUtils.getDataSummary(context, attrs);
headerKeywords = XmlParserUtils.getDataKeywords(context, attrs);
enabled = !nonIndexableKeys.contains(key);
DatabaseRow.Builder builder = new DatabaseRow.Builder();
builder.setLocale(localeStr)
DatabaseRow.Builder headerBuilder = new DatabaseRow.Builder();
headerBuilder.setLocale(localeStr)
.setEntries(null)
.setClassName(fragmentName)
.setScreenTitle(screenTitle)
@@ -614,8 +619,9 @@ public class DatabaseIndexingManager {
.setKey(key)
.setUserId(-1 /* default user id */);
updateOneRowWithFilteredData(database, builder, title, summary,
null /* summary off */, keywords);
// Flag for XML headers which a child element's title.
boolean isHeaderUnique = true;
DatabaseRow.Builder builder;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
&& (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
@@ -625,11 +631,15 @@ public class DatabaseIndexingManager {
nodeName = parser.getName();
title = XmlParserUtils.getDataTitle(context, attrs);
key = XmlParserUtils.getDataKey(context, attrs);
enabled = ! nonIndexableKeys.contains(key);
title = XmlParserUtils.getDataTitle(context, attrs);
keywords = XmlParserUtils.getDataKeywords(context, attrs);
if (isHeaderUnique && TextUtils.equals(headerTitle, title)) {
isHeaderUnique = false;
}
builder = new DatabaseRow.Builder();
builder.setLocale(localeStr)
.setClassName(fragmentName)
@@ -674,6 +684,12 @@ public class DatabaseIndexingManager {
keywords);
}
}
// The xml header's title does not match the title of one of the child settings.
if (isHeaderUnique) {
updateOneRowWithFilteredData(database, headerBuilder, headerTitle, headerSummary,
null /* summary off */, headerKeywords);
}
} catch (XmlPullParserException e) {
throw new RuntimeException("Error parsing PreferenceScreen", e);
} catch (IOException e) {