OSDN Git Service

Gracefully ignore items that don't support notifications
authorTony Wickham <twickham@google.com>
Thu, 2 Feb 2017 21:58:33 +0000 (13:58 -0800)
committerTony Wickham <twickham@google.com>
Thu, 2 Feb 2017 23:37:18 +0000 (15:37 -0800)
PackageUserKey is only meant to be used for items that support
notifications, so when trying to update it for an item that
doesn't, we don't use it to check if the item has notifications.

This fixes a crash that happens when trying to update notifications
for a legacy shortcut, as such a shortcut doesn't have a component
on its intent, which we were trying to use to populate PackageUserKey.

Bug: 34842278
Change-Id: I8c69ccebbf9d93505d5b29ecd25d76c65610ddc4

src/com/android/launcher3/Workspace.java
src/com/android/launcher3/allapps/AllAppsContainerView.java
src/com/android/launcher3/util/PackageUserKey.java

index d2008a6..9819418 100644 (file)
@@ -3987,8 +3987,8 @@ public class Workspace extends PagedView
         mapOverItems(MAP_RECURSE, new ItemOperator() {
             @Override
             public boolean evaluate(ItemInfo info, View v) {
-                if (info instanceof ShortcutInfo && v instanceof BubbleTextView) {
-                    packageUserKey.updateFromItemInfo(info);
+                if (info instanceof ShortcutInfo && v instanceof BubbleTextView
+                        && packageUserKey.updateFromItemInfo(info)) {
                     if (updatedBadges.contains(packageUserKey)) {
                         ((BubbleTextView) v).applyBadgeState(info);
                     }
index ec1fa34..54d0bbe 100644 (file)
@@ -478,8 +478,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
     public void updateIconBadges(Set<PackageUserKey> updatedBadges) {
         final PackageUserKey packageUserKey = new PackageUserKey(null, null);
         for (AlphabeticalAppsList.AdapterItem app : mApps.getAdapterItems()) {
-            if (app.appInfo != null) {
-                packageUserKey.updateFromItemInfo(app.appInfo);
+            if (app.appInfo != null && packageUserKey.updateFromItemInfo(app.appInfo)) {
                 if (updatedBadges.contains(packageUserKey)) {
                     mAdapter.notifyItemChanged(app.position);
                 }
index d08b0e9..3fb2401 100644 (file)
@@ -4,6 +4,7 @@ import android.os.UserHandle;
 import android.service.notification.StatusBarNotification;
 
 import com.android.launcher3.ItemInfo;
+import com.android.launcher3.shortcuts.DeepShortcutManager;
 
 import java.util.Arrays;
 
@@ -32,9 +33,16 @@ public class PackageUserKey {
         mHashCode = Arrays.hashCode(new Object[] {packageName, user});
     }
 
-    /** This should only be called to avoid new object creations in a loop. */
-    public void updateFromItemInfo(ItemInfo info) {
-        update(info.getTargetComponent().getPackageName(), info.user);
+    /**
+     * This should only be called to avoid new object creations in a loop.
+     * @return Whether this PackageUserKey was successfully updated - it shouldn't be used if not.
+     */
+    public boolean updateFromItemInfo(ItemInfo info) {
+        if (DeepShortcutManager.supportsShortcuts(info)) {
+            update(info.getTargetComponent().getPackageName(), info.user);
+            return true;
+        }
+        return false;
     }
 
     @Override