Use last saved icon if pinned shortcut is unpublished
Bug: 62814533 Change-Id: I683bd6abdf17defc55c0f17d8688951d4841c066
This commit is contained in:
parent
6f7f4bb97e
commit
5fe66e3eef
|
@ -35,6 +35,7 @@ import android.graphics.drawable.PaintDrawable;
|
|||
import android.os.Build;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.android.launcher3.AppInfo;
|
||||
import com.android.launcher3.IconCache;
|
||||
|
@ -45,6 +46,7 @@ import com.android.launcher3.config.FeatureFlags;
|
|||
import com.android.launcher3.model.PackageItemInfo;
|
||||
import com.android.launcher3.shortcuts.DeepShortcutManager;
|
||||
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
|
||||
import com.android.launcher3.util.Provider;
|
||||
|
||||
/**
|
||||
* Helper methods for generating various launcher icons
|
||||
|
@ -315,14 +317,28 @@ public class LauncherIcons {
|
|||
|
||||
public static Bitmap createShortcutIcon(ShortcutInfoCompat shortcutInfo, Context context,
|
||||
boolean badged) {
|
||||
return createShortcutIcon(shortcutInfo, context, badged, null);
|
||||
}
|
||||
|
||||
public static Bitmap createShortcutIcon(ShortcutInfoCompat shortcutInfo, Context context,
|
||||
boolean badged, @Nullable Provider<Bitmap> fallbackIconProvider) {
|
||||
LauncherAppState app = LauncherAppState.getInstance(context);
|
||||
Drawable unbadgedDrawable = DeepShortcutManager.getInstance(context)
|
||||
.getShortcutIconDrawable(shortcutInfo,
|
||||
app.getInvariantDeviceProfile().fillResIconDpi);
|
||||
IconCache cache = app.getIconCache();
|
||||
Bitmap unbadgedBitmap = unbadgedDrawable == null
|
||||
? cache.getDefaultIcon(Process.myUserHandle())
|
||||
: LauncherIcons.createScaledBitmapWithoutShadow(unbadgedDrawable, context, 0);
|
||||
Bitmap unbadgedBitmap = null;
|
||||
if (unbadgedDrawable != null) {
|
||||
unbadgedBitmap = LauncherIcons.createScaledBitmapWithoutShadow(
|
||||
unbadgedDrawable, context, 0);
|
||||
} else {
|
||||
if (fallbackIconProvider != null) {
|
||||
unbadgedBitmap = fallbackIconProvider.get();
|
||||
}
|
||||
if (unbadgedBitmap == null) {
|
||||
unbadgedBitmap = cache.getDefaultIcon(Process.myUserHandle());
|
||||
}
|
||||
}
|
||||
|
||||
if (!badged) {
|
||||
return unbadgedBitmap;
|
||||
|
|
|
@ -24,8 +24,8 @@ import android.content.Intent;
|
|||
import android.content.IntentFilter;
|
||||
import android.content.pm.LauncherActivityInfo;
|
||||
import android.content.pm.PackageInstaller;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Process;
|
||||
import android.os.SystemClock;
|
||||
import android.os.Trace;
|
||||
|
@ -66,6 +66,7 @@ import com.android.launcher3.util.LooperIdleLock;
|
|||
import com.android.launcher3.util.ManagedProfileHeuristic;
|
||||
import com.android.launcher3.util.MultiHashMap;
|
||||
import com.android.launcher3.util.PackageManagerHelper;
|
||||
import com.android.launcher3.util.Provider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -459,8 +460,18 @@ public class LoaderTask implements Runnable {
|
|||
continue;
|
||||
}
|
||||
info = new ShortcutInfo(pinnedShortcut, context);
|
||||
final ShortcutInfo finalInfo = info;
|
||||
Provider<Bitmap> fallbackIconProvider = new Provider<Bitmap>() {
|
||||
@Override
|
||||
public Bitmap get() {
|
||||
// If the pinned deep shortcut is no longer published,
|
||||
// use the last saved icon instead of the default.
|
||||
return c.loadIcon(finalInfo);
|
||||
}
|
||||
};
|
||||
info.iconBitmap = LauncherIcons
|
||||
.createShortcutIcon(pinnedShortcut, context);
|
||||
.createShortcutIcon(pinnedShortcut, context,
|
||||
true /* badged */, fallbackIconProvider);
|
||||
if (pmHelper.isAppSuspended(
|
||||
pinnedShortcut.getPackage(), info.user)) {
|
||||
info.isDisabled |= ShortcutInfo.FLAG_DISABLED_SUSPENDED;
|
||||
|
|
Loading…
Reference in New Issue