From 34ab6df4355d8b82b9ed021664d56a39f3a9b860 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Thu, 6 Jul 2017 06:16:01 -0700 Subject: [PATCH] Fixing legacy shortcuts which only specify packageName in the intent dont get restored on apk install. For various model update task, we only use targetComponent (unlike loader where we all check packageName for legacy shortcuts). This causes various shortcuts which only specity packageName in the intent to get skipped during the check. Instead creating a pseudo component for these shortcuts similar to IconCache Bug: 62944669 Change-Id: I0aa0a4c15ef3ad88dc6cdd579a76315fb2ff780b --- src/com/android/launcher3/IconCache.java | 2 +- src/com/android/launcher3/ItemInfo.java | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java index 4b71ba01d2..3bcd7afb46 100644 --- a/src/com/android/launcher3/IconCache.java +++ b/src/com/android/launcher3/IconCache.java @@ -68,7 +68,7 @@ public class IconCache { private static final int INITIAL_ICON_CACHE_CAPACITY = 50; // Empty class name is used for storing package default entry. - private static final String EMPTY_CLASS_NAME = "."; + public static final String EMPTY_CLASS_NAME = "."; private static final boolean DEBUG = false; private static final boolean DEBUG_IGNORE_CACHE = false; diff --git a/src/com/android/launcher3/ItemInfo.java b/src/com/android/launcher3/ItemInfo.java index 11c5309f22..c5be096a27 100644 --- a/src/com/android/launcher3/ItemInfo.java +++ b/src/com/android/launcher3/ItemInfo.java @@ -137,7 +137,18 @@ public class ItemInfo { } public ComponentName getTargetComponent() { - return getIntent() == null ? null : getIntent().getComponent(); + Intent intent = getIntent(); + if (intent == null) { + return null; + } + ComponentName cn = intent.getComponent(); + if (itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT && cn == null) { + // Legacy shortcuts may not have a componentName but just a packageName. In that case + // create a dummy componentName instead of adding additional check everywhere. + String pkg = intent.getPackage(); + return pkg == null ? null : new ComponentName(pkg, IconCache.EMPTY_CLASS_NAME); + } + return cn; } public void writeToValues(ContentWriter writer) {