package androidx.startup; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageManager; import android.os.Bundle; 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 r0.c; import s0.b; /* loaded from: classes.dex */ public final class a { /* renamed from: d, reason: collision with root package name */ private static volatile a f2669d; /* renamed from: e, reason: collision with root package name */ private static final Object f2670e = new Object(); /* renamed from: c, reason: collision with root package name */ final Context f2673c; /* renamed from: b, reason: collision with root package name */ final Set f2672b = new HashSet(); /* renamed from: a, reason: collision with root package name */ final Map f2671a = new HashMap(); a(Context context) { this.f2673c = context.getApplicationContext(); } private Object c(Class cls, Set set) { Object obj; if (b.d()) { try { b.a(cls.getSimpleName()); } finally { b.b(); } } if (set.contains(cls)) { throw new IllegalStateException(String.format("Cannot initialize %s. Cycle detected.", cls.getName())); } if (this.f2671a.containsKey(cls)) { obj = this.f2671a.get(cls); } else { set.add(cls); try { r0.a aVar = (r0.a) cls.getDeclaredConstructor(new Class[0]).newInstance(new Object[0]); List dependencies = aVar.dependencies(); if (!dependencies.isEmpty()) { for (Class cls2 : dependencies) { if (!this.f2671a.containsKey(cls2)) { c(cls2, set); } } } obj = aVar.create(this.f2673c); set.remove(cls); this.f2671a.put(cls, obj); } catch (Throwable th) { throw new c(th); } } return obj; } public static a d(Context context) { if (f2669d == null) { synchronized (f2670e) { if (f2669d == null) { f2669d = new a(context); } } } return f2669d; } void a() { try { try { b.a("Startup"); b(this.f2673c.getPackageManager().getProviderInfo(new ComponentName(this.f2673c.getPackageName(), InitializationProvider.class.getName()), 128).metaData); } catch (PackageManager.NameNotFoundException e10) { throw new c(e10); } } finally { b.b(); } } void b(Bundle bundle) { String string = this.f2673c.getString(r0.b.f13605a); if (bundle != null) { try { HashSet hashSet = new HashSet(); for (String str : bundle.keySet()) { if (string.equals(bundle.getString(str, null))) { Class cls = Class.forName(str); if (r0.a.class.isAssignableFrom(cls)) { this.f2672b.add(cls); } } } Iterator it = this.f2672b.iterator(); while (it.hasNext()) { c((Class) it.next(), hashSet); } } catch (ClassNotFoundException e10) { throw new c(e10); } } } public boolean e(Class cls) { return this.f2672b.contains(cls); } }