Browse Source

Catch RuntimeException thrown by NotificationManager

In case anything goes wront during calling
'NotificationManger#activeNotification' an 'RuntimeException' will be
thrown. This results in a crash if not catched.

Resolves: #2078

Signed-off-by: Tim Krüger <t@timkrueger.me>
Tim Krüger 2 years ago
parent
commit
964dc2a76d
1 changed files with 10 additions and 5 deletions
  1. 10 5
      app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt

+ 10 - 5
app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt

@@ -1709,14 +1709,19 @@ class ChatController(args: Bundle) :
         binding.messageInputView.findViewById<ImageButton>(R.id.attachmentButton)?.visibility = View.VISIBLE
     }
 
+    @Suppress("Detekt.TooGenericExceptionCaught")
     private fun cancelNotificationsForCurrentConversation() {
         if (conversationUser != null) {
             if (!TextUtils.isEmpty(roomToken)) {
-                NotificationUtils.cancelExistingNotificationsForRoom(
-                    applicationContext,
-                    conversationUser,
-                    roomToken!!
-                )
+                try {
+                    NotificationUtils.cancelExistingNotificationsForRoom(
+                        applicationContext,
+                        conversationUser,
+                        roomToken!!
+                    )
+                } catch (e: RuntimeException) {
+                    Log.w(TAG, "Cancel notifications for current conversation results with an error.", e)
+                }
             }
         }
     }