Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
Ensure telemetry is init'd early to generate clientID
Browse files Browse the repository at this point in the history
  • Loading branch information
colintheshots committed Dec 28, 2018
1 parent 5c5de48 commit 9827c02
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions app/src/main/java/org/mozilla/focus/FocusApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Job
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withTimeoutOrNull
import mozilla.components.service.fretboard.Fretboard
import mozilla.components.service.fretboard.ValuesProvider
import mozilla.components.service.fretboard.source.kinto.KintoExperimentSource
Expand Down Expand Up @@ -47,10 +44,6 @@ class FocusApplication : LocaleAwareApplication(), CoroutineScope {
override val coroutineContext: CoroutineContext
get() = job + Dispatchers.Main

companion object {
private const val FRETBOARD_BLOCKING_NETWORK_READ_TIMEOUT = 10000L
}

val components: Components by lazy { Components() }

var visibilityLifeCycleCallback: VisibilityLifeCycleCallback? = null
Expand All @@ -66,6 +59,7 @@ class FocusApplication : LocaleAwareApplication(), CoroutineScope {

PreferenceManager.setDefaultValues(this, R.xml.settings, false)

TelemetryWrapper.init(this@FocusApplication)
loadExperiments()

enableStrictMode()
Expand All @@ -78,7 +72,6 @@ class FocusApplication : LocaleAwareApplication(), CoroutineScope {
registerForLocaleUpdates(this@FocusApplication)
}

TelemetryWrapper.init(this@FocusApplication)
AdjustHelper.setupAdjustIfNeeded(this@FocusApplication)

visibilityLifeCycleCallback = VisibilityLifeCycleCallback(this@FocusApplication)
Expand All @@ -90,7 +83,7 @@ class FocusApplication : LocaleAwareApplication(), CoroutineScope {
register(CleanupSessionObserver(this@FocusApplication))
}

async(IO) { updateExperiments() }
launch(IO) { fretboard.updateExperiments() }
}

private fun loadExperiments() {
Expand All @@ -105,16 +98,10 @@ class FocusApplication : LocaleAwareApplication(), CoroutineScope {
}
})
fretboard.loadExperiments()
TelemetryWrapper.recordActiveExperiments(this)
WebViewProvider.determineEngine(this@FocusApplication)
}

private suspend fun updateExperiments() = coroutineScope {
val updateExperimentsAsync = async { fretboard.updateExperiments() }
withTimeoutOrNull(FRETBOARD_BLOCKING_NETWORK_READ_TIMEOUT) {
updateExperimentsAsync.await() // then update disk and memory from the network
}
}

private fun enableStrictMode() {
// Android/WebView sometimes commit strict mode violations, see e.g.
// https://github.com/mozilla-mobile/focus-android/issues/660
Expand Down

0 comments on commit 9827c02

Please sign in to comment.