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

Commit 8099e194 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "shortcut-worker-thread" into ub-launcher3-master

* changes:
  fetch and update shortcut icons in background thread
  Revert "Revert "Revert "Revert "cache shourtcut image""""
parents d410c1b8 4ec390e4
Loading
Loading
Loading
Loading
+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;

@@ -42,6 +43,13 @@ public interface CachingLogic<T> {
        return null;
    }

    /**
     * Returns the timestamp the entry was last updated in cache.
     */
    default long getLastUpdatedTime(T object, PackageInfo info) {
        return info.lastUpdateTime;
    }

    /**
     * Returns true the object should be added to mem cache; otherwise returns false.
     */
+2 −2
Original line number Diff line number Diff line
@@ -171,7 +171,8 @@ 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
                if (version == info.versionCode
                        && updateTime == cachingLogic.getLastUpdatedTime(app, info)
                        && TextUtils.equals(c.getString(systemStateIndex),
                                mIconCache.getIconSystemState(info.packageName))) {

@@ -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
+2 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.launcher3;

import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
import static com.android.launcher3.util.ShortcutUtil.fetchAndUpdateShortcutIconAsync;

import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
@@ -482,9 +483,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
                return Pair.create(si, null);
            } else if (shortcutInfo != null) {
                WorkspaceItemInfo itemInfo = new WorkspaceItemInfo(shortcutInfo, mContext);
                LauncherIcons li = LauncherIcons.obtain(mContext);
                itemInfo.applyFrom(li.createShortcutIcon(shortcutInfo));
                li.recycle();
                fetchAndUpdateShortcutIconAsync(mContext, itemInfo, shortcutInfo, true);
                return Pair.create(itemInfo, shortcutInfo);
            } else if (providerInfo != null) {
                LauncherAppWidgetProviderInfo info = LauncherAppWidgetProviderInfo
+12 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
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;
@@ -50,6 +51,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.PackageUserKey;
import com.android.launcher3.util.Preconditions;
@@ -65,6 +67,7 @@ public class IconCache extends BaseIconCache {

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

    private final LauncherApps mLauncherApps;
    private final UserManagerCompat mUserManager;
@@ -78,6 +81,7 @@ public class IconCache extends BaseIconCache {
                inv.fillResIconDpi, inv.iconBitmapSize, true /* inMemoryCache */);
        mComponentWithLabelCachingLogic = new ComponentCachingLogic(context, false);
        mLauncherActivityInfoCachingLogic = LauncherActivityCachingLogic.newInstance(context);
        mShortcutCachingLogic = new ShortcutCachingLogic();
        mLauncherApps = mContext.getSystemService(LauncherApps.class);
        mUserManager = UserManagerCompat.getInstance(mContext);
        mInstantAppResolver = InstantAppResolver.newInstance(mContext);
@@ -175,6 +179,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.
+21 −9
Original line number Diff line number Diff line
@@ -21,10 +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 androidx.annotation.WorkerThread;

import com.android.launcher3.AppInfo;
import com.android.launcher3.FastBitmapDrawable;
@@ -34,7 +34,6 @@ import com.android.launcher3.LauncherAppState;
import com.android.launcher3.R;
import com.android.launcher3.graphics.IconShape;
import com.android.launcher3.model.PackageItemInfo;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.util.Themes;

import java.util.function.Supplier;
@@ -115,24 +114,37 @@ public class LauncherIcons extends BaseIconFactory implements AutoCloseable {
    }

    // below methods should also migrate to BaseIconFactory

    @WorkerThread
    public BitmapInfo createShortcutIcon(ShortcutInfo shortcutInfo) {
        return createShortcutIcon(shortcutInfo, true /* badged */);
    }

    @WorkerThread
    public BitmapInfo createShortcutIcon(ShortcutInfo shortcutInfo, boolean badged) {
        return createShortcutIcon(shortcutInfo, badged, null);
    }

    public BitmapInfo createShortcutIcon(ShortcutInfo shortcutInfo,
            boolean badged, @Nullable Supplier<ItemInfoWithIcon> fallbackIconProvider) {
        Drawable unbadgedDrawable = DeepShortcutManager.getInstance(mContext)
                .getShortcutIconDrawable(shortcutInfo, mFillResIconDpi);
    @WorkerThread
    public BitmapInfo createShortcutIcon(ShortcutInfo shortcutInfo, boolean badged,
            @Nullable Supplier<ItemInfoWithIcon> fallbackIconProvider) {
        return createShortcutIcon(shortcutInfo, badged, true, fallbackIconProvider);
    }

    @WorkerThread
    public BitmapInfo createShortcutIcon(ShortcutInfo shortcutInfo, boolean badged,
            boolean useCache, @Nullable Supplier<ItemInfoWithIcon> fallbackIconProvider) {
        IconCache cache = LauncherAppState.getInstance(mContext).getIconCache();
        final BitmapInfo bitmapInfo;
        if (useCache) {
            bitmapInfo = cache.getDeepShortcutTitleAndIcon(shortcutInfo);
        } else {
            bitmapInfo = new BitmapInfo();
            new ShortcutCachingLogic().loadIcon(mContext, shortcutInfo, bitmapInfo);
        }

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