Skip to content

Commit

Permalink
add full crash logcat report
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr328 committed Apr 22, 2020
1 parent 4417a85 commit 75de6ce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
24 changes: 5 additions & 19 deletions app/src/main/java/com/github/kr328/clash/dump/LogcatDumper.kt
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
package com.github.kr328.clash.dump

object LogcatDumper {
fun dump(): List<String> {
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<String>()
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()
""
}
}
}

0 comments on commit 75de6ce

Please sign in to comment.