package com.applovin.impl; import android.media.ResourceBusyException; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.SystemClock; import androidx.work.PeriodicWorkRequest; import com.applovin.impl.a7; import com.applovin.impl.b7; import com.applovin.impl.x5; import com.applovin.impl.y5; import com.applovin.impl.y6; import com.applovin.impl.z6; import com.applovin.impl.z7; import com.facebook.ads.AdError; import com.mbridge.msdk.playercommon.exoplayer2.C; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.UUID; /* loaded from: classes.dex */ public class y5 implements b7 { private final UUID c; private final z7.c d; private final qd e; private final HashMap f; private final boolean g; private final int[] h; private final boolean i; private final g j; private final mc k; private final h l; private final long m; private final List n; private final Set o; private final Set p; private int q; private z7 r; private x5 s; private x5 t; private Looper u; private Handler v; private int w; private byte[] x; volatile d y; public static final class e extends Exception { private e(UUID uuid) { super("Media does not support uuid: " + uuid); } } public static final class b { private boolean d; private boolean f; private final HashMap a = new HashMap(); private UUID b = t2.d; private z7.c c = m9.d; private mc g = new g6(); private int[] e = new int[0]; private long h = PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS; public b a(boolean z) { this.d = z; return this; } public b b(boolean z) { this.f = z; return this; } public b a(int... iArr) { for (int i : iArr) { boolean z = true; if (i != 2 && i != 1) { z = false; } b1.a(z); } this.e = (int[]) iArr.clone(); return this; } public b a(UUID uuid, z7.c cVar) { this.b = (UUID) b1.a(uuid); this.c = (z7.c) b1.a(cVar); return this; } public y5 a(qd qdVar) { return new y5(this.b, this.c, qdVar, this.a, this.d, this.e, this.f, this.g, this.h); } } private y5(UUID uuid, z7.c cVar, qd qdVar, HashMap hashMap, boolean z, int[] iArr, boolean z2, mc mcVar, long j) { b1.a(uuid); b1.a(!t2.b.equals(uuid), "Use C.CLEARKEY_UUID instead"); this.c = uuid; this.d = cVar; this.e = qdVar; this.f = hashMap; this.g = z; this.h = iArr; this.i = z2; this.k = mcVar; this.j = new g(); this.l = new h(); this.w = 0; this.n = new ArrayList(); this.o = rj.b(); this.p = rj.b(); this.m = j; } @Override // com.applovin.impl.b7 public z6 a(Looper looper, a7.a aVar, f9 f9Var) { b1.b(this.q > 0); a(looper); return a(looper, aVar, f9Var, true); } private void d() { pp it = ib.a((Collection) this.p).iterator(); while (it.hasNext()) { ((z6) it.next()).a((a7.a) null); } } private void b(Looper looper) { if (this.y == null) { this.y = new d(looper); } } private void e() { pp it = ib.a((Collection) this.o).iterator(); while (it.hasNext()) { ((f) it.next()).a(); } } public class d extends Handler { public d(Looper looper) { super(looper); } @Override // android.os.Handler public void handleMessage(Message message) { byte[] bArr = (byte[]) message.obj; if (bArr == null) { return; } for (x5 x5Var : y5.this.n) { if (x5Var.a(bArr)) { x5Var.a(message.what); return; } } } } public class g implements x5.a { private final Set a = new HashSet(); private x5 b; public g() { } @Override // com.applovin.impl.x5.a public void a() { this.b = null; eb a = eb.a((Collection) this.a); this.a.clear(); pp it = a.iterator(); while (it.hasNext()) { ((x5) it.next()).i(); } } public void b(x5 x5Var) { this.a.remove(x5Var); if (this.b == x5Var) { this.b = null; if (this.a.isEmpty()) { return; } x5 x5Var2 = (x5) this.a.iterator().next(); this.b = x5Var2; x5Var2.k(); } } @Override // com.applovin.impl.x5.a public void a(Exception exc, boolean z) { this.b = null; eb a = eb.a((Collection) this.a); this.a.clear(); pp it = a.iterator(); while (it.hasNext()) { ((x5) it.next()).b(exc, z); } } @Override // com.applovin.impl.x5.a public void a(x5 x5Var) { this.a.add(x5Var); if (this.b != null) { return; } this.b = x5Var; x5Var.k(); } } /* JADX INFO: Access modifiers changed from: private */ public void c() { if (this.r != null && this.q == 0 && this.n.isEmpty() && this.o.isEmpty()) { ((z7) b1.a(this.r)).a(); this.r = null; } } public class h implements x5.b { private h() { } @Override // com.applovin.impl.x5.b public void b(final x5 x5Var, int i) { if (i == 1 && y5.this.q > 0 && y5.this.m != C.TIME_UNSET) { y5.this.p.add(x5Var); ((Handler) b1.a(y5.this.v)).postAtTime(new Runnable() { // from class: com.applovin.impl.y5$h$$ExternalSyntheticLambda0 @Override // java.lang.Runnable public final void run() { x5.this.a((a7.a) null); } }, x5Var, SystemClock.uptimeMillis() + y5.this.m); } else if (i == 0) { y5.this.n.remove(x5Var); if (y5.this.s == x5Var) { y5.this.s = null; } if (y5.this.t == x5Var) { y5.this.t = null; } y5.this.j.b(x5Var); if (y5.this.m != C.TIME_UNSET) { ((Handler) b1.a(y5.this.v)).removeCallbacksAndMessages(x5Var); y5.this.p.remove(x5Var); } } y5.this.c(); } @Override // com.applovin.impl.x5.b public void a(x5 x5Var, int i) { if (y5.this.m != C.TIME_UNSET) { y5.this.p.remove(x5Var); ((Handler) b1.a(y5.this.v)).removeCallbacksAndMessages(x5Var); } } } public class c implements z7.b { private c() { } @Override // com.applovin.impl.z7.b public void a(z7 z7Var, byte[] bArr, int i, int i2, byte[] bArr2) { ((d) b1.a(y5.this.y)).obtainMessage(i, bArr).sendToTarget(); } } public class f implements b7.b { private final a7.a b; private z6 c; private boolean d; public f(a7.a aVar) { this.b = aVar; } public void a(final f9 f9Var) { ((Handler) b1.a(y5.this.v)).post(new Runnable() { // from class: com.applovin.impl.y5$f$$ExternalSyntheticLambda1 @Override // java.lang.Runnable public final void run() { y5.f.this.b(f9Var); } }); } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void b(f9 f9Var) { if (y5.this.q == 0 || this.d) { return; } y5 y5Var = y5.this; this.c = y5Var.a((Looper) b1.a(y5Var.u), this.b, f9Var, false); y5.this.o.add(this); } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void c() { if (this.d) { return; } z6 z6Var = this.c; if (z6Var != null) { z6Var.a(this.b); } y5.this.o.remove(this); this.d = true; } @Override // com.applovin.impl.b7.b public void a() { xp.a((Handler) b1.a(y5.this.v), new Runnable() { // from class: com.applovin.impl.y5$f$$ExternalSyntheticLambda0 @Override // java.lang.Runnable public final void run() { y5.f.this.c(); } }); } } /* JADX INFO: Access modifiers changed from: private */ /* JADX WARN: Multi-variable type inference failed */ public z6 a(Looper looper, a7.a aVar, f9 f9Var, boolean z) { List list; b(looper); y6 y6Var = f9Var.p; if (y6Var == null) { return a(Cif.e(f9Var.m), z); } x5 x5Var = null; Object[] objArr = 0; if (this.x == null) { list = a((y6) b1.a(y6Var), this.c, false); if (list.isEmpty()) { e eVar = new e(this.c); pc.a("DefaultDrmSessionMgr", "DRM error", eVar); if (aVar != null) { aVar.a(eVar); } return new u7(new z6.a(eVar, AdError.AD_ASSETS_UNSUPPORTED_TYPE_ERROR_CODE)); } } else { list = null; } if (this.g) { Iterator it = this.n.iterator(); while (true) { if (!it.hasNext()) { break; } x5 x5Var2 = (x5) it.next(); if (xp.a(x5Var2.a, list)) { x5Var = x5Var2; break; } } } else { x5Var = this.t; } if (x5Var == null) { x5Var = a(list, false, aVar, z); if (!this.g) { this.t = x5Var; } this.n.add(x5Var); } else { x5Var.b(aVar); } return x5Var; } @Override // com.applovin.impl.b7 public b7.b b(Looper looper, a7.a aVar, f9 f9Var) { b1.b(this.q > 0); a(looper); f fVar = new f(aVar); fVar.a(f9Var); return fVar; } @Override // com.applovin.impl.b7 public final void b() { int i = this.q; this.q = i + 1; if (i != 0) { return; } if (this.r == null) { z7 a2 = this.d.a(this.c); this.r = a2; a2.a(new c()); } else if (this.m != C.TIME_UNSET) { for (int i2 = 0; i2 < this.n.size(); i2++) { ((x5) this.n.get(i2)).b(null); } } } private static boolean a(z6 z6Var) { return z6Var.b() == 1 && (xp.a < 19 || (((z6.a) b1.a(z6Var.getError())).getCause() instanceof ResourceBusyException)); } private boolean a(y6 y6Var) { if (this.x != null) { return true; } if (a(y6Var, this.c, true).isEmpty()) { if (y6Var.d != 1 || !y6Var.a(0).a(t2.b)) { return false; } pc.d("DefaultDrmSessionMgr", "DrmInitData only contains common PSSH SchemeData. Assuming support for: " + this.c); } String str = y6Var.c; if (str == null || C.CENC_TYPE_cenc.equals(str)) { return true; } return C.CENC_TYPE_cbcs.equals(str) ? xp.a >= 25 : (C.CENC_TYPE_cbc1.equals(str) || C.CENC_TYPE_cens.equals(str)) ? false : true; } private x5 a(List list, boolean z, a7.a aVar) { b1.a(this.r); x5 x5Var = new x5(this.c, this.r, this.j, this.l, list, this.w, this.i | z, z, this.x, this.f, this.e, (Looper) b1.a(this.u), this.k); x5Var.b(aVar); if (this.m != C.TIME_UNSET) { x5Var.b(null); } return x5Var; } private x5 a(List list, boolean z, a7.a aVar, boolean z2) { x5 a2 = a(list, z, aVar); if (a(a2) && !this.p.isEmpty()) { d(); a(a2, aVar); a2 = a(list, z, aVar); } if (!a(a2) || !z2 || this.o.isEmpty()) { return a2; } e(); if (!this.p.isEmpty()) { d(); } a(a2, aVar); return a(list, z, aVar); } @Override // com.applovin.impl.b7 public int a(f9 f9Var) { int c2 = ((z7) b1.a(this.r)).c(); y6 y6Var = f9Var.p; if (y6Var == null) { if (xp.a(this.h, Cif.e(f9Var.m)) != -1) { return c2; } return 0; } if (a(y6Var)) { return c2; } return 1; } private synchronized void a(Looper looper) { try { Looper looper2 = this.u; if (looper2 == null) { this.u = looper; this.v = new Handler(looper); } else { b1.b(looper2 == looper); b1.a(this.v); } } catch (Throwable th) { throw th; } } private z6 a(int i, boolean z) { z7 z7Var = (z7) b1.a(this.r); if ((z7Var.c() == 2 && l9.d) || xp.a(this.h, i) == -1 || z7Var.c() == 1) { return null; } x5 x5Var = this.s; if (x5Var == null) { x5 a2 = a((List) eb.h(), true, (a7.a) null, z); this.n.add(a2); this.s = a2; } else { x5Var.b(null); } return this.s; } @Override // com.applovin.impl.b7 public final void a() { int i = this.q - 1; this.q = i; if (i != 0) { return; } if (this.m != C.TIME_UNSET) { ArrayList arrayList = new ArrayList(this.n); for (int i2 = 0; i2 < arrayList.size(); i2++) { ((x5) arrayList.get(i2)).a((a7.a) null); } } e(); c(); } public void a(int i, byte[] bArr) { b1.b(this.n.isEmpty()); if (i == 1 || i == 3) { b1.a(bArr); } this.w = i; this.x = bArr; } private void a(z6 z6Var, a7.a aVar) { z6Var.a(aVar); if (this.m != C.TIME_UNSET) { z6Var.a((a7.a) null); } } private static List a(y6 y6Var, UUID uuid, boolean z) { ArrayList arrayList = new ArrayList(y6Var.d); for (int i = 0; i < y6Var.d; i++) { y6.b a2 = y6Var.a(i); if ((a2.a(uuid) || (t2.c.equals(uuid) && a2.a(t2.b))) && (a2.f != null || z)) { arrayList.add(a2); } } return arrayList; } }