Bug 996753 - Telemetry probes for settings pages. r=liuche
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Mon, 25 Aug 2014 15:28:10 -0700
changeset 223180 ec7f0f0432f58c4e0efb0a24bca7afae8be74a1f
parent 223079 bef8c1d8b3bd76c3cdee88d89e4048c26f3989ec
child 223181 a1a03dfa771a98ae73074f08b7f7cfed30f6777e
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche
bugs996753
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 996753 - Telemetry probes for settings pages. r=liuche
mobile/android/base/TelemetryContract.java
mobile/android/base/preferences/GeckoPreferenceFragment.java
mobile/android/base/preferences/GeckoPreferences.java
--- a/mobile/android/base/TelemetryContract.java
+++ b/mobile/android/base/TelemetryContract.java
@@ -153,16 +153,19 @@ public interface TelemetryContract {
 
         // No method is specified.
         NONE(null),
 
         // Action triggered from a pageaction in the URLBar.
         // Note: Only used in JavaScript for now, but here for completeness.
         PAGEACTION("pageaction"),
 
+        // Action triggered from a settings screen.
+        SETTINGS("settings"),
+
         // Action triggered from a suggestion provided to the user.
         SUGGESTION("suggestion"),
 
         // Action triggered from a SuperToast.
         // Note: Only used in JavaScript for now, but here for completeness.
         TOAST("toast"),
 
         // VALUES BELOW THIS LINE ARE EXCLUSIVE TO TESTING.
@@ -204,16 +207,19 @@ public interface TelemetryContract {
 
         // Started when a Reader viewer becomes active in the foreground.
         // Note: Only used in JavaScript for now, but here for completeness.
         READER("reader.1"),
 
         // Started when the search activity launches.
         SEARCH_ACTIVITY("searchactivity.1"),
 
+        // Settings activity is active.
+        SETTINGS("settings.1"),
+
         // VALUES BELOW THIS LINE ARE EXCLUSIVE TO TESTING.
         _TEST_STARTED_TWICE("_test_session_started_twice.1"),
         _TEST_STOPPED_TWICE("_test_session_stopped_twice.1"),
         ;
 
         private final String string;
 
         Session(final String string) {
--- a/mobile/android/base/preferences/GeckoPreferenceFragment.java
+++ b/mobile/android/base/preferences/GeckoPreferenceFragment.java
@@ -8,16 +8,19 @@ package org.mozilla.gecko.preferences;
 import java.util.Locale;
 
 import org.mozilla.gecko.AppConstants.Versions;
 import org.mozilla.gecko.BrowserLocaleManager;
 import org.mozilla.gecko.GeckoSharedPrefs;
 import org.mozilla.gecko.LocaleManager;
 import org.mozilla.gecko.PrefsHelper;
 import org.mozilla.gecko.R;
+import org.mozilla.gecko.Telemetry;
+import org.mozilla.gecko.TelemetryContract;
+import org.mozilla.gecko.TelemetryContract.Method;
 
 import android.app.ActionBar;
 import android.app.Activity;
 import android.content.Context;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.os.Bundle;
 import android.preference.PreferenceActivity;
@@ -54,16 +57,22 @@ public class GeckoPreferenceFragment ext
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
         // Write prefs to our custom GeckoSharedPrefs file.
         getPreferenceManager().setSharedPreferencesName(GeckoSharedPrefs.APP_PREFS_NAME);
 
         int res = getResource();
+        if (res == R.xml.preferences) {
+            Telemetry.startUISession(TelemetryContract.Session.SETTINGS);
+        } else {
+            final String resourceName = getArguments().getString("resource");
+            Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, Method.SETTINGS, resourceName);
+        }
 
         // Display a menu for Search preferences.
         if (res == R.xml.preferences_search) {
             setHasOptionsMenu(true);
         }
 
         addPreferencesFromResource(res);
 
@@ -190,10 +199,15 @@ public class GeckoPreferenceFragment ext
     }
 
     @Override
     public void onDestroy() {
         super.onDestroy();
         if (mPrefsRequestId > 0) {
             PrefsHelper.removeObserver(mPrefsRequestId);
         }
+
+        final int res = getResource();
+        if (res == R.xml.preferences) {
+            Telemetry.stopUISession(TelemetryContract.Session.SETTINGS);
+        }
     }
 }
\ No newline at end of file
--- a/mobile/android/base/preferences/GeckoPreferences.java
+++ b/mobile/android/base/preferences/GeckoPreferences.java
@@ -333,28 +333,31 @@ OnSharedPreferenceChangeListener
         // fixed in bug 833625).
         if (Versions.preHC) {
             // Write prefs to our custom GeckoSharedPrefs file.
             getPreferenceManager().setSharedPreferencesName(GeckoSharedPrefs.APP_PREFS_NAME);
 
             int res = 0;
             if (intentExtras != null && intentExtras.containsKey(INTENT_EXTRA_RESOURCES)) {
                 // Fetch resource id from intent.
-                String resourceName = intentExtras.getString(INTENT_EXTRA_RESOURCES);
+                final String resourceName = intentExtras.getString(INTENT_EXTRA_RESOURCES);
+                Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, Method.SETTINGS, resourceName);
+
                 if (resourceName != null) {
                     res = getResources().getIdentifier(resourceName, "xml", getPackageName());
                     if (res == 0) {
                         Log.e(LOGTAG, "No resource found named " + resourceName);
                     }
                 }
             }
             if (res == 0) {
                 // No resource specified, or the resource was invalid; use the default preferences screen.
                 Log.e(LOGTAG, "Displaying default settings.");
                 res = R.xml.preferences;
+                Telemetry.startUISession(TelemetryContract.Session.SETTINGS);
             }
 
             // We don't include a title in the XML, so set it here, in a locale-aware fashion.
             updateTitleForPrefsResource(res);
             addPreferencesFromResource(res);
         }
 
         EventDispatcher.getInstance().registerGeckoThreadListener(this,
@@ -471,16 +474,23 @@ OnSharedPreferenceChangeListener
     @Override
     protected void onDestroy() {
         super.onDestroy();
         EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
             "Sanitize:Finished");
         if (mPrefsRequestId > 0) {
             PrefsHelper.removeObserver(mPrefsRequestId);
         }
+
+        // The intent extras will be null if this is the top-level settings
+        // activity. In that case, we want to end the SETTINGS telmetry session.
+        // For HC+ versions of Android this is handled in GeckoPreferenceFragment.
+        if (Versions.preHC && getIntent().getExtras() == null) {
+            Telemetry.stopUISession(TelemetryContract.Session.SETTINGS);
+        }
     }
 
     @Override
     public void onPause() {
         // Symmetric with onResume.
         if (Versions.feature11Plus) {
             if (isMultiPane()) {
                 SharedPreferences prefs = GeckoSharedPrefs.forApp(this);