package com.tencent.mapsdk.internal; import a40.f; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.AsyncTask; import android.os.Bundle; import com.meizu.cloud.pushsdk.constants.PushConstants; 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.JSONException; import org.json.JSONObject; /* compiled from: TMS */ public final class ql { /* renamed from: a reason: collision with root package name */ public Context f28786a; public WeakReference<a> b; /* compiled from: TMS */ public interface a { void c(); } /* compiled from: TMS */ public final class b extends AsyncTask<Context, Void, Void> { private b() { } /* access modifiers changed from: private */ /* JADX WARNING: Removed duplicated region for block: B:44:0x00bb */ /* JADX WARNING: Removed duplicated region for block: B:46:0x00c0 */ /* JADX WARNING: Removed duplicated region for block: B:49:0x00cb */ /* renamed from: a */ public Void doInBackground(Context... contextArr) { WeakReference<a> weakReference; Throwable th2; InputStream inputStream; Context context; Context context2; Context context3; Context context4; JSONObject optJSONObject; int a5 = qi.a(); StringBuilder j = f.j("https://confinfo.map.qq.com/confinfo?", "apiKey="); boolean z = false; if (contextArr != null && contextArr.length > 0) { j.append(ql.a(contextArr[0].getApplicationContext())); } NetResponse doStream = NetManager.getInstance().builder().url(j.toString()).timeOut(PushConstants.WORK_RECEIVER_EVENT_CORE_ERROR).doStream(); try { inputStream = doStream.dataStream; try { byte[] b = kb.b(inputStream); if (b != null) { if (b.length != 0) { JSONObject jSONObject = new JSONObject(new String(b)); if (jSONObject.optInt("error", -1) == 0 && (optJSONObject = jSONObject.optJSONObject("info")) != null) { a5 = optJSONObject.optInt("scenic", a5); } if (inputStream != null) { kb.a((Closeable) inputStream); } kb.a((Closeable) doStream.dataStream); if (a5 != qi.a()) { z = true; } if (z && (context4 = ql.this.f28786a) != null) { qi.a(context4, a5); weakReference = ql.this.b; weakReference.get().c(); } return null; } } if (inputStream != null) { kb.a((Closeable) inputStream); } kb.a((Closeable) doStream.dataStream); if (a5 != qi.a()) { z = true; } if (z && (context3 = ql.this.f28786a) != null) { qi.a(context3, a5); ql.this.b.get().c(); } return null; } catch (Throwable th3) { th2 = th3; try { th2.printStackTrace(); if (inputStream != null) { kb.a((Closeable) inputStream); } if (doStream != null) { kb.a((Closeable) doStream.dataStream); } if (a5 != qi.a()) { z = true; } if (z && (context2 = ql.this.f28786a) != null) { qi.a(context2, a5); weakReference = ql.this.b; weakReference.get().c(); } return null; } catch (Throwable th4) { if (inputStream != null) { kb.a((Closeable) inputStream); } if (doStream != null) { kb.a((Closeable) doStream.dataStream); } if (a5 != qi.a()) { z = true; } if (z && (context = ql.this.f28786a) != null) { qi.a(context, a5); ql.this.b.get().c(); } throw th4; } } } catch (Throwable th5) { th2 = th5; inputStream = null; th2.printStackTrace(); if (inputStream != null) { } if (doStream != null) { } if (a5 != qi.a()) { } qi.a(context2, a5); weakReference = ql.this.b; weakReference.get().c(); return null; } } public /* synthetic */ b(ql qlVar, byte b) { this(); } } public ql(Context context, a aVar) { this.f28786a = context; this.b = new WeakReference<>(aVar); } private void a() { new b(this, (byte) 0).execute(this.f28786a); } private static int a(String str, int i) throws JSONException { JSONObject optJSONObject; JSONObject jSONObject = new JSONObject(str); return (jSONObject.optInt("error", -1) != 0 || (optJSONObject = jSONObject.optJSONObject("info")) == null) ? i : optJSONObject.optInt("scenic", i); } private static /* synthetic */ int b(String str, int i) throws JSONException { JSONObject optJSONObject; JSONObject jSONObject = new JSONObject(str); return (jSONObject.optInt("error", -1) != 0 || (optJSONObject = jSONObject.optJSONObject("info")) == null) ? i : optJSONObject.optInt("scenic", i); } 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 e) { e.printStackTrace(); } if (applicationInfo == null || (bundle = applicationInfo.metaData) == null) { return ""; } return bundle.getString("TencentMapSDK"); } }