package b2;

import android.content.Context;
import android.os.Bundle;
import android.os.Trace;
import com.martsnew.tv.R;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import s7.d;

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

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

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

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

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

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

    public C0533a(Context context) {
        this.f9187c = context.getApplicationContext();
    }

    public static C0533a c(Context context) {
        if (f9183d == null) {
            synchronized (f9184e) {
                try {
                    if (f9183d == null) {
                        f9183d = new C0533a(context);
                    }
                } finally {
                }
            }
        }
        return f9183d;
    }

    public final void a(Bundle bundle) {
        HashSet hashSet;
        String string = this.f9187c.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.f9186b;
                    if (!zHasNext) {
                        break;
                    }
                    String next = it.next();
                    if (string.equals(bundle.getString(next, null))) {
                        Class<?> cls = Class.forName(next);
                        if (InterfaceC0534b.class.isAssignableFrom(cls)) {
                            hashSet.add(cls);
                        }
                    }
                }
                Iterator it2 = hashSet.iterator();
                while (it2.hasNext()) {
                    b((Class) it2.next(), hashSet2);
                }
            } catch (ClassNotFoundException e8) {
                throw new A6.b(e8);
            }
        }
    }

    public final Object b(Class cls, HashSet hashSet) {
        Object objB;
        if (d.w()) {
            try {
                d.e(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.f9185a;
        if (map.containsKey(cls)) {
            objB = map.get(cls);
        } else {
            hashSet.add(cls);
            try {
                InterfaceC0534b interfaceC0534b = (InterfaceC0534b) cls.getDeclaredConstructor(null).newInstance(null);
                List<Class> listA = interfaceC0534b.a();
                if (!listA.isEmpty()) {
                    for (Class cls2 : listA) {
                        if (!map.containsKey(cls2)) {
                            b(cls2, hashSet);
                        }
                    }
                }
                objB = interfaceC0534b.b(this.f9187c);
                hashSet.remove(cls);
                map.put(cls, objB);
            } catch (Throwable th2) {
                throw new A6.b(th2);
            }
        }
        Trace.endSection();
        return objB;
    }
}
