2020-01-22 21:46:41 -08:00
|
|
|
package com.geeksville.mesh
|
2020-01-22 09:28:59 -08:00
|
|
|
|
2020-02-12 15:47:06 -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
|
2020-02-12 15:47:06 -08:00
|
|
|
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
2022-02-08 13:50:21 -08:00
|
|
|
import dagger.hilt.android.HiltAndroidApp
|
2020-01-24 17:05:55 -08:00
|
|
|
|
2022-02-08 13:50:21 -08:00
|
|
|
// NOTE: This is a workaround since the Hilt Gradle plugin doesn't support constructors with default parameters
|
|
|
|
|
open class GeeksvilleApplicationWrapper : GeeksvilleApplication()
|
|
|
|
|
|
|
|
|
|
@HiltAndroidApp
|
|
|
|
|
class MeshUtilApplication : GeeksvilleApplicationWrapper() {
|
2020-02-12 15:47:06 -08:00
|
|
|
|
|
|
|
|
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
|
2020-02-12 15:47:06 -08:00
|
|
|
// leave off when running in the debugger
|
2020-02-25 10:48:54 -08:00
|
|
|
if (!isEmulator && (!BuildConfig.DEBUG || !Debug.isDebuggerConnected())) {
|
2020-02-24 15:33:35 -08:00
|
|
|
val crashlytics = FirebaseCrashlytics.getInstance()
|
2020-04-11 13:20:30 -07:00
|
|
|
crashlytics.setCrashlyticsCollectionEnabled(isAnalyticsAllowed)
|
2020-04-05 12:51:58 -07:00
|
|
|
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
|
|
|
|
|
|
2021-01-05 12:01:42 +08:00
|
|
|
// 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
|
|
|
}
|
2020-04-12 09:50:54 -07:00
|
|
|
|
2021-01-05 12:01:42 +08:00
|
|
|
fun sendCrashReports() {
|
2021-03-29 20:33:06 +08:00
|
|
|
if (isAnalyticsAllowed)
|
2021-01-05 12:01:42 +08:00
|
|
|
crashlytics.sendUnsentReports()
|
|
|
|
|
}
|
2020-04-12 09:50:54 -07:00
|
|
|
|
2021-01-05 12:01:42 +08:00
|
|
|
// Send any old reports if user approves
|
|
|
|
|
sendCrashReports()
|
2021-03-29 20:33:06 +08:00
|
|
|
|
2021-01-05 12:01:42 +08:00
|
|
|
// Attach to our exception wrapper
|
|
|
|
|
Exceptions.reporter = { exception, _, _ ->
|
|
|
|
|
crashlytics.recordException(exception)
|
|
|
|
|
sendCrashReports() // Send the new report
|
2020-04-12 09:50:54 -07:00
|
|
|
}
|
2020-02-24 15:33:35 -08:00
|
|
|
}
|
2020-02-12 15:47:06 -08:00
|
|
|
}
|
2020-01-24 17:05:55 -08:00
|
|
|
}
|