Bug 746938 - Prevent NullPointerException in getNetworkType; r=mounir

This commit is contained in:
Geoff Brown 2012-06-21 11:54:35 -07:00
parent 9ed0a5d8ba
commit 1808c270e2

View File

@ -186,12 +186,17 @@ public class GeckoNetworkManager
private static NetworkType getNetworkType() {
ConnectivityManager cm =
(ConnectivityManager)GeckoApp.mAppContext.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm.getActiveNetworkInfo() == null) {
if (cm == null) {
Log.e("GeckoNetworkManager", "Connectivity service does not exist");
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 +212,10 @@ public class GeckoNetworkManager
TelephonyManager tm =
(TelephonyManager)GeckoApp.mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
if (tm == null) {
Log.e("GeckoNetworkManager", "Telephony service does not exist");
return NetworkType.NETWORK_UNKNOWN;
}
switch (tm.getNetworkType()) {
case TelephonyManager.NETWORK_TYPE_IDEN: