From a81b4a0dbe0ab43263f19fb7071e49428bdf400c Mon Sep 17 00:00:00 2001
From: Mady Mellor <madym@google.com>
Date: Fri, 15 Sep 2023 10:36:45 -0700
Subject: [PATCH] Catch an exception when loading a bubble icon

If an app gives us a shortcut whose icon can't be looked up, an
exception is thrown. This CL modifies the code to catch an
exception and default to the app icon instead of the shortcut
icon.

Test: manual - modify icon loading code to throw an exception
             - create a bubble
	     => observe there is no crash and the bubble uses
	        the app icon instead
Bug: 300073572

Change-Id: Iedc9825c42ec2f50bb9939e34acd9f1960dd229e
(cherry picked from commit bf53369482dbb4df3b532b1cbe0287a04dacfd61)
---
 .../wm/shell/bubbles/BubbleViewInfoTask.java       | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTask.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTask.java
index 66e69300f45f..39e3180ffe2a 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTask.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTask.java
@@ -257,8 +257,16 @@ public class BubbleViewInfoTask extends AsyncTask<Void, Void, BubbleViewInfoTask
             return false;
         }
 
-        // Badged bubble image
-        Drawable bubbleDrawable = iconFactory.getBubbleDrawable(c, info.shortcutInfo, b.getIcon());
+        Drawable bubbleDrawable = null;
+        try {
+            // Badged bubble image
+            bubbleDrawable = iconFactory.getBubbleDrawable(c, info.shortcutInfo,
+                    b.getIcon());
+        } catch (Exception e) {
+            // If we can't create the icon we'll default to the app icon
+            Log.w(TAG, "Exception creating icon for the bubble: " + b.getKey());
+        }
+
         if (bubbleDrawable == null) {
             // Default to app icon
             bubbleDrawable = appIcon;
@@ -268,7 +276,7 @@ public class BubbleViewInfoTask extends AsyncTask<Void, Void, BubbleViewInfoTask
                 b.isImportantConversation());
         info.badgeBitmap = badgeBitmapInfo.icon;
         // Raw badge bitmap never includes the important conversation ring
-        info.rawBadgeBitmap = b.isImportantConversation() // is this needed for bar?
+        info.rawBadgeBitmap = b.isImportantConversation()
                 ? iconFactory.getBadgeBitmap(badgedIcon, false).icon
                 : badgeBitmapInfo.icon;
 
-- 
GitLab