@@ -6,51 +6,66 @@ package org.mozilla.samples.glean
6
6
7
7
import android.app.Application
8
8
import android.content.Intent
9
+ import kotlinx.coroutines.*
9
10
import mozilla.components.lib.fetch.httpurlconnection.HttpURLConnectionClient
10
11
import mozilla.components.service.experiments.Configuration as ExperimentsConfig
11
12
import mozilla.components.service.glean.Glean
13
+ import mozilla.components.service.glean.Experiments as Exp
12
14
import mozilla.components.service.glean.config.Configuration
13
15
import mozilla.components.service.glean.net.ConceptFetchHttpUploader
14
16
import mozilla.components.service.experiments.Experiments
17
+ import mozilla.components.service.glean.RustHttpConfig
15
18
import mozilla.components.support.base.log.Log
16
19
import mozilla.components.support.base.log.sink.AndroidLogSink
17
20
import org.mozilla.samples.glean.GleanMetrics.Basic
18
21
import org.mozilla.samples.glean.GleanMetrics.Test
19
22
import org.mozilla.samples.glean.GleanMetrics.Custom
20
23
import org.mozilla.samples.glean.GleanMetrics.Pings
24
+ import kotlin.coroutines.CoroutineContext
25
+
21
26
22
27
class GleanApplication : Application () {
23
28
24
29
override fun onCreate () {
25
- super .onCreate()
26
-
27
- // We want the log messages of all builds to go to Android logcat
28
- Log .addSink(AndroidLogSink ())
29
-
30
- // Register the sample application's custom pings.
31
- Glean .registerPings(Pings )
32
-
33
- // Initialize the Glean library. Ideally, this is the first thing that
34
- // must be done right after enabling logging.
35
- val client by lazy { HttpURLConnectionClient () }
36
- val httpClient = ConceptFetchHttpUploader .fromClient(client)
37
- val config = Configuration (httpClient = httpClient)
38
- Glean .initialize(applicationContext, uploadEnabled = true , configuration = config)
39
-
40
- // Initialize the Experiments library and pass in the callback that will generate a
41
- // broadcast Intent to signal the application that experiments have been updated. This is
42
- // only relevant to the experiments library, aside from recording the experiment in Glean.
43
- Experiments .initialize(applicationContext, ExperimentsConfig (httpClient = client)) {
44
- val intent = Intent ()
45
- intent.action = " org.mozilla.samples.glean.experiments.updated"
46
- sendBroadcast(intent)
47
- }
30
+ super .onCreate()
31
+ // We want the log messages of all builds to go to Android logcat
32
+ Log .addSink(AndroidLogSink ())
33
+
34
+ // Register the sample application's custom pings.
35
+ Glean .registerPings(Pings )
48
36
49
- Test .timespan.start()
37
+ // Initialize the Glean library. Ideally, this is the first thing that
38
+ // must be done right after enabling logging.
39
+ val client by lazy { HttpURLConnectionClient () }
40
+ val httpClient = ConceptFetchHttpUploader .fromClient(client)
41
+ val config = Configuration (httpClient = httpClient)
42
+ Glean .initialize(applicationContext, uploadEnabled = true , configuration = config)
43
+ RustHttpConfig .setClient(lazy { HttpURLConnectionClient () })
44
+ Thread {
45
+ GlobalScope .launch {
46
+ var exp = mozilla.components.service.glean.Experiments
47
+ exp.initialize(" https://kinto.dev.mozaws.net/v1/" ,
48
+ " messaging-collection" ,
49
+ " main" ,
50
+ applicationContext.dataDir.path)
51
+ val res = exp.getBranch(" button-color" )
52
+ println (res)
53
+ }
54
+ }.start()
55
+ // Initialize the Experiments library and pass in the callback that will generate a
56
+ // broadcast Intent to signal the application that experiments have been updated. This is
57
+ // only relevant to the experiments library, aside from recording the experiment in Glean.
58
+ Experiments .initialize(applicationContext, ExperimentsConfig (httpClient = client)) {
59
+ val intent = Intent ()
60
+ intent.action = " org.mozilla.samples.glean.experiments.updated"
61
+ sendBroadcast(intent)
62
+ }
50
63
51
- Custom .counter.add ()
64
+ Test .timespan.start ()
52
65
53
- // Set a sample value for a metric.
54
- Basic .os.set(" Android" )
66
+ Custom .counter.add()
67
+
68
+ // Set a sample value for a metric.
69
+ Basic .os.set(" Android" )
70
+ }
55
71
}
56
- }
0 commit comments