Merge "Fix bug #17250939 Stability: ANRs in Settings: at com.android.settings.search.Index.updateInternal(Index.java:518)" into lmp-dev
diff --git a/src/com/android/settings/search/Index.java b/src/com/android/settings/search/Index.java
index 65d825b..f5a2fa9 100644
--- a/src/com/android/settings/search/Index.java
+++ b/src/com/android/settings/search/Index.java
@@ -181,6 +181,16 @@
nonIndexableKeys = new HashMap<String, List<String>>();
}
+ public UpdateData(UpdateData other) {
+ dataToUpdate = new ArrayList<SearchIndexableData>(other.dataToUpdate);
+ dataToDelete = new ArrayList<SearchIndexableData>(other.dataToDelete);
+ nonIndexableKeys = new HashMap<String, List<String>>(other.nonIndexableKeys);
+ }
+
+ public UpdateData copy() {
+ return new UpdateData(this);
+ }
+
public void clear() {
dataToUpdate.clear();
dataToDelete.clear();
@@ -286,7 +296,7 @@
}
}
- public boolean update() {
+ public void update() {
final Intent intent = new Intent(SearchIndexablesContract.PROVIDER_INTERFACE);
List<ResolveInfo> list =
mContext.getPackageManager().queryIntentContentProviders(intent, 0);
@@ -304,7 +314,7 @@
addNonIndexablesKeysFromRemoteProvider(packageName, authority);
}
- return updateInternal();
+ updateInternal();
}
private boolean addIndexablesFromRemoteProvider(String packageName, String authority) {
@@ -443,11 +453,10 @@
}
}
- private boolean updateFromRemoteProvider(String packageName, String authority) {
- if (!addIndexablesFromRemoteProvider(packageName, authority)) {
- return false;
+ private void updateFromRemoteProvider(String packageName, String authority) {
+ if (addIndexablesFromRemoteProvider(packageName, authority)) {
+ updateInternal();
}
- return updateInternal();
}
/**
@@ -457,9 +466,8 @@
* @param rebuild true means that you want to delete the data from the Index first.
* @param includeInSearchResults true means that you want the bit "enabled" set so that the
* data will be seen included into the search results
- * @return true of the Index update has been successful.
*/
- public boolean updateFromClassNameResource(String className, boolean rebuild,
+ public void updateFromClassNameResource(String className, boolean rebuild,
boolean includeInSearchResults) {
if (className == null) {
throw new IllegalArgumentException("class name cannot be null!");
@@ -467,7 +475,7 @@
final SearchIndexableResource res = SearchIndexableResources.getResourceByName(className);
if (res == null ) {
Log.e(LOG_TAG, "Cannot find SearchIndexableResources for class name: " + className);
- return false;
+ return;
}
res.context = mContext;
res.enabled = includeInSearchResults;
@@ -476,15 +484,14 @@
}
addIndexableData(res);
mDataToProcess.forceUpdate = true;
- boolean result = updateInternal();
+ updateInternal();
res.enabled = false;
- return result;
}
- public boolean updateFromSearchIndexableData(SearchIndexableData data) {
+ public void updateFromSearchIndexableData(SearchIndexableData data) {
addIndexableData(data);
mDataToProcess.forceUpdate = true;
- return updateInternal();
+ updateInternal();
}
private SQLiteDatabase getReadableDatabase() {
@@ -510,21 +517,12 @@
SearchIndexablesContract.NON_INDEXABLES_KEYS_PATH);
}
- private boolean updateInternal() {
+ private void updateInternal() {
synchronized (mDataToProcess) {
final UpdateIndexTask task = new UpdateIndexTask();
- task.execute(mDataToProcess);
- try {
- final boolean result = task.get();
- mDataToProcess.clear();
- return result;
- } catch (InterruptedException e) {
- Log.e(LOG_TAG, "Cannot update index", e);
- return false;
- } catch (ExecutionException e) {
- Log.e(LOG_TAG, "Cannot update index", e);
- return false;
- }
+ UpdateData copy = mDataToProcess.copy();
+ task.execute(copy);
+ mDataToProcess.clear();
}
}
@@ -1143,7 +1141,7 @@
/**
* A private class for updating the Index database
*/
- private class UpdateIndexTask extends AsyncTask<UpdateData, Integer, Boolean> {
+ private class UpdateIndexTask extends AsyncTask<UpdateData, Integer, Void> {
@Override
protected void onPreExecute() {
@@ -1152,15 +1150,13 @@
}
@Override
- protected void onPostExecute(Boolean aBoolean) {
- super.onPostExecute(aBoolean);
+ protected void onPostExecute(Void aVoid) {
+ super.onPostExecute(aVoid);
mIsAvailable.set(true);
}
@Override
- protected Boolean doInBackground(UpdateData... params) {
- boolean result = false;
-
+ protected Void doInBackground(UpdateData... params) {
final List<SearchIndexableData> dataToUpdate = params[0].dataToUpdate;
final List<SearchIndexableData> dataToDelete = params[0].dataToDelete;
final Map<String, List<String>> nonIndexableKeys = params[0].nonIndexableKeys;
@@ -1180,11 +1176,11 @@
forceUpdate);
}
database.setTransactionSuccessful();
- result = true;
} finally {
database.endTransaction();
}
- return result;
+
+ return null;
}
private boolean processDataToUpdate(SQLiteDatabase database, String localeStr,