package x0;

import A2.u;
import android.content.Context;
import android.os.Bundle;
import android.os.Trace;
import com.riyaz.zvytour.R;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

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

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

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

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

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

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

    public C1098a(Context context) {
        this.f10694c = context.getApplicationContext();
    }

    public static C1098a c(Context context) {
        if (f10690d == null) {
            synchronized (f10691e) {
                try {
                    if (f10690d == null) {
                        f10690d = new C1098a(context);
                    }
                } finally {
                }
            }
        }
        return f10690d;
    }

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

    public final Object b(Class cls, HashSet hashSet) {
        Object objB;
        if (android.support.v4.media.session.b.k()) {
            try {
                Trace.beginSection(android.support.v4.media.session.b.t(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.f10692a;
        if (map.containsKey(cls)) {
            objB = map.get(cls);
        } else {
            hashSet.add(cls);
            try {
                InterfaceC1099b interfaceC1099b = (InterfaceC1099b) cls.getDeclaredConstructor(new Class[0]).newInstance(new Object[0]);
                List<Class> listA = interfaceC1099b.a();
                if (!listA.isEmpty()) {
                    for (Class cls2 : listA) {
                        if (!map.containsKey(cls2)) {
                            b(cls2, hashSet);
                        }
                    }
                }
                objB = interfaceC1099b.b(this.f10694c);
                hashSet.remove(cls);
                map.put(cls, objB);
            } catch (Throwable th2) {
                throw new u(th2);
            }
        }
        Trace.endSection();
        return objB;
    }
}
