From b2ae8acc0c65a5464a4782ee43e0594a15b9cc16 Mon Sep 17 00:00:00 2001 From: Michael Jurka Date: Fri, 21 Sep 2012 12:06:06 -0700 Subject: Try to fix RTE when updating shortcuts Bug: 6529398 Change-Id: Ib88eda5dc1eaf72aae161b25b080197b1049e824 --- src/com/android/launcher2/LauncherModel.java | 83 +++++++++++++++++----------- 1 file changed, 51 insertions(+), 32 deletions(-) (limited to 'src') 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: -- cgit v1.2.3