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); 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) { private void pushNow(final Message message) {
mXmppConnectionService.updateUnreadCountBadge(); mXmppConnectionService.updateUnreadCountBadge();
if (!notify(message)) { if (!notify(message)) {

View File

@ -1,31 +1,35 @@
package eu.siacs.conversations.utils; package eu.siacs.conversations.utils;
import android.content.Context; import android.content.Context;
import android.support.annotation.NonNull;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.Writer; import java.io.Writer;
import java.lang.Thread.UncaughtExceptionHandler; import java.lang.Thread.UncaughtExceptionHandler;
import eu.siacs.conversations.services.NotificationService;
public class ExceptionHandler implements UncaughtExceptionHandler { public class ExceptionHandler implements UncaughtExceptionHandler {
private UncaughtExceptionHandler defaultHandler; private final UncaughtExceptionHandler defaultHandler;
private Context context; private final Context context;
public ExceptionHandler(Context context) { ExceptionHandler(final Context context) {
this.context = context; this.context = context;
this.defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); this.defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
} }
@Override @Override
public void uncaughtException(Thread thread, Throwable ex) { public void uncaughtException(@NonNull Thread thread, final Throwable throwable) {
Writer result = new StringWriter(); NotificationService.cancelIncomingCallNotification(context);
PrintWriter printWriter = new PrintWriter(result); final Writer stringWriter = new StringWriter();
ex.printStackTrace(printWriter); final PrintWriter printWriter = new PrintWriter(stringWriter);
String stacktrace = result.toString(); throwable.printStackTrace(printWriter);
final String stacktrace = stringWriter.toString();
printWriter.close(); printWriter.close();
ExceptionHelper.writeToStacktraceFile(context, stacktrace); 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; package eu.siacs.conversations.utils;
import android.support.v7.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.Signature; import android.content.pm.Signature;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v7.app.AlertDialog;
import android.util.Log; import android.util.Log;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -16,7 +16,6 @@ import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import eu.siacs.conversations.Config; 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); private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
public static void init(Context context) { public static void init(Context context) {
if (!(Thread.getDefaultUncaughtExceptionHandler() instanceof ExceptionHandler)) { if (Thread.getDefaultUncaughtExceptionHandler() instanceof ExceptionHandler) {
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler( return;
context));
} }
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(context));
} }
public static boolean checkForCrash(XmppActivity activity) { public static boolean checkForCrash(XmppActivity activity) {