package com.loc; import android.content.Context; import android.content.SharedPreferences; import android.text.TextUtils; import com.loc.bl; import com.taobao.weex.el.parse.Operators; import io.dcloud.common.adapter.util.DeviceInfo; import java.net.URL; import java.util.ArrayList; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; /* compiled from: AMapDnsManager */ public final class fc { public static int a = 1; public static int b = 2; private static fc e; private long c = 0; private boolean d = false; private ArrayList<String> f = new ArrayList<>(); private el g = new el(); private el h = new el(); private long i = 120000; private Context j; private String k; private boolean l = false; private fc(Context context) { this.j = context; } public static synchronized fc a(Context context) { fc fcVar; synchronized (fc.class) { if (e == null) { e = new fc(context); } fcVar = e; } return fcVar; } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private el b(int i2) { return i2 == b ? this.h : this.g; } private synchronized void b(boolean z, final int i2) { if (!z) { if (!fi.o() && this.l) { return; } } if (this.c != 0) { long currentTimeMillis = System.currentTimeMillis(); long j2 = this.c; if (currentTimeMillis - j2 < this.i) { return; } if (currentTimeMillis - j2 < 60000) { return; } } this.c = System.currentTimeMillis(); this.l = true; StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); StringBuffer stringBuffer = new StringBuffer(); for (StackTraceElement stackTraceElement : stackTrace) { stringBuffer.append(stackTraceElement.getClassName() + Operators.BRACKET_START_STR + stackTraceElement.getMethodName() + ":" + stackTraceElement.getLineNumber() + "),"); } cj.a().b(new ck() { /* class com.loc.fc.AnonymousClass1 */ @Override // com.loc.ck public final void a() { JSONObject jSONObject; int i; StringBuilder sb = new StringBuilder(DeviceInfo.HTTP_PROTOCOL); sb.append(fi.q()); sb.append("?host=dualstack-a.apilocate.amap.com&query="); sb.append(i2 == fc.b ? 6 : 4); String sb2 = sb.toString(); fd fdVar = new fd(); fdVar.b(sb2); fdVar.c(sb2); fdVar.a(bl.a.SINGLE); fdVar.a(bl.c.HTTP); try { bg.a(); JSONObject jSONObject2 = new JSONObject(new String(bg.a(fdVar).a)); String[] b2 = fc.b(jSONObject2.optJSONArray("ips"), fc.a); if (b2 != null && b2.length > 0 && !fc.b(b2, fc.this.b(fc.a).a())) { fc.this.b(fc.a).a(b2); fc.this.f(fc.a); } String[] b3 = fc.b(jSONObject2.optJSONArray("ipsv6"), fc.b); if (b3 != null && b3.length > 0 && !fc.b(b3, fc.this.b(fc.b).a())) { fc.this.b(fc.b).a(b3); fc.this.f(fc.b); } if ((jSONObject2.has("ips") || jSONObject2.has("ipsv6")) && jSONObject2.has("ttl") && (i = jSONObject2.getInt("ttl")) > 30) { fc.this.i = (long) (i * 1000); return; } return; } catch (Throwable unused) { } fo.a(fc.this.j, "O018", jSONObject); } }); } /* access modifiers changed from: private */ public static boolean b(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; } /* access modifiers changed from: private */ public static String[] b(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 == b) { string = Operators.ARRAY_START_STR + string + Operators.ARRAY_END_STR; } strArr[i3] = string; } } return strArr; } private static String c(int i2) { return i2 == b ? "last_ip_6" : "last_ip_4"; } private void d(int i2) { if (b(i2).d()) { SharedPreferences.Editor a2 = fp.a(this.j, "cbG9jaXA"); fp.a(a2, c(i2)); fp.a(a2); b(i2).a(false); } } private String e(int i2) { String str; int i3 = 0; b(false, i2); String[] a2 = b(i2).a(); if (a2 == null || a2.length <= 0) { g(i2); return b(i2).b(); } int length = a2.length; while (true) { if (i3 >= length) { str = null; break; } str = a2[i3]; if (!this.f.contains(str)) { break; } i3++; } if (TextUtils.isEmpty(str)) { return null; } b(i2).a(str); return str; } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void f(int i2) { if (b(i2).a() != null && b(i2).a().length > 0) { String str = b(i2).a()[0]; if (!str.equals(this.k) && !this.f.contains(str)) { this.k = str; SharedPreferences.Editor a2 = fp.a(this.j, "cbG9jaXA"); fp.a(a2, c(i2), str); fp.a(a2); } } } private void g(int i2) { String a2 = fp.a(this.j, "cbG9jaXA", c(i2), (String) null); if (!TextUtils.isEmpty(a2) && !this.f.contains(a2)) { b(i2).a(a2); b(i2).b(a2); b(i2).a(true); } } public final String a(ff ffVar, int i2) { try { if (fi.p() && ffVar != null) { String b2 = ffVar.b(); String host = new URL(b2).getHost(); if (!"http://abroad.apilocate.amap.com/mobile/binary".equals(b2)) { if (!"abroad.apilocate.amap.com".equals(host)) { String str = "apilocate.amap.com".equalsIgnoreCase(host) ? "httpdns.apilocate.amap.com" : host; if (!m.d(str)) { return null; } String e2 = e(i2); if (!TextUtils.isEmpty(e2)) { ffVar.d(b2.replace(host, e2)); ffVar.a().put("host", str); ffVar.e(str); ffVar.a(i2 == b); return e2; } } } } } catch (Throwable unused) { } return null; } public final void a(int i2) { if (!b(i2).e()) { this.f.add(b(i2).b()); d(i2); b(true, i2); return; } d(i2); } public final void a(boolean z, int i2) { b(i2).b(z); if (z) { String c2 = b(i2).c(); String b2 = b(i2).b(); if (!TextUtils.isEmpty(b2) && !b2.equals(c2)) { SharedPreferences.Editor a2 = fp.a(this.j, "cbG9jaXA"); fp.a(a2, c(i2), b2); fp.a(a2); } } } }