package defpackage;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.lang.ref.Reference;
import java.net.Socket;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/* JADX INFO: renamed from: ᵵᵾʝ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C4778 implements Cloneable {

    /* JADX INFO: renamed from: ʿٴˇ, reason: contains not printable characters */
    public C0764 f18167;

    /* JADX INFO: renamed from: ˀᵭ, reason: contains not printable characters */
    public boolean f18168;

    /* JADX INFO: renamed from: ˁˌᵩ, reason: contains not printable characters */
    public boolean f18169;

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public Object f18170;

    /* JADX INFO: renamed from: ˉᵵᵜ, reason: contains not printable characters */
    public boolean f18171;

    /* JADX INFO: renamed from: ˊᵡᵗʨ, reason: contains not printable characters */
    public volatile boolean f18172;

    /* JADX INFO: renamed from: ˊᵾʽʼ, reason: contains not printable characters */
    public boolean f18173;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public final C3423 f18174;

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public InterfaceC2274 f18175;

    /* JADX INFO: renamed from: ˑˊᵲ, reason: contains not printable characters */
    public boolean f18176;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public final C2736 f18177;

    /* JADX INFO: renamed from: ᵛˑﹳ, reason: contains not printable characters */
    public volatile C0764 f18178;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public final C4402 f18179;

    /* JADX INFO: renamed from: ᵠˏˏ, reason: contains not printable characters */
    public boolean f18180;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public volatile AbstractC0396 f18181;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public final C4705 f18182;

    /* JADX INFO: renamed from: ᵵᵬᵽ, reason: contains not printable characters */
    public final CopyOnWriteArrayList f18183;

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public final AtomicBoolean f18184;

    /* JADX INFO: renamed from: ᵸˆˁ, reason: contains not printable characters */
    public C4013 f18185;

    static {
        AtomicReferenceFieldUpdater.newUpdater(C4778.class, AbstractC0396.class, "ᵨᵼⁱ");
    }

    public C4778(C3423 c3423, C4402 c4402) {
        this.f18174 = c3423;
        this.f18179 = c4402;
        this.f18177 = (C2736) c3423.f13205.ˌᴵ;
        c3423.f13207.getClass();
        this.f18181 = AbstractC0396.f2246;
        C4705 c4705 = new C4705(this);
        c4705.mo3055(0L);
        this.f18182 = c4705;
        this.f18184 = new AtomicBoolean();
        this.f18173 = true;
        this.f18183 = new CopyOnWriteArrayList();
        new AtomicReference(c4402.f16707);
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public static final String m9962(C4778 c4778) {
        StringBuilder sb = new StringBuilder();
        sb.append(c4778.f18172 ? "canceled " : "");
        sb.append("call");
        sb.append(" to ");
        sb.append(c4778.f18179.f16708.m4640());
        return sb.toString();
    }

    public final void cancel() {
        if (this.f18172) {
            return;
        }
        this.f18172 = true;
        C0764 c0764 = this.f18178;
        if (c0764 != null) {
            ((InterfaceC0340) c0764.f3429).cancel();
        }
        Iterator it = this.f18183.iterator();
        while (it.hasNext()) {
            ((InterfaceC4344) it.next()).cancel();
        }
        this.f18181.getClass();
    }

    public final Object clone() {
        return new C4778(this.f18174, this.f18179);
    }

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public final void m9963(boolean z) {
        C0764 c0764;
        synchronized (this) {
            if (!this.f18173) {
                throw new IllegalStateException("released");
            }
        }
        if (z && (c0764 = this.f18178) != null) {
            ((InterfaceC0340) c0764.f3429).cancel();
            ((C4778) c0764.f3428).m9966(c0764, true, true, true, true, null);
        }
        this.f18167 = null;
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final IOException m9964(IOException iOException) {
        IOException interruptedIOException;
        Socket socketM9965;
        TimeZone timeZone = AbstractC1190.f5068;
        C4013 c4013 = this.f18185;
        if (c4013 != null) {
            synchronized (c4013) {
                socketM9965 = m9965();
            }
            if (this.f18185 == null) {
                if (socketM9965 != null) {
                    AbstractC1190.m3664(socketM9965);
                }
                this.f18181.getClass();
            } else if (socketM9965 != null) {
                ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Check failed.");
                return null;
            }
        }
        if (!this.f18176 && this.f18182.m10665()) {
            interruptedIOException = new InterruptedIOException("timeout");
            if (iOException != null) {
                interruptedIOException.initCause(iOException);
            }
        } else {
            interruptedIOException = iOException;
        }
        AbstractC0396 abstractC0396 = this.f18181;
        if (iOException != null) {
            abstractC0396.getClass();
            return interruptedIOException;
        }
        abstractC0396.getClass();
        return interruptedIOException;
    }

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public final Socket m9965() {
        C4013 c4013 = this.f18185;
        TimeZone timeZone = AbstractC1190.f5068;
        ArrayList arrayList = c4013.f15415;
        int size = arrayList.size();
        int i = 0;
        int i2 = 0;
        while (true) {
            if (i2 >= size) {
                i = -1;
                break;
            }
            Object obj = arrayList.get(i2);
            i2++;
            if (ᵥˈᵛ.ˊᵫᵗ(((Reference) obj).get(), this)) {
                break;
            }
            i++;
        }
        if (i == -1) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Check failed.");
            return null;
        }
        arrayList.remove(i);
        this.f18185 = null;
        if (!arrayList.isEmpty()) {
            return null;
        }
        c4013.f15419 = System.nanoTime();
        C2736 c2736 = this.f18177;
        ConcurrentLinkedQueue concurrentLinkedQueue = (ConcurrentLinkedQueue) c2736.f10523;
        C5380 c5380 = (C5380) c2736.f10520;
        TimeZone timeZone2 = AbstractC1190.f5068;
        if (!c4013.f15420) {
            c5380.m10972((C2280) c2736.f10521, 0L);
            return null;
        }
        c4013.f15420 = true;
        concurrentLinkedQueue.remove(c4013);
        if (concurrentLinkedQueue.isEmpty()) {
            c5380.m10971();
        }
        return c4013.f15416;
    }

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public final IOException m9966(C0764 c0764, boolean z, boolean z2, boolean z3, boolean z4, IOException iOException) {
        boolean z5;
        boolean z6;
        if (c0764.equals(this.f18178)) {
            synchronized (this) {
                z5 = false;
                if (z) {
                    try {
                        if (!this.f18180) {
                            if ((z2 || !this.f18171) && ((!z4 || !this.f18169) && (!z3 || !this.f18168))) {
                            }
                        }
                        if (z) {
                            this.f18180 = false;
                        }
                        if (z2) {
                            this.f18171 = false;
                        }
                        if (z4) {
                            this.f18169 = false;
                        }
                        if (z3) {
                            this.f18168 = false;
                        }
                        boolean z7 = (this.f18180 || this.f18171 || this.f18169 || this.f18168) ? false : true;
                        if (z7) {
                            if (!this.f18173) {
                                z5 = true;
                            }
                        }
                        boolean z8 = z7;
                        z6 = z5;
                        z5 = z8;
                    } catch (Throwable th) {
                        throw th;
                    }
                } else {
                    z6 = z2 ? false : false;
                }
            }
            if (z5) {
                this.f18178 = null;
                C4013 c4013 = this.f18185;
                if (c4013 != null) {
                    c4013.m8825();
                }
            }
            if (z6) {
                return m9964(iOException);
            }
        }
        return iOException;
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public final C1120 m9967() {
        if (!this.f18184.compareAndSet(false, true)) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Already Executed");
            return null;
        }
        this.f18182.m10664();
        AbstractC2570 abstractC2570 = AbstractC2570.f9922;
        this.f18170 = AbstractC2570.f9922.mo6293();
        this.f18181.getClass();
        try {
            ᵥᵵᵶᵩ r2 = this.f18174.f13203;
            synchronized (r2) {
                ((ArrayDeque) r2.ᵯᵷʽ).add(this);
            }
            return m9970();
        } finally {
            ᵥᵵᵶᵩ r3 = this.f18174.f13203;
            r3.getClass();
            ᵥᵵᵶᵩ.ʽᵡᵢᵾ(r3, (RunnableC0911) null, this, (RunnableC0911) null, 5);
        }
    }

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public final IOException m9968(IOException iOException) {
        boolean z;
        synchronized (this) {
            z = false;
            if (this.f18173) {
                this.f18173 = false;
                if (!this.f18180 && !this.f18171 && !this.f18169) {
                    if (!this.f18168) {
                        z = true;
                    }
                }
            }
        }
        return z ? m9964(iOException) : iOException;
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final void m9969(C4013 c4013) {
        TimeZone timeZone = AbstractC1190.f5068;
        if (this.f18185 != null) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Check failed.");
        } else {
            this.f18185 = c4013;
            c4013.f15415.add(new C3016(this, this.f18170));
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x0099  */
    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final C1120 m9970() {
        ArrayList arrayList = new ArrayList();
        AbstractC5477.m11101(this.f18174.f13183, arrayList);
        arrayList.add(new C5468(5));
        arrayList.add(new C5468(3));
        arrayList.add(new C5468(4));
        arrayList.add(C5468.f20704);
        AbstractC5477.m11101(this.f18174.f13191, arrayList);
        arrayList.add(C5468.f20703);
        C4402 c4402 = this.f18179;
        C3423 c3423 = this.f18174;
        C2729 c2729 = new C2729(this, arrayList, 0, null, c4402, c3423.f13189, c3423.f13193, c3423.f13192, c3423.f13204, c3423.f13190, c3423.f13205, c3423.f13202, c3423.f13206, c3423.f13184, c3423.f13194, c3423.f13199, c3423.f13196, c3423.f13188, c3423.f13198, c3423.f13195, c3423.f13186);
        boolean z = false;
        try {
            try {
                C1120 c1120M6629 = c2729.m6629(c4402);
                if (this.f18172) {
                    AbstractC1701.m4653(c1120M6629);
                    throw new IOException("Canceled");
                }
                m9968(null);
                return c1120M6629;
            } catch (IOException e) {
                z = true;
                throw m9968(e);
            }
        } catch (Throwable th) {
            if (!z) {
            }
            throw th;
        }
        if (!z) {
            m9968(null);
        }
        throw th;
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final void m9971(InterfaceC3525 interfaceC3525) {
        if (!this.f18184.compareAndSet(false, true)) {
            ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Already Executed");
            return;
        }
        AbstractC2570 abstractC2570 = AbstractC2570.f9922;
        this.f18170 = AbstractC2570.f9922.mo6293();
        this.f18181.getClass();
        ᵥᵵᵶᵩ r0 = this.f18174.f13203;
        RunnableC0911 runnableC0911 = new RunnableC0911(this, interfaceC3525);
        r0.getClass();
        ᵥᵵᵶᵩ.ʽᵡᵢᵾ(r0, runnableC0911, (C4778) null, (RunnableC0911) null, 6);
    }
}
