Commit edbfb041 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Ignore all exceptions when creating the Sentry client, only try to access it if it is initialized

parent 127cf86e
Pipeline #5984 passed with stage
in 2 minutes and 12 seconds
......@@ -94,7 +94,7 @@ fun Context.log(
}
fun Context.log(e: Throwable, extras: Map<String, String>? = null) {
logErrorSentry(e, extras)
if(SmokeScreen.sentryReady) logErrorSentry(e, extras)
getPreferences().lastCrashTimeStamp = System.currentTimeMillis()
if (Logger.isEnabled(this)) {
Logger.getInstance(this).log(e)
......
......@@ -45,7 +45,10 @@ import kotlin.system.exitProcess
* You can contact the developer at daniel.wolf@frostnerd.com.
*/
class SmokeScreen : Application() {
companion object {
var sentryReady:Boolean = false
private set
}
private var defaultUncaughtExceptionHandler: Thread.UncaughtExceptionHandler? = null
val customUncaughtExceptionHandler = EnrichableUncaughtExceptionHandler()
private fun showCrashNotification() {
......@@ -95,9 +98,16 @@ class SmokeScreen : Application() {
LeakSentry.watchIfEnabled(this)
}
fun closeSentry() {
Sentry.close()
sentryReady = false
}
fun initSentry(forceStatus: Status = Status.NONE) {
if (!BuildConfig.DEBUG && BuildConfig.SENTRY_DSN != "dummy") {
GlobalScope.launch(Dispatchers.IO) {
sentryReady = false
try {
val hostName = InetAddress.getLocalHost().hostName
if(!hostName.startsWith("mars-sandbox", true)) {
val enabledType = getPreferences().crashreportingType
......@@ -132,6 +142,7 @@ class SmokeScreen : Application() {
addTag("app.fromCi", BuildConfig.FROM_CI.toString())
addTag("app.commit", BuildConfig.COMMIT_HASH)
}
sentryReady = true
} else if (enabledType == Crashreporting.MINIMAL || forceStatus == Status.DATASAVING) {
// Inits Sentry in datasaving mode
// Only data absolutely necessary is transmitted (Android version, app version).
......@@ -153,7 +164,11 @@ class SmokeScreen : Application() {
}
this.addBuilderHelper(DatasavingSentryEventHelper())
}
sentryReady = true
}
}
} catch(ex:Throwable) {
ex.printStackTrace()
}
}
}
......
......@@ -58,7 +58,7 @@ class CrashReportingEnableDialog(
) { dialog, _ ->
context.getPreferences().crashreportingType = Crashreporting.OFF
context.getPreferences().crashReportingConsent = false
Sentry.close()
(context.applicationContext as SmokeScreen).closeSentry()
dialog.dismiss()
}
setButton(DialogInterface.BUTTON_NEUTRAL, context.getString(R.string.dialog_crashreporting_neutral)) { _, _ ->
......
......@@ -428,10 +428,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
false
} else {
if(newValue == Crashreporting.MINIMAL.value) {
Sentry.close()
(requireContext().applicationContext as SmokeScreen).closeSentry()
(requireContext().applicationContext as SmokeScreen).initSentry(Status.DATASAVING)
} else if(newValue == Crashreporting.OFF.value) {
Sentry.close()
(requireContext().applicationContext as SmokeScreen).closeSentry()
}
true
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment