package w3; import android.app.Application; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.text.TextUtils; import android.util.Log; import b4.o; import b4.x; import com.google.android.gms.ads.RequestConfiguration; import com.google.android.gms.common.api.internal.BackgroundDetector; import com.google.android.gms.common.internal.Objects; import com.google.android.gms.common.internal.Preconditions; import com.google.android.gms.common.util.Base64Utils; import com.google.android.gms.common.util.PlatformVersion; import com.google.android.gms.common.util.ProcessUtils; import com.google.firebase.FirebaseCommonRegistrar; import com.google.firebase.components.ComponentDiscoveryService; import com.google.firebase.concurrent.ExecutorsRegistrar; import com.google.firebase.provider.FirebaseInitProvider; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import v.r; /* loaded from: classes2.dex */ public class f { /* renamed from: k, reason: collision with root package name */ private static final Object f15128k = new Object(); /* renamed from: l, reason: collision with root package name */ static final Map f15129l = new androidx.collection.a(); /* renamed from: a, reason: collision with root package name */ private final Context f15130a; /* renamed from: b, reason: collision with root package name */ private final String f15131b; /* renamed from: c, reason: collision with root package name */ private final n f15132c; /* renamed from: d, reason: collision with root package name */ private final b4.o f15133d; /* renamed from: g, reason: collision with root package name */ private final x f15136g; /* renamed from: h, reason: collision with root package name */ private final o4.b f15137h; /* renamed from: e, reason: collision with root package name */ private final AtomicBoolean f15134e = new AtomicBoolean(false); /* renamed from: f, reason: collision with root package name */ private final AtomicBoolean f15135f = new AtomicBoolean(); /* renamed from: i, reason: collision with root package name */ private final List f15138i = new CopyOnWriteArrayList(); /* renamed from: j, reason: collision with root package name */ private final List f15139j = new CopyOnWriteArrayList(); public interface a { void onBackgroundStateChanged(boolean z10); } private static class b implements BackgroundDetector.BackgroundStateChangeListener { /* renamed from: a, reason: collision with root package name */ private static AtomicReference f15140a = new AtomicReference(); private b() { } /* JADX INFO: Access modifiers changed from: private */ public static void b(Context context) { if (PlatformVersion.isAtLeastIceCreamSandwich() && (context.getApplicationContext() instanceof Application)) { Application application = (Application) context.getApplicationContext(); if (f15140a.get() == null) { b bVar = new b(); if (com.google.android.gms.common.api.internal.a.a(f15140a, null, bVar)) { BackgroundDetector.initialize(application); BackgroundDetector.getInstance().addListener(bVar); } } } } @Override // com.google.android.gms.common.api.internal.BackgroundDetector.BackgroundStateChangeListener public void onBackgroundStateChanged(boolean z10) { synchronized (f.f15128k) { Iterator it = new ArrayList(f.f15129l.values()).iterator(); while (it.hasNext()) { f fVar = (f) it.next(); if (fVar.f15134e.get()) { fVar.z(z10); } } } } } private static class c extends BroadcastReceiver { /* renamed from: b, reason: collision with root package name */ private static AtomicReference f15141b = new AtomicReference(); /* renamed from: a, reason: collision with root package name */ private final Context f15142a; public c(Context context) { this.f15142a = context; } /* JADX INFO: Access modifiers changed from: private */ public static void b(Context context) { if (f15141b.get() == null) { c cVar = new c(context); if (com.google.android.gms.common.api.internal.a.a(f15141b, null, cVar)) { context.registerReceiver(cVar, new IntentFilter("android.intent.action.USER_UNLOCKED")); } } } public void c() { this.f15142a.unregisterReceiver(this); } @Override // android.content.BroadcastReceiver public void onReceive(Context context, Intent intent) { synchronized (f.f15128k) { Iterator it = f.f15129l.values().iterator(); while (it.hasNext()) { ((f) it.next()).q(); } } c(); } } protected f(final Context context, String str, n nVar) { this.f15130a = (Context) Preconditions.checkNotNull(context); this.f15131b = Preconditions.checkNotEmpty(str); this.f15132c = (n) Preconditions.checkNotNull(nVar); p b10 = FirebaseInitProvider.b(); y4.c.b("Firebase"); y4.c.b("ComponentDiscovery"); List b11 = b4.g.c(context, ComponentDiscoveryService.class).b(); y4.c.a(); y4.c.b("Runtime"); o.b g10 = b4.o.k(c4.m.INSTANCE).d(b11).c(new FirebaseCommonRegistrar()).c(new ExecutorsRegistrar()).b(b4.c.s(context, Context.class, new Class[0])).b(b4.c.s(this, f.class, new Class[0])).b(b4.c.s(nVar, n.class, new Class[0])).g(new y4.b()); if (r.a(context) && FirebaseInitProvider.c()) { g10.b(b4.c.s(b10, p.class, new Class[0])); } b4.o e10 = g10.e(); this.f15133d = e10; y4.c.a(); this.f15136g = new x(new o4.b() { // from class: w3.d @Override // o4.b public final Object get() { t4.a w10; w10 = f.this.w(context); return w10; } }); this.f15137h = e10.b(m4.f.class); g(new a() { // from class: w3.e @Override // w3.f.a public final void onBackgroundStateChanged(boolean z10) { f.this.x(z10); } }); y4.c.a(); } private void h() { Preconditions.checkState(!this.f15135f.get(), "FirebaseApp was deleted"); } private static List j() { ArrayList arrayList = new ArrayList(); synchronized (f15128k) { Iterator it = f15129l.values().iterator(); while (it.hasNext()) { arrayList.add(((f) it.next()).n()); } } Collections.sort(arrayList); return arrayList; } public static f l() { f fVar; synchronized (f15128k) { fVar = (f) f15129l.get("[DEFAULT]"); if (fVar == null) { throw new IllegalStateException("Default FirebaseApp is not initialized in this process " + ProcessUtils.getMyProcessName() + ". Make sure to call FirebaseApp.initializeApp(Context) first."); } ((m4.f) fVar.f15137h.get()).l(); } return fVar; } public static f m(String str) { f fVar; String str2; synchronized (f15128k) { fVar = (f) f15129l.get(y(str)); if (fVar == null) { List j10 = j(); if (j10.isEmpty()) { str2 = RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED; } else { str2 = "Available app names: " + TextUtils.join(", ", j10); } throw new IllegalStateException(String.format("FirebaseApp with name %s doesn't exist. %s", str, str2)); } ((m4.f) fVar.f15137h.get()).l(); } return fVar; } /* JADX INFO: Access modifiers changed from: private */ public void q() { if (!r.a(this.f15130a)) { Log.i("FirebaseApp", "Device in Direct Boot Mode: postponing initialization of Firebase APIs for app " + n()); c.b(this.f15130a); return; } Log.i("FirebaseApp", "Device unlocked: initializing all Firebase APIs for app " + n()); this.f15133d.n(v()); ((m4.f) this.f15137h.get()).l(); } public static f r(Context context) { synchronized (f15128k) { if (f15129l.containsKey("[DEFAULT]")) { return l(); } n a10 = n.a(context); if (a10 == null) { Log.w("FirebaseApp", "Default FirebaseApp failed to initialize because no default options were found. This usually means that com.google.gms:google-services was not applied to your gradle project."); return null; } return s(context, a10); } } public static f s(Context context, n nVar) { return t(context, nVar, "[DEFAULT]"); } public static f t(Context context, n nVar, String str) { f fVar; b.b(context); String y10 = y(str); if (context.getApplicationContext() != null) { context = context.getApplicationContext(); } synchronized (f15128k) { Map map = f15129l; Preconditions.checkState(!map.containsKey(y10), "FirebaseApp name " + y10 + " already exists!"); Preconditions.checkNotNull(context, "Application context cannot be null."); fVar = new f(context, y10, nVar); map.put(y10, fVar); } fVar.q(); return fVar; } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ t4.a w(Context context) { return new t4.a(context, p(), (l4.c) this.f15133d.a(l4.c.class)); } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void x(boolean z10) { if (z10) { return; } ((m4.f) this.f15137h.get()).l(); } private static String y(String str) { return str.trim(); } /* JADX INFO: Access modifiers changed from: private */ public void z(boolean z10) { Log.d("FirebaseApp", "Notifying background state change listeners."); Iterator it = this.f15138i.iterator(); while (it.hasNext()) { ((a) it.next()).onBackgroundStateChanged(z10); } } public boolean equals(Object obj) { if (obj instanceof f) { return this.f15131b.equals(((f) obj).n()); } return false; } public void g(a aVar) { h(); if (this.f15134e.get() && BackgroundDetector.getInstance().isInBackground()) { aVar.onBackgroundStateChanged(true); } this.f15138i.add(aVar); } public int hashCode() { return this.f15131b.hashCode(); } public Object i(Class cls) { h(); return this.f15133d.a(cls); } public Context k() { h(); return this.f15130a; } public String n() { h(); return this.f15131b; } public n o() { h(); return this.f15132c; } public String p() { return Base64Utils.encodeUrlSafeNoPadding(n().getBytes(Charset.defaultCharset())) + "+" + Base64Utils.encodeUrlSafeNoPadding(o().c().getBytes(Charset.defaultCharset())); } public String toString() { return Objects.toStringHelper(this).add("name", this.f15131b).add("options", this.f15132c).toString(); } public boolean u() { h(); return ((t4.a) this.f15136g.get()).b(); } public boolean v() { return "[DEFAULT]".equals(n()); } }