4399游戏盒 v7.2.1.31版本的 MD5 值为:951717f45e3fda95c8a358caf4ca93e1
以下内容为反编译后的 NetworkCheckHandler.java 源代码,内容仅作参考
package com.download.okhttp;
import android.os.Looper;
import android.text.TextUtils;
import com.download.DownloadModel;
import com.download.constance.K;
import com.framework.manager.network.NetworkStatusManager;
import java.net.InetSocketAddress;
import java.net.Socket;
import timber.log.Timber;
public class NetworkCheckHandler {
public interface CallBack {
void onCheck(NetWorkKind netWorkKind);
}
public static void checkNetwork(final DownloadModel downloadModel, final CallBack callBack) {
if (Looper.myLooper() == Looper.getMainLooper()) {
new Thread(new Runnable() {
@Override
public void run() {
NetworkCheckHandler.checkNetwork(DownloadModel.this, callBack);
}
}).start();
}
if (downloadModel == null || callBack == null) {
return;
}
callBack.onCheck(checkNetwork(downloadModel));
}
public static NetWorkKind checkNetwork(DownloadModel downloadModel) {
if (((Boolean) downloadModel.getExtra(K.key.DOWNLOAD_TASK_UNIT_TEST, false)).booleanValue()) {
return NetWorkKind.HasNet;
}
if (downloadModel == null) {
return NetWorkKind.NoNet;
}
if (!NetworkStatusManager.getCurrentNetwork().networkAvalible()) {
return NetWorkKind.UnAvalible;
}
return checkReachable("www.baidu.com");
}
public static NetWorkKind checkReachable(String str) {
Socket socket;
NetWorkKind netWorkKind = NetWorkKind.NoNet;
if (TextUtils.isEmpty(str)) {
throw new NullPointerException("host can't null");
}
Socket socket2 = null;
try {
try {
try {
socket = new Socket();
} catch (Exception e) {
Timber.e(e);
}
} catch (Exception e2) {
e = e2;
}
} catch (Throwable th) {
th = th;
socket = socket2;
}
try {
socket.connect(new InetSocketAddress(str, 80), 4000);
netWorkKind = NetWorkKind.HasNet;
socket.close();
} catch (Exception e3) {
e = e3;
socket2 = socket;
Timber.e(e);
if (socket2 != null) {
socket2.close();
}
return netWorkKind;
} catch (Throwable th2) {
th = th2;
if (socket != null) {
try {
socket.close();
} catch (Exception e4) {
Timber.e(e4);
}
}
throw th;
}
return netWorkKind;
}
}