summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher2
diff options
context:
space:
mode:
authorMichael Jurka <mikejurka@google.com>2012-09-21 15:28:48 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-09-21 15:28:48 -0700
commite5574e0b7316890bcbce2465e632a04049b57769 (patch)
tree009f99c30cb5c3b210fc6f24f5bcbd4db4a877fe /src/com/android/launcher2
parentc4a9233a94ef186baa8113ceb44b08c65725ed41 (diff)
parentb2ae8acc0c65a5464a4782ee43e0594a15b9cc16 (diff)
downloadandroid_packages_apps_Trebuchet-e5574e0b7316890bcbce2465e632a04049b57769.tar.gz
android_packages_apps_Trebuchet-e5574e0b7316890bcbce2465e632a04049b57769.tar.bz2
android_packages_apps_Trebuchet-e5574e0b7316890bcbce2465e632a04049b57769.zip
Merge "Try to fix RTE when updating shortcuts" into jb-mr1-dev
Diffstat (limited to 'src/com/android/launcher2')
-rw-r--r--src/com/android/launcher2/LauncherModel.java83
1 files changed, 51 insertions, 32 deletions
diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java
index 11beda8dd..86a9a84f4 100644
--- a/src/com/android/launcher2/LauncherModel.java
+++ b/src/com/android/launcher2/LauncherModel.java
@@ -262,28 +262,59 @@ public class LauncherModel extends BroadcastReceiver {
}
}
+ static void checkItemInfoLocked(
+ final long itemId, final ItemInfo item, StackTraceElement[] stackTrace) {
+ ItemInfo modelItem = sBgItemsIdMap.get(itemId);
+ if (modelItem != null && item != modelItem) {
+ // check all the data is consistent
+ if (modelItem instanceof ShortcutInfo && item instanceof ShortcutInfo) {
+ ShortcutInfo modelShortcut = (ShortcutInfo) modelItem;
+ ShortcutInfo shortcut = (ShortcutInfo) item;
+ if (modelShortcut.title.toString().equals(shortcut.title.toString()) &&
+ modelShortcut.intent.filterEquals(shortcut.intent) &&
+ modelShortcut.id == shortcut.id &&
+ modelShortcut.itemType == shortcut.itemType &&
+ modelShortcut.container == shortcut.container &&
+ modelShortcut.screen == shortcut.screen &&
+ modelShortcut.cellX == shortcut.cellX &&
+ modelShortcut.cellY == shortcut.cellY &&
+ modelShortcut.spanX == shortcut.spanX &&
+ modelShortcut.spanY == shortcut.spanY &&
+ ((modelShortcut.dropPos == null && shortcut.dropPos == null) ||
+ (modelShortcut.dropPos != null &&
+ shortcut.dropPos != null &&
+ modelShortcut.dropPos[0] == shortcut.dropPos[0] &&
+ modelShortcut.dropPos[1] == shortcut.dropPos[1]))) {
+ // For all intents and purposes, this is the same object
+ return;
+ }
+ }
+
+ // the modelItem needs to match up perfectly with item if our model is
+ // to be consistent with the database-- for now, just require
+ // modelItem == item or the equality check above
+ String msg = "item: " + ((item != null) ? item.toString() : "null") +
+ "modelItem: " +
+ ((modelItem != null) ? modelItem.toString() : "null") +
+ "Error: ItemInfo passed to checkItemInfo doesn't match original";
+ RuntimeException e = new RuntimeException(msg);
+ if (stackTrace != null) {
+ e.setStackTrace(stackTrace);
+ }
+ throw e;
+ }
+ }
+
static void checkItemInfo(final ItemInfo item) {
final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
final long itemId = item.id;
Runnable r = new Runnable() {
- public void run() {
- synchronized (sBgLock) {
- ItemInfo modelItem = sBgItemsIdMap.get(itemId);
- if (modelItem != null && item != modelItem) {
- // the modelItem needs to match up perfectly with item if our model is
- // to be consistent with the database-- for now, just require
- // modelItem == item
- String msg = "item: " + ((item != null) ? item.toString() : "null") +
- "modelItem: " +
- ((modelItem != null) ? modelItem.toString() : "null") +
- "Error: ItemInfo passed to checkItemInfo doesn't match original";
- RuntimeException e = new RuntimeException(msg);
- e.setStackTrace(stackTrace);
- throw e;
- }
- }
+ public void run() {
+ synchronized (sBgLock) {
+ checkItemInfoLocked(itemId, item, stackTrace);
}
- };
+ }
+ };
runOnWorkerThread(r);
}
@@ -300,16 +331,7 @@ public class LauncherModel extends BroadcastReceiver {
// Lock on mBgLock *after* the db operation
synchronized (sBgLock) {
- ItemInfo modelItem = sBgItemsIdMap.get(itemId);
- if (item != modelItem) {
- // the modelItem needs to match up perfectly with item if our model is to be
- // consistent with the database-- for now, just require modelItem == item
- String msg = "item: " + ((item != null) ? item.toString() : "null") +
- "modelItem: " + ((modelItem != null) ? modelItem.toString() : "null") +
- "Error: ItemInfo passed to " + callingFunction + " doesn't match " +
- "original";
- throw new RuntimeException(msg);
- }
+ checkItemInfoLocked(itemId, item, stackTrace);
if (item.container != LauncherSettings.Favorites.CONTAINER_DESKTOP &&
item.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
@@ -329,6 +351,7 @@ public class LauncherModel extends BroadcastReceiver {
// Items are added/removed from the corresponding FolderInfo elsewhere, such
// as in Workspace.onDrop. Here, we just add/remove them from the list of items
// that are on the desktop, as appropriate
+ ItemInfo modelItem = sBgItemsIdMap.get(itemId);
if (modelItem.container == LauncherSettings.Favorites.CONTAINER_DESKTOP ||
modelItem.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
switch (modelItem.itemType) {
@@ -572,11 +595,7 @@ public class LauncherModel extends BroadcastReceiver {
// Lock on mBgLock *after* the db operation
synchronized (sBgLock) {
- if (sBgItemsIdMap.containsKey(item.id)) {
- // we should not be adding new items in the db with the same id
- throw new RuntimeException("Error: ItemInfo id (" + item.id + ") passed to " +
- "addItemToDatabase already exists." + item.toString());
- }
+ checkItemInfoLocked(item.id, item, null);
sBgItemsIdMap.put(item.id, item);
switch (item.itemType) {
case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: