diff --git a/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java b/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java index a3185741cc..882af59110 100644 --- a/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java +++ b/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java @@ -101,11 +101,11 @@ public class BaseIconFactory implements AutoCloseable { } public BitmapInfo createIconBitmap(Bitmap icon) { - if (mIconBitmapSize == icon.getWidth() && mIconBitmapSize == icon.getHeight()) { - return BitmapInfo.fromBitmap(icon); + if (mIconBitmapSize != icon.getWidth() || mIconBitmapSize != icon.getHeight()) { + icon = createIconBitmap(new BitmapDrawable(mContext.getResources(), icon), 1f); } - return BitmapInfo.fromBitmap( - createIconBitmap(new BitmapDrawable(mContext.getResources(), icon), 1f)); + + return BitmapInfo.fromBitmap(icon, mDisableColorExtractor ? null : mColorExtractor); } public BitmapInfo createBadgedIconBitmap(Drawable icon, UserHandle user, diff --git a/src/com/android/launcher3/icons/LauncherIcons.java b/src/com/android/launcher3/icons/LauncherIcons.java index 4b869cff69..f0a63ba999 100644 --- a/src/com/android/launcher3/icons/LauncherIcons.java +++ b/src/com/android/launcher3/icons/LauncherIcons.java @@ -114,7 +114,7 @@ public class LauncherIcons extends BaseIconFactory implements AutoCloseable { } public BitmapInfo createShortcutIcon(ShortcutInfoCompat shortcutInfo, - boolean badged, @Nullable Provider fallbackIconProvider) { + boolean badged, @Nullable Provider fallbackIconProvider) { Drawable unbadgedDrawable = DeepShortcutManager.getInstance(mContext) .getShortcutIconDrawable(shortcutInfo, mFillResIconDpi); IconCache cache = LauncherAppState.getInstance(mContext).getIconCache(); @@ -125,9 +125,12 @@ public class LauncherIcons extends BaseIconFactory implements AutoCloseable { } else { if (fallbackIconProvider != null) { // Fallback icons are already badged and with appropriate shadow - Bitmap fullIcon = fallbackIconProvider.get(); - if (fullIcon != null) { - return createIconBitmap(fullIcon); + ItemInfoWithIcon fullIcon = fallbackIconProvider.get(); + if (fullIcon != null && fullIcon.iconBitmap != null) { + BitmapInfo result = new BitmapInfo(); + result.icon = fullIcon.iconBitmap; + result.color = fullIcon.iconColor; + return result; } } unbadgedBitmap = cache.getDefaultIcon(Process.myUserHandle()).icon; diff --git a/src/com/android/launcher3/model/LoaderCursor.java b/src/com/android/launcher3/model/LoaderCursor.java index 3aeb1c078c..8efebf14b9 100644 --- a/src/com/android/launcher3/model/LoaderCursor.java +++ b/src/com/android/launcher3/model/LoaderCursor.java @@ -165,6 +165,15 @@ public class LoaderCursor extends CursorWrapper { * Loads the icon from the cursor and updates the {@param info} if the icon is an app resource. */ protected boolean loadIcon(ShortcutInfo info) { + try (LauncherIcons li = LauncherIcons.obtain(mContext)) { + return loadIcon(info, li); + } + } + + /** + * Loads the icon from the cursor and updates the {@param info} if the icon is an app resource. + */ + protected boolean loadIcon(ShortcutInfo info, LauncherIcons li) { if (itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) { String packageName = getString(iconPackageIndex); String resourceName = getString(iconResourceIndex); @@ -172,9 +181,7 @@ public class LoaderCursor extends CursorWrapper { info.iconResource = new ShortcutIconResource(); info.iconResource.packageName = packageName; info.iconResource.resourceName = resourceName; - LauncherIcons li = LauncherIcons.obtain(mContext); BitmapInfo iconInfo = li.createIconBitmap(info.iconResource); - li.recycle(); if (iconInfo != null) { info.applyFrom(iconInfo); return true; @@ -184,11 +191,11 @@ public class LoaderCursor extends CursorWrapper { // Failed to load from resource, try loading from DB. byte[] data = getBlob(iconIndex); - try (LauncherIcons li = LauncherIcons.obtain(mContext)) { + try { info.applyFrom(li.createIconBitmap(BitmapFactory.decodeByteArray(data, 0, data.length))); return true; } catch (Exception e) { - Log.e(TAG, "Failed to load icon for info " + info, e); + Log.e(TAG, "Failed to decode byte array for info " + info, e); return false; } } diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java index 2ecebb7b56..f711787cfe 100644 --- a/src/com/android/launcher3/model/LoaderTask.java +++ b/src/com/android/launcher3/model/LoaderTask.java @@ -43,6 +43,7 @@ import android.util.MutableInt; import com.android.launcher3.AllAppsList; import com.android.launcher3.AppInfo; import com.android.launcher3.FolderInfo; +import com.android.launcher3.ItemInfoWithIcon; import com.android.launcher3.icons.ComponentWithLabel; import com.android.launcher3.icons.ComponentWithLabel.ComponentCachingLogic; import com.android.launcher3.icons.cache.IconCacheUpdateHandler; @@ -493,12 +494,12 @@ public class LoaderTask implements Runnable { } info = new ShortcutInfo(pinnedShortcut, context); final ShortcutInfo finalInfo = info; - // If the pinned deep shortcut is no longer published, - // use the last saved icon instead of the default. - Provider fallbackIconProvider = () -> - c.loadIcon(finalInfo) ? finalInfo.iconBitmap : null; LauncherIcons li = LauncherIcons.obtain(context); + // If the pinned deep shortcut is no longer published, + // use the last saved icon instead of the default. + Provider fallbackIconProvider = () -> + c.loadIcon(finalInfo, li) ? finalInfo : null; info.applyFrom(li.createShortcutIcon(pinnedShortcut, true /* badged */, fallbackIconProvider)); li.recycle(); diff --git a/src/com/android/launcher3/model/ShortcutsChangedTask.java b/src/com/android/launcher3/model/ShortcutsChangedTask.java index e99fed9294..4e699f79a6 100644 --- a/src/com/android/launcher3/model/ShortcutsChangedTask.java +++ b/src/com/android/launcher3/model/ShortcutsChangedTask.java @@ -97,7 +97,7 @@ public class ShortcutsChangedTask extends BaseModelUpdateTask { // keep the current icon instead of reverting to the default icon. LauncherIcons li = LauncherIcons.obtain(context); shortcutInfo.applyFrom(li.createShortcutIcon(fullDetails, true, - Provider.of(shortcutInfo.iconBitmap))); + Provider.of(shortcutInfo))); li.recycle(); updatedShortcutInfos.add(shortcutInfo); } diff --git a/src/com/android/launcher3/model/UserLockStateChangedTask.java b/src/com/android/launcher3/model/UserLockStateChangedTask.java index 8e7557a2ee..59f42846b1 100644 --- a/src/com/android/launcher3/model/UserLockStateChangedTask.java +++ b/src/com/android/launcher3/model/UserLockStateChangedTask.java @@ -95,7 +95,7 @@ public class UserLockStateChangedTask extends BaseModelUpdateTask { // If the shortcut is pinned but no longer has an icon in the system, // keep the current icon instead of reverting to the default icon. LauncherIcons li = LauncherIcons.obtain(context); - si.applyFrom(li.createShortcutIcon(shortcut, true, Provider.of(si.iconBitmap))); + si.applyFrom(li.createShortcutIcon(shortcut, true, Provider.of(si))); li.recycle(); } else { si.runtimeStatusFlags |= FLAG_DISABLED_LOCKED_USER;