package com.applovin.impl; import android.net.Uri; import android.text.TextUtils; import com.applovin.impl.l5; import com.applovin.impl.qa; import com.applovin.impl.z7; import java.io.Closeable; import java.io.InputStream; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; /* loaded from: classes.dex */ public final class ra implements qd { private final qa.b a; private final String b; private final boolean c; private final Map d; public ra(String str, boolean z, qa.b bVar) { b1.a((z && TextUtils.isEmpty(str)) ? false : true); this.a = bVar; this.b = str; this.c = z; this.d = new HashMap(); } @Override // com.applovin.impl.qd public byte[] a(UUID uuid, z7.a aVar) { String str; String b = aVar.b(); if (this.c || TextUtils.isEmpty(b)) { b = this.b; } if (!TextUtils.isEmpty(b)) { HashMap hashMap = new HashMap(); UUID uuid2 = t2.e; if (uuid2.equals(uuid)) { str = "text/xml"; } else { str = t2.c.equals(uuid) ? com.ironsource.nb.L : "application/octet-stream"; } hashMap.put("Content-Type", str); if (uuid2.equals(uuid)) { hashMap.put("SOAPAction", "http://schemas.microsoft.com/DRM/2007/03/protocols/AcquireLicense"); } synchronized (this.d) { hashMap.putAll(this.d); } return a(this.a, b, aVar.a(), hashMap); } l5.b bVar = new l5.b(); Uri uri = Uri.EMPTY; throw new rd(bVar.a(uri).a(), uri, gb.h(), 0L, new IllegalStateException("No license URL")); } @Override // com.applovin.impl.qd public byte[] a(UUID uuid, z7.d dVar) { return a(this.a, dVar.b() + "&signedRequest=" + xp.a(dVar.a()), null, Collections.emptyMap()); } private static String a(qa.e eVar, int i) { Map map; List list; int i2 = eVar.d; if ((i2 != 307 && i2 != 308) || i >= 5 || (map = eVar.g) == null || (list = (List) map.get("Location")) == null || list.isEmpty()) { return null; } return (String) list.get(0); } public void a(String str, String str2) { b1.a((Object) str); b1.a((Object) str2); synchronized (this.d) { this.d.put(str, str2); } } private static byte[] a(qa.b bVar, String str, byte[] bArr, Map map) { fl flVar = new fl(bVar.a()); l5 a = new l5.b().b(str).a(map).b(2).a(bArr).a(1).a(); int i = 0; l5 l5Var = a; while (true) { try { k5 k5Var = new k5(flVar, l5Var); try { try { return xp.a((InputStream) k5Var); } catch (qa.e e) { String a2 = a(e, i); if (a2 != null) { i++; l5Var = l5Var.a().b(a2).a(); } else { throw e; } } } finally { xp.a((Closeable) k5Var); } } catch (Exception e2) { throw new rd(a, (Uri) b1.a(flVar.h()), flVar.e(), flVar.g(), e2); } } } }