Bug 1261830 - Content notifications: Stamp telemetry events with experiment session. r?margaret draft
authorSebastian Kaspari <s.kaspari@gmail.com>
Mon, 11 Apr 2016 11:25:39 +0200
changeset 349382 1b9625eebe1d5c8065347a439eae24a47825e957
parent 349381 a003e040f00771f18c84b691a58c09a0c139f953
child 518079 5a6d4b6b780c2c5749d72411e97eb225c871e243
push id15064
push users.kaspari@gmail.com
push dateMon, 11 Apr 2016 09:26:04 +0000
reviewersmargaret
bugs1261830
milestone48.0a1
Bug 1261830 - Content notifications: Stamp telemetry events with experiment session. r?margaret MozReview-Commit-ID: 8Nsdfbe6x74
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/feeds/FeedService.java
mobile/android/base/java/org/mozilla/gecko/feeds/action/CheckForUpdatesAction.java
mobile/android/base/java/org/mozilla/gecko/feeds/action/SubscribeToFeedAction.java
mobile/android/base/java/org/mozilla/gecko/feeds/action/WithdrawSubscriptionsAction.java
mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -3715,18 +3715,22 @@ public class BrowserApp extends GeckoApp
         if (isViewMultipleAction) {
             List<String> urls = intent.getStringArrayListExtra("urls");
             if (urls != null) {
                 openUrls(urls);
             }
 
             // Launched from a "content notification"
             if (intent.hasExtra(CheckForUpdatesAction.EXTRA_CONTENT_NOTIFICATION)) {
+                Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, FeedService.getEnabledExperiment(this));
+
                 Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.NOTIFICATION, "content_update");
                 Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT, "content_update");
+
+                Telemetry.stopUISession(TelemetryContract.Session.EXPERIMENT, FeedService.getEnabledExperiment(this));
             }
         }
 
         if (!mInitialized || !Intent.ACTION_MAIN.equals(action)) {
             return;
         }
 
         // Check to see how many times the app has been launched.
--- a/mobile/android/base/java/org/mozilla/gecko/feeds/FeedService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/feeds/FeedService.java
@@ -143,12 +143,26 @@ public class FeedService extends IntentS
     }
 
     public static boolean isInExperiment(Context context) {
         return SwitchBoard.isInExperiment(context, Experiments.CONTENT_NOTIFICATIONS_12HRS) ||
                SwitchBoard.isInExperiment(context, Experiments.CONTENT_NOTIFICATIONS_5PM) ||
                SwitchBoard.isInExperiment(context, Experiments.CONTENT_NOTIFICATIONS_8AM);
     }
 
+    public static String getEnabledExperiment(Context context) {
+        String experiment = null;
+
+        if (SwitchBoard.isInExperiment(context, Experiments.CONTENT_NOTIFICATIONS_12HRS)) {
+            experiment = Experiments.CONTENT_NOTIFICATIONS_12HRS;
+        } else if (SwitchBoard.isInExperiment(context, Experiments.CONTENT_NOTIFICATIONS_8AM)) {
+            experiment = Experiments.CONTENT_NOTIFICATIONS_8AM;
+        } else if (SwitchBoard.isInExperiment(context, Experiments.CONTENT_NOTIFICATIONS_5PM)) {
+            experiment = Experiments.CONTENT_NOTIFICATIONS_5PM;
+        }
+
+        return experiment;
+    }
+
     private boolean isPreferenceEnabled() {
         return GeckoSharedPrefs.forApp(this).getBoolean(GeckoPreferences.PREFS_NOTIFICATIONS_CONTENT, true);
     }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/feeds/action/CheckForUpdatesAction.java
+++ b/mobile/android/base/java/org/mozilla/gecko/feeds/action/CheckForUpdatesAction.java
@@ -23,16 +23,17 @@ import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.BrowserApp;
 import org.mozilla.gecko.GeckoApp;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.UrlAnnotations;
 import org.mozilla.gecko.feeds.FeedFetcher;
+import org.mozilla.gecko.feeds.FeedService;
 import org.mozilla.gecko.feeds.parser.Feed;
 import org.mozilla.gecko.feeds.subscriptions.FeedSubscription;
 import org.mozilla.gecko.preferences.GeckoPreferences;
 import org.mozilla.gecko.util.StringUtils;
 
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -114,17 +115,19 @@ public class CheckForUpdatesAction exten
         }
 
         if (feedCount == 1) {
             showNotificationForSingleUpdate(updatedFeeds.get(0));
         } else {
             showNotificationForMultipleUpdates(updatedFeeds);
         }
 
+        Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, FeedService.getEnabledExperiment(context));
         Telemetry.sendUIEvent(TelemetryContract.Event.SHOW, TelemetryContract.Method.NOTIFICATION, "content_update");
