diff --git a/app/src/debug/java/org/mozilla/fenix/AdjustHelper.kt b/app/src/debug/java/org/mozilla/fenix/AdjustHelper.kt deleted file mode 100644 index 7f51065c7..000000000 --- a/app/src/debug/java/org/mozilla/fenix/AdjustHelper.kt +++ /dev/null @@ -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. - } -} diff --git a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt index f684fcae9..f1f8aa437 100644 --- a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt +++ b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt @@ -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() } diff --git a/app/src/main/java/org/mozilla/fenix/components/Analytics.kt b/app/src/main/java/org/mozilla/fenix/components/Analytics.kt index e711f7461..e60f7adb4 100644 --- a/app/src/main/java/org/mozilla/fenix/components/Analytics.kt +++ b/app/src/main/java/org/mozilla/fenix/components/Analytics.kt @@ -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 } ) } } diff --git a/app/src/release/java/org/mozilla/fenix/AdjustHelper.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/AdjustMetricsService.kt similarity index 65% rename from app/src/release/java/org/mozilla/fenix/AdjustHelper.kt rename to app/src/main/java/org/mozilla/fenix/components/metrics/AdjustMetricsService.kt index fe2eade07..7c46d5f71 100644 --- a/app/src/release/java/org/mozilla/fenix/AdjustHelper.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/AdjustMetricsService.kt @@ -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() diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt index 1f8186eb3..710983f18 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/Metrics.kt @@ -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) { +class Metrics(private val services: List, 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) }