diff options
author | Jon Miranda <jonmiranda@google.com> | 2019-10-25 14:07:36 -0700 |
---|---|---|
committer | Jonathan Miranda <jonmiranda@google.com> | 2019-11-08 23:27:26 +0000 |
commit | 47835458089c656139246f13dbcd5baedfec3c16 (patch) | |
tree | 8d946a6a7150e5d0cf7a8b0ff927a52f9cd87de3 | |
parent | a9012ea7178df79c4ed1e728c7fbda160fffb1bb (diff) | |
download | android_packages_apps_Trebuchet-47835458089c656139246f13dbcd5baedfec3c16.tar.gz android_packages_apps_Trebuchet-47835458089c656139246f13dbcd5baedfec3c16.tar.bz2 android_packages_apps_Trebuchet-47835458089c656139246f13dbcd5baedfec3c16.zip |
[DO NOT MERGE] Fix NPE caused by an install flow where we decode the LauncherActivityInfo
but we don't fill in the data Intent.
Adding do not merge tag here, as we want the fix to have soak time in QPR2 ASAP.
The fix for master will be added to master branch next time we drop code from
ub-launcher3-master.
Bug: 143190879
Change-Id: I8f774203b99f022b2cf1708de6d8fe2398b332ce
(cherry picked from commit 4459e3f6f91fdd917850f9d37c1a4a734fa55ed7)
-rw-r--r-- | src/com/android/launcher3/InstallShortcutReceiver.java | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/com/android/launcher3/InstallShortcutReceiver.java b/src/com/android/launcher3/InstallShortcutReceiver.java index f19c60268..89ec2a564 100644 --- a/src/com/android/launcher3/InstallShortcutReceiver.java +++ b/src/com/android/launcher3/InstallShortcutReceiver.java @@ -39,6 +39,9 @@ import android.util.Base64; import android.util.Log; import android.util.Pair; +import androidx.annotation.Nullable; +import androidx.annotation.WorkerThread; + import com.android.launcher3.compat.LauncherAppsCompat; import com.android.launcher3.compat.UserManagerCompat; import com.android.launcher3.icons.BitmapInfo; @@ -250,11 +253,6 @@ public class InstallShortcutReceiver extends BroadcastReceiver { return info == null ? null : (WorkspaceItemInfo) info.getItemInfo().first; } - public static WorkspaceItemInfo fromActivityInfo(LauncherActivityInfo info, Context context) { - return (WorkspaceItemInfo) - new PendingInstallShortcutInfo(info, context).getItemInfo().first; - } - public static void queueShortcut(ShortcutInfo info, Context context) { queuePendingShortcutInfo(new PendingInstallShortcutInfo(info, context), context); } @@ -330,10 +328,10 @@ public class InstallShortcutReceiver extends BroadcastReceiver { private static class PendingInstallShortcutInfo { final boolean isActivity; - final ShortcutInfo shortcutInfo; - final AppWidgetProviderInfo providerInfo; + @Nullable final ShortcutInfo shortcutInfo; + @Nullable final AppWidgetProviderInfo providerInfo; - final Intent data; + @Nullable final Intent data; final Context mContext; final Intent launchIntent; final String label; @@ -363,7 +361,12 @@ public class InstallShortcutReceiver extends BroadcastReceiver { shortcutInfo = null; providerInfo = null; - data = null; + String packageName = info.getComponentName().getPackageName(); + data = new Intent(); + data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent().setComponent( + new ComponentName(packageName, "")).setPackage(packageName)); + data.putExtra(Intent.EXTRA_SHORTCUT_NAME, info.getLabel()); + user = info.getUser(); mContext = context; @@ -457,9 +460,10 @@ public class InstallShortcutReceiver extends BroadcastReceiver { // This name is only used for comparisons and notifications, so fall back to activity // name if not supplied String name = ensureValidName(mContext, launchIntent, label).toString(); - Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON); - Intent.ShortcutIconResource iconResource = - data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); + Bitmap icon = data == null ? null + : data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON); + Intent.ShortcutIconResource iconResource = data == null ? null + : data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); // Only encode the parameters which are supported by the API. JSONStringer json = new JSONStringer() @@ -469,9 +473,11 @@ public class InstallShortcutReceiver extends BroadcastReceiver { .key(APP_SHORTCUT_TYPE_KEY).value(isActivity); if (icon != null) { byte[] iconByteArray = GraphicsUtils.flattenBitmap(icon); - json = json.key(ICON_KEY).value( - Base64.encodeToString( - iconByteArray, 0, iconByteArray.length, Base64.DEFAULT)); + if (iconByteArray != null) { + json = json.key(ICON_KEY).value( + Base64.encodeToString( + iconByteArray, 0, iconByteArray.length, Base64.DEFAULT)); + } } if (iconResource != null) { json = json.key(ICON_RESOURCE_NAME_KEY).value(iconResource.resourceName); |