discord-jadx/app/src/main/java/com/google/android/exoplayer2/drm/DefaultDrmSession.java
2021-07-13 22:23:20 +02:00

624 lines
22 KiB
Java

package com.google.android.exoplayer2.drm;
import android.annotation.SuppressLint;
import android.media.NotProvisionedException;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.util.Log;
import android.util.Pair;
import androidx.annotation.GuardedBy;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import c.i.a.c.d2.r;
import c.i.a.c.h0;
import c.i.a.c.h2.u;
import c.i.a.c.i2.f0;
import c.i.a.c.i2.k;
import c.i.a.c.i2.l;
import c.i.a.c.i2.p;
import c.i.a.c.z1.a0;
import c.i.a.c.z1.b0;
import c.i.a.c.z1.n;
import c.i.a.c.z1.o;
import c.i.a.c.z1.q;
import c.i.a.c.z1.w;
import c.i.a.c.z1.x;
import com.airbnb.lottie.parser.AnimatableValueParser;
import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.drm.DefaultDrmSessionManager;
import com.google.android.exoplayer2.drm.DrmInitData;
import com.google.android.exoplayer2.drm.DrmSession;
import com.google.android.exoplayer2.upstream.HttpDataSource$CleartextNotPermittedException;
import com.google.android.exoplayer2.upstream.Loader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
@RequiresApi(18)
public class DefaultDrmSession implements DrmSession {
@Nullable
public final List<DrmInitData.SchemeData> a;
public final x b;
/* renamed from: c reason: collision with root package name */
public final a f2224c;
public final b d;
public final int e;
public final boolean f;
public final boolean g;
public final HashMap<String, String> h;
public final l<q.a> i;
public final u j;
public final b0 k;
public final UUID l;
public final e m;
public int n;
public int o;
@Nullable
public HandlerThread p;
@Nullable
public c q;
@Nullable
public w r;
@Nullable
/* renamed from: s reason: collision with root package name */
public DrmSession.DrmSessionException f2225s;
@Nullable
public byte[] t;
public byte[] u;
@Nullable
public x.a v;
@Nullable
public x.d w;
public static final class UnexpectedDrmSessionException extends IOException {
public UnexpectedDrmSessionException(@Nullable Throwable th) {
super(th);
}
}
public interface a {
}
public interface b {
}
@SuppressLint({"HandlerLeak"})
public class c extends Handler {
@GuardedBy("this")
public boolean a;
public c(Looper looper) {
super(looper);
}
public void a(int i, Object obj, boolean z2) {
obtainMessage(i, new d(r.a.getAndIncrement(), z2, SystemClock.elapsedRealtime(), obj)).sendToTarget();
}
/* JADX WARNING: Removed duplicated region for block: B:43:0x00c2 A[RETURN] */
/* JADX WARNING: Removed duplicated region for block: B:44:0x00c3 */
@Override // android.os.Handler
public void handleMessage(Message message) {
byte[] bArr;
d dVar = (d) message.obj;
boolean z2 = true;
try {
int i = message.what;
if (i == 0) {
DefaultDrmSession defaultDrmSession = DefaultDrmSession.this;
bArr = ((a0) defaultDrmSession.k).c(defaultDrmSession.l, (x.d) dVar.d);
} else if (i == 1) {
DefaultDrmSession defaultDrmSession2 = DefaultDrmSession.this;
bArr = ((a0) defaultDrmSession2.k).a(defaultDrmSession2.l, (x.a) dVar.d);
} else {
throw new RuntimeException();
}
} catch (MediaDrmCallbackException e) {
d dVar2 = (d) message.obj;
if (dVar2.b) {
int i2 = dVar2.e + 1;
dVar2.e = i2;
if (i2 <= ((c.i.a.c.h2.r) DefaultDrmSession.this.j).a(3)) {
SystemClock.elapsedRealtime();
SystemClock.elapsedRealtime();
Object unexpectedDrmSessionException = e.getCause() instanceof IOException ? (IOException) e.getCause() : new UnexpectedDrmSessionException(e.getCause());
c.i.a.c.h2.r rVar = (c.i.a.c.h2.r) DefaultDrmSession.this.j;
long min = ((unexpectedDrmSessionException instanceof ParserException) || (unexpectedDrmSessionException instanceof FileNotFoundException) || (unexpectedDrmSessionException instanceof HttpDataSource$CleartextNotPermittedException) || (unexpectedDrmSessionException instanceof Loader.UnexpectedLoaderException)) ? -9223372036854775807L : (long) Math.min((dVar2.e - 1) * 1000, 5000);
if (min != -9223372036854775807L) {
synchronized (this) {
if (!this.a) {
sendMessageDelayed(Message.obtain(message), min);
if (z2) {
bArr = e;
} else {
return;
}
}
}
}
}
}
z2 = false;
if (z2) {
}
} catch (Exception e2) {
p.c("DefaultDrmSession", "Key/provisioning request produced an unexpected exception. Not retrying.", e2);
bArr = e2;
}
u uVar = DefaultDrmSession.this.j;
long j = dVar.a;
Objects.requireNonNull(uVar);
synchronized (this) {
if (!this.a) {
DefaultDrmSession.this.m.obtainMessage(message.what, Pair.create(dVar.d, bArr)).sendToTarget();
}
}
}
}
public static final class d {
public final long a;
public final boolean b;
/* renamed from: c reason: collision with root package name */
public final long f2226c;
public final Object d;
public int e;
public d(long j, boolean z2, long j2, Object obj) {
this.a = j;
this.b = z2;
this.f2226c = j2;
this.d = obj;
}
}
@SuppressLint({"HandlerLeak"})
public class e extends Handler {
public e(Looper looper) {
super(looper);
}
@Override // android.os.Handler
public void handleMessage(Message message) {
Pair pair = (Pair) message.obj;
Object obj = pair.first;
Object obj2 = pair.second;
int i = message.what;
if (i == 0) {
DefaultDrmSession defaultDrmSession = DefaultDrmSession.this;
if (obj != defaultDrmSession.w) {
return;
}
if (defaultDrmSession.n == 2 || defaultDrmSession.i()) {
defaultDrmSession.w = null;
if (obj2 instanceof Exception) {
((DefaultDrmSessionManager.d) defaultDrmSession.f2224c).a((Exception) obj2);
return;
}
try {
defaultDrmSession.b.j((byte[]) obj2);
DefaultDrmSessionManager.d dVar = (DefaultDrmSessionManager.d) defaultDrmSession.f2224c;
for (DefaultDrmSession defaultDrmSession2 : DefaultDrmSessionManager.this.n) {
if (defaultDrmSession2.l(false)) {
defaultDrmSession2.h(true);
}
}
DefaultDrmSessionManager.this.n.clear();
} catch (Exception e) {
((DefaultDrmSessionManager.d) defaultDrmSession.f2224c).a(e);
}
}
} else if (i == 1) {
DefaultDrmSession defaultDrmSession3 = DefaultDrmSession.this;
if (obj == defaultDrmSession3.v && defaultDrmSession3.i()) {
defaultDrmSession3.v = null;
if (obj2 instanceof Exception) {
defaultDrmSession3.k((Exception) obj2);
return;
}
try {
byte[] bArr = (byte[]) obj2;
if (defaultDrmSession3.e == 3) {
x xVar = defaultDrmSession3.b;
byte[] bArr2 = defaultDrmSession3.u;
int i2 = f0.a;
xVar.i(bArr2, bArr);
defaultDrmSession3.g(c.i.a.c.z1.b.a);
return;
}
byte[] i3 = defaultDrmSession3.b.i(defaultDrmSession3.t, bArr);
int i4 = defaultDrmSession3.e;
if (!((i4 != 2 && (i4 != 0 || defaultDrmSession3.u == null)) || i3 == null || i3.length == 0)) {
defaultDrmSession3.u = i3;
}
defaultDrmSession3.n = 4;
defaultDrmSession3.g(n.a);
} catch (Exception e2) {
defaultDrmSession3.k(e2);
}
}
}
}
}
public DefaultDrmSession(UUID uuid, x xVar, a aVar, b bVar, @Nullable List<DrmInitData.SchemeData> list, int i, boolean z2, boolean z3, @Nullable byte[] bArr, HashMap<String, String> hashMap, b0 b0Var, Looper looper, u uVar) {
if (i == 1 || i == 3) {
Objects.requireNonNull(bArr);
}
this.l = uuid;
this.f2224c = aVar;
this.d = bVar;
this.b = xVar;
this.e = i;
this.f = z2;
this.g = z3;
if (bArr != null) {
this.u = bArr;
this.a = null;
} else {
Objects.requireNonNull(list);
this.a = Collections.unmodifiableList(list);
}
this.h = hashMap;
this.k = b0Var;
this.i = new l<>();
this.j = uVar;
this.n = 2;
this.m = new e(looper);
}
@Override // com.google.android.exoplayer2.drm.DrmSession
public void a(@Nullable q.a aVar) {
boolean z2 = false;
AnimatableValueParser.D(this.o >= 0);
if (aVar != null) {
l<q.a> lVar = this.i;
synchronized (lVar.i) {
ArrayList arrayList = new ArrayList(lVar.l);
arrayList.add(aVar);
lVar.l = Collections.unmodifiableList(arrayList);
Integer num = lVar.j.get(aVar);
if (num == null) {
HashSet hashSet = new HashSet(lVar.k);
hashSet.add(aVar);
lVar.k = Collections.unmodifiableSet(hashSet);
}
lVar.j.put(aVar, Integer.valueOf(num != null ? num.intValue() + 1 : 1));
}
}
int i = this.o + 1;
this.o = i;
if (i == 1) {
if (this.n == 2) {
z2 = true;
}
AnimatableValueParser.D(z2);
HandlerThread handlerThread = new HandlerThread("ExoPlayer:DrmRequestHandler");
this.p = handlerThread;
handlerThread.start();
this.q = new c(this.p.getLooper());
if (l(true)) {
h(true);
}
} else if (aVar != null && i()) {
aVar.d();
}
DefaultDrmSessionManager.e eVar = (DefaultDrmSessionManager.e) this.d;
DefaultDrmSessionManager defaultDrmSessionManager = DefaultDrmSessionManager.this;
if (defaultDrmSessionManager.l != -9223372036854775807L) {
defaultDrmSessionManager.o.remove(this);
Handler handler = DefaultDrmSessionManager.this.u;
Objects.requireNonNull(handler);
handler.removeCallbacksAndMessages(this);
}
}
@Override // com.google.android.exoplayer2.drm.DrmSession
public void b(@Nullable q.a aVar) {
AnimatableValueParser.D(this.o > 0);
int i = this.o - 1;
this.o = i;
if (i == 0) {
this.n = 0;
e eVar = this.m;
int i2 = f0.a;
eVar.removeCallbacksAndMessages(null);
c cVar = this.q;
synchronized (cVar) {
cVar.removeCallbacksAndMessages(null);
cVar.a = true;
}
this.q = null;
this.p.quit();
this.p = null;
this.r = null;
this.f2225s = null;
this.v = null;
this.w = null;
byte[] bArr = this.t;
if (bArr != null) {
this.b.g(bArr);
this.t = null;
}
g(c.i.a.c.z1.a.a);
}
if (aVar != null) {
if (i()) {
aVar.f();
}
l<q.a> lVar = this.i;
synchronized (lVar.i) {
Integer num = lVar.j.get(aVar);
if (num != null) {
ArrayList arrayList = new ArrayList(lVar.l);
arrayList.remove(aVar);
lVar.l = Collections.unmodifiableList(arrayList);
if (num.intValue() == 1) {
lVar.j.remove(aVar);
HashSet hashSet = new HashSet(lVar.k);
hashSet.remove(aVar);
lVar.k = Collections.unmodifiableSet(hashSet);
} else {
lVar.j.put(aVar, Integer.valueOf(num.intValue() - 1));
}
}
}
}
b bVar = this.d;
int i3 = this.o;
DefaultDrmSessionManager.e eVar2 = (DefaultDrmSessionManager.e) bVar;
Objects.requireNonNull(eVar2);
if (i3 == 1) {
DefaultDrmSessionManager defaultDrmSessionManager = DefaultDrmSessionManager.this;
if (defaultDrmSessionManager.l != -9223372036854775807L) {
defaultDrmSessionManager.o.add(this);
Handler handler = DefaultDrmSessionManager.this.u;
Objects.requireNonNull(handler);
handler.postAtTime(new c.i.a.c.z1.d(this), this, SystemClock.uptimeMillis() + DefaultDrmSessionManager.this.l);
return;
}
}
if (i3 == 0) {
DefaultDrmSessionManager.this.m.remove(this);
DefaultDrmSessionManager defaultDrmSessionManager2 = DefaultDrmSessionManager.this;
if (defaultDrmSessionManager2.r == this) {
defaultDrmSessionManager2.r = null;
}
if (defaultDrmSessionManager2.f2228s == this) {
defaultDrmSessionManager2.f2228s = null;
}
if (defaultDrmSessionManager2.n.size() > 1 && DefaultDrmSessionManager.this.n.get(0) == this) {
DefaultDrmSessionManager.this.n.get(1).n();
}
DefaultDrmSessionManager.this.n.remove(this);
DefaultDrmSessionManager defaultDrmSessionManager3 = DefaultDrmSessionManager.this;
if (defaultDrmSessionManager3.l != -9223372036854775807L) {
Handler handler2 = defaultDrmSessionManager3.u;
Objects.requireNonNull(handler2);
handler2.removeCallbacksAndMessages(this);
DefaultDrmSessionManager.this.o.remove(this);
}
}
}
@Override // com.google.android.exoplayer2.drm.DrmSession
public final UUID c() {
return this.l;
}
@Override // com.google.android.exoplayer2.drm.DrmSession
public boolean d() {
return this.f;
}
@Override // com.google.android.exoplayer2.drm.DrmSession
@Nullable
public final w e() {
return this.r;
}
@Override // com.google.android.exoplayer2.drm.DrmSession
@Nullable
public final DrmSession.DrmSessionException f() {
if (this.n == 1) {
return this.f2225s;
}
return null;
}
public final void g(k<q.a> kVar) {
Set<q.a> set;
l<q.a> lVar = this.i;
synchronized (lVar.i) {
set = lVar.k;
}
for (q.a aVar : set) {
kVar.accept(aVar);
}
}
@Override // com.google.android.exoplayer2.drm.DrmSession
public final int getState() {
return this.n;
}
/* JADX WARNING: Removed duplicated region for block: B:41:0x008f A[Catch:{ NumberFormatException -> 0x0093 }] */
@RequiresNonNull({"sessionId"})
public final void h(boolean z2) {
long j;
Pair pair;
long j2;
String str;
if (!this.g) {
byte[] bArr = this.t;
int i = f0.a;
int i2 = this.e;
if (i2 == 0 || i2 == 1) {
if (this.u == null) {
m(bArr, 1, z2);
} else if (this.n == 4 || p()) {
if (!h0.d.equals(this.l)) {
j = Long.MAX_VALUE;
} else {
Map<String, String> o = o();
if (o == null) {
pair = null;
} else {
long j3 = -9223372036854775807L;
try {
String str2 = o.get("LicenseDurationRemaining");
if (str2 != null) {
j2 = Long.parseLong(str2);
Long valueOf = Long.valueOf(j2);
str = o.get("PlaybackDurationRemaining");
if (str != null) {
j3 = Long.parseLong(str);
}
pair = new Pair(valueOf, Long.valueOf(j3));
}
} catch (NumberFormatException unused) {
}
j2 = -9223372036854775807L;
Long valueOf = Long.valueOf(j2);
try {
str = o.get("PlaybackDurationRemaining");
if (str != null) {
}
} catch (NumberFormatException unused2) {
}
pair = new Pair(valueOf, Long.valueOf(j3));
}
Objects.requireNonNull(pair);
j = Math.min(((Long) pair.first).longValue(), ((Long) pair.second).longValue());
}
if (this.e == 0 && j <= 60) {
Log.d("DefaultDrmSession", "Offline license has expired or will expire soon. Remaining seconds: " + j);
m(bArr, 2, z2);
} else if (j <= 0) {
j(new KeysExpiredException());
} else {
this.n = 4;
g(o.a);
}
}
} else if (i2 != 2) {
if (i2 == 3) {
Objects.requireNonNull(this.u);
Objects.requireNonNull(this.t);
if (p()) {
m(this.u, 3, z2);
}
}
} else if (this.u == null || p()) {
m(bArr, 2, z2);
}
}
}
@EnsuresNonNullIf(expression = {"sessionId"}, result = true)
public final boolean i() {
int i = this.n;
return i == 3 || i == 4;
}
public final void j(Exception exc) {
this.f2225s = new DrmSession.DrmSessionException(exc);
g(new c.i.a.c.z1.c(exc));
if (this.n != 4) {
this.n = 1;
}
}
public final void k(Exception exc) {
if (exc instanceof NotProvisionedException) {
((DefaultDrmSessionManager.d) this.f2224c).b(this);
} else {
j(exc);
}
}
@EnsuresNonNullIf(expression = {"sessionId"}, result = true)
public final boolean l(boolean z2) {
if (i()) {
return true;
}
try {
byte[] e2 = this.b.e();
this.t = e2;
this.r = this.b.c(e2);
g(c.i.a.c.z1.k.a);
this.n = 3;
Objects.requireNonNull(this.t);
return true;
} catch (NotProvisionedException e3) {
if (z2) {
((DefaultDrmSessionManager.d) this.f2224c).b(this);
return false;
}
j(e3);
return false;
} catch (Exception e4) {
j(e4);
return false;
}
}
public final void m(byte[] bArr, int i, boolean z2) {
try {
x.a k = this.b.k(bArr, this.a, i, this.h);
this.v = k;
c cVar = this.q;
int i2 = f0.a;
Objects.requireNonNull(k);
cVar.a(1, k, z2);
} catch (Exception e2) {
k(e2);
}
}
public void n() {
x.d d2 = this.b.d();
this.w = d2;
c cVar = this.q;
int i = f0.a;
Objects.requireNonNull(d2);
cVar.a(0, d2, true);
}
@Nullable
public Map<String, String> o() {
byte[] bArr = this.t;
if (bArr == null) {
return null;
}
return this.b.b(bArr);
}
@RequiresNonNull({"sessionId", "offlineLicenseKeySetId"})
public final boolean p() {
try {
this.b.f(this.t, this.u);
return true;
} catch (Exception e2) {
p.b("DefaultDrmSession", "Error trying to restore keys.", e2);
j(e2);
return false;
}
}
}