2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-17 15:26:23 +00:00

[fenix] No issue: Add Sentry breadcrumbs to ease crash investigations

This commit is contained in:
Colin Lee 2019-06-14 12:08:46 -05:00 committed by Jeff Boek
parent 839c60a7da
commit ad6f6d17b8
2 changed files with 49 additions and 19 deletions

View File

@ -12,9 +12,13 @@ import android.view.View
import androidx.annotation.IdRes import androidx.annotation.IdRes
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.NavigationUI import androidx.navigation.ui.NavigationUI
import io.sentry.Sentry
import io.sentry.event.Breadcrumb
import io.sentry.event.BreadcrumbBuilder
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -28,6 +32,7 @@ import mozilla.components.support.base.feature.BackHandler
import mozilla.components.support.ktx.kotlin.isUrl import mozilla.components.support.ktx.kotlin.isUrl
import mozilla.components.support.ktx.kotlin.toNormalizedUrl import mozilla.components.support.ktx.kotlin.toNormalizedUrl
import mozilla.components.support.utils.SafeIntent import mozilla.components.support.utils.SafeIntent
import org.mozilla.fenix.components.isSentryEnabled
import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.nav import org.mozilla.fenix.ext.nav
@ -55,32 +60,30 @@ open class HomeActivity : AppCompatActivity() {
lateinit var browsingModeManager: BrowsingModeManager lateinit var browsingModeManager: BrowsingModeManager
private val onDestinationChangedListener = NavController.OnDestinationChangedListener { _, dest, _ ->
val fragmentName = resources.getResourceEntryName(dest.id)
Sentry.getContext().recordBreadcrumb(
BreadcrumbBuilder()
.setCategory("DestinationChanged")
.setMessage("Changing to fragment $fragmentName, isCustomTab: $isCustomTab")
.setLevel(Breadcrumb.Level.INFO)
.build()
)
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
components.publicSuffixList.prefetch() components.publicSuffixList.prefetch()
browsingModeManager = createBrowsingModeManager() setupThemeAndBrowsingMode()
themeManager = createThemeManager(
when (browsingModeManager.isPrivate) {
true -> ThemeManager.Theme.Private
false -> ThemeManager.Theme.Normal
}
)
setTheme(themeManager.currentTheme)
ThemeManager.applyStatusBarTheme(window, themeManager, this)
setContentView(R.layout.activity_home) setContentView(R.layout.activity_home)
// Add ids to this that we don't want to have a toolbar back button setupToolbarAndNavigation()
val appBarConfiguration = AppBarConfiguration.Builder().build()
val navigationToolbar = findViewById<Toolbar>(R.id.navigationToolbar) if (Settings.getInstance(this).isTelemetryEnabled && isSentryEnabled()) {
setSupportActionBar(navigationToolbar) navHost.navController.addOnDestinationChangedListener(onDestinationChangedListener)
NavigationUI.setupWithNavController(navigationToolbar, navHost.navController, appBarConfiguration)
navigationToolbar.setNavigationOnClickListener {
onBackPressed()
} }
supportActionBar?.hide()
intent intent
?.let { SafeIntent(it) } ?.let { SafeIntent(it) }
@ -97,8 +100,33 @@ open class HomeActivity : AppCompatActivity() {
handleOpenedFromExternalSourceIfNecessary(intent) handleOpenedFromExternalSourceIfNecessary(intent)
} }
private fun setupThemeAndBrowsingMode() {
browsingModeManager = createBrowsingModeManager()
themeManager = createThemeManager(
when (browsingModeManager.isPrivate) {
true -> ThemeManager.Theme.Private
false -> ThemeManager.Theme.Normal
}
)
setTheme(themeManager.currentTheme)
ThemeManager.applyStatusBarTheme(window, themeManager, this)
}
private fun setupToolbarAndNavigation() {
// Add ids to this that we don't want to have a toolbar back button
val appBarConfiguration = AppBarConfiguration.Builder().build()
val navigationToolbar = findViewById<Toolbar>(R.id.navigationToolbar)
setSupportActionBar(navigationToolbar)
NavigationUI.setupWithNavController(navigationToolbar, navHost.navController, appBarConfiguration)
navigationToolbar.setNavigationOnClickListener {
onBackPressed()
}
supportActionBar?.hide()
}
override fun onDestroy() { override fun onDestroy() {
sessionObserver?.let { components.core.sessionManager.unregister(it) } sessionObserver?.let { components.core.sessionManager.unregister(it) }
navHost.navController.removeOnDestinationChangedListener(onDestinationChangedListener)
super.onDestroy() super.onDestroy()
} }

View File

@ -34,7 +34,7 @@ class Analytics(
val crashReporter: CrashReporter by lazy { val crashReporter: CrashReporter by lazy {
val services = mutableListOf<CrashReporterService>() val services = mutableListOf<CrashReporterService>()
if (!BuildConfig.SENTRY_TOKEN.isNullOrEmpty()) { if (isSentryEnabled()) {
val sentryService = SentryService( val sentryService = SentryService(
context, context,
BuildConfig.SENTRY_TOKEN, BuildConfig.SENTRY_TOKEN,
@ -85,3 +85,5 @@ class Analytics(
) )
} }
} }
fun isSentryEnabled() = !BuildConfig.SENTRY_TOKEN.isNullOrEmpty()