Bug 1572806 - Added profile_date parameter to Telemetry Activation Ping r=VladBaicu
authorAndrei Lazar <andrei.a.lazar@softvision.ro>
Wed, 25 Sep 2019 15:24:34 +0000
changeset 494933 7b6ae979745160ea591785e5e98ca773484edb92
parent 494932 029511f2fefc2ff0db4c750966cf563e0345aabc
child 494934 f04641fbd14787d57547375aebbfea16abe64f8b
push id114131
push userdluca@mozilla.com
push dateThu, 26 Sep 2019 09:47:34 +0000
treeherdermozilla-inbound@1dc1a755079a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersVladBaicu
bugs1572806
milestone71.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 1572806 - Added profile_date parameter to Telemetry Activation Ping r=VladBaicu Profile creation date (profile_date) is now embedded in Telemetry Activation Ping. Differential Revision: https://phabricator.services.mozilla.com/D47097
mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryActivationPingDelegate.java
mobile/android/base/java/org/mozilla/gecko/telemetry/pingbuilders/TelemetryActivationPingBuilder.java
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryActivationPingDelegate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryActivationPingDelegate.java
@@ -85,16 +85,18 @@ public class TelemetryActivationPingDele
 
             final TelemetryActivationPingBuilder pingBuilder = new TelemetryActivationPingBuilder(activity);
             if (identifier != null) {
                 pingBuilder.setIdentifier(identifier);
             } else {
                 pingBuilder.setClientID(clientID);
             }
 
+            pingBuilder.setProfileCreationDate(TelemetryActivationPingBuilder.getProfileCreationDate(activity, profile));
+
             getTelemetryDispatcher().queuePingForUpload(activity, pingBuilder);
         });
     }
 
     @WorkerThread // via constructor
     private TelemetryDispatcher getTelemetryDispatcher() {
         if (telemetryDispatcher == null) {
             final GeckoProfile profile = GeckoThread.getActiveProfile();
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/pingbuilders/TelemetryActivationPingBuilder.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/pingbuilders/TelemetryActivationPingBuilder.java
@@ -1,27 +1,31 @@
 package org.mozilla.gecko.telemetry.pingbuilders;
 
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.os.Build;
 import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.annotation.WorkerThread;
 
 import org.mozilla.gecko.AppConstants;
+import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.GeckoSharedPrefs;
 import org.mozilla.gecko.Locales;
 import org.mozilla.gecko.distribution.DistributionStoreCallback;
 import org.mozilla.gecko.telemetry.TelemetryOutgoingPing;
 import org.mozilla.gecko.util.DateUtil;
 import org.mozilla.gecko.util.StringUtils;
 
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Locale;
+import java.util.concurrent.TimeUnit;
 
 /**
  * Builds a {@link TelemetryOutgoingPing} representing a activation ping.
  *
  */
 public class TelemetryActivationPingBuilder extends TelemetryPingBuilder {
     private static final String LOGTAG = StringUtils.safeSubstring(TelemetryActivationPingBuilder.class.getSimpleName(), 0, 23);
 
@@ -38,16 +42,17 @@ public class TelemetryActivationPingBuil
     private static final String CLIENT_ID = "clientId";
     private static final String MANUFACTURER = "manufacturer";
     private static final String MODEL = "model";
     private static final String DISTRIBUTION_ID = "distribution_id";
     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 = "profile_date";
     private static final String TIMEZONE_OFFSET = "tz";
     private static final String APP_NAME = "app_name";
     private static final String CHANNEL = "channel";
 
     public TelemetryActivationPingBuilder(final Context context) {
         super(VERSION_VALUE, true);
         initPayloadConstants(context);
     }
@@ -120,9 +125,33 @@ public class TelemetryActivationPingBuil
 
     public TelemetryActivationPingBuilder setClientID(@NonNull final String clientID) {
         if (clientID == null) {
             throw new IllegalArgumentException("Expected non-null clientID");
         }
         payload.put(CLIENT_ID, clientID);
         return this;
     }
+
+    /**
+     * @param date The profile creation date in days to the unix epoch (not millis!), or null if there is an error.
+     */
+    public TelemetryActivationPingBuilder setProfileCreationDate(@Nullable final Long date) {
+        if (date != null && date < 0) {
+            throw new IllegalArgumentException("Expect positive date value. Received: " + date);
+        }
+        payload.put(PROFILE_CREATION_DATE, date);
+        return this;
+    }
+
+    /**
+     * @return the profile creation date in the format expected by
+     *         {@link TelemetryActivationPingBuilder#setProfileCreationDate(Long)}.
+     */
+    @WorkerThread
+    public static Long getProfileCreationDate(final Context context, final GeckoProfile profile) {
+        final long profileMillis = profile.getAndPersistProfileCreationDate(context);
+        if (profileMillis < 0) {
+            return null;
+        }
+        return (long) Math.floor((double) profileMillis / TimeUnit.DAYS.toMillis(1));
+    }
 }