From 1d8b7cba318b0c9e8472ffdfd2ca5f5f6a08d655 Mon Sep 17 00:00:00 2001 From: Sihua Ma Date: Tue, 2 Aug 2022 10:49:37 -0700 Subject: [PATCH] Showing Toast message when the target package is null for the disabled shortcut The shortcut for a certain set of apps could have their component names set to null. In this case, if we still need the package name for the shortcut, we should use the package name from the intent, which is accomplished in getTargetPackage. Additionally, if the target package is still null, we are falling back to showing the Toast messages only. Fix: 239685630 Test: Verified that the crash no longer happens after clicking on grayed out shortcuts Change-Id: I4de68ea1a227032e16e5c00407f75159a7aba30f --- .../android/launcher3/model/data/ItemInfoWithIcon.java | 7 +++---- src/com/android/launcher3/touch/ItemClickHandler.java | 8 +++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/com/android/launcher3/model/data/ItemInfoWithIcon.java b/src/com/android/launcher3/model/data/ItemInfoWithIcon.java index 76a0c4d64c..e5fb015f2e 100644 --- a/src/com/android/launcher3/model/data/ItemInfoWithIcon.java +++ b/src/com/android/launcher3/model/data/ItemInfoWithIcon.java @@ -16,7 +16,6 @@ package com.android.launcher3.model.data; -import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -220,10 +219,10 @@ public abstract class ItemInfoWithIcon extends ItemInfo { /** Creates an intent to that launches the app store at this app's page. */ @Nullable public Intent getMarketIntent(Context context) { - ComponentName componentName = getTargetComponent(); + String targetPackage = getTargetPackage(); - return componentName != null - ? new PackageManagerHelper(context).getMarketIntent(componentName.getPackageName()) + return targetPackage != null + ? new PackageManagerHelper(context).getMarketIntent(targetPackage) : null; } diff --git a/src/com/android/launcher3/touch/ItemClickHandler.java b/src/com/android/launcher3/touch/ItemClickHandler.java index e95a787cfd..32c5aa529f 100644 --- a/src/com/android/launcher3/touch/ItemClickHandler.java +++ b/src/com/android/launcher3/touch/ItemClickHandler.java @@ -248,13 +248,19 @@ public class ItemClickHandler { final Launcher launcher = Launcher.getLauncher(context); if (shortcut.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT && shortcut.isDisabledVersionLower()) { + final Intent marketIntent = shortcut.getMarketIntent(context); + // No market intent means no target package for the shortcut, which should be an + // issue. Falling back to showing toast messages. + if (marketIntent == null) { + return false; + } new AlertDialog.Builder(context) .setTitle(R.string.dialog_update_title) .setMessage(R.string.dialog_update_message) .setPositiveButton(R.string.dialog_update, (d, i) -> { // Direct the user to the play store to update the app - context.startActivity(shortcut.getMarketIntent(context)); + context.startActivity(marketIntent); }) .setNeutralButton(R.string.dialog_remove, (d, i) -> { // Remove the icon if launcher is successfully initialized