am 6508fe1b: (-s ours) am d0642c42: Merge remote-tracking branch \'goog/ub-now-lunchbox\' into lunchbox-release

* commit '6508fe1b07ec888012255e3a2438382b45a9707f':
  Fix NPE in when dropping from all apps (issue 12917451)
  update placeholder on package install or restore
diff --git a/res/values-lo-rLA/strings.xml b/res/values-lo-rLA/strings.xml
index 79a0a4a..a23b77b 100644
--- a/res/values-lo-rLA/strings.xml
+++ b/res/values-lo-rLA/strings.xml
@@ -95,6 +95,8 @@
     <string name="migration_cling_use_default" msgid="2626475813981258626">"ເລີ່ມຕົ້ນໃໝ່"</string>
     <string name="workspace_cling_title" msgid="5626202359865825661">"ຈັດການພື້ນທີ່ຂອງທ່ານ"</string>
     <string name="workspace_cling_move_item" msgid="528201129978005352">"ແຕະຄ້າງໄວ້ທີ່ພາບພື້ນຫຼັງເພື່ອຈັດການພາບພື້ນຫຼັງ, ວິດເຈັດແລະການຕັ້ງຄ່າ."</string>
+    <string name="all_apps_cling_title" msgid="34929250753095858">"ເລືອກແອັບຯ"</string>
+    <string name="all_apps_cling_add_item" msgid="400866858451850784">"ເພື່ອເພີ່ມແອັບຯໃສ່ໜ້າຈໍຫຼັກຂອງທ່ານ, ໃຫ້ແຕະຄ້າງໄວ້."</string>
     <string name="folder_cling_title" msgid="3894908818693254164">"ນີ້ແມ່ນໂຟນເດີ"</string>
     <string name="folder_cling_create_folder" msgid="6158215559475836131">"ເພື່ອ​ສ້າງ​ອັນໃໝ່​ແບບນີ້ ໃຫ້​ແຕະ​ຄ້າງ​ໄວ້​ທີ່​ແອັບຯ​ທີ່​ຕ້ອງການ​ຍ້າຍ​ແລ້ວ​ລາກ​ມັນ​ໄປ​ຫາ​ໂຕ​ອື່ນ."</string>
     <string name="cling_dismiss" msgid="8962359497601507581">"ຕົກລົງ"</string>
diff --git a/src/com/android/launcher3/AppInfo.java b/src/com/android/launcher3/AppInfo.java
index da222f1..d5a7769 100644
--- a/src/com/android/launcher3/AppInfo.java
+++ b/src/com/android/launcher3/AppInfo.java
@@ -64,10 +64,6 @@
         return intent;
     }
 
-    protected Intent getRestoredIntent() {
-        return null;
-    }
-
     /**
      * Must not hold the Context.
      */
diff --git a/src/com/android/launcher3/InstallShortcutReceiver.java b/src/com/android/launcher3/InstallShortcutReceiver.java
index 28cef13..7ab4e04 100644
--- a/src/com/android/launcher3/InstallShortcutReceiver.java
+++ b/src/com/android/launcher3/InstallShortcutReceiver.java
@@ -304,7 +304,7 @@
             // Add the new apps to the model and bind them
             if (!addShortcuts.isEmpty()) {
                 LauncherAppState app = LauncherAppState.getInstance();
-                app.getModel().addAndBindAddedWorkspaceApps(context, addShortcuts);
+                app.getModel().addAndBindAddedApps(context, addShortcuts, new ArrayList<AppInfo>());
             }
         }
     }
diff --git a/src/com/android/launcher3/ItemInfo.java b/src/com/android/launcher3/ItemInfo.java
index 3dc92c9..36ba6c1 100644
--- a/src/com/android/launcher3/ItemInfo.java
+++ b/src/com/android/launcher3/ItemInfo.java
@@ -122,10 +122,6 @@
         throw new RuntimeException("Unexpected Intent");
     }
 
