OSDN Git Service

Ensuring that ShortcutInfo always has an icon
authorSunny Goyal <sunnygoyal@google.com>
Wed, 9 Nov 2016 18:43:58 +0000 (10:43 -0800)
committerSunny Goyal <sunnygoyal@google.com>
Tue, 13 Dec 2016 18:31:12 +0000 (10:31 -0800)
> Making iconBitmap public instead of a getter (similar to AppInfo)
> Removing getIcon() which can lead to IO on UI thread
> Removing updateIcon and handling the update at the caller

Bug: 21325319
Change-Id: I6a49b9043f974e9629ea25e77012d97cc04c0594

17 files changed:
src/com/android/launcher3/AppInfo.java
src/com/android/launcher3/BubbleTextView.java
src/com/android/launcher3/IconCache.java
src/com/android/launcher3/InstallShortcutReceiver.java
src/com/android/launcher3/Launcher.java
src/com/android/launcher3/LauncherModel.java
src/com/android/launcher3/ShortcutInfo.java
src/com/android/launcher3/Workspace.java
src/com/android/launcher3/folder/FolderIcon.java
src/com/android/launcher3/folder/FolderPagedView.java
src/com/android/launcher3/graphics/LauncherIcons.java
src/com/android/launcher3/model/CacheDataUpdatedTask.java
src/com/android/launcher3/model/PackageUpdatedTask.java
src/com/android/launcher3/shortcuts/DeepShortcutView.java
src/com/android/launcher3/util/CursorIconInfo.java
src/com/android/launcher3/util/ManagedProfileHeuristic.java
tests/src/com/android/launcher3/model/CacheDataUpdatedTaskTest.java

index 3b22f46..23e2882 100644 (file)
@@ -81,8 +81,14 @@ public class AppInfo extends ItemInfo {
 
     public AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user,
             IconCache iconCache, boolean quietModeEnabled) {
+        this(context, info, user, iconCache, quietModeEnabled, true /* useLowResIcon */);
+    }
+
+    public AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user,
+            IconCache iconCache, boolean quietModeEnabled, boolean useLowResIcon) {
         this.componentName = info.getComponentName();
         this.container = ItemInfo.NO_ID;
+        this.user = user;
         if (PackageManagerHelper.isAppSuspended(info.getApplicationInfo())) {
             isDisabled |= ShortcutInfo.FLAG_DISABLED_SUSPENDED;
         }
@@ -90,9 +96,8 @@ public class AppInfo extends ItemInfo {
             isDisabled |= ShortcutInfo.FLAG_DISABLED_QUIET_USER;
         }
 
-        iconCache.getTitleAndIcon(this, info, true /* useLowResIcon */);
+        iconCache.getTitleAndIcon(this, info, useLowResIcon);
         intent = makeLaunchIntent(context, info, user);
-        this.user = user;
     }
 
     public AppInfo(AppInfo info) {
index 51cd052..0c1a156 100644 (file)
@@ -155,13 +155,12 @@ public class BubbleTextView extends TextView
         setAccessibilityDelegate(mLauncher.getAccessibilityDelegate());
     }
 
