Skip to content

Commit

Permalink
Exclude Glean from build
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Finkel committed Apr 22, 2020
1 parent 94f19b7 commit fd42637
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 5 deletions.
16 changes: 14 additions & 2 deletions app/build.gradle
Expand Up @@ -35,10 +35,12 @@ android {
buildConfigField "String", "AMO_COLLECTION", "\"7e8d6dc651b54ab385fb8791bf9dac\""
def deepLinkSchemeValue = "fenix-dev"
buildConfigField "String", "DEEP_LINK_SCHEME", "\"$deepLinkSchemeValue\""
def includeGlean = Config.includeGlean
manifestPlaceholders = [
"isRaptorEnabled": "false",
"deepLinkScheme": deepLinkSchemeValue
]
buildConfigField "boolean", "GLEAN_INCLUDED", "$includeGlean"
}

def releaseTemplate = {
Expand Down Expand Up @@ -291,6 +293,7 @@ android.applicationVariants.all { variant ->
println("Build type: " + variant.buildType.name)
println("Flavor: " + variant.flavorName)
println("Telemetry enabled: " + !isDebug)
println("Glean included: " + Config.includeGlean)

if (useReleaseVersioning) {
// The Google Play Store does not allow multiple APKs for the same app that all have the
Expand Down Expand Up @@ -498,7 +501,11 @@ dependencies {

implementation Deps.mozilla_service_sync_logins
implementation Deps.mozilla_service_firefox_accounts
implementation Deps.mozilla_service_glean
if (Config.includeGlean) {
implementation Deps.mozilla_service_glean
} else {
compileOnly Deps.mozilla_service_glean
}
implementation Deps.mozilla_service_experiments
implementation Deps.mozilla_service_location

Expand Down Expand Up @@ -594,7 +601,12 @@ dependencies {

// For the initial release of Glean 19, we require consumer applications to
// depend on a separate library for unit tests. This will be removed in future releases.
testImplementation "org.mozilla.telemetry:glean-forUnitTests:${project.ext.glean_version}"
if (Config.includeGlean) {
testImplementation "org.mozilla.telemetry:glean-forUnitTests:${project.ext.glean_version}"
//} else {
// testCompileOnly Deps.mozilla_service_glean
// testCompileOnly "org.mozilla.telemetry:glean-forUnitTests:${project.ext.glean_version}"
}

lintChecks project(":mozilla-lint-rules")
}
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/org/mozilla/fenix/FenixApplication.kt
Expand Up @@ -88,7 +88,12 @@ open class FenixApplication : LocaleAwareApplication() {
protected fun initializeGlean() {
val telemetryEnabled = settings().isTelemetryEnabled

logger.debug("Initializing Glean (uploadEnabled=$telemetryEnabled, isFennec=${Config.channel.isFennec})")
if (BuildConfig.GLEAN_INCLUDED) {
logger.debug("Initializing Glean (uploadEnabled=$telemetryEnabled, isFennec=${Config.channel.isFennec})")
} else {
logger.debug("Not initializing Glean")
return
}

Glean.initialize(
applicationContext = this,
Expand Down
Expand Up @@ -16,6 +16,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import mozilla.components.support.base.log.logger.Logger
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.GleanMetrics.Activation
import org.mozilla.fenix.GleanMetrics.Pings
import java.io.IOException
Expand Down Expand Up @@ -177,6 +178,10 @@ class ActivationPing(private val context: Context) {
* starts.
*/
fun checkAndSend() {
if (BuildConfig.GLEAN_INCLUDED) {
Logger.debug("Ignoring ActivationPing - Glean not available")
return
}
if (wasAlreadyTriggered()) {
Logger.debug("ActivationPing - already generated")
return
Expand Down
Expand Up @@ -8,6 +8,7 @@ import android.content.Context
import mozilla.components.service.glean.Glean
import mozilla.components.service.glean.private.NoExtraKeys
import mozilla.components.support.base.log.logger.Logger
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.GleanMetrics.AboutPage
import org.mozilla.fenix.GleanMetrics.Addons
import org.mozilla.fenix.GleanMetrics.AppTheme
Expand Down Expand Up @@ -518,6 +519,11 @@ class GleanMetricsService(private val context: Context) : MetricsService {
private val installationPing = InstallationPing(context)

override fun start() {
if (BuildConfig.GLEAN_INCLUDED) {
logger.debug("Not Enabling Glean.")
return
}

logger.debug("Enabling Glean.")
// Initialization of Glean already happened in FenixApplication.
Glean.setUploadEnabled(true)
Expand All @@ -542,6 +548,7 @@ class GleanMetricsService(private val context: Context) : MetricsService {
}

internal fun setStartupMetrics() {

Metrics.apply {
defaultBrowser.set(BrowsersCache.all(context).isDefaultBrowser)
MozillaProductDetector.getMozillaBrowserDefault(context)?.also {
Expand Down
Expand Up @@ -29,6 +29,7 @@ import mozilla.components.concept.sync.AuthType
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.Config
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
Expand Down Expand Up @@ -164,6 +165,11 @@ class SettingsFragment : PreferenceFragmentCompat() {
}
}

// Only show telemetry settings if Glean was included
val dataChoicePreference =
findPreference<Preference>(getPreferenceKey(R.string.pref_key_data_choices))
dataChoicePreference?.setVisible(BuildConfig.GLEAN_INCLUDED)

setupPreferences()

if (shouldUpdateAccountUIState) {
Expand Down
Expand Up @@ -113,16 +113,18 @@ class AboutFragment : Fragment(), AboutPageListener {
val geckoVersion = GeckoViewBuildConfig.MOZ_APP_VERSION + "-" + GeckoViewBuildConfig.MOZ_APP_BUILDID
val appServicesAbbreviation = getString(R.string.app_services_abbreviation)
val appServicesVersion = mozilla.components.Build.applicationServicesVersion
val gleanIncluded = BuildConfig.GLEAN_INCLUDED

String.format(
"%s (Build #%s)\n%s\n%s: %s\n%s: %s",
"%s (Build #%s)\n%s\n%s: %s\n%s: %s\nGlean: %s",
packageInfo.versionName,
versionCode,
componentsVersion,
maybeGecko,
geckoVersion,
appServicesAbbreviation,
appServicesVersion
appServicesVersion,
gleanIncluded
)
} catch (e: PackageManager.NameNotFoundException) {
""
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/org/mozilla/fenix/utils/Settings.kt
Expand Up @@ -172,16 +172,19 @@ class Settings private constructor(
val isTelemetryEnabled by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_telemetry),
default = true
// false
)

val isMarketingTelemetryEnabled by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_marketing_telemetry),
default = true
// false
)

val isExperimentationEnabled by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_experimentation),
default = true
// false
)

private var trackingProtectionOnboardingShownThisSession = false
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/java/Config.kt
Expand Up @@ -17,6 +17,8 @@ object Config {
const val minSdkVersion = 21
const val targetSdkVersion = 28

const val includeGlean = true

@JvmStatic
private fun generateDebugVersionName(): String {
val today = Date()
Expand Down

0 comments on commit fd42637

Please sign in to comment.