Merge "Fix search after upgrade" into nyc-dev
diff --git a/src/com/android/settings/search/Index.java b/src/com/android/settings/search/Index.java
index 40d34bc..d4fc6f8 100644
--- a/src/com/android/settings/search/Index.java
+++ b/src/com/android/settings/search/Index.java
@@ -140,7 +140,6 @@
IndexColumns.DATA_SUMMARY_OFF_NORMALIZED,
IndexColumns.DATA_ENTRIES
};
- private static final String INDEX = "index";
// Max number of saved search queries (who will be used for proposing suggestions)
private static long MAX_SAVED_SEARCH_QUERY = 64;
@@ -1223,7 +1222,7 @@
database.endTransaction();
}
if (fullIndex) {
- setLocaleIndexed(localeStr);
+ IndexDatabaseHelper.setLocaleIndexed(mContext, localeStr);
}
return null;
@@ -1233,7 +1232,7 @@
List<SearchIndexableData> dataToUpdate, Map<String, List<String>> nonIndexableKeys,
boolean forceUpdate) {
- if (!forceUpdate && isLocaleAlreadyIndexed(database, localeStr)) {
+ if (!forceUpdate && IndexDatabaseHelper.isLocaleAlreadyIndexed(mContext, localeStr)) {
Log.d(LOG_TAG, "Locale '" + localeStr + "' is already indexed");
return true;
}
@@ -1294,14 +1293,6 @@
return database.delete(Tables.TABLE_PREFS_INDEX, whereClause, whereArgs);
}
-
- private void setLocaleIndexed(String locale) {
- mContext.getSharedPreferences(INDEX, 0).edit().putBoolean(locale, true).commit();
- }
-
- private boolean isLocaleAlreadyIndexed(SQLiteDatabase database, String locale) {
- return mContext.getSharedPreferences(INDEX, 0).getBoolean(locale, false);
- }
}
/**
diff --git a/src/com/android/settings/search/IndexDatabaseHelper.java b/src/com/android/settings/search/IndexDatabaseHelper.java
index 152cbf3..cddee68 100644
--- a/src/com/android/settings/search/IndexDatabaseHelper.java
+++ b/src/com/android/settings/search/IndexDatabaseHelper.java
@@ -30,6 +30,8 @@
private static final String DATABASE_NAME = "search_index.db";
private static final int DATABASE_VERSION = 115;
+ private static final String INDEX = "index";
+
public interface Tables {
public static final String TABLE_PREFS_INDEX = "prefs_index";
public static final String TABLE_META_INDEX = "meta_index";
@@ -63,7 +65,7 @@
public static final String BUILD = "build";
}
- public interface SavedQueriesColums {
+ public interface SavedQueriesColums {
public static final String QUERY = "query";
public static final String TIME_STAMP = "timestamp";
}
@@ -133,6 +135,8 @@
private static IndexDatabaseHelper sSingleton;
+ private final Context mContext;
+
public static synchronized IndexDatabaseHelper getInstance(Context context) {
if (sSingleton == null) {
sSingleton = new IndexDatabaseHelper(context);
@@ -142,6 +146,7 @@
public IndexDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
+ mContext = context;
}
@Override
@@ -175,7 +180,7 @@
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion < DATABASE_VERSION) {
- Log.w(TAG, "Detected schema version '" + oldVersion + "'. " +
+ Log.w(TAG, "Detected schema version '" + oldVersion + "'. " +
"Index needs to be rebuilt for schema version '" + newVersion + "'.");
// We need to drop the tables and recreate them
reconstruct(db);
@@ -184,7 +189,7 @@
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- Log.w(TAG, "Detected schema version '" + oldVersion + "'. " +
+ Log.w(TAG, "Detected schema version '" + oldVersion + "'. " +
"Index needs to be rebuilt for schema version '" + newVersion + "'.");
// We need to drop the tables and recreate them
reconstruct(db);
@@ -203,11 +208,9 @@
if (cursor.moveToFirst()) {
version = cursor.getString(0);
}
- }
- catch (Exception e) {
+ } catch (Exception e) {
Log.e(TAG, "Cannot get build version from Index metadata");
- }
- finally {
+ } finally {
if (cursor != null) {
cursor.close();
}
@@ -215,7 +218,20 @@
return version;
}
+ public static void clearLocalesIndexed(Context context) {
+ context.getSharedPreferences(INDEX, 0).edit().clear().commit();
+ }
+
+ public static void setLocaleIndexed(Context context, String locale) {
+ context.getSharedPreferences(INDEX, 0).edit().putBoolean(locale, true).commit();
+ }
+
+ public static boolean isLocaleAlreadyIndexed(Context context, String locale) {
+ return context.getSharedPreferences(INDEX, 0).getBoolean(locale, false);
+ }
+
private void dropTables(SQLiteDatabase db) {
+ clearLocalesIndexed(mContext);
db.execSQL("DROP TABLE IF EXISTS " + Tables.TABLE_META_INDEX);
db.execSQL("DROP TABLE IF EXISTS " + Tables.TABLE_PREFS_INDEX);
db.execSQL("DROP TABLE IF EXISTS " + Tables.TABLE_SAVED_QUERIES);