-    protected Intent getRestoredIntent() {
-        throw new RuntimeException("Unexpected Intent");
-    }
-
     /**
      * Write the fields of this item to the DB
      * 
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index c57d32e..13507c6 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -3852,17 +3852,15 @@
         }
 
         // Add the new screens
-        if (newScreens != null) {
-            bindAddScreens(newScreens);
-        }
+        bindAddScreens(newScreens);
 
         // We add the items without animation on non-visible pages, and with
         // animations on the new page (which we will try and snap to).
-        if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
+        if (!addNotAnimated.isEmpty()) {
             bindItems(addNotAnimated, 0,
                     addNotAnimated.size(), false);
         }
-        if (addAnimated != null && !addAnimated.isEmpty()) {
+        if (!addAnimated.isEmpty()) {
             bindItems(addAnimated, 0,
                     addAnimated.size(), true);
         }
diff --git a/src/com/android/launcher3/LauncherBackupHelper.java b/src/com/android/launcher3/LauncherBackupHelper.java
index a45f293..335028d 100644
--- a/src/com/android/launcher3/LauncherBackupHelper.java
+++ b/src/com/android/launcher3/LauncherBackupHelper.java
@@ -193,7 +193,7 @@
             Log.e(TAG, "launcher backup has failed", e);
         }
 
-        out.key = keys.toArray(new BackupProtos.Key[keys.size()]);
+        out.key = keys.toArray(BackupProtos.Key.emptyArray());
         writeJournal(newState, out);
         Log.v(TAG, "onBackup: wrote " + out.bytes + "b in " + out.rows + " rows.");
     }
@@ -266,7 +266,7 @@
         // will catch any changes the restore process might have made
         Journal out = new Journal();
         out.t = 0;
-        out.key = mKeys.toArray(new BackupProtos.Key[mKeys.size()]);
+        out.key = mKeys.toArray(BackupProtos.Key.emptyArray());
         writeJournal(newState, out);
         Log.v(TAG, "onRestore: read " + mKeys.size() + " rows");
         mKeys.clear();
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index ff8a356..6839bb3 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -292,52 +292,17 @@
         return null;
     }
 
-    public void addAppsToAllApps(final Context ctx, final ArrayList<AppInfo> allAppsApps) {
-        final Callbacks callbacks = mCallbacks != null ? mCallbacks.get() : null;
-
-        if (allAppsApps == null) {
-            throw new RuntimeException("allAppsApps must not be null");
-        }
-        if (allAppsApps.isEmpty()) {
-            return;
-        }
-
-        final ArrayList<AppInfo> restoredAppsFinal = new ArrayList<AppInfo>();
-        Iterator<AppInfo> iter = allAppsApps.iterator();
-        while (iter.hasNext()) {
-            ItemInfo a = iter.next();
-            if (LauncherModel.appWasRestored(ctx, a.getIntent())) {
-                restoredAppsFinal.add((AppInfo) a);
-            }
-        }
-
-        // Process the newly added applications and add them to the database first
-        Runnable r = new Runnable() {
-            public void run() {
-                runOnMainThread(new Runnable() {
-                    public void run() {
-                        Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
-                        if (callbacks == cb && cb != null) {
-                            callbacks.bindAppsAdded(null, null, null, allAppsApps);
-                            if (!restoredAppsFinal.isEmpty()) {
-                                callbacks.bindAppsUpdated(restoredAppsFinal);
-                            }
-                        }
-                    }
-                });
-            }
-        };
-        runOnWorkerThread(r);
+    public void addAndBindAddedApps(final Context context, final ArrayList<ItemInfo> workspaceApps,
+                                    final ArrayList<AppInfo> allAppsApps) {
+        Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
+        addAndBindAddedApps(context, workspaceApps, cb, allAppsApps);
     }
-
-    public void addAndBindAddedWorkspaceApps(final Context context,
-            final ArrayList<ItemInfo> workspaceApps) {
-        final Callbacks callbacks = mCallbacks != null ? mCallbacks.get() : null;
-
-        if (workspaceApps == null) {
+    public void addAndBindAddedApps(final Context context, final ArrayList<ItemInfo> workspaceApps,
+                                final Callbacks callbacks, final ArrayList<AppInfo> allAppsApps) {
+        if (workspaceApps == null || allAppsApps == null) {
             throw new RuntimeException("workspaceApps and allAppsApps must not be null");
         }
-        if (workspaceApps.isEmpty()) {
+        if (workspaceApps.isEmpty() && allAppsApps.isEmpty()) {
             return;
         }
         // Process the newly added applications and add them to the database first
@@ -345,7 +310,6 @@
             public void run() {
                 final ArrayList<ItemInfo> addedShortcutsFinal = new ArrayList<ItemInfo>();
                 final ArrayList<Long> addedWorkspaceScreensFinal = new ArrayList<Long>();
-                final ArrayList<AppInfo> restoredAppsFinal = new ArrayList<AppInfo>();
 
                 // Get the list of workspace screens.  We need to append to this list and
                 // can not use sBgWorkspaceScreens because loadWorkspace() may not have been
@@ -366,11 +330,6 @@
 
                         // Short-circuit this logic if the icon exists somewhere on the workspace
                         if (LauncherModel.shortcutExists(context, name, launchIntent)) {
-                            // Only InstallShortcutReceiver sends us shortcutInfos, ignore them
-                            if (a instanceof AppInfo &&
-                                    LauncherModel.appWasRestored(context, launchIntent)) {
-                                restoredAppsFinal.add((AppInfo) a);
-                            }
                             continue;
                         }
 
@@ -426,7 +385,7 @@
                 // Update the workspace screens
                 updateWorkspaceScreenOrder(context, workspaceScreens);
 
-                if (!addedShortcutsFinal.isEmpty()) {
+                if (!addedShortcutsFinal.isEmpty() || !allAppsApps.isEmpty()) {
                     runOnMainThread(new Runnable() {
                         public void run() {
                             Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
@@ -445,10 +404,7 @@
                                     }
                                 }
                                 callbacks.bindAppsAdded(addedWorkspaceScreensFinal,
-                                        addNotAnimated, addAnimated, null);
-                                if (!restoredAppsFinal.isEmpty()) {
-                                    callbacks.bindAppsUpdated(restoredAppsFinal);
-                                }
+                                        addNotAnimated, addAnimated, allAppsApps);
                             }
                         }
                     });
@@ -814,30 +770,6 @@
     }
 
     /**
-     * Returns true if the shortcuts already exists in the database.
-     * we identify a shortcut by the component name of the intent.
-     */
-    static boolean appWasRestored(Context context, Intent intent) {
-        final ContentResolver cr = context.getContentResolver();
-        final ComponentName component = intent.getComponent();
-        if (component == null) {
-            return false;
-        }
-        String componentName = component.flattenToString();
-        final String where = "intent glob \"*component=" + componentName + "*\" and restored = 1";
-        Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI,
-                new String[]{"intent", "restored"}, where, null, null);
-        boolean result = false;
-        try {
-            result = c.moveToFirst();
-        } finally {
-            c.close();
-        }
-        Log.d(TAG, "shortcutWasRestored is " + result + " for " + componentName);
-        return result;
-    }
-
-    /**
      * Returns an ItemInfo array containing all the items in the LauncherModel.
      * The ItemInfo.id is not set through this function.
      */
