同程有借 v1.0.0版本的 MD5 值为:e33397cdbab33543d0c134ec96d77fb8
以下内容为反编译后的 ExceptionDetector.java 源代码,内容仅作参考
package anet.channel.detect;
import android.text.TextUtils;
import android.util.Pair;
import androidx.core.app.NotificationCompat;
import anet.channel.AwcnConfig;
import anet.channel.GlobalAppRuntimeInfo;
import anet.channel.statist.RequestStatistic;
import anet.channel.status.NetworkStatusHelper;
import anet.channel.strategy.IConnStrategy;
import anet.channel.strategy.StrategyCenter;
import anet.channel.strategy.dispatch.DispatchConstants;
import anet.channel.thread.ThreadPoolExecutorFactory;
import anet.channel.util.ALog;
import com.bonree.sdk.agent.engine.external.Instrumented;
import com.bonree.sdk.agent.engine.external.JSONObjectInstrumentation;
import com.taobao.accs.common.Constants;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Future;
import org.android.netutil.NetUtils;
import org.android.netutil.PingEntry;
import org.android.netutil.PingResponse;
import org.android.netutil.PingTask;
import org.android.spdy.SpdyAgent;
import org.android.spdy.SpdySessionKind;
import org.android.spdy.SpdyVersion;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@Instrumented
public class ExceptionDetector {
long f1956a;
String f1957b;
String f1958c;
String f1959d;
LimitedQueue<Pair<String, Integer>> f1960e = new LimitedQueue<>(10);
public class LimitedQueue<E> extends LinkedList<E> {
private int f1962b;
public LimitedQueue(int i9) {
this.f1962b = i9;
}
@Override
public boolean add(E e9) {
boolean add = super.add(e9);
while (add && size() > this.f1962b) {
super.remove();
}
return add;
}
}
public class a {
String f1963a;
String f1964b;
String f1965c;
Future<PingResponse> f1966d;
Future<PingResponse> f1967e;
Future<PingResponse> f1968f;
private a() {
}
a(ExceptionDetector exceptionDetector, anet.channel.detect.a aVar) {
this();
}
}
public void a() {
NetworkStatusHelper.addStatusChangeListener(new anet.channel.detect.a(this));
}
public void b() throws JSONException {
ALog.e("anet.ExceptionDetector", "network detect start.", null, new Object[0]);
SpdyAgent.getInstance(GlobalAppRuntimeInfo.getContext(), SpdyVersion.SPDY3, SpdySessionKind.NONE_SESSION);
JSONObject jSONObject = new JSONObject();
JSONObject jSONObject2 = new JSONObject();
NetworkStatusHelper.NetworkStatus status = NetworkStatusHelper.getStatus();
jSONObject2.put(NotificationCompat.CATEGORY_STATUS, status.getType());
jSONObject2.put("subType", NetworkStatusHelper.getNetworkSubType());
if (status != NetworkStatusHelper.NetworkStatus.NO) {
if (status.isMobile()) {
jSONObject2.put("apn", NetworkStatusHelper.getApn());
jSONObject2.put("carrier", NetworkStatusHelper.getCarrier());
} else {
jSONObject2.put(DispatchConstants.BSSID, NetworkStatusHelper.getWifiBSSID());
jSONObject2.put("ssid", NetworkStatusHelper.getWifiSSID());
}
jSONObject2.put("proxy", NetworkStatusHelper.getProxyType());
}
jSONObject.put("NetworkInfo", jSONObject2);
String defaultGateway = status.isWifi() ? NetUtils.getDefaultGateway("114.114.114.114") : NetUtils.getPreferNextHop("114.114.114.114", 2);
Future<PingResponse> launch = !TextUtils.isEmpty(defaultGateway) ? new PingTask(defaultGateway, 1000, 3, 0, 0).launch() : null;
a a9 = a("guide-acs.m.taobao.com", this.f1957b);
a a10 = a("gw.alicdn.com", this.f1959d);
a a11 = a("msgacs.m.taobao.com", this.f1958c);
JSONObject jSONObject3 = new JSONObject();
jSONObject3.put("nextHop", defaultGateway);
jSONObject3.put("ping", a(launch));
jSONObject.put("LocalDetect", jSONObject3);
JSONArray jSONArray = new JSONArray();
jSONArray.put(a(a9));
jSONArray.put(a(a10));
jSONArray.put(a(a11));
jSONObject.put("InternetDetect", jSONArray);
JSONObject jSONObject4 = new JSONObject();
Iterator<Pair<String, Integer>> it = this.f1960e.iterator();
while (it.hasNext()) {
Pair<String, Integer> next = it.next();
jSONObject4.put((String) next.first, next.second);
}
jSONObject.put("BizDetect", jSONObject4);
this.f1960e.clear();
ALog.e("anet.ExceptionDetector", "network detect result: " + JSONObjectInstrumentation.toString(jSONObject), null, new Object[0]);
}
public boolean c() {
if (this.f1960e.size() != 10) {
return false;
}
if (NetworkStatusHelper.getStatus() == NetworkStatusHelper.NetworkStatus.NO) {
ALog.e("anet.ExceptionDetector", "no network", null, new Object[0]);
return false;
}
long currentTimeMillis = System.currentTimeMillis();
if (currentTimeMillis < this.f1956a) {
return false;
}
Iterator<Pair<String, Integer>> it = this.f1960e.iterator();
int i9 = 0;
while (it.hasNext()) {
int intValue = ((Integer) it.next().second).intValue();
if (intValue == -202 || intValue == -400 || intValue == -401 || intValue == -405 || intValue == -406) {
i9++;
}
}
boolean z8 = i9 * 2 > 10;
if (z8) {
this.f1956a = currentTimeMillis + 1800000;
}
return z8;
}
public void a(RequestStatistic requestStatistic) {
if (!AwcnConfig.isNetworkDetectEnable()) {
ALog.i("anet.ExceptionDetector", "network detect closed.", null, new Object[0]);
} else {
ThreadPoolExecutorFactory.submitDetectTask(new c(this, requestStatistic));
}
}
private ArrayList<String> a(String str, int i9) {
ArrayList<String> arrayList = new ArrayList<>();
if (TextUtils.isEmpty(str)) {
return arrayList;
}
int i10 = 0;
while (i10 < i9) {
i10++;
PingResponse pingResponse = null;
try {
pingResponse = (PingResponse) new PingTask(str, 0, 1, 0, i10).launch().get();
} catch (Exception unused) {
}
StringBuilder sb = new StringBuilder();
if (pingResponse != null) {
String lastHopIPStr = pingResponse.getLastHopIPStr();
double d9 = pingResponse.getResults()[0].rtt;
int errcode = pingResponse.getErrcode();
if (TextUtils.isEmpty(lastHopIPStr)) {
lastHopIPStr = "*";
}
sb.append("hop=");
sb.append(lastHopIPStr);
sb.append(",rtt=");
sb.append(d9);
sb.append(",errCode=");
sb.append(errcode);
}
arrayList.add(sb.toString());
}
return arrayList;
}
private a a(String str, String str2) {
a aVar = new a(this, null);
aVar.f1963a = str;
try {
aVar.f1964b = InetAddress.getByName(str).getHostAddress();
} catch (UnknownHostException unused) {
}
if (!TextUtils.isEmpty(str2)) {
aVar.f1965c = str2;
} else {
List<IConnStrategy> connStrategyListByHost = StrategyCenter.getInstance().getConnStrategyListByHost(str);
if (connStrategyListByHost != null && !connStrategyListByHost.isEmpty()) {
aVar.f1965c = connStrategyListByHost.get(0).getIp();
}
}
String str3 = !TextUtils.isEmpty(aVar.f1965c) ? aVar.f1965c : aVar.f1964b;
if (!TextUtils.isEmpty(str3)) {
String str4 = str3;
aVar.f1966d = new PingTask(str4, 1000, 3, 0, 0).launch();
aVar.f1967e = new PingTask(str4, 1000, 3, 1172, 0).launch();
aVar.f1968f = new PingTask(str4, 1000, 3, 1432, 0).launch();
}
return aVar;
}
private JSONObject a(a aVar) throws JSONException {
JSONObject jSONObject = new JSONObject();
if (aVar != null && aVar.f1966d != null) {
jSONObject.put(Constants.KEY_HOST, aVar.f1963a);
jSONObject.put("currentIp", aVar.f1965c);
jSONObject.put("localIp", aVar.f1964b);
jSONObject.put("ping", a(aVar.f1966d));
JSONObject jSONObject2 = new JSONObject();
jSONObject2.put("1200", a(aVar.f1967e));
jSONObject2.put("1460", a(aVar.f1968f));
jSONObject.put("MTU", jSONObject2);
if ("guide-acs.m.taobao.com".equals(aVar.f1963a)) {
ArrayList<String> a9 = a(!TextUtils.isEmpty(aVar.f1965c) ? aVar.f1965c : aVar.f1964b, 5);
JSONObject jSONObject3 = new JSONObject();
int i9 = 0;
while (i9 < a9.size()) {
int i10 = i9 + 1;
jSONObject3.put(String.valueOf(i10), a9.get(i9));
i9 = i10;
}
jSONObject.put("traceRoute", jSONObject3);
}
}
return jSONObject;
}
private JSONObject a(Future<PingResponse> future) throws JSONException {
PingEntry[] results;
JSONObject jSONObject = new JSONObject();
if (future == null) {
return jSONObject;
}
PingResponse pingResponse = null;
try {
pingResponse = future.get();
} catch (Exception unused) {
}
if (pingResponse == null) {
return jSONObject;
}
jSONObject.put("errCode", pingResponse.getErrcode());
JSONArray jSONArray = new JSONArray();
for (PingEntry pingEntry : pingResponse.getResults()) {
jSONArray.put("seq=" + pingEntry.seq + ",hop=" + pingEntry.hop + ",rtt=" + pingEntry.rtt);
}
jSONObject.put("response", jSONArray);
return jSONObject;
}
}