enhance(crash/log): Dump crash exception

This commit is contained in:
Ahmad Ansori Palembani 2024-06-27 12:23:30 +07:00
parent b891cd26e2
commit 8b5c065d8a
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
2 changed files with 5 additions and 2 deletions

View file

@ -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,

View file

@ -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") }