For #945 - Disable leanplum when we stop telemetry
parent
1bb65a9243
commit
c5205b6236
|
@ -48,7 +48,9 @@ open class FenixApplication : Application() {
|
|||
|
||||
setupLeakCanary()
|
||||
loadExperiments()
|
||||
components.analytics.metrics.start()
|
||||
if (Settings.getInstance(this).isTelemetryEnabled) {
|
||||
components.analytics.metrics.start()
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun setupLeakCanary() {
|
||||
|
|
|
@ -35,10 +35,14 @@ class AdjustMetricsService(private val application: Application) : MetricsServic
|
|||
config.setLogLevel(LogLevel.SUPRESS)
|
||||
|
||||
Adjust.onCreate(config)
|
||||
|
||||
Adjust.setEnabled(true)
|
||||
application.registerActivityLifecycleCallbacks(AdjustLifecycleCallbacks())
|
||||
}
|
||||
|
||||
override fun stop() {
|
||||
Adjust.setEnabled(false)
|
||||
}
|
||||
|
||||
// We're not currently sending events directly to Adjust
|
||||
override fun track(event: Event) { }
|
||||
override fun shouldTrack(event: Event): Boolean = false
|
||||
|
|
|
@ -86,6 +86,10 @@ class GleanMetricsService(private val context: Context) : MetricsService {
|
|||
}
|
||||
}
|
||||
|
||||
override fun stop() {
|
||||
Glean.setUploadEnabled(false)
|
||||
}
|
||||
|
||||
override fun track(event: Event) {
|
||||
event.wrapper?.track(event)
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.util.Log
|
|||
import com.leanplum.Leanplum
|
||||
import com.leanplum.LeanplumActivityHelper
|
||||
import com.leanplum.annotations.Parser
|
||||
import com.leanplum.internal.LeanplumInternal
|
||||
import org.mozilla.fenix.BuildConfig
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
|
||||
|
@ -79,6 +80,7 @@ class LeanplumMetricsService(private val application: Application) : MetricsServ
|
|||
}
|
||||
}
|
||||
|
||||
Leanplum.setIsTestModeEnabled(false)
|
||||
Leanplum.setApplicationContext(application)
|
||||
Parser.parseVariables(application)
|
||||
|
||||
|
@ -86,6 +88,20 @@ class LeanplumMetricsService(private val application: Application) : MetricsServ
|
|||
Leanplum.start(application)
|
||||
}
|
||||
|
||||
override fun stop() {
|
||||
// As written in LeanPlum SDK documentation, "This prevents Leanplum from communicating with the server."
|
||||
// as this "isTestMode" flag is checked before LeanPlum SDK does anything.
|
||||
// Also has the benefit effect of blocking the display of already downloaded messages.
|
||||
// The reverse of this - setIsTestModeEnabled(false) must be called before trying to init
|
||||
// LP in the same session.
|
||||
Leanplum.setIsTestModeEnabled(true)
|
||||
|
||||
// This is just to allow restarting LP and it's functionality in the same app session
|
||||
// as LP stores it's state internally and check against it
|
||||
LeanplumInternal.setCalledStart(false)
|
||||
LeanplumInternal.setHasStarted(false)
|
||||
}
|
||||
|
||||
override fun track(event: Event) {
|
||||
event.name?.also {
|
||||
Leanplum.track(it, event.extras)
|
||||
|
|
|
@ -117,6 +117,7 @@ private fun Fact.toEvent(): Event? = when (Pair(component, item)) {
|
|||
|
||||
interface MetricsService {
|
||||
fun start()
|
||||
fun stop()
|
||||
fun track(event: Event)
|
||||
fun shouldTrack(event: Event): Boolean
|
||||
}
|
||||
|
@ -141,6 +142,13 @@ class Metrics(private val services: List<MetricsService>, private val isTelemetr
|
|||
initialized = true
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
if (!initialized) { return }
|
||||
|
||||
services.forEach { it.stop() }
|
||||
initialized = false
|
||||
}
|
||||
|
||||
fun track(event: Event) {
|
||||
if (BuildConfig.TELEMETRY && !isTelemetryEnabled.invoke() && !initialized) { return }
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.SwitchPreference
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
|
||||
class DataChoicesFragment : PreferenceFragmentCompat() {
|
||||
|
@ -17,6 +18,18 @@ class DataChoicesFragment : PreferenceFragmentCompat() {
|
|||
super.onCreate(savedInstanceState)
|
||||
(activity as AppCompatActivity).title = getString(R.string.preferences_data_choices)
|
||||
(activity as AppCompatActivity).supportActionBar?.show()
|
||||
|
||||
preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener { sharedPreferences, key ->
|
||||
when (key) {
|
||||
getString(R.string.pref_key_telemetry) -> {
|
||||
if (sharedPreferences.getBoolean(key, Settings.getInstance(requireContext()).isTelemetryEnabled)) {
|
||||
requireComponents.analytics.metrics.start()
|
||||
} else {
|
||||
requireComponents.analytics.metrics.stop()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
|
|
Loading…
Reference in New Issue