dismiss incoming call notification on crash. fixes #3701

This commit is contained in:
Daniel Gultsch 2020-05-08 19:34:20 +02:00
parent abfa4eae08
commit bd0234ba4d
3 changed files with 26 additions and 14 deletions

View file

@ -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)) {

View file

@ -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);
}
}

View file

@ -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) {