package defpackage;

import androidx.media3.container.NalUnitUtil;
import androidx.media3.exoplayer.rtsp.RtspHeaders;
import androidx.media3.extractor.AacUtil;
import defpackage.gj1;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Set;
import javax.net.ssl.HttpsURLConnection;
import kotlin.Metadata;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.ContinuationImpl;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\n\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\u0018\u00002\u00020\u0001¨\u0006\u0002"}, d2 = {"Lgj;", "Lfb4;", "ktor-client-android"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public final class gj extends fb4 {
    public static final /* synthetic */ int i = 0;
    public final mj e;
    public final Set f;

    public gj(mj mjVar) {
        super("ktor-android");
        this.e = mjVar;
        this.f = st.ao(new ib4[]{re4.a, g98.a});
    }

    @Override // defpackage.fb4, defpackage.ab4
    /* JADX INFO: renamed from: bj, reason: from getter */
    public final Set getF() {
        return this.f;
    }

    /* JADX WARN: Removed duplicated region for block: B:68:0x01cd A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:69:0x01ce A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0017  */
    @Override // defpackage.ab4
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object bp(gd4 gd4Var, ContinuationImpl continuationImpl) throws IOException {
        fj fjVar;
        gd4 gd4Var2;
        Object obj;
        gj gjVar;
        HttpURLConnection httpURLConnection;
        gj1 gj1Var;
        HttpURLConnection httpURLConnection2;
        ns3 ns3Var;
        vy6 vy6Var;
        gd4 gd4Var3;
        gj1 gj1Var2;
        ns3 ns3Var2;
        vy6 vy6Var2;
        gd4 gd4Var4;
        if (continuationImpl instanceof fj) {
            fjVar = (fj) continuationImpl;
            int i2 = fjVar.j;
            if ((i2 & Integer.MIN_VALUE) != 0) {
                fjVar.j = i2 - Integer.MIN_VALUE;
            } else {
                fjVar = new fj(this, continuationImpl);
            }
        }
        Object obj2 = fjVar.f;
        ck1 ck1Var = ck1.a;
        int i3 = fjVar.j;
        if (i3 == 0) {
            s38.b(obj2);
            fjVar.a = this;
            gd4Var2 = gd4Var;
            fjVar.b = gd4Var2;
            fjVar.j = 1;
            Set set = cea.a;
            gj1.b bVarCb = fjVar.getB().cb(e55.b);
            cr4.d(bVarCb);
            obj = ((e55) bVarCb).a;
            if (obj != ck1Var) {
                gjVar = this;
            }
        }
        if (i3 != 1) {
            if (i3 != 2) {
                if (i3 != 3) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(obj2);
                return obj2;
            }
            httpURLConnection2 = fjVar.e;
            vy6Var = fjVar.d;
            ns3Var = fjVar.c;
            gj1Var = (gj1) fjVar.b;
            gd4Var3 = (gd4) fjVar.a;
            s38.b(obj2);
            httpURLConnection = httpURLConnection2;
            vy6Var2 = vy6Var;
            ns3Var2 = ns3Var;
            gj1Var2 = gj1Var;
            gd4Var4 = gd4Var3;
            ej ejVar = new ej(gj1Var2, gd4Var4, vy6Var2, ns3Var2, 0);
            fjVar.a = null;
            fjVar.b = null;
            fjVar.c = null;
            fjVar.d = null;
            fjVar.e = null;
            fjVar.j = 3;
            Object objA = uj.a(httpURLConnection, gd4Var4, ejVar, fjVar);
            return objA == ck1Var ? ck1Var : objA;
        }
        gd4 gd4Var5 = (gd4) fjVar.b;
        gjVar = (gj) fjVar.a;
        s38.b(obj2);
        obj = obj2;
        gd4Var2 = gd4Var5;
        gj1 gj1Var3 = (gj1) obj;
        ns3 ns3VarB = ys1.b(null);
        faa faaVar = gd4Var2.a;
        l14 l14Var = gd4Var2.c;
        wc4 wc4Var = gd4Var2.b;
        String str = faaVar.g;
        vy6 vy6Var3 = gd4Var2.d;
        List list = qc4.a;
        String strE = l14Var.e(RtspHeaders.CONTENT_LENGTH);
        Long lBoxLong = strE != null ? Boxing.boxLong(Long.parseLong(strE)) : vy6Var3.getA();
        gjVar.getClass();
        mj mjVar = gjVar.e;
        URL url = new URL(str);
        mjVar.getClass();
        URLConnection uRLConnectionOpenConnection = url.openConnection();
        cr4.f(uRLConnectionOpenConnection, "openConnection(...)");
        httpURLConnection = (HttpURLConnection) uRLConnectionOpenConnection;
        httpURLConnection.setConnectTimeout(AacUtil.AAC_LC_MAX_RATE_BYTES_PER_SECOND);
        httpURLConnection.setReadTimeout(AacUtil.AAC_LC_MAX_RATE_BYTES_PER_SECOND);
        se4 se4Var = (se4) gd4Var2.a();
        if (se4Var != null) {
            Long l = se4Var.b;
            if (l != null) {
                httpURLConnection.setConnectTimeout(te4.c(l.longValue()));
            }
            Long l2 = se4Var.c;
            if (l2 != null) {
                httpURLConnection.setReadTimeout(te4.c(l2.longValue()));
            }
            Long l3 = se4Var.a;
            if (l3 != null) {
                long jLongValue = l3.longValue();
                if (jLongValue != Long.MAX_VALUE && (httpURLConnection.getConnectTimeout() == 0 || httpURLConnection.getConnectTimeout() > jLongValue)) {
                    httpURLConnection.setConnectTimeout(te4.c(jLongValue));
                }
            }
        }
        if (httpURLConnection instanceof HttpsURLConnection) {
            mjVar.a.invoke(httpURLConnection);
        }
        httpURLConnection.setRequestMethod(wc4Var.a);
        httpURLConnection.setUseCaches(false);
        httpURLConnection.setInstanceFollowRedirects(false);
        cea.a(l14Var, vy6Var3, new zd(httpURLConnection, 3));
        mjVar.b.invoke(httpURLConnection);
        if (!jj.a.contains(wc4Var)) {
            if (lBoxLong == null && httpURLConnection.getRequestProperty("Transfer-Encoding") == null) {
                httpURLConnection.addRequestProperty("Transfer-Encoding", "chunked");
            }
            if (lBoxLong != null) {
                httpURLConnection.setFixedLengthStreamingMode(lBoxLong.longValue());
            } else {
                httpURLConnection.setChunkedStreamingMode(0);
            }
            httpURLConnection.setDoOutput(true);
            OutputStream outputStream = httpURLConnection.getOutputStream();
            cr4.f(outputStream, "getOutputStream(...)");
            fjVar.a = gd4Var2;
            fjVar.b = gj1Var3;
            fjVar.c = ns3VarB;
            fjVar.d = vy6Var3;
            fjVar.e = httpURLConnection;
            fjVar.j = 2;
            if (jj.a(vy6Var3, outputStream, gj1Var3, fjVar) != ck1Var) {
                gj1Var = gj1Var3;
                httpURLConnection2 = httpURLConnection;
                ns3Var = ns3VarB;
                vy6Var = vy6Var3;
                gd4Var3 = gd4Var2;
                httpURLConnection = httpURLConnection2;
                vy6Var2 = vy6Var;
                ns3Var2 = ns3Var;
                gj1Var2 = gj1Var;
                gd4Var4 = gd4Var3;
                ej ejVar2 = new ej(gj1Var2, gd4Var4, vy6Var2, ns3Var2, 0);
                fjVar.a = null;
                fjVar.b = null;
                fjVar.c = null;
                fjVar.d = null;
                fjVar.e = null;
                fjVar.j = 3;
                Object objA2 = uj.a(httpURLConnection, gd4Var4, ejVar2, fjVar);
                if (objA2 == ck1Var) {
                }
            }
        }
        if (!xy6.a(vy6Var3)) {
            throw new IllegalStateException(("Request of type " + wc4Var + " couldn't send a body with the [Android] engine.").toString());
        }
        gj1Var2 = gj1Var3;
        ns3Var2 = ns3VarB;
        vy6Var2 = vy6Var3;
        gd4Var4 = gd4Var2;
        ej ejVar22 = new ej(gj1Var2, gd4Var4, vy6Var2, ns3Var2, 0);
        fjVar.a = null;
        fjVar.b = null;
        fjVar.c = null;
        fjVar.d = null;
        fjVar.e = null;
        fjVar.j = 3;
        Object objA22 = uj.a(httpURLConnection, gd4Var4, ejVar22, fjVar);
        if (objA22 == ck1Var) {
        }
    }

    @Override // defpackage.ab4
    public final kb4 f() {
        return this.e;
    }
}
