package com.amap.api.col; import android.content.Context; import android.net.Proxy; import android.os.Build; import android.text.TextUtils; import com.huawei.hms.support.hianalytics.HiAnalyticsConstant; import com.meizu.cloud.pushsdk.notification.model.TimeDisplaySetting; import java.util.HashMap; import java.util.Locale; import java.util.concurrent.ExecutorService; import org.json.JSONObject; /* compiled from: LocNetManager */ public class ia { private static ia f; gr a = null; boolean b = false; volatile int c = 0; /* renamed from: d reason: collision with root package name */ public String f1053d = "com.autonavi.httpdns.HttpDnsManager"; boolean e = false; private Object g = null; private String h = "apilocatesrc.amap.com"; private Context i = null; private int j = 0; private ExecutorService k = null; private int l = f.c; /* access modifiers changed from: package-private */ /* compiled from: LocNetManager */ public class a implements Runnable { ib a = null; a(ib ibVar) { this.a = ibVar; } public void run() { ia.this.c++; ia.this.a(this.a); ia iaVar = ia.this; iaVar.c--; } } private ia(Context context) { this.i = context; c(context); this.a = gr.a(); } public static ia a(Context context, boolean z) { if (f == null) { f = new ia(context); } return f; } private boolean b(Context context) { return ik.b(context, "pref", "dns_faile_count_total", 0) < 2; } private void c(Context context) { try { if (this.g == null && !this.e) { fa a2 = f.a("HttpDNS", "1.0.0"); boolean a3 = ii.a(context, a2); this.e = a3; int i2 = 1; if (a3) { try { this.g = gd.a(context, a2, this.f1053d, null, new Class[]{Context.class}, new Object[]{context}); } catch (Throwable unused) { } if (this.g == null) { i2 = 0; } ii.a(context, "HttpDns", i2); return; } this.e = true; } } catch (Throwable th) { f.a(th, "APS", "initHttpDns"); } } private boolean d(Context context) { return this.g != null && !a(context); } private void b(ib ibVar) { try { if (this.c <= 5) { ExecutorService executorService = this.k; if (executorService == null || executorService.isShutdown()) { this.k = fi.c(); } this.k.submit(new a(ibVar)); } } catch (Throwable unused) { } } public gz a(Context context, JSONObject jSONObject, byte[] bArr, String str, boolean z) throws Throwable { if (il.a(jSONObject, "httptimeout")) { try { this.l = jSONObject.getInt("httptimeout"); } catch (Throwable th) { f.a(th, "LocNetManager", HiAnalyticsConstant.Direction.REQUEST); } } if (il.a(il.c(context)) == -1) { return null; } HashMap hashMap = new HashMap(); String str2 = "loc"; ib ibVar = new ib(context, f.a(str2)); hashMap.clear(); hashMap.put("Content-Type", "application/octet-stream"); hashMap.put("Accept-Encoding", "gzip"); hashMap.put("gzipped", "1"); hashMap.put("Connection", "Keep-Alive"); hashMap.put("User-Agent", "AMAP_Location_SDK_Android 3.2.1"); hashMap.put("KEY", er.f(context)); hashMap.put("enginever", "4.7"); String a2 = eu.a(); String a3 = eu.a(context, a2, "key=" + er.f(context)); hashMap.put(TimeDisplaySetting.TIME_DISPLAY_SETTING, a2); hashMap.put("scode", a3); if (!z) { str2 = "locf"; } hashMap.put("encr", "1"); ibVar.a(z); ibVar.a(String.format(Locale.US, "platform=Android&sdkversion=%s&product=%s&loc_channel=%s", "3.2.1", str2, 3)); ibVar.b(hashMap); ibVar.b(str); ibVar.c(il.a(bArr)); ibVar.a(ey.a(context)); HashMap hashMap2 = new HashMap(); hashMap2.put("output", "bin"); hashMap2.put("policy", "3103"); ibVar.a(hashMap2); ibVar.a(this.l); ibVar.b(this.l); this.b = false; boolean optBoolean = jSONObject.optBoolean("locationProtocol", false); if (optBoolean) { ibVar.b(ibVar.g().replace("http", "https")); } else if (b(context) && d(context) && !"http://abroad.apilocate.amap.com/mobile/binary".equals(ibVar.g())) { String a4 = a(context, this.h); if (!z && TextUtils.isEmpty(a4)) { a4 = ik.b(context, "ip", "last_ip", ""); } if (!TextUtils.isEmpty(a4)) { this.b = true; ik.a(context, "ip", "last_ip", a4); ibVar.b(f.b().replace("apilocatesrc.amap.com", a4)); ibVar.e().put("host", "apilocatesrc.amap.com"); } } long b2 = il.b(); try { gz a5 = this.a.a(ibVar, optBoolean); this.j = Long.valueOf(il.b() - b2).intValue(); if (this.b) { ik.a(context, "pref", "dns_faile_count_total", 0L); } return a5; } catch (Throwable th2) { if (this.b) { b(ibVar); } throw th2; } } public String a(byte[] bArr, Context context, String str, boolean z) { if (il.a(il.c(context)) == -1) { return null; } HashMap hashMap = new HashMap(); ib ibVar = new ib(context, f.a("loc")); hashMap.clear(); hashMap.put("Content-Type", "application/x-www-form-urlencoded"); hashMap.put("Connection", "Keep-Alive"); if (z) { hashMap.put("User-Agent", "AMAP_Location_SDK_Android 3.2.1"); HashMap hashMap2 = new HashMap(); hashMap2.put("custom", "26260A1F00020002"); hashMap2.put("key", er.f(context)); String a2 = eu.a(); String a3 = eu.a(context, a2, fb.c(hashMap2)); hashMap2.put(TimeDisplaySetting.TIME_DISPLAY_SETTING, a2); hashMap2.put("scode", a3); ibVar.b(bArr); ibVar.a(true); ibVar.a(String.format(Locale.US, "platform=Android&sdkversion=%s&product=%s&loc_channel=%s", "3.2.1", "loc", 3)); ibVar.a(hashMap2); } ibVar.b(hashMap); ibVar.b(str); if (!z) { ibVar.c(bArr); } ibVar.a(ey.a(context)); ibVar.a(f.c); ibVar.b(f.c); try { return new String(this.a.b(ibVar), "utf-8"); } catch (Throwable th) { f.a(th, "LocNetManager", "post"); return null; } } public static boolean a(Context context) { int i2; String str = null; try { if (Build.VERSION.SDK_INT >= 14) { str = System.getProperty("http.proxyHost"); String property = System.getProperty("http.proxyPort"); if (property == null) { property = "-1"; } i2 = Integer.parseInt(property); } else { str = Proxy.getHost(context); i2 = Proxy.getPort(context); } } catch (Throwable th) { th.printStackTrace(); i2 = -1; } if (str == null || i2 == -1) { return false; } return true; } public int a() { return this.j; } private String a(Context context, String str) { if (!d(context)) { return null; } try { return (String) ig.a(this.g, "getIpByHostAsync", str); } catch (Throwable unused) { ii.b(context, "HttpDns", 0); return null; } } /* access modifiers changed from: package-private */ /* JADX WARNING: Code restructure failed: missing block: B:13:?, code lost: com.amap.api.col.ik.a(r8.i, "pref", "dns_faile_count_total", 0L); */ /* JADX WARNING: Exception block dominator not found, dom blocks: [] */ /* JADX WARNING: Missing exception handler attribute for start block: B:12:0x003c */ public synchronized void a(ib ibVar) { ibVar.b(f.b()); long b2 = ik.b(this.i, "pref", "dns_faile_count_total", 0L); if (b2 < 2) { this.a.a(ibVar, false); long j2 = b2 + 1; if (j2 >= 2) { ij.a(this.i, "HttpDNS", "dns faile too much"); } ik.a(this.i, "pref", "dns_faile_count_total", j2); return; } return; } }