diff --git a/quickstep/src/com/android/launcher3/model/PredictionUpdateTask.java b/quickstep/src/com/android/launcher3/model/PredictionUpdateTask.java index d604742979..cd08897320 100644 --- a/quickstep/src/com/android/launcher3/model/PredictionUpdateTask.java +++ b/quickstep/src/com/android/launcher3/model/PredictionUpdateTask.java @@ -18,6 +18,7 @@ package com.android.launcher3.model; import static com.android.launcher3.EncryptionType.ENCRYPTED; import static com.android.launcher3.LauncherPrefs.nonRestorableItem; import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT; +import static com.android.launcher3.icons.cache.CacheLookupFlag.DEFAULT_LOOKUP_FLAG; import static com.android.quickstep.InstantAppResolverImpl.COMPONENT_CLASS_MARKER; import android.app.prediction.AppTarget; @@ -95,7 +96,7 @@ public class PredictionUpdateTask implements ModelUpdateTask { itemInfo = apps.data.stream() .filter(info -> user.equals(info.user) && cn.equals(info.componentName)) .map(ai -> { - app.getIconCache().getTitleAndIcon(ai, false); + app.getIconCache().getTitleAndIcon(ai, DEFAULT_LOOKUP_FLAG); return ai.makeWorkspaceItem(context); }) .findAny() @@ -106,7 +107,7 @@ public class PredictionUpdateTask implements ModelUpdateTask { return null; } AppInfo ai = new AppInfo(context, lai, user); - app.getIconCache().getTitleAndIcon(ai, lai, false); + app.getIconCache().getTitleAndIcon(ai, lai, DEFAULT_LOOKUP_FLAG); return ai.makeWorkspaceItem(context); }); diff --git a/quickstep/src/com/android/launcher3/model/QuickstepModelDelegate.java b/quickstep/src/com/android/launcher3/model/QuickstepModelDelegate.java index 2f4c6f614c..daba0dd68e 100644 --- a/quickstep/src/com/android/launcher3/model/QuickstepModelDelegate.java +++ b/quickstep/src/com/android/launcher3/model/QuickstepModelDelegate.java @@ -26,6 +26,7 @@ import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT; import static com.android.launcher3.hybridhotseat.HotseatPredictionModel.convertDataModelToAppTargetBundle; +import static com.android.launcher3.icons.cache.CacheLookupFlag.DEFAULT_LOOKUP_FLAG; import static com.android.launcher3.model.PredictionHelper.getAppTargetFromItemInfo; import static com.android.launcher3.model.PredictionHelper.wrapAppTargetWithItemLocation; import static com.android.launcher3.util.Executors.MODEL_EXECUTOR; @@ -572,7 +573,7 @@ public class QuickstepModelDelegate extends ModelDelegate { mPmHelper, mUMS.isUserQuiet(user)); info.container = mContainer; - mAppState.getIconCache().getTitleAndIcon(info, lai, false); + mAppState.getIconCache().getTitleAndIcon(info, lai, DEFAULT_LOOKUP_FLAG); mReadCount++; return info.makeWorkspaceItem(mAppState.getContext()); } diff --git a/quickstep/src/com/android/quickstep/util/AppPairsController.java b/quickstep/src/com/android/quickstep/util/AppPairsController.java index 3a0324c951..839979205a 100644 --- a/quickstep/src/com/android/quickstep/util/AppPairsController.java +++ b/quickstep/src/com/android/quickstep/util/AppPairsController.java @@ -215,7 +215,7 @@ public class AppPairsController { newAppPair.getAppContents().forEach(member -> { member.title = ""; member.bitmap = iconCache.getDefaultIcon(newAppPair.user); - iconCache.getTitleAndIcon(member, member.usingLowResIcon()); + iconCache.getTitleAndIcon(member, member.getMatchingLookupFlag()); }); MAIN_EXECUTOR.execute(() -> { LauncherAccessibilityDelegate delegate = diff --git a/quickstep/src/com/android/quickstep/util/SplitToWorkspaceController.java b/quickstep/src/com/android/quickstep/util/SplitToWorkspaceController.java index bdfaa486d1..86090d5c0a 100644 --- a/quickstep/src/com/android/quickstep/util/SplitToWorkspaceController.java +++ b/quickstep/src/com/android/quickstep/util/SplitToWorkspaceController.java @@ -16,6 +16,7 @@ package com.android.quickstep.util; +import static com.android.launcher3.icons.cache.CacheLookupFlag.DEFAULT_LOOKUP_FLAG; import static com.android.launcher3.util.Executors.MODEL_EXECUTOR; import android.animation.Animator; @@ -89,7 +90,7 @@ public class SplitToWorkspaceController { MODEL_EXECUTOR.execute(() -> { PackageItemInfo infoInOut = new PackageItemInfo(pendingIntent.getCreatorPackage(), pendingIntent.getCreatorUserHandle()); - mIconCache.getTitleAndIconForApp(infoInOut, false); + mIconCache.getTitleAndIconForApp(infoInOut, DEFAULT_LOOKUP_FLAG); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); view.post(() -> { diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index 247ee4804d..1fc14ec0c3 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -1351,12 +1351,10 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, mIconLoadRequest.cancel(); mIconLoadRequest = null; } - if (getTag() instanceof ItemInfoWithIcon && !mHighResUpdateInProgress) { - ItemInfoWithIcon info = (ItemInfoWithIcon) getTag(); - if (info.usingLowResIcon()) { - mIconLoadRequest = LauncherAppState.getInstance(getContext()).getIconCache() - .updateIconInBackground(BubbleTextView.this, info); - } + if (getTag() instanceof ItemInfoWithIcon info && !mHighResUpdateInProgress + && info.getMatchingLookupFlag().useLowRes()) { + mIconLoadRequest = LauncherAppState.getInstance(getContext()).getIconCache() + .updateIconInBackground(BubbleTextView.this, info); } } diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index ebcb5da814..9060691d9e 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -631,7 +631,7 @@ public final class Utilities { Drawable mainIcon = null; Drawable badge = null; - if ((info instanceof ItemInfoWithIcon iiwi) && !iiwi.usingLowResIcon()) { + if ((info instanceof ItemInfoWithIcon iiwi) && !iiwi.getMatchingLookupFlag().useLowRes()) { badge = iiwi.bitmap.getBadgeDrawable(context, useTheme); } diff --git a/src/com/android/launcher3/icons/IconCache.java b/src/com/android/launcher3/icons/IconCache.java index e7c4024a18..ab4105c2ee 100644 --- a/src/com/android/launcher3/icons/IconCache.java +++ b/src/com/android/launcher3/icons/IconCache.java @@ -17,6 +17,7 @@ package com.android.launcher3.icons; import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT; +import static com.android.launcher3.icons.cache.CacheLookupFlag.DEFAULT_LOOKUP_FLAG; import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import static com.android.launcher3.util.Executors.MODEL_EXECUTOR; import static com.android.launcher3.widget.WidgetSections.NO_CATEGORY; @@ -51,6 +52,7 @@ import com.android.launcher3.Flags; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.Utilities; import com.android.launcher3.icons.cache.BaseIconCache; +import com.android.launcher3.icons.cache.CacheLookupFlag; import com.android.launcher3.icons.cache.CachedObject; import com.android.launcher3.icons.cache.CachedObjectCachingLogic; import com.android.launcher3.icons.cache.LauncherActivityCachingLogic; @@ -163,12 +165,12 @@ public class IconCache extends BaseIconCache { Supplier task; if (info instanceof AppInfo || info instanceof WorkspaceItemInfo) { task = () -> { - getTitleAndIcon(info, false); + getTitleAndIcon(info, DEFAULT_LOOKUP_FLAG); return info; }; } else if (info instanceof PackageItemInfo pii) { task = () -> { - getTitleAndIconForApp(pii, false); + getTitleAndIconForApp(pii, DEFAULT_LOOKUP_FLAG); return pii; }; } else { @@ -207,7 +209,7 @@ public class IconCache extends BaseIconCache { public synchronized void updateTitleAndIcon(AppInfo application) { CacheEntry entry = cacheLocked(application.componentName, application.user, () -> null, LauncherActivityCachingLogic.INSTANCE, - application.usingLowResIcon() ? LookupFlag.USE_LOW_RES : LookupFlag.DEFAULT); + application.getMatchingLookupFlag()); if (entry.bitmap != null || !isDefaultIcon(entry.bitmap, application.user)) { applyCacheEntry(entry, application); } @@ -218,11 +220,11 @@ public class IconCache extends BaseIconCache { */ @SuppressWarnings("NewApi") public synchronized void getTitleAndIcon(ItemInfoWithIcon info, - LauncherActivityInfo activityInfo, boolean useLowResIcon) { + LauncherActivityInfo activityInfo, @NonNull CacheLookupFlag lookupFlag) { boolean isAppArchived = Flags.enableSupportForArchiving() && activityInfo != null && activityInfo.getActivityInfo().isArchived; // If we already have activity info, no need to use package icon - getTitleAndIcon(info, () -> activityInfo, isAppArchived, useLowResIcon); + getTitleAndIcon(info, () -> activityInfo, lookupFlag.withUsePackageIcon(isAppArchived)); } /** @@ -252,7 +254,7 @@ public class IconCache extends BaseIconCache { user, () -> si, CacheableShortcutCachingLogic.INSTANCE, - LookupFlag.SKIP_ADD_TO_MEM_CACHE).bitmap; + DEFAULT_LOOKUP_FLAG.withSkipAddToMemCache()).bitmap; if (bitmapInfo.isNullOrLowRes()) { bitmapInfo = getDefaultIcon(user); } @@ -291,12 +293,12 @@ public class IconCache extends BaseIconCache { appInfo.intent = new Intent(Intent.ACTION_MAIN) .addCategory(Intent.CATEGORY_LAUNCHER) .setComponent(cn); - getTitleAndIcon(appInfo, false); + getTitleAndIcon(appInfo, DEFAULT_LOOKUP_FLAG); return appInfo; } } PackageItemInfo pkgInfo = new PackageItemInfo(pkg, shortcutInfo.getUserHandle()); - getTitleAndIconForApp(pkgInfo, false); + getTitleAndIconForApp(pkgInfo, DEFAULT_LOOKUP_FLAG); return pkgInfo; } @@ -304,7 +306,9 @@ public class IconCache extends BaseIconCache { * Fill in {@param info} with the icon and label. If the * corresponding activity is not found, it reverts to the package icon. */ - public synchronized void getTitleAndIcon(ItemInfoWithIcon info, boolean useLowResIcon) { + public synchronized void getTitleAndIcon( + @NonNull ItemInfoWithIcon info, + @NonNull CacheLookupFlag lookupFlag) { // null info means not installed, but if we have a component from the intent then // we should still look in the cache for restored app icons. if (info.getTargetComponent() == null) { @@ -314,7 +318,7 @@ public class IconCache extends BaseIconCache { } else { Intent intent = info.getIntent(); getTitleAndIcon(info, () -> mLauncherApps.resolveActivity(intent, info.user), - true, useLowResIcon); + lookupFlag.withUsePackageIcon()); } } @@ -324,7 +328,7 @@ public class IconCache extends BaseIconCache { public synchronized String getTitleNoCache(CachedObject info) { CacheEntry entry = cacheLocked(info.getComponent(), info.getUser(), () -> info, CachedObjectCachingLogic.INSTANCE, - LookupFlag.USE_LOW_RES | LookupFlag.SKIP_ADD_TO_MEM_CACHE); + DEFAULT_LOOKUP_FLAG.withUseLowRes().withSkipAddToMemCache()); return Utilities.trim(entry.title); } @@ -334,12 +338,9 @@ public class IconCache extends BaseIconCache { public synchronized void getTitleAndIcon( @NonNull ItemInfoWithIcon infoInOut, @NonNull Supplier activityInfoProvider, - boolean usePkgIcon, boolean useLowResIcon) { - int lookupFlags = LookupFlag.DEFAULT; - if (usePkgIcon) lookupFlags |= LookupFlag.USE_PACKAGE_ICON; - if (useLowResIcon) lookupFlags |= LookupFlag.USE_LOW_RES; + @NonNull CacheLookupFlag lookupFlag) { CacheEntry entry = cacheLocked(infoInOut.getTargetComponent(), infoInOut.user, - activityInfoProvider, LauncherActivityCachingLogic.INSTANCE, lookupFlags); + activityInfoProvider, LauncherActivityCachingLogic.INSTANCE, lookupFlag); applyCacheEntry(entry, infoInOut); } @@ -441,7 +442,7 @@ public class IconCache extends BaseIconCache { /* user = */ sectionKey.first, () -> duplicateIconRequests.get(0).launcherActivityInfo, LauncherActivityCachingLogic.INSTANCE, - sectionKey.second ? LookupFlag.USE_LOW_RES : LookupFlag.DEFAULT, + DEFAULT_LOOKUP_FLAG.withUseLowRes(sectionKey.second), c); for (IconRequestInfo iconRequest : duplicateIconRequests) { @@ -515,9 +516,10 @@ public class IconCache extends BaseIconCache { * Fill in {@param infoInOut} with the corresponding icon and label. */ public synchronized void getTitleAndIconForApp( - @NonNull final PackageItemInfo infoInOut, final boolean useLowResIcon) { + @NonNull final PackageItemInfo infoInOut, + @NonNull CacheLookupFlag lookupFlag) { CacheEntry entry = getEntryForPackageLocked( - infoInOut.packageName, infoInOut.user, useLowResIcon); + infoInOut.packageName, infoInOut.user, lookupFlag.useLowRes()); applyCacheEntry(entry, infoInOut); if (infoInOut.widgetCategory == NO_CATEGORY) { return; diff --git a/src/com/android/launcher3/model/AddWorkspaceItemsTask.java b/src/com/android/launcher3/model/AddWorkspaceItemsTask.java index 55bcb7036a..b936adf22c 100644 --- a/src/com/android/launcher3/model/AddWorkspaceItemsTask.java +++ b/src/com/android/launcher3/model/AddWorkspaceItemsTask.java @@ -194,8 +194,7 @@ public class AddWorkspaceItemsTask implements ModelUpdateTask { WorkspaceItemInfo wii = (WorkspaceItemInfo) itemInfo; wii.title = ""; wii.bitmap = cache.getDefaultIcon(item.user); - cache.getTitleAndIcon(wii, - ((WorkspaceItemInfo) itemInfo).usingLowResIcon()); + cache.getTitleAndIcon(wii, wii.getMatchingLookupFlag()); } } diff --git a/src/com/android/launcher3/model/AllAppsList.java b/src/com/android/launcher3/model/AllAppsList.java index 7bc92733de..98f9afdaaa 100644 --- a/src/com/android/launcher3/model/AllAppsList.java +++ b/src/com/android/launcher3/model/AllAppsList.java @@ -16,6 +16,7 @@ package com.android.launcher3.model; +import static com.android.launcher3.icons.cache.CacheLookupFlag.DEFAULT_LOOKUP_FLAG; import static com.android.launcher3.model.data.AppInfo.COMPONENT_KEY_COMPARATOR; import static com.android.launcher3.model.data.AppInfo.EMPTY_ARRAY; @@ -151,7 +152,7 @@ public class AllAppsList { return; } if (loadIcon) { - mIconCache.getTitleAndIcon(info, activityInfo, false /* useLowResIcon */); + mIconCache.getTitleAndIcon(info, activityInfo, DEFAULT_LOOKUP_FLAG); info.sectionName = mIndex.computeSectionName(info.title); } else { info.title = ""; @@ -177,7 +178,7 @@ public class AllAppsList { AppInfo promiseAppInfo = new AppInfo(installInfo); if (loadIcon) { - mIconCache.getTitleAndIcon(promiseAppInfo, promiseAppInfo.usingLowResIcon()); + mIconCache.getTitleAndIcon(promiseAppInfo, promiseAppInfo.getMatchingLookupFlag()); promiseAppInfo.sectionName = mIndex.computeSectionName(promiseAppInfo.title); } else { promiseAppInfo.title = ""; @@ -338,7 +339,7 @@ public class AllAppsList { } else { Intent launchIntent = AppInfo.makeLaunchIntent(info); - mIconCache.getTitleAndIcon(applicationInfo, info, false /* useLowResIcon */); + mIconCache.getTitleAndIcon(applicationInfo, info, DEFAULT_LOOKUP_FLAG); applicationInfo.sectionName = mIndex.computeSectionName(applicationInfo.title); applicationInfo.intent = launchIntent; AppInfo.updateRuntimeFlagsForActivityTarget(applicationInfo, info, diff --git a/src/com/android/launcher3/model/CacheDataUpdatedTask.java b/src/com/android/launcher3/model/CacheDataUpdatedTask.java index 66b4fd9560..b544b91382 100644 --- a/src/com/android/launcher3/model/CacheDataUpdatedTask.java +++ b/src/com/android/launcher3/model/CacheDataUpdatedTask.java @@ -63,7 +63,7 @@ public class CacheDataUpdatedTask implements ModelUpdateTask { if (si.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION && isValidShortcut(si) && cn != null && mPackages.contains(cn.getPackageName())) { - iconCache.getTitleAndIcon(si, si.usingLowResIcon()); + iconCache.getTitleAndIcon(si, si.getMatchingLookupFlag()); updatedShortcuts.add(si); } }); diff --git a/src/com/android/launcher3/model/ItemInstallQueue.java b/src/com/android/launcher3/model/ItemInstallQueue.java index f9c6e9632b..c4f222fc38 100644 --- a/src/com/android/launcher3/model/ItemInstallQueue.java +++ b/src/com/android/launcher3/model/ItemInstallQueue.java @@ -21,6 +21,7 @@ import static android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_ID; import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET; import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT; +import static com.android.launcher3.icons.cache.CacheLookupFlag.DEFAULT_LOOKUP_FLAG; import static com.android.launcher3.model.data.AppInfo.makeLaunchIntent; import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_ARCHIVED; import static com.android.launcher3.util.Executors.MODEL_EXECUTOR; @@ -308,7 +309,8 @@ public class ItemInstallQueue { } } LauncherAppState.getInstance(context).getIconCache() - .getTitleAndIcon(si, () -> lai, usePackageIcon, false); + .getTitleAndIcon(si, () -> lai, + DEFAULT_LOOKUP_FLAG.withUsePackageIcon(usePackageIcon)); return Pair.create(si, null); } case ITEM_TYPE_DEEP_SHORTCUT: { diff --git a/src/com/android/launcher3/model/LoaderCursor.java b/src/com/android/launcher3/model/LoaderCursor.java index c01b1b6926..536d4c9cd3 100644 --- a/src/com/android/launcher3/model/LoaderCursor.java +++ b/src/com/android/launcher3/model/LoaderCursor.java @@ -18,6 +18,7 @@ package com.android.launcher3.model; import static com.android.launcher3.LauncherSettings.Favorites.TABLE_NAME; import static com.android.launcher3.Utilities.SHOULD_SHOW_FIRST_PAGE_WIDGET; +import static com.android.launcher3.icons.cache.CacheLookupFlag.DEFAULT_LOOKUP_FLAG; import android.content.ComponentName; import android.content.ContentValues; @@ -300,7 +301,7 @@ public class LoaderCursor extends CursorWrapper { // the fallback icon if (!loadIcon(info)) { - mIconCache.getTitleAndIcon(info, false /* useLowResIcon */); + mIconCache.getTitleAndIcon(info, DEFAULT_LOOKUP_FLAG); } if (hasRestoreFlag(WorkspaceItemInfo.FLAG_RESTORED_ICON)) { @@ -364,7 +365,8 @@ public class LoaderCursor extends CursorWrapper { UserIconInfo userIconInfo = userCache.getUserInfo(user); if (loadIcon) { - mIconCache.getTitleAndIcon(info, mActivityInfo, useLowResIcon); + mIconCache.getTitleAndIcon(info, mActivityInfo, + DEFAULT_LOOKUP_FLAG.withUseLowRes(useLowResIcon)); if (mIconCache.isDefaultIcon(info.bitmap, user)) { loadIcon(info); } diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java index f96e9591e6..e6b9d42e43 100644 --- a/src/com/android/launcher3/model/LoaderTask.java +++ b/src/com/android/launcher3/model/LoaderTask.java @@ -25,6 +25,7 @@ import static com.android.launcher3.LauncherPrefs.IS_FIRST_LOAD_AFTER_RESTORE; import static com.android.launcher3.LauncherPrefs.SHOULD_SHOW_SMARTSPACE; import static com.android.launcher3.LauncherSettings.Favorites.TABLE_NAME; import static com.android.launcher3.icons.CacheableShortcutInfo.convertShortcutsToCacheableShortcuts; +import static com.android.launcher3.icons.cache.CacheLookupFlag.DEFAULT_LOOKUP_FLAG; import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_HAS_SHORTCUT_PERMISSION; import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_PRIVATE_PROFILE_QUIET_MODE_ENABLED; import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_QUIET_MODE_CHANGE_PERMISSION; @@ -599,10 +600,10 @@ public class LoaderTask implements Runnable { info.rank = rank; if (info instanceof WorkspaceItemInfo wii - && wii.usingLowResIcon() + && wii.getMatchingLookupFlag().useLowRes() && wii.itemType == Favorites.ITEM_TYPE_APPLICATION && verifiers.stream().anyMatch(it -> it.isItemInPreview(info.rank))) { - mIconCache.getTitleAndIcon(wii, false); + mIconCache.getTitleAndIcon(wii, DEFAULT_LOOKUP_FLAG); } else if (info instanceof AppPairInfo api) { api.fetchHiResIconsIfNeeded(mIconCache); } @@ -765,7 +766,7 @@ public class LoaderTask implements Runnable { iconRequestInfos.add(new IconRequestInfo<>( promiseAppInfo, /* launcherActivityInfo= */ null, - promiseAppInfo.usingLowResIcon())); + promiseAppInfo.getMatchingLookupFlag().useLowRes())); } } } diff --git a/src/com/android/launcher3/model/PackageUpdatedTask.java b/src/com/android/launcher3/model/PackageUpdatedTask.java index 5464afed2e..d619965aa8 100644 --- a/src/com/android/launcher3/model/PackageUpdatedTask.java +++ b/src/com/android/launcher3/model/PackageUpdatedTask.java @@ -326,7 +326,8 @@ public class PackageUpdatedTask implements ModelUpdateTask { itemInfo.setNonResizeable(ApiWrapper.INSTANCE.get(context) .isNonResizeableActivity(activities.get(0))); } - iconCache.getTitleAndIcon(itemInfo, itemInfo.usingLowResIcon()); + iconCache.getTitleAndIcon( + itemInfo, itemInfo.getMatchingLookupFlag()); infoUpdated = true; } } diff --git a/src/com/android/launcher3/model/SessionFailureTask.kt b/src/com/android/launcher3/model/SessionFailureTask.kt index 0d006fa70c..8baf568ace 100644 --- a/src/com/android/launcher3/model/SessionFailureTask.kt +++ b/src/com/android/launcher3/model/SessionFailureTask.kt @@ -48,7 +48,7 @@ class SessionFailureTask(val packageName: String, val user: UserHandle) : ModelU for (info in dataModel.itemsIdMap) { if (info is WorkspaceItemInfo && info.isArchived && user == info.user) { // Refresh icons on the workspace for archived apps. - iconCache.getTitleAndIcon(info, info.usingLowResIcon()) + iconCache.getTitleAndIcon(info, info.matchingLookupFlag) updatedItems.add(info) } } diff --git a/src/com/android/launcher3/model/WidgetsModel.java b/src/com/android/launcher3/model/WidgetsModel.java index a27d2f183e..a17646556b 100644 --- a/src/com/android/launcher3/model/WidgetsModel.java +++ b/src/com/android/launcher3/model/WidgetsModel.java @@ -4,6 +4,7 @@ package com.android.launcher3.model; import static android.appwidget.AppWidgetProviderInfo.WIDGET_FEATURE_HIDE_FROM_PICKER; import static com.android.launcher3.BuildConfig.WIDGETS_ENABLED; +import static com.android.launcher3.icons.cache.CacheLookupFlag.DEFAULT_LOOKUP_FLAG; import static com.android.launcher3.pm.ShortcutConfigActivityInfo.queryList; import static com.android.launcher3.widget.WidgetSections.NO_CATEGORY; @@ -203,7 +204,7 @@ public class WidgetsModel { // Update each package entry IconCache iconCache = app.getIconCache(); for (PackageItemInfo p : packageItemInfoCache.values()) { - iconCache.getTitleAndIconForApp(p, true /* userLowResIcon */); + iconCache.getTitleAndIconForApp(p, DEFAULT_LOOKUP_FLAG.withUseLowRes()); } } diff --git a/src/com/android/launcher3/model/WorkspaceItemProcessor.kt b/src/com/android/launcher3/model/WorkspaceItemProcessor.kt index e86b5926a6..e23eba93df 100644 --- a/src/com/android/launcher3/model/WorkspaceItemProcessor.kt +++ b/src/com/android/launcher3/model/WorkspaceItemProcessor.kt @@ -33,6 +33,7 @@ import com.android.launcher3.LauncherSettings.Favorites import com.android.launcher3.backuprestore.LauncherRestoreEventLogger.RestoreError import com.android.launcher3.config.FeatureFlags import com.android.launcher3.icons.CacheableShortcutInfo +import com.android.launcher3.icons.cache.CacheLookupFlag.Companion.DEFAULT_LOOKUP_FLAG import com.android.launcher3.logging.FileLog import com.android.launcher3.model.data.AppInfo import com.android.launcher3.model.data.AppPairInfo @@ -521,7 +522,7 @@ class WorkspaceItemProcessor( appWidgetInfo.providerName, appWidgetInfo.user, ) - iconCache.getTitleAndIconForApp(appWidgetInfo.pendingItemInfo, false) + iconCache.getTitleAndIconForApp(appWidgetInfo.pendingItemInfo, DEFAULT_LOOKUP_FLAG) } WidgetInflater.TYPE_REAL -> WidgetSizes.updateWidgetSizeRangesAsync( diff --git a/src/com/android/launcher3/model/data/AppPairInfo.kt b/src/com/android/launcher3/model/data/AppPairInfo.kt index 82eda36ee6..073d0e0efe 100644 --- a/src/com/android/launcher3/model/data/AppPairInfo.kt +++ b/src/com/android/launcher3/model/data/AppPairInfo.kt @@ -20,6 +20,7 @@ import android.content.Context import com.android.launcher3.LauncherSettings import com.android.launcher3.R import com.android.launcher3.icons.IconCache +import com.android.launcher3.icons.cache.CacheLookupFlag.Companion.DEFAULT_LOOKUP_FLAG import com.android.launcher3.logger.LauncherAtom import com.android.launcher3.views.ActivityContext @@ -72,16 +73,17 @@ class AppPairInfo() : CollectionInfo() { val isTablet = (ActivityContext.lookupContext(context) as ActivityContext).getDeviceProfile().isTablet return Pair( - isTablet || !getFirstApp().isNonResizeable(), - isTablet || !getSecondApp().isNonResizeable(), + isTablet || !getFirstApp().isNonResizeable, + isTablet || !getSecondApp().isNonResizeable, ) } /** Fetches high-res icons for member apps if needed. */ fun fetchHiResIconsIfNeeded(iconCache: IconCache) { - getAppContents().stream().filter(ItemInfoWithIcon::usingLowResIcon).forEach { member -> - iconCache.getTitleAndIcon(member, false) - } + getAppContents() + .stream() + .filter { it.matchingLookupFlag.useLowRes() } + .forEach { member -> iconCache.getTitleAndIcon(member, DEFAULT_LOOKUP_FLAG) } } /** diff --git a/src/com/android/launcher3/model/data/ItemInfoWithIcon.java b/src/com/android/launcher3/model/data/ItemInfoWithIcon.java index 6ac44ffc93..772ea7fe88 100644 --- a/src/com/android/launcher3/model/data/ItemInfoWithIcon.java +++ b/src/com/android/launcher3/model/data/ItemInfoWithIcon.java @@ -23,10 +23,10 @@ import android.os.Process; import androidx.annotation.Nullable; import com.android.launcher3.Flags; -import com.android.launcher3.Utilities; import com.android.launcher3.icons.BitmapInfo; import com.android.launcher3.icons.BitmapInfo.DrawableCreationFlags; import com.android.launcher3.icons.FastBitmapDrawable; +import com.android.launcher3.icons.cache.CacheLookupFlag; import com.android.launcher3.logging.FileLog; import com.android.launcher3.pm.PackageInstallInfo; import com.android.launcher3.util.ApiWrapper; @@ -185,10 +185,10 @@ public abstract class ItemInfoWithIcon extends ItemInfo { } /** - * Indicates whether we're using a low res icon + * Returns the lookup flag to match this current state of this info */ - public boolean usingLowResIcon() { - return bitmap.isLowRes(); + public CacheLookupFlag getMatchingLookupFlag() { + return bitmap.getMatchingLookupFlag(); } /** diff --git a/src/com/android/launcher3/model/data/WorkspaceItemInfo.java b/src/com/android/launcher3/model/data/WorkspaceItemInfo.java index 9af61f0e77..0a5dd6242d 100644 --- a/src/com/android/launcher3/model/data/WorkspaceItemInfo.java +++ b/src/com/android/launcher3/model/data/WorkspaceItemInfo.java @@ -142,7 +142,7 @@ public class WorkspaceItemInfo extends ItemInfoWithIcon { .put(Favorites.OPTIONS, options) .put(Favorites.RESTORED, status); - if (!usingLowResIcon()) { + if (!getMatchingLookupFlag().useLowRes()) { writer.putIcon(bitmap, user); } } diff --git a/src/com/android/launcher3/widget/picker/WidgetsListHeader.java b/src/com/android/launcher3/widget/picker/WidgetsListHeader.java index d164dd08c0..2f123a3465 100644 --- a/src/com/android/launcher3/widget/picker/WidgetsListHeader.java +++ b/src/com/android/launcher3/widget/picker/WidgetsListHeader.java @@ -234,12 +234,9 @@ public final class WidgetsListHeader extends LinearLayout implements ItemInfoUpd mIconLoadRequest.cancel(); mIconLoadRequest = null; } - if (getTag() instanceof ItemInfoWithIcon) { - ItemInfoWithIcon info = (ItemInfoWithIcon) getTag(); - if (info.usingLowResIcon()) { - mIconLoadRequest = LauncherAppState.getInstance(getContext()).getIconCache() - .updateIconInBackground(this, info); - } + if (getTag() instanceof ItemInfoWithIcon info && info.getMatchingLookupFlag().useLowRes()) { + mIconLoadRequest = LauncherAppState.getInstance(getContext()).getIconCache() + .updateIconInBackground(this, info); } } } diff --git a/src/com/android/launcher3/widget/picker/WidgetsTwoPaneSheet.java b/src/com/android/launcher3/widget/picker/WidgetsTwoPaneSheet.java index f9bd5f1d24..df76400717 100644 --- a/src/com/android/launcher3/widget/picker/WidgetsTwoPaneSheet.java +++ b/src/com/android/launcher3/widget/picker/WidgetsTwoPaneSheet.java @@ -22,6 +22,7 @@ import static com.android.launcher3.UtilitiesKt.CLIP_CHILDREN_FALSE_MODIFIER; import static com.android.launcher3.UtilitiesKt.CLIP_TO_PADDING_FALSE_MODIFIER; import static com.android.launcher3.UtilitiesKt.modifyAttributesOnViewTree; import static com.android.launcher3.UtilitiesKt.restoreAttributesOnViewTree; +import static com.android.launcher3.icons.cache.CacheLookupFlag.DEFAULT_LOOKUP_FLAG; import static com.android.launcher3.widget.picker.WidgetsListItemAnimator.WIDGET_LIST_ITEM_APPEARANCE_DELAY; import static com.android.launcher3.widget.picker.model.data.WidgetPickerDataUtils.findContentEntryForPackageUser; @@ -51,6 +52,7 @@ import androidx.annotation.Px; import com.android.launcher3.DeviceProfile; import com.android.launcher3.R; import com.android.launcher3.Utilities; +import com.android.launcher3.icons.cache.CacheLookupFlag; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.model.data.PackageItemInfo; import com.android.launcher3.recyclerview.ViewHolderBinder; @@ -691,8 +693,8 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet { } @Override - public boolean usingLowResIcon() { - return false; + public CacheLookupFlag getMatchingLookupFlag() { + return DEFAULT_LOOKUP_FLAG; } } } diff --git a/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheTest.java b/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheTest.java index 9b4bd71608..9026748f60 100644 --- a/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheTest.java +++ b/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheTest.java @@ -21,6 +21,7 @@ import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentat import static com.android.launcher3.icons.IconCache.EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE; import static com.android.launcher3.icons.IconCacheUpdateHandlerTestKt.waitForUpdateHandlerToFinish; +import static com.android.launcher3.icons.cache.CacheLookupFlag.DEFAULT_LOOKUP_FLAG; import static com.android.launcher3.model.data.AppInfo.makeLaunchIntent; import static com.android.launcher3.util.Executors.MODEL_EXECUTOR; import static com.android.launcher3.util.LauncherModelHelper.TEST_ACTIVITY; @@ -164,7 +165,7 @@ public class IconCacheTest { WorkspaceItemInfo info = new WorkspaceItemInfo(); info.intent = makeLaunchIntent(cn); runOnExecutorSync(MODEL_EXECUTOR, - () -> mIconCache.getTitleAndIcon(info, lai, false)); + () -> mIconCache.getTitleAndIcon(info, lai, DEFAULT_LOOKUP_FLAG)); assertNotNull(info.bitmap); assertFalse(info.bitmap.isLowRes()); diff --git a/tests/multivalentTests/src/com/android/launcher3/icons/cache/CacheLookupFlagTest.kt b/tests/multivalentTests/src/com/android/launcher3/icons/cache/CacheLookupFlagTest.kt new file mode 100644 index 0000000000..7b1851d3ee --- /dev/null +++ b/tests/multivalentTests/src/com/android/launcher3/icons/cache/CacheLookupFlagTest.kt @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.icons.cache + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.SmallTest +import com.android.launcher3.icons.cache.CacheLookupFlag.Companion.DEFAULT_LOOKUP_FLAG +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test +import org.junit.runner.RunWith + +@SmallTest +@RunWith(AndroidJUnit4::class) +class CacheLookupFlagTest { + + @Test + fun `useLowRes preserves lowRes values`() { + assertFalse(DEFAULT_LOOKUP_FLAG.useLowRes()) + assertTrue(DEFAULT_LOOKUP_FLAG.withUseLowRes().useLowRes()) + assertFalse(DEFAULT_LOOKUP_FLAG.withUseLowRes().withUseLowRes(false).useLowRes()) + assertTrue( + DEFAULT_LOOKUP_FLAG.withUseLowRes().withUseLowRes(false).withUseLowRes().useLowRes() + ) + } + + @Test + fun `usePackageIcon preserves lowRes values`() { + assertFalse(DEFAULT_LOOKUP_FLAG.usePackageIcon()) + assertTrue(DEFAULT_LOOKUP_FLAG.withUsePackageIcon().usePackageIcon()) + assertFalse( + DEFAULT_LOOKUP_FLAG.withUsePackageIcon().withUsePackageIcon(false).usePackageIcon() + ) + assertTrue( + DEFAULT_LOOKUP_FLAG.withUsePackageIcon() + .withUsePackageIcon(false) + .withUsePackageIcon() + .usePackageIcon() + ) + } + + @Test + fun `skipAddToMemCache preserves lowRes values`() { + assertFalse(DEFAULT_LOOKUP_FLAG.skipAddToMemCache()) + assertTrue(DEFAULT_LOOKUP_FLAG.withSkipAddToMemCache().skipAddToMemCache()) + assertFalse( + DEFAULT_LOOKUP_FLAG.withSkipAddToMemCache() + .withSkipAddToMemCache(false) + .skipAddToMemCache() + ) + assertTrue( + DEFAULT_LOOKUP_FLAG.withSkipAddToMemCache() + .withSkipAddToMemCache(false) + .withSkipAddToMemCache() + .skipAddToMemCache() + ) + } + + @Test + fun `preserves multiple flags`() { + val flag = DEFAULT_LOOKUP_FLAG.withSkipAddToMemCache().withUseLowRes() + + assertTrue(flag.skipAddToMemCache()) + assertTrue(flag.useLowRes()) + assertFalse(flag.usePackageIcon()) + } +}