灵犀直播 v1.0.127版本的 MD5 值为:a63989b077d9456fb57c6835ee2849a1

以下内容为反编译后的 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.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.JSONObject;
public class ExceptionDetector {
    public long f170a;
    public String f171b;
    public String f172c;
    public String f173d;
    public LimitedQueue<Pair<String, Integer>> f174e = new LimitedQueue<>(10);

    public class LimitedQueue<E> extends LinkedList<E> {
        private int f176b;

        public LimitedQueue(int i) {
            this.f176b = i;
        }

        @Override
        public boolean add(E e2) {
            boolean add = super.add(e2);
            while (add && size() > this.f176b) {
                super.remove();
            }
            return add;
        }
    }

    public class a {
        public String f177a;
        public String f178b;
        public String f179c;
        public Future<PingResponse> f180d;
        public Future<PingResponse> f181e;
        public Future<PingResponse> f182f;

        private a() {
        }

        public a(ExceptionDetector exceptionDetector, anet.channel.detect.a aVar) {
            this();
        }
    }

    public void a() {
        NetworkStatusHelper.addStatusChangeListener(new anet.channel.detect.a(this));
    }

    public void b() {
        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 a2 = a("guide-acs.m.taobao.com", this.f171b);
        a a3 = a("gw.alicdn.com", this.f173d);
        a a4 = a("msgacs.m.taobao.com", this.f172c);
        JSONObject jSONObject3 = new JSONObject();
        jSONObject3.put("nextHop", defaultGateway);
        jSONObject3.put("ping", a(launch));
        jSONObject.put("LocalDetect", jSONObject3);
        JSONArray jSONArray = new JSONArray();
        jSONArray.put(a(a2));
        jSONArray.put(a(a3));
        jSONArray.put(a(a4));
        jSONObject.put("InternetDetect", jSONArray);
        JSONObject jSONObject4 = new JSONObject();
        Iterator<Pair<String, Integer>> it = this.f174e.iterator();
        while (it.hasNext()) {
            Pair<String, Integer> next = it.next();
            jSONObject4.put((String) next.first, next.second);
        }
        jSONObject.put("BizDetect", jSONObject4);
        this.f174e.clear();
        ALog.e("anet.ExceptionDetector", "network detect result: " + jSONObject.toString(), null, new Object[0]);
    }

    public boolean c() {
        if (this.f174e.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.f170a) {
            return false;
        }
        Iterator<Pair<String, Integer>> it = this.f174e.iterator();
        int i = 0;
        while (it.hasNext()) {
            int intValue = ((Integer) it.next().second).intValue();
            if (intValue == -202 || intValue == -400 || intValue == -401 || intValue == -405 || intValue == -406) {
                i++;
            }
        }
        boolean z = i * 2 > 10;
        if (z) {
            this.f170a = currentTimeMillis + 1800000;
        }
        return z;
    }

    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 i) {
        ArrayList<String> arrayList = new ArrayList<>();
        if (TextUtils.isEmpty(str)) {
            return arrayList;
        }
        int i2 = 0;
        while (i2 < i) {
            i2++;
            PingResponse pingResponse = null;
            try {
                pingResponse = (PingResponse) new PingTask(str, 0, 1, 0, i2).launch().get();
            } catch (Exception unused) {
            }
            StringBuilder sb = new StringBuilder();
            if (pingResponse != null) {
                String lastHopIPStr = pingResponse.getLastHopIPStr();
                double d2 = pingResponse.getResults()[0].rtt;
                int errcode = pingResponse.getErrcode();
                if (TextUtils.isEmpty(lastHopIPStr)) {
                    lastHopIPStr = "*";
                }
                sb.append("hop=");
                sb.append(lastHopIPStr);
                sb.append(",rtt=");
                sb.append(d2);
                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.f177a = str;
        try {
            aVar.f178b = InetAddress.getByName(str).getHostAddress();
        } catch (UnknownHostException unused) {
        }
        if (!TextUtils.isEmpty(str2)) {
            aVar.f179c = str2;
        } else {
            List<IConnStrategy> connStrategyListByHost = StrategyCenter.getInstance().getConnStrategyListByHost(str);
            if (connStrategyListByHost != null && !connStrategyListByHost.isEmpty()) {
                aVar.f179c = connStrategyListByHost.get(0).getIp();
            }
        }
        String str3 = !TextUtils.isEmpty(aVar.f179c) ? aVar.f179c : aVar.f178b;
        if (!TextUtils.isEmpty(str3)) {
            String str4 = str3;
            aVar.f180d = new PingTask(str4, 1000, 3, 0, 0).launch();
            aVar.f181e = new PingTask(str4, 1000, 3, 1172, 0).launch();
            aVar.f182f = new PingTask(str4, 1000, 3, 1432, 0).launch();
        }
        return aVar;
    }

    private JSONObject a(a aVar) {
        JSONObject jSONObject = new JSONObject();
        if (aVar != null && aVar.f180d != null) {
            jSONObject.put(Constants.KEY_HOST, aVar.f177a);
            jSONObject.put("currentIp", aVar.f179c);
            jSONObject.put("localIp", aVar.f178b);
            jSONObject.put("ping", a(aVar.f180d));
            JSONObject jSONObject2 = new JSONObject();
            jSONObject2.put("1200", a(aVar.f181e));
            jSONObject2.put("1460", a(aVar.f182f));
            jSONObject.put("MTU", jSONObject2);
            if ("guide-acs.m.taobao.com".equals(aVar.f177a)) {
                ArrayList<String> a2 = a(!TextUtils.isEmpty(aVar.f179c) ? aVar.f179c : aVar.f178b, 5);
                JSONObject jSONObject3 = new JSONObject();
                int i = 0;
                while (i < a2.size()) {
                    int i2 = i + 1;
                    jSONObject3.put(String.valueOf(i2), a2.get(i));
                    i = i2;
                }
                jSONObject.put("traceRoute", jSONObject3);
            }
        }
        return jSONObject;
    }

    private JSONObject a(Future<PingResponse> future) {
        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;
    }
}