Updating ItemInfo objects in the worker thread

> Launcher was making non-trivial updates to ItemInfo objects
on UI thread. These updates were getting skipped when the
Activity gets destroyed (possibly due to onConfigurationChange)
> Unregistering SessionCallback on application onTerminate,
rather than activity onDestroy

Bug: 17941096
Change-Id: Iad4a50871fe09470f26139b44a2e9886833032f1
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index ec1c0aa..3762c2f 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -125,6 +125,7 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -2031,7 +2032,6 @@
         mWorkspace = null;
         mDragController = null;
 
-        PackageInstallerCompat.getInstance(this).onStop();
         LauncherAnimUtils.onDestroyActivity();
     }
 
@@ -4715,33 +4715,54 @@
             return;
         }
 
-        if (mWorkspace != null) {
-            mWorkspace.updateShortcutsAndWidgets(apps);
-        }
-
         if (!LauncherAppState.isDisableAllApps() &&
                 mAppsCustomizeContent != null) {
             mAppsCustomizeContent.updateApps(apps);
         }
     }
 
+    @Override
+    public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
+        Runnable r = new Runnable() {
+            public void run() {
+                bindWidgetsRestored(widgets);
+            }
+        };
+        if (waitUntilResume(r)) {
+            return;
+        }
+        mWorkspace.widgetsRestored(widgets);
+    }
+
     /**
      * Some shortcuts were updated in the background.
      *
      * Implementation of the method from LauncherModel.Callbacks.
      */
-    public void bindShortcutsUpdated(final ArrayList<ShortcutInfo> shortcuts) {
+    @Override
+    public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated,
+            final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) {
         Runnable r = new Runnable() {
             public void run() {
-                bindShortcutsUpdated(shortcuts);
+                bindShortcutsChanged(updated, removed, user);
             }
         };
         if (waitUntilResume(r)) {
             return;
         }
 
-        if (mWorkspace != null) {
-            mWorkspace.updateShortcuts(shortcuts);
+        if (!updated.isEmpty()) {
+            mWorkspace.updateShortcuts(updated);
+        }
+
+        if (!removed.isEmpty()) {
+            HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
+            for (ShortcutInfo si : removed) {
+                removedComponents.add(si.getTargetComponent());
+            }
+            mWorkspace.removeItemsByComponentName(removedComponents, user);
+            // Notify the drag controller
+            mDragController.onAppsRemoved(new ArrayList<String>(), removedComponents);
         }
     }
 
@@ -4792,19 +4813,23 @@
         }
 
         if (reason == 0) {
+            HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
+            for (AppInfo info : appInfos) {
+                removedComponents.add(info.componentName);
+            }
             if (!packageNames.isEmpty()) {
                 mWorkspace.removeItemsByPackageName(packageNames, user);
             }
-            if (!appInfos.isEmpty()) {
-                mWorkspace.removeItemsByApplicationInfo(appInfos, user);
+            if (!removedComponents.isEmpty()) {
+                mWorkspace.removeItemsByComponentName(removedComponents, user);
             }
+            // Notify the drag controller
+            mDragController.onAppsRemoved(packageNames, removedComponents);
+
         } else {
             mWorkspace.disableShortcutsByPackageName(packageNames, user, reason);
         }
 
-        // Notify the drag controller
-        mDragController.onAppsRemoved(packageNames, appInfos);
-
         // Update AllApps
         if (!LauncherAppState.isDisableAllApps() &&
                 mAppsCustomizeContent != null) {