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
This commit is contained in:
Alex Chau
2021-10-25 21:03:37 +01:00
parent 85da1db1aa
commit 53c7ed5084

View File

@@ -70,6 +70,8 @@ public class FloatingIconView extends FrameLayout implements
// 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 @@ public class FloatingIconView extends FrameLayout implements
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 @@ public class FloatingIconView extends FrameLayout implements
mOnTargetChangeRunnable = null;
mBadge = null;
sTmpObjArray[0] = null;
sRecycledFetchIconId = sFetchIconId;
mIconLoadResult = null;
mClipIconView.recycle();
mBtvDrawable.setBackground(null);