package zh; import android.net.TrafficStats; import android.text.TextUtils; import bi.a; import bi.e; import ci.b; import ci.g; import ci.h; import j.q; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Pattern; import me.h0; import me.k; import me.l; import me.n; import mh.c; import org.json.JSONException; import org.json.JSONObject; import u3.y; import uc.my0; import wh.e; public class d implements e { /* renamed from: m reason: collision with root package name */ public static final Object f199234m = new Object(); /* renamed from: n reason: collision with root package name */ public static final ThreadFactory f199235n = new a(); /* renamed from: a reason: collision with root package name */ public final c f199236a; /* renamed from: b reason: collision with root package name */ public final ci.c f199237b; /* renamed from: c reason: collision with root package name */ public final bi.d f199238c; /* renamed from: d reason: collision with root package name */ public final m f199239d; /* renamed from: e reason: collision with root package name */ public final bi.b f199240e; /* renamed from: f reason: collision with root package name */ public final k f199241f; /* renamed from: g reason: collision with root package name */ public final Object f199242g = new Object(); /* renamed from: h reason: collision with root package name */ public final ExecutorService f199243h; /* renamed from: i reason: collision with root package name */ public final ExecutorService f199244i; /* renamed from: j reason: collision with root package name */ public String f199245j; /* renamed from: k reason: collision with root package name */ public Set<ai.a> f199246k = new HashSet(); /* renamed from: l reason: collision with root package name */ public final List<l> f199247l = new ArrayList(); public class a implements ThreadFactory { /* renamed from: b reason: collision with root package name */ public final AtomicInteger f199248b = new AtomicInteger(1); public Thread newThread(Runnable runnable) { return new Thread(runnable, String.format("firebase-installations-executor-%d", Integer.valueOf(this.f199248b.getAndIncrement()))); } } public static /* synthetic */ class b { /* renamed from: a reason: collision with root package name */ public static final /* synthetic */ int[] f199249a; /* renamed from: b reason: collision with root package name */ public static final /* synthetic */ int[] f199250b; /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:13:0x0031 */ /* JADX WARNING: Missing exception handler attribute for start block: B:7:0x0019 */ static { int[] iArr = new int[h.a().length]; f199250b = iArr; try { iArr[q.e(1)] = 1; } catch (NoSuchFieldError unused) { } f199250b[q.e(2)] = 2; try { f199250b[q.e(3)] = 3; } catch (NoSuchFieldError unused2) { } int[] iArr2 = new int[ci.d.a().length]; f199249a = iArr2; iArr2[q.e(1)] = 1; try { f199249a[q.e(2)] = 2; } catch (NoSuchFieldError unused3) { } } } public d(c cVar, yh.a<gi.h> aVar, yh.a<e> aVar2) { TimeUnit timeUnit = TimeUnit.SECONDS; LinkedBlockingQueue linkedBlockingQueue = new LinkedBlockingQueue(); ThreadFactory threadFactory = f199235n; ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0, 1, 30, timeUnit, linkedBlockingQueue, threadFactory); cVar.a(); ci.c cVar2 = new ci.c(cVar.f112265a, aVar, aVar2); bi.d dVar = new bi.d(cVar); m c14 = m.c(); bi.b bVar = new bi.b(cVar); k kVar = new k(); this.f199236a = cVar; this.f199237b = cVar2; this.f199238c = dVar; this.f199239d = c14; this.f199240e = bVar; this.f199241f = kVar; this.f199243h = threadPoolExecutor; this.f199244i = new ThreadPoolExecutor(0, 1, 30, timeUnit, new LinkedBlockingQueue(), threadFactory); } public static d f(c cVar) { cVar.a(); return (d) cVar.f112268d.a(e.class); } @Override // zh.e public k<j> a(boolean z14) { h(); l lVar = new l(); h hVar = new h(this.f199239d, lVar); synchronized (this.f199242g) { this.f199247l.add(hVar); } h0<TResult> h0Var = lVar.f111925a; this.f199243h.execute(new b(this, z14)); return h0Var; } public final void b(boolean z14) { bi.e b14; synchronized (f199234m) { c cVar = this.f199236a; cVar.a(); my0 a14 = my0.a(cVar.f112265a, "generatefid.lock"); try { b14 = this.f199238c.b(); if (b14.i()) { String i14 = i(b14); bi.d dVar = this.f199238c; a.b bVar = (a.b) b14.k(); bVar.f12615a = i14; bVar.b(3); b14 = bVar.a(); dVar.a(b14); } } finally { if (a14 != null) { a14.b(); } } } if (z14) { a.b bVar2 = (a.b) b14.k(); bVar2.f12617c = null; b14 = bVar2.a(); } l(b14); this.f199244i.execute(new c(this, z14)); } public final bi.e c(bi.e eVar) throws f { g f14; ci.c cVar = this.f199237b; String d14 = d(); bi.a aVar = (bi.a) eVar; String str = aVar.f12608b; String g14 = g(); String str2 = aVar.f12611e; if (cVar.f18050d.a()) { URL a14 = cVar.a(String.format("projects/%s/installations/%s/authTokens:generate", g14, str)); for (int i14 = 0; i14 <= 1; i14++) { TrafficStats.setThreadStatsTag(32771); HttpURLConnection c14 = cVar.c(a14, d14); try { c14.setRequestMethod("POST"); c14.addRequestProperty("Authorization", "FIS_v2 " + str2); c14.setDoOutput(true); cVar.h(c14); int responseCode = c14.getResponseCode(); cVar.f18050d.b(responseCode); if (responseCode >= 200 && responseCode < 300) { f14 = cVar.f(c14); } else { ci.c.b(c14, null, d14, g14); if (responseCode != 401) { if (responseCode != 404) { if (responseCode == 429) { throw new f("Firebase servers have received too many requests from this client in a short period of time. Please try again later.", 3); } else if (responseCode < 500 || responseCode >= 600) { b.C0355b bVar = (b.C0355b) g.a(); bVar.f18044c = 2; f14 = bVar.a(); } else { c14.disconnect(); TrafficStats.clearThreadStatsTag(); } } } b.C0355b bVar2 = (b.C0355b) g.a(); bVar2.f18044c = 3; f14 = bVar2.a(); } c14.disconnect(); TrafficStats.clearThreadStatsTag(); ci.b bVar3 = (ci.b) f14; int i15 = b.f199250b[q.e(bVar3.f18041c)]; if (i15 == 1) { String str3 = bVar3.f18039a; long j14 = bVar3.f18040b; long b14 = this.f199239d.b(); a.b bVar4 = (a.b) eVar.k(); bVar4.f12617c = str3; bVar4.f12619e = Long.valueOf(j14); bVar4.f12620f = Long.valueOf(b14); return bVar4.a(); } else if (i15 == 2) { a.b bVar5 = (a.b) eVar.k(); bVar5.f12621g = "BAD CONFIG"; bVar5.b(5); return bVar5.a(); } else if (i15 == 3) { synchronized (this) { this.f199245j = null; } e.a k14 = eVar.k(); k14.b(2); return k14.a(); } else { throw new f("Firebase Installations Service is unavailable. Please try again later.", 2); } } catch (IOException | AssertionError unused) { } catch (Throwable th4) { c14.disconnect(); TrafficStats.clearThreadStatsTag(); throw th4; } } throw new f("Firebase Installations Service is unavailable. Please try again later.", 2); } throw new f("Firebase Installations Service is unavailable. Please try again later.", 2); } public String d() { c cVar = this.f199236a; cVar.a(); return cVar.f112267c.f112282a; } public String e() { c cVar = this.f199236a; cVar.a(); return cVar.f112267c.f112283b; } public String g() { c cVar = this.f199236a; cVar.a(); return cVar.f112267c.f112288g; } @Override // zh.e public k<String> getId() { String str; h(); synchronized (this) { str = this.f199245j; } if (str != null) { return n.e(str); } l lVar = new l(); i iVar = new i(lVar); synchronized (this.f199242g) { this.f199247l.add(iVar); } h0<TResult> h0Var = lVar.f111925a; this.f199243h.execute(new y(this, 3)); return h0Var; } public final void h() { iz.a.i(e(), "Please set your Application ID. A valid Firebase App ID is required to communicate with Firebase server APIs: It identifies your application with Firebase.Please refer to https://firebase.google.com/support/privacy/init-options."); iz.a.i(g(), "Please set your Project ID. A valid Firebase Project ID is required to communicate with Firebase server APIs: It identifies your application with Firebase.Please refer to https://firebase.google.com/support/privacy/init-options."); iz.a.i(d(), "Please set a valid API key. A Firebase API key is required to communicate with Firebase server APIs: It authenticates your project with Google.Please refer to https://firebase.google.com/support/privacy/init-options."); String e14 = e(); Pattern pattern = m.f199258c; iz.a.c(e14.contains(":"), "Please set your Application ID. A valid Firebase App ID is required to communicate with Firebase server APIs: It identifies your application with Firebase.Please refer to https://firebase.google.com/support/privacy/init-options."); iz.a.c(m.f199258c.matcher(d()).matches(), "Please set a valid API key. A Firebase API key is required to communicate with Firebase server APIs: It authenticates your project with Google.Please refer to https://firebase.google.com/support/privacy/init-options."); } /* JADX WARNING: Code restructure failed: missing block: B:3:0x001c, code lost: if ("[DEFAULT]".equals(r0.f112266b) != false) goto L_0x001e; */ public final String i(bi.e eVar) { String string; c cVar = this.f199236a; cVar.a(); if (!cVar.f112266b.equals("CHIME_ANDROID_SDK")) { c cVar2 = this.f199236a; cVar2.a(); } boolean z14 = true; if (((bi.a) eVar).f12609c != 1) { z14 = false; } if (z14) { bi.b bVar = this.f199240e; synchronized (bVar.f12623a) { synchronized (bVar.f12623a) { string = bVar.f12623a.getString("|S|id", null); } if (string == null) { string = bVar.a(); } } return TextUtils.isEmpty(string) ? this.f199241f.a() : string; } return this.f199241f.a(); } public final bi.e j(bi.e eVar) throws f { ci.e e14; bi.a aVar = (bi.a) eVar; String str = aVar.f12608b; boolean z14 = false; String str2 = null; if (str != null && str.length() == 11) { bi.b bVar = this.f199240e; synchronized (bVar.f12623a) { String[] strArr = bi.b.f12622c; int length = strArr.length; int i14 = 0; while (true) { if (i14 >= length) { break; } String str3 = strArr[i14]; String string = bVar.f12623a.getString("|T|" + bVar.f12624b + "|" + str3, null); if (string == null || string.isEmpty()) { i14++; } else if (string.startsWith("{")) { try { str2 = new JSONObject(string).getString(zq0.c.QUERY_KEY_TOKEN); } catch (JSONException unused) { } } else { str2 = string; } } } } ci.c cVar = this.f199237b; String d14 = d(); String str4 = aVar.f12608b; String g14 = g(); String e15 = e(); if (cVar.f18050d.a()) { URL a14 = cVar.a(String.format("projects/%s/installations", g14)); int i15 = 0; while (i15 <= 1) { TrafficStats.setThreadStatsTag(32769); HttpURLConnection c14 = cVar.c(a14, d14); try { c14.setRequestMethod("POST"); c14.setDoOutput(true); if (str2 != null) { c14.addRequestProperty("x-goog-fis-android-iid-migration-auth", str2); } cVar.g(c14, str4, e15); int responseCode = c14.getResponseCode(); cVar.f18050d.b(responseCode); if ((responseCode < 200 || responseCode >= 300) ? z14 : true) { e14 = cVar.e(c14); c14.disconnect(); TrafficStats.clearThreadStatsTag(); } else { try { ci.c.b(c14, e15, d14, g14); if (responseCode == 429) { throw new f("Firebase servers have received too many requests from this client in a short period of time. Please try again later.", 3); } else if (responseCode < 500 || responseCode >= 600) { ci.a aVar2 = new ci.a(null, null, null, null, 2, null); c14.disconnect(); TrafficStats.clearThreadStatsTag(); e14 = aVar2; } else { c14.disconnect(); TrafficStats.clearThreadStatsTag(); i15++; z14 = false; } } catch (IOException | AssertionError unused2) { } } ci.a aVar3 = (ci.a) e14; int i16 = b.f199249a[q.e(aVar3.f18038e)]; if (i16 == 1) { String str5 = aVar3.f18035b; String str6 = aVar3.f18036c; long b14 = this.f199239d.b(); String c15 = aVar3.f18037d.c(); long d15 = aVar3.f18037d.d(); a.b bVar2 = (a.b) eVar.k(); bVar2.f12615a = str5; bVar2.b(4); bVar2.f12617c = c15; bVar2.f12618d = str6; bVar2.f12619e = Long.valueOf(d15); bVar2.f12620f = Long.valueOf(b14); return bVar2.a(); } else if (i16 == 2) { a.b bVar3 = (a.b) eVar.k(); bVar3.f12621g = "BAD CONFIG"; bVar3.b(5); return bVar3.a(); } else { throw new f("Firebase Installations Service is unavailable. Please try again later.", 2); } } catch (Throwable th4) { c14.disconnect(); TrafficStats.clearThreadStatsTag(); throw th4; } } throw new f("Firebase Installations Service is unavailable. Please try again later.", 2); } throw new f("Firebase Installations Service is unavailable. Please try again later.", 2); } public final void k(Exception exc) { synchronized (this.f199242g) { Iterator<l> it3 = this.f199247l.iterator(); while (it3.hasNext()) { if (it3.next().a(exc)) { it3.remove(); } } } } public final void l(bi.e eVar) { synchronized (this.f199242g) { Iterator<l> it3 = this.f199247l.iterator(); while (it3.hasNext()) { if (it3.next().b(eVar)) { it3.remove(); } } } } }