package defpackage;

import android.net.TrafficStats;
import android.net.Uri;
import androidx.media3.datasource.HttpDataSource$HttpDataSourceException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;

/* renamed from: ᵙˆᵰ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C2574 extends AbstractC1628 {

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public final C5553 f9989;

    /* renamed from: ˎˑː, reason: contains not printable characters */
    public HttpURLConnection f9990;

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public C4179 f9991;

    /* renamed from: ᐧﾞ, reason: contains not printable characters */
    public long f9992;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public final C5553 f9993;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public final int f9994;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public final int f9995;

    /* renamed from: ᵧـˌᵎ, reason: contains not printable characters */
    public boolean f9996;

    /* renamed from: ᵮᵠـˌ, reason: contains not printable characters */
    public InputStream f9997;

    /* renamed from: ᵶʔᵢˊ, reason: contains not printable characters */
    public long f9998;

    /* renamed from: ᵺʙ, reason: contains not printable characters */
    public int f9999;

    public C2574(int i, int i2, C5553 c5553) {
        super(true);
        this.f9995 = i;
        this.f9994 = i2;
        this.f9989 = c5553;
        this.f9993 = new C5553(0);
    }

    /* JADX WARN: Multi-variable type inference failed */
    @Override // defpackage.InterfaceC2569
    public final void close() {
        try {
            InputStream inputStream = this.f9997;
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    String str = AbstractC3558.f13329;
                    throw new HttpDataSource$HttpDataSourceException(2000, 3, e);
                }
            }
        } finally {
            this.f9997 = null;
            m6472();
            if (this.f9996) {
                this.f9996 = false;
                m4667();
            }
            this.f9990 = null;
            this.f9991 = null;
            TrafficStats.clearThreadStatsTag();
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:14:0x0028 A[Catch: IOException -> 0x0032, TRY_LEAVE, TryCatch #0 {IOException -> 0x0032, blocks: (B:5:0x0004, B:7:0x000d, B:10:0x0017, B:11:0x001d, B:14:0x0028), top: B:19:0x0004 }] */
    @Override // defpackage.InterfaceC1463
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final int read(byte[] r7, int r8, int r9) throws java.io.IOException {
        /*
            r6 = this;
            if (r9 != 0) goto L4
            r6 = 0
            return r6
        L4:
            long r0 = r6.f9992     // Catch: java.io.IOException -> L32
            r2 = -1
            int r2 = (r0 > r2 ? 1 : (r0 == r2 ? 0 : -1))
            r3 = -1
            if (r2 == 0) goto L1d
            long r4 = r6.f9998     // Catch: java.io.IOException -> L32
            long r0 = r0 - r4
            r4 = 0
            int r2 = (r0 > r4 ? 1 : (r0 == r4 ? 0 : -1))
            if (r2 != 0) goto L17
            goto L27
        L17:
            long r4 = (long) r9     // Catch: java.io.IOException -> L32
            long r0 = java.lang.Math.min(r4, r0)     // Catch: java.io.IOException -> L32
            int r9 = (int) r0     // Catch: java.io.IOException -> L32
        L1d:
            java.io.InputStream r0 = r6.f9997     // Catch: java.io.IOException -> L32
            java.lang.String r1 = defpackage.AbstractC3558.f13329     // Catch: java.io.IOException -> L32
            int r7 = r0.read(r7, r8, r9)     // Catch: java.io.IOException -> L32
            if (r7 != r3) goto L28
        L27:
            return r3
        L28:
            long r8 = r6.f9998     // Catch: java.io.IOException -> L32
            long r0 = (long) r7     // Catch: java.io.IOException -> L32
            long r8 = r8 + r0
            r6.f9998 = r8     // Catch: java.io.IOException -> L32
            r6.m4668(r7)     // Catch: java.io.IOException -> L32
            return r7
        L32:
            r6 = move-exception
            java.lang.String r7 = defpackage.AbstractC3558.f13329
            r7 = 2
            androidx.media3.datasource.HttpDataSource$HttpDataSourceException r6 = androidx.media3.datasource.HttpDataSource$HttpDataSourceException.m358(r7, r6)
            throw r6
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C2574.read(byte[], int, int):int");
    }

    /* JADX WARN: Removed duplicated region for block: B:22:0x0075  */
    /* JADX WARN: Removed duplicated region for block: B:45:0x00d2  */
    /* JADX WARN: Removed duplicated region for block: B:58:0x013d  */
    /* JADX WARN: Removed duplicated region for block: B:61:0x0143  */
    /* JADX WARN: Removed duplicated region for block: B:62:0x0146  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x0157 A[Catch: IOException -> 0x0162, TRY_LEAVE, TryCatch #8 {IOException -> 0x0162, blocks: (B:66:0x014f, B:68:0x0157), top: B:130:0x014f }] */
    @Override // defpackage.InterfaceC2569
    /* renamed from: ˏˋٴ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final long mo1165(defpackage.C4179 r28) throws java.security.NoSuchAlgorithmException, java.io.IOException, java.lang.NumberFormatException, java.security.KeyManagementException {
        /*
            Method dump skipped, instructions count: 485
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C2574.mo1165(ᵮʿʽᵘ):long");
    }

    /* renamed from: ᵞʡ, reason: contains not printable characters */
    public final void m6471(long j) throws IOException {
        if (j == 0) {
            return;
        }
        byte[] bArr = new byte[4096];
        while (j > 0) {
            int iMin = (int) Math.min(j, 4096L);
            InputStream inputStream = this.f9997;
            String str = AbstractC3558.f13329;
            int i = inputStream.read(bArr, 0, iMin);
            if (Thread.currentThread().isInterrupted()) {
                throw new HttpDataSource$HttpDataSourceException(2000, 1, new InterruptedIOException());
            }
            if (i == -1) {
                throw new HttpDataSource$HttpDataSourceException(2008);
            }
            j -= i;
            m4668(i);
        }
    }

    @Override // defpackage.AbstractC1628, defpackage.InterfaceC2569
    /* renamed from: ᵨᵳʝ */
    public final Map mo1416() {
        HttpURLConnection httpURLConnection = this.f9990;
        return httpURLConnection == null ? C2172.f8575 : new C4589(httpURLConnection.getHeaderFields());
    }

    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public final void m6472() {
        HttpURLConnection httpURLConnection = this.f9990;
        if (httpURLConnection != null) {
            try {
                httpURLConnection.disconnect();
            } catch (Exception e) {
                ᵳʿˉ.ᵸˑ("Unexpected error while disconnecting", e);
            }
        }
    }

    /* renamed from: ᵸʓᵠ, reason: contains not printable characters */
    public final HttpURLConnection m6473(URL url, int i, byte[] bArr, long j, long j2, boolean z, boolean z2, Map map) throws NoSuchAlgorithmException, IOException, KeyManagementException {
        HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
        if (httpURLConnection instanceof HttpsURLConnection) {
            try {
                TrustManager[] trustManagerArr = {new ᵻʔᵵ(1)};
                SSLContext sSLContext = SSLContext.getInstance("TLS");
                sSLContext.init(null, trustManagerArr, null);
                ((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(sSLContext.getSocketFactory());
            } catch (Exception unused) {
            }
        }
        httpURLConnection.setConnectTimeout(this.f9995);
        httpURLConnection.setReadTimeout(this.f9994);
        HashMap map2 = new HashMap();
        C5553 c5553 = this.f9989;
        if (c5553 != null) {
            map2.putAll(c5553.m11183());
        }
        map2.putAll(this.f9993.m11183());
        map2.putAll(map);
        for (Map.Entry entry : map2.entrySet()) {
            httpURLConnection.setRequestProperty((String) entry.getKey(), (String) entry.getValue());
        }
        String strM1243 = AbstractC0137.m1243(j, j2);
        if (strM1243 != null) {
            httpURLConnection.setRequestProperty("Range", strM1243);
        }
        httpURLConnection.setRequestProperty("Accept-Encoding", z ? "gzip" : "identity");
        httpURLConnection.setInstanceFollowRedirects(z2);
        httpURLConnection.setDoOutput(bArr != null);
        httpURLConnection.setRequestMethod(C4179.m9098(i));
        if (bArr != null) {
            httpURLConnection.setFixedLengthStreamingMode(bArr.length);
            httpURLConnection.connect();
            OutputStream outputStream = httpURLConnection.getOutputStream();
            outputStream.write(bArr);
            outputStream.close();
        } else {
            httpURLConnection.connect();
        }
        return httpURLConnection;
    }

    @Override // defpackage.InterfaceC2569
    /* renamed from: ᵿʗᵝʽ */
    public final Uri mo1166() {
        HttpURLConnection httpURLConnection = this.f9990;
        if (httpURLConnection != null) {
            return Uri.parse(httpURLConnection.getURL().toString());
        }
        C4179 c4179 = this.f9991;
        if (c4179 != null) {
            return c4179.f15620;
        }
        return null;
    }
}
