package com.google.firebase.installations; import android.text.TextUtils; import androidx.appcompat.app.m; import b4.x; import com.google.android.gms.common.internal.Preconditions; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.TaskCompletionSource; import com.google.android.gms.tasks.Tasks; import com.google.firebase.installations.d; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; import r4.d; import r4.f; /* loaded from: classes2.dex */ public class c implements p4.e { /* renamed from: m, reason: collision with root package name */ private static final Object f5455m = new Object(); /* renamed from: n, reason: collision with root package name */ private static final ThreadFactory f5456n = new a(); /* renamed from: a, reason: collision with root package name */ private final w3.f f5457a; /* renamed from: b, reason: collision with root package name */ private final r4.c f5458b; /* renamed from: c, reason: collision with root package name */ private final q4.c f5459c; /* renamed from: d, reason: collision with root package name */ private final i f5460d; /* renamed from: e, reason: collision with root package name */ private final x f5461e; /* renamed from: f, reason: collision with root package name */ private final p4.g f5462f; /* renamed from: g, reason: collision with root package name */ private final Object f5463g; /* renamed from: h, reason: collision with root package name */ private final ExecutorService f5464h; /* renamed from: i, reason: collision with root package name */ private final Executor f5465i; /* renamed from: j, reason: collision with root package name */ private String f5466j; /* renamed from: k, reason: collision with root package name */ private Set f5467k; /* renamed from: l, reason: collision with root package name */ private final List f5468l; class a implements ThreadFactory { /* renamed from: a, reason: collision with root package name */ private final AtomicInteger f5469a = new AtomicInteger(1); a() { } @Override // java.util.concurrent.ThreadFactory public Thread newThread(Runnable runnable) { return new Thread(runnable, String.format("firebase-installations-executor-%d", Integer.valueOf(this.f5469a.getAndIncrement()))); } } static /* synthetic */ class b { /* renamed from: a, reason: collision with root package name */ static final /* synthetic */ int[] f5470a; /* renamed from: b, reason: collision with root package name */ static final /* synthetic */ int[] f5471b; static { int[] iArr = new int[f.b.values().length]; f5471b = iArr; try { iArr[f.b.OK.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { f5471b[f.b.BAD_CONFIG.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } try { f5471b[f.b.AUTH_ERROR.ordinal()] = 3; } catch (NoSuchFieldError unused3) { } int[] iArr2 = new int[d.b.values().length]; f5470a = iArr2; try { iArr2[d.b.OK.ordinal()] = 1; } catch (NoSuchFieldError unused4) { } try { f5470a[d.b.BAD_CONFIG.ordinal()] = 2; } catch (NoSuchFieldError unused5) { } } } c(final w3.f fVar, o4.b bVar, ExecutorService executorService, Executor executor) { this(executorService, executor, fVar, new r4.c(fVar.k(), bVar), new q4.c(fVar), i.c(), new x(new o4.b() { // from class: p4.b @Override // o4.b public final Object get() { q4.b y10; y10 = com.google.firebase.installations.c.y(w3.f.this); return y10; } }), new p4.g()); } private String A(q4.d dVar) { if ((!this.f5457a.n().equals("CHIME_ANDROID_SDK") && !this.f5457a.v()) || !dVar.m()) { return this.f5462f.a(); } String f10 = o().f(); return TextUtils.isEmpty(f10) ? this.f5462f.a() : f10; } private q4.d B(q4.d dVar) { r4.d d10 = this.f5458b.d(l(), dVar.d(), t(), m(), (dVar.d() == null || dVar.d().length() != 11) ? null : o().i()); int i10 = b.f5470a[d10.e().ordinal()]; if (i10 == 1) { return dVar.s(d10.c(), d10.d(), this.f5460d.b(), d10.b().c(), d10.b().d()); } if (i10 == 2) { return dVar.q("BAD CONFIG"); } throw new d("Firebase Installations Service is unavailable. Please try again later.", d.a.UNAVAILABLE); } private void C(Exception exc) { synchronized (this.f5463g) { Iterator it = this.f5468l.iterator(); while (it.hasNext()) { if (((h) it.next()).b(exc)) { it.remove(); } } } } private void D(q4.d dVar) { synchronized (this.f5463g) { Iterator it = this.f5468l.iterator(); while (it.hasNext()) { if (((h) it.next()).a(dVar)) { it.remove(); } } } } private synchronized void E(String str) { this.f5466j = str; } private synchronized void F(q4.d dVar, q4.d dVar2) { if (this.f5467k.size() != 0 && !TextUtils.equals(dVar.d(), dVar2.d())) { Iterator it = this.f5467k.iterator(); if (it.hasNext()) { m.a(it.next()); dVar2.d(); throw null; } } } private Task f() { TaskCompletionSource taskCompletionSource = new TaskCompletionSource(); h(new e(this.f5460d, taskCompletionSource)); return taskCompletionSource.getTask(); } private Task g() { TaskCompletionSource taskCompletionSource = new TaskCompletionSource(); h(new f(taskCompletionSource)); return taskCompletionSource.getTask(); } private void h(h hVar) { synchronized (this.f5463g) { this.f5468l.add(hVar); } } /* JADX INFO: Access modifiers changed from: private */ /* JADX WARN: Removed duplicated region for block: B:17:0x0032 */ /* JADX WARN: Removed duplicated region for block: B:20:0x003f */ /* JADX WARN: Removed duplicated region for block: B:22:0x004a */ /* renamed from: i, reason: merged with bridge method [inline-methods] */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public void v(boolean r3) { /* r2 = this; q4.d r0 = r2.r() boolean r1 = r0.i() // Catch: com.google.firebase.installations.d -> L5f if (r1 != 0) goto L22 boolean r1 = r0.l() // Catch: com.google.firebase.installations.d -> L5f if (r1 == 0) goto L11 goto L22 L11: if (r3 != 0) goto L1d com.google.firebase.installations.i r3 = r2.f5460d // Catch: com.google.firebase.installations.d -> L5f boolean r3 = r3.f(r0) // Catch: com.google.firebase.installations.d -> L5f if (r3 == 0) goto L1c goto L1d L1c: return L1d: q4.d r3 = r2.k(r0) // Catch: com.google.firebase.installations.d -> L5f goto L26 L22: q4.d r3 = r2.B(r0) // Catch: com.google.firebase.installations.d -> L5f L26: r2.u(r3) r2.F(r0, r3) boolean r0 = r3.k() if (r0 == 0) goto L39 java.lang.String r0 = r3.d() r2.E(r0) L39: boolean r0 = r3.i() if (r0 == 0) goto L4a com.google.firebase.installations.d r3 = new com.google.firebase.installations.d com.google.firebase.installations.d$a r0 = com.google.firebase.installations.d.a.BAD_CONFIG r3.(r0) r2.C(r3) goto L5e L4a: boolean r0 = r3.j() if (r0 == 0) goto L5b java.io.IOException r3 = new java.io.IOException java.lang.String r0 = "Installation ID could not be validated with the Firebase servers (maybe it was deleted). Firebase Installations will need to create a new Installation ID and auth token. Please retry your last request." r3.(r0) r2.C(r3) goto L5e L5b: r2.D(r3) L5e: return L5f: r3 = move-exception r2.C(r3) return */ throw new UnsupportedOperationException("Method not decompiled: com.google.firebase.installations.c.v(boolean):void"); } /* JADX INFO: Access modifiers changed from: private */ /* renamed from: j, reason: merged with bridge method [inline-methods] */ public final void x(final boolean z10) { q4.d s10 = s(); if (z10) { s10 = s10.p(); } D(s10); this.f5465i.execute(new Runnable() { // from class: p4.c @Override // java.lang.Runnable public final void run() { com.google.firebase.installations.c.this.v(z10); } }); } private q4.d k(q4.d dVar) { r4.f e10 = this.f5458b.e(l(), dVar.d(), t(), dVar.f()); int i10 = b.f5471b[e10.b().ordinal()]; if (i10 == 1) { return dVar.o(e10.c(), e10.d(), this.f5460d.b()); } if (i10 == 2) { return dVar.q("BAD CONFIG"); } if (i10 != 3) { throw new d("Firebase Installations Service is unavailable. Please try again later.", d.a.UNAVAILABLE); } E(null); return dVar.r(); } private synchronized String n() { return this.f5466j; } private q4.b o() { return (q4.b) this.f5461e.get(); } public static c p() { return q(w3.f.l()); } public static c q(w3.f fVar) { Preconditions.checkArgument(fVar != null, "Null is not a valid value of FirebaseApp."); return (c) fVar.i(p4.e.class); } private q4.d r() { q4.d d10; synchronized (f5455m) { com.google.firebase.installations.b a10 = com.google.firebase.installations.b.a(this.f5457a.k(), "generatefid.lock"); try { d10 = this.f5459c.d(); } finally { if (a10 != null) { a10.b(); } } } return d10; } private q4.d s() { q4.d d10; synchronized (f5455m) { com.google.firebase.installations.b a10 = com.google.firebase.installations.b.a(this.f5457a.k(), "generatefid.lock"); try { d10 = this.f5459c.d(); if (d10.j()) { d10 = this.f5459c.b(d10.t(A(d10))); } } finally { if (a10 != null) { a10.b(); } } } return d10; } private void u(q4.d dVar) { synchronized (f5455m) { com.google.firebase.installations.b a10 = com.google.firebase.installations.b.a(this.f5457a.k(), "generatefid.lock"); try { this.f5459c.b(dVar); } finally { if (a10 != null) { a10.b(); } } } } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void w() { x(false); } /* JADX INFO: Access modifiers changed from: private */ public static /* synthetic */ q4.b y(w3.f fVar) { return new q4.b(fVar); } private void z() { Preconditions.checkNotEmpty(m(), "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."); Preconditions.checkNotEmpty(t(), "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."); Preconditions.checkNotEmpty(l(), "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."); Preconditions.checkArgument(i.h(m()), "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."); Preconditions.checkArgument(i.g(l()), "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."); } @Override // p4.e public Task a(final boolean z10) { z(); Task f10 = f(); this.f5464h.execute(new Runnable() { // from class: p4.d @Override // java.lang.Runnable public final void run() { com.google.firebase.installations.c.this.x(z10); } }); return f10; } @Override // p4.e public Task getId() { z(); String n10 = n(); if (n10 != null) { return Tasks.forResult(n10); } Task g10 = g(); this.f5464h.execute(new Runnable() { // from class: p4.a @Override // java.lang.Runnable public final void run() { com.google.firebase.installations.c.this.w(); } }); return g10; } String l() { return this.f5457a.o().b(); } String m() { return this.f5457a.o().c(); } String t() { return this.f5457a.o().e(); } c(ExecutorService executorService, Executor executor, w3.f fVar, r4.c cVar, q4.c cVar2, i iVar, x xVar, p4.g gVar) { this.f5463g = new Object(); this.f5467k = new HashSet(); this.f5468l = new ArrayList(); this.f5457a = fVar; this.f5458b = cVar; this.f5459c = cVar2; this.f5460d = iVar; this.f5461e = xVar; this.f5462f = gVar; this.f5464h = executorService; this.f5465i = executor; } }