mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-15 18:12:54 +00:00
No Issue - Adds a debug metric controller
This commit is contained in:
parent
61e99ea476
commit
76033f3f20
@ -17,7 +17,7 @@ import org.mozilla.fenix.HomeActivity
|
|||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.components.metrics.GleanMetricsService
|
import org.mozilla.fenix.components.metrics.GleanMetricsService
|
||||||
import org.mozilla.fenix.components.metrics.LeanplumMetricsService
|
import org.mozilla.fenix.components.metrics.LeanplumMetricsService
|
||||||
import org.mozilla.fenix.components.metrics.Metrics
|
import org.mozilla.fenix.components.metrics.MetricController
|
||||||
import org.mozilla.fenix.utils.Settings
|
import org.mozilla.fenix.utils.Settings
|
||||||
import org.mozilla.geckoview.BuildConfig.MOZ_APP_BUILDID
|
import org.mozilla.geckoview.BuildConfig.MOZ_APP_BUILDID
|
||||||
import org.mozilla.geckoview.BuildConfig.MOZ_APP_VERSION
|
import org.mozilla.geckoview.BuildConfig.MOZ_APP_VERSION
|
||||||
@ -68,8 +68,8 @@ class Analytics(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val metrics: Metrics by lazy {
|
val metrics: MetricController by lazy {
|
||||||
Metrics(
|
MetricController.create(
|
||||||
listOf(
|
listOf(
|
||||||
GleanMetricsService(context),
|
GleanMetricsService(context),
|
||||||
LeanplumMetricsService(context as Application)
|
LeanplumMetricsService(context as Application)
|
||||||
|
@ -7,14 +7,12 @@ import android.content.Context
|
|||||||
import mozilla.components.service.glean.Glean
|
import mozilla.components.service.glean.Glean
|
||||||
import mozilla.components.service.glean.private.NoExtraKeys
|
import mozilla.components.service.glean.private.NoExtraKeys
|
||||||
import mozilla.components.support.utils.Browsers
|
import mozilla.components.support.utils.Browsers
|
||||||
import org.mozilla.fenix.BuildConfig
|
|
||||||
import org.mozilla.fenix.GleanMetrics.CrashReporter
|
import org.mozilla.fenix.GleanMetrics.CrashReporter
|
||||||
import org.mozilla.fenix.GleanMetrics.Events
|
import org.mozilla.fenix.GleanMetrics.Events
|
||||||
import org.mozilla.fenix.GleanMetrics.FindInPage
|
import org.mozilla.fenix.GleanMetrics.FindInPage
|
||||||
import org.mozilla.fenix.GleanMetrics.ContextMenu
|
import org.mozilla.fenix.GleanMetrics.ContextMenu
|
||||||
import org.mozilla.fenix.GleanMetrics.QuickActionSheet
|
import org.mozilla.fenix.GleanMetrics.QuickActionSheet
|
||||||
import org.mozilla.fenix.GleanMetrics.Metrics
|
import org.mozilla.fenix.GleanMetrics.Metrics
|
||||||
import org.mozilla.fenix.utils.Settings
|
|
||||||
|
|
||||||
private class EventWrapper<T : Enum<T>>(
|
private class EventWrapper<T : Enum<T>>(
|
||||||
private val recorder: ((Map<T, String>?) -> Unit),
|
private val recorder: ((Map<T, String>?) -> Unit),
|
||||||
@ -109,13 +107,19 @@ private val Event.wrapper
|
|||||||
}
|
}
|
||||||
|
|
||||||
class GleanMetricsService(private val context: Context) : MetricsService {
|
class GleanMetricsService(private val context: Context) : MetricsService {
|
||||||
|
private var initialized = false
|
||||||
|
|
||||||
override fun start() {
|
override fun start() {
|
||||||
|
Glean.setUploadEnabled(true)
|
||||||
|
if (initialized) return
|
||||||
|
|
||||||
Glean.initialize(context)
|
Glean.initialize(context)
|
||||||
Glean.setUploadEnabled(IsGleanEnabled)
|
|
||||||
|
|
||||||
Metrics.apply {
|
Metrics.apply {
|
||||||
defaultBrowser.set(Browsers.all(context).isDefaultBrowser)
|
defaultBrowser.set(Browsers.all(context).isDefaultBrowser)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun stop() {
|
override fun stop() {
|
||||||
@ -127,10 +131,6 @@ class GleanMetricsService(private val context: Context) : MetricsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun shouldTrack(event: Event): Boolean {
|
override fun shouldTrack(event: Event): Boolean {
|
||||||
return Settings.getInstance(context).isTelemetryEnabled && event.wrapper != null
|
return event.wrapper != null
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val IsGleanEnabled = BuildConfig.TELEMETRY
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import mozilla.components.support.base.Component
|
|||||||
import mozilla.components.support.base.facts.Fact
|
import mozilla.components.support.base.facts.Fact
|
||||||
import mozilla.components.support.base.facts.FactProcessor
|
import mozilla.components.support.base.facts.FactProcessor
|
||||||
import mozilla.components.support.base.facts.Facts
|
import mozilla.components.support.base.facts.Facts
|
||||||
|
import mozilla.components.support.base.log.logger.Logger
|
||||||
import org.mozilla.fenix.BuildConfig
|
import org.mozilla.fenix.BuildConfig
|
||||||
|
|
||||||
sealed class Event {
|
sealed class Event {
|
||||||
@ -144,7 +145,37 @@ interface MetricsService {
|
|||||||
fun shouldTrack(event: Event): Boolean
|
fun shouldTrack(event: Event): Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
class Metrics(private val services: List<MetricsService>, private val isTelemetryEnabled: () -> Boolean) {
|
interface MetricController {
|
||||||
|
fun start()
|
||||||
|
fun stop()
|
||||||
|
fun track(event: Event)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun create(services: List<MetricsService>, isTelemetryEnabled: () -> Boolean): MetricController {
|
||||||
|
return if (BuildConfig.TELEMETRY) return ReleaseMetricController(services, isTelemetryEnabled)
|
||||||
|
else DebugMetricController()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DebugMetricController : MetricController {
|
||||||
|
override fun start() {
|
||||||
|
Logger.debug("DebugMetricController: start")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun stop() {
|
||||||
|
Logger.debug("DebugMetricController: stop")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun track(event: Event) {
|
||||||
|
Logger.debug("DebugMetricController: track event: $event")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ReleaseMetricController(
|
||||||
|
private val services: List<MetricsService>,
|
||||||
|
private val isTelemetryEnabled: () -> Boolean
|
||||||
|
) : MetricController {
|
||||||
private var initialized = false
|
private var initialized = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -157,22 +188,22 @@ class Metrics(private val services: List<MetricsService>, private val isTelemetr
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun start() {
|
override fun start() {
|
||||||
if (BuildConfig.TELEMETRY && !isTelemetryEnabled.invoke() || initialized) { return }
|
if (!isTelemetryEnabled.invoke() || initialized) { return }
|
||||||
|
|
||||||
services.forEach { it.start() }
|
services.forEach { it.start() }
|
||||||
initialized = true
|
initialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stop() {
|
override fun stop() {
|
||||||
if (!initialized) { return }
|
if (!initialized) { return }
|
||||||
|
|
||||||
services.forEach { it.stop() }
|
services.forEach { it.stop() }
|
||||||
initialized = false
|
initialized = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun track(event: Event) {
|
override fun track(event: Event) {
|
||||||
if (BuildConfig.TELEMETRY && !isTelemetryEnabled.invoke() && !initialized) { return }
|
if (!isTelemetryEnabled.invoke() && !initialized) { return }
|
||||||
|
|
||||||
services
|
services
|
||||||
.filter { it.shouldTrack(event) }
|
.filter { it.shouldTrack(event) }
|
||||||
|
Loading…
Reference in New Issue
Block a user