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:
@@ -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) {
|
||||
|
@@ -15,7 +15,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package com.android.settings.search;
|
||||
package com.android.settings.search2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
@@ -25,8 +25,8 @@ import android.provider.SearchIndexableResource;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.search.IndexDatabaseHelper.SiteMapColumns;
|
||||
import com.android.settings.search2.DatabaseIndexingManager;
|
||||
import com.android.settings.search.IndexDatabaseHelper;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
import com.android.settings.testutils.DatabaseTestUtils;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -43,7 +43,6 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.android.settings.dashboard.SiteMapManager.SITE_MAP_COLUMNS;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
@@ -625,6 +624,16 @@ public class DatabaseIndexingManagerTest {
|
||||
assertThat(cursor.getCount()).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResourceWithTitleAndSettingName_TitleNotInserted() {
|
||||
SearchIndexableResource resource = getFakeResource(R.xml.swipe_to_notification_settings);
|
||||
mManager.indexFromResource(mDb, localeStr, resource, new ArrayList<String>());
|
||||
|
||||
Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index WHERE" +
|
||||
" enabled = 1", null);
|
||||
assertThat(cursor.getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
// Util functions
|
||||
|
||||
private SearchIndexableRaw getFakeRaw() {
|
Reference in New Issue
Block a user