mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
enhance(crash/log): Dump crash exception
This commit is contained in:
parent
b891cd26e2
commit
8b5c065d8a
2 changed files with 5 additions and 2 deletions
|
@ -48,7 +48,7 @@ class CrashActivity : AppCompatActivity() {
|
|||
acceptText = stringResource(MR.strings.dump_crash_logs),
|
||||
onAcceptClick = {
|
||||
scope.launch {
|
||||
CrashLogUtil(context).dumpLogs()
|
||||
CrashLogUtil(context).dumpLogs(exception)
|
||||
}
|
||||
},
|
||||
canAccept = true,
|
||||
|
|
|
@ -27,12 +27,15 @@ class CrashLogUtil(private val context: Context) {
|
|||
setSmallIcon(R.drawable.ic_yokai)
|
||||
}
|
||||
|
||||
suspend fun dumpLogs() = withNonCancellableContext {
|
||||
suspend fun dumpLogs(exception: Throwable? = null) = withNonCancellableContext {
|
||||
try {
|
||||
val file = context.createFileInCacheDir("yokai_crash_logs.txt")
|
||||
file.appendText(getDebugInfo() + "\n\n")
|
||||
file.appendText(getExtensionsInfo() + "\n\n")
|
||||
exception?.let { file.appendText("$it\n\n") }
|
||||
|
||||
Runtime.getRuntime().exec("logcat *:E -d -f ${file.absolutePath}")
|
||||
|
||||
showNotification(file.getUriCompat(context))
|
||||
} catch (e: IOException) {
|
||||
withUIContext { context.toast("Failed to get logs") }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue