Fixing icon cache thrashing due to an unsupported icon
Bug: 284032965
Test: Verified by reproducing the use case
Flag: N/A
(cherry picked from commit 41737b3e8bbe4c72ed8570771b7d64fdbcfcebbb)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:23085999e062d3cd57ec522e6b206d3af9589623)
Merged-In: I835dd545a01eb2fd7990e0fd5ad51bac0e4b1f33
Change-Id: I835dd545a01eb2fd7990e0fd5ad51bac0e4b1f33
diff --git a/src/com/android/launcher3/icons/IconCache.java b/src/com/android/launcher3/icons/IconCache.java
index 3c63f26..72feb7b 100644
--- a/src/com/android/launcher3/icons/IconCache.java
+++ b/src/com/android/launcher3/icons/IconCache.java
@@ -100,6 +100,7 @@
private final UserCache mUserManager;
private final InstantAppResolver mInstantAppResolver;
private final IconProvider mIconProvider;
+ private final HandlerRunnable mCancelledRunnable;
private final SparseArray<BitmapInfo> mWidgetCategoryBitmapInfos;
@@ -121,6 +122,10 @@
mInstantAppResolver = InstantAppResolver.newInstance(mContext);
mIconProvider = iconProvider;
mWidgetCategoryBitmapInfos = new SparseArray<>();
+
+ mCancelledRunnable = new HandlerRunnable(
+ mWorkerHandler, () -> null, MAIN_EXECUTOR, c -> { });
+ mCancelledRunnable.cancel();
}
@Override
@@ -176,23 +181,30 @@
public HandlerRunnable updateIconInBackground(final ItemInfoUpdateReceiver caller,
final ItemInfoWithIcon info) {
Preconditions.assertUIThread();
+ Supplier<ItemInfoWithIcon> task;
+ if (info instanceof AppInfo || info instanceof WorkspaceItemInfo) {
+ task = () -> {
+ getTitleAndIcon(info, false);
+ return info;
+ };
+ } else if (info instanceof PackageItemInfo pii) {
+ task = () -> {
+ getTitleAndIconForApp(pii, false);
+ return pii;
+ };
+ } else {
+ Log.i(TAG, "Icon update not supported for "
+ + info == null ? "null" : info.getClass().getName());
+ return mCancelledRunnable;
+ }
+
if (mPendingIconRequestCount <= 0) {
MODEL_EXECUTOR.setThreadPriority(Process.THREAD_PRIORITY_FOREGROUND);
}
mPendingIconRequestCount++;
HandlerRunnable<ItemInfoWithIcon> request = new HandlerRunnable<>(mWorkerHandler,
- () -> {
- if (info instanceof AppInfo || info instanceof WorkspaceItemInfo) {
- getTitleAndIcon(info, false);
- } else if (info instanceof PackageItemInfo) {
- getTitleAndIconForApp((PackageItemInfo) info, false);
- }
- return info;
- },
- MAIN_EXECUTOR,
- caller::reapplyItemInfo,
- this::onIconRequestEnd);
+ task, MAIN_EXECUTOR, caller::reapplyItemInfo, this::onIconRequestEnd);
Utilities.postAsyncCallback(mWorkerHandler, request);
return request;
}