From 964dc2a76d4b7558a873dc4a209c2aec9b941be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Fri, 27 May 2022 12:15:09 +0200 Subject: [PATCH] Catch RuntimeException thrown by NotificationManager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../nextcloud/talk/controllers/ChatController.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index b1a9e50fd..5fc0aa2a2 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -1709,14 +1709,19 @@ class ChatController(args: Bundle) : binding.messageInputView.findViewById(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) + } } } }