Skip to content

Commit 8c0defd

Browse files
committed
fixed network lint abort
1 parent 70c06d5 commit 8c0defd

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

library/src/main/java/com/qiniu/android/utils/AndroidNetwork.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)