Avoid calling getIconResult if recycle is called after request is queued
Fix: 203582251
Test: atest -c NexusLauncherTests:com.android.launcher3.memory.MemoryTests
Change-Id: Ice1e981e1813df516008be578aa89ee17fb79fab
diff --git a/src/com/android/launcher3/views/FloatingIconView.java b/src/com/android/launcher3/views/FloatingIconView.java
index 872adec..8b7ad46 100644
--- a/src/com/android/launcher3/views/FloatingIconView.java
+++ b/src/com/android/launcher3/views/FloatingIconView.java
@@ -70,6 +70,8 @@
// Manages loading the icon on a worker thread
private static @Nullable IconLoadResult sIconLoadResult;
+ private static long sFetchIconId = 0;
+ private static long sRecycledFetchIconId = sFetchIconId;
public static final float SHAPE_PROGRESS_DURATION = 0.10f;
private static final RectF sTmpRectF = new RectF();
@@ -519,8 +521,13 @@
IconLoadResult result = new IconLoadResult(info,
btvIcon == null ? false : btvIcon.isThemed());
- MODEL_EXECUTOR.getHandler().postAtFrontOfQueue(() ->
- getIconResult(l, v, info, position, btvIcon, result));
+ final long fetchIconId = sFetchIconId++;
+ MODEL_EXECUTOR.getHandler().postAtFrontOfQueue(() -> {
+ if (fetchIconId < sRecycledFetchIconId) {
+ return;
+ }
+ getIconResult(l, v, info, position, btvIcon, result);
+ });
sIconLoadResult = result;
return result;
@@ -622,6 +629,7 @@
mOnTargetChangeRunnable = null;
mBadge = null;
sTmpObjArray[0] = null;
+ sRecycledFetchIconId = sFetchIconId;
mIconLoadResult = null;
mClipIconView.recycle();
mBtvDrawable.setBackground(null);