Merge "Fixing icon cache thrashing due to an unsupported icon" into udc-dev am: 6c8d57d8b5

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/23493432

Change-Id: I5dc3afca04227155e8f1d39e72534328dcdd27ea
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Sunny Goyal
2023-06-01 01:41:17 +00:00
committed by Automerger Merge Worker
+23 -11
View File
@@ -100,6 +100,7 @@ public class IconCache extends BaseIconCache {
private final UserCache mUserManager;
private final InstantAppResolver mInstantAppResolver;
private final IconProvider mIconProvider;
private final HandlerRunnable mCancelledRunnable;
private final SparseArray<BitmapInfo> mWidgetCategoryBitmapInfos;
@@ -117,6 +118,10 @@ public class IconCache extends BaseIconCache {
mInstantAppResolver = InstantAppResolver.newInstance(mContext);
mIconProvider = iconProvider;
mWidgetCategoryBitmapInfos = new SparseArray<>();
mCancelledRunnable = new HandlerRunnable(
mWorkerHandler, () -> null, MAIN_EXECUTOR, c -> { });
mCancelledRunnable.cancel();
}
@Override
@@ -172,23 +177,30 @@ public class IconCache extends BaseIconCache {
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;
}