曹妃甸核酸检测平台.apk(点击下载) / NetDetector.java


package com.netease.nrtc;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.SparseArray;
import com.netease.nrtc.engine.rawapi.IRtcNetDetectHandler;
import com.netease.nrtc.engine.rawapi.RtcNetDetectResult;
import com.netease.nrtc.monitor.d;
import com.netease.nrtc.utility.c.c;
import com.netease.nrtc.utility.l;
import com.netease.yunxin.base.annotation.GuardedBy;
import com.netease.yunxin.base.annotation.Keep;
import com.netease.yunxin.base.http.HttpStack;
import com.netease.yunxin.base.trace.Trace;
import com.netease.yunxin.base.utils.StringUtils;
import com.netease.yunxin.base.utils.jni.LibraryUtils;
import cz.msebera.android.httpclient.HttpHost;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

@Keep
public class NetDetector {

    /* renamed from: a  reason: collision with root package name */
    private static final AtomicInteger f10251a = new AtomicInteger(0);

    /* renamed from: b  reason: collision with root package name */
    private static NetDetector f10252b;

    /* renamed from: c  reason: collision with root package name */
    private Context f10253c;
    @GuardedBy("mTasks")

    /* renamed from: d  reason: collision with root package name */
    private final SparseArray<a> f10254d;

    /* renamed from: e  reason: collision with root package name */
    private long f10255e;

    /* renamed from: f  reason: collision with root package name */
    private boolean f10256f;

    /* renamed from: g  reason: collision with root package name */
    private Handler f10257g = new Handler(Looper.getMainLooper());

    /* renamed from: h  reason: collision with root package name */
    private String f10258h = "https://nrtc.netease.im/nrtc/detect.action";

    /* access modifiers changed from: private */
    public class a {

        /* renamed from: a  reason: collision with root package name */
        public String f10259a;

        /* renamed from: b  reason: collision with root package name */
        public int f10260b;

        /* renamed from: c  reason: collision with root package name */
        public String f10261c;

        /* renamed from: d  reason: collision with root package name */
        public String f10262d;

        /* renamed from: e  reason: collision with root package name */
        public int f10263e;

        /* renamed from: f  reason: collision with root package name */
        public IRtcNetDetectHandler f10264f;

        /* renamed from: g  reason: collision with root package name */
        public String f10265g;

        /* renamed from: h  reason: collision with root package name */
        public String f10266h;

        private a() {
        }

        public String toString() {
            return "Task{id=" + this.f10260b + ", turn='" + this.f10261c + '\'' + ", proxy='" + this.f10262d + '\'' + ", type=" + this.f10263e + ", netType='" + this.f10265g + '\'' + ", mccmnc='" + this.f10266h + '\'' + '}';
        }
    }

    private NetDetector() {
        LibraryUtils.loadLibrary("nrtc_sdk");
        this.f10255e = create();
        this.f10254d = new SparseArray<>();
        this.f10256f = false;
    }

    public static NetDetector a() {
        if (f10252b == null) {
            synchronized (NetDetector.class) {
                if (f10252b == null) {
                    f10252b = new NetDetector();
                }
            }
        }
        return f10252b;
    }

    private void a(IRtcNetDetectHandler iRtcNetDetectHandler, String str, int i, RtcNetDetectResult rtcNetDetectResult) {
        if (iRtcNetDetectHandler != null) {
            this.f10257g.post(new e(rtcNetDetectResult, str, iRtcNetDetectHandler, i));
        }
    }

    /* access modifiers changed from: private */
    public static /* synthetic */ void a(RtcNetDetectResult rtcNetDetectResult, String str, IRtcNetDetectHandler iRtcNetDetectHandler, int i) {
        if (rtcNetDetectResult == null) {
            rtcNetDetectResult = new RtcNetDetectResult();
            rtcNetDetectResult.uuid = str;
        }
        iRtcNetDetectHandler.onDetectResult(i, rtcNetDetectResult);
    }

