Bug 1243595 - Add session measurements to core ping builder & update version. r=ahunt draft
authorMichael Comella <michael.l.comella@gmail.com>
Tue, 17 May 2016 17:13:35 -0700
changeset 368041 f748e38737a0e582975b19fd9ee7eb9a2fc43818
parent 368040 bf95b42c4a2f01f424f6f2cdbfedad728715730d
child 368042 37cd71cad6bcf1031261b9fcbb89a5ebfd92a888
push id18421
push usermichael.l.comella@gmail.com
push dateWed, 18 May 2016 00:13:57 +0000
reviewersahunt
bugs1243595
milestone49.0a1
Bug 1243595 - Add session measurements to core ping builder & update version. r=ahunt MozReview-Commit-ID: Erwd83PZ57k
mobile/android/base/java/org/mozilla/gecko/telemetry/pingbuilders/TelemetryCorePingBuilder.java
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/pingbuilders/TelemetryCorePingBuilder.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/pingbuilders/TelemetryCorePingBuilder.java
@@ -37,32 +37,34 @@ import java.util.concurrent.TimeUnit;
  *
  * See https://gecko.readthedocs.org/en/latest/toolkit/components/telemetry/telemetry/core-ping.html
  * for details on the core ping.
  */
 public class TelemetryCorePingBuilder extends TelemetryPingBuilder {
     private static final String LOGTAG = StringUtils.safeSubstring(TelemetryCorePingBuilder.class.getSimpleName(), 0, 23);
 
     private static final String NAME = "core";
-    private static final int VERSION_VALUE = 6; // For version history, see toolkit/components/telemetry/docs/core-ping.rst
+    private static final int VERSION_VALUE = 7; // For version history, see toolkit/components/telemetry/docs/core-ping.rst
     private static final String OS_VALUE = "Android";
 
     private static final String ARCHITECTURE = "arch";
     private static final String CLIENT_ID = "clientId";
     private static final String DEFAULT_SEARCH_ENGINE = "defaultSearch";
     private static final String DEVICE = "device";
     private static final String DISTRIBUTION_ID = "distributionId";
     private static final String EXPERIMENTS = "experiments";
     private static final String LOCALE = "locale";
     private static final String OS_ATTR = "os";
     private static final String OS_VERSION = "osversion";
     private static final String PING_CREATION_DATE = "created";
     private static final String PROFILE_CREATION_DATE = "profileDate";
     private static final String SEARCH_COUNTS = "searches";
     private static final String SEQ = "seq";
+    private static final String SESSION_COUNT = "sessionCount";
+    private static final String SESSION_DURATION = "sessionDuration";
     private static final String TIMEZONE_OFFSET = "tz";
     private static final String VERSION_ATTR = "v";
 
     public TelemetryCorePingBuilder(final Context context) {
         initPayloadConstants(context);
     }
 
     private void initPayloadConstants(final Context context) {
@@ -170,16 +172,36 @@ public class TelemetryCorePingBuilder ex
             // Since this is an increasing value, it's possible we can overflow into negative values and get into a
             // crash loop so we don't crash on invalid arg - we can investigate if we see negative values on the server.
             Log.w(LOGTAG, "Expected positive sequence number. Received: " + seq);
         }
         payload.put(SEQ, seq);
         return this;
     }
 
+    public TelemetryCorePingBuilder setSessionCount(final int sessionCount) {
+        if (sessionCount < 0) {
+            // Since this is an increasing value, it's possible we can overflow into negative values and get into a
+            // crash loop so we don't crash on invalid arg - we can investigate if we see negative values on the server.
+            Log.w(LOGTAG, "Expected positive session count. Received: " + sessionCount);
+        }
+        payload.put(SESSION_COUNT, sessionCount);
+        return this;
+    }
+
+    public TelemetryCorePingBuilder setSessionDuration(final long sessionDuration) {
+        if (sessionDuration < 0) {
+            // Since this is an increasing value, it's possible we can overflow into negative values and get into a
+            // crash loop so we don't crash on invalid arg - we can investigate if we see negative values on the server.
+            Log.w(LOGTAG, "Expected positive session duration. Received: " + sessionDuration);
+        }
+        payload.put(SESSION_DURATION, sessionDuration);
+        return this;
+    }
+
     /**
      * Gets the sequence number from shared preferences and increments it in the prefs. This method
      * is not thread safe.
      */
     @WorkerThread // synchronous shared prefs write.
     public static int getAndIncrementSequenceNumber(final SharedPreferences sharedPrefsForProfile) {
         final int seq = sharedPrefsForProfile.getInt(TelemetryConstants.PREF_SEQ_COUNT, 1);