@@ -78,9 +78,9 @@ public static String getHostIP() {
7878 public static String networkType (Context context ) {
7979 ConnectivityManager connectivity = (ConnectivityManager ) context .getSystemService (Context .CONNECTIVITY_SERVICE );
8080 NetworkInfo networkInfo = connectivity .getActiveNetworkInfo ();
81- if (connectivity == null || !networkInfo .isConnected ())
81+ if (connectivity == null || !networkInfo .isConnected ()) {
8282 return Constants .NETWORK_CLASS_UNKNOWN ;
83-
83+ }
8484 int netWorkType = connectivity .getActiveNetworkInfo ().getType ();
8585 if (netWorkType == ConnectivityManager .TYPE_WIFI ) {
8686 return Constants .NETWORK_WIFI ;
@@ -91,7 +91,14 @@ public static String networkType(Context context) {
9191 }
9292
9393 private static String getNetWorkClass (Context context ) {
94+ if (context .checkPermission (Manifest .permission .READ_PHONE_STATE , Process .myPid (), Process .myUid ()) != PackageManager .PERMISSION_GRANTED ) {
95+ return Constants .NETWORK_CLASS_UNKNOWN ;
96+ }
97+
9498 TelephonyManager telephonyManager = (TelephonyManager ) context .getSystemService (Context .TELEPHONY_SERVICE );
99+ if (telephonyManager == null ){
100+ return Constants .NETWORK_CLASS_UNKNOWN ;
101+ }
95102
96103 switch (telephonyManager .getNetworkType ()) {
97104 case TelephonyManager .NETWORK_TYPE_GPRS :
@@ -118,7 +125,6 @@ private static String getNetWorkClass(Context context) {
118125 default :
119126 return Constants .NETWORK_CLASS_UNKNOWN ;
120127 }
121-
122128 }
123129
124130 /**
0 commit comments