package t2;

import E3.v;
import android.content.Context;
import android.os.Bundle;
import android.os.Trace;
import com.debridstream.tv.R;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import n2.AbstractC2612c;

/* JADX INFO: renamed from: t2.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C2946a {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static volatile C2946a f24290d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final Object f24291e = new Object();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Context f24294c;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final HashSet f24293b = new HashSet();

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final HashMap f24292a = new HashMap();

    public C2946a(Context context) {
        this.f24294c = context.getApplicationContext();
    }

    public static C2946a c(Context context) {
        if (f24290d == null) {
            synchronized (f24291e) {
                try {
                    if (f24290d == null) {
                        f24290d = new C2946a(context);
                    }
                } finally {
                }
            }
        }
        return f24290d;
    }

    public final void a(Bundle bundle) {
        HashSet hashSet;
        String string = this.f24294c.getString(R.string.androidx_startup);
        if (bundle != null) {
            try {
                HashSet hashSet2 = new HashSet();
                Iterator<String> it = bundle.keySet().iterator();
                while (true) {
                    boolean zHasNext = it.hasNext();
                    hashSet = this.f24293b;
                    if (!zHasNext) {
                        break;
                    }
                    String next = it.next();
                    if (string.equals(bundle.getString(next, null))) {
                        Class<?> cls = Class.forName(next);
                        if (InterfaceC2947b.class.isAssignableFrom(cls)) {
                            hashSet.add(cls);
                        }
                    }
                }
                Iterator it2 = hashSet.iterator();
                while (it2.hasNext()) {
                    b((Class) it2.next(), hashSet2);
                }
            } catch (ClassNotFoundException e6) {
                throw new v(e6);
            }
        }
    }

    public final Object b(Class cls, HashSet hashSet) {
        Object objB;
        if (AbstractC2612c.p()) {
            try {
                AbstractC2612c.d(cls.getSimpleName());
            } catch (Throwable th) {
                Trace.endSection();
                throw th;
            }
        }
        if (hashSet.contains(cls)) {
            throw new IllegalStateException("Cannot initialize " + cls.getName() + ". Cycle detected.");
        }
        HashMap map = this.f24292a;
        if (map.containsKey(cls)) {
            objB = map.get(cls);
        } else {
            hashSet.add(cls);
            try {
                InterfaceC2947b interfaceC2947b = (InterfaceC2947b) cls.getDeclaredConstructor(new Class[0]).newInstance(new Object[0]);
                List<Class> listA = interfaceC2947b.a();
                if (!listA.isEmpty()) {
                    for (Class cls2 : listA) {
                        if (!map.containsKey(cls2)) {
                            b(cls2, hashSet);
                        }
                    }
                }
                objB = interfaceC2947b.b(this.f24294c);
                hashSet.remove(cls);
                map.put(cls, objB);
            } catch (Throwable th2) {
                throw new v(th2);
            }
        }
        Trace.endSection();
        return objB;
    }
}
