From 29f2e4c0e63ac40bc06bc6c80b9e1f4147c39cf1 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 10 Dec 2018 10:53:46 +0100 Subject: [PATCH] Let unexpected error write crash log --- app/src/main/java/eu/faircode/email/ApplicationEx.java | 9 +++++---- app/src/main/java/eu/faircode/email/Helper.java | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ApplicationEx.java b/app/src/main/java/eu/faircode/email/ApplicationEx.java index e9fc8cdb1b..5975005a8d 100644 --- a/app/src/main/java/eu/faircode/email/ApplicationEx.java +++ b/app/src/main/java/eu/faircode/email/ApplicationEx.java @@ -47,7 +47,7 @@ public class ApplicationEx extends Application { public void uncaughtException(Thread thread, Throwable ex) { if (ownFault(ex)) { Log.e(Helper.TAG, ex + "\r\n" + Log.getStackTraceString(ex)); - writeCrashLog(ex); + writeCrashLog(ApplicationEx.this, ex); if (prev != null) prev.uncaughtException(thread, ex); @@ -110,17 +110,18 @@ public class ApplicationEx extends Application { return true; ex = ex.getCause(); } + return false; } - private void writeCrashLog(Throwable ex) { - File file = new File(getCacheDir(), "crash.log"); + static void writeCrashLog(Context context, Throwable ex) { + File file = new File(context.getCacheDir(), "crash.log"); Log.w(Helper.TAG, "Writing exception to " + file); FileWriter out = null; try { out = new FileWriter(file); - out.write(ex.toString() + "\n" + Log.getStackTraceString(ex)); + out.write(ex + "\r\n" + Log.getStackTraceString(ex)); } catch (IOException e) { Log.e(Helper.TAG, e + "\n" + Log.getStackTraceString(e)); } finally { diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index b88d446058..f16ea30f2a 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -189,7 +189,7 @@ public class Helper { } static void unexpectedError(final Context context, final LifecycleOwner owner, final Throwable ex) { - Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); + ApplicationEx.writeCrashLog(context, ex); if (owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) new DialogBuilderLifecycle(context, owner)