Bug 1243387 - (Part 2) Update SuggestClient to use NetworkUtils. r=mfinkle
--- a/mobile/android/base/java/org/mozilla/gecko/SuggestClient.java
+++ b/mobile/android/base/java/org/mozilla/gecko/SuggestClient.java
@@ -12,20 +12,19 @@ import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import org.json.JSONArray;
import org.mozilla.gecko.annotation.RobocopTarget;
import org.mozilla.gecko.util.HardwareUtils;
import android.content.Context;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
import android.text.TextUtils;
import android.util.Log;
+import org.mozilla.gecko.util.NetworkUtils;
/**
* Use network-based search suggestions.
*/
public class SuggestClient {
private static final String LOGTAG = "GeckoSuggestClient";
// This should go through GeckoInterface to get the UA, but the search activity
@@ -65,17 +64,17 @@ public class SuggestClient {
if (query.equals(mPrevQuery))
return mPrevResults;
ArrayList<String> suggestions = new ArrayList<String>();
if (TextUtils.isEmpty(mSuggestTemplate) || TextUtils.isEmpty(query)) {
return suggestions;
}
- if (!isNetworkConnected() && mCheckNetwork) {
+ if (!NetworkUtils.isConnected(mContext) && mCheckNetwork) {
Log.i(LOGTAG, "Not connected to network");
return suggestions;
}
try {
String encoded = URLEncoder.encode(query, "UTF-8");
String suggestUri = mSuggestTemplate.replace("__searchTerms__", encoded);
@@ -124,29 +123,16 @@ public class SuggestClient {
Log.e(LOGTAG, "Error", e);
}
mPrevQuery = query;
mPrevResults = suggestions;
return suggestions;
}
- private boolean isNetworkConnected() {
- NetworkInfo networkInfo = getActiveNetworkInfo();
- return networkInfo != null && networkInfo.isConnected();
- }
-
- private NetworkInfo getActiveNetworkInfo() {
- ConnectivityManager connectivity = (ConnectivityManager) mContext
- .getSystemService(Context.CONNECTIVITY_SERVICE);
- if (connectivity == null)
- return null;
- return connectivity.getActiveNetworkInfo();
- }
-
private String convertStreamToString(java.io.InputStream is) {
try {
return new java.util.Scanner(is).useDelimiter("\\A").next();
} catch (java.util.NoSuchElementException e) {
return "";
}
}
}