Commit 8a526203 authored by Andrei Lazar's avatar Andrei Lazar
Browse files

Bug 1572806 - Added profile_date parameter to Telemetry Activation Ping. r=VladBaicu, a=RyanVM

Profile creation date (profile_date) is now embedded in Telemetry Activation Ping.

Differential Revision: https://phabricator.services.mozilla.com/D47097

--HG--
extra : rebase_source : 11e16ff1569ce7b2d2ef37778c55916bcc67067a
extra : source : 7b6ae979745160ea591785e5e98ca773484edb92
parent ed192ce8
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -90,6 +90,8 @@ public class TelemetryActivationPingDelegate extends BrowserAppDelegate {
                pingBuilder.setClientID(clientID);
            }

            pingBuilder.setProfileCreationDate(TelemetryActivationPingBuilder.getProfileCreationDate(activity, profile));

            getTelemetryDispatcher().queuePingForUpload(activity, pingBuilder);
        });
    }
+29 −0
Original line number Diff line number Diff line
@@ -4,8 +4,11 @@ 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;
@@ -17,6 +20,7 @@ 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.
@@ -43,6 +47,7 @@ public class TelemetryActivationPingBuilder extends TelemetryPingBuilder {
    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";
@@ -125,4 +130,28 @@ public class TelemetryActivationPingBuilder extends TelemetryPingBuilder {
        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));
    }
}