From bd0234ba4d71d08142cafbf975db28f5891a5fb1 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 8 May 2020 19:34:20 +0200 Subject: [PATCH] dismiss incoming call notification on crash. fixes #3701 --- .../services/NotificationService.java | 9 ++++++++ .../conversations/utils/ExceptionHandler.java | 22 +++++++++++-------- .../conversations/utils/ExceptionHelper.java | 9 ++++---- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index 17448fac3..bd3df024a 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -426,6 +426,15 @@ public class NotificationService { cancel(INCOMING_CALL_NOTIFICATION_ID); } + public static void cancelIncomingCallNotification(final Context context) { + final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); + try { + notificationManager.cancel(INCOMING_CALL_NOTIFICATION_ID); + } catch (RuntimeException e) { + Log.d(Config.LOGTAG, "unable to cancel incoming call notification after crash", e); + } + } + private void pushNow(final Message message) { mXmppConnectionService.updateUnreadCountBadge(); if (!notify(message)) { diff --git a/src/main/java/eu/siacs/conversations/utils/ExceptionHandler.java b/src/main/java/eu/siacs/conversations/utils/ExceptionHandler.java index b8a0fa511..68672156b 100644 --- a/src/main/java/eu/siacs/conversations/utils/ExceptionHandler.java +++ b/src/main/java/eu/siacs/conversations/utils/ExceptionHandler.java @@ -1,31 +1,35 @@ package eu.siacs.conversations.utils; import android.content.Context; +import android.support.annotation.NonNull; import java.io.PrintWriter; import java.io.StringWriter; import java.io.Writer; import java.lang.Thread.UncaughtExceptionHandler; +import eu.siacs.conversations.services.NotificationService; + public class ExceptionHandler implements UncaughtExceptionHandler { - private UncaughtExceptionHandler defaultHandler; - private Context context; + private final UncaughtExceptionHandler defaultHandler; + private final Context context; - public ExceptionHandler(Context context) { + ExceptionHandler(final Context context) { this.context = context; this.defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); } @Override - public void uncaughtException(Thread thread, Throwable ex) { - Writer result = new StringWriter(); - PrintWriter printWriter = new PrintWriter(result); - ex.printStackTrace(printWriter); - String stacktrace = result.toString(); + public void uncaughtException(@NonNull Thread thread, final Throwable throwable) { + NotificationService.cancelIncomingCallNotification(context); + final Writer stringWriter = new StringWriter(); + final PrintWriter printWriter = new PrintWriter(stringWriter); + throwable.printStackTrace(printWriter); + final String stacktrace = stringWriter.toString(); printWriter.close(); ExceptionHelper.writeToStacktraceFile(context, stacktrace); - this.defaultHandler.uncaughtException(thread, ex); + this.defaultHandler.uncaughtException(thread, throwable); } } diff --git a/src/main/java/eu/siacs/conversations/utils/ExceptionHelper.java b/src/main/java/eu/siacs/conversations/utils/ExceptionHelper.java index e9f3bcb24..ca515e8fa 100644 --- a/src/main/java/eu/siacs/conversations/utils/ExceptionHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/ExceptionHelper.java @@ -1,12 +1,12 @@ package eu.siacs.conversations.utils; -import android.support.v7.app.AlertDialog; import android.content.Context; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.Signature; import android.preference.PreferenceManager; +import android.support.v7.app.AlertDialog; import android.util.Log; import java.io.BufferedReader; @@ -16,7 +16,6 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.List; import java.util.Locale; import eu.siacs.conversations.Config; @@ -33,10 +32,10 @@ public class ExceptionHelper { private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); public static void init(Context context) { - if (!(Thread.getDefaultUncaughtExceptionHandler() instanceof ExceptionHandler)) { - Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler( - context)); + if (Thread.getDefaultUncaughtExceptionHandler() instanceof ExceptionHandler) { + return; } + Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(context)); } public static boolean checkForCrash(XmppActivity activity) {