package o;

import android.content.Context;
import androidx.work.impl.WorkDatabase;
import com.google.firebase.components.ComponentRegistrar;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.Rj, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C0450Rj implements InterfaceC0217Ij, InterfaceC2956xx {
    public static final C0398Pj s = new C0398Pj(0);
    public final Object l;
    public final Object m;
    public final Object n;

    /* renamed from: o, reason: collision with root package name */
    public final Object f317o;
    public final Object p;
    public final Object q;
    public final Object r;

    public C0450Rj(BZ bz, BZ bz2, BZ bz3, BZ bz4, BZ bz5, BZ bz6, G0 g0) {
        this.l = bz;
        this.m = bz2;
        this.n = bz3;
        this.f317o = bz4;
        this.p = bz5;
        this.q = bz6;
        this.r = g0;
    }

    @Override // o.InterfaceC0217Ij
    public synchronized DZ b(JZ jz) {
        BK bk = (BK) ((HashMap) this.n).get(jz);
        if (bk != null) {
            return bk;
        }
        return s;
    }

    @Override // o.InterfaceC0217Ij
    public synchronized DZ d(JZ jz) {
        AbstractC0752ap.v(jz, "Null interface requested.");
        return (DZ) ((HashMap) this.m).get(jz);
    }

    @Override // o.InterfaceC0217Ij
    public LU g(JZ jz) {
        DZ dzD = d(jz);
        return dzD == null ? new LU(LU.c, LU.d) : dzD instanceof LU ? (LU) dzD : new LU(null, dzD);
    }

    @Override // o.CZ
    public Object get() {
        return new C2692v80((C2121p70) ((CZ) this.l).get(), (C1457i70) ((CZ) this.m).get(), (InterfaceC1169f70) ((CZ) this.n).get(), (C3017yf0) ((CZ) this.f317o).get(), (InterfaceC1326gp) ((CZ) this.p).get(), (OY) ((BZ) this.q).get(), (InterfaceC2747vn) ((CZ) this.r).get());
    }

    public void h(HashMap map, boolean z) {
        ArrayDeque arrayDeque;
        for (Map.Entry entry : map.entrySet()) {
            C2549tj c2549tj = (C2549tj) entry.getKey();
            DZ dz = (DZ) entry.getValue();
            int i = c2549tj.d;
            if (i == 1 || (i == 2 && z)) {
                dz.get();
            }
        }
        C0178Gw c0178Gw = (C0178Gw) this.p;
        synchronized (c0178Gw) {
            try {
                arrayDeque = c0178Gw.b;
                if (arrayDeque != null) {
                    c0178Gw.b = null;
                } else {
                    arrayDeque = null;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        if (arrayDeque != null) {
            Iterator it = arrayDeque.iterator();
            if (it.hasNext()) {
                it.next().getClass();
                throw new ClassCastException();
            }
        }
    }

    public void i() {
        HashMap map = (HashMap) this.m;
        HashMap map2 = (HashMap) this.n;
        for (C2549tj c2549tj : ((HashMap) this.l).keySet()) {
            for (C2660ur c2660ur : c2549tj.c) {
                boolean z = c2660ur.b == 2;
                JZ jz = c2660ur.a;
                if (z && !map2.containsKey(jz)) {
                    Set set = Collections.EMPTY_SET;
                    BK bk = new BK();
                    bk.b = null;
                    bk.a = Collections.newSetFromMap(new ConcurrentHashMap());
                    bk.a.addAll(set);
                    map2.put(jz, bk);
                } else if (map.containsKey(jz)) {
                    continue;
                } else {
                    int i = c2660ur.b;
                    if (i == 1) {
                        throw new C2850wr("Unsatisfied dependency for component " + c2549tj + ": " + jz);
                    }
                    if (i != 2) {
                        map.put(jz, new LU(LU.c, LU.d));
                    }
                }
            }
        }
    }

    public ArrayList j(ArrayList arrayList) {
        HashMap map = (HashMap) this.m;
        ArrayList arrayList2 = new ArrayList();
        int size = arrayList.size();
        int i = 0;
        while (i < size) {
            Object obj = arrayList.get(i);
            i++;
            C2549tj c2549tj = (C2549tj) obj;
            if (c2549tj.e == 0) {
                DZ dz = (DZ) ((HashMap) this.l).get(c2549tj);
                for (JZ jz : c2549tj.b) {
                    if (map.containsKey(jz)) {
                        arrayList2.add(new O3(4, (LU) ((DZ) map.get(jz)), dz));
                    } else {
                        map.put(jz, dz);
                    }
                }
            }
        }
        return arrayList2;
    }

    public ArrayList k() {
        HashMap map = (HashMap) this.n;
        ArrayList arrayList = new ArrayList();
        HashMap map2 = new HashMap();
        for (Map.Entry entry : ((HashMap) this.l).entrySet()) {
            C2549tj c2549tj = (C2549tj) entry.getKey();
            if (c2549tj.e != 0) {
                DZ dz = (DZ) entry.getValue();
                for (JZ jz : c2549tj.b) {
                    if (!map2.containsKey(jz)) {
                        map2.put(jz, new HashSet());
                    }
                    ((Set) map2.get(jz)).add(dz);
                }
            }
        }
        for (Map.Entry entry2 : map2.entrySet()) {
            if (map.containsKey(entry2.getKey())) {
                BK bk = (BK) map.get(entry2.getKey());
                Iterator it = ((Set) entry2.getValue()).iterator();
                while (it.hasNext()) {
                    arrayList.add(new O3(5, bk, (DZ) it.next()));
                }
            } else {
                JZ jz2 = (JZ) entry2.getKey();
                Set set = (Set) ((Collection) entry2.getValue());
                BK bk2 = new BK();
                bk2.b = null;
                bk2.a = Collections.newSetFromMap(new ConcurrentHashMap());
                bk2.a.addAll(set);
                map.put(jz2, bk2);
            }
        }
        return arrayList;
    }

    public C0450Rj(ArrayList arrayList, ArrayList arrayList2, C0688a6 c0688a6) {
        Dh0 dh0 = Dh0.l;
        this.l = new HashMap();
        this.m = new HashMap();
        this.n = new HashMap();
        this.f317o = new HashSet();
        this.q = new AtomicReference();
        C0178Gw c0178Gw = new C0178Gw();
        this.p = c0178Gw;
        this.r = c0688a6;
        ArrayList arrayList3 = new ArrayList();
        arrayList3.add(C2549tj.c(c0178Gw, C0178Gw.class, InterfaceC2250qb0.class, GZ.class));
        int i = 0;
        arrayList3.add(C2549tj.c(this, C0450Rj.class, new Class[0]));
        int size = arrayList2.size();
        int i2 = 0;
        while (i2 < size) {
            Object obj = arrayList2.get(i2);
            i2++;
            C2549tj c2549tj = (C2549tj) obj;
            if (c2549tj != null) {
                arrayList3.add(c2549tj);
            }
        }
        ArrayList arrayList4 = new ArrayList();
        int size2 = arrayList.size();
        int i3 = 0;
        while (i3 < size2) {
            Object obj2 = arrayList.get(i3);
            i3++;
            arrayList4.add(obj2);
        }
        ArrayList arrayList5 = new ArrayList();
        synchronized (this) {
            Iterator it = arrayList4.iterator();
            while (it.hasNext()) {
                try {
                    ComponentRegistrar componentRegistrar = (ComponentRegistrar) ((DZ) it.next()).get();
                    if (componentRegistrar != null) {
                        arrayList3.addAll(((C0688a6) this.r).m(componentRegistrar));
                        it.remove();
                    }
                } catch (FI unused) {
                    it.remove();
                }
            }
            Iterator it2 = arrayList3.iterator();
            while (it2.hasNext()) {
                Object[] array = ((C2549tj) it2.next()).b.toArray();
                int length = array.length;
                int i4 = 0;
                while (true) {
                    if (i4 < length) {
                        Object obj3 = array[i4];
                        if (obj3.toString().contains("kotlinx.coroutines.CoroutineDispatcher")) {
                            if (((HashSet) this.f317o).contains(obj3.toString())) {
                                it2.remove();
                                break;
                            }
                            ((HashSet) this.f317o).add(obj3.toString());
                        }
                        i4++;
                    }
                }
            }
            if (((HashMap) this.l).isEmpty()) {
                AbstractC1904ms0.c(arrayList3);
            } else {
                ArrayList arrayList6 = new ArrayList(((HashMap) this.l).keySet());
                arrayList6.addAll(arrayList3);
                AbstractC1904ms0.c(arrayList6);
            }
            int size3 = arrayList3.size();
            int i5 = 0;
            while (i5 < size3) {
                Object obj4 = arrayList3.get(i5);
                i5++;
                C2549tj c2549tj2 = (C2549tj) obj4;
                ((HashMap) this.l).put(c2549tj2, new AK(new C0424Qj(i, this, c2549tj2)));
            }
            arrayList5.addAll(j(arrayList3));
            arrayList5.addAll(k());
            i();
        }
        int size4 = arrayList5.size();
        while (i < size4) {
            Object obj5 = arrayList5.get(i);
            i++;
            ((Runnable) obj5).run();
        }
        Boolean bool = (Boolean) ((AtomicReference) this.q).get();
        if (bool != null) {
            h((HashMap) this.l, bool.booleanValue());
        }
    }

    public C0450Rj(Context context, C1414hl c1414hl, C2062oc0 c2062oc0, XY xy, WorkDatabase workDatabase, Dm0 dm0, ArrayList arrayList) {
        new BP();
        this.l = context.getApplicationContext();
        this.n = c2062oc0;
        this.m = xy;
        this.f317o = c1414hl;
        this.p = workDatabase;
        this.q = dm0;
        this.r = arrayList;
    }
}
