зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1249288
- Add default search engine to core ping. r=rnewman
The default search engine attribute may be null in the core ping if we haven't been able to retrieve the value yet. It's unclear when this might be, but the possibility is in the javadoc of `SearchEngineManager.getEngine`. MozReview-Commit-ID: IrJB6GyjyTO --HG-- extra : rebase_source : 7be9fdf01e57b5eba21842707a42662307dc5bee
This commit is contained in:
Родитель
d71b3f2d7e
Коммит
f7a0910b90
|
@ -58,6 +58,7 @@ import org.mozilla.gecko.reader.ReaderModeUtils;
|
|||
import org.mozilla.gecko.reader.ReadingListHelper;
|
||||
import org.mozilla.gecko.restrictions.Restrictable;
|
||||
import org.mozilla.gecko.restrictions.RestrictedProfileConfiguration;
|
||||
import org.mozilla.gecko.search.SearchEngineManager;
|
||||
import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository;
|
||||
import org.mozilla.gecko.tabqueue.TabQueueHelper;
|
||||
import org.mozilla.gecko.tabqueue.TabQueuePrompt;
|
||||
|
@ -155,6 +156,7 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
@ -288,6 +290,8 @@ public class BrowserApp extends GeckoApp
|
|||
private final DynamicToolbar mDynamicToolbar = new DynamicToolbar();
|
||||
private final ScreenshotObserver mScreenshotObserver = new ScreenshotObserver();
|
||||
|
||||
private SearchEngineManager searchEngineManager;
|
||||
|
||||
@Override
|
||||
public View onCreateView(final String name, final Context context, final AttributeSet attrs) {
|
||||
final View view;
|
||||
|
@ -699,7 +703,10 @@ public class BrowserApp extends GeckoApp
|
|||
"Telemetry:Gather",
|
||||
"Updater:Launch");
|
||||
|
||||
// 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);
|
||||
searchEngineManager = new SearchEngineManager(this, distribution);
|
||||
|
||||
// Init suggested sites engine in BrowserDB.
|
||||
final SuggestedSites suggestedSites = new SuggestedSites(appContext, distribution);
|
||||
|
@ -1414,6 +1421,9 @@ public class BrowserApp extends GeckoApp
|
|||
mZoomedView.destroy();
|
||||
}
|
||||
|
||||
searchEngineManager.destroy();
|
||||
searchEngineManager = null;
|
||||
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener((GeckoEventListener) this,
|
||||
"Gecko:DelayedStartup",
|
||||
"Menu:Open",
|
||||
|
@ -4021,13 +4031,38 @@ public class BrowserApp extends GeckoApp
|
|||
// We store synchronously before sending the Intent to ensure this sequence number will not be re-used.
|
||||
sharedPrefs.edit().putInt(TelemetryConstants.PREF_SEQ_COUNT, seq + 1).commit();
|
||||
|
||||
final Intent i = new Intent(TelemetryConstants.ACTION_UPLOAD_CORE);
|
||||
i.setClass(this, TelemetryUploadService.class);
|
||||
i.putExtra(TelemetryConstants.EXTRA_DOC_ID, UUID.randomUUID().toString());
|
||||
i.putExtra(TelemetryConstants.EXTRA_PROFILE_NAME, profile.getName());
|
||||
i.putExtra(TelemetryConstants.EXTRA_PROFILE_PATH, profile.getDir().toString());
|
||||
i.putExtra(TelemetryConstants.EXTRA_SEQ, seq);
|
||||
startService(i);
|
||||
searchEngineManager.getEngine(new UploadTelemetryCallback(getContext(), seq, profile.getName(), profile.getDir()));
|
||||
}
|
||||
|
||||
private static class UploadTelemetryCallback implements SearchEngineManager.SearchEngineCallback {
|
||||
private final WeakReference<Context> contextWeakReference;
|
||||
private final int seq;
|
||||
private final String profileName;
|
||||
private final String profileDirPath;
|
||||
|
||||
public UploadTelemetryCallback(final Context context, final int seq, final String profileName, final File profileDir) {
|
||||
this.contextWeakReference = new WeakReference<>(context);
|
||||
this.seq = seq;
|
||||
this.profileName = profileName;
|
||||
this.profileDirPath = profileDir.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final org.mozilla.gecko.search.SearchEngine engine) {
|
||||
final Context context = this.contextWeakReference.get();
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Intent i = new Intent(TelemetryConstants.ACTION_UPLOAD_CORE);
|
||||
i.setClass(context, TelemetryUploadService.class);
|
||||
i.putExtra(TelemetryConstants.EXTRA_DEFAULT_SEARCH_ENGINE, engine.getIdentifier());
|
||||
i.putExtra(TelemetryConstants.EXTRA_DOC_ID, UUID.randomUUID().toString());
|
||||
i.putExtra(TelemetryConstants.EXTRA_PROFILE_NAME, this.profileName);
|
||||
i.putExtra(TelemetryConstants.EXTRA_PROFILE_PATH, this.profileDirPath);
|
||||
i.putExtra(TelemetryConstants.EXTRA_SEQ, this.seq);
|
||||
context.startService(i);
|
||||
}
|
||||
}
|
||||
|
||||
public static interface TabStripInterface {
|
||||
|
|
|
@ -16,6 +16,7 @@ public class TelemetryConstants {
|
|||
"Firefox-Android-Telemetry/" + AppConstants.MOZ_APP_VERSION + " (" + AppConstants.MOZ_APP_UA_NAME + ")";
|
||||
|
||||
public static final String ACTION_UPLOAD_CORE = "uploadCore";
|
||||
public static final String EXTRA_DEFAULT_SEARCH_ENGINE = "defaultSearchEngine";
|
||||
public static final String EXTRA_DOC_ID = "docId";
|
||||
public static final String EXTRA_PROFILE_NAME = "geckoProfileName";
|
||||
public static final String EXTRA_PROFILE_PATH = "geckoProfilePath";
|
||||
|
@ -28,11 +29,12 @@ public class TelemetryConstants {
|
|||
private CorePing() { /* To prevent instantiation */ }
|
||||
|
||||
public static final String NAME = "core";
|
||||
public static final int VERSION_VALUE = 1;
|
||||
public static final int VERSION_VALUE = 2; // For version history, see toolkit/components/telemetry/docs/core-ping.rst
|
||||
public static final String OS_VALUE = "Android";
|
||||
|
||||
public static final String ARCHITECTURE = "arch";
|
||||
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 EXPERIMENTS = "experiments";
|
||||
public static final String LOCALE = "locale";
|
||||
|
|
|
@ -7,6 +7,8 @@ package org.mozilla.gecko.telemetry;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.mozilla.gecko.AppConstants;
|
||||
import org.mozilla.gecko.Locales;
|
||||
|
@ -62,14 +64,16 @@ public class TelemetryPingGenerator {
|
|||
* @throws IOException when client ID could not be created
|
||||
*/
|
||||
public static TelemetryPing createCorePing(final Context context, final String docId, final String clientId,
|
||||
final String serverURLSchemeHostPort, final int seq, final long profileCreationDateDays) {
|
||||
final String serverURLSchemeHostPort, final int seq, final long profileCreationDateDays,
|
||||
@Nullable final String defaultSearchEngine) {
|
||||
final String serverURL = getTelemetryServerURL(docId, serverURLSchemeHostPort, CorePing.NAME);
|
||||
final ExtendedJSONObject payload = createCorePingPayload(context, clientId, seq, profileCreationDateDays);
|
||||
final ExtendedJSONObject payload =
|
||||
createCorePingPayload(context, clientId, seq, profileCreationDateDays, defaultSearchEngine);
|
||||
return new TelemetryPing(serverURL, payload);
|
||||
}
|
||||
|
||||
private static ExtendedJSONObject createCorePingPayload(final Context context, final String clientId,
|
||||
final int seq, final long profileCreationDate) {
|
||||
final int seq, final long profileCreationDate, @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);
|
||||
|
@ -82,6 +86,7 @@ public class TelemetryPingGenerator {
|
|||
|
||||
ping.put(CorePing.ARCHITECTURE, AppConstants.ANDROID_CPU_ARCH);
|
||||
ping.put(CorePing.CLIENT_ID, clientId);
|
||||
ping.put(CorePing.DEFAULT_SEARCH_ENGINE, TextUtils.isEmpty(defaultSearchEngine) ? null : defaultSearchEngine);
|
||||
ping.put(CorePing.DEVICE, deviceDescriptor);
|
||||
ping.put(CorePing.LOCALE, Locales.getLanguageTag(Locale.getDefault()));
|
||||
ping.put(CorePing.OS_VERSION, Integer.toString(Build.VERSION.SDK_INT)); // A String for cross-platform reasons.
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.WorkerThread;
|
||||
import android.util.Log;
|
||||
import ch.boye.httpclientandroidlib.HttpResponse;
|
||||
|
@ -81,13 +82,14 @@ public class TelemetryUploadService extends BackgroundService {
|
|||
return;
|
||||
}
|
||||
|
||||
final String defaultSearchEngine = intent.getStringExtra(TelemetryConstants.EXTRA_DEFAULT_SEARCH_ENGINE);
|
||||
final String docId = intent.getStringExtra(TelemetryConstants.EXTRA_DOC_ID);
|
||||
final int seq = intent.getIntExtra(TelemetryConstants.EXTRA_SEQ, -1);
|
||||
|
||||
final String profileName = intent.getStringExtra(TelemetryConstants.EXTRA_PROFILE_NAME);
|
||||
final String profilePath = intent.getStringExtra(TelemetryConstants.EXTRA_PROFILE_PATH);
|
||||
|
||||
uploadCorePing(docId, seq, profileName, profilePath);
|
||||
uploadCorePing(docId, seq, profileName, profilePath, defaultSearchEngine);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -165,7 +167,7 @@ public class TelemetryUploadService extends BackgroundService {
|
|||
|
||||
@WorkerThread
|
||||
private void uploadCorePing(@NonNull final String docId, final int seq, @NonNull final String profileName,
|
||||
@NonNull final String profilePath) {
|
||||
@NonNull final String profilePath, @Nullable final String defaultSearchEngine) {
|
||||
final GeckoProfile profile = GeckoProfile.get(this, profileName, profilePath);
|
||||
final long profileCreationDate = getProfileCreationDate(profile);
|
||||
final String clientId;
|
||||
|
@ -183,7 +185,7 @@ public class TelemetryUploadService extends BackgroundService {
|
|||
sharedPrefs.getString(TelemetryConstants.PREF_SERVER_URL, TelemetryConstants.DEFAULT_SERVER_URL);
|
||||
|
||||
final TelemetryPing corePing = TelemetryPingGenerator.createCorePing(this, docId, clientId,
|
||||
serverURLSchemeHostPort, seq, profileCreationDate);
|
||||
serverURLSchemeHostPort, seq, profileCreationDate, defaultSearchEngine);
|
||||
final CorePingResultDelegate resultDelegate = new CorePingResultDelegate();
|
||||
uploadPing(corePing, resultDelegate);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче