Merge "Remove locale checking for indexing."
This commit is contained in:
committed by
Android (Google) Code Review
commit
ecb8355aff
@@ -18,7 +18,8 @@
|
||||
package com.android.settings.search;
|
||||
|
||||
import static com.android.settings.search.DatabaseResultLoader.COLUMN_INDEX_ID;
|
||||
import static com.android.settings.search.DatabaseResultLoader.COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE;
|
||||
import static com.android.settings.search.DatabaseResultLoader
|
||||
.COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE;
|
||||
import static com.android.settings.search.DatabaseResultLoader.COLUMN_INDEX_KEY;
|
||||
import static com.android.settings.search.DatabaseResultLoader.SELECT_COLUMNS;
|
||||
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.CLASS_NAME;
|
||||
@@ -26,7 +27,8 @@ import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_
|
||||
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_KEYWORDS;
|
||||
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_KEY_REF;
|
||||
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_ON;
|
||||
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_SUMMARY_ON_NORMALIZED;
|
||||
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns
|
||||
.DATA_SUMMARY_ON_NORMALIZED;
|
||||
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_TITLE;
|
||||
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DATA_TITLE_NORMALIZED;
|
||||
import static com.android.settings.search.IndexDatabaseHelper.IndexColumns.DOCID;
|
||||
@@ -132,7 +134,7 @@ public class DatabaseIndexingManager {
|
||||
PreIndexData indexData = getIndexDataFromProviders(providers, isFullIndex);
|
||||
|
||||
final long updateDatabaseStartTime = System.currentTimeMillis();
|
||||
updateDatabase(indexData, isFullIndex, localeStr);
|
||||
updateDatabase(indexData, isFullIndex);
|
||||
if (SettingsSearchIndexablesProvider.DEBUG) {
|
||||
final long updateDatabaseTime = System.currentTimeMillis() - updateDatabaseStartTime;
|
||||
Log.d(LOG_TAG, "performIndexing updateDatabase took time: " + updateDatabaseTime);
|
||||
@@ -197,10 +199,9 @@ public class DatabaseIndexingManager {
|
||||
* Finally, we record that the locale has been indexed.
|
||||
*
|
||||
* @param needsReindexing true the database needs to be rebuilt.
|
||||
* @param localeStr the default locale for the device.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
void updateDatabase(PreIndexData preIndexData, boolean needsReindexing, String localeStr) {
|
||||
void updateDatabase(PreIndexData preIndexData, boolean needsReindexing) {
|
||||
final Map<String, Set<String>> nonIndexableKeys = preIndexData.nonIndexableKeys;
|
||||
|
||||
final SQLiteDatabase database = getWritableDatabase();
|
||||
@@ -213,7 +214,7 @@ public class DatabaseIndexingManager {
|
||||
database.beginTransaction();
|
||||
|
||||
// Convert all Pre-index data to Index data.
|
||||
List<IndexData> indexData = getIndexData(localeStr, preIndexData);
|
||||
List<IndexData> indexData = getIndexData(preIndexData);
|
||||
insertIndexData(database, indexData);
|
||||
|
||||
// Only check for non-indexable key updates after initial index.
|
||||
@@ -229,9 +230,9 @@ public class DatabaseIndexingManager {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
List<IndexData> getIndexData(String locale, PreIndexData data) {
|
||||
List<IndexData> getIndexData(PreIndexData data) {
|
||||
if (mConverter == null) {
|
||||
mConverter = new IndexDataConverter(mContext, locale);
|
||||
mConverter = new IndexDataConverter(mContext);
|
||||
}
|
||||
return mConverter.convertPreIndexDataToIndexData(data);
|
||||
}
|
||||
|
@@ -67,7 +67,7 @@ public class IndexData {
|
||||
= Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
|
||||
|
||||
private IndexData(Builder builder) {
|
||||
locale = builder.mLocale;
|
||||
locale = Locale.getDefault().toString();
|
||||
updatedTitle = normalizeHyphen(builder.mTitle);
|
||||
updatedSummaryOn = normalizeHyphen(builder.mSummaryOn);
|
||||
if (Locale.JAPAN.toString().equalsIgnoreCase(locale)) {
|
||||
@@ -158,7 +158,6 @@ public class IndexData {
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String mLocale;
|
||||
private String mTitle;
|
||||
private String mSummaryOn;
|
||||
private String mEntries;
|
||||
@@ -177,11 +176,6 @@ public class IndexData {
|
||||
private int mPayloadType;
|
||||
private ResultPayload mPayload;
|
||||
|
||||
public Builder setLocale(String locale) {
|
||||
mLocale = locale;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTitle(String title) {
|
||||
mTitle = title;
|
||||
return this;
|
||||
|
@@ -59,11 +59,8 @@ public class IndexDataConverter {
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
private String mLocale;
|
||||
|
||||
public IndexDataConverter(Context context, String locale) {
|
||||
public IndexDataConverter(Context context) {
|
||||
mContext = context;
|
||||
mLocale = locale;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,7 +70,6 @@ public class IndexDataConverter {
|
||||
* {@link SearchIndexableRaw} and non-indexable keys.
|
||||
*/
|
||||
public List<IndexData> convertPreIndexDataToIndexData(PreIndexData preIndexData) {
|
||||
|
||||
final long current = System.currentTimeMillis();
|
||||
final List<SearchIndexableData> indexableData = preIndexData.dataToUpdate;
|
||||
final Map<String, Set<String>> nonIndexableKeys = preIndexData.nonIndexableKeys;
|
||||
@@ -125,18 +121,12 @@ public class IndexDataConverter {
|
||||
*/
|
||||
@Nullable
|
||||
private IndexData.Builder convertRaw(SearchIndexableRaw raw, Set<String> nonIndexableKeys) {
|
||||
// Should be the same locale as the one we are processing
|
||||
if (!raw.locale.toString().equalsIgnoreCase(mLocale)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// A row is enabled if it does not show up as an nonIndexableKey
|
||||
boolean enabled = !(nonIndexableKeys != null && nonIndexableKeys.contains(raw.key));
|
||||
|
||||
IndexData.Builder builder = new IndexData.Builder();
|
||||
builder.setTitle(raw.title)
|
||||
.setSummaryOn(raw.summaryOn)
|
||||
.setLocale(mLocale)
|
||||
.setEntries(raw.entries)
|
||||
.setKeywords(raw.keywords)
|
||||
.setClassName(raw.className)
|
||||
@@ -219,7 +209,6 @@ public class IndexDataConverter {
|
||||
headerBuilder.setTitle(headerTitle)
|
||||
.setSummaryOn(headerSummary)
|
||||
.setKeywords(headerKeywords)
|
||||
.setLocale(mLocale)
|
||||
.setClassName(fragmentName)
|
||||
.setScreenTitle(screenTitle)
|
||||
.setIntentAction(intentAction)
|
||||
@@ -253,7 +242,6 @@ public class IndexDataConverter {
|
||||
|
||||
builder = new IndexData.Builder();
|
||||
builder.setTitle(title)
|
||||
.setLocale(mLocale)
|
||||
.setKeywords(keywords)
|
||||
.setClassName(fragmentName)
|
||||
.setScreenTitle(screenTitle)
|
||||
@@ -352,11 +340,6 @@ public class IndexDataConverter {
|
||||
|
||||
if (resList != null) {
|
||||
for (SearchIndexableResource item : resList) {
|
||||
// Should be the same locale as the one we are processing
|
||||
if (!item.locale.toString().equalsIgnoreCase(mLocale)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
item.className = TextUtils.isEmpty(item.className)
|
||||
? className
|
||||
: item.className;
|
||||
|
@@ -86,15 +86,12 @@ public class DatabaseIndexingManagerTest {
|
||||
private final String updatedSummaryOn = "summary-on";
|
||||
private final String normalizedSummaryOn = "summaryon";
|
||||
private final String summaryOff = "summary\u2011off";
|
||||
private final String updatedSummaryOff = "summary-off";
|
||||
private final String normalizedSummaryOff = "summaryoff";
|
||||
private final String entries = "entries";
|
||||
private final String keywords = "keywords, keywordss, keywordsss";
|
||||
private final String spaceDelimittedKeywords = "keywords keywordss keywordsss";
|
||||
private final String screenTitle = "screen title";
|
||||
private final String className = "class name";
|
||||
private final int iconResId = 0xff;
|
||||
private final int noIcon = 0;
|
||||
private final String action = "action";
|
||||
private final String targetPackage = "target package";
|
||||
private final String targetClass = "target class";
|
||||
@@ -210,8 +207,7 @@ public class DatabaseIndexingManagerTest {
|
||||
|
||||
mManager.performIndexing();
|
||||
|
||||
verify(mManager).updateDatabase(data, true /* isFullIndex */,
|
||||
Locale.getDefault().toString());
|
||||
verify(mManager).updateDatabase(data, true /* isFullIndex */);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -243,8 +239,7 @@ public class DatabaseIndexingManagerTest {
|
||||
|
||||
mManager.performIndexing();
|
||||
|
||||
verify(mManager).updateDatabase(data, true /* isFullIndex */,
|
||||
Locale.getDefault().toString());
|
||||
verify(mManager).updateDatabase(data, true /* isFullIndex */);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -278,7 +273,7 @@ public class DatabaseIndexingManagerTest {
|
||||
@Test
|
||||
public void testLocaleUpdated_afterIndexing_localeNotAdded() {
|
||||
PreIndexData emptydata = new PreIndexData();
|
||||
mManager.updateDatabase(emptydata, true /* isFullIndex */, localeStr);
|
||||
mManager.updateDatabase(emptydata, true /* isFullIndex */);
|
||||
|
||||
assertThat(IndexDatabaseHelper.isLocaleAlreadyIndexed(mContext, localeStr)).isFalse();
|
||||
}
|
||||
@@ -295,7 +290,7 @@ public class DatabaseIndexingManagerTest {
|
||||
// Test that addDataToDatabase is called when dataToUpdate is non-empty
|
||||
PreIndexData indexData = new PreIndexData();
|
||||
indexData.dataToUpdate.add(getFakeRaw());
|
||||
mManager.updateDatabase(indexData, true /* isFullIndex */, localeStr);
|
||||
mManager.updateDatabase(indexData, true /* isFullIndex */);
|
||||
|
||||
Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
|
||||
cursor.moveToPosition(0);
|
||||
@@ -383,7 +378,7 @@ public class DatabaseIndexingManagerTest {
|
||||
public void testEmptyNonIndexableKeys_emptyDataKeyResources_addedToDatabase() {
|
||||
insertSpecialCase(TITLE_ONE, true /* enabled */, null /* dataReferenceKey */);
|
||||
PreIndexData emptydata = new PreIndexData();
|
||||
mManager.updateDatabase(emptydata, false /* needsReindexing */, localeStr);
|
||||
mManager.updateDatabase(emptydata, false /* needsReindexing */);
|
||||
|
||||
Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index WHERE enabled = 1", null);
|
||||
cursor.moveToPosition(0);
|
||||
|
@@ -56,10 +56,7 @@ public class IndexDataConverterTest {
|
||||
private static final String normalizedTitle = "titletitle";
|
||||
private static final String summaryOn = "summary\u2011on";
|
||||
private static final String updatedSummaryOn = "summary-on";
|
||||
private static final String normalizedSummaryOn = "summaryon";
|
||||
private static final String summaryOff = "summary\u2011off";
|
||||
private static final String updatedSummaryOff = "summary-off";
|
||||
private static final String normalizedSummaryOff = "summaryoff";
|
||||
private static final String entries = "entries";
|
||||
private static final String keywords = "keywords, keywordss, keywordsss";
|
||||
private static final String spaceDelimittedKeywords = "keywords keywordss keywordsss";
|
||||
@@ -100,7 +97,7 @@ public class IndexDataConverterTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mConverter = spy(new IndexDataConverter(mContext, localeStr));
|
||||
mConverter = spy(new IndexDataConverter(mContext));
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -160,13 +157,13 @@ public class IndexDataConverterTest {
|
||||
* TODO (b/66916397) investigate why locale is attached to IndexData
|
||||
*/
|
||||
@Test
|
||||
public void testInsertRawColumn_mismatchedLocale_noRowInserted() {
|
||||
public void testInsertRawColumn_mismatchedLocale_rowInserted() {
|
||||
final SearchIndexableRaw raw = getFakeRaw("ca-fr");
|
||||
PreIndexData preIndexData = new PreIndexData();
|
||||
preIndexData.dataToUpdate.add(raw);
|
||||
List<IndexData> indexData = mConverter.convertPreIndexDataToIndexData(preIndexData);
|
||||
|
||||
assertThat(indexData).isEmpty();
|
||||
assertThat(indexData).hasSize(1);
|
||||
}
|
||||
|
||||
// Tests for the flow: IndexOneResource -> IndexFromResource ->
|
||||
|
@@ -40,7 +40,7 @@ import org.robolectric.annotation.Config;
|
||||
public class IndexDataTest {
|
||||
private IndexData.Builder mBuilder;
|
||||
|
||||
private static final String LOCALE = "locale";
|
||||
private static final String LOCALE = "en_US";
|
||||
private static final String TITLE = "updated-title";
|
||||
private static final String NORM_TITLE = "updatedtitle";
|
||||
private static final String SUMMARY_ON = "updated-summary-on";
|
||||
@@ -156,8 +156,7 @@ public class IndexDataTest {
|
||||
|
||||
private IndexData.Builder createBuilder() {
|
||||
mBuilder = new IndexData.Builder();
|
||||
mBuilder.setLocale(LOCALE)
|
||||
.setTitle(TITLE)
|
||||
mBuilder.setTitle(TITLE)
|
||||
.setSummaryOn(SUMMARY_ON)
|
||||
.setEntries(ENTRIES)
|
||||
.setClassName(CLASS_NAME)
|
||||
|
Reference in New Issue
Block a user