Easier way to handle shortcuts

Change-Id: I91c4a25e961774de0bed51ba986802a1834173f9
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index db7a2ba..2634e21 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -3643,9 +3643,8 @@
         mWorkspaceLoading = false;
         if (upgradePath) {
             mWorkspace.saveWorkspaceToDb();
-            ArrayList<ComponentName> allApps = constructAllAppsComponents();
-            mWorkspace.stripDuplicateApps(allApps);
-            mIntentsOnWorkspaceFromUpgradePath = mWorkspace.stripDuplicateApps(allApps);
+            mWorkspace.stripDuplicateApps();
+            mIntentsOnWorkspaceFromUpgradePath = mWorkspace.stripDuplicateApps();
         }
 
         mWorkspace.post(new Runnable() {
@@ -3656,25 +3655,6 @@
         });
     }
 
-    private ArrayList<ComponentName> constructAllAppsComponents() {
-        // Run through this twice... a little hackleberry, but the right solution is complex.
-        final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
-        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
-
-        List<ResolveInfo> apps = getPackageManager().queryIntentActivities(mainIntent, 0);
-        ArrayList<ComponentName> allApps = new ArrayList<ComponentName>();
-
-        int count = apps.size();
-        for (int i = 0; i < count; i++) {
-            ActivityInfo ai = apps.get(i).activityInfo;
-
-            ComponentName cn =
-                    new ComponentName(ai.applicationInfo.packageName, ai.name);
-            allApps.add(cn);
-        }
-        return allApps;
-    }
-
     private boolean canRunNewAppsAnimation() {
         long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
         return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index dc784ee..41f0242 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -3430,19 +3430,18 @@
         }
     }
 
-    ArrayList<ComponentName> stripDuplicateApps(ArrayList<ComponentName> allApps) {
+    ArrayList<ComponentName> stripDuplicateApps() {
         ArrayList<ComponentName> uniqueIntents = new ArrayList<ComponentName>();
-        stripDuplicateApps((CellLayout) mLauncher.getHotseat().getLayout(), uniqueIntents, allApps);
+        stripDuplicateApps((CellLayout) mLauncher.getHotseat().getLayout(), uniqueIntents);
         int count = getChildCount();
         for (int i = 0; i < count; i++) {
             CellLayout cl = (CellLayout) getChildAt(i);
-            stripDuplicateApps(cl, uniqueIntents, allApps);
+            stripDuplicateApps(cl, uniqueIntents);
         }
         return uniqueIntents;
     }
 
-    void stripDuplicateApps(CellLayout cl, ArrayList<ComponentName> uniqueIntents,
-            ArrayList<ComponentName> allApps) {
+    void stripDuplicateApps(CellLayout cl, ArrayList<ComponentName> uniqueIntents) {
         int count = cl.getShortcutsAndWidgets().getChildCount();
 
         ArrayList<View> children = new ArrayList<View>();
@@ -3458,15 +3457,11 @@
             if (info instanceof ShortcutInfo) {
                 ShortcutInfo si = (ShortcutInfo) info;
                 ComponentName cn = si.intent.getComponent();
-                Uri dataUri = si.intent.getData();
 
-                // If dataUri is not null / empty or if this component isn't one that would
-                // have previously showed up in the AllApps list, then this is a widget-type
-                // shortcut, so ignore it.
-                if ((dataUri != null && !dataUri.equals(Uri.EMPTY))
-                        || !allApps.contains(cn)) {
+                if (si.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
                     continue;
                 }
+
                 if (!uniqueIntents.contains(cn)) {
                     uniqueIntents.add(cn);
                 } else {
@@ -3481,13 +3476,8 @@
                     if (items.get(j).getTag() instanceof ShortcutInfo) {
                         ShortcutInfo si = (ShortcutInfo) items.get(j).getTag();
                         ComponentName cn = si.intent.getComponent();
-                        Uri dataUri = si.intent.getData();
 
-                        // If dataUri is not null / empty or if this component isn't one that would
-                        // have previously showed up in the AllApps list, then this is a widget-type
-                        // shortcut, so ignore it.
-                        if (dataUri != null && !dataUri.equals(Uri.EMPTY)
-                                || !allApps.contains(cn)) {
+                        if (si.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
                             continue;
                         }
                         if (!uniqueIntents.contains(cn)) {