2014-10-22 16:38:44 +00:00
|
|
|
package eu.siacs.conversations.utils;
|
|
|
|
|
2015-07-20 12:26:29 +00:00
|
|
|
import android.content.Context;
|
2020-05-08 17:34:20 +00:00
|
|
|
import android.support.annotation.NonNull;
|
2015-07-20 12:26:29 +00:00
|
|
|
|
2014-10-22 16:38:44 +00:00
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.io.StringWriter;
|
|
|
|
import java.io.Writer;
|
|
|
|
import java.lang.Thread.UncaughtExceptionHandler;
|
|
|
|
|
2020-05-08 17:34:20 +00:00
|
|
|
import eu.siacs.conversations.services.NotificationService;
|
|
|
|
|
2014-10-22 16:38:44 +00:00
|
|
|
public class ExceptionHandler implements UncaughtExceptionHandler {
|
|
|
|
|
2020-05-08 17:34:20 +00:00
|
|
|
private final UncaughtExceptionHandler defaultHandler;
|
|
|
|
private final Context context;
|
2014-10-22 16:38:44 +00:00
|
|
|
|
2020-05-08 17:34:20 +00:00
|
|
|
ExceptionHandler(final Context context) {
|
2014-10-22 16:38:44 +00:00
|
|
|
this.context = context;
|
|
|
|
this.defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-05-08 17:34:20 +00:00
|
|
|
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();
|
2014-10-22 16:38:44 +00:00
|
|
|
printWriter.close();
|
2016-05-21 06:54:29 +00:00
|
|
|
ExceptionHelper.writeToStacktraceFile(context, stacktrace);
|
2020-05-08 17:34:20 +00:00
|
|
|
this.defaultHandler.uncaughtException(thread, throwable);
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|