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;
}
}
- 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;
String key = XmlParserUtils.getDataKey(context, attrs);
String title;
+ String headerTitle;
String summary;
+ String headerSummary;
String keywords;
+ String headerKeywords;
String childFragment;
ResultPayload payload;
boolean enabled;
// 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)
.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)) {
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)
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) {
*
*/
-package com.android.settings.search;
+package com.android.settings.search2;
import android.content.Context;
import android.database.Cursor;
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;
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;
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() {