From 3e7ca96f43b69236411e346e08a810f35f93fdd8 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 7 Dec 2018 15:35:03 +0100 Subject: [PATCH] Write logcat on crash --- .../java/eu/faircode/email/ApplicationEx.java | 41 ++++++++++++++++++- .../main/java/eu/faircode/email/Helper.java | 2 +- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ApplicationEx.java b/app/src/main/java/eu/faircode/email/ApplicationEx.java index 027184986d..eaeda7ff07 100644 --- a/app/src/main/java/eu/faircode/email/ApplicationEx.java +++ b/app/src/main/java/eu/faircode/email/ApplicationEx.java @@ -28,9 +28,15 @@ import android.os.DeadSystemException; import android.os.RemoteException; import android.util.Log; +import java.io.BufferedOutputStream; +import java.io.BufferedReader; import java.io.File; +import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.util.Date; public class ApplicationEx extends Application { private Thread.UncaughtExceptionHandler prev = null; @@ -119,7 +125,40 @@ public class ApplicationEx extends Application { FileWriter out = null; try { out = new FileWriter(file); - out.write(ex.toString() + "\n" + Log.getStackTraceString(ex)); + out.write(new Date() + "\r\n"); + out.write(ex.toString() + "\r\n"); + out.write(Log.getStackTraceString(ex) + "\r\n"); + + out.write("\r\n"); + + Process proc = null; + BufferedReader br = null; + OutputStream os = null; + try { + os = new BufferedOutputStream(new FileOutputStream(file)); + + String[] cmd = new String[]{"logcat", + "-d", + "-v", "threadtime", + //"-t", "1000", + Helper.TAG + ":I"}; + proc = Runtime.getRuntime().exec(cmd); + br = new BufferedReader(new InputStreamReader(proc.getInputStream())); + + String line; + while ((line = br.readLine()) != null) + out.write(line + "\r\n"); + } catch (Throwable exex) { + out.write(exex.toString()); + } finally { + if (os != null) + os.close(); + if (br != null) + br.close(); + if (proc != null) + proc.destroy(); + } + } 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 18a63d09e5..fcefca8e59 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -212,7 +212,7 @@ public class Helper { draft.folder = drafts.id; draft.msgid = EntityMessage.generateMessageId(); draft.to = new Address[]{Helper.myAddress()}; - draft.subject = context.getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME + " crash log"; + draft.subject = context.getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME + " unexpected error"; draft.content = true; draft.received = new Date().getTime(); draft.setContactInfo(context);