From 75de6ce04196959f1e3902a7def68c97a1264b97 Mon Sep 17 00:00:00 2001 From: Kr328 Date: Thu, 23 Apr 2020 00:12:07 +0800 Subject: [PATCH] add full crash logcat report --- .../com/github/kr328/clash/MainApplication.kt | 2 +- .../github/kr328/clash/dump/LogcatDumper.kt | 24 ++++--------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/github/kr328/clash/MainApplication.kt b/app/src/main/java/com/github/kr328/clash/MainApplication.kt index 90e67e1..275cd2b 100644 --- a/app/src/main/java/com/github/kr328/clash/MainApplication.kt +++ b/app/src/main/java/com/github/kr328/clash/MainApplication.kt @@ -42,7 +42,7 @@ class MainApplication : Application() { if (!report.stackTrace.contains("DeadObjectException")) return mutableListOf() - val logcat = LogcatDumper.dump().joinToString(separator = "\n") + val logcat = LogcatDumper.dump() return mutableListOf( ErrorAttachmentLog.attachmentWithText(logcat, "logcat.txt") diff --git a/app/src/main/java/com/github/kr328/clash/dump/LogcatDumper.kt b/app/src/main/java/com/github/kr328/clash/dump/LogcatDumper.kt index 4869262..8db2809 100644 --- a/app/src/main/java/com/github/kr328/clash/dump/LogcatDumper.kt +++ b/app/src/main/java/com/github/kr328/clash/dump/LogcatDumper.kt @@ -1,34 +1,20 @@ package com.github.kr328.clash.dump object LogcatDumper { - fun dump(): List { + fun dump(): String { return try { val process = - Runtime.getRuntime().exec(arrayOf("logcat", "-d", "-s", "-v", "raw", "Go", "AndroidRuntime")) + Runtime.getRuntime().exec(arrayOf("logcat", "-d", "-s", "-v", "raw", "Go", "AndroidRuntime", "DEBUG")) - val result = process.inputStream.bufferedReader().useLines { - var list = mutableListOf() - var capture = false - - it.forEach { line -> - if (line.startsWith("panic")) { - capture = true - - list = mutableListOf() - } - - if (capture) - list.add(line) - } - - list + val result = process.inputStream.use { + it.reader().readText() } process.waitFor() result } catch (e: Exception) { - emptyList() + "" } } }