diff options
3 files changed, 54 insertions, 8 deletions
diff --git a/go/src/com/android/launcher3/shortcuts/DeepShortcutManager.java b/go/src/com/android/launcher3/shortcuts/DeepShortcutManager.java index 1e449108d..73adaa14f 100644 --- a/go/src/com/android/launcher3/shortcuts/DeepShortcutManager.java +++ b/go/src/com/android/launcher3/shortcuts/DeepShortcutManager.java @@ -25,6 +25,7 @@ import android.os.Bundle; import android.os.UserHandle; import com.android.launcher3.ItemInfo; +import com.android.launcher3.notification.NotificationKeyData; import java.util.Collections; import java.util.List; @@ -52,6 +53,11 @@ public class DeepShortcutManager { return false; } + public static boolean supportsNotificationDots( + ItemInfo info, List<NotificationKeyData> notifications) { + return false; + } + public boolean wasLastCallSuccess() { return false; } diff --git a/src/com/android/launcher3/popup/PopupDataProvider.java b/src/com/android/launcher3/popup/PopupDataProvider.java index 2d301ac00..dd496b02b 100644 --- a/src/com/android/launcher3/popup/PopupDataProvider.java +++ b/src/com/android/launcher3/popup/PopupDataProvider.java @@ -40,6 +40,7 @@ import java.util.Map; import java.util.function.Predicate; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; /** * Provides data for the popup menu that appears after long-clicking on apps. @@ -167,12 +168,14 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan return count == null ? 0 : count; } - public DotInfo getDotInfoForItem(ItemInfo info) { - if (!DeepShortcutManager.supportsShortcuts(info)) { + public @Nullable DotInfo getDotInfoForItem(@NonNull ItemInfo info) { + DotInfo dotInfo = mPackageUserToDotInfos.get(PackageUserKey.fromItemInfo(info)); + List<NotificationKeyData> notifications = + dotInfo == null ? Collections.EMPTY_LIST : dotInfo.getNotificationKeys(); + if (!DeepShortcutManager.supportsNotificationDots(info, notifications)) { return null; } - - return mPackageUserToDotInfos.get(PackageUserKey.fromItemInfo(info)); + return dotInfo; } public @NonNull List<NotificationKeyData> getNotificationKeysForItem(ItemInfo info) { diff --git a/src_shortcuts_overrides/com/android/launcher3/shortcuts/DeepShortcutManager.java b/src_shortcuts_overrides/com/android/launcher3/shortcuts/DeepShortcutManager.java index 6b6f70d7b..f42bafe5e 100644 --- a/src_shortcuts_overrides/com/android/launcher3/shortcuts/DeepShortcutManager.java +++ b/src_shortcuts_overrides/com/android/launcher3/shortcuts/DeepShortcutManager.java @@ -30,6 +30,7 @@ import android.util.Log; import com.android.launcher3.ItemInfo; import com.android.launcher3.LauncherSettings; import com.android.launcher3.WorkspaceItemInfo; +import com.android.launcher3.notification.NotificationKeyData; import java.util.ArrayList; import java.util.Collections; @@ -64,10 +65,40 @@ public class DeepShortcutManager { } public static boolean supportsShortcuts(ItemInfo info) { - boolean isItemPromise = info instanceof WorkspaceItemInfo - && ((WorkspaceItemInfo) info).hasPromiseIconUi(); - return info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION - && !info.isDisabled() && !isItemPromise; + return isActive(info) && isApp(info); + } + + public static boolean supportsNotificationDots( + ItemInfo info, List<NotificationKeyData> notifications) { + if (!isActive(info)) { + return false; + } + return isApp(info) || (isPinnedShortcut(info) + && shouldShowNotificationDotForPinnedShortcut(info, notifications)); + } + + private static boolean isApp(ItemInfo info) { + return info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; + } + + private static boolean isPinnedShortcut(ItemInfo info) { + return info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT + && info.container != ItemInfo.NO_ID + && info instanceof WorkspaceItemInfo; + } + + private static boolean shouldShowNotificationDotForPinnedShortcut( + ItemInfo info, List<NotificationKeyData> notifications) { + String shortcutId = ((WorkspaceItemInfo) info).getDeepShortcutId(); + if (shortcutId == null) { + return false; + } + for (NotificationKeyData notification : notifications) { + if (shortcutId.equals(notification.shortcutId)) { + return true; + } + } + return false; } public boolean wasLastCallSuccess() { @@ -183,6 +214,12 @@ public class DeepShortcutManager { return shortcutIds; } + private static boolean isActive(ItemInfo info) { + boolean isLoading = info instanceof WorkspaceItemInfo + && ((WorkspaceItemInfo) info).hasPromiseIconUi(); + return !isLoading && !info.isDisabled(); + } + /** * Query the system server for all the shortcuts matching the given parameters. * If packageName == null, we query for all shortcuts with the passed flags, regardless of app. |