@@ -1629,7 +1561,8 @@
                 }
             }
             if (!added.isEmpty()) {
-                addAndBindAddedWorkspaceApps(context, added);
+                Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
+                addAndBindAddedApps(context, added, cb, new ArrayList<AppInfo>());
             }
         }
 
@@ -1884,7 +1817,7 @@
                                     Launcher.addDumpLog(TAG,
                                             "constructing info for partially restored package",
                                             true);
-                                    info = getRestoredItemInfo(c, titleIndex, intent);
+                                    info = getRestoredItemInfo(c, titleIndex);
                                     intent = getRestoredItemIntent(c, context, intent);
                                 } else if (itemType ==
                                         LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
@@ -2709,14 +2642,14 @@
 
             if (added != null) {
                 // Ensure that we add all the workspace applications to the db
-                if (LauncherAppState.isDisableAllApps()) {
-                    final ArrayList<ItemInfo> addedInfos = new ArrayList<ItemInfo>(added);
-                    addAndBindAddedWorkspaceApps(context, addedInfos);
+                Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
+                if (!LauncherAppState.isDisableAllApps()) {
+                    addAndBindAddedApps(context, new ArrayList<ItemInfo>(), cb, added);
                 } else {
-                    addAppsToAllApps(context, added);
+                    final ArrayList<ItemInfo> addedInfos = new ArrayList<ItemInfo>(added);
+                    addAndBindAddedApps(context, addedInfos, cb, added);
                 }
             }
-
             if (modified != null) {
                 final ArrayList<AppInfo> modifiedFinal = modified;
 
@@ -2855,7 +2788,7 @@
      * Make an ShortcutInfo object for a restored application or shortcut item that points
      * to a package that is not yet installed on the system.
      */
-    public ShortcutInfo getRestoredItemInfo(Cursor cursor, int titleIndex, Intent intent) {
+    public ShortcutInfo getRestoredItemInfo(Cursor cursor, int titleIndex) {
         final ShortcutInfo info = new ShortcutInfo();
         info.usingFallbackIcon = true;
         info.setIcon(getFallbackIcon());
@@ -2865,7 +2798,6 @@
             info.title = "";
         }
         info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
-        info.restoredIntent = intent;
         return info;
     }
 
@@ -2874,7 +2806,6 @@
      * to the market page for the item.
      */
     private Intent getRestoredItemIntent(Cursor c, Context context, Intent intent) {
-        final boolean debug = false;
         ComponentName componentName = intent.getComponent();
         Intent marketIntent = new Intent(Intent.ACTION_VIEW);
         Uri marketUri = new Uri.Builder()
@@ -2882,7 +2813,7 @@
                 .authority("details")
                 .appendQueryParameter("id", componentName.getPackageName())
                 .build();
-        if (debug) Log.d(TAG, "manufactured intent uri: " + marketUri.toString());
+        Log.d(TAG, "manufactured intent uri: " + marketUri.toString());
         marketIntent.setData(marketUri);
         return marketIntent;
     }
@@ -3048,10 +2979,6 @@
                     Intent.ACTION_MAIN.equals(intent.getAction()) && name != null) {
                 return true;
             }
-            // placeholder shortcuts get special treatment, let them through too.
-            if (info.getRestoredIntent() != null) {
-                return true;
-            }
         }
         return false;
     }
diff --git a/src/com/android/launcher3/ShortcutInfo.java b/src/com/android/launcher3/ShortcutInfo.java
index 79d114c..660f32c 100644
--- a/src/com/android/launcher3/ShortcutInfo.java
+++ b/src/com/android/launcher3/ShortcutInfo.java
@@ -64,12 +64,6 @@
     long firstInstallTime;
     int flags = 0;
 
-    /**
-     * If this shortcut is a placeholder, then intent will be a market intent for the package, and
-     * this will hold the original intent from the database.  Otherwise, null.
-     */
-    Intent restoredIntent;
-
     ShortcutInfo() {
         itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
     }
@@ -78,21 +72,6 @@
         return intent;
     }
 
-    protected Intent getRestoredIntent() {
-        return restoredIntent;
-    }
-
-    /**
-     * Overwrite placeholder data with restored data, or do nothing if this is not a placeholder.
-     */
-    public void restore() {
-        if (restoredIntent != null) {
-            intent = restoredIntent;
-            restoredIntent = null;
-        }
-    }
-
-
     ShortcutInfo(Intent intent, CharSequence title, Bitmap icon) {
         this();
         this.intent = intent;
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 50d29ed..751b4c6 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -2709,13 +2709,12 @@
                     mTargetCell);
             float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0],
                     mDragViewVisualCenter[1], mTargetCell);
-            if (mCreateUserFolderOnDrop && willCreateUserFolder((ItemInfo) d.dragInfo,
-                    dropTargetLayout, mTargetCell, distance, true)) {
+            if (willCreateUserFolder((ItemInfo) d.dragInfo, dropTargetLayout,
+                    mTargetCell, distance, true)) {
                 return true;
             }
-
-            if (mAddToExistingFolderOnDrop && willAddToExistingUserFolder((ItemInfo) d.dragInfo,
-                    dropTargetLayout, mTargetCell, distance)) {
+            if (willAddToExistingUserFolder((ItemInfo) d.dragInfo, dropTargetLayout,
+                    mTargetCell, distance)) {
                 return true;
             }
 
@@ -4613,15 +4612,11 @@
     private void updateShortcut(HashMap<ComponentName, AppInfo> appsMap, ItemInfo info,
                                 View child) {
         ComponentName cn = info.getIntent().getComponent();
-        if (info.getRestoredIntent() != null) {
-            cn = info.getRestoredIntent().getComponent();
-        }
         if (cn != null) {
-            AppInfo appInfo = appsMap.get(cn);
+            AppInfo appInfo = appsMap.get(info.getIntent().getComponent());
             if ((appInfo != null) && LauncherModel.isShortcutInfoUpdateable(info)) {
                 ShortcutInfo shortcutInfo = (ShortcutInfo) info;
                 BubbleTextView shortcut = (BubbleTextView) child;
-                shortcutInfo.restore();
                 shortcutInfo.updateIcon(mIconCache);
                 shortcutInfo.title = appInfo.title.toString();
                 shortcut.applyFromShortcutInfo(shortcutInfo, mIconCache);