Add ACRA for crash reports (#180)

This commit is contained in:
Kirill Kamakin
2023-11-11 21:53:04 +01:00
committed by GitHub
parent 7867e2426d
commit 3d0cf8b902
5 changed files with 63 additions and 0 deletions

View File

@@ -1,8 +1,16 @@
package gq.kirmanak.mealient.extensions
import android.app.Activity
import android.app.Application
import android.app.job.JobInfo
import android.content.Context
import android.content.ContextWrapper
import gq.kirmanak.mealient.BuildConfig
import org.acra.config.httpSender
import org.acra.config.scheduler
import org.acra.data.StringFormat
import org.acra.ktx.initAcra
import org.acra.sender.HttpSender
fun Context.findActivity(): Activity? {
var context = this
@@ -12,3 +20,27 @@ fun Context.findActivity(): Activity? {
}
return null
}
internal fun Application.setupCrashReporting() {
val acraHost = BuildConfig.ACRA_HOST.takeUnless { it.isBlank() } ?: return
val acraLogin = BuildConfig.ACRA_LOGIN.takeUnless { it.isBlank() } ?: return
val acraPassword = BuildConfig.ACRA_PASSWORD.takeUnless { it.isBlank() } ?: return
initAcra {
reportFormat = StringFormat.JSON
alsoReportToAndroidFramework = true
httpSender {
uri = "$acraHost/report"
basicAuthLogin = acraLogin
basicAuthPassword = acraPassword
httpMethod = HttpSender.Method.POST
// TODO compressed reports are failing due to https://github.com/F43nd1r/Acrarium/issues/458
compress = false
}
scheduler {
requiresNetworkType = JobInfo.NETWORK_TYPE_UNMETERED
requiresBatteryNotLow = true
}
}
}