summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2011-09-03 12:07:56 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-09-03 12:07:56 -0700
commite05b381c55a09170e4dfeb999800e8176731b29c (patch)
treed50380da587b8856c60d625c037d17e4d234d536 /src
parent6ba2a1b6e7595a14ba33e98f728b39d0ecb3ae36 (diff)
parent603bcb91a091d0f4512fdfb92d6df3c6f9fa8059 (diff)
downloadandroid_packages_apps_Trebuchet-e05b381c55a09170e4dfeb999800e8176731b29c.tar.gz
android_packages_apps_Trebuchet-e05b381c55a09170e4dfeb999800e8176731b29c.tar.bz2
android_packages_apps_Trebuchet-e05b381c55a09170e4dfeb999800e8176731b29c.zip
Merge "Prevent accessing LauncherModel data structures on main thread. (5220358)"
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher2/Launcher.java7
-rw-r--r--src/com/android/launcher2/LauncherModel.java41
2 files changed, 37 insertions, 11 deletions
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 637d95607..8bbf902b3 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -1602,7 +1602,9 @@ public final class Launcher extends Activity
* leak the previous Home screen on orientation change.
*/
private void unbindWorkspaceAndHotseatItems() {
- LauncherModel.unbindWorkspaceItems();
+ if (mModel != null) {
+ mModel.unbindWorkspaceItems();
+ }
}
/**
@@ -2754,9 +2756,6 @@ public final class Launcher extends Activity
if (mHotseat != null) {
mHotseat.resetLayout();
}
-
- // This wasn't being called before which resulted in a leak of AppWidgetHostViews
- unbindWorkspaceAndHotseatItems();
}
/**
diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java
index eee1a2674..e0b04dacb 100644
--- a/src/com/android/launcher2/LauncherModel.java
+++ b/src/com/android/launcher2/LauncherModel.java
@@ -155,10 +155,31 @@ public class LauncherModel extends BroadcastReceiver {
return Bitmap.createBitmap(mDefaultIcon);
}
- public static void unbindWorkspaceItems() {
- for (ItemInfo item: sWorkspaceItems) {
- item.unbind();
- }
+ public void unbindWorkspaceItems() {
+ sWorker.post(new Runnable() {
+ @Override
+ public void run() {
+ unbindWorkspaceItemsOnMainThread();
+ }
+ });
+ }
+
+ /** Unbinds all the sWorkspaceItems on the main thread, and return a copy of sWorkspaceItems
+ * that is save to reference from the main thread. */
+ private ArrayList<ItemInfo> unbindWorkspaceItemsOnMainThread() {
+ // Ensure that we don't use the same workspace items data structure on the main thread
+ // by making a copy of workspace items first.
+ final ArrayList<ItemInfo> workspaceItems = new ArrayList<ItemInfo>(sWorkspaceItems);
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ for (ItemInfo item : workspaceItems) {
+ item.unbind();
+ }
+ }
+ });
+
+ return workspaceItems;
}
/**
@@ -1176,8 +1197,12 @@ public class LauncherModel extends BroadcastReceiver {
}
}
});
+
+ // Unbind previously bound workspace items to prevent a leak of AppWidgetHostViews.
+ final ArrayList<ItemInfo> workspaceItems = unbindWorkspaceItemsOnMainThread();
+
// Add the items to the workspace.
- N = sWorkspaceItems.size();
+ N = workspaceItems.size();
for (int i=0; i<N; i+=ITEMS_CHUNK) {
final int start = i;
final int chunkSize = (i+ITEMS_CHUNK <= N) ? ITEMS_CHUNK : (N-i);
@@ -1185,16 +1210,18 @@ public class LauncherModel extends BroadcastReceiver {
public void run() {
Callbacks callbacks = tryGetCallbacks(oldCallbacks);
if (callbacks != null) {
- callbacks.bindItems(sWorkspaceItems, start, start+chunkSize);
+ callbacks.bindItems(workspaceItems, start, start+chunkSize);
}
}
});
}
+ // Ensure that we don't use the same folders data structure on the main thread
+ final HashMap<Long, FolderInfo> folders = new HashMap<Long, FolderInfo>(sFolders);
mHandler.post(new Runnable() {
public void run() {
Callbacks callbacks = tryGetCallbacks(oldCallbacks);
if (callbacks != null) {
- callbacks.bindFolders(sFolders);
+ callbacks.bindFolders(folders);
}
}
});