Bug 1270963 - Fix NPE in UploadTelemetryCorePingCallback. r=ahunt
MozReview-Commit-ID: HgdZvuuiGDT
--- a/mobile/android/base/java/org/mozilla/gecko/search/SearchEngineManager.java
+++ b/mobile/android/base/java/org/mozilla/gecko/search/SearchEngineManager.java
@@ -79,17 +79,17 @@ public class SearchEngineManager impleme
// This should only be accessed from the background thread.
private String fallbackLocale;
// Cached version of default locale included in Distribution preferences.
// This should only be accessed from the background thread.
private String distributionLocale;
public static interface SearchEngineCallback {
- public void execute(SearchEngine engine);
+ public void execute(@Nullable SearchEngine engine);
}
public SearchEngineManager(Context context, Distribution distribution) {
this.context = context;
this.distribution = distribution;
GeckoSharedPrefs.forApp(context).registerOnSharedPreferenceChangeListener(this);
}
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/UploadTelemetryCorePingCallback.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/UploadTelemetryCorePingCallback.java
@@ -2,16 +2,17 @@
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mozilla.gecko.telemetry;
import android.content.SharedPreferences;
+import android.support.annotation.Nullable;
import android.support.annotation.WorkerThread;
import android.util.Log;
import org.mozilla.gecko.BrowserApp;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.distribution.DistributionStoreCallback;
import org.mozilla.gecko.search.SearchEngineManager;
import org.mozilla.gecko.telemetry.pingbuilders.TelemetryCorePingBuilder;
@@ -31,17 +32,17 @@ public class UploadTelemetryCorePingCall
private final WeakReference<BrowserApp> activityWeakReference;
public UploadTelemetryCorePingCallback(final BrowserApp activity) {
this.activityWeakReference = new WeakReference<>(activity);
}
// May be called from any thread.
@Override
- public void execute(final org.mozilla.gecko.search.SearchEngine engine) {
+ public void execute(@Nullable final org.mozilla.gecko.search.SearchEngine engine) {
// Don't waste resources queueing to the background thread if we don't have a reference.
if (this.activityWeakReference.get() == null) {
return;
}
// The containing method can be called from onStart: queue this work so that
// the first launch of the activity doesn't trigger profile init too early.
//
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/pingbuilders/TelemetryCorePingBuilder.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/pingbuilders/TelemetryCorePingBuilder.java
@@ -167,13 +167,16 @@ public class TelemetryCorePingBuilder ex
}
return (long) Math.floor((double) profileMillis / TimeUnit.DAYS.toMillis(1));
}
/**
* @return the search engine identifier in the format expected by the core ping.
*/
@Nullable
- public static String getEngineIdentifier(final SearchEngine searchEngine) {
+ public static String getEngineIdentifier(@Nullable final SearchEngine searchEngine) {
+ if (searchEngine == null) {
+ return null;
+ }
final String identifier = searchEngine.getIdentifier();
return TextUtils.isEmpty(identifier) ? null : identifier;
}
}