Meshtastic-Android/app/src/google/java/com/geeksville/mesh/MeshUtilApplication.kt

56 lines
2.2 KiB
Kotlin
Raw Normal View History

2020-01-22 21:46:41 -08:00
package com.geeksville.mesh
2020-01-22 09:28:59 -08:00
import android.os.Debug
2022-09-04 22:52:40 -03:00
import com.geeksville.mesh.android.AppPrefs
import com.geeksville.mesh.android.BuildUtils.isEmulator
import com.geeksville.mesh.android.GeeksvilleApplication
import com.geeksville.mesh.android.Logging
import com.geeksville.mesh.util.Exceptions
import com.google.firebase.crashlytics.crashlytics
import com.google.firebase.Firebase
import dagger.hilt.android.HiltAndroidApp
@HiltAndroidApp
class MeshUtilApplication : GeeksvilleApplication() {
override fun onCreate() {
super.onCreate()
2020-02-14 07:47:20 -08:00
Logging.showLogs = BuildConfig.DEBUG
2020-04-11 13:20:30 -07:00
// We default to off in the manifest - we turn on here if the user approves
// leave off when running in the debugger
if (!isEmulator && (!BuildConfig.DEBUG || !Debug.isDebuggerConnected())) {
val crashlytics = Firebase.crashlytics
2020-04-11 13:20:30 -07:00
crashlytics.setCrashlyticsCollectionEnabled(isAnalyticsAllowed)
crashlytics.setCustomKey("debug_build", BuildConfig.DEBUG)
2020-02-24 15:33:35 -08:00
2020-04-21 08:31:28 -07:00
val pref = AppPrefs(this)
crashlytics.setUserId(pref.getInstallId()) // be able to group all bugs per anonymous user
// We always send our log messages to the crashlytics lib, but they only get sent to the server if we report an exception
// This makes log messages work properly if someone turns on analytics just before they click report bug.
// send all log messages through crashyltics, so if we do crash we'll have those in the report
val standardLogger = Logging.printlog
Logging.printlog = { level, tag, message ->
crashlytics.log("$tag: $message")
standardLogger(level, tag, message)
2020-02-24 15:33:35 -08:00
}
fun sendCrashReports() {
2021-03-29 20:33:06 +08:00
if (isAnalyticsAllowed)
crashlytics.sendUnsentReports()
}
// Send any old reports if user approves
sendCrashReports()
2021-03-29 20:33:06 +08:00
// Attach to our exception wrapper
Exceptions.reporter = { exception, _, _ ->
crashlytics.recordException(exception)
sendCrashReports() // Send the new report
}
2020-02-24 15:33:35 -08:00
}
}
}