Bug 746938 - Prevent NullPointerException in getNetworkType; r=mounir

This commit is contained in:
Geoff Brown 2012-05-21 13:40:49 -07:00
parent 29bff9dcd8
commit 87a7e9e00d

View File

@ -186,11 +186,18 @@ public class GeckoNetworkManager
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:
@ -207,6 +214,11 @@ public class GeckoNetworkManager
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: