Bug 1260758 - Add distribution field to Fennec core ping; r=mfinkle,mkaply

This commit is contained in:
Michael Comella 2016-04-13 15:17:13 -05:00
Родитель 094aad9e14
Коммит 05e644fb67
6 изменённых файлов: 47 добавлений и 6 удалений

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

@ -24,6 +24,8 @@ import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.SuggestedSites;
import org.mozilla.gecko.distribution.Distribution;
import org.mozilla.gecko.distribution.Distribution.DistributionDescriptor;
import org.mozilla.gecko.distribution.DistributionStoreCallback;
import org.mozilla.gecko.dlc.DownloadContentService;
import org.mozilla.gecko.dlc.catalog.DownloadContent;
import org.mozilla.gecko.favicons.Favicons;
@ -688,7 +690,9 @@ public class BrowserApp extends GeckoApp
// We want to upload the telemetry core ping as soon after startup as possible. It relies on the
// Distribution being initialized. If you move this initialization, ensure it plays well with telemetry.
Distribution distribution = Distribution.init(this);
final Distribution distribution = Distribution.init(this);
distribution.addOnDistributionReadyCallback(new DistributionStoreCallback(this, getProfile().getName()));
searchEngineManager = new SearchEngineManager(this, distribution);
// Init suggested sites engine in BrowserDB.

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

@ -352,6 +352,34 @@ public class Distribution {
return descFile;
}
public DistributionDescriptor getDescriptor() {
File descFile = getDistributionFile("preferences.json");
if (descFile == null) {
// Logging and existence checks are handled in getDistributionFile.
return null;
}
try {
JSONObject all = new JSONObject(FileUtils.getFileContents(descFile));
if (!all.has("Global")) {
Log.e(LOGTAG, "Distribution preferences.json has no Global entry!");
return null;
}
return new DistributionDescriptor(all.getJSONObject("Global"));
} catch (IOException e) {
Log.e(LOGTAG, "Error getting distribution descriptor file.", e);
Telemetry.addToHistogram(HISTOGRAM_CODE_CATEGORY, CODE_CATEGORY_MALFORMED_DISTRIBUTION);
return null;
} catch (JSONException e) {
Log.e(LOGTAG, "Error parsing preferences.json", e);
Telemetry.addToHistogram(HISTOGRAM_CODE_CATEGORY, CODE_CATEGORY_MALFORMED_DISTRIBUTION);
return null;
}
}
/**
* Get the Android preferences from the preferences.json file, if any exist.
* @return The preferences in a JSONObject, or an empty JSONObject if no preferences are defined.

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

@ -36,6 +36,7 @@ public class TelemetryConstants {
public static final String CLIENT_ID = "clientId";
public static final String DEFAULT_SEARCH_ENGINE = "defaultSearch";
public static final String DEVICE = "device";
public static final String DISTRIBUTION_ID = "distributionId";
public static final String EXPERIMENTS = "experiments";
public static final String LOCALE = "locale";
public static final String OS_ATTR = "os";

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

@ -65,15 +65,16 @@ public class TelemetryPingGenerator {
*/
public static TelemetryPing createCorePing(final Context context, final String docId, final String clientId,
final String serverURLSchemeHostPort, final int seq, final long profileCreationDateDays,
@Nullable final String defaultSearchEngine) {
@Nullable final String distributionId, @Nullable final String defaultSearchEngine) {
final String serverURL = getTelemetryServerURL(docId, serverURLSchemeHostPort, CorePing.NAME);
final ExtendedJSONObject payload =
createCorePingPayload(context, clientId, seq, profileCreationDateDays, defaultSearchEngine);
createCorePingPayload(context, clientId, seq, profileCreationDateDays, distributionId, defaultSearchEngine);
return new TelemetryPing(serverURL, payload);
}
private static ExtendedJSONObject createCorePingPayload(final Context context, final String clientId,
final int seq, final long profileCreationDate, @Nullable final String defaultSearchEngine) {
final int seq, final long profileCreationDate, @Nullable final String distributionId,
@Nullable final String defaultSearchEngine) {
final ExtendedJSONObject ping = new ExtendedJSONObject();
ping.put(CorePing.VERSION_ATTR, CorePing.VERSION_VALUE);
ping.put(CorePing.OS_ATTR, CorePing.OS_VALUE);
@ -93,6 +94,11 @@ public class TelemetryPingGenerator {
ping.put(CorePing.SEQ, seq);
ping.putArray(CorePing.EXPERIMENTS, Experiments.getActiveExperiments(context));
// Optional.
if (distributionId != null) {
ping.put(CorePing.DISTRIBUTION_ID, distributionId);
}
// `null` indicates failure more clearly than < 0.
final Long finalProfileCreationDate = (profileCreationDate < 0) ? null : profileCreationDate;
ping.put(CorePing.PROFILE_CREATION_DATE, finalProfileCreationDate);

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

@ -16,6 +16,7 @@ import ch.boye.httpclientandroidlib.client.ClientProtocolException;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.background.BackgroundService;
import org.mozilla.gecko.distribution.DistributionStoreCallback;
import org.mozilla.gecko.preferences.GeckoPreferences;
import org.mozilla.gecko.sync.net.BaseResource;
import org.mozilla.gecko.sync.net.BaseResourceDelegate;
@ -183,9 +184,9 @@ public class TelemetryUploadService extends BackgroundService {
// TODO (bug 1241685): Sync this preference with the gecko preference.
final String serverURLSchemeHostPort =
sharedPrefs.getString(TelemetryConstants.PREF_SERVER_URL, TelemetryConstants.DEFAULT_SERVER_URL);
final String distributionId = sharedPrefs.getString(DistributionStoreCallback.PREF_DISTRIBUTION_ID, null);
final TelemetryPing corePing = TelemetryPingGenerator.createCorePing(this, docId, clientId,
serverURLSchemeHostPort, seq, profileCreationDate, defaultSearchEngine);
serverURLSchemeHostPort, seq, profileCreationDate, distributionId, defaultSearchEngine);
final CorePingResultDelegate resultDelegate = new CorePingResultDelegate();
uploadPing(corePing, resultDelegate);
}

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

@ -245,6 +245,7 @@ gbjar.sources += ['java/org/mozilla/gecko/' + x for x in [
'db/URLMetadataTable.java',
'DevToolsAuthHelper.java',
'distribution/Distribution.java',
'distribution/DistributionStoreCallback.java',
'distribution/ReferrerDescriptor.java',
'distribution/ReferrerReceiver.java',
'dlc/BaseAction.java',