Snap for 6640159 from 5a695b5b5ac3aa622f9b4b688f7048fe8f63e401 to mainline-release

Change-Id: Ifd61d072c51a93e48b6c1c4669f8b4cc4069e84e
diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionUiStateManager.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionUiStateManager.java
index 5e54cd2..a0f6b04 100644
--- a/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionUiStateManager.java
+++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionUiStateManager.java
@@ -52,7 +52,6 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import java.util.Optional;
 import java.util.OptionalInt;
 import java.util.stream.IntStream;
 
@@ -315,16 +314,22 @@
      * {@link LauncherSettings.Favorites#ITEM_TYPE_DEEP_SHORTCUT}
      */
     public OptionalInt getAllAppsRank(@Nullable ItemInfo itemInfo) {
-        Optional<ComponentKey> componentKey = Optional.ofNullable(itemInfo)
-                .filter(item -> item.itemType == ITEM_TYPE_APPLICATION
-                        || item.itemType == ITEM_TYPE_SHORTCUT
-                        || item.itemType == ITEM_TYPE_DEEP_SHORTCUT)
-                .map(ItemInfo::getTargetComponent)
-                .map(componentName -> new ComponentKey(componentName, itemInfo.user));
+        if (itemInfo == null || itemInfo.getTargetComponent() == null || itemInfo.user == null) {
+            return OptionalInt.empty();
+        }
 
-        return componentKey.map(key -> IntStream.range(0, getCurrentState().apps.size())
-                .filter(index -> key.equals(getCurrentState().apps.get(index).getComponentKey()))
-                .findFirst()).orElseGet(OptionalInt::empty);
+        if (itemInfo.itemType == ITEM_TYPE_APPLICATION
+                || itemInfo.itemType == ITEM_TYPE_SHORTCUT
+                || itemInfo.itemType == ITEM_TYPE_DEEP_SHORTCUT) {
+            ComponentKey key = new ComponentKey(itemInfo.getTargetComponent(),
+                    itemInfo.user);
+            final List<ComponentKeyMapper> apps = getCurrentState().apps;
+            return IntStream.range(0, apps.size())
+                    .filter(index -> key.equals(apps.get(index).getComponentKey()))
+                    .findFirst();
+        }
+
+        return OptionalInt.empty();
     }
 
     /**
diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java
index 1dbb9e2..987cd0f 100644
--- a/quickstep/recents_ui_overrides/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java
+++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java
@@ -655,11 +655,15 @@
                             + ",launchLocation:" + itemInfo.container);
         }
 
-        final ComponentKey k = new ComponentKey(itemInfo.getTargetComponent(), itemInfo.user);
+        if (itemInfo.getTargetComponent() == null || itemInfo.user == null) {
+            return;
+        }
+
+        final ComponentKey key = new ComponentKey(itemInfo.getTargetComponent(), itemInfo.user);
 
         final List<ComponentKeyMapper> predictedApps = new ArrayList<>(mComponentKeyMappers);
         OptionalInt rank = IntStream.range(0, predictedApps.size())
-                .filter((i) -> k.equals(predictedApps.get(i).getComponentKey()))
+                .filter(index -> key.equals(predictedApps.get(index).getComponentKey()))
                 .findFirst();
         if (!rank.isPresent()) {
             return;
diff --git a/quickstep/src/com/android/quickstep/TaskThumbnailCache.java b/quickstep/src/com/android/quickstep/TaskThumbnailCache.java
index ace6743..2b7a8ec 100644
--- a/quickstep/src/com/android/quickstep/TaskThumbnailCache.java
+++ b/quickstep/src/com/android/quickstep/TaskThumbnailCache.java
@@ -166,11 +166,13 @@
             public void run() {
                 ThumbnailData thumbnail = ActivityManagerWrapper.getInstance().getTaskThumbnail(
                         key.id, lowResolution);
-                if (isCanceled()) {
-                    // We don't call back to the provided callback in this case
-                    return;
-                }
+
                 MAIN_EXECUTOR.execute(() -> {
+                    if (isCanceled()) {
+                        // We don't call back to the provided callback in this case
+                        return;
+                    }
+
                     mCache.put(key, thumbnail);
                     callback.accept(thumbnail);
                     onEnd();