package p068w0;

import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import androidx.startup.InitializationProvider;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import p070x0.C1805b;

/* renamed from: w0.a */
/* loaded from: classes.dex */
public final class C1790a {

    /* renamed from: d */
    public static volatile C1790a f4514d;

    /* renamed from: e */
    public static final Object f4515e = new Object();

    /* renamed from: c */
    public final Context f4518c;

    /* renamed from: b */
    public final Set<Class<? extends InterfaceC1791b<?>>> f4517b = new HashSet();

    /* renamed from: a */
    public final Map<Class<?>, Object> f4516a = new HashMap();

    public C1790a(Context context) {
        this.f4518c = context.getApplicationContext();
    }

    /* renamed from: e */
    public static C1790a m396e(Context context) {
        if (f4514d == null) {
            synchronized (f4515e) {
                if (f4514d == null) {
                    f4514d = new C1790a(context);
                }
            }
        }
        return f4514d;
    }

    /* renamed from: a */
    public void m400a() {
        try {
            try {
                C1805b.m370a("Startup");
                m399b(this.f4518c.getPackageManager().getProviderInfo(new ComponentName(this.f4518c.getPackageName(), InitializationProvider.class.getName()), 128).metaData);
            } catch (PackageManager.NameNotFoundException e) {
                throw new C1793d(e);
            }
        } finally {
            C1805b.m369b();
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* renamed from: b */
    public void m399b(Bundle bundle) {
        String string = this.f4518c.getString(C1792c.androidx_startup);
        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 (InterfaceC1791b.class.isAssignableFrom(cls)) {
                            this.f4517b.add(cls);
                        }
                    }
                }
                for (Class<? extends InterfaceC1791b<?>> cls2 : this.f4517b) {
                    m397d(cls2, hashSet);
                }
            } catch (ClassNotFoundException e) {
                throw new C1793d(e);
            }
        }
    }

    /* renamed from: c */
    public <T> T m398c(Class<? extends InterfaceC1791b<?>> cls) {
        T t;
        synchronized (f4515e) {
            t = (T) this.f4516a.get(cls);
            if (t == null) {
                t = (T) m397d(cls, new HashSet());
            }
        }
        return t;
    }

    /* renamed from: d */
    public final <T> T m397d(Class<? extends InterfaceC1791b<?>> cls, Set<Class<?>> set) {
        T t;
        if (C1805b.m367d()) {
            try {
                C1805b.m370a(cls.getSimpleName());
            } finally {
                C1805b.m369b();
            }
        }
        if (set.contains(cls)) {
            throw new IllegalStateException(String.format("Cannot initialize %s. Cycle detected.", cls.getName()));
        }
        if (this.f4516a.containsKey(cls)) {
            t = (T) this.f4516a.get(cls);
        } else {
            set.add(cls);
            InterfaceC1791b<?> newInstance = cls.getDeclaredConstructor(new Class[0]).newInstance(new Object[0]);
            List<Class<? extends InterfaceC1791b<?>>> mo393a = newInstance.mo393a();
            if (!mo393a.isEmpty()) {
                for (Class<? extends InterfaceC1791b<?>> cls2 : mo393a) {
                    if (!this.f4516a.containsKey(cls2)) {
                        m397d(cls2, set);
                    }
                }
            }
            t = (T) newInstance.mo392b(this.f4518c);
            set.remove(cls);
            this.f4516a.put(cls, t);
        }
        return t;
    }

    /* renamed from: f */
    public <T> T m395f(Class<? extends InterfaceC1791b<T>> cls) {
        return (T) m398c(cls);
    }

    /* renamed from: g */
    public boolean m394g(Class<? extends InterfaceC1791b<?>> cls) {
        return this.f4517b.contains(cls);
    }
}