summaryrefslogtreecommitdiffstats
path: root/mobile/android/android-components/samples/glean/samples-glean-library
diff options
context:
space:
mode:
Diffstat (limited to 'mobile/android/android-components/samples/glean/samples-glean-library')
-rw-r--r--mobile/android/android-components/samples/glean/samples-glean-library/README.md5
-rw-r--r--mobile/android/android-components/samples/glean/samples-glean-library/build.gradle55
-rw-r--r--mobile/android/android-components/samples/glean/samples-glean-library/metrics.yaml27
-rw-r--r--mobile/android/android-components/samples/glean/samples-glean-library/src/main/AndroidManifest.xml4
-rw-r--r--mobile/android/android-components/samples/glean/samples-glean-library/src/main/java/org/mozilla/samples/glean/library/SamplesGleanLibrary.kt31
5 files changed, 122 insertions, 0 deletions
diff --git a/mobile/android/android-components/samples/glean/samples-glean-library/README.md b/mobile/android/android-components/samples/glean/samples-glean-library/README.md
new file mode 100644
index 0000000000..97a4de14b6
--- /dev/null
+++ b/mobile/android/android-components/samples/glean/samples-glean-library/README.md
@@ -0,0 +1,5 @@
+samples_glean_library is a toy library that uses glean to record metrics. It
+exists simply to show how libraries that are neither the application or glean
+itself can record metrics, and those metrics will be stored and sent as part of
+the [main pings](../../../components/service/glean/docs/pings.md) that glean
+provides.
diff --git a/mobile/android/android-components/samples/glean/samples-glean-library/build.gradle b/mobile/android/android-components/samples/glean/samples-glean-library/build.gradle
new file mode 100644
index 0000000000..68df279fab
--- /dev/null
+++ b/mobile/android/android-components/samples/glean/samples-glean-library/build.gradle
@@ -0,0 +1,55 @@
+/* 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/. */
+
+buildscript {
+ repositories {
+ gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
+ maven {
+ url repository
+ if (gradle.mozconfig.substs.ALLOW_INSECURE_GRADLE_REPOSITORIES) {
+ allowInsecureProtocol = true
+ }
+ }
+ }
+
+ dependencies {
+ classpath "org.mozilla.telemetry:glean-gradle-plugin:${Versions.mozilla_glean}"
+ }
+ }
+}
+
+plugins {
+ id "com.jetbrains.python.envs" version "$python_envs_plugin"
+}
+
+apply plugin: 'com.android.library'
+apply plugin: 'kotlin-android'
+
+android {
+ defaultConfig {
+ minSdkVersion config.minSdkVersion
+ compileSdk config.compileSdkVersion
+ targetSdkVersion config.targetSdkVersion
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ }
+ }
+
+ buildFeatures {
+ buildConfig true
+ }
+
+ namespace 'mozilla.samples.glean.library'
+}
+
+dependencies {
+ implementation project(':service-glean')
+}
+
+apply plugin: "org.mozilla.telemetry.glean-gradle-plugin"
+
diff --git a/mobile/android/android-components/samples/glean/samples-glean-library/metrics.yaml b/mobile/android/android-components/samples/glean/samples-glean-library/metrics.yaml
new file mode 100644
index 0000000000..c999c586cf
--- /dev/null
+++ b/mobile/android/android-components/samples/glean/samples-glean-library/metrics.yaml
@@ -0,0 +1,27 @@
+# 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/.
+
+# This file defines the built-in pings that are recorded by glean telemetry.
+# They are # automatically converted to Kotlin code at build time
+# using the `glean_parser` PyPI package.
+---
+
+$schema: moz://mozilla.org/schemas/glean/metrics/1-0-0
+
+sample_metrics:
+ test:
+ type: counter
+ description: >
+ A simple counter defined in a third-party library
+ # To see the result immediately when pressing the "send ping" button in the
+ # interface, uncomment the following:
+ # send_in_pings:
+ # - baseline
+ bugs:
+ - https://bugzilla.mozilla.org/123456789
+ data_reviews:
+ - N/A
+ notification_emails:
+ - CHANGE-ME@example.com
+ expires: 2100-01-01
diff --git a/mobile/android/android-components/samples/glean/samples-glean-library/src/main/AndroidManifest.xml b/mobile/android/android-components/samples/glean/samples-glean-library/src/main/AndroidManifest.xml
new file mode 100644
index 0000000000..e16cda1d34
--- /dev/null
+++ b/mobile/android/android-components/samples/glean/samples-glean-library/src/main/AndroidManifest.xml
@@ -0,0 +1,4 @@
+<!-- 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/. -->
+<manifest />
diff --git a/mobile/android/android-components/samples/glean/samples-glean-library/src/main/java/org/mozilla/samples/glean/library/SamplesGleanLibrary.kt b/mobile/android/android-components/samples/glean/samples-glean-library/src/main/java/org/mozilla/samples/glean/library/SamplesGleanLibrary.kt
new file mode 100644
index 0000000000..d9d635ddd4
--- /dev/null
+++ b/mobile/android/android-components/samples/glean/samples-glean-library/src/main/java/org/mozilla/samples/glean/library/SamplesGleanLibrary.kt
@@ -0,0 +1,31 @@
+/* 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.samples.glean.library
+
+import mozilla.components.service.glean.Glean
+import mozilla.samples.glean.library.GleanMetrics.SampleMetrics
+
+/**
+ * These are just simple functions to test calling the Glean API
+ * from a third-party library.
+ */
+object SamplesGleanLibrary {
+ /**
+ * Record to a metric defined in *this* library's metrics.yaml file.
+ */
+ fun recordMetric() {
+ SampleMetrics.test.add()
+ }
+
+ /**
+ * Notate an active experiment.
+ */
+ fun recordExperiment() {
+ Glean.setExperimentActive(
+ "third_party_library",
+ "enabled",
+ )
+ }
+}