Fixes #1041 - Disables telemetry when the toggle is off
parent
72b9d4ebdb
commit
3f86764a3a
|
@ -1,13 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix
|
||||
|
||||
import android.content.Context
|
||||
|
||||
object AdjustHelper {
|
||||
fun setupAdjustIfNeeded(context: Context) {
|
||||
// DEBUG: No Adjust - This class has different implementations for all build types.
|
||||
}
|
||||
}
|
|
@ -19,7 +19,6 @@ import mozilla.components.support.base.log.Log
|
|||
import mozilla.components.support.base.log.logger.Logger
|
||||
import mozilla.components.support.base.log.sink.AndroidLogSink
|
||||
import mozilla.components.support.rustlog.RustLog
|
||||
import org.mozilla.fenix.AdjustHelper.setupAdjustIfNeeded
|
||||
import org.mozilla.fenix.components.Components
|
||||
import java.io.File
|
||||
|
||||
|
@ -44,9 +43,7 @@ open class FenixApplication : Application() {
|
|||
}
|
||||
|
||||
setupLeakCanary()
|
||||
|
||||
loadExperiments()
|
||||
setupAdjustIfNeeded(this)
|
||||
components.analytics.metrics.start()
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,11 @@ import mozilla.components.lib.crash.service.MozillaSocorroService
|
|||
import mozilla.components.lib.crash.service.SentryService
|
||||
import org.mozilla.fenix.BuildConfig
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.components.metrics.AdjustMetricsService
|
||||
import org.mozilla.fenix.components.metrics.GleanMetricsService
|
||||
import org.mozilla.fenix.components.metrics.LeanplumMetricsService
|
||||
import org.mozilla.fenix.components.metrics.Metrics
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
import org.mozilla.geckoview.BuildConfig.MOZ_APP_BUILDID
|
||||
import org.mozilla.geckoview.BuildConfig.MOZ_APP_VERSION
|
||||
|
||||
|
@ -48,8 +50,10 @@ class Analytics(
|
|||
Metrics(
|
||||
listOf(
|
||||
GleanMetricsService(context),
|
||||
LeanplumMetricsService(context as Application)
|
||||
)
|
||||
LeanplumMetricsService(context as Application),
|
||||
AdjustMetricsService(context)
|
||||
),
|
||||
isTelemetryEnabled = { Settings.getInstance(context).isTelemetryEnabled }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,30 +1,27 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix
|
||||
package org.mozilla.fenix.components.metrics
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
|
||||
import android.util.Log
|
||||
import com.adjust.sdk.Adjust
|
||||
import com.adjust.sdk.AdjustConfig
|
||||
import com.adjust.sdk.LogLevel
|
||||
import mozilla.components.service.glean.Glean
|
||||
import org.mozilla.fenix.BuildConfig
|
||||
import java.lang.IllegalStateException
|
||||
|
||||
object AdjustHelper {
|
||||
@Suppress("UnreachableCode")
|
||||
fun setupAdjustIfNeeded(application: FenixApplication) {
|
||||
// RELEASE: Enable Adjust - This class has different implementations for all build types.
|
||||
return
|
||||
class AdjustMetricsService(private val application: Application) : MetricsService {
|
||||
override fun start() {
|
||||
if ((BuildConfig.ADJUST_TOKEN.isNullOrEmpty())) {
|
||||
Log.i(LOGTAG, "No adjust token defined")
|
||||
|
||||
if (TextUtils.isEmpty(BuildConfig.ADJUST_TOKEN)) {
|
||||
throw IllegalStateException("No adjust token defined for release build")
|
||||
}
|
||||
if (!BuildConfig.DEBUG) {
|
||||
throw IllegalStateException("No adjust token defined for release build")
|
||||
}
|
||||
|
||||
if (!Glean.getUploadEnabled()) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -42,6 +39,14 @@ object AdjustHelper {
|
|||
application.registerActivityLifecycleCallbacks(AdjustLifecycleCallbacks())
|
||||
}
|
||||
|
||||
// We're not currently sending events directly to Adjust
|
||||
override fun track(event: Event) { }
|
||||
override fun shouldTrack(event: Event): Boolean = false
|
||||
|
||||
companion object {
|
||||
private const val LOGTAG = "AdjustMetricsService"
|
||||
}
|
||||
|
||||
private class AdjustLifecycleCallbacks : Application.ActivityLifecycleCallbacks {
|
||||
override fun onActivityResumed(activity: Activity) {
|
||||
Adjust.onResume()
|
|
@ -3,6 +3,8 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
package org.mozilla.fenix.components.metrics
|
||||
|
||||
import org.mozilla.fenix.BuildConfig
|
||||
|
||||
sealed class Event {
|
||||
object AddBookmark : Event()
|
||||
object RemoveBookmark : Event()
|
||||
|
@ -46,12 +48,19 @@ interface MetricsService {
|
|||
fun shouldTrack(event: Event): Boolean
|
||||
}
|
||||
|
||||
class Metrics(private val services: List<MetricsService>) {
|
||||
class Metrics(private val services: List<MetricsService>, private val isTelemetryEnabled: () -> Boolean) {
|
||||
private var initialized = false
|
||||
|
||||
fun start() {
|
||||
if (BuildConfig.TELEMETRY && !isTelemetryEnabled.invoke() || initialized) { return }
|
||||
|
||||
services.forEach { it.start() }
|
||||
initialized = true
|
||||
}
|
||||
|
||||
fun track(event: Event) {
|
||||
if (BuildConfig.TELEMETRY && !isTelemetryEnabled.invoke() && !initialized) { return }
|
||||
|
||||
services
|
||||
.filter { it.shouldTrack(event) }
|
||||
.forEach { it.track(event) }
|
||||
|
|
Loading…
Reference in New Issue