Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ddd0ff44 authored by Pinyao Ting's avatar Pinyao Ting
Browse files

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
parent ca939f07
Loading
Loading
Loading
Loading
+2 −10
Original line number Diff line number Diff line
@@ -273,7 +273,7 @@ public abstract class BaseIconCache {
        if (entry.icon == null) return;
        entry.title = cachingLogic.getLabel(object);
        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(),
                componentName.getPackageName(), cachingLogic.getKeywords(object, mLocaleList));
@@ -312,20 +312,12 @@ public abstract class BaseIconCache {
            @NonNull ComponentName componentName, @NonNull UserHandle user,
            @NonNull Supplier<T> infoProvider, @NonNull CachingLogic<T> cachingLogic,
            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();
        ComponentKey cacheKey = new ComponentKey(componentName, user);
        CacheEntry entry = mCache.get(cacheKey);
        if (entry == null || (entry.isLowRes() && !useLowResIcon)) {
            entry = new CacheEntry();
            if (addToMemCache) {
            if (cachingLogic.addToMemCache()) {
                mCache.put(cacheKey, entry);
            }

+7 −0
Original line number Diff line number Diff line
@@ -49,4 +49,11 @@ public interface CachingLogic<T> {
    default long getLastUpdatedTime(T object, PackageInfo info) {
        return info.lastUpdateTime;
    }

    /**
     * Returns true the object should be added to mem cache; otherwise returns false.
     */
    default boolean addToMemCache() {
        return true;
    }
}
+8 −1
Original line number Diff line number Diff line
@@ -34,9 +34,11 @@ public interface ComponentWithLabel {
    class ComponentCachingLogic implements CachingLogic<ComponentWithLabel> {

        private final PackageManager mPackageManager;
        private final boolean mAddToMemCache;

        public ComponentCachingLogic(Context context) {
        public ComponentCachingLogic(Context context, boolean addToMemCache) {
            mPackageManager = context.getPackageManager();
            mAddToMemCache = addToMemCache;
        }

        @Override
@@ -60,5 +62,10 @@ public interface ComponentWithLabel {
            // Do not load icon.
            target.icon = BitmapInfo.LOW_RES_ICON;
        }

        @Override
        public boolean addToMemCache() {
            return mAddToMemCache;
        }
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ public class IconCache extends BaseIconCache {
    public IconCache(Context context, InvariantDeviceProfile inv) {
        super(context, LauncherFiles.APP_ICONS_DB, MODEL_EXECUTOR.getLooper(),
                inv.fillResIconDpi, inv.iconBitmapSize, true /* inMemoryCache */);
        mComponentWithLabelCachingLogic = new ComponentCachingLogic(context);
        mComponentWithLabelCachingLogic = new ComponentCachingLogic(context, false);
        mLauncherActivityInfoCachingLogic = LauncherActivityCachingLogic.newInstance(context);
        mShortcutCachingLogic = new ShortcutCachingLogic();
        mLauncherApps = LauncherAppsCompat.getInstance(mContext);
@@ -206,7 +206,7 @@ public class IconCache extends BaseIconCache {
    public synchronized String getTitleNoCache(ComponentWithLabel info) {
        CacheEntry entry = cacheLocked(info.getComponent(), info.getUser(), () -> info,
                mComponentWithLabelCachingLogic, false /* usePackageIcon */,
                true /* useLowResIcon */, false /* addToMemCache */);
                true /* useLowResIcon */);
        return Utilities.trim(entry.title);
    }

+5 −0
Original line number Diff line number Diff line
@@ -64,4 +64,9 @@ public class ShortcutCachingLogic implements CachingLogic<ShortcutInfo> {
        if (shortcutInfo == null) return info.lastUpdateTime;
        return Math.max(shortcutInfo.getLastChangedTimestamp(), info.lastUpdateTime);
    }

    @Override
    public boolean addToMemCache() {
        return false;
    }
}
Loading