package g;

import g.s;
import j.t;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.ArrayList;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;

/* JADX INFO: loaded from: classes.dex */
public final class y implements d {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final w f6495b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final g.i0.g.h f6496c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final h.c f6497d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    @Nullable
    public n f6498e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final z f6499f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final boolean f6500g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public boolean f6501h;

    public class a extends h.c {
        public a() {
        }

        @Override // h.c
        public void m() {
            y.this.a();
        }
    }

    public final class b extends g.i0.b {

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

        public b(e eVar) {
            super("OkHttp %s", y.this.c());
            this.f6502c = eVar;
        }

        @Override // g.i0.b
        public void a() {
            boolean z;
            d0 d0VarB;
            y.this.f6497d.i();
            try {
                try {
                    d0VarB = y.this.b();
                } catch (IOException e2) {
                    e = e2;
                    z = false;
                }
                try {
                    if (y.this.f6496c.f6214d) {
                        ((t.a) this.f6502c).a(y.this, new IOException("Canceled"));
                    } else {
                        ((t.a) this.f6502c).b(y.this, d0VarB);
                    }
                } catch (IOException e3) {
                    e = e3;
                    z = true;
                    IOException iOExceptionD = y.this.d(e);
                    if (z) {
                        g.i0.j.f.f6405a.l(4, "Callback failure for " + y.this.e(), iOExceptionD);
                    } else {
                        Objects.requireNonNull(y.this.f6498e);
                        ((t.a) this.f6502c).a(y.this, iOExceptionD);
                    }
                }
                l lVar = y.this.f6495b.f6478d;
                lVar.a(lVar.f6423c, this);
            } catch (Throwable th) {
                l lVar2 = y.this.f6495b.f6478d;
                lVar2.a(lVar2.f6423c, this);
                throw th;
            }
        }
    }

    public y(w wVar, z zVar, boolean z) {
        this.f6495b = wVar;
        this.f6499f = zVar;
        this.f6500g = z;
        this.f6496c = new g.i0.g.h(wVar, z);
        a aVar = new a();
        this.f6497d = aVar;
        Objects.requireNonNull(wVar);
        aVar.g(0, TimeUnit.MILLISECONDS);
    }

    public void a() {
        g.i0.g.c cVar;
        g.i0.f.c cVar2;
        g.i0.g.h hVar = this.f6496c;
        hVar.f6214d = true;
        g.i0.f.g gVar = hVar.f6212b;
        if (gVar != null) {
            synchronized (gVar.f6184d) {
                gVar.m = true;
                cVar = gVar.n;
                cVar2 = gVar.f6190j;
            }
            if (cVar != null) {
                cVar.a();
            } else if (cVar2 != null) {
                g.i0.c.e(cVar2.f6161d);
            }
        }
    }

    public d0 b() {
        ArrayList arrayList = new ArrayList();
        arrayList.addAll(this.f6495b.f6481g);
        arrayList.add(this.f6496c);
        arrayList.add(new g.i0.g.a(this.f6495b.k));
        Objects.requireNonNull(this.f6495b);
        arrayList.add(new g.i0.e.a(null));
        arrayList.add(new g.i0.f.a(this.f6495b));
        if (!this.f6500g) {
            arrayList.addAll(this.f6495b.f6482h);
        }
        arrayList.add(new g.i0.g.b(this.f6500g));
        z zVar = this.f6499f;
        n nVar = this.f6498e;
        w wVar = this.f6495b;
        return new g.i0.g.f(arrayList, null, null, null, 0, zVar, this, nVar, wVar.x, wVar.y, wVar.z).a(zVar);
    }

    public String c() {
        s.a aVarK = this.f6499f.f6504a.k("/...");
        Objects.requireNonNull(aVarK);
        aVarK.f6450b = s.b("", " \"':;<=>@[]^`{}|/\\?#", false, false, false, true);
        aVarK.f6451c = s.b("", " \"':;<=>@[]^`{}|/\\?#", false, false, false, true);
        return aVarK.a().f6448j;
    }

    public Object clone() {
        w wVar = this.f6495b;
        y yVar = new y(wVar, this.f6499f, this.f6500g);
        yVar.f6498e = ((o) wVar.f6483i).f6427a;
        return yVar;
    }

    @Nullable
    public IOException d(@Nullable IOException iOException) {
        if (!this.f6497d.k()) {
            return iOException;
        }
        InterruptedIOException interruptedIOException = new InterruptedIOException("timeout");
        if (iOException != null) {
            interruptedIOException.initCause(iOException);
        }
        return interruptedIOException;
    }

    public String e() {
        StringBuilder sb = new StringBuilder();
        sb.append(this.f6496c.f6214d ? "canceled " : "");
        sb.append(this.f6500g ? "web socket" : "call");
        sb.append(" to ");
        sb.append(c());
        return sb.toString();
    }
}
