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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrei Lazar 2019-09-25 15:24:34 +00:00
Родитель b57387dc4b
Коммит be3c96389f
2 изменённых файлов: 31 добавлений и 0 удалений

Просмотреть файл

@ -90,6 +90,8 @@ public class TelemetryActivationPingDelegate extends BrowserAppDelegate {
pingBuilder.setClientID(clientID);
}
pingBuilder.setProfileCreationDate(TelemetryActivationPingBuilder.getProfileCreationDate(activity, profile));
getTelemetryDispatcher().queuePingForUpload(activity, pingBuilder);
});
}

Просмотреть файл

@ -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));
}
}