Bug 746938 - Prevent NullPointerException in getNetworkType; r=mounir
authorGeoff Brown <gbrown@mozilla.com>
Mon, 21 May 2012 13:40:49 -0700
changeset 98570 9463528f5c09cfef9397791075347d93d7fca65a
parent 98569 81c7d89d9d0667bd98d4914b4ff272a6f96952bd
child 98571 e0ad3136549b9f9bd86ebebc9c2f10a504244b19
push id1116
push userlsblakk@mozilla.com
push dateMon, 16 Jul 2012 19:38:18 +0000
treeherdermozilla-beta@95f959a8b4dc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmounir
bugs746938
milestone15.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 746938 - Prevent NullPointerException in getNetworkType; r=mounir
embedding/android/GeckoNetworkManager.java
--- a/embedding/android/GeckoNetworkManager.java
+++ b/embedding/android/GeckoNetworkManager.java
@@ -181,37 +181,49 @@ public class GeckoNetworkManager
       stopListening();
     }
   }
 
   private static NetworkType getNetworkType() {
     ConnectivityManager cm =
       (ConnectivityManager)GeckoApp.mAppContext.getSystemService(Context.CONNECTIVITY_SERVICE);
 
-    if (cm.getActiveNetworkInfo() == null) {
+    if (cm == null) {
+      Log.w("GeckoNetworkManager", "Could not access Connectivity service");
       return NetworkType.NETWORK_NONE;
     }
 
-    switch (cm.getActiveNetworkInfo().getType()) {
+    NetworkInfo ni = cm.getActiveNetworkInfo();
+
+    if (ni == null) {
+      return NetworkType.NETWORK_NONE;
+    }
+
+    switch (ni.getType()) {
       case ConnectivityManager.TYPE_ETHERNET:
         return NetworkType.NETWORK_ETHERNET;
       case ConnectivityManager.TYPE_WIFI:
         return NetworkType.NETWORK_WIFI;
       case ConnectivityManager.TYPE_WIMAX:
         return NetworkType.NETWORK_WIMAX;
       case ConnectivityManager.TYPE_MOBILE:
         break; // We will handle sub-types after the switch.
       default:
         Log.w("GeckoNetworkManager", "Ignoring the current network type.");
         return NetworkType.NETWORK_UNKNOWN;
     }
 
     TelephonyManager tm =
       (TelephonyManager)GeckoApp.mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
 
+    if (tm == null) {
+      Log.w("GeckoNetworkManager", "Could not access Telephony service");
+      return NetworkType.NETWORK_UNKNOWN;
+    }
+
     switch (tm.getNetworkType()) {
       case TelephonyManager.NETWORK_TYPE_IDEN:
       case TelephonyManager.NETWORK_TYPE_CDMA:
         return NetworkType.NETWORK_2_G;
       case TelephonyManager.NETWORK_TYPE_GPRS:
       case TelephonyManager.NETWORK_TYPE_1xRTT:
         return NetworkType.NETWORK_2_5_G;
       case TelephonyManager.NETWORK_TYPE_EDGE: