最右.apk(点击下载) / xz4.java


package defpackage;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import com.alipay.sdk.cons.c;
import com.huawei.hms.push.constant.RemoteMessageConst;
import com.loc.bk;
import com.meituan.robust.Constants;
import java.net.URL;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/* renamed from: xz4  reason: default package */
public final class xz4 {
    public static xz4 i = null;
    public static int j = 1;
    public static int k = 2;

    /* renamed from: a  reason: collision with root package name */
    public long f34633a = 0;

    /* renamed from: b  reason: collision with root package name */
    public ArrayList<String> f34634b = new ArrayList<>();
    public gz4 c = new gz4();
    public gz4 d = new gz4();
    public long e = 120000;
    public Context f;
    public String g;
    public boolean h = false;

    /* renamed from: xz4$a */
    public final class a extends kx4 {

        /* renamed from: b  reason: collision with root package name */
        public final /* synthetic */ int f34635b;

        public a(int i) {
            this.f34635b = i;
        }

        @Override // defpackage.kx4
        public final void a() {
            JSONObject jSONObject;
            int i;
            StringBuilder sb = new StringBuilder("http://");
            sb.append(d05.G());
            sb.append("?host=dualstack-a.apilocate.amap.com&query=");
            sb.append(this.f34635b == xz4.k ? 6 : 4);
            String sb2 = sb.toString();
            yz4 yz4 = new yz4();
            yz4.L(sb2);
            yz4.N(sb2);
            yz4.d(bk.a.SINGLE);
            yz4.f(bk.c.HTTP);
            try {
                gw4.b();
                JSONObject jSONObject2 = new JSONObject(new String(gw4.c(yz4).f29311a));
                String[] n = xz4.n(jSONObject2.optJSONArray("ips"), xz4.j);
                if (n != null && n.length > 0 && !xz4.m(n, xz4.this.j(xz4.j).d())) {
                    xz4.this.j(xz4.j).c(n);
                    xz4.this.r(xz4.j);
                }
                String[] n2 = xz4.n(jSONObject2.optJSONArray("ipsv6"), xz4.k);
                if (n2 != null && n2.length > 0 && !xz4.m(n2, xz4.this.j(xz4.k).d())) {
                    xz4.this.j(xz4.k).c(n2);
                    xz4.this.r(xz4.k);
                }
                if ((jSONObject2.has("ips") || jSONObject2.has("ipsv6")) && jSONObject2.has(RemoteMessageConst.TTL) && (i = jSONObject2.getInt(RemoteMessageConst.TTL)) > 30) {
                    xz4.this.e = (long) (i * 1000);
                    return;
                }
                return;
            } catch (Throwable unused) {
            }
            j05.m(xz4.this.f, "O018", jSONObject);
        }
    }

    public xz4(Context context) {
        this.f = context;
    }

    public static synchronized xz4 d(Context context) {
        xz4 xz4;
        synchronized (xz4.class) {
            if (i == null) {
                i = new xz4(context);
            }
            xz4 = i;
        }
        return xz4;
    }

    public static boolean m(String[] strArr, String[] strArr2) {
        if (strArr == null || strArr.length == 0 || strArr2 == null || strArr2.length == 0 || strArr.length != strArr2.length) {
            return false;
        }
        int length = strArr.length;
        for (int i2 = 0; i2 < length; i2++) {
            if (!strArr[i2].equals(strArr2[i2])) {
                return false;
            }
        }
        return true;
    }

    public static String[] n(JSONArray jSONArray, int i2) throws JSONException {
        if (jSONArray == null || jSONArray.length() == 0) {
            return new String[0];
        }
        int length = jSONArray.length();
        String[] strArr = new String[length];
        for (int i3 = 0; i3 < length; i3++) {
            String string = jSONArray.getString(i3);
            if (!TextUtils.isEmpty(string)) {
                if (i2 == k) {
                    string = Constants.ARRAY_TYPE + string + "]";
                }
                strArr[i3] = string;
            }
        }
        return strArr;
    }

