2022-04-19 18:28:49 -07:00
|
|
|
package co.electriccoin.zcash.ui.screen.support.model
|
|
|
|
|
2022-05-31 09:38:02 -07:00
|
|
|
import android.content.Context
|
|
|
|
import co.electriccoin.zcash.crash.ExceptionPath
|
|
|
|
import co.electriccoin.zcash.crash.ReportedException
|
|
|
|
import co.electriccoin.zcash.crash.android.getExceptionDirectory
|
|
|
|
import co.electriccoin.zcash.crash.new
|
|
|
|
import co.electriccoin.zcash.spackle.io.listFilesSuspend
|
2022-04-19 18:28:49 -07:00
|
|
|
import kotlinx.datetime.Instant
|
2022-05-31 09:38:02 -07:00
|
|
|
import java.io.File
|
2022-04-19 18:28:49 -07:00
|
|
|
|
2023-02-20 08:07:26 -08:00
|
|
|
data class CrashInfo(val exceptionClassName: String, val isUncaught: Boolean, val timestamp: Instant) {
|
2023-12-11 01:20:32 -08:00
|
|
|
fun toSupportString() =
|
|
|
|
buildString {
|
|
|
|
appendLine("Exception")
|
|
|
|
appendLine(" Class name: $exceptionClassName")
|
|
|
|
appendLine(" Is uncaught: $isUncaught")
|
|
|
|
appendLine(" Timestamp: $timestamp")
|
2022-04-19 18:28:49 -07:00
|
|
|
|
2023-12-11 01:20:32 -08:00
|
|
|
// For now, don't include the stacktrace. It'll be too long for the emails we want to generate
|
|
|
|
}
|
2022-04-19 18:28:49 -07:00
|
|
|
|
2022-05-31 09:38:02 -07:00
|
|
|
companion object
|
2022-04-19 18:28:49 -07:00
|
|
|
}
|
|
|
|
|
2023-12-11 01:20:32 -08:00
|
|
|
fun List<CrashInfo>.toCrashSupportString() =
|
|
|
|
buildString {
|
|
|
|
// Using the header "Exceptions" instead of "Crashes" to reduce risk of alarming users
|
|
|
|
appendLine("Exceptions:")
|
|
|
|
this@toCrashSupportString.forEach {
|
|
|
|
appendLine(it.toSupportString())
|
|
|
|
}
|
2022-04-19 18:28:49 -07:00
|
|
|
}
|
2022-05-31 09:38:02 -07:00
|
|
|
|
|
|
|
// If you change this, be sure to update the test case under /docs/testing/manual_testing/Contact Support.md
|
|
|
|
private const val MAX_EXCEPTIONS_TO_REPORT = 5
|
|
|
|
|
|
|
|
suspend fun CrashInfo.Companion.all(context: Context): List<CrashInfo> {
|
|
|
|
val exceptionDirectory = ExceptionPath.getExceptionDirectory(context) ?: return emptyList()
|
|
|
|
val filesList: List<File> = exceptionDirectory.listFilesSuspend().toList()
|
|
|
|
return filesList
|
|
|
|
.mapNotNull {
|
|
|
|
ReportedException.new(it)
|
|
|
|
}.sortedBy { it.time }
|
|
|
|
.reversed()
|
|
|
|
.take(MAX_EXCEPTIONS_TO_REPORT)
|
|
|
|
.map { CrashInfo(it.exceptionClassName, it.isUncaught, it.time) }
|
|
|
|
}
|