Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Glean baseline pings integration. (stage 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
daoshengmu committed Oct 10, 2019
1 parent 58b59be commit 16a615e
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 5 deletions.
11 changes: 11 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
plugins {
id "com.jetbrains.python.envs" version "0.0.26"
}

apply plugin: 'com.android.application'
apply from: "$project.rootDir/tools/gradle/versionCode.gradle"
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

def getGitHash = { ->
def stdout = new ByteArrayOutputStream()
Expand Down Expand Up @@ -32,6 +37,11 @@ def getUseDebugSigningOnRelease = { ->
return false
}

// Generate markdown docs for the collected metrics.
ext.gleanGenerateMarkdownDocs = true
ext.gleanDocsDirectory = "$rootDir/docs"
apply from: 'https://github.com/mozilla-mobile/android-components/raw/' + 'v12.0.0' + '/components/service/glean/scripts/sdk_generator.gradle'

android {
compileSdkVersion build_versions.target_sdk
defaultConfig {
Expand Down Expand Up @@ -435,6 +445,7 @@ dependencies {
implementation deps.android_components.ui_autocomplete
implementation deps.android_components.concept_fetch
implementation deps.android_components.lib_fetch
implementation deps.android_components.glean

// Kotlin dependency
implementation deps.kotlin.stdlib
Expand Down
22 changes: 22 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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/.


$schema: moz://mozilla.org/schemas/glean/metrics/1-0-0

metrics:
distribution_name:
type: string
lifetime: application
description: >
The distribution name of this application.
send_in_pings:
- metrics
bugs:
- https://github.com/MozillaReality/FirefoxReality/issues/1420
data_reviews:
- https://github.com/MozillaReality/FirefoxReality/pull/1854
notification_emails:
- [email protected]
expires: "2020-05-01"
16 changes: 16 additions & 0 deletions app/pings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$schema: moz://mozilla.org/schemas/glean/pings/1-0-0

activation:
description: >
This ping is intended to provide a measure of the activation of mobile products.
It's generated when Fenix starts, right after Glean is initialized. It doesn't
include the client_id, since it might be reporting an hashed version of the
Google Advertising ID.
include_client_id: false
bugs:
- 1538011
- 1501822
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/1707#issuecomment-486972209
notification_emails:
- [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.mozilla.vrbrowser.crashreporting.CrashReporterService;
import org.mozilla.vrbrowser.crashreporting.GlobalExceptionHandler;
import org.mozilla.vrbrowser.geolocation.GeolocationWrapper;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.ui.widgets.prompts.ConfirmPromptWidget;
import org.mozilla.vrbrowser.utils.DeviceType;
import org.mozilla.vrbrowser.input.MotionEventGenerator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.res.Configuration;

import org.mozilla.vrbrowser.browser.Places;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.utils.LocaleUtils;

Expand All @@ -26,6 +27,7 @@ public void onCreate() {
mPlaces = new Places(this);

TelemetryWrapper.init(this);
GleanMetricsService.init(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.telemetry.TelemetryHolder;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.utils.DeviceType;
import org.mozilla.vrbrowser.utils.LocaleUtils;
Expand Down Expand Up @@ -116,10 +117,17 @@ public void setTelemetryEnabled(boolean isEnabled) {
final boolean hasEnabled = isTelemetryEnabled();
if (hasEnabled != isEnabled) {
TelemetryWrapper.init(mContext);
GleanMetricsService.init(mContext);
}

TelemetryHolder.get().getConfiguration().setUploadEnabled(isEnabled);
TelemetryHolder.get().getConfiguration().setCollectionEnabled(isEnabled);

if (isEnabled) {
GleanMetricsService.start();
} else {
GleanMetricsService.stop();
}
}

public void setGeolocationData(String aGeolocationData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

import java.util.Locale;

import kotlin.coroutines.Continuation;
import mozilla.components.browser.search.provider.localization.SearchLocalization;
import mozilla.components.browser.search.provider.localization.SearchLocalizationProvider;

public class GeolocationLocalizationProvider extends SearchLocalizationProvider {
public class GeolocationLocalizationProvider implements SearchLocalizationProvider {

private String mCountry;
private String mLanguage;
Expand All @@ -20,20 +22,21 @@ public class GeolocationLocalizationProvider extends SearchLocalizationProvider
mRegion = data.getCountryCode();
}

public SearchLocalization determineRegion(Continuation<? super SearchLocalization> continuation) {
return new SearchLocalization(mLanguage, mCountry, mRegion);
}

@NotNull
@Override
public String getCountry() {
return mCountry;
}

@NotNull
@Override
public String getLanguage() {
return mLanguage;
}

@Nullable
@Override
public String getRegion() {
return mRegion;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.mozilla.vrbrowser.telemetry;

import android.content.Context;
import android.util.Log;

import androidx.annotation.UiThread;

import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.utils.DeviceType;
import org.mozilla.vrbrowser.utils.SystemUtils;
import org.mozilla.vrbrowser.BuildConfig;
import org.mozilla.vrbrowser.GleanMetrics.Metrics;

import mozilla.components.service.glean.Glean;
import mozilla.components.service.glean.config.Configuration;


public class GleanMetricsService {

private final static String APP_NAME = "FirefoxReality";
private static boolean initialized = false;
private final static String LOGTAG = SystemUtils.createLogtag(GleanMetricsService.class);
private static Context context = null;

// We should call this at the application initial stage.
public static void init(Context aContext) {
if (initialized)
return;

context = aContext;
initialized = true;

final boolean telemetryEnabled = SettingsStore.getInstance(aContext).isTelemetryEnabled();
Glean.INSTANCE.setUploadEnabled(telemetryEnabled);
Configuration config = new Configuration(Configuration.DEFAULT_TELEMETRY_ENDPOINT,
BuildConfig.BUILD_TYPE);
Glean.INSTANCE.initialize(aContext, config);

if (!Glean.INSTANCE.isInitialized()) {
Log.d(LOGTAG, "Glean doesn't be initialized yet.");
}

}

// It would be called when users turn on/off the setting of telemetry.
// e.g., SettingsStore.getInstance(context).setTelemetryEnabled();
@UiThread
public static void start() {
Glean.INSTANCE.setUploadEnabled(true);
setStartupMetrics();
}

// It would be called when users turn on/off the setting of telemetry.
// e.g., SettingsStore.getInstance(context).setTelemetryEnabled();
@UiThread
public static void stop() {
Glean.INSTANCE.setUploadEnabled(false);
}

private static void setStartupMetrics() {
Metrics.INSTANCE.distributionName.set(APP_NAME + "_" + (DeviceType.isOculusBuild() ? "oculusvr" : BuildConfig.FLAVOR_platform));
}
}
25 changes: 25 additions & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!-- AUTOGENERATED BY glean_parser. DO NOT EDIT. -->

# Metrics
This document enumerates the metrics collected by this project.
This project may depend on other projects which also collect metrics.
This means you might have to go searching through the dependency tree to get a full picture of everything collected by this project.
Sorry about that.

# Pings

- [metrics](#metrics)


## metrics
This is a built-in ping that is assembled out of the box by the Glean SDK.
See the Glean SDK documentation for the [`metrics` ping](https://mozilla.github.io/glean/book/user/pings/metrics.html).
The following metrics are added to the ping:

| Name | Type | Description | Data reviews | Extras | Expiration |
| --- | --- | --- | --- | --- | --- |
| metrics.distribution_name |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |The distribution name of this application. |[1](https://github.com/MozillaReality/FirefoxReality/pull/1854)||2020-05-01 |


<!-- AUTOGENERATED BY glean_parser. DO NOT EDIT. -->

3 changes: 2 additions & 1 deletion versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def versions = [:]
// GeckoView versions can be found here:
// https://maven.mozilla.org/?prefix=maven2/org/mozilla/geckoview/
versions.gecko_view = "71.0.20190930095343"
versions.android_components = "4.0.0"
versions.android_components = "16.0.0"
versions.mozilla_speech = "1.0.6"
versions.openwnn = "1.3.7"
versions.google_vr = "1.190.0"
Expand Down Expand Up @@ -53,6 +53,7 @@ deps.gecko_view = gecko_view

def android_components = [:]
android_components.telemetry = "org.mozilla.components:service-telemetry:$versions.android_components"
android_components.glean = "org.mozilla.components:service-glean:$versions.android_components"
android_components.browser_errorpages = "org.mozilla.components:browser-errorpages:$versions.android_components"
android_components.browser_search = "org.mozilla.components:browser-search:$versions.android_components"
android_components.browser_storage = "org.mozilla.components:browser-storage-sync:$versions.android_components"
Expand Down

0 comments on commit 16a615e

Please sign in to comment.