Loading src/com/android/settings/SettingsActivity.java +1 −6 Original line number Diff line number Diff line Loading @@ -564,12 +564,7 @@ public class SettingsActivity extends SettingsDrawerActivity // Run the Index update only if we have some space if (!Utils.isLowStorage(this)) { long indexStartTime = System.currentTimeMillis(); AsyncTask.execute(new Runnable() { @Override public void run() { Index.getInstance(getApplicationContext()).update(); } }); if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took " + (System.currentTimeMillis() - indexStartTime) + " ms"); } else { Loading src/com/android/settings/search/Index.java +59 −49 Original line number Diff line number Diff line Loading @@ -140,6 +140,7 @@ public class Index { 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; Loading Loading @@ -177,6 +178,7 @@ public class Index { public Map<String, List<String>> nonIndexableKeys; public boolean forceUpdate = false; public boolean fullIndex = true; public UpdateData() { dataToUpdate = new ArrayList<SearchIndexableData>(); Loading @@ -189,6 +191,7 @@ public class Index { dataToDelete = new ArrayList<SearchIndexableData>(other.dataToDelete); nonIndexableKeys = new HashMap<String, List<String>>(other.nonIndexableKeys); forceUpdate = other.forceUpdate; fullIndex = other.fullIndex; } public UpdateData copy() { Loading @@ -200,6 +203,7 @@ public class Index { dataToDelete.clear(); nonIndexableKeys.clear(); forceUpdate = false; fullIndex = false; } } Loading @@ -213,9 +217,7 @@ public class Index { */ public static Index getInstance(Context context) { if (sInstance == null) { sInstance = new Index(context, BASE_AUTHORITY); } else { sInstance.setContext(context); sInstance = new Index(context.getApplicationContext(), BASE_AUTHORITY); } return sInstance; } Loading Loading @@ -301,6 +303,9 @@ public class Index { } public void update() { AsyncTask.execute(new Runnable() { @Override public void run() { final Intent intent = new Intent(SearchIndexablesContract.PROVIDER_INTERFACE); List<ResolveInfo> list = mContext.getPackageManager().queryIntentContentProviders(intent, 0); Loading @@ -318,8 +323,11 @@ public class Index { addNonIndexablesKeysFromRemoteProvider(packageName, authority); } mDataToProcess.fullIndex = true; updateInternal(); } }); } private boolean addIndexablesFromRemoteProvider(String packageName, String authority) { try { Loading Loading @@ -472,7 +480,7 @@ public class Index { * @param includeInSearchResults true means that you want the bit "enabled" set so that the * data will be seen included into the search results */ public void updateFromClassNameResource(String className, boolean rebuild, public void updateFromClassNameResource(String className, final boolean rebuild, boolean includeInSearchResults) { if (className == null) { throw new IllegalArgumentException("class name cannot be null!"); Loading @@ -484,6 +492,9 @@ public class Index { } res.context = mContext; res.enabled = includeInSearchResults; AsyncTask.execute(new Runnable() { @Override public void run() { if (rebuild) { deleteIndexableData(res); } Loading @@ -492,12 +503,19 @@ public class Index { updateInternal(); res.enabled = false; } }); } public void updateFromSearchIndexableData(SearchIndexableData data) { AsyncTask.execute(new Runnable() { @Override public void run() { addIndexableData(data); mDataToProcess.forceUpdate = true; updateInternal(); } }); } private SQLiteDatabase getReadableDatabase() { return IndexDatabaseHelper.getInstance(mContext).getReadableDatabase(); Loading Loading @@ -1182,6 +1200,7 @@ public class Index { final Map<String, List<String>> nonIndexableKeys = params[0].nonIndexableKeys; final boolean forceUpdate = params[0].forceUpdate; final boolean fullIndex = params[0].fullIndex; final SQLiteDatabase database = getWritableDatabase(); if (database == null) { Loading @@ -1203,6 +1222,9 @@ public class Index { } finally { database.endTransaction(); } if (fullIndex) { setLocaleIndexed(localeStr); } return null; } Loading @@ -1225,8 +1247,8 @@ public class Index { try { indexOneSearchIndexableData(database, localeStr, data, nonIndexableKeys); } catch (Exception e) { Log.e(LOG_TAG, "Cannot index: " + data.className + " for locale: " + localeStr, e); Log.e(LOG_TAG, "Cannot index: " + (data != null ? data.className : data) + " for locale: " + localeStr, e); } } Loading Loading @@ -1273,24 +1295,12 @@ public class Index { return database.delete(Tables.TABLE_PREFS_INDEX, whereClause, whereArgs); } private boolean isLocaleAlreadyIndexed(SQLiteDatabase database, String locale) { Cursor cursor = null; boolean result = false; final StringBuilder sb = new StringBuilder(IndexColumns.LOCALE); sb.append(" = "); DatabaseUtils.appendEscapedSQLString(sb, locale); try { // We care only for 1 row cursor = database.query(Tables.TABLE_PREFS_INDEX, null, sb.toString(), null, null, null, null, "1"); final int count = cursor.getCount(); result = (count >= 1); } finally { if (cursor != null) { cursor.close(); private void setLocaleIndexed(String locale) { mContext.getSharedPreferences(INDEX, 0).edit().putBoolean(locale, true).commit(); } } return result; private boolean isLocaleAlreadyIndexed(SQLiteDatabase database, String locale) { return mContext.getSharedPreferences(INDEX, 0).getBoolean(locale, false); } } Loading Loading
src/com/android/settings/SettingsActivity.java +1 −6 Original line number Diff line number Diff line Loading @@ -564,12 +564,7 @@ public class SettingsActivity extends SettingsDrawerActivity // Run the Index update only if we have some space if (!Utils.isLowStorage(this)) { long indexStartTime = System.currentTimeMillis(); AsyncTask.execute(new Runnable() { @Override public void run() { Index.getInstance(getApplicationContext()).update(); } }); if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took " + (System.currentTimeMillis() - indexStartTime) + " ms"); } else { Loading
src/com/android/settings/search/Index.java +59 −49 Original line number Diff line number Diff line Loading @@ -140,6 +140,7 @@ public class Index { 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; Loading Loading @@ -177,6 +178,7 @@ public class Index { public Map<String, List<String>> nonIndexableKeys; public boolean forceUpdate = false; public boolean fullIndex = true; public UpdateData() { dataToUpdate = new ArrayList<SearchIndexableData>(); Loading @@ -189,6 +191,7 @@ public class Index { dataToDelete = new ArrayList<SearchIndexableData>(other.dataToDelete); nonIndexableKeys = new HashMap<String, List<String>>(other.nonIndexableKeys); forceUpdate = other.forceUpdate; fullIndex = other.fullIndex; } public UpdateData copy() { Loading @@ -200,6 +203,7 @@ public class Index { dataToDelete.clear(); nonIndexableKeys.clear(); forceUpdate = false; fullIndex = false; } } Loading @@ -213,9 +217,7 @@ public class Index { */ public static Index getInstance(Context context) { if (sInstance == null) { sInstance = new Index(context, BASE_AUTHORITY); } else { sInstance.setContext(context); sInstance = new Index(context.getApplicationContext(), BASE_AUTHORITY); } return sInstance; } Loading Loading @@ -301,6 +303,9 @@ public class Index { } public void update() { AsyncTask.execute(new Runnable() { @Override public void run() { final Intent intent = new Intent(SearchIndexablesContract.PROVIDER_INTERFACE); List<ResolveInfo> list = mContext.getPackageManager().queryIntentContentProviders(intent, 0); Loading @@ -318,8 +323,11 @@ public class Index { addNonIndexablesKeysFromRemoteProvider(packageName, authority); } mDataToProcess.fullIndex = true; updateInternal(); } }); } private boolean addIndexablesFromRemoteProvider(String packageName, String authority) { try { Loading Loading @@ -472,7 +480,7 @@ public class Index { * @param includeInSearchResults true means that you want the bit "enabled" set so that the * data will be seen included into the search results */ public void updateFromClassNameResource(String className, boolean rebuild, public void updateFromClassNameResource(String className, final boolean rebuild, boolean includeInSearchResults) { if (className == null) { throw new IllegalArgumentException("class name cannot be null!"); Loading @@ -484,6 +492,9 @@ public class Index { } res.context = mContext; res.enabled = includeInSearchResults; AsyncTask.execute(new Runnable() { @Override public void run() { if (rebuild) { deleteIndexableData(res); } Loading @@ -492,12 +503,19 @@ public class Index { updateInternal(); res.enabled = false; } }); } public void updateFromSearchIndexableData(SearchIndexableData data) { AsyncTask.execute(new Runnable() { @Override public void run() { addIndexableData(data); mDataToProcess.forceUpdate = true; updateInternal(); } }); } private SQLiteDatabase getReadableDatabase() { return IndexDatabaseHelper.getInstance(mContext).getReadableDatabase(); Loading Loading @@ -1182,6 +1200,7 @@ public class Index { final Map<String, List<String>> nonIndexableKeys = params[0].nonIndexableKeys; final boolean forceUpdate = params[0].forceUpdate; final boolean fullIndex = params[0].fullIndex; final SQLiteDatabase database = getWritableDatabase(); if (database == null) { Loading @@ -1203,6 +1222,9 @@ public class Index { } finally { database.endTransaction(); } if (fullIndex) { setLocaleIndexed(localeStr); } return null; } Loading @@ -1225,8 +1247,8 @@ public class Index { try { indexOneSearchIndexableData(database, localeStr, data, nonIndexableKeys); } catch (Exception e) { Log.e(LOG_TAG, "Cannot index: " + data.className + " for locale: " + localeStr, e); Log.e(LOG_TAG, "Cannot index: " + (data != null ? data.className : data) + " for locale: " + localeStr, e); } } Loading Loading @@ -1273,24 +1295,12 @@ public class Index { return database.delete(Tables.TABLE_PREFS_INDEX, whereClause, whereArgs); } private boolean isLocaleAlreadyIndexed(SQLiteDatabase database, String locale) { Cursor cursor = null; boolean result = false; final StringBuilder sb = new StringBuilder(IndexColumns.LOCALE); sb.append(" = "); DatabaseUtils.appendEscapedSQLString(sb, locale); try { // We care only for 1 row cursor = database.query(Tables.TABLE_PREFS_INDEX, null, sb.toString(), null, null, null, null, "1"); final int count = cursor.getCount(); result = (count >= 1); } finally { if (cursor != null) { cursor.close(); private void setLocaleIndexed(String locale) { mContext.getSharedPreferences(INDEX, 0).edit().putBoolean(locale, true).commit(); } } return result; private boolean isLocaleAlreadyIndexed(SQLiteDatabase database, String locale) { return mContext.getSharedPreferences(INDEX, 0).getBoolean(locale, false); } } Loading