Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glean integration #349

Merged
merged 11 commits into from Jan 10, 2019
19 changes: 19 additions & 0 deletions app/build.gradle
Expand Up @@ -2,6 +2,10 @@
* 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/. */

plugins {
id "com.jetbrains.python.envs" version "0.0.25"
pocmo marked this conversation as resolved.
Show resolved Hide resolved
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
Expand Down Expand Up @@ -94,6 +98,16 @@ android.applicationVariants.all { variant ->
buildConfigField 'boolean', 'CRASH_REPORTING_ENABLED', 'false'
}

// -------------------------------------------------------------------------------------------------
// Activating telemetry with command line paramter.
// -------------------------------------------------------------------------------------------------

if (project.hasProperty("telemetry") && project.property("telemetry") == "true") {
buildConfigField 'boolean', 'TELEMETRY_ENABLED', 'true'
} else {
buildConfigField 'boolean', 'TELEMETRY_ENABLED', 'false'
}

// -------------------------------------------------------------------------------------------------
// Generating version codes for Google Play
// -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -158,6 +172,7 @@ dependencies {
implementation Deps.mozilla_ui_colors

implementation Deps.mozilla_service_firefox_accounts
implementation Deps.mozilla_service_glean

implementation Deps.mozilla_support_utils
implementation Deps.mozilla_support_ktx
Expand Down Expand Up @@ -215,3 +230,7 @@ task printBuildVariants {
println "variants: " + groovy.json.JsonOutput.toJson(buildVariants)
}
}

// Normally this should use the same version as the dependency. But since we are using snapshots we can't reference a
// git tag. So we are just using "master" and hoping for the best.
apply from: 'https://github.com/mozilla-mobile/android-components/raw/master/components/service/glean/scripts/sdk_generator.gradle'
Expand Up @@ -5,10 +5,12 @@
package org.mozilla.reference.browser

import android.app.Application
import mozilla.components.service.glean.Glean
import mozilla.components.support.base.log.Log
import mozilla.components.support.base.log.logger.Logger
import mozilla.components.support.base.log.sink.AndroidLogSink
import org.mozilla.reference.browser.ext.isCrashReportActive
import org.mozilla.reference.browser.settings.Settings

class BrowserApplication : Application() {
val components by lazy { Components(this) }
Expand All @@ -19,6 +21,9 @@ class BrowserApplication : Application() {
// We want the log messages of all builds to go to Android logcat
Log.addSink(AndroidLogSink())

Glean.initialize(this)
pocmo marked this conversation as resolved.
Show resolved Hide resolved
Glean.setMetricsEnabled(BuildConfig.TELEMETRY_ENABLED && Settings.isTelemetryEnabled(this))

if (isCrashReportActive) {
components.analytics.crashReporter.install(this)
}
Expand Down
@@ -0,0 +1,15 @@
/* 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.reference.browser.settings

import android.content.Context
import android.preference.PreferenceManager
import org.mozilla.reference.browser.R

object Settings {
fun isTelemetryEnabled(context: Context): Boolean =
PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
context.getString(R.string.pref_key_telemetry), true)
}
3 changes: 2 additions & 1 deletion buildSrc/src/main/java/Dependencies.kt
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// Synchronized version numbers for dependencies used by (some) modules
private object Versions {
object Versions {
pocmo marked this conversation as resolved.
Show resolved Hide resolved
const val kotlin = "1.3.10"
const val coroutines = "1.0.1"

Expand Down Expand Up @@ -68,6 +68,7 @@ object Deps {
const val mozilla_ui_colors = "org.mozilla.components:ui-colors:${Versions.mozilla_android_components}"

const val mozilla_service_firefox_accounts = "org.mozilla.components:service-firefox-accounts:${Versions.mozilla_android_components}"
const val mozilla_service_glean = "org.mozilla.components:service-glean:${Versions.mozilla_android_components}"

const val mozilla_support_utils = "org.mozilla.components:support-utils:${Versions.mozilla_android_components}"
const val mozilla_support_ktx= "org.mozilla.components:support-ktx:${Versions.mozilla_android_components}"
Expand Down