1
0
Fork 0

Fixes #1041 - Disables telemetry when the toggle is off

master
Jeff Boek 2019-03-15 13:09:59 -07:00
parent 72b9d4ebdb
commit 3f86764a3a
5 changed files with 35 additions and 33 deletions

View File

@ -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.
}
}

View File

@ -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.logger.Logger
import mozilla.components.support.base.log.sink.AndroidLogSink import mozilla.components.support.base.log.sink.AndroidLogSink
import mozilla.components.support.rustlog.RustLog import mozilla.components.support.rustlog.RustLog
import org.mozilla.fenix.AdjustHelper.setupAdjustIfNeeded
import org.mozilla.fenix.components.Components import org.mozilla.fenix.components.Components
import java.io.File import java.io.File
@ -44,9 +43,7 @@ open class FenixApplication : Application() {
} }
setupLeakCanary() setupLeakCanary()
loadExperiments() loadExperiments()
setupAdjustIfNeeded(this)
components.analytics.metrics.start() components.analytics.metrics.start()
} }

View File

@ -11,9 +11,11 @@ import mozilla.components.lib.crash.service.MozillaSocorroService
import mozilla.components.lib.crash.service.SentryService import mozilla.components.lib.crash.service.SentryService
import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.R 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.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.Metrics
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
@ -48,8 +50,10 @@ class Analytics(
Metrics( Metrics(
listOf( listOf(
GleanMetricsService(context), GleanMetricsService(context),
LeanplumMetricsService(context as Application) LeanplumMetricsService(context as Application),
) AdjustMetricsService(context)
),
isTelemetryEnabled = { Settings.getInstance(context).isTelemetryEnabled }
) )
} }
} }

View File

@ -1,30 +1,27 @@
/* This Source Code Form is subject to the terms of the Mozilla Public /* 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 * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.components.metrics
package org.mozilla.fenix
import android.app.Activity import android.app.Activity
import android.app.Application import android.app.Application
import android.os.Bundle import android.os.Bundle
import android.text.TextUtils import android.util.Log
import com.adjust.sdk.Adjust import com.adjust.sdk.Adjust
import com.adjust.sdk.AdjustConfig import com.adjust.sdk.AdjustConfig
import com.adjust.sdk.LogLevel import com.adjust.sdk.LogLevel
import mozilla.components.service.glean.Glean import org.mozilla.fenix.BuildConfig
import java.lang.IllegalStateException
object AdjustHelper { class AdjustMetricsService(private val application: Application) : MetricsService {
@Suppress("UnreachableCode") override fun start() {
fun setupAdjustIfNeeded(application: FenixApplication) { if ((BuildConfig.ADJUST_TOKEN.isNullOrEmpty())) {
// RELEASE: Enable Adjust - This class has different implementations for all build types. Log.i(LOGTAG, "No adjust token defined")
return
if (TextUtils.isEmpty(BuildConfig.ADJUST_TOKEN)) { if (!BuildConfig.DEBUG) {
throw IllegalStateException("No adjust token defined for release build") throw IllegalStateException("No adjust token defined for release build")
} }
if (!Glean.getUploadEnabled()) {
return return
} }
@ -42,6 +39,14 @@ object AdjustHelper {
application.registerActivityLifecycleCallbacks(AdjustLifecycleCallbacks()) 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 { private class AdjustLifecycleCallbacks : Application.ActivityLifecycleCallbacks {
override fun onActivityResumed(activity: Activity) { override fun onActivityResumed(activity: Activity) {
Adjust.onResume() Adjust.onResume()

View File

@ -3,6 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.components.metrics package org.mozilla.fenix.components.metrics
import org.mozilla.fenix.BuildConfig
sealed class Event { sealed class Event {
object AddBookmark : Event() object AddBookmark : Event()
object RemoveBookmark : Event() object RemoveBookmark : Event()
@ -46,12 +48,19 @@ interface MetricsService {
fun shouldTrack(event: Event): Boolean 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() { fun start() {
if (BuildConfig.TELEMETRY && !isTelemetryEnabled.invoke() || initialized) { return }
services.forEach { it.start() } services.forEach { it.start() }
initialized = true
} }
fun track(event: Event) { fun track(event: Event) {
if (BuildConfig.TELEMETRY && !isTelemetryEnabled.invoke() && !initialized) { return }
services services
.filter { it.shouldTrack(event) } .filter { it.shouldTrack(event) }
.forEach { it.track(event) } .forEach { it.track(event) }