+        Telemetry.stopUISession(TelemetryContract.Session.EXPERIMENT, FeedService.getEnabledExperiment(context));
     }
 
     private void showNotificationForSingleUpdate(Feed feed) {
         final String date = DateFormat.getMediumDateFormat(context).format(new Date(feed.getLastItem().getTimestamp()));
 
         NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle()
                 .bigText(feed.getLastItem().getTitle())
                 .setBigContentTitle(feed.getTitle())
--- a/mobile/android/base/java/org/mozilla/gecko/feeds/action/SubscribeToFeedAction.java
+++ b/mobile/android/base/java/org/mozilla/gecko/feeds/action/SubscribeToFeedAction.java
@@ -9,16 +9,17 @@ import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
 
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.UrlAnnotations;
 import org.mozilla.gecko.feeds.FeedFetcher;
+import org.mozilla.gecko.feeds.FeedService;
 import org.mozilla.gecko.feeds.subscriptions.FeedSubscription;
 
 /**
  * SubscribeToFeedAction: Try to fetch a feed and create a subscription if successful.
  */
 public class SubscribeToFeedAction extends FeedAction {
     private static final String LOGTAG = "FeedSubscribeAction";
 
@@ -66,11 +67,13 @@ public class SubscribeToFeedAction exten
 
         log("Subscribing to feed: " + response.feed.getTitle());
         log("          Last item: " + response.feed.getLastItem().getTitle());
 
         final FeedSubscription subscription = FeedSubscription.create(feedUrl, response);
 
         urlAnnotations.insertFeedSubscription(context.getContentResolver(), subscription);
 
+        Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, FeedService.getEnabledExperiment(context));
         Telemetry.sendUIEvent(TelemetryContract.Event.SAVE, TelemetryContract.Method.SERVICE, "content_update");
+        Telemetry.stopUISession(TelemetryContract.Session.EXPERIMENT, FeedService.getEnabledExperiment(context));
     }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/feeds/action/WithdrawSubscriptionsAction.java
+++ b/mobile/android/base/java/org/mozilla/gecko/feeds/action/WithdrawSubscriptionsAction.java
@@ -11,16 +11,17 @@ import android.content.Intent;
 import android.database.Cursor;
 
 import org.json.JSONException;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.UrlAnnotations;
+import org.mozilla.gecko.feeds.FeedService;
 import org.mozilla.gecko.feeds.subscriptions.FeedSubscription;
 
 /**
  * WithdrawSubscriptionsAction: Look for feeds to unsubscribe from.
  */
 public class WithdrawSubscriptionsAction extends FeedAction {
     private static final String LOGTAG = "FeedWithdrawAction";
 
@@ -79,17 +80,19 @@ public class WithdrawSubscriptionsAction
             while (cursor.moveToNext()) {
                 final FeedSubscription subscription = FeedSubscription.fromCursor(cursor);
 
                 if (!urlAnnotations.hasWebsiteForFeedUrl(resolver, subscription.getFeedUrl())) {
                     log("Removing subscription for feed: " + subscription.getFeedUrl());
 
                     urlAnnotations.deleteFeedSubscription(resolver, subscription);
 
+                    Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, FeedService.getEnabledExperiment(context));
                     Telemetry.sendUIEvent(TelemetryContract.Event.UNSAVE, TelemetryContract.Method.SERVICE, "content_update");
+                    Telemetry.stopUISession(TelemetryContract.Session.EXPERIMENT, FeedService.getEnabledExperiment(context));
                 }
             }
         } catch (JSONException e) {
             log("Could not deserialize subscription", e);
         } finally {
             cursor.close();
         }
     }
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
@@ -382,17 +382,19 @@ OnSharedPreferenceChangeListener
         if (intentExtras != null && intentExtras.containsKey(DataReportingNotification.ALERT_NAME_DATAREPORTING_NOTIFICATION)) {
             Telemetry.sendUIEvent(TelemetryContract.Event.LAUNCH, Method.NOTIFICATION, "settings-data-choices");
             NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
             notificationManager.cancel(DataReportingNotification.ALERT_NAME_DATAREPORTING_NOTIFICATION.hashCode());
         }
 
         // Launched from "Notifications settings" action button in a notification.
         if (intentExtras != null && intentExtras.containsKey(CheckForUpdatesAction.EXTRA_CONTENT_NOTIFICATION)) {
+            Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, FeedService.getEnabledExperiment(this));
             Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, Method.BUTTON, "notification-settings");
+            Telemetry.stopUISession(TelemetryContract.Session.EXPERIMENT, FeedService.getEnabledExperiment(this));
         }
     }
 
     /**
      * Initializes the action bar configuration in code.
      *
      * Declaring these attributes in XML does not work on some devices for an unknown reason
      * (e.g. the back button stops working or the logo disappears; see bug 1152314) so we