From 514870f71c2c5e6a6d1a3d4cc2f01c3cc0a592b9 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Sun, 7 Jan 2024 15:51:16 +0200 Subject: [PATCH] Filter exceptions reporting via ACRA --- app/build.gradle | 2 ++ .../kotatsu/core/ErrorReportingAdmin.kt | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 app/src/main/kotlin/org/koitharu/kotatsu/core/ErrorReportingAdmin.kt diff --git a/app/build.gradle b/app/build.gradle index 6ebe8f691..b83b9b333 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -138,6 +138,8 @@ dependencies { implementation 'ch.acra:acra-http:5.11.3' implementation 'ch.acra:acra-dialog:5.11.3' + compileOnly 'com.google.auto.service:auto-service-annotations:1.1.1' + ksp 'dev.zacsweers.autoservice:auto-service-ksp:1.1.0' debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12' diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ErrorReportingAdmin.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ErrorReportingAdmin.kt new file mode 100644 index 000000000..e088254f8 --- /dev/null +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ErrorReportingAdmin.kt @@ -0,0 +1,24 @@ +package org.koitharu.kotatsu.core + +import android.content.Context +import com.google.auto.service.AutoService +import org.acra.builder.ReportBuilder +import org.acra.config.CoreConfiguration +import org.acra.config.ReportingAdministrator + +@AutoService(ReportingAdministrator::class) +class ErrorReportingAdmin : ReportingAdministrator { + + override fun shouldStartCollecting( + context: Context, + config: CoreConfiguration, + reportBuilder: ReportBuilder + ): Boolean { + return reportBuilder.exception?.isDeadOs() != true + } + + private fun Throwable.isDeadOs(): Boolean { + val className = javaClass.simpleName + return className == "DeadSystemException" || className == "DeadSystemRuntimeException" || cause?.isDeadOs() == true + } +}