From c0e546a533c7c22e2f1a211179b2518c7506b18c Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Wed, 27 Mar 2019 11:04:00 -0700 Subject: [PATCH] [fenix] Fixes https://github.com/mozilla-mobile/fenix/issues/1219: Display crash reporter (without reporting) on all builds --- .../org/mozilla/fenix/FenixApplication.kt | 7 ------ .../org/mozilla/fenix/components/Analytics.kt | 24 ++++++++++++------- .../java/org/mozilla/fenix/utils/Settings.kt | 4 +++- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt index e0e3e883d5..afc5fe6895 100644 --- a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt +++ b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt @@ -91,13 +91,6 @@ open class FenixApplication : Application() { } private fun setupCrashReporting() { - @Suppress("ConstantConditionIf") - if (!BuildConfig.CRASH_REPORTING || BuildConfig.BUILD_TYPE != "release") { - // Only enable crash reporting if this is a release build and if crash reporting was explicitly enabled - // via a Gradle command line flag. - return - } - components .analytics .crashReporter diff --git a/app/src/main/java/org/mozilla/fenix/components/Analytics.kt b/app/src/main/java/org/mozilla/fenix/components/Analytics.kt index 4588ad6f85..561f7856b0 100644 --- a/app/src/main/java/org/mozilla/fenix/components/Analytics.kt +++ b/app/src/main/java/org/mozilla/fenix/components/Analytics.kt @@ -9,6 +9,7 @@ import android.app.PendingIntent import android.content.Context import android.content.Intent import mozilla.components.lib.crash.CrashReporter +import mozilla.components.lib.crash.service.CrashReporterService import mozilla.components.lib.crash.service.MozillaSocorroService import mozilla.components.lib.crash.service.SentryService import org.mozilla.fenix.BuildConfig @@ -28,14 +29,21 @@ class Analytics( private val context: Context ) { val crashReporter: CrashReporter by lazy { - val sentryService = SentryService( - context, - BuildConfig.SENTRY_TOKEN, - tags = mapOf("geckoview" to "$MOZ_APP_VERSION-$MOZ_APP_BUILDID"), - sendEventForNativeCrashes = true - ) + var services = listOf() - val socorroService = MozillaSocorroService(context, "Fenix") + if (!BuildConfig.SENTRY_TOKEN.isNullOrEmpty()) { + val sentryService = SentryService( + context, + BuildConfig.SENTRY_TOKEN, + tags = mapOf("geckoview" to "$MOZ_APP_VERSION-$MOZ_APP_BUILDID"), + sendEventForNativeCrashes = true + ) + + services += sentryService + } + + val socorroService = MozillaSocorroService(context, context.getString(R.string.app_name)) + services += socorroService val intent = Intent(context, HomeActivity::class.java).apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP @@ -49,7 +57,7 @@ class Analytics( ) CrashReporter( - services = listOf(sentryService, socorroService), + services = services, shouldPrompt = CrashReporter.Prompt.ALWAYS, promptConfiguration = CrashReporter.PromptConfiguration( appName = context.getString(R.string.app_name), diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index b09845c823..2041f8eca2 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -8,6 +8,7 @@ import android.content.Context import android.content.SharedPreferences import android.preference.PreferenceManager import mozilla.components.feature.sitepermissions.SitePermissionsRules +import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.R import org.mozilla.fenix.ext.getPreferenceKey import java.security.InvalidParameterException @@ -42,7 +43,8 @@ class Settings private constructor(context: Context) { get() = preferences.getString(appContext.getPreferenceKey(R.string.pref_key_search_engine), "") ?: "" val isCrashReportingEnabled: Boolean - get() = preferences.getBoolean(appContext.getPreferenceKey(R.string.pref_key_crash_reporter), true) + get() = preferences.getBoolean(appContext.getPreferenceKey(R.string.pref_key_crash_reporter), true) && + BuildConfig.CRASH_REPORTING && BuildConfig.BUILD_TYPE == "release" val isRemoteDebuggingEnabled: Boolean get() = preferences.getBoolean(appContext.getPreferenceKey(R.string.pref_key_remote_debugging), false)