Bug 1249288 - Don't call SearchEngineManager change callback if it's null. r=margaret
The callback may be null if setChangeCallback is never called and would cause
a crash.
MozReview-Commit-ID: BNd16Db1A8Q
--- a/mobile/android/base/java/org/mozilla/gecko/search/SearchEngineManager.java
+++ b/mobile/android/base/java/org/mozilla/gecko/search/SearchEngineManager.java
@@ -1,16 +1,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.search;
import android.content.Context;
import android.content.SharedPreferences;
+import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.Locales;
@@ -58,17 +59,17 @@ public class SearchEngineManager impleme
// This should go through GeckoInterface to get the UA, but the search activity
// doesn't use a GeckoView yet. Until it does, get the UA directly.
private static final String USER_AGENT = HardwareUtils.isTablet() ?
AppConstants.USER_AGENT_FENNEC_TABLET : AppConstants.USER_AGENT_FENNEC_MOBILE;
private Context context;
private Distribution distribution;
- private SearchEngineCallback changeCallback;
+ @Nullable private SearchEngineCallback changeCallback;
private SearchEngine engine;
// Cached version of default locale included in Gecko chrome manifest.
// 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.
@@ -132,23 +133,25 @@ public class SearchEngineManager impleme
}
getDefaultEngine(changeCallback);
}
/**
* Runs a SearchEngineCallback on the main thread.
*/
- private void runCallback(final SearchEngine engine, final SearchEngineCallback callback) {
+ private void runCallback(final SearchEngine engine, @Nullable final SearchEngineCallback callback) {
ThreadUtils.postToUiThread(new Runnable() {
@Override
public void run() {
// Cache engine for future calls to getEngine.
SearchEngineManager.this.engine = engine;
- callback.execute(engine);
+ if (callback != null) {
+ callback.execute(engine);
+ }
}
});
}
/**
* This method finds and creates the default search engine. It will first look for
* the default engine name, then create the engine from that name.
*