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