package p138.p176.p177.p190.p194;

import android.annotation.TargetApi;
import android.net.Uri;
import android.text.TextUtils;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import p138.p176.p177.p190.C3414;
import p138.p176.p177.p190.p194.InterfaceC3537;
import p138.p176.p177.p190.p238.C4097;
import p138.p176.p177.p190.p238.C4098;
import p138.p176.p177.p190.p238.C4104;
import p138.p176.p177.p190.p239.C4150;

/* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ࢬ.ޒ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@TargetApi(18)
public final class C3544 implements InterfaceC3545 {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final HttpDataSource.InterfaceC0316 f10517;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final String f10518;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final boolean f10519 = false;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final Map<String, String> f10520 = new HashMap();

    public C3544(String str, HttpDataSource.InterfaceC0316 interfaceC0316) {
        this.f10517 = interfaceC0316;
        this.f10518 = str;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static byte[] m5847(HttpDataSource.InterfaceC0316 interfaceC0316, String str, byte[] bArr, Map<String, String> map) {
        int i;
        boolean z;
        Map<String, List<String>> map2;
        List<String> list;
        HttpDataSource httpDataSourceMo1286 = interfaceC0316.mo1286();
        if (map != null) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                String key = entry.getKey();
                String value = entry.getValue();
                C4104 c4104 = (C4104) httpDataSourceMo1286;
                if (key == null) {
                    throw null;
                }
                if (value == null) {
                    throw null;
                }
                c4104.f13136.m1288(key, value);
            }
        }
        String str2 = str;
        int i2 = 0;
        while (true) {
            C4097 c4097 = new C4097(httpDataSourceMo1286, new C4098(Uri.parse(str2), 2, bArr, 0L, 0L, -1L, null, 1));
            try {
                try {
                    byte[] bArrM6772 = C4150.m6772((InputStream) c4097);
                    try {
                        c4097.close();
                    } catch (IOException unused) {
                    }
                    return bArrM6772;
                } catch (HttpDataSource.InvalidResponseCodeException e) {
                    if (e.f1975 == 307 || e.f1975 == 308) {
                        i = i2 + 1;
                        if (i2 < 5) {
                            z = true;
                        } else {
                            i2 = i;
                            i = i2;
                            z = false;
                        }
                    } else {
                        i = i2;
                        z = false;
                    }
                    String str3 = (!z || (map2 = e.f1976) == null || (list = map2.get("Location")) == null || list.isEmpty()) ? null : list.get(0);
                    if (str3 == null) {
                        throw e;
                    }
                    try {
                        c4097.close();
                    } catch (IOException unused2) {
                    }
                    String str4 = str3;
                    i2 = i;
                    str2 = str4;
                }
            } catch (Throwable th) {
                C4150.m6764((Closeable) c4097);
                throw th;
            }
        }
    }

    @Override // p138.p176.p177.p190.p194.InterfaceC3545
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public byte[] mo5848(UUID uuid, InterfaceC3537.C3538 c3538) {
        String str = c3538.f10506;
        if (this.f10519 || TextUtils.isEmpty(str)) {
            str = this.f10518;
        }
        HashMap map = new HashMap();
        map.put("Content-Type", C3414.f9976.equals(uuid) ? "text/xml" : C3414.f9974.equals(uuid) ? "application/json" : "application/octet-stream");
        if (C3414.f9976.equals(uuid)) {
            map.put("SOAPAction", "http://schemas.microsoft.com/DRM/2007/03/protocols/AcquireLicense");
        }
        synchronized (this.f10520) {
            map.putAll(this.f10520);
        }
        return m5847(this.f10517, str, c3538.f10505, map);
    }

    @Override // p138.p176.p177.p190.p194.InterfaceC3545
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public byte[] mo5849(UUID uuid, InterfaceC3537.C3541 c3541) {
        return m5847(this.f10517, c3541.f10508 + "&signedRequest=" + C4150.m6760(c3541.f10507), null, null);
    }
}
