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

Commit 2cfa8dc0 authored by Pinyao Ting's avatar Pinyao Ting Committed by android-build-merger
Browse files

Merge changes from topic "cache-shortcut-image" into ub-launcher3-qt-future-dev

am: 570d9a1e

Change-Id: I3182c90a69d1c93daf8d33cfe7f15f613ac972fd
parents 388a2122 570d9a1e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -267,6 +267,10 @@ public abstract class BaseIconCache {
            entry = new CacheEntry();
            cachingLogic.loadIcon(mContext, object, entry);
        }
        // Icon can't be loaded from cachingLogic, which implies alternative icon was loaded
        // (e.g. fallback icon, default icon). So we drop here since there's no point in caching
        // an empty entry.
        if (entry.icon == null) return;
        entry.title = cachingLogic.getLabel(object);
        entry.contentDescription = mPackageManager.getUserBadgedLabel(entry.title, user);
        mCache.put(key, entry);
+8 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.launcher3.icons.cache;

import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.LocaleList;
import android.os.UserHandle;

@@ -41,4 +42,11 @@ public interface CachingLogic<T> {
    default String getKeywords(T object, LocaleList localeList) {
        return null;
    }

    /**
     * Returns the timestamp the entry was last updated in cache.
     */
    default long getLastUpdatedTime(T object, PackageInfo info) {
        return info.lastUpdateTime;
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -171,8 +171,9 @@ public class IconCacheUpdateHandler {
                long updateTime = c.getLong(indexLastUpdate);
                int version = c.getInt(indexVersion);
                T app = componentMap.remove(component);
                if (version == info.versionCode && updateTime == info.lastUpdateTime &&
                        TextUtils.equals(c.getString(systemStateIndex),
                if (version == info.versionCode
                        && updateTime == cachingLogic.getLastUpdatedTime(app, info)
                        && TextUtils.equals(c.getString(systemStateIndex),
                                mIconCache.getIconSystemState(info.packageName))) {

                    if (mFilterMode == MODE_CLEAR_VALID_ITEMS) {
@@ -231,7 +232,6 @@ public class IconCacheUpdateHandler {
        }
    }


    /**
     * A runnable that updates invalid icons and adds missing icons in the DB for the provided
     * LauncherActivityInfo list. Items are updated/added one at a time, so that the
+12 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.pm.LauncherActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ShortcutInfo;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Process;
@@ -49,6 +50,7 @@ import com.android.launcher3.icons.cache.BaseIconCache;
import com.android.launcher3.icons.cache.CachingLogic;
import com.android.launcher3.icons.cache.HandlerRunnable;
import com.android.launcher3.model.PackageItemInfo;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.util.InstantAppResolver;
import com.android.launcher3.util.Preconditions;

@@ -63,6 +65,7 @@ public class IconCache extends BaseIconCache {

    private final CachingLogic<ComponentWithLabel> mComponentWithLabelCachingLogic;
    private final CachingLogic<LauncherActivityInfo> mLauncherActivityInfoCachingLogic;
    private final CachingLogic<ShortcutInfo> mShortcutCachingLogic;

    private final LauncherAppsCompat mLauncherApps;
    private final UserManagerCompat mUserManager;
@@ -76,6 +79,7 @@ public class IconCache extends BaseIconCache {
                inv.fillResIconDpi, inv.iconBitmapSize, true /* inMemoryCache */);
        mComponentWithLabelCachingLogic = new ComponentCachingLogic(context);
        mLauncherActivityInfoCachingLogic = LauncherActivityCachingLogic.newInstance(context);
        mShortcutCachingLogic = new ShortcutCachingLogic();
        mLauncherApps = LauncherAppsCompat.getInstance(mContext);
        mUserManager = UserManagerCompat.getInstance(mContext);
        mInstantAppResolver = InstantAppResolver.newInstance(mContext);
@@ -173,6 +177,14 @@ public class IconCache extends BaseIconCache {
        getTitleAndIcon(info, () -> activityInfo, false, useLowResIcon);
    }

    /**
     * Fill in info with the icon and label for deep shortcut.
     */
    public synchronized CacheEntry getDeepShortcutTitleAndIcon(ShortcutInfo info) {
        return cacheLocked(ShortcutKey.fromInfo(info).componentName, info.getUserHandle(),
                () -> info, mShortcutCachingLogic, false, false);
    }

    /**
     * Fill in {@param info} with the icon and label. If the
     * corresponding activity is not found, it reverts to the package icon.
+6 −8
Original line number Diff line number Diff line
@@ -21,9 +21,10 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Process;

import androidx.annotation.Nullable;

import com.android.launcher3.AppInfo;
import com.android.launcher3.FastBitmapDrawable;
import com.android.launcher3.InvariantDeviceProfile;
@@ -31,14 +32,12 @@ import com.android.launcher3.ItemInfoWithIcon;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.R;
import com.android.launcher3.graphics.IconShape;
import com.android.launcher3.icons.cache.BaseIconCache;
import com.android.launcher3.model.PackageItemInfo;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.util.Themes;

import java.util.function.Supplier;

import androidx.annotation.Nullable;

/**
 * Wrapper class to provide access to {@link BaseIconFactory} and also to provide pool of this class
 * that are threadsafe.
@@ -126,13 +125,12 @@ public class LauncherIcons extends BaseIconFactory implements AutoCloseable {

    public BitmapInfo createShortcutIcon(ShortcutInfo shortcutInfo,
            boolean badged, @Nullable Supplier<ItemInfoWithIcon> fallbackIconProvider) {
        Drawable unbadgedDrawable = DeepShortcutManager.getInstance(mContext)
                .getShortcutIconDrawable(shortcutInfo, mFillResIconDpi);
        IconCache cache = LauncherAppState.getInstance(mContext).getIconCache();
        BaseIconCache.CacheEntry entry = cache.getDeepShortcutTitleAndIcon(shortcutInfo);

        final Bitmap unbadgedBitmap;
        if (unbadgedDrawable != null) {
            unbadgedBitmap = createScaledBitmapWithoutShadow(unbadgedDrawable, 0);
        if (entry.icon != null) {
            unbadgedBitmap = entry.icon;
        } else {
            if (fallbackIconProvider != null) {
                // Fallback icons are already badged and with appropriate shadow
Loading