    public static String o(int i2) {
        return i2 == k ? "last_ip_6" : "last_ip_4";
    }

    public final String e(a05 a05, int i2) {
        try {
            if (d05.F() && a05 != null) {
                String j2 = a05.j();
                String host = new URL(j2).getHost();
                if (!"http://abroad.apilocate.amap.com/mobile/binary".equals(j2)) {
                    if (!"abroad.apilocate.amap.com".equals(host)) {
                        String str = "apilocate.amap.com".equalsIgnoreCase(host) ? "httpdns.apilocate.amap.com" : host;
                        if (!t05.J(str)) {
                            return null;
                        }
                        String q = q(i2);
                        if (!TextUtils.isEmpty(q)) {
                            a05.c0(j2.replace(host, q));
                            a05.b().put(c.f, str);
                            a05.d0(str);
                            a05.i(i2 == k);
                            return q;
                        }
                    }
                }
            }
        } catch (Throwable unused) {
        }
        return null;
    }

    public final void f(int i2) {
        if (!j(i2).j()) {
            this.f34634b.add(j(i2).e());
            p(i2);
            l(true, i2);
            return;
        }
        p(i2);
    }

    public final void g(boolean z, int i2) {
        j(i2).g(z);
        if (z) {
            String h2 = j(i2).h();
            String e2 = j(i2).e();
            if (!TextUtils.isEmpty(e2) && !e2.equals(h2)) {
                SharedPreferences.Editor c2 = k05.c(this.f, "cbG9jaXA");
                k05.j(c2, o(i2), e2);
                k05.f(c2);
            }
        }
    }

    public final gz4 j(int i2) {
        return i2 == k ? this.d : this.c;
    }

    public final synchronized void l(boolean z, int i2) {
        if (!z) {
            if (!d05.E() && this.h) {
                return;
            }
        }
        if (this.f34633a != 0) {
            long currentTimeMillis = System.currentTimeMillis();
            long j2 = this.f34633a;
            if (currentTimeMillis - j2 < this.e) {
                return;
            }
            if (currentTimeMillis - j2 < 60000) {
                return;
            }
        }
        this.f34633a = System.currentTimeMillis();
        this.h = true;
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
        StringBuffer stringBuffer = new StringBuffer();
        for (StackTraceElement stackTraceElement : stackTrace) {
            stringBuffer.append(stackTraceElement.getClassName() + "(" + stackTraceElement.getMethodName() + ":" + stackTraceElement.getLineNumber() + "),");
        }
        jx4.f().d(new a(i2));
    }

    public final void p(int i2) {
        if (j(i2).i()) {
            SharedPreferences.Editor c2 = k05.c(this.f, "cbG9jaXA");
            k05.g(c2, o(i2));
            k05.f(c2);
            j(i2).b(false);
        }
    }

    public final String q(int i2) {
        String str;
        int i3 = 0;
        l(false, i2);
        String[] d2 = j(i2).d();
        if (d2 == null || d2.length <= 0) {
            s(i2);
            return j(i2).e();
        }
        int length = d2.length;
        while (true) {
            if (i3 >= length) {
                str = null;
                break;
            }
            str = d2[i3];
            if (!this.f34634b.contains(str)) {
                break;
            }
            i3++;
        }
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        j(i2).a(str);
        return str;
    }

    public final void r(int i2) {
        if (j(i2).d() != null && j(i2).d().length > 0) {
            String str = j(i2).d()[0];
            if (!str.equals(this.g) && !this.f34634b.contains(str)) {
                this.g = str;
                SharedPreferences.Editor c2 = k05.c(this.f, "cbG9jaXA");
                k05.j(c2, o(i2), str);
                k05.f(c2);
            }
        }
    }

    public final void s(int i2) {
        String e2 = k05.e(this.f, "cbG9jaXA", o(i2), null);
        if (!TextUtils.isEmpty(e2) && !this.f34634b.contains(e2)) {
            j(i2).a(e2);
            j(i2).f(e2);
            j(i2).b(true);
        }
    }
}