2022-05-31 09:38:02 -07:00
|
|
|
package co.electriccoin.zcash.app
|
|
|
|
|
2023-01-26 11:12:44 -08:00
|
|
|
import co.electriccoin.zcash.crash.android.GlobalCrashReporter
|
2022-05-31 09:38:02 -07:00
|
|
|
import co.electriccoin.zcash.spackle.StrictModeCompat
|
|
|
|
import co.electriccoin.zcash.spackle.Twig
|
2023-01-26 11:12:44 -08:00
|
|
|
import co.electriccoin.zcash.ui.preference.StandardPreferenceKeys
|
|
|
|
import co.electriccoin.zcash.ui.preference.StandardPreferenceSingleton
|
|
|
|
import kotlinx.coroutines.launch
|
2022-05-31 09:38:02 -07:00
|
|
|
|
|
|
|
@Suppress("unused")
|
2023-01-26 11:12:44 -08:00
|
|
|
class ZcashApplication : CoroutineApplication() {
|
2022-05-31 09:38:02 -07:00
|
|
|
|
|
|
|
override fun onCreate() {
|
|
|
|
super.onCreate()
|
|
|
|
|
2023-01-26 11:12:44 -08:00
|
|
|
configureLogging()
|
|
|
|
|
|
|
|
configureStrictMode()
|
|
|
|
|
|
|
|
// Since analytics will need disk IO internally, we want this to be registered after strict
|
|
|
|
// mode is configured to ensure none of that IO happens on the main thread
|
|
|
|
configureAnalytics()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun configureLogging() {
|
2022-05-31 09:38:02 -07:00
|
|
|
Twig.initialize(applicationContext)
|
|
|
|
Twig.info { "Starting application…" }
|
|
|
|
|
2023-02-17 03:05:23 -08:00
|
|
|
if (!BuildConfig.DEBUG) {
|
2022-05-31 09:38:02 -07:00
|
|
|
// In release builds, logs should be stripped by R8 rules
|
|
|
|
Twig.assertLoggingStripped()
|
|
|
|
}
|
2023-01-26 11:12:44 -08:00
|
|
|
}
|
2022-05-31 09:38:02 -07:00
|
|
|
|
2023-01-26 11:12:44 -08:00
|
|
|
private fun configureStrictMode() {
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
StrictModeCompat.enableStrictMode(BuildConfig.IS_STRICT_MODE_CRASH_ENABLED)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun configureAnalytics() {
|
|
|
|
if (GlobalCrashReporter.register(this)) {
|
|
|
|
applicationScope.launch {
|
|
|
|
val prefs = StandardPreferenceSingleton.getInstance(applicationContext)
|
|
|
|
StandardPreferenceKeys.IS_ANALYTICS_ENABLED.observe(prefs).collect {
|
|
|
|
if (it) {
|
|
|
|
GlobalCrashReporter.enable()
|
|
|
|
} else {
|
|
|
|
GlobalCrashReporter.disableAndDelete()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-31 09:38:02 -07:00
|
|
|
}
|
|
|
|
}
|