    /* access modifiers changed from: private */
    public /* synthetic */ void a(String str, IRtcNetDetectHandler iRtcNetDetectHandler, String str2, int i, int i2) {
        int i3;
        int i4;
        HttpStack.HttpStackResponse doPost = HttpStack.doPost(this.f10258h + "?appkey=" + str);
        if (doPost == null) {
            i4 = -1;
        } else {
            int i5 = doPost.code;
            if (i5 != 200) {
                a(iRtcNetDetectHandler, str2, i5, (RtcNetDetectResult) null);
                return;
            }
            String str3 = doPost.result;
            if (StringUtils.isEmpty(str3)) {
                i4 = -2;
            } else {
                try {
                    JSONObject jSONObject = new JSONObject(str3);
                    i3 = jSONObject.optInt("code");
                    if (i3 == 200) {
                        JSONArray optJSONArray = jSONObject.optJSONArray("turnaddrs");
                        HashSet hashSet = new HashSet();
                        if (optJSONArray != null && optJSONArray.length() > 0) {
                            hashSet.add(optJSONArray.getString(0));
                        }
                        JSONArray optJSONArray2 = jSONObject.optJSONArray("proxyaddrs");
                        HashSet hashSet2 = new HashSet();
                        if (optJSONArray2 != null && optJSONArray2.length() > 0) {
                            hashSet2.add(optJSONArray2.getString(0));
                        }
                        HashSet hashSet3 = new HashSet();
                        hashSet3.add(Integer.valueOf(i));
                        if (hashSet.isEmpty()) {
                            i3 = -4;
                        } else {
                            a(hashSet, hashSet2, hashSet3, i2, 1, iRtcNetDetectHandler, str2, 0);
                        }
                    }
                } catch (JSONException unused) {
                    i3 = -3;
                }
                if (i3 != 200) {
                    a(iRtcNetDetectHandler, str2, i3, (RtcNetDetectResult) null);
                    return;
                }
                return;
            }
        }
        a(iRtcNetDetectHandler, str2, i4, (RtcNetDetectResult) null);
    }

    /* JADX WARNING: Code restructure failed: missing block: B:38:0x014e, code lost:
        r0 = r26;
     */
    private void a(Set<String> set, Set<String> set2, Set<Integer> set3, int i, int i2, IRtcNetDetectHandler iRtcNetDetectHandler, String str, int i3) {
        Iterator<String> it2;
        Iterator<Integer> it3;
        int i4;
        IRtcNetDetectHandler iRtcNetDetectHandler2 = iRtcNetDetectHandler;
        d.a(d.i);
        Iterator<String> it4 = set.iterator();
        while (it4.hasNext()) {
            String next = it4.next();
            Iterator<Integer> it5 = set3.iterator();
            while (it5.hasNext()) {
                int intValue = it5.next().intValue();
                int i5 = i2;
                while (true) {
                    int i6 = i5 - 1;
                    if (i5 <= 0) {
                        break;
                    }
                    AnonymousClass1 r9 = null;
                    if (set2.isEmpty()) {
                        a aVar = new a();
                        aVar.f10261c = next;
                        aVar.f10262d = "";
                        aVar.f10263e = intValue;
                        aVar.f10260b = f10251a.incrementAndGet();
                        aVar.f10265g = c.b(c.a(this.f10253c));
                        aVar.f10266h = c.c(this.f10253c);
                        aVar.f10264f = iRtcNetDetectHandler2;
                        aVar.f10259a = str;
                        it2 = it4;
                        it3 = it5;
                        i4 = intValue;
                        if (detect(this.f10255e, (long) aVar.f10260b, aVar.f10263e, i, aVar.f10261c, aVar.f10262d, i3) == 0) {
                            synchronized (this.f10254d) {
                                this.f10254d.put(aVar.f10260b, aVar);
                            }
                            Trace.d("NetDetector", "add detect task:" + aVar.toString());
                        } else {
                            continue;
                        }
                    } else {
                        it2 = it4;
                        it3 = it5;
                        i4 = intValue;
                        for (String str2 : set2) {
                            a aVar2 = new a();
                            aVar2.f10261c = next;
                            aVar2.f10262d = str2;
                            aVar2.f10263e = i4;
                            aVar2.f10260b = f10251a.incrementAndGet();
                            aVar2.f10265g = c.b(c.a(this.f10253c));
                            aVar2.f10266h = c.c(this.f10253c);
                            aVar2.f10264f = iRtcNetDetectHandler2;
                            aVar2.f10259a = str;
                            if (detect(this.f10255e, (long) aVar2.f10260b, aVar2.f10263e, i, aVar2.f10261c, aVar2.f10262d, i3) == 0) {
                                synchronized (this.f10254d) {
                                    this.f10254d.put(aVar2.f10260b, aVar2);
                                }
                                Trace.d("NetDetector", "add detect task:" + aVar2.toString());
                            }
                            iRtcNetDetectHandler2 = iRtcNetDetectHandler;
                            r9 = r9;
                        }
                        continue;
                    }
                    it4 = it2;
                    iRtcNetDetectHandler2 = iRtcNetDetectHandler;
                    intValue = i4;
                    i5 = i6;
                    it5 = it3;
                }
            }
            iRtcNetDetectHandler2 = iRtcNetDetectHandler;
        }
    }

    private void b() {
        long j = this.f10255e;
        if (j != 0) {
            dispose(j);
            this.f10255e = 0;
        }
    }

    private native long create();

    private native int detect(long j, long j2, int i, int i2, String str, String str2, int i3);

    private native void dispose(long j);

    private native void init(long j, String str, String str2, long j2);

    public synchronized String a(String str, int i, int i2, IRtcNetDetectHandler iRtcNetDetectHandler) {
        String uuid;
        d.a(d.i);
        uuid = UUID.randomUUID().toString();
        new Thread(new d(this, str, iRtcNetDetectHandler, uuid, i, i2)).start();
        return uuid;
    }

    public synchronized void a(Context context, String str, String str2) {
        if (!this.f10256f) {
            if (this.f10255e != 0) {
                init(this.f10255e, str, str2, (!l.a(context) || !l.c(context)) ? 6 : 7);
            }
            this.f10253c = context;
            this.f10256f = true;
        }
    }

    public void a(String str) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        if (str.startsWith(HttpHost.DEFAULT_SCHEME_NAME) || str.startsWith("https")) {
            this.f10258h = str;
        }
    }

    public synchronized void a(Set<String> set, final int i, int i2, int i3, IRtcNetDetectHandler iRtcNetDetectHandler) {
        a(set, new HashSet(), new HashSet<Integer>() {
            /* class com.netease.nrtc.NetDetector.AnonymousClass1 */

            {
                add(Integer.valueOf(i));
            }
        }, i2, 1, iRtcNetDetectHandler, null, i3);
    }

    public synchronized void a(Set<String> set, Set<String> set2, Set<Integer> set3, int i, int i2, IRtcNetDetectHandler iRtcNetDetectHandler) {
        a(set, set2, set3, i, i2, iRtcNetDetectHandler, null, 0);
    }

    public synchronized void b(String str) {
        if (!StringUtils.isEmpty(str)) {
            synchronized (this.f10254d) {
                int i = 0;
                while (true) {
                    if (i >= this.f10254d.size()) {
                        break;
                    }
                    a valueAt = this.f10254d.valueAt(i);
                    if (str.equals(valueAt.f10259a)) {
                        valueAt.f10264f = null;
                        break;
                    }
                    i++;
                }
            }
        }
    }

    /* access modifiers changed from: protected */
    public void finalize() throws Throwable {
        super.finalize();
        b();
    }

    /* access modifiers changed from: package-private */
    @Keep
    public synchronized void onDetectResult(long j, int i, int i2, int i3, int i4, int i5, int i6, String str) {
        int i7;
        a aVar;
        synchronized (this.f10254d) {
            i7 = (int) j;
            aVar = this.f10254d.get(i7);
        }
        if (aVar == null || aVar.f10264f == null) {
            Trace.i("NetDetector", "not find task " + j + " info or task callback is null!");
        } else {
            RtcNetDetectResult rtcNetDetectResult = new RtcNetDetectResult();
            rtcNetDetectResult.ip = aVar.f10261c;
            rtcNetDetectResult.proxyIp = aVar.f10262d;
            rtcNetDetectResult.taskType = aVar.f10263e;
            rtcNetDetectResult.netType = aVar.f10265g;
            rtcNetDetectResult.mccmnc = aVar.f10266h;
            rtcNetDetectResult.timestamp = System.currentTimeMillis();
            rtcNetDetectResult.osType = "AOS";
            rtcNetDetectResult.loss = i2;
            rtcNetDetectResult.rttMax = i3;
            rtcNetDetectResult.rttMin = i4;
            rtcNetDetectResult.rttAvg = i5;
            rtcNetDetectResult.rttMdev = i6;
            rtcNetDetectResult.detailInfo = str;
            rtcNetDetectResult.uuid = aVar.f10259a;
            a(aVar.f10264f, aVar.f10259a, i, rtcNetDetectResult);
            Trace.i("NetDetector", "net detect task:" + j + " , code:" + i);
        }
        synchronized (this.f10254d) {
            this.f10254d.remove(i7);
        }
    }
}