From 7695e603bf1f4369115ba64c24e8b09c213b4e9c Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Fri, 5 Aug 2016 12:44:51 -0700 Subject: Remove shortcuts that no longer exist or are no longer pinned. (This change is in the onShortcutsChanged() callback.) - Remove all workspace icons that correspond to shortcuts that are now unpinned - Remove all workspace icons that have the same package and user handle as passed in onShortcutsChanged(), if they aren't included in the list of shortcuts that is also passed. These cases will happen for static and dynamic shortcuts, respectively, when an app's data is cleared. Bug: 30316501 Change-Id: I50db6567cb318d087012ab5d8208e765b81c6f99 --- src/com/android/launcher3/LauncherModel.java | 57 ++++++++++++++++++---------- 1 file changed, 36 insertions(+), 21 deletions(-) (limited to 'src/com/android/launcher3/LauncherModel.java') diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 68450e7a7..d66ce6b91 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -3380,40 +3380,55 @@ public class LauncherModel extends BroadcastReceiver public void run() { mDeepShortcutManager.onShortcutsChanged(mShortcuts); - Map idsToShortcuts = new HashMap<>(); - for (ShortcutInfoCompat shortcut : mShortcuts) { - idsToShortcuts.put(shortcut.getId(), shortcut); - } - // Find ShortcutInfo's that have changed on the workspace. + final ArrayList removedShortcutInfos = new ArrayList<>(); MultiHashMap idsToWorkspaceShortcutInfos = new MultiHashMap<>(); for (ItemInfo itemInfo : sBgItemsIdMap) { if (itemInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) { ShortcutInfo si = (ShortcutInfo) itemInfo; if (si.getPromisedIntent().getPackage().equals(mPackageName) && si.user.equals(mUser)) { - String shortcutId = si.getDeepShortcutId(); - if (idsToShortcuts.containsKey(shortcutId)) { - idsToWorkspaceShortcutInfos.addToList(shortcutId, si); - } + idsToWorkspaceShortcutInfos.addToList(si.getDeepShortcutId(), si); } } } - // Update the workspace to reflect the changes to updated shortcuts residing on it. - List shortcuts = mDeepShortcutManager.queryForFullDetails( - mPackageName, new ArrayList<>(idsToWorkspaceShortcutInfos.keySet()), mUser); - ArrayList updatedShortcutInfos = new ArrayList<>(); - Context context = LauncherAppState.getInstance().getContext(); - for (ShortcutInfoCompat fullDetails : shortcuts) { - List shortcutInfos = idsToWorkspaceShortcutInfos - .get(fullDetails.getId()); - for (ShortcutInfo shortcutInfo : shortcutInfos) { - shortcutInfo.updateFromDeepShortcutInfo(fullDetails, context); - updatedShortcutInfos.add(shortcutInfo); + final Context context = LauncherAppState.getInstance().getContext(); + final ArrayList updatedShortcutInfos = new ArrayList<>(); + if (!idsToWorkspaceShortcutInfos.isEmpty()) { + // Update the workspace to reflect the changes to updated shortcuts residing on it. + List shortcuts = mDeepShortcutManager.queryForFullDetails( + mPackageName, new ArrayList<>(idsToWorkspaceShortcutInfos.keySet()), mUser); + for (ShortcutInfoCompat fullDetails : shortcuts) { + List shortcutInfos = idsToWorkspaceShortcutInfos + .remove(fullDetails.getId()); + if (!fullDetails.isPinned()) { + // The shortcut was previously pinned but is no longer, so remove it from + // the workspace and our pinned shortcut counts. + // Note that we put this check here, after querying for full details, + // because there's a possible race condition between pinning and + // receiving this callback. + removedShortcutInfos.addAll(shortcutInfos); + continue; + } + for (ShortcutInfo shortcutInfo : shortcutInfos) { + shortcutInfo.updateFromDeepShortcutInfo(fullDetails, context); + updatedShortcutInfos.add(shortcutInfo); + } } } - bindUpdatedShortcuts(updatedShortcutInfos, mUser); + + // If there are still entries in idsToWorkspaceShortcutInfos, that means that + // the corresponding shortcuts weren't passed in onShortcutsChanged(). This + // means they were cleared, so we remove and unpin them now. + for (String id : idsToWorkspaceShortcutInfos.keySet()) { + removedShortcutInfos.addAll(idsToWorkspaceShortcutInfos.get(id)); + } + + bindUpdatedShortcuts(updatedShortcutInfos, removedShortcutInfos, mUser); + if (!removedShortcutInfos.isEmpty()) { + deleteItemsFromDatabase(context, removedShortcutInfos); + } if (mUpdateIdMap) { // Update the deep shortcut map if the list of ids has changed for an activity. -- cgit v1.2.3