package b4; import android.util.Log; import b4.o; import com.google.firebase.components.ComponentRegistrar; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicReference; /* loaded from: classes2.dex */ public class o implements e, g4.a { /* renamed from: h, reason: collision with root package name */ private static final o4.b f3116h = new o4.b() { // from class: b4.l @Override // o4.b public final Object get() { return Collections.emptySet(); } }; /* renamed from: a, reason: collision with root package name */ private final Map f3117a; /* renamed from: b, reason: collision with root package name */ private final Map f3118b; /* renamed from: c, reason: collision with root package name */ private final Map f3119c; /* renamed from: d, reason: collision with root package name */ private final List f3120d; /* renamed from: e, reason: collision with root package name */ private final v f3121e; /* renamed from: f, reason: collision with root package name */ private final AtomicReference f3122f; /* renamed from: g, reason: collision with root package name */ private final j f3123g; public static final class b { /* renamed from: a, reason: collision with root package name */ private final Executor f3124a; /* renamed from: b, reason: collision with root package name */ private final List f3125b = new ArrayList(); /* renamed from: c, reason: collision with root package name */ private final List f3126c = new ArrayList(); /* renamed from: d, reason: collision with root package name */ private j f3127d = j.f3109a; b(Executor executor) { this.f3124a = executor; } /* JADX INFO: Access modifiers changed from: private */ public static /* synthetic */ ComponentRegistrar f(ComponentRegistrar componentRegistrar) { return componentRegistrar; } public b b(c cVar) { this.f3126c.add(cVar); return this; } public b c(final ComponentRegistrar componentRegistrar) { this.f3125b.add(new o4.b() { // from class: b4.p @Override // o4.b public final Object get() { ComponentRegistrar f10; f10 = o.b.f(ComponentRegistrar.this); return f10; } }); return this; } public b d(Collection collection) { this.f3125b.addAll(collection); return this; } public o e() { return new o(this.f3124a, this.f3125b, this.f3126c, this.f3127d); } public b g(j jVar) { this.f3127d = jVar; return this; } } public static b k(Executor executor) { return new b(executor); } private void l(List list) { ArrayList arrayList = new ArrayList(); synchronized (this) { Iterator it = this.f3120d.iterator(); while (it.hasNext()) { try { ComponentRegistrar componentRegistrar = (ComponentRegistrar) ((o4.b) it.next()).get(); if (componentRegistrar != null) { list.addAll(this.f3123g.a(componentRegistrar)); it.remove(); } } catch (w e10) { it.remove(); Log.w("ComponentDiscovery", "Invalid component registrar.", e10); } } if (this.f3117a.isEmpty()) { q.a(list); } else { ArrayList arrayList2 = new ArrayList(this.f3117a.keySet()); arrayList2.addAll(list); q.a(arrayList2); } Iterator it2 = list.iterator(); while (it2.hasNext()) { final c cVar = (c) it2.next(); this.f3117a.put(cVar, new x(new o4.b() { // from class: b4.k @Override // o4.b public final Object get() { Object p10; p10 = o.this.p(cVar); return p10; } })); } arrayList.addAll(u(list)); arrayList.addAll(v()); t(); } Iterator it3 = arrayList.iterator(); while (it3.hasNext()) { ((Runnable) it3.next()).run(); } s(); } private void m(Map map, boolean z10) { for (Map.Entry entry : map.entrySet()) { c cVar = (c) entry.getKey(); o4.b bVar = (o4.b) entry.getValue(); if (cVar.n() || (cVar.o() && z10)) { bVar.get(); } } this.f3121e.d(); } private static List o(Iterable iterable) { ArrayList arrayList = new ArrayList(); Iterator it = iterable.iterator(); while (it.hasNext()) { arrayList.add(it.next()); } return arrayList; } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ Object p(c cVar) { return cVar.h().a(new f0(cVar, this)); } private void s() { Boolean bool = (Boolean) this.f3122f.get(); if (bool != null) { m(this.f3117a, bool.booleanValue()); } } private void t() { for (c cVar : this.f3117a.keySet()) { for (r rVar : cVar.g()) { if (rVar.f() && !this.f3119c.containsKey(rVar.b())) { this.f3119c.put(rVar.b(), y.b(Collections.emptySet())); } else if (this.f3118b.containsKey(rVar.b())) { continue; } else { if (rVar.e()) { throw new z(String.format("Unsatisfied dependency for component %s: %s", cVar, rVar.b())); } if (!rVar.f()) { this.f3118b.put(rVar.b(), c0.c()); } } } } } private List u(List list) { ArrayList arrayList = new ArrayList(); Iterator it = list.iterator(); while (it.hasNext()) { c cVar = (c) it.next(); if (cVar.p()) { final o4.b bVar = (o4.b) this.f3117a.get(cVar); for (e0 e0Var : cVar.j()) { if (this.f3118b.containsKey(e0Var)) { final c0 c0Var = (c0) ((o4.b) this.f3118b.get(e0Var)); arrayList.add(new Runnable() { // from class: b4.m @Override // java.lang.Runnable public final void run() { c0.this.f(bVar); } }); } else { this.f3118b.put(e0Var, bVar); } } } } return arrayList; } private List v() { ArrayList arrayList = new ArrayList(); HashMap hashMap = new HashMap(); for (Map.Entry entry : this.f3117a.entrySet()) { c cVar = (c) entry.getKey(); if (!cVar.p()) { o4.b bVar = (o4.b) entry.getValue(); for (e0 e0Var : cVar.j()) { if (!hashMap.containsKey(e0Var)) { hashMap.put(e0Var, new HashSet()); } ((Set) hashMap.get(e0Var)).add(bVar); } } } for (Map.Entry entry2 : hashMap.entrySet()) { if (this.f3119c.containsKey(entry2.getKey())) { final y yVar = (y) this.f3119c.get(entry2.getKey()); for (final o4.b bVar2 : (Set) entry2.getValue()) { arrayList.add(new Runnable() { // from class: b4.n @Override // java.lang.Runnable public final void run() { y.this.a(bVar2); } }); } } else { this.f3119c.put((e0) entry2.getKey(), y.b((Collection) entry2.getValue())); } } return arrayList; } @Override // b4.e public /* synthetic */ Object a(Class cls) { return d.b(this, cls); } @Override // b4.e public /* synthetic */ o4.b b(Class cls) { return d.c(this, cls); } @Override // b4.e public synchronized o4.b c(e0 e0Var) { y yVar = (y) this.f3119c.get(e0Var); if (yVar != null) { return yVar; } return f3116h; } @Override // b4.e public /* synthetic */ Set d(e0 e0Var) { return d.d(this, e0Var); } @Override // b4.e public /* synthetic */ Object e(e0 e0Var) { return d.a(this, e0Var); } @Override // b4.e public synchronized o4.b f(e0 e0Var) { d0.c(e0Var, "Null interface requested."); return (o4.b) this.f3118b.get(e0Var); } @Override // b4.e public /* synthetic */ Set g(Class cls) { return d.e(this, cls); } public void n(boolean z10) { HashMap hashMap; if (com.google.android.gms.common.api.internal.a.a(this.f3122f, null, Boolean.valueOf(z10))) { synchronized (this) { hashMap = new HashMap(this.f3117a); } m(hashMap, z10); } } private o(Executor executor, Iterable iterable, Collection collection, j jVar) { this.f3117a = new HashMap(); this.f3118b = new HashMap(); this.f3119c = new HashMap(); this.f3122f = new AtomicReference(); v vVar = new v(executor); this.f3121e = vVar; this.f3123g = jVar; ArrayList arrayList = new ArrayList(); arrayList.add(c.s(vVar, v.class, l4.d.class, l4.c.class)); arrayList.add(c.s(this, g4.a.class, new Class[0])); Iterator it = collection.iterator(); while (it.hasNext()) { c cVar = (c) it.next(); if (cVar != null) { arrayList.add(cVar); } } this.f3120d = o(iterable); l(arrayList); } }