diff --git a/build.gradle b/build.gradle index 466525b1a0d..7dcf365502c 100644 --- a/build.gradle +++ b/build.gradle @@ -6,6 +6,7 @@ import static org.gradle.api.tasks.testing.TestResult.ResultType buildscript { repositories { + mavenLocal() if (project.hasProperty("googleRepo")) { maven { name "Google" @@ -48,6 +49,7 @@ plugins { allprojects { repositories { + mavenLocal() if (project.hasProperty("googleRepo")) { maven { name "Google" diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 9f05b8434c8..f97029ccf50 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -7,6 +7,7 @@ plugins { } repositories { + mavenLocal() jcenter() } diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt index 9fa64294b8a..812a84297f4 100644 --- a/buildSrc/src/main/java/Dependencies.kt +++ b/buildSrc/src/main/java/Dependencies.kt @@ -29,7 +29,7 @@ object Versions { const val mozilla_appservices = "61.0.10" - const val mozilla_glean = "31.4.1" + const val mozilla_glean = "31.4.1-TESTING29" const val material = "1.1.0" const val nearby = "17.0.0" diff --git a/components/browser/engine-gecko-beta/build.gradle b/components/browser/engine-gecko-beta/build.gradle index 3b6fc7b0b35..9e52254ffe5 100644 --- a/components/browser/engine-gecko-beta/build.gradle +++ b/components/browser/engine-gecko-beta/build.gradle @@ -4,6 +4,7 @@ buildscript { repositories { + mavenLocal() maven { url "https://maven.mozilla.org/maven2" } diff --git a/components/browser/engine-gecko-nightly/build.gradle b/components/browser/engine-gecko-nightly/build.gradle index 8e89ee8f13d..cbad52cacf1 100644 --- a/components/browser/engine-gecko-nightly/build.gradle +++ b/components/browser/engine-gecko-nightly/build.gradle @@ -4,6 +4,7 @@ buildscript { repositories { + mavenLocal() maven { url "https://maven.mozilla.org/maven2" } diff --git a/components/browser/engine-gecko/build.gradle b/components/browser/engine-gecko/build.gradle index 03b52d8df95..7f74a7e37c7 100644 --- a/components/browser/engine-gecko/build.gradle +++ b/components/browser/engine-gecko/build.gradle @@ -4,6 +4,7 @@ buildscript { repositories { + mavenLocal() maven { url "https://maven.mozilla.org/maven2" } diff --git a/components/lib/crash/build.gradle b/components/lib/crash/build.gradle index 883f2a3713c..70bd49c37a7 100644 --- a/components/lib/crash/build.gradle +++ b/components/lib/crash/build.gradle @@ -4,6 +4,7 @@ buildscript { repositories { + mavenLocal() maven { url "https://maven.mozilla.org/maven2" } diff --git a/components/service/glean/build.gradle b/components/service/glean/build.gradle index 1d41358148b..8a756c8ffc9 100644 --- a/components/service/glean/build.gradle +++ b/components/service/glean/build.gradle @@ -46,8 +46,9 @@ dependencies { implementation Dependencies.kotlin_stdlib implementation Dependencies.kotlin_coroutines implementation Dependencies.androidx_work_runtime - - api GLEAN_LIBRARY + api (GLEAN_LIBRARY) { + exclude group: 'org.mozilla.components', module: 'concept-fetch' + } // So consumers can set a HTTP client. api project(':concept-fetch') diff --git a/components/service/glean/src/main/java/mozilla/components/service/glean/Experiments.kt b/components/service/glean/src/main/java/mozilla/components/service/glean/Experiments.kt new file mode 100644 index 00000000000..e090a2755a6 --- /dev/null +++ b/components/service/glean/src/main/java/mozilla/components/service/glean/Experiments.kt @@ -0,0 +1,17 @@ +package mozilla.components.service.glean + +import android.content.Context +import kotlinx.coroutines.* +import mozilla.telemetry.glean.Experiments as ExperimentsCore + +object Experiments { + private var inner: ExperimentsCore = ExperimentsCore + private val job = SupervisorJob() + private val scope = CoroutineScope(Dispatchers.IO) + job + fun initialize(applicationContext: Context, dbPath: String) { + inner.initialize(applicationContext, dbPath) + } + fun getBranch(experimentName: String): String { + return inner.getBranch(experimentName) + } +} \ No newline at end of file diff --git a/components/service/glean/src/main/java/mozilla/components/service/glean/HttpConfig.kt b/components/service/glean/src/main/java/mozilla/components/service/glean/HttpConfig.kt new file mode 100644 index 00000000000..d71e7b38451 --- /dev/null +++ b/components/service/glean/src/main/java/mozilla/components/service/glean/HttpConfig.kt @@ -0,0 +1,24 @@ +package mozilla.components.service.glean + + +import mozilla.components.concept.fetch.Client +import mozilla.telemetry.glean.RustHttpConfig as HttpConfig + +/** + * An object allowing configuring the HTTP client used by Rust code. + */ +object RustHttpConfig { + + /** + * Set the HTTP client to be used by all Rust code. + * + * The `Lazy`'s value is not read until the first request is made. + * + * This must be called + * - after initializing a megazord for users using a custom megazord build. + * - before any other calls into application-services rust code which make HTTP requests. + */ + fun setClient(c: Lazy) { + HttpConfig.setClient(c) + } +} \ No newline at end of file diff --git a/components/support/migration/build.gradle b/components/support/migration/build.gradle index cde517a0442..203d13959cd 100644 --- a/components/support/migration/build.gradle +++ b/components/support/migration/build.gradle @@ -4,6 +4,7 @@ buildscript { repositories { + mavenLocal() maven { url "https://maven.mozilla.org/maven2" } diff --git a/components/support/sync-telemetry/build.gradle b/components/support/sync-telemetry/build.gradle index d455d5b1716..497caa4f8d2 100644 --- a/components/support/sync-telemetry/build.gradle +++ b/components/support/sync-telemetry/build.gradle @@ -4,6 +4,7 @@ buildscript { repositories { + mavenLocal() maven { url "https://maven.mozilla.org/maven2" } diff --git a/components/tooling/glean-gradle-plugin/build.gradle b/components/tooling/glean-gradle-plugin/build.gradle index f995ea574c6..7fe1bda0fc5 100644 --- a/components/tooling/glean-gradle-plugin/build.gradle +++ b/components/tooling/glean-gradle-plugin/build.gradle @@ -10,6 +10,7 @@ plugins { } repositories { + mavenLocal() mavenCentral() } @@ -67,6 +68,7 @@ publishing { } repositories { + mavenLocal() maven { url = "$buildDir/maven" } diff --git a/samples/glean/build.gradle b/samples/glean/build.gradle index beaaa54e066..214c1722f9b 100644 --- a/samples/glean/build.gradle +++ b/samples/glean/build.gradle @@ -4,6 +4,7 @@ buildscript { repositories { + mavenLocal() maven { url "https://maven.mozilla.org/maven2" } diff --git a/samples/glean/samples-glean-library/build.gradle b/samples/glean/samples-glean-library/build.gradle index 073281bdfca..eaf37762d6c 100644 --- a/samples/glean/samples-glean-library/build.gradle +++ b/samples/glean/samples-glean-library/build.gradle @@ -4,6 +4,7 @@ buildscript { repositories { + mavenLocal() maven { url "https://maven.mozilla.org/maven2" } diff --git a/samples/glean/src/main/java/org/mozilla/samples/glean/GleanApplication.kt b/samples/glean/src/main/java/org/mozilla/samples/glean/GleanApplication.kt index 88a048b0132..f6dbbffd192 100644 --- a/samples/glean/src/main/java/org/mozilla/samples/glean/GleanApplication.kt +++ b/samples/glean/src/main/java/org/mozilla/samples/glean/GleanApplication.kt @@ -6,51 +6,66 @@ package org.mozilla.samples.glean import android.app.Application import android.content.Intent +import kotlinx.coroutines.* import mozilla.components.lib.fetch.httpurlconnection.HttpURLConnectionClient import mozilla.components.service.experiments.Configuration as ExperimentsConfig import mozilla.components.service.glean.Glean +import mozilla.components.service.glean.Experiments as Exp import mozilla.components.service.glean.config.Configuration import mozilla.components.service.glean.net.ConceptFetchHttpUploader import mozilla.components.service.experiments.Experiments +import mozilla.components.service.glean.RustHttpConfig import mozilla.components.support.base.log.Log import mozilla.components.support.base.log.sink.AndroidLogSink import org.mozilla.samples.glean.GleanMetrics.Basic import org.mozilla.samples.glean.GleanMetrics.Test import org.mozilla.samples.glean.GleanMetrics.Custom import org.mozilla.samples.glean.GleanMetrics.Pings +import kotlin.coroutines.CoroutineContext + class GleanApplication : Application() { override fun onCreate() { - super.onCreate() - - // We want the log messages of all builds to go to Android logcat - Log.addSink(AndroidLogSink()) - - // Register the sample application's custom pings. - Glean.registerPings(Pings) - - // Initialize the Glean library. Ideally, this is the first thing that - // must be done right after enabling logging. - val client by lazy { HttpURLConnectionClient() } - val httpClient = ConceptFetchHttpUploader.fromClient(client) - val config = Configuration(httpClient = httpClient) - Glean.initialize(applicationContext, uploadEnabled = true, configuration = config) - - // Initialize the Experiments library and pass in the callback that will generate a - // broadcast Intent to signal the application that experiments have been updated. This is - // only relevant to the experiments library, aside from recording the experiment in Glean. - Experiments.initialize(applicationContext, ExperimentsConfig(httpClient = client)) { - val intent = Intent() - intent.action = "org.mozilla.samples.glean.experiments.updated" - sendBroadcast(intent) - } + super.onCreate() + // We want the log messages of all builds to go to Android logcat + Log.addSink(AndroidLogSink()) + + // Register the sample application's custom pings. + Glean.registerPings(Pings) - Test.timespan.start() + // Initialize the Glean library. Ideally, this is the first thing that + // must be done right after enabling logging. + val client by lazy { HttpURLConnectionClient() } + val httpClient = ConceptFetchHttpUploader.fromClient(client) + val config = Configuration(httpClient = httpClient) + Glean.initialize(applicationContext, uploadEnabled = true, configuration = config) + RustHttpConfig.setClient(lazy { HttpURLConnectionClient() }) + Thread { + GlobalScope.launch { + var exp = mozilla.components.service.glean.Experiments + exp.initialize(applicationContext, applicationContext.dataDir.path) + val res = exp.getBranch("button-color") + println(res) + //TODO + // Send an enrolled event for the experiment + // Send a saw button-color button. AKA "User saw some branch of the experiment" + } + }.start() + // Initialize the Experiments library and pass in the callback that will generate a + // broadcast Intent to signal the application that experiments have been updated. This is + // only relevant to the experiments library, aside from recording the experiment in Glean. + Experiments.initialize(applicationContext, ExperimentsConfig(httpClient = client)) { + val intent = Intent() + intent.action = "org.mozilla.samples.glean.experiments.updated" + sendBroadcast(intent) + } - Custom.counter.add() + Test.timespan.start() - // Set a sample value for a metric. - Basic.os.set("Android") + Custom.counter.add() + + // Set a sample value for a metric. + Basic.os.set("Android") + } } -} diff --git a/settings.gradle b/settings.gradle index a6e8dfa49f0..c933317c593 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,6 +6,7 @@ import org.yaml.snakeyaml.Yaml buildscript { repositories { + mavenLocal() jcenter() }