From 19797b419b490cd56c048f37b7592b80dcf12f41 Mon Sep 17 00:00:00 2001 From: Zak Cohen Date: Sun, 28 Jun 2020 20:34:48 -0700 Subject: [PATCH 1/2] Thumbnail Cache - check canceled status on the right thread. The cache was checking the canceled status on the background thread, but the cancel call was being made on the main thread. This was leading to canceled requests still delivering this thumbnail in some cases. Bug: 159840851 Test: local build and non-repo of bug Change-Id: I9a3556f6570eee1db39ebec202c115d58010d7f8 --- .../src/com/android/quickstep/TaskThumbnailCache.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/quickstep/src/com/android/quickstep/TaskThumbnailCache.java b/quickstep/src/com/android/quickstep/TaskThumbnailCache.java index ace674383e..2b7a8ec250 100644 --- a/quickstep/src/com/android/quickstep/TaskThumbnailCache.java +++ b/quickstep/src/com/android/quickstep/TaskThumbnailCache.java @@ -166,11 +166,13 @@ public class TaskThumbnailCache { 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(); From 43bf883841790a63ada0145325800aa135da7de2 Mon Sep 17 00:00:00 2001 From: thiruram Date: Mon, 29 Jun 2020 10:47:14 -0700 Subject: [PATCH 2/2] Fixes NPE with system shortcuts. Bug: 160109140 Change-Id: I35c00fc1792fcf11fc61e1876f9184bd5fb309ce (cherry picked from commit 53925ff9c6558e330aed20a2e406d68474a41247) --- .../PredictionUiStateManager.java | 25 +++++++++++-------- .../HotseatPredictionController.java | 8 ++++-- 2 files changed, 21 insertions(+), 12 deletions(-) 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 5e54cd292f..a0f6b044ba 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 com.android.launcher3.util.MainThreadInitializedObject; 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 @@ public class PredictionUiStateManager implements StateListener, * {@link LauncherSettings.Favorites#ITEM_TYPE_DEEP_SHORTCUT} */ public OptionalInt getAllAppsRank(@Nullable ItemInfo itemInfo) { - Optional 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 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 1dbb9e2d6b..987cd0fcf6 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 @@ public class HotseatPredictionController implements DragController.DragListener, + ",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 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;