4399游戏盒 v7.2.1.31版本的 MD5 值为:951717f45e3fda95c8a358caf4ca93e1
以下内容为反编译后的 NetworkStatusManager.java 源代码,内容仅作参考
package com.framework.manager.network;
import android.annotation.SuppressLint;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Looper;
import android.os.StrictMode;
import com.framework.utils.AH;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import timber.log.Timber;
public class NetworkStatusManager {
private static int Bn = 1000;
private static NetworkStats Bq;
private static List<NetworkChange> mListeners = new ArrayList();
private static NetworkTestHost Bo = new NetworkTestHost("wwww.baidu.com", 80);
private static NetworkTestHost Bp = new NetworkTestHost("www.4399.cn", 80);
public interface NetworkChange {
void change(NetworkStats networkStats);
}
private static void dC() {
if (Looper.myLooper() == Looper.getMainLooper()) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().build());
}
}
public static boolean checkIsWifi() {
return getCurrentNetwork().checkIsWifi();
}
public static boolean checkIsAvalible() {
return getCurrentNetwork().networkAvalible();
}
@SuppressLint({"MissingPermission"})
private static NetworkInfo dD() {
ConnectivityManager connectivityManager = (ConnectivityManager) AH.getApplication().getSystemService("connectivity");
if (connectivityManager != null) {
try {
return connectivityManager.getActiveNetworkInfo();
} catch (Exception e) {
Timber.e(e);
}
}
return null;
}
public static void onNetworkChanged() {
getCurrentNetwork();
List<NetworkChange> list = mListeners;
for (NetworkChange networkChange : (NetworkChange[]) list.toArray(new NetworkChange[list.size()])) {
networkChange.change(Bq);
}
Timber.d("onNetworkChanged: current net type=" + Bq.getNetworkTypeName(), new Object[0]);
}
public static NetworkStats getCurrentNetwork() {
NetworkInfo dD = dD();
NetworkStats networkStats = Bq;
if (networkStats == null) {
Bq = new NetworkStats(dD);
} else {
networkStats.setNetworkInfo(dD);
}
return Bq;
}
public static synchronized boolean checkReachable() {
boolean a2;
synchronized (NetworkStatusManager.class) {
if (Build.VERSION.SDK_INT > 9) {
dC();
}
a2 = a(Bo);
if (!a2) {
a2 = a(Bp);
}
}
return a2;
}
private static boolean a(NetworkTestHost networkTestHost) {
Socket socket;
if (networkTestHost == null) {
return false;
}
try {
socket = new Socket();
try {
socket.connect(networkTestHost.Address(), Bn);
try {
socket.close();
} catch (Exception e) {
Timber.d("Error while closing socket.", e);
}
return true;
} catch (Exception unused) {
if (socket == null) {
return false;
}
try {
socket.close();
return false;
} catch (Exception e2) {
Timber.d("Error while closing socket.", e2);
return false;
}
} catch (Throwable th) {
th = th;
if (socket != null) {
try {
socket.close();
} catch (Exception e3) {
Timber.d("Error while closing socket.", e3);
}
}
throw th;
}
} catch (Exception unused2) {
socket = null;
} catch (Throwable th2) {
th = th2;
socket = null;
}
}
public static void addNetworkChangeListener(NetworkChange networkChange) {
if (mListeners.contains(networkChange)) {
return;
}
mListeners.add(networkChange);
}
public static void removeNetworkChangeListener(NetworkChange networkChange) {
if (networkChange == null) {
return;
}
mListeners.remove(networkChange);
}
}