package com.tencent.mapsdk.internal; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.AsyncTask; import android.os.Bundle; import com.tencent.map.tools.net.NetManager; import com.tencent.map.tools.net.NetResponse; import java.io.Closeable; import java.io.InputStream; import java.lang.ref.WeakReference; import org.json.JSONObject; public final class rk { /* renamed from: c reason: collision with root package name */ private static final String f58604c = "https://confinfo.map.qq.com/confinfo?"; /* renamed from: a reason: collision with root package name */ public Context f58605a; /* renamed from: b reason: collision with root package name */ public WeakReference<a> f58606b; public interface a { void c(); } public class b extends AsyncTask<Context, Void, Void> { private b() { } /* access modifiers changed from: private */ /* JADX WARNING: Code restructure failed: missing block: B:28:0x0095, code lost: if (r9 != null) goto L_0x0097; */ /* JADX WARNING: Code restructure failed: missing block: B:29:0x0097, code lost: r9.c(); */ /* JADX WARNING: Code restructure failed: missing block: B:56:0x00f0, code lost: if (r9 != null) goto L_0x0097; */ /* JADX WARNING: Removed duplicated region for block: B:46:0x00ca */ /* JADX WARNING: Removed duplicated region for block: B:48:0x00cf */ /* JADX WARNING: Removed duplicated region for block: B:51:0x00da */ /* renamed from: a */ public Void doInBackground(Context... contextArr) { InputStream inputStream; Context context; a aVar; Context context2; Context context3; JSONObject optJSONObject; int a15 = rh.a(); StringBuilder sb5 = new StringBuilder(); sb5.append(rk.f58604c); sb5.append("apiKey="); boolean z15 = false; if (contextArr != null && contextArr.length > 0) { sb5.append(rk.a(contextArr[0].getApplicationContext())); } NetResponse doStream = NetManager.getInstance().builder().url(sb5.toString()).timeOut(3000).doStream(); try { inputStream = doStream.dataStream; try { byte[] b15 = kp.b(inputStream); if (b15 != null) { if (b15.length != 0) { JSONObject jSONObject = new JSONObject(new String(b15)); if (jSONObject.optInt("error", -1) == 0 && (optJSONObject = jSONObject.optJSONObject("info")) != null) { a15 = optJSONObject.optInt("scenic", a15); } if (inputStream != null) { kp.a((Closeable) inputStream); } kp.a((Closeable) doStream.dataStream); if (a15 != rh.a()) { z15 = true; } if (z15 && (context3 = rk.this.f58605a) != null) { rh.a(context3, a15); aVar = rk.this.f58606b.get(); } return null; } } if (inputStream != null) { kp.a((Closeable) inputStream); } kp.a((Closeable) doStream.dataStream); if (a15 != rh.a()) { z15 = true; } if (z15 && (context2 = rk.this.f58605a) != null) { rh.a(context2, a15); a aVar2 = rk.this.f58606b.get(); if (aVar2 != null) { aVar2.c(); } } return null; } catch (Throwable unused) { if (inputStream != null) { } if (doStream != null) { } if (a15 != rh.a()) { } rh.a(context, a15); aVar = rk.this.f58606b.get(); } } catch (Throwable unused2) { inputStream = null; if (inputStream != null) { kp.a((Closeable) inputStream); } if (doStream != null) { kp.a((Closeable) doStream.dataStream); } if (a15 != rh.a()) { z15 = true; } if (z15 && (context = rk.this.f58605a) != null) { rh.a(context, a15); aVar = rk.this.f58606b.get(); } return null; } } public /* synthetic */ b(rk rkVar, byte b15) { this(); } } public rk(Context context, a aVar) { this.f58605a = context; this.f58606b = new WeakReference<>(aVar); } private void a() { new b(this, (byte) 0).execute(this.f58605a); } private static int a(String str, int i15) { JSONObject optJSONObject; JSONObject jSONObject = new JSONObject(str); return (jSONObject.optInt("error", -1) != 0 || (optJSONObject = jSONObject.optJSONObject("info")) == null) ? i15 : optJSONObject.optInt("scenic", i15); } private static /* synthetic */ int b(String str, int i15) { JSONObject optJSONObject; JSONObject jSONObject = new JSONObject(str); return (jSONObject.optInt("error", -1) != 0 || (optJSONObject = jSONObject.optJSONObject("info")) == null) ? i15 : optJSONObject.optInt("scenic", i15); } public static String a(Context context) { Bundle bundle; if (context == null) { return ""; } ApplicationInfo applicationInfo = null; try { applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 128); } catch (PackageManager.NameNotFoundException unused) { } if (applicationInfo == null || (bundle = applicationInfo.metaData) == null) { return ""; } return bundle.getString("TencentMapSDK"); } }