Skip to content

Commit

Permalink
RecorderThread: Always preserve logcat on errors
Browse files Browse the repository at this point in the history
This is more user-friendly since it doesn't require the user to manually
enable debug mode and then try to reproduce the error.

Signed-off-by: Andrew Gunnerson <[email protected]>
  • Loading branch information
chenxiaolong committed Mar 3, 2024
1 parent e5c5ebe commit 8e24977
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions app/src/main/java/com/chiller3/bcr/RecorderThread.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class RecorderThread(
) : Thread(RecorderThread::class.java.simpleName) {
private val tag = "${RecorderThread::class.java.simpleName}/${id}"
private val prefs = Preferences(context)
private val isDebug = prefs.isDebugMode

enum class State {
NOT_STARTED,
Expand Down Expand Up @@ -256,7 +255,16 @@ class RecorderThread(
Log.i(tag, "Recording thread completed")

try {
stopLogcat()?.let { additionalFiles.add(it) }
val logcatOutput = stopLogcat()

// Log files are always kept when an error occurs to avoid the hassle of having the
// user manually enable debug mode and needing to reproduce the problem.
if (prefs.isDebugMode || errorMsg != null) {
additionalFiles.add(logcatOutput)
} else {
Log.d(tag, "No need to preserve logcat")
logcatOutput.toDocumentFile(context).delete()
}
} catch (e: Exception) {
Log.w(tag, "Failed to dump logcat", e)
}
Expand Down Expand Up @@ -305,10 +313,6 @@ class RecorderThread(
}

private fun startLogcat() {
if (!isDebug) {
return
}

assert(!this::logcatProcess.isInitialized) { "logcat already started" }

Log.d(tag, "Starting log file (${BuildConfig.VERSION_NAME})")
Expand All @@ -324,11 +328,7 @@ class RecorderThread(
.start()
}

private fun stopLogcat(): OutputFile? {
if (!isDebug) {
return null
}

private fun stopLogcat(): OutputFile {
assert(this::logcatProcess.isInitialized) { "logcat not started" }

var uri = logcatFile.uri
Expand Down

0 comments on commit 8e24977

Please sign in to comment.