package w5; import android.net.Uri; import android.text.TextUtils; import com.google.common.collect.r; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import p7.a0; import p7.j; import p7.l; import p7.l0; import p7.n; import q7.a; import q7.n0; import s5.i; import w5.b0; public final class g0 implements i0 { /* renamed from: a reason: collision with root package name */ private final j.a f28115a; /* renamed from: b reason: collision with root package name */ private final String f28116b; /* renamed from: c reason: collision with root package name */ private final boolean f28117c; /* renamed from: d reason: collision with root package name */ private final Map<String, String> f28118d; public g0(String str, boolean z10, j.a aVar) { a.a(!z10 || !TextUtils.isEmpty(str)); this.f28115a = aVar; this.f28116b = str; this.f28117c = z10; this.f28118d = new HashMap(); } private static byte[] c(j.a aVar, String str, byte[] bArr, Map<String, String> map) throws j0 { l0 l0Var = new l0(aVar.a()); n a10 = new n.b().j(str).e(map).d(2).c(bArr).b(1).a(); int i10 = 0; n nVar = a10; while (true) { try { l lVar = new l(l0Var, nVar); try { return n0.U0(lVar); } catch (a0 e10) { String d10 = d(e10, i10); if (d10 != null) { i10++; nVar = nVar.a().j(d10).a(); } else { throw e10; } } finally { n0.n(lVar); } } catch (Exception e11) { throw new j0(a10, (Uri) a.e(l0Var.r()), l0Var.k(), l0Var.q(), e11); } } } private static String d(a0 a0Var, int i10) { Map<String, List<String>> map; List<String> list; int i11 = a0Var.f22701d; if (((i11 == 307 || i11 == 308) && i10 < 5) && (map = a0Var.f22703f) != null && (list = map.get("Location")) != null && !list.isEmpty()) { return list.get(0); } return null; } @Override // w5.i0 public byte[] a(UUID uuid, b0.a aVar) throws j0 { String b10 = aVar.b(); if (this.f28117c || TextUtils.isEmpty(b10)) { b10 = this.f28116b; } if (!TextUtils.isEmpty(b10)) { HashMap hashMap = new HashMap(); UUID uuid2 = i.f24361e; hashMap.put("Content-Type", uuid2.equals(uuid) ? "text/xml" : i.f24359c.equals(uuid) ? "application/json" : "application/octet-stream"); if (uuid2.equals(uuid)) { hashMap.put("SOAPAction", "http://schemas.microsoft.com/DRM/2007/03/protocols/AcquireLicense"); } synchronized (this.f28118d) { hashMap.putAll(this.f28118d); } return c(this.f28115a, b10, aVar.a(), hashMap); } throw new j0(new n.b().i(Uri.EMPTY).a(), Uri.EMPTY, r.j(), 0, new IllegalStateException("No license URL")); } @Override // w5.i0 public byte[] b(UUID uuid, b0.d dVar) throws j0 { return c(this.f28115a, dVar.b() + "&signedRequest=" + n0.D(dVar.a()), null, Collections.emptyMap()); } public void e(String str, String str2) { a.e(str); a.e(str2); synchronized (this.f28118d) { this.f28118d.put(str, str2); } } }