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 f6509b;

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

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

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

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

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

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

    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 f6516c;

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

        @Override // g.i0.b
        public void a() {
            boolean z;
            d0 d0VarB;
            y.this.f6511d.i();
            try {
                try {
                    d0VarB = y.this.b();
                } catch (IOException e2) {
                    e = e2;
                    z = false;
                }
                try {
                    if (y.this.f6510c.f6228d) {
                        ((t.a) this.f6516c).a(y.this, new IOException("Canceled"));
                    } else {
                        ((t.a) this.f6516c).b(y.this, d0VarB);
                    }
                } catch (IOException e3) {
                    e = e3;
                    z = true;
                    IOException iOExceptionD = y.this.d(e);
                    if (z) {
                        g.i0.j.f.f6419a.l(4, "Callback failure for " + y.this.e(), iOExceptionD);
                    } else {
                        Objects.requireNonNull(y.this.f6512e);
                        ((t.a) this.f6516c).a(y.this, iOExceptionD);
                    }
                }
                l lVar = y.this.f6509b.f6492d;
                lVar.a(lVar.f6437c, this);
            } catch (Throwable th) {
                l lVar2 = y.this.f6509b.f6492d;
                lVar2.a(lVar2.f6437c, this);
                throw th;
            }
        }
    }

    public y(w wVar, z zVar, boolean z) {
        this.f6509b = wVar;
        this.f6513f = zVar;
        this.f6514g = z;
        this.f6510c = new g.i0.g.h(wVar, z);
        a aVar = new a();
        this.f6511d = 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.f6510c;
        hVar.f6228d = true;
        g.i0.f.g gVar = hVar.f6226b;
        if (gVar != null) {
            synchronized (gVar.f6198d) {
                gVar.m = true;
                cVar = gVar.n;
                cVar2 = gVar.f6204j;
            }
            if (cVar != null) {
                cVar.a();
            } else if (cVar2 != null) {
                g.i0.c.e(cVar2.f6175d);
            }
        }
    }

    public d0 b() {
        ArrayList arrayList = new ArrayList();
        arrayList.addAll(this.f6509b.f6495g);
        arrayList.add(this.f6510c);
        arrayList.add(new g.i0.g.a(this.f6509b.k));
        Objects.requireNonNull(this.f6509b);
        arrayList.add(new g.i0.e.a(null));
        arrayList.add(new g.i0.f.a(this.f6509b));
        if (!this.f6514g) {
            arrayList.addAll(this.f6509b.f6496h);
        }
        arrayList.add(new g.i0.g.b(this.f6514g));
        z zVar = this.f6513f;
        n nVar = this.f6512e;
        w wVar = this.f6509b;
        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.f6513f.f6518a.k("/...");
        Objects.requireNonNull(aVarK);
        aVarK.f6464b = s.b("", " \"':;<=>@[]^`{}|/\\?#", false, false, false, true);
        aVarK.f6465c = s.b("", " \"':;<=>@[]^`{}|/\\?#", false, false, false, true);
        return aVarK.a().f6462j;
    }

    public Object clone() {
        w wVar = this.f6509b;
        y yVar = new y(wVar, this.f6513f, this.f6514g);
        yVar.f6512e = ((o) wVar.f6497i).f6441a;
        return yVar;
    }

    @Nullable
    public IOException d(@Nullable IOException iOException) {
        if (!this.f6511d.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.f6510c.f6228d ? "canceled " : "");
        sb.append(this.f6514g ? "web socket" : "call");
        sb.append(" to ");
        sb.append(c());
        return sb.toString();
    }
}
