package kotlinx.coroutines.internal;

import F1.y0;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;

/* JADX INFO: loaded from: classes.dex */
public final class l {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final l f5170a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final y0 f5171b;

    static {
        l lVar = new l();
        f5170a = lVar;
        s.e("kotlinx.coroutines.fast.service.loader", true);
        f5171b = lVar.a();
    }

    private l() {
    }

    private final y0 a() {
        Object next;
        try {
            List listL = D1.i.l(D1.i.c(ServiceLoader.load(MainDispatcherFactory.class, MainDispatcherFactory.class.getClassLoader()).iterator()));
            Iterator it = listL.iterator();
            if (it.hasNext()) {
                next = it.next();
                if (it.hasNext()) {
                    int loadPriority = ((MainDispatcherFactory) next).getLoadPriority();
                    do {
                        Object next2 = it.next();
                        int loadPriority2 = ((MainDispatcherFactory) next2).getLoadPriority();
                        if (loadPriority < loadPriority2) {
                            next = next2;
                            loadPriority = loadPriority2;
                        }
                    } while (it.hasNext());
                }
            } else {
                next = null;
            }
            MainDispatcherFactory mainDispatcherFactory = (MainDispatcherFactory) next;
            if (mainDispatcherFactory != null) {
                return m.d(mainDispatcherFactory, listL);
            }
            m.b(null, null, 3, null);
            return null;
        } catch (Throwable th) {
            m.b(th, null, 2, null);
            return null;
        }
    }
}