-    public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache) {
-        applyFromShortcutInfo(info, iconCache, false);
+    public void applyFromShortcutInfo(ShortcutInfo info) {
+        applyFromShortcutInfo(info, false);
     }
 
-    public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache,
-            boolean promiseStateChanged) {
-        applyIconAndLabel(info.getIcon(iconCache), info);
+    public void applyFromShortcutInfo(ShortcutInfo info, boolean promiseStateChanged) {
+        applyIconAndLabel(info.iconBitmap, info);
         setTag(info);
         if (promiseStateChanged || info.isPromise()) {
             applyState(promiseStateChanged);
@@ -557,8 +556,7 @@ public class BubbleTextView extends TextView
             if (info instanceof AppInfo) {
                 applyFromApplicationInfo((AppInfo) info);
             } else if (info instanceof ShortcutInfo) {
-                applyFromShortcutInfo((ShortcutInfo) info,
-                        LauncherAppState.getInstance().getIconCache());
+                applyFromShortcutInfo((ShortcutInfo) info);
                 if ((info.rank < FolderIcon.NUM_ITEMS_IN_PREVIEW) && (info.container >= 0)) {
                     View folderIcon =
                             mLauncher.getWorkspace().getHomescreenIconByItemId(info.container);
index 4b09bf8..9f332a4 100644 (file)
@@ -490,7 +490,7 @@ public class IconCache {
         // 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 (component == null) {
-            shortcutInfo.setIcon(getDefaultIcon(user));
+            shortcutInfo.iconBitmap = getDefaultIcon(user);
             shortcutInfo.title = "";
             shortcutInfo.contentDescription = "";
             shortcutInfo.usingLowResIcon = false;
@@ -507,7 +507,7 @@ public class IconCache {
             ShortcutInfo shortcutInfo, ComponentName component, LauncherActivityInfoCompat info,
             UserHandleCompat user, boolean usePkgIcon, boolean useLowResIcon) {
         CacheEntry entry = cacheLocked(component, info, user, usePkgIcon, useLowResIcon);
-        shortcutInfo.setIcon(getNonNullIcon(entry, user));
+        shortcutInfo.iconBitmap = getNonNullIcon(entry, user);
         shortcutInfo.title = Utilities.trim(entry.title);
         shortcutInfo.contentDescription = entry.contentDescription;
         shortcutInfo.usingLowResIcon = entry.isLowResIcon;
index 46bc3b3..2f92201 100644 (file)
@@ -433,7 +433,10 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
 
         public ItemInfo getItemInfo() {
             if (activityInfo != null) {
-                return new ShortcutInfo(activityInfo, mContext);
+                return new AppInfo(mContext, activityInfo, user,
+                        LauncherAppState.getInstance().getIconCache(),
+                        UserManagerCompat.getInstance(mContext).isQuietModeEnabled(user),
+                        false /* useLowResIcon */).makeShortcut();
             } else if (shortcutInfo != null) {
                 return new ShortcutInfo(shortcutInfo, mContext);
             } else if (providerInfo != null) {
index accc3cd..35d34a3 100644 (file)
@@ -1424,7 +1424,7 @@ public class Launcher extends Activity
     public View createShortcut(ViewGroup parent, ShortcutInfo info) {
         BubbleTextView favorite = (BubbleTextView) getLayoutInflater().inflate(R.layout.app_icon,
                 parent, false);
-        favorite.applyFromShortcutInfo(info, mIconCache);
+        favorite.applyFromShortcutInfo(info);
         favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx);
         favorite.setOnClickListener(this);
         favorite.setOnFocusChangeListener(mFocusHandler);
@@ -2108,8 +2108,7 @@ public class Launcher extends Activity
                 cellX, cellY);
 
         // Create the view
-        FolderIcon newFolder =
-            FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
+        FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo);
         mWorkspace.addInScreen(newFolder, folderInfo);
         // Force measure the new folder icon
         CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
@@ -3346,7 +3345,7 @@ public class Launcher extends Activity
                 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: {
                     view = FolderIcon.fromXml(R.layout.folder_icon, this,
                             (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
-                            (FolderInfo) item, mIconCache);
+                            (FolderInfo) item);
                     break;
                 }
                 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: {
@@ -4037,13 +4036,6 @@ public class Launcher extends Activity
         return new AppInfo(this, activityInfo, user, mIconCache);
     }
 
-    // TODO: This method should be a part of LauncherSearchCallback
-    public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
-            Bitmap icon) {
-        return new ShortcutInfo(shortcutIntent, caption, caption, icon,
-                UserHandleCompat.myUserHandle());
-    }
-
     protected void moveWorkspaceToDefaultScreen() {
         mWorkspace.moveToDefaultScreen(false);
     }
index cc56d43..2a6f56b 100644 (file)
@@ -1792,8 +1792,10 @@ public class LauncherModel extends BroadcastReceiver
                     Collections.sort(folder.contents, Folder.ITEM_POS_COMPARATOR);
                     int pos = 0;
                     for (ShortcutInfo info : folder.contents) {
-                        if (info.usingLowResIcon) {
-                            info.updateIcon(mIconCache, false);
+                        if (info.usingLowResIcon &&
+                                info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
+                            mIconCache.getTitleAndIcon(
+                                    info, info.getPromisedIntent(), info.user, false);
                         }
                         pos ++;
                         if (pos >= FolderIcon.NUM_ITEMS_IN_PREVIEW) {
@@ -2518,13 +2520,10 @@ public class LauncherModel extends BroadcastReceiver
             int promiseType, int itemType, CursorIconInfo iconInfo) {
         final ShortcutInfo info = new ShortcutInfo();
         info.user = UserHandleCompat.myUserHandle();
-
-        Bitmap icon = iconInfo.loadIcon(c, info);
+        info.iconBitmap = iconInfo.loadIcon(c, info);
         // the fallback icon
-        if (icon == null) {
+        if (info.iconBitmap == null) {
             mIconCache.getTitleAndIcon(info, intent, info.user, false /* useLowResIcon */);
-        } else {
-            info.setIcon(icon);
         }
 
         if ((promiseType & ShortcutInfo.FLAG_RESTORED_ICON) != 0) {
@@ -2595,9 +2594,9 @@ public class LauncherModel extends BroadcastReceiver
 
         final ShortcutInfo info = new ShortcutInfo();
         mIconCache.getTitleAndIcon(info, componentName, lai, user, false, useLowResIcon);
-        if (mIconCache.isDefaultIcon(info.getIcon(mIconCache), user) && c != null) {
+        if (mIconCache.isDefaultIcon(info.iconBitmap, user) && c != null) {
             Bitmap icon = iconInfo.loadIcon(c);
-            info.setIcon(icon == null ? mIconCache.getDefaultIcon(user) : icon);
+            info.iconBitmap = icon != null ? icon : mIconCache.getDefaultIcon(user);
         }
 
         if (lai != null && PackageManagerHelper.isAppSuspended(lai.getApplicationInfo())) {
@@ -2640,12 +2639,11 @@ public class LauncherModel extends BroadcastReceiver
      */
     public void loadInfoFromCursor(ShortcutInfo info, Cursor c, CursorIconInfo iconInfo) {
         info.title = iconInfo.getTitle(c);
-        Bitmap icon = iconInfo.loadIcon(c, info);
+        info.iconBitmap = iconInfo.loadIcon(c, info);
         // the fallback icon
-        if (icon == null) {
-            icon = mIconCache.getDefaultIcon(info.user);
+        if (info.iconBitmap == null) {
+            info.iconBitmap = mIconCache.getDefaultIcon(info.user);
         }
-        info.setIcon(icon);
     }
 
     ShortcutInfo infoFromShortcutIntent(Context context, Intent data) {
@@ -2659,34 +2657,28 @@ public class LauncherModel extends BroadcastReceiver
             return null;
         }
 
-        Bitmap icon = null;
-        ShortcutIconResource iconResource = null;
+        final ShortcutInfo info = new ShortcutInfo();
+
+        // Only support intents for current user for now. Intents sent from other
+        // users wouldn't get here without intent forwarding anyway.
+        info.user = UserHandleCompat.myUserHandle();
 
         if (bitmap instanceof Bitmap) {
-            icon = LauncherIcons.createIconBitmap((Bitmap) bitmap, context);
+            info.iconBitmap = LauncherIcons.createIconBitmap((Bitmap) bitmap, context);
         } else {
             Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
             if (extra instanceof ShortcutIconResource) {
-                iconResource = (ShortcutIconResource) extra;
-                icon = LauncherIcons.createIconBitmap(iconResource.packageName,
-                        iconResource.resourceName, context);
+                info.iconResource = (ShortcutIconResource) extra;
+                info.iconBitmap = LauncherIcons.createIconBitmap(info.iconResource, context);
             }
         }
-
-        final ShortcutInfo info = new ShortcutInfo();
-
-        // Only support intents for current user for now. Intents sent from other
-        // users wouldn't get here without intent forwarding anyway.
-        info.user = UserHandleCompat.myUserHandle();
-        if (icon == null) {
-            icon = mIconCache.getDefaultIcon(info.user);
+        if (info.iconBitmap == null) {
+            info.iconBitmap = mIconCache.getDefaultIcon(info.user);
         }
-        info.setIcon(icon);
 
         info.title = Utilities.trim(name);
         info.contentDescription = mUserManager.getBadgedLabelForUser(info.title, info.user);
         info.intent = intent;
-        info.iconResource = iconResource;
 
         return info;
     }
index d6d03d3..fd65337 100644 (file)
@@ -26,10 +26,8 @@ import android.os.Build;
 import android.text.TextUtils;
 
 import com.android.launcher3.LauncherSettings.Favorites;
-import com.android.launcher3.compat.LauncherActivityInfoCompat;
 import com.android.launcher3.compat.UserHandleCompat;
 import com.android.launcher3.compat.UserManagerCompat;
-import com.android.launcher3.folder.FolderIcon;
 import com.android.launcher3.graphics.LauncherIcons;
 import com.android.launcher3.shortcuts.DeepShortcutManager;
 import com.android.launcher3.shortcuts.ShortcutInfoCompat;
@@ -80,7 +78,7 @@ public class ShortcutInfo extends ItemInfo {
     /**
      * Indicates whether we're using a low res icon
      */
-    boolean usingLowResIcon;
+    public boolean usingLowResIcon;
 
     /**
      * If isShortcut=true and customIcon=false, this contains a reference to the
@@ -91,7 +89,7 @@ public class ShortcutInfo extends ItemInfo {
     /**
      * The application icon.
      */
-    private Bitmap mIcon;
+    public Bitmap iconBitmap;
 
     /**
      * Indicates that the icon is disabled due to safe mode restrictions.
@@ -163,22 +161,12 @@ public class ShortcutInfo extends ItemInfo {
         return promisedIntent != null ? promisedIntent : intent;
     }
 
-    ShortcutInfo(Intent intent, CharSequence title, CharSequence contentDescription,
-            Bitmap icon, UserHandleCompat user) {
-        this();
-        this.intent = intent;
-        this.title = Utilities.trim(title);
-        this.contentDescription = contentDescription;
-        mIcon = icon;
-        this.user = user;
-    }
-
     public ShortcutInfo(ShortcutInfo info) {
         super(info);
         title = info.title;
         intent = new Intent(info.intent);
         iconResource = info.iconResource;
-        mIcon = info.mIcon; // TODO: should make a copy here.  maybe we don't need this ctor at all
+        iconBitmap = info.iconBitmap;
         status = info.status;
         mInstallProgress = info.mInstallProgress;
         isDisabled = info.isDisabled;
@@ -190,15 +178,8 @@ public class ShortcutInfo extends ItemInfo {
         title = Utilities.trim(info.title);
         intent = new Intent(info.intent);
         isDisabled = info.isDisabled;
-    }
-
-    public ShortcutInfo(LauncherActivityInfoCompat info, Context context) {
-        user = info.getUser();
-        title = Utilities.trim(info.getLabel());
-        contentDescription = UserManagerCompat.getInstance(context)
-                .getBadgedLabelForUser(info.getLabel(), info.getUser());
-        intent = AppInfo.makeLaunchIntent(context, info, info.getUser());
-        itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
+        iconBitmap = info.iconBitmap;
+        usingLowResIcon = info.usingLowResIcon;
     }
 
     /**
@@ -211,28 +192,6 @@ public class ShortcutInfo extends ItemInfo {
         updateFromDeepShortcutInfo(shortcutInfo, context);
     }
 
-    public void setIcon(Bitmap b) {
-        mIcon = b;
-    }
-
-    public Bitmap getIcon(IconCache iconCache) {
-        if (mIcon == null) {
-            updateIcon(iconCache);
-        }
-        return mIcon;
-    }
-
-    public void updateIcon(IconCache iconCache, boolean useLowRes) {
-        if (itemType == Favorites.ITEM_TYPE_APPLICATION) {
-            iconCache.getTitleAndIcon(this, promisedIntent != null ? promisedIntent : intent, user,
-                    useLowRes);
-        }
-    }
-
-    public void updateIcon(IconCache iconCache) {
-        updateIcon(iconCache, shouldUseLowResIcon());
-    }
-
     @Override
     void onAddToDatabase(ContentWriter writer) {
         super.onAddToDatabase(writer);
@@ -241,7 +200,7 @@ public class ShortcutInfo extends ItemInfo {
                 .put(LauncherSettings.Favorites.RESTORED, status);
 
         if (!usingLowResIcon) {
-            writer.putIcon(mIcon, user);
+            writer.putIcon(iconBitmap, user);
         }
         if (iconResource != null) {
             writer.put(LauncherSettings.BaseLauncherColumns.ICON_PACKAGE, iconResource.packageName)
@@ -251,7 +210,7 @@ public class ShortcutInfo extends ItemInfo {
     }
 
     public ComponentName getTargetComponent() {
-        return promisedIntent != null ? promisedIntent.getComponent() : intent.getComponent();
+        return getPromisedIntent().getComponent();
     }
 
     public boolean hasStatusFlag(int flag) {
@@ -272,10 +231,6 @@ public class ShortcutInfo extends ItemInfo {
         status |= FLAG_INSTALL_SESSION_ACTIVE;
     }
 
-    public boolean shouldUseLowResIcon() {
-        return usingLowResIcon && container >= 0 && rank >= FolderIcon.NUM_ITEMS_IN_PREVIEW;
-    }
-
     public void updateFromDeepShortcutInfo(ShortcutInfoCompat shortcutInfo, Context context) {
         // {@link ShortcutInfoCompat#getActivity} can change during an update. Recreate the intent
         intent = shortcutInfo.makeIntent(context);
@@ -304,7 +259,7 @@ public class ShortcutInfo extends ItemInfo {
         Bitmap unbadgedBitmap = unbadgedDrawable == null
                 ? cache.getDefaultIcon(UserHandleCompat.myUserHandle())
                 : LauncherIcons.createScaledBitmapWithoutShadow(unbadgedDrawable, context);
-        setIcon(getBadgedIcon(unbadgedBitmap, shortcutInfo, cache, context));
+        iconBitmap = getBadgedIcon(unbadgedBitmap, shortcutInfo, cache, context);
     }
 
     protected Bitmap getBadgedIcon(Bitmap unbadgedBitmap, ShortcutInfoCompat shortcutInfo,
index 13bea20..13b3e28 100644 (file)
@@ -172,7 +172,6 @@ public class Workspace extends PagedView
     private CellLayout mDropToLayout = null;
 
     @Thunk Launcher mLauncher;
-    @Thunk IconCache mIconCache;
     @Thunk DragController mDragController;
 
     // These are temporary variables to prevent having to allocate a new object just to
@@ -502,9 +501,7 @@ public class Workspace extends PagedView
      */
     protected void initWorkspace() {
         mCurrentPage = getDefaultPage();
-        LauncherAppState app = LauncherAppState.getInstance();
         DeviceProfile grid = mLauncher.getDeviceProfile();
-        mIconCache = app.getIconCache();
         setWillNotDraw(false);
         setClipChildren(false);
         setClipToPadding(false);
@@ -3397,7 +3394,7 @@ public class Workspace extends PagedView
                 break;
             case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
                 view = FolderIcon.fromXml(R.layout.folder_icon, mLauncher, cellLayout,
-                        (FolderInfo) info, mIconCache);
+                        (FolderInfo) info);
                 break;
             default:
                 throw new IllegalStateException("Unknown item type: " + info.itemType);
@@ -4078,8 +4075,7 @@ public class Workspace extends PagedView
                     Drawable oldIcon = getTextViewIcon(shortcut);
                     boolean oldPromiseState = (oldIcon instanceof PreloadIconDrawable)
                             && ((PreloadIconDrawable) oldIcon).hasNotCompleted();
-                    shortcut.applyFromShortcutInfo(si, mIconCache,
-                            si.isPromise() != oldPromiseState);
+                    shortcut.applyFromShortcutInfo(si, si.isPromise() != oldPromiseState);
                 }
                 // process all the shortcuts
                 return false;
index 3745323..973245b 100644 (file)
@@ -146,7 +146,7 @@ public class FolderIcon extends FrameLayout implements FolderListener {
     }
 
     public static FolderIcon fromXml(int resId, Launcher launcher, ViewGroup group,
-            FolderInfo folderInfo, IconCache iconCache) {
+            FolderInfo folderInfo) {
         @SuppressWarnings("all") // suppress dead code warning
         final boolean error = INITIAL_ITEM_ANIMATION_DURATION >= DROP_IN_ANIMATION_DURATION;
         if (error) {
index 8aaeb9e..3a318b5 100644 (file)
@@ -31,7 +31,6 @@ import com.android.launcher3.BubbleTextView;
 import com.android.launcher3.CellLayout;
 import com.android.launcher3.DeviceProfile;
 import com.android.launcher3.FocusHelper.PagedFolderKeyEventListener;
-import com.android.launcher3.IconCache;
 import com.android.launcher3.InvariantDeviceProfile;
 import com.android.launcher3.ItemInfo;
 import com.android.launcher3.Launcher;
@@ -73,7 +72,6 @@ public class FolderPagedView extends PagedView {
     public final boolean mIsRtl;
 
     private final LayoutInflater mInflater;
-    private final IconCache mIconCache;
     private final ViewGroupFocusHelper mFocusIndicatorHelper;
 
     @Thunk final HashMap<View, Runnable> mPendingAnimations = new HashMap<>();
@@ -107,7 +105,6 @@ public class FolderPagedView extends PagedView {
         mMaxItemsPerPage = mMaxCountX * mMaxCountY;
 
         mInflater = LayoutInflater.from(context);
-        mIconCache = app.getIconCache();
 
         mIsRtl = Utilities.isRtl(getResources());
         setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
@@ -231,7 +228,7 @@ public class FolderPagedView extends PagedView {
     public View createNewView(ShortcutInfo item) {
         final BubbleTextView textView = (BubbleTextView) mInflater.inflate(
                 R.layout.folder_application, null, false);
-        textView.applyFromShortcutInfo(item, mIconCache);
+        textView.applyFromShortcutInfo(item);
         textView.setOnClickListener(mFolder);
         textView.setOnLongClickListener(mFolder);
         textView.setOnFocusChangeListener(mFocusIndicatorHelper);
index 9f3f357..6f9f7ff 100644 (file)
@@ -18,6 +18,7 @@ package com.android.launcher3.graphics;
 
 import android.annotation.TargetApi;
 import android.content.Context;
+import android.content.Intent.ShortcutIconResource;
 import android.content.pm.PackageManager;
 import android.content.res.Resources;
 import android.database.Cursor;
@@ -66,14 +67,13 @@ public class LauncherIcons {
      * Returns a bitmap suitable for the all apps view. If the package or the resource do not
      * exist, it returns null.
      */
-    public static Bitmap createIconBitmap(String packageName, String resourceName,
-            Context context) {
+    public static Bitmap createIconBitmap(ShortcutIconResource iconRes, Context context) {
         PackageManager packageManager = context.getPackageManager();
         // the resource
         try {
-            Resources resources = packageManager.getResourcesForApplication(packageName);
+            Resources resources = packageManager.getResourcesForApplication(iconRes.packageName);
             if (resources != null) {
-                final int id = resources.getIdentifier(resourceName, null, null);
+                final int id = resources.getIdentifier(iconRes.resourceName, null, null);
                 return createIconBitmap(
                         resources.getDrawableForDensity(id, LauncherAppState.getInstance()
                                 .getInvariantDeviceProfile().fillResIconDpi), context);
index 9f24e90..64771d5 100644 (file)
@@ -25,6 +25,7 @@ import com.android.launcher3.LauncherAppState;
 import com.android.launcher3.LauncherModel.CallbackTask;
 import com.android.launcher3.LauncherModel.Callbacks;
 import com.android.launcher3.LauncherSettings;
+import com.android.launcher3.LauncherSettings.Favorites;
 import com.android.launcher3.ShortcutInfo;
 import com.android.launcher3.compat.UserHandleCompat;
 
@@ -61,9 +62,10 @@ public class CacheDataUpdatedTask extends ExtendedModelTask {
                 if (info instanceof ShortcutInfo && mUser.equals(info.user)) {
                     ShortcutInfo si = (ShortcutInfo) info;
                     ComponentName cn = si.getTargetComponent();
-                    if (isValidShortcut(si) &&
-                            cn != null && mPackages.contains(cn.getPackageName())) {
-                        si.updateIcon(iconCache);
+                    if (si.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION
+                            && isValidShortcut(si) && cn != null
+                            && mPackages.contains(cn.getPackageName())) {
+                        iconCache.getTitleAndIcon(si, si.getPromisedIntent(), si.user, si.usingLowResIcon);
                         updatedShortcuts.add(si);
                     }
                 }
@@ -85,7 +87,7 @@ public class CacheDataUpdatedTask extends ExtendedModelTask {
     public boolean isValidShortcut(ShortcutInfo si) {
         switch (mOp) {
             case OP_CACHE_UPDATE:
-                return si.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
+                return true;
             case OP_SESSION_UPDATE:
                 return si.isPromise();
             default:
index 176e8ea..aae3490 100644 (file)
@@ -34,6 +34,7 @@ import com.android.launcher3.LauncherModel;
 import com.android.launcher3.LauncherModel.CallbackTask;
 import com.android.launcher3.LauncherModel.Callbacks;
 import com.android.launcher3.LauncherSettings;
+import com.android.launcher3.LauncherSettings.Favorites;
 import com.android.launcher3.ShortcutInfo;
 import com.android.launcher3.Utilities;
 import com.android.launcher3.compat.LauncherAppsCompat;
@@ -209,11 +210,9 @@ public class PackageUpdatedTask extends ExtendedModelTask {
                         // Update shortcuts which use iconResource.
                         if ((si.iconResource != null)
                                 && packageSet.contains(si.iconResource.packageName)) {
-                            Bitmap icon = LauncherIcons.createIconBitmap(
-                                    si.iconResource.packageName,
-                                    si.iconResource.resourceName, context);
+                            Bitmap icon = LauncherIcons.createIconBitmap(si.iconResource, context);
                             if (icon != null) {
-                                si.setIcon(icon);
+                                si.iconBitmap = icon;
                                 infoUpdated = true;
                             }
                         }
@@ -251,14 +250,16 @@ public class PackageUpdatedTask extends ExtendedModelTask {
                                 si.promisedIntent = null;
                                 si.status = ShortcutInfo.DEFAULT;
                                 infoUpdated = true;
-                                si.updateIcon(iconCache);
+                                if (si.itemType == Favorites.ITEM_TYPE_APPLICATION) {
+                                    iconCache.getTitleAndIcon(si, si.getPromisedIntent(),
+                                            si.user, si.usingLowResIcon);
+                                }
                             }
 
                             if (appInfo != null && Intent.ACTION_MAIN.equals(si.intent.getAction())
                                     && si.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
-                                si.updateIcon(iconCache);
-                                si.title = Utilities.trim(appInfo.title);
-                                si.contentDescription = appInfo.contentDescription;
+                                iconCache.getTitleAndIcon(
+                                        si, si.getPromisedIntent(), si.user, si.usingLowResIcon);
                                 infoUpdated = true;
                             }
 
index e7fc415..6796137 100644 (file)
@@ -26,9 +26,7 @@ import android.util.AttributeSet;
 import android.view.View;
 import android.widget.FrameLayout;
 
-import com.android.launcher3.IconCache;
 import com.android.launcher3.Launcher;
-import com.android.launcher3.LauncherAppState;
 import com.android.launcher3.LogAccelerateInterpolator;
 import com.android.launcher3.R;
 import com.android.launcher3.ShortcutInfo;
@@ -95,8 +93,7 @@ public class DeepShortcutView extends FrameLayout implements ValueAnimator.Anima
     /** package private **/
     void applyShortcutInfo(UnbadgedShortcutInfo info, DeepShortcutsContainer container) {
         mInfo = info;
-        IconCache cache = LauncherAppState.getInstance().getIconCache();
-        mBubbleText.applyFromShortcutInfo(info, cache);
+        mBubbleText.applyFromShortcutInfo(info);
         mIconView.setBackground(mBubbleText.getIcon());
 
         // Use the long label as long as it exists and fits.
index 6603ee7..3bc4eab 100644 (file)
@@ -60,7 +60,7 @@ public class CursorIconInfo {
             info.iconResource = new ShortcutIconResource();
             info.iconResource.packageName = packageName;
             info.iconResource.resourceName = resourceName;
-            icon = LauncherIcons.createIconBitmap(packageName, resourceName, mContext);
+            icon = LauncherIcons.createIconBitmap(info.iconResource, mContext);
         }
         if (icon == null) {
             // Failed to load from resource, try loading from DB.
index 817a38a..6b4021f 100644 (file)
@@ -19,7 +19,9 @@ package com.android.launcher3.util;
 import android.content.Context;
 import android.content.SharedPreferences;
 
+import com.android.launcher3.AppInfo;
 import com.android.launcher3.FolderInfo;
+import com.android.launcher3.IconCache;
 import com.android.launcher3.ItemInfo;
 import com.android.launcher3.LauncherAppState;
 import com.android.launcher3.LauncherFiles;
@@ -65,11 +67,13 @@ public class ManagedProfileHeuristic {
     private final Context mContext;
     private final LauncherModel mModel;
     private final UserHandleCompat mUser;
+    private final IconCache mIconCache;
 
     private ManagedProfileHeuristic(Context context, UserHandleCompat user) {
         mContext = context;
         mUser = user;
         mModel = LauncherAppState.getInstance().getModel();
+        mIconCache = LauncherAppState.getInstance().getIconCache();
     }
 
     public void processPackageRemoved(String[] packages) {
@@ -108,10 +112,12 @@ public class ManagedProfileHeuristic {
             long folderCreationTime =
                     mUserManager.getUserCreationTime(user) + AUTO_ADD_TO_FOLDER_DURATION;
 
+            boolean quietModeEnabled = UserManagerCompat.getInstance(mContext)
+                    .isQuietModeEnabled(user);
             for (int i = 0; i < count; i++) {
                 LauncherActivityInstallInfo info = apps.get(i);
-
-                ShortcutInfo si = new ShortcutInfo(info.info, mContext);
+                ShortcutInfo si = new AppInfo(mContext, info.info, user, mIconCache,
+                        quietModeEnabled, false /* useLowResIcon */).makeShortcut();
                 ((info.installTime <= folderCreationTime) ? workFolderApps : homescreenApps).add(si);
             }
 
index 25b8df9..646ef27 100644 (file)
@@ -1,15 +1,12 @@
 package com.android.launcher3.model;
 
 import com.android.launcher3.AppInfo;
-import com.android.launcher3.IconCache;
 import com.android.launcher3.ItemInfo;
 import com.android.launcher3.ShortcutInfo;
 
 import java.util.Arrays;
 import java.util.HashSet;
 
-import static org.mockito.Mockito.mock;
-
 /**
  * Tests for {@link CacheDataUpdatedTask}
  */
@@ -67,14 +64,13 @@ public class CacheDataUpdatedTaskTest extends BaseModelUpdateTaskTestCase {
 
     private void verifyUpdate(Long... idsUpdated) {
         HashSet<Long> updates = new HashSet<>(Arrays.asList(idsUpdated));
-        IconCache noOpIconCache = mock(IconCache.class);
         for (ItemInfo info : bgDataModel.itemsIdMap) {
             if (updates.contains(info.id)) {
                 assertEquals(NEW_LABEL_PREFIX + info.id, info.title);
-                assertNotNull(((ShortcutInfo) info).getIcon(noOpIconCache));
+                assertNotNull(((ShortcutInfo) info).iconBitmap);
             } else {
                 assertNotSame(NEW_LABEL_PREFIX + info.id, info.title);
-                assertNull(((ShortcutInfo) info).getIcon(noOpIconCache));
+                assertNull(((ShortcutInfo) info).iconBitmap);
             }
         }
     }