多宝语音 v1.5.0版本的 MD5 值为:dcfcdc4e4f0a662eb0256f88e60f66b1

以下内容为反编译后的 c.java 源代码,内容仅作参考


package com.netease.gslb.core;

import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.SystemClock;
import android.text.TextUtils;
import anet.channel.strategy.dispatch.DispatchConstants;
import anet.channel.util.HttpConstant;
import com.alipay.sdk.app.OpenAuthTask;
import com.huawei.hms.push.constant.RemoteMessageConst;
import com.netease.gslb.core.h.d;
import com.netease.gslb.sdk.NELPGslbState;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class c {

    public static final com.netease.gslb.core.h.c f15290g = com.netease.gslb.core.h.c.c("GslbService");

    public static volatile int f15291h = 1800000;

    public static volatile c f15292i = null;

    public final Handler f15295c;

    public final ExecutorService f15296d;

    public final Map<String, List<p>> f15293a = new LinkedHashMap();

    public q f15297e = d();

    public String f15298f = null;

    public final Handler f15294b = new Handler(Looper.getMainLooper());

    public class a implements Runnable {

        public final com.netease.gslb.core.f f15299a;

        public final String f15300b;

        public a(c cVar, com.netease.gslb.core.f fVar, String str) {
            this.f15299a = fVar;
            this.f15300b = str;
        }

        @Override
        public void run() {
            this.f15299a.onResult(this.f15300b, null);
        }
    }

    public class b implements Runnable {

        public final com.netease.gslb.core.f f15301a;

        public final String f15302b;

        public b(c cVar, com.netease.gslb.core.f fVar, String str) {
            this.f15301a = fVar;
            this.f15302b = str;
        }

        @Override
        public void run() {
            this.f15301a.onResult(this.f15302b, null);
        }
    }

    public class RunnableC0204c implements Runnable {

        public final String f15303a;

        public final com.netease.gslb.core.f f15304b;

        public final q f15305c;

        public class a implements Runnable {
            public a() {
            }

            @Override
            public void run() {
                RunnableC0204c runnableC0204c = RunnableC0204c.this;
                runnableC0204c.f15304b.onResult(runnableC0204c.f15303a, null);
            }
        }

        public class b implements Runnable {

            public final com.netease.gslb.core.a f15308a;

            public b(com.netease.gslb.core.a aVar) {
                this.f15308a = aVar;
            }

            @Override
            public void run() {
                RunnableC0204c runnableC0204c = RunnableC0204c.this;
                runnableC0204c.f15304b.onResult(runnableC0204c.f15303a, this.f15308a);
            }
        }

        public RunnableC0204c(String str, com.netease.gslb.core.f fVar, q qVar) {
            this.f15303a = str;
            this.f15304b = fVar;
            this.f15305c = qVar;
        }

        @Override
        public void run() {
            synchronized (c.this.f15293a) {
                if (!c.this.f(this.f15303a)) {
                    c.this.a(Collections.singletonList(this.f15303a));
                }
                List c11 = c.this.c(this.f15303a);
                if (c11 == null) {
                    c.f15290g.b("queryDetailResult null list");
                    c.this.f15294b.post(new a());
                    return;
                }
                p pVar = (p) c11.get(this.f15305c.f15360a);
                if (pVar.a() == 16) {
                    c.this.b(pVar, this.f15305c);
                }
                com.netease.gslb.core.a aVar = new com.netease.gslb.core.a();
                pVar.f15337a.lock();
                int a11 = pVar.a(28, 3000L);
                aVar.f15274b = new LinkedList();
                if (a11 == 4 && pVar.f15340d.size() > 0) {
                    Iterator it2 = pVar.f15340d.values().iterator();
                    while (it2.hasNext()) {
                        aVar.f15274b.add(c.this.a(this.f15303a, (com.netease.gslb.core.b) it2.next()));
                    }
                } else {
                    aVar.f15274b.add(new com.netease.gslb.core.b(this.f15303a));
                }
                aVar.f15273a = this.f15303a;
                aVar.f15275c = pVar.f15347k;
                aVar.f15276d = pVar.f15342f;
                aVar.f15277e = pVar.f15343g;
                aVar.f15278f = pVar.f15344h;
                aVar.f15279g = pVar.f15345i;
                aVar.f15280h = pVar.f15346j;
                aVar.f15281i = pVar.f15348l;
                aVar.f15282j = pVar.f15349m;
                aVar.f15283k = pVar.f15350n;
                aVar.f15284l = pVar.f15351o;
                aVar.f15285m = pVar.f15352p;
                c.f15290g.a("queryDetailResult done:" + pVar);
                pVar.f15337a.unlock();
                c.this.f15294b.post(new b(aVar));
            }
        }
    }

    public class d implements Runnable {

        public final p f15310a;

        public final q f15311b;

        public d(p pVar, q qVar) {
            this.f15310a = pVar;
            this.f15311b = qVar;
        }

        @Override
        public void run() {
            c.this.a(this.f15310a, this.f15311b);
        }
    }

    public class e implements Runnable {

        public final p f15313a;

        public final q f15314b;

        public e(p pVar, q qVar) {
            this.f15313a = pVar;
            this.f15314b = qVar;
        }

        @Override
        public void run() {
            c.this.a(this.f15313a, this.f15314b);
        }
    }

    public class f implements Runnable {

        public class a implements Runnable {

            public final p f15317a;

            public a(p pVar) {
                this.f15317a = pVar;
            }

            @Override
            public void run() {
                c cVar = c.this;
                cVar.a(this.f15317a, cVar.f15297e);
            }
        }

        public f() {
        }

        @Override
        public void run() {
            q b11 = c.b();
            c.f15290g.a("onNetworkChanged network is form " + c.this.f15297e + " changed to " + b11);
            if (c.this.f15297e != b11) {
                c.this.f15297e = b11;
                if (!c.b(b11)) {
                    synchronized (c.this.f15293a) {
                        Iterator it2 = c.this.f15293a.values().iterator();
                        while (it2.hasNext()) {
                            p pVar = (p) ((List) it2.next()).get(c.this.f15297e.f15360a);
                            pVar.f15337a.lock();
                            if (b11 == q.kNetWorkTypeWifi || pVar.a() == 0 || pVar.a() == 16) {
                                pVar.a(1);
                                c.this.f15296d.submit(new a(pVar));
                            }
                            pVar.f15337a.unlock();
                        }
                    }
                }
            }
        }
    }

    public class g implements Runnable {
        public g() {
        }

        @Override
        public void run() {
            c.this.a(false);
            c.this.f15295c.postDelayed(this, 10000L);
        }
    }

    public class h implements d.c {
        public h() {
        }

        @Override
        public void a() {
            c.this.e();
        }
    }

    public class i implements Comparator<com.netease.gslb.core.b> {
        @Override
        public int compare(com.netease.gslb.core.b bVar, com.netease.gslb.core.b bVar2) {
            int i11 = bVar2.f15289d - bVar.f15289d;
            if (i11 == 0) {
                return bVar2.f15288c - bVar.f15288c;
            }
            return i11;
        }
    }

    public class j implements Runnable {

        public final String f15321a;

        public j(c cVar, String str) {
            this.f15321a = str;
        }

        @Override
        public void run() {
            try {
                InetAddress.getByName(new URI(this.f15321a).getHost()).getHostAddress();
            } catch (Exception unused) {
            }
        }
    }

    public class k implements Runnable {

        public final com.netease.gslb.core.g f15322a;

        public final String f15323b;

        public k(c cVar, com.netease.gslb.core.g gVar, String str) {
            this.f15322a = gVar;
            this.f15323b = str;
        }

        @Override
        public void run() {
            this.f15322a.onResult(this.f15323b, null);
        }
    }

    public class l implements Runnable {

        public final com.netease.gslb.core.g f15324a;

        public final String f15325b;

        public l(c cVar, com.netease.gslb.core.g gVar, String str) {
            this.f15324a = gVar;
            this.f15325b = str;
        }

        @Override
        public void run() {
            this.f15324a.onResult(this.f15325b, null);
        }
    }

    public class m implements Runnable {

        public final com.netease.gslb.core.g f15326a;

        public final String f15327b;

        public m(c cVar, com.netease.gslb.core.g gVar, String str) {
            this.f15326a = gVar;
            this.f15327b = str;
        }

        @Override
        public void run() {
            this.f15326a.onResult(this.f15327b, null);
        }
    }

    public class n implements Runnable {

        public final String f15328a;

        public final com.netease.gslb.core.g f15329b;

        public final q f15330c;

        public class a implements Runnable {
            public a() {
            }

            @Override
            public void run() {
                n nVar = n.this;
                nVar.f15329b.onResult(nVar.f15328a, null);
            }
        }

        public class b implements Runnable {

            public final List f15333a;

            public b(List list) {
                this.f15333a = list;
            }

            @Override
            public void run() {
                n nVar = n.this;
                nVar.f15329b.onResult(nVar.f15328a, this.f15333a);
            }
        }

        public n(String str, com.netease.gslb.core.g gVar, q qVar) {
            this.f15328a = str;
            this.f15329b = gVar;
            this.f15330c = qVar;
        }

        @Override
        public void run() {
            synchronized (c.this.f15293a) {
                if (!c.this.f(this.f15328a)) {
                    c.this.a(Collections.singletonList(this.f15328a));
                }
                List c11 = c.this.c(this.f15328a);
                if (c11 == null) {
                    c.f15290g.b("queryResult null list");
                    c.this.f15294b.post(new a());
                    return;
                }
                p pVar = (p) c11.get(this.f15330c.f15360a);
                if (pVar.a() == 16) {
                    c.this.b(pVar, this.f15330c);
                }
                pVar.f15337a.lock();
                int a11 = pVar.a(28, 3000L);
                LinkedList linkedList = new LinkedList();
                if (a11 == 4 && pVar.f15340d.size() > 0) {
                    Iterator it2 = pVar.f15340d.values().iterator();
                    while (it2.hasNext()) {
                        linkedList.add(c.this.a(this.f15328a, (com.netease.gslb.core.b) it2.next()));
                    }
                } else {
                    linkedList.add(new com.netease.gslb.core.b(this.f15328a));
                }
                c.f15290g.b("queryResult done:" + pVar);
                pVar.f15337a.unlock();
                c.this.f15294b.post(new b(linkedList));
            }
        }
    }

    public class o implements Runnable {

        public final com.netease.gslb.core.f f15335a;

        public final String f15336b;

        public o(c cVar, com.netease.gslb.core.f fVar, String str) {
            this.f15335a = fVar;
            this.f15336b = str;
        }

        @Override
        public void run() {
            this.f15335a.onResult(this.f15336b, null);
        }
    }

    public static class p {

        public final ReentrantLock f15337a;

        public final Condition f15338b;

        public final String f15339c;

        public final Map<String, com.netease.gslb.core.b> f15340d;

        public final q f15341e;

        public long f15342f;

        public long f15343g;

        public long f15344h;

        public long f15345i;

        public long f15346j;

        public int f15347k;

        public boolean f15348l;

        public long f15349m;

        public long f15350n;

        public Exception f15351o;

        public JSONObject f15352p;

        public long f15353q;

        public volatile int f15354r;

        public p(String str, q qVar, g gVar) {
            this(str, qVar);
        }

        public String toString() {
            return "DataManager{originalUrl='" + this.f15339c + "', gslbResults=" + this.f15340d + ", networkType=" + this.f15341e + '}';
        }

        public p(String str, q qVar) {
            ReentrantLock reentrantLock = new ReentrantLock();
            this.f15337a = reentrantLock;
            this.f15338b = reentrantLock.newCondition();
            this.f15340d = new LinkedHashMap();
            this.f15342f = 0L;
            this.f15343g = 0L;
            this.f15344h = 0L;
            this.f15345i = 0L;
            this.f15346j = 0L;
            this.f15347k = 0;
            this.f15348l = false;
            this.f15349m = 0L;
            this.f15350n = 0L;
            this.f15351o = null;
            this.f15352p = null;
            this.f15353q = SystemClock.elapsedRealtime();
            this.f15354r = 0;
            this.f15339c = str;
            this.f15341e = qVar;
        }

        public final int a() {
            this.f15337a.lock();
            int i11 = this.f15354r;
            this.f15337a.unlock();
            return i11;
        }

        public final void a(int i11) {
            this.f15337a.lock();
            this.f15354r = i11;
            this.f15338b.signalAll();
            this.f15337a.unlock();
        }

        public final int a(int i11, long j11) {
            long elapsedRealtime = SystemClock.elapsedRealtime() + j11;
            this.f15337a.lock();
            while ((this.f15354r & i11) == 0 && j11 > 0) {
                try {
                    this.f15338b.await(j11, TimeUnit.MILLISECONDS);
                    j11 = elapsedRealtime - SystemClock.elapsedRealtime();
                } catch (InterruptedException e11) {
                    c.f15290g.b("interruptedException:" + e11);
                    e11.printStackTrace();
                }
            }
            int i12 = this.f15354r;
            this.f15337a.unlock();
            return i12;
        }
    }

    public enum q {
        kNetWorkTypeNone(-1),
        kNetWorkTypeWifi(0),
        kNetWorkTypeCellular(1),
        kNetWorkTypeMax(2);


        public final int f15360a;

        q(int i11) {
            this.f15360a = i11;
        }
    }

    public c() {
        HandlerThread handlerThread = new HandlerThread("NEGslb");
        handlerThread.start();
        Handler handler = new Handler(handlerThread.getLooper());
        this.f15295c = handler;
        handler.postDelayed(new g(), 10000L);
        this.f15296d = new ThreadPoolExecutor(0, 2, 60L, TimeUnit.SECONDS, new com.netease.gslb.core.d());
        com.netease.gslb.core.h.d.a(new h());
    }

    public void g() {
        f15290g.a(com.alipay.sdk.m.x.d.f10565w);
        a(true);
    }

    public void h() {
        f15290g.a("removeAllPullUrls");
        synchronized (this.f15293a) {
            Iterator<List<p>> it2 = this.f15293a.values().iterator();
            while (it2.hasNext()) {
                Iterator<p> it3 = it2.next().iterator();
                while (it3.hasNext()) {
                    it3.next().a(8);
                }
            }
            this.f15293a.clear();
        }
    }

    public static c c() {
        if (f15292i == null) {
            synchronized (c.class) {
                if (f15292i == null) {
                    f15292i = new c();
                }
            }
        }
        return f15292i;
    }

    public static q d() {
        int c11 = com.netease.gslb.core.h.d.c();
        if (c11 == 0) {
            return q.kNetWorkTypeNone;
        }
        if (c11 == 1) {
            return q.kNetWorkTypeWifi;
        }
        if (c11 != 2 && c11 != 3) {
            return q.kNetWorkTypeCellular;
        }
        return q.kNetWorkTypeCellular;
    }

    public static boolean e(String str) {
        return !TextUtils.isEmpty(str) && str.toLowerCase().startsWith("nertc");
    }

    public Map<String, NELPGslbState> f() {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        q d11 = d();
        if (b(d11)) {
            return linkedHashMap;
        }
        synchronized (this.f15293a) {
            for (Map.Entry<String, List<p>> entry : this.f15293a.entrySet()) {
                linkedHashMap.put(entry.getKey(), a(entry.getValue().get(d11.f15360a).f15354r));
            }
        }
        return linkedHashMap;
    }

    public static q b() {
        return d();
    }

    public final void e() {
        this.f15295c.post(new f());
    }

    public final List<p> g(String str) {
        return this.f15293a.remove(b(str));
    }

    public static boolean b(q qVar) {
        return qVar.f15360a <= q.kNetWorkTypeNone.f15360a || qVar.f15360a >= q.kNetWorkTypeMax.f15360a;
    }

    public void b(List<String> list) {
        if (list == null) {
            f15290g.b("removePullUrls, urls is null");
            return;
        }
        for (String str : list) {
            com.netease.gslb.core.h.c cVar = f15290g;
            cVar.a("remove pull url:" + str);
            synchronized (this.f15293a) {
                List<p> g11 = g(str);
                if (g11 != null) {
                    Iterator<p> it2 = g11.iterator();
                    while (it2.hasNext()) {
                        it2.next().a(8);
                    }
                    f15290g.a("removed pull url:" + str);
                } else {
                    cVar.a("no such url in the queue:" + str);
                }
            }
        }
    }

    public static boolean d(String str) {
        return str == null || str.isEmpty() || !(str.startsWith("http") || str.startsWith("https") || str.startsWith("rtmp") || str.startsWith("nertc") || str.startsWith("artc"));
    }

    public final List<p> c(String str) {
        return this.f15293a.get(b(str));
    }

    public void h(String str) {
        f15290g.a("setGslbRequestUrl:" + str);
        this.f15298f = str;
    }

    public static String a(InputStream inputStream) {
        Scanner useDelimiter = new Scanner(inputStream).useDelimiter("\\A");
        return useDelimiter.hasNext() ? useDelimiter.next() : "";
    }

    public final boolean f(String str) {
        return this.f15293a.containsKey(b(str));
    }

    public static void a(p pVar, String str) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        if (!b(d())) {
            pVar.f15340d.clear();
            try {
                JSONObject jSONObject = new JSONObject(str);
                pVar.f15352p = jSONObject;
                JSONArray optJSONArray = jSONObject.optJSONArray("pullUrls");
                if (optJSONArray == null) {
                    pVar.f15340d.put(pVar.f15339c, new com.netease.gslb.core.b(pVar.f15339c));
                    f15290g.b("no pull urls");
                    return;
                }
                ArrayList arrayList = new ArrayList();
                LinkedList<com.netease.gslb.core.b> linkedList = new LinkedList();
                com.netease.gslb.core.b bVar = new com.netease.gslb.core.b(pVar.f15339c);
                bVar.f15288c = 1;
                boolean z11 = false;
                for (int i11 = 0; i11 < optJSONArray.length(); i11++) {
                    JSONObject optJSONObject = optJSONArray.optJSONObject(i11);
                    String optString = optJSONObject.optString("url", "");
                    if (!optString.isEmpty()) {
                        if (optString.equals(pVar.f15339c)) {
                            bVar.f15288c = optJSONObject.optInt(RemoteMessageConst.Notification.PRIORITY, 1);
                            bVar.f15287b = optJSONObject.optString("cdnType", "Unknown");
                        } else {
                            com.netease.gslb.core.b bVar2 = new com.netease.gslb.core.b(optJSONObject.optString("url", ""));
                            arrayList.add(bVar2.f15286a);
                            int optInt = optJSONObject.optInt(RemoteMessageConst.Notification.PRIORITY, 1);
                            bVar2.f15288c = optInt;
                            if (!z11 && optInt > 0 && !pVar.f15339c.startsWith("nertc") && !pVar.f15339c.startsWith("artc")) {
                                z11 = true;
                            }
                            bVar2.f15287b = optJSONObject.optString("cdnType", "Unknown");
                            linkedList.add(bVar2);
                        }
                    }
                }
                if (z11 && linkedList.size() > 1) {
                    pVar.f15349m = System.currentTimeMillis();
                    Map<String, Integer> a11 = com.netease.gslb.core.e.b().a(arrayList, OpenAuthTask.Duplex);
                    for (com.netease.gslb.core.b bVar3 : linkedList) {
                        bVar3.f15289d = (bVar3.f15288c * OpenAuthTask.Duplex) / a11.get(bVar3.f15286a).intValue();
                    }
                    pVar.f15348l = true;
                    pVar.f15350n = System.currentTimeMillis();
                } else {
                    pVar.f15348l = false;
                }
                Collections.sort(linkedList, new i());
                for (com.netease.gslb.core.b bVar4 : linkedList) {
                    pVar.f15340d.put(bVar4.f15286a, bVar4);
                }
                pVar.f15340d.put(bVar.f15286a, bVar);
                return;
            } catch (JSONException e11) {
                f15290g.b("jsonException:" + e11);
                e11.printStackTrace();
                return;
            }
        }
        pVar.a(16);
    }

    public void b(int i11) {
        f15290g.a("setResultValidity:" + i11);
        if (i11 > 0) {
            f15291h = i11 * 1000;
        }
    }

    public final void b(p pVar, q qVar) {
        pVar.a(1);
        this.f15296d.submit(new d(pVar, qVar));
    }

    public final String b(String str) {
        Uri parse = Uri.parse(str);
        return parse.getScheme() + HttpConstant.SCHEME_SPLIT + parse.getHost();
    }

    public static NELPGslbState a(int i11) {
        if (i11 == 2) {
            return NELPGslbState.RUNNING;
        }
        if (i11 != 4) {
            return NELPGslbState.WAITING;
        }
        return NELPGslbState.COMPLETED;
    }

    public synchronized void a(List<String> list) {
        if (list == null) {
            f15290g.b("addPullUrls null urls");
            return;
        }
        Iterator<String> it2 = list.iterator();
        while (it2.hasNext()) {
            a(it2.next());
        }
    }

    public void a(String str) {
        com.netease.gslb.core.h.c cVar = f15290g;
        cVar.a("addPullUrl:" + str);
        if (d(str)) {
            cVar.b("ignore invalid url:" + str);
            return;
        }
        if (e(str)) {
            cVar.a("ignore low delay url:" + str);
            return;
        }
        q d11 = d();
        if (b(d11)) {
            cVar.b("ignore invalid network type:" + d11);
            return;
        }
        synchronized (this.f15293a) {
            if (!f(str)) {
                ArrayList arrayList = new ArrayList(q.kNetWorkTypeMax.f15360a);
                g gVar = null;
                arrayList.add(new p(str, q.kNetWorkTypeWifi, gVar));
                arrayList.add(new p(str, q.kNetWorkTypeCellular, gVar));
                a(str, arrayList);
                p pVar = arrayList.get(d11.f15360a);
                pVar.f15342f = System.currentTimeMillis();
                b(pVar, d11);
                this.f15295c.post(new j(this, str));
            } else {
                cVar.b(str + " was cached, ignored!");
            }
        }
    }

    public Object a(String str, com.netease.gslb.core.g gVar) {
        com.netease.gslb.core.h.c cVar = f15290g;
        cVar.a("queryResult start:" + str);
        if (gVar == null) {
            cVar.b("listener is null");
            return null;
        }
        if (d(str)) {
            cVar.b("queryResult illegal url:" + str);
            this.f15294b.post(new k(this, gVar, str));
            return null;
        }
        if (e(str)) {
            cVar.a("queryResult ignore low delay url:" + str);
            this.f15294b.post(new l(this, gVar, str));
            return null;
        }
        q d11 = d();
        if (b(d11)) {
            cVar.b("queryResult invalid network type");
            this.f15294b.post(new m(this, gVar, str));
            return null;
        }
        Object obj = new Object();
        this.f15295c.postAtTime(new n(str, gVar, d11), obj, SystemClock.uptimeMillis());
        return obj;
    }

    public Object a(String str, com.netease.gslb.core.f fVar) {
        com.netease.gslb.core.h.c cVar = f15290g;
        cVar.a("queryDetailResult start:" + str);
        if (fVar == null) {
            cVar.b("queryDetailResult listener is null");
            return null;
        }
        if (d(str)) {
            cVar.b("queryDetailResult illegal url:" + str);
            this.f15294b.post(new o(this, fVar, str));
            return null;
        }
        if (e(str)) {
            cVar.a("queryDetailResult ignore low delay url:" + str);
            this.f15294b.post(new a(this, fVar, str));
            return null;
        }
        q d11 = d();
        if (b(d11)) {
            cVar.b("queryDetailResult invalid network type");
            this.f15294b.post(new b(this, fVar, str));
            return null;
        }
        Object obj = new Object();
        this.f15295c.postAtTime(new RunnableC0204c(str, fVar, d11), obj, SystemClock.uptimeMillis());
        return obj;
    }

    public void a(Object obj) {
        if (obj != null) {
            this.f15295c.removeCallbacksAndMessages(obj);
        }
    }

    public final void a(p pVar, q qVar) {
        String str;
        HttpURLConnection httpURLConnection;
        int responseCode;
        com.netease.gslb.core.h.c cVar = f15290g;
        cVar.a("doGslb start:" + pVar);
        pVar.f15343g = System.currentTimeMillis();
        if (pVar.a() == 8) {
            cVar.a("doGslb canceled url:" + pVar.f15339c);
            return;
        }
        q d11 = d();
        if (d11 == qVar) {
            pVar.a(2);
            JSONObject a11 = a(pVar.f15339c, qVar);
            String str2 = this.f15298f;
            if (str2 == null || str2.isEmpty()) {
                str = (pVar.f15339c.contains(".live.126.net") || pVar.f15339c.contains(".live.netease.im")) ? "https://gslb.live.netease.im/getpullurl" : "https://gslb.live.netease.im/getvodpullurl";
            } else {
                str = this.f15298f;
            }
            try {
                try {
                    try {
                        try {
                            pVar.f15345i = System.currentTimeMillis();
                            httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
                            byte[] bytes = a11.toString().getBytes("UTF-8");
                            httpURLConnection.setRequestMethod("POST");
                            httpURLConnection.setUseCaches(false);
                            httpURLConnection.setDoInput(true);
                            httpURLConnection.setConnectTimeout(8000);
                            httpURLConnection.setReadTimeout(8000);
                            httpURLConnection.addRequestProperty("origin", "https://appr.tc");
                            httpURLConnection.setDoOutput(true);
                            httpURLConnection.setFixedLengthStreamingMode(bytes.length);
                            httpURLConnection.setRequestProperty(HttpConstant.CONTENT_TYPE, "application/json");
                            httpURLConnection.setRequestProperty(DispatchConstants.DOMAIN, new URI(pVar.f15339c).getHost());
                            httpURLConnection.setRequestProperty("deviceid", com.netease.gslb.core.h.b.a());
                            OutputStream outputStream = httpURLConnection.getOutputStream();
                            outputStream.write(bytes);
                            outputStream.close();
                            responseCode = httpURLConnection.getResponseCode();
                            pVar.f15346j = System.currentTimeMillis();
                            pVar.f15347k = responseCode;
                        } catch (Exception e11) {
                            f15290g.b("doGslb exception:" + e11);
                            e11.printStackTrace();
                            pVar.a(16);
                            pVar.f15351o = e11;
                        }
                    } catch (IllegalArgumentException e12) {
                        f15290g.b("doGslb illegalArgumentException:" + e12);
                        e12.printStackTrace();
                        pVar.a(16);
                        pVar.f15351o = e12;
                    } catch (SocketTimeoutException e13) {
                        f15290g.b("doGslb socketTimeoutException:" + e13);
                        e13.printStackTrace();
                        pVar.a(16);
                        pVar.f15351o = e13;
                    }
                } catch (MalformedURLException e14) {
                    f15290g.b("doGslb malformedURLException:" + e14);
                    e14.printStackTrace();
                    pVar.a(16);
                } catch (IOException e15) {
                    f15290g.b("doGslb ioException:" + e15);
                    e15.printStackTrace();
                    pVar.a(16);
                    pVar.f15351o = e15;
                }
                if (responseCode != 200) {
                    cVar.b("doGslb connection response code is " + responseCode);
                    httpURLConnection.disconnect();
                    pVar.a(16);
                    return;
                }
                InputStream inputStream = httpURLConnection.getInputStream();
                String a12 = a(inputStream);
                inputStream.close();
                httpURLConnection.disconnect();
                if (pVar.a() == 8) {
                    cVar.a("doGslb canceled url:" + pVar.f15339c);
                    return;
                }
                cVar.a("doGslb response:" + a12);
                a(pVar, a12);
                pVar.f15337a.lock();
                pVar.f15353q = SystemClock.elapsedRealtime();
                pVar.a(4);
                cVar.a("doGslb succeeded:" + pVar);
                pVar.f15337a.unlock();
                return;
            } finally {
                pVar.f15344h = System.currentTimeMillis();
            }
        }
        cVar.a("doGslb current network is not invalid" + d11 + ", request network:" + qVar);
        pVar.a(0);
    }

    public final JSONObject a(String str, q qVar) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("domainUrl", str);
            jSONObject.put("sdk_type", 1);
            jSONObject.put("sdk_version", "gslb-1.1.4");
            if (qVar == q.kNetWorkTypeWifi) {
                jSONObject.put("network", 1);
            } else if (qVar == q.kNetWorkTypeCellular) {
                jSONObject.put("network", 4);
            } else {
                jSONObject.put("network", 0);
            }
            jSONObject.put("platform", 2);
            jSONObject.put("sys_version", Build.VERSION.SDK_INT);
            jSONObject.put("device_id", com.netease.gslb.core.h.b.a());
        } catch (JSONException e11) {
            f15290g.b("jsonException:" + e11);
            e11.printStackTrace();
        }
        JSONObject jSONObject2 = new JSONObject();
        try {
            jSONObject2.put("pullUrl", str);
            jSONObject2.put("version", "1.1.4-android");
            jSONObject2.put("sdkParas", jSONObject);
        } catch (JSONException e12) {
            f15290g.b("jsonException:" + e12);
            e12.printStackTrace();
        }
        if (!str.startsWith("nertc") && !str.startsWith("artc")) {
            jSONObject2.put("scene", 0);
            return jSONObject2;
        }
        jSONObject2.put("scene", 1);
        return jSONObject2;
    }

    public final void a(boolean z11) {
        q d11 = d();
        if (b(d11)) {
            return;
        }
        synchronized (this.f15293a) {
            Iterator<List<p>> it2 = this.f15293a.values().iterator();
            while (it2.hasNext()) {
                p pVar = it2.next().get(d11.f15360a);
                pVar.f15337a.lock();
                if (pVar.a() != 1 && pVar.a() != 8) {
                    if (z11 || SystemClock.elapsedRealtime() - pVar.f15353q > f15291h) {
                        f15290g.a("refresh, url:" + pVar.f15339c);
                        pVar.a(1);
                        this.f15296d.submit(new e(pVar, d11));
                    }
                    pVar.f15337a.unlock();
                }
                pVar.f15337a.unlock();
            }
        }
    }

    public final void a(String str, List<p> list) {
        this.f15293a.put(b(str), list);
    }

    public final com.netease.gslb.core.b a(String str, com.netease.gslb.core.b bVar) {
        com.netease.gslb.core.b bVar2;
        try {
            bVar2 = bVar.clone();
        } catch (CloneNotSupportedException e11) {
            e11.printStackTrace();
            bVar2 = null;
        }
        Uri parse = Uri.parse(str);
        Uri parse2 = Uri.parse(bVar.f15286a);
        if (parse.getHost().equalsIgnoreCase(parse2.getHost())) {
            bVar2.f15286a = str;
            return bVar2;
        }
        String replaceFirst = str.replaceFirst(parse.getScheme() + HttpConstant.SCHEME_SPLIT, "");
        Uri.Builder builder = new Uri.Builder();
        builder.scheme(parse.getScheme()).authority(parse2.getHost());
        bVar2.f15286a = builder.build() + "/" + replaceFirst;
        return bVar2;
    }
}