Add status to DeepShortcutManager api calls.

This way we can handle SecurityExceptions differently. For instance,
if a SecurityException causes us to fail to get details for pinned
shortcuts, we keep the pinned shortcuts in the database so that they
will be loaded next time launcher has the correct permissions.

Change-Id: I1102fce612ade10ad7f577b44a99c8cf087d5ccd
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 39e28c0..a75edb7 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -71,10 +71,10 @@
 import com.android.launcher3.util.GridOccupancy;
 import com.android.launcher3.util.LongArrayMap;
 import com.android.launcher3.util.ManagedProfileHeuristic;
+import com.android.launcher3.util.MultiHashMap;
 import com.android.launcher3.util.PackageManagerHelper;
 import com.android.launcher3.util.Preconditions;
 import com.android.launcher3.util.StringFilter;
-import com.android.launcher3.util.MultiHashMap;
 import com.android.launcher3.util.Thunk;
 import com.android.launcher3.util.ViewOnDrawExecutor;
 
@@ -1942,7 +1942,16 @@
                                         List<ShortcutInfoCompat> fullDetails = mDeepShortcutManager
                                                 .queryForFullDetails(packageName,
                                                 Collections.singletonList(shortcutId), user);
-                                        if (fullDetails != null && !fullDetails.isEmpty()) {
+                                        if (fullDetails == null || fullDetails.isEmpty()) {
+                                            // There are no details for the shortcut. If this is due
+                                            // to a SecurityException, keep it in the database so
+                                            // we can restore the icon when the launcher regains
+                                            // permission. Otherwise remove the icon from the db.
+                                            if (!mDeepShortcutManager.wasLastCallSuccess()) {
+                                                itemsToRemove.add(id);
+                                                continue;
+                                            }
+                                        } else {
                                             pinnedShortcut = fullDetails.get(0);
                                             shouldPin = true;
                                         }