Exclude shortcuts in popup from IconCache.
We want to load from/save icons to icon cache for pinned shortcuts only to reduce memory footprint. Bug: 140242324 Change-Id: I25c7d59e29c6e27752b36c2c3c226849d4e177af
This commit is contained in:
@@ -273,7 +273,7 @@ public abstract class BaseIconCache {
|
|||||||
if (entry.icon == null) return;
|
if (entry.icon == null) return;
|
||||||
entry.title = cachingLogic.getLabel(object);
|
entry.title = cachingLogic.getLabel(object);
|
||||||
entry.contentDescription = mPackageManager.getUserBadgedLabel(entry.title, user);
|
entry.contentDescription = mPackageManager.getUserBadgedLabel(entry.title, user);
|
||||||
mCache.put(key, entry);
|
if (cachingLogic.addToMemCache()) mCache.put(key, entry);
|
||||||
|
|
||||||
ContentValues values = newContentValues(entry, entry.title.toString(),
|
ContentValues values = newContentValues(entry, entry.title.toString(),
|
||||||
componentName.getPackageName(), cachingLogic.getKeywords(object, mLocaleList));
|
componentName.getPackageName(), cachingLogic.getKeywords(object, mLocaleList));
|
||||||
@@ -312,20 +312,12 @@ public abstract class BaseIconCache {
|
|||||||
@NonNull ComponentName componentName, @NonNull UserHandle user,
|
@NonNull ComponentName componentName, @NonNull UserHandle user,
|
||||||
@NonNull Supplier<T> infoProvider, @NonNull CachingLogic<T> cachingLogic,
|
@NonNull Supplier<T> infoProvider, @NonNull CachingLogic<T> cachingLogic,
|
||||||
boolean usePackageIcon, boolean useLowResIcon) {
|
boolean usePackageIcon, boolean useLowResIcon) {
|
||||||
return cacheLocked(componentName, user, infoProvider, cachingLogic, usePackageIcon,
|
|
||||||
useLowResIcon, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected <T> CacheEntry cacheLocked(
|
|
||||||
@NonNull ComponentName componentName, @NonNull UserHandle user,
|
|
||||||
@NonNull Supplier<T> infoProvider, @NonNull CachingLogic<T> cachingLogic,
|
|
||||||
boolean usePackageIcon, boolean useLowResIcon, boolean addToMemCache) {
|
|
||||||
assertWorkerThread();
|
assertWorkerThread();
|
||||||
ComponentKey cacheKey = new ComponentKey(componentName, user);
|
ComponentKey cacheKey = new ComponentKey(componentName, user);
|
||||||
CacheEntry entry = mCache.get(cacheKey);
|
CacheEntry entry = mCache.get(cacheKey);
|
||||||
if (entry == null || (entry.isLowRes() && !useLowResIcon)) {
|
if (entry == null || (entry.isLowRes() && !useLowResIcon)) {
|
||||||
entry = new CacheEntry();
|
entry = new CacheEntry();
|
||||||
if (addToMemCache) {
|
if (cachingLogic.addToMemCache()) {
|
||||||
mCache.put(cacheKey, entry);
|
mCache.put(cacheKey, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,4 +49,11 @@ public interface CachingLogic<T> {
|
|||||||
default long getLastUpdatedTime(T object, PackageInfo info) {
|
default long getLastUpdatedTime(T object, PackageInfo info) {
|
||||||
return info.lastUpdateTime;
|
return info.lastUpdateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true the object should be added to mem cache; otherwise returns false.
|
||||||
|
*/
|
||||||
|
default boolean addToMemCache() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,9 +34,11 @@ public interface ComponentWithLabel {
|
|||||||
class ComponentCachingLogic implements CachingLogic<ComponentWithLabel> {
|
class ComponentCachingLogic implements CachingLogic<ComponentWithLabel> {
|
||||||
|
|
||||||
private final PackageManager mPackageManager;
|
private final PackageManager mPackageManager;
|
||||||
|
private final boolean mAddToMemCache;
|
||||||
|
|
||||||
public ComponentCachingLogic(Context context) {
|
public ComponentCachingLogic(Context context, boolean addToMemCache) {
|
||||||
mPackageManager = context.getPackageManager();
|
mPackageManager = context.getPackageManager();
|
||||||
|
mAddToMemCache = addToMemCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -60,5 +62,10 @@ public interface ComponentWithLabel {
|
|||||||
// Do not load icon.
|
// Do not load icon.
|
||||||
target.icon = BitmapInfo.LOW_RES_ICON;
|
target.icon = BitmapInfo.LOW_RES_ICON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addToMemCache() {
|
||||||
|
return mAddToMemCache;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class IconCache extends BaseIconCache {
|
|||||||
public IconCache(Context context, InvariantDeviceProfile inv) {
|
public IconCache(Context context, InvariantDeviceProfile inv) {
|
||||||
super(context, LauncherFiles.APP_ICONS_DB, MODEL_EXECUTOR.getLooper(),
|
super(context, LauncherFiles.APP_ICONS_DB, MODEL_EXECUTOR.getLooper(),
|
||||||
inv.fillResIconDpi, inv.iconBitmapSize, true /* inMemoryCache */);
|
inv.fillResIconDpi, inv.iconBitmapSize, true /* inMemoryCache */);
|
||||||
mComponentWithLabelCachingLogic = new ComponentCachingLogic(context);
|
mComponentWithLabelCachingLogic = new ComponentCachingLogic(context, false);
|
||||||
mLauncherActivityInfoCachingLogic = LauncherActivityCachingLogic.newInstance(context);
|
mLauncherActivityInfoCachingLogic = LauncherActivityCachingLogic.newInstance(context);
|
||||||
mShortcutCachingLogic = new ShortcutCachingLogic();
|
mShortcutCachingLogic = new ShortcutCachingLogic();
|
||||||
mLauncherApps = LauncherAppsCompat.getInstance(mContext);
|
mLauncherApps = LauncherAppsCompat.getInstance(mContext);
|
||||||
@@ -206,7 +206,7 @@ public class IconCache extends BaseIconCache {
|
|||||||
public synchronized String getTitleNoCache(ComponentWithLabel info) {
|
public synchronized String getTitleNoCache(ComponentWithLabel info) {
|
||||||
CacheEntry entry = cacheLocked(info.getComponent(), info.getUser(), () -> info,
|
CacheEntry entry = cacheLocked(info.getComponent(), info.getUser(), () -> info,
|
||||||
mComponentWithLabelCachingLogic, false /* usePackageIcon */,
|
mComponentWithLabelCachingLogic, false /* usePackageIcon */,
|
||||||
true /* useLowResIcon */, false /* addToMemCache */);
|
true /* useLowResIcon */);
|
||||||
return Utilities.trim(entry.title);
|
return Utilities.trim(entry.title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,4 +64,9 @@ public class ShortcutCachingLogic implements CachingLogic<ShortcutInfo> {
|
|||||||
if (shortcutInfo == null) return info.lastUpdateTime;
|
if (shortcutInfo == null) return info.lastUpdateTime;
|
||||||
return Math.max(shortcutInfo.getLastChangedTimestamp(), info.lastUpdateTime);
|
return Math.max(shortcutInfo.getLastChangedTimestamp(), info.lastUpdateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addToMemCache() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -242,8 +242,8 @@ public class LoaderTask implements Runnable {
|
|||||||
|
|
||||||
verifyNotStopped();
|
verifyNotStopped();
|
||||||
TraceHelper.partitionSection(TAG, "step 4.3: save widgets in icon cache");
|
TraceHelper.partitionSection(TAG, "step 4.3: save widgets in icon cache");
|
||||||
updateHandler.updateIcons(allWidgetsList, new ComponentCachingLogic(mApp.getContext()),
|
updateHandler.updateIcons(allWidgetsList, new ComponentCachingLogic(
|
||||||
mApp.getModel()::onWidgetLabelsUpdated);
|
mApp.getContext(), true), mApp.getModel()::onWidgetLabelsUpdated);
|
||||||
|
|
||||||
verifyNotStopped();
|
verifyNotStopped();
|
||||||
TraceHelper.partitionSection(TAG, "step 5: Finish icon cache update");
|
TraceHelper.partitionSection(TAG, "step 5: Finish icon cache update");
|
||||||
|
|||||||
Reference in New Issue
Block a user