package s1; import android.os.Build; import android.util.Log; import com.bumptech.glide.i; import com.google.android.gms.ads.RequestConfiguration; import java.util.ArrayList; import java.util.List; import java.util.Map; import n2.a; import s1.f; import s1.i; /* loaded from: classes.dex */ class h implements f.a, Runnable, Comparable, a.f { private q1.a A; private com.bumptech.glide.load.data.d B; private volatile s1.f C; private volatile boolean D; private volatile boolean E; private boolean F; /* renamed from: d, reason: collision with root package name */ private final e f13816d; /* renamed from: e, reason: collision with root package name */ private final y.e f13817e; /* renamed from: h, reason: collision with root package name */ private com.bumptech.glide.d f13820h; /* renamed from: i, reason: collision with root package name */ private q1.f f13821i; /* renamed from: j, reason: collision with root package name */ private com.bumptech.glide.g f13822j; /* renamed from: k, reason: collision with root package name */ private n f13823k; /* renamed from: l, reason: collision with root package name */ private int f13824l; /* renamed from: m, reason: collision with root package name */ private int f13825m; /* renamed from: n, reason: collision with root package name */ private j f13826n; /* renamed from: o, reason: collision with root package name */ private q1.h f13827o; /* renamed from: p, reason: collision with root package name */ private b f13828p; /* renamed from: q, reason: collision with root package name */ private int f13829q; /* renamed from: r, reason: collision with root package name */ private EnumC0227h f13830r; /* renamed from: s, reason: collision with root package name */ private g f13831s; /* renamed from: t, reason: collision with root package name */ private long f13832t; /* renamed from: u, reason: collision with root package name */ private boolean f13833u; /* renamed from: v, reason: collision with root package name */ private Object f13834v; /* renamed from: w, reason: collision with root package name */ private Thread f13835w; /* renamed from: x, reason: collision with root package name */ private q1.f f13836x; /* renamed from: y, reason: collision with root package name */ private q1.f f13837y; /* renamed from: z, reason: collision with root package name */ private Object f13838z; /* renamed from: a, reason: collision with root package name */ private final s1.g f13813a = new s1.g(); /* renamed from: b, reason: collision with root package name */ private final List f13814b = new ArrayList(); /* renamed from: c, reason: collision with root package name */ private final n2.c f13815c = n2.c.a(); /* renamed from: f, reason: collision with root package name */ private final d f13818f = new d(); /* renamed from: g, reason: collision with root package name */ private final f f13819g = new f(); static /* synthetic */ class a { /* renamed from: a, reason: collision with root package name */ static final /* synthetic */ int[] f13839a; /* renamed from: b, reason: collision with root package name */ static final /* synthetic */ int[] f13840b; /* renamed from: c, reason: collision with root package name */ static final /* synthetic */ int[] f13841c; static { int[] iArr = new int[q1.c.values().length]; f13841c = iArr; try { iArr[q1.c.SOURCE.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { f13841c[q1.c.TRANSFORMED.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } int[] iArr2 = new int[EnumC0227h.values().length]; f13840b = iArr2; try { iArr2[EnumC0227h.RESOURCE_CACHE.ordinal()] = 1; } catch (NoSuchFieldError unused3) { } try { f13840b[EnumC0227h.DATA_CACHE.ordinal()] = 2; } catch (NoSuchFieldError unused4) { } try { f13840b[EnumC0227h.SOURCE.ordinal()] = 3; } catch (NoSuchFieldError unused5) { } try { f13840b[EnumC0227h.FINISHED.ordinal()] = 4; } catch (NoSuchFieldError unused6) { } try { f13840b[EnumC0227h.INITIALIZE.ordinal()] = 5; } catch (NoSuchFieldError unused7) { } int[] iArr3 = new int[g.values().length]; f13839a = iArr3; try { iArr3[g.INITIALIZE.ordinal()] = 1; } catch (NoSuchFieldError unused8) { } try { f13839a[g.SWITCH_TO_SOURCE_SERVICE.ordinal()] = 2; } catch (NoSuchFieldError unused9) { } try { f13839a[g.DECODE_DATA.ordinal()] = 3; } catch (NoSuchFieldError unused10) { } } } interface b { void a(h hVar); void b(v vVar, q1.a aVar, boolean z10); void e(q qVar); } private final class c implements i.a { /* renamed from: a, reason: collision with root package name */ private final q1.a f13842a; c(q1.a aVar) { this.f13842a = aVar; } @Override // s1.i.a public v a(v vVar) { return h.this.v(this.f13842a, vVar); } } private static class d { /* renamed from: a, reason: collision with root package name */ private q1.f f13844a; /* renamed from: b, reason: collision with root package name */ private q1.k f13845b; /* renamed from: c, reason: collision with root package name */ private u f13846c; d() { } void a() { this.f13844a = null; this.f13845b = null; this.f13846c = null; } void b(e eVar, q1.h hVar) { n2.b.a("DecodeJob.encode"); try { eVar.a().a(this.f13844a, new s1.e(this.f13845b, this.f13846c, hVar)); } finally { this.f13846c.h(); n2.b.d(); } } boolean c() { return this.f13846c != null; } void d(q1.f fVar, q1.k kVar, u uVar) { this.f13844a = fVar; this.f13845b = kVar; this.f13846c = uVar; } } interface e { u1.a a(); } private static class f { /* renamed from: a, reason: collision with root package name */ private boolean f13847a; /* renamed from: b, reason: collision with root package name */ private boolean f13848b; /* renamed from: c, reason: collision with root package name */ private boolean f13849c; f() { } private boolean a(boolean z10) { return (this.f13849c || z10 || this.f13848b) && this.f13847a; } synchronized boolean b() { this.f13848b = true; return a(false); } synchronized boolean c() { this.f13849c = true; return a(false); } synchronized boolean d(boolean z10) { this.f13847a = true; return a(z10); } synchronized void e() { this.f13848b = false; this.f13847a = false; this.f13849c = false; } } private enum g { INITIALIZE, SWITCH_TO_SOURCE_SERVICE, DECODE_DATA } /* renamed from: s1.h$h, reason: collision with other inner class name */ private enum EnumC0227h { INITIALIZE, RESOURCE_CACHE, DATA_CACHE, SOURCE, ENCODE, FINISHED } h(e eVar, y.e eVar2) { this.f13816d = eVar; this.f13817e = eVar2; } private void A() { int i10 = a.f13839a[this.f13831s.ordinal()]; if (i10 == 1) { this.f13830r = k(EnumC0227h.INITIALIZE); this.C = j(); y(); } else if (i10 == 2) { y(); } else { if (i10 == 3) { i(); return; } throw new IllegalStateException("Unrecognized run reason: " + this.f13831s); } } private void B() { Throwable th; this.f13815c.c(); if (!this.D) { this.D = true; return; } if (this.f13814b.isEmpty()) { th = null; } else { List list = this.f13814b; th = (Throwable) list.get(list.size() - 1); } throw new IllegalStateException("Already notified", th); } private v g(com.bumptech.glide.load.data.d dVar, Object obj, q1.a aVar) { if (obj == null) { dVar.b(); return null; } try { long b10 = m2.f.b(); v h10 = h(obj, aVar); if (Log.isLoggable("DecodeJob", 2)) { o("Decoded result " + h10, b10); } return h10; } finally { dVar.b(); } } private v h(Object obj, q1.a aVar) { return z(obj, aVar, this.f13813a.h(obj.getClass())); } private void i() { v vVar; if (Log.isLoggable("DecodeJob", 2)) { p("Retrieved data", this.f13832t, "data: " + this.f13838z + ", cache key: " + this.f13836x + ", fetcher: " + this.B); } try { vVar = g(this.B, this.f13838z, this.A); } catch (q e10) { e10.i(this.f13837y, this.A); this.f13814b.add(e10); vVar = null; } if (vVar != null) { r(vVar, this.A, this.F); } else { y(); } } private s1.f j() { int i10 = a.f13840b[this.f13830r.ordinal()]; if (i10 == 1) { return new w(this.f13813a, this); } if (i10 == 2) { return new s1.c(this.f13813a, this); } if (i10 == 3) { return new z(this.f13813a, this); } if (i10 == 4) { return null; } throw new IllegalStateException("Unrecognized stage: " + this.f13830r); } private EnumC0227h k(EnumC0227h enumC0227h) { int i10 = a.f13840b[enumC0227h.ordinal()]; if (i10 == 1) { return this.f13826n.a() ? EnumC0227h.DATA_CACHE : k(EnumC0227h.DATA_CACHE); } if (i10 == 2) { return this.f13833u ? EnumC0227h.FINISHED : EnumC0227h.SOURCE; } if (i10 == 3 || i10 == 4) { return EnumC0227h.FINISHED; } if (i10 == 5) { return this.f13826n.b() ? EnumC0227h.RESOURCE_CACHE : k(EnumC0227h.RESOURCE_CACHE); } throw new IllegalArgumentException("Unrecognized stage: " + enumC0227h); } private q1.h l(q1.a aVar) { q1.h hVar = this.f13827o; if (Build.VERSION.SDK_INT < 26) { return hVar; } boolean z10 = aVar == q1.a.RESOURCE_DISK_CACHE || this.f13813a.w(); q1.g gVar = z1.t.f15778j; Boolean bool = (Boolean) hVar.c(gVar); if (bool != null && (!bool.booleanValue() || z10)) { return hVar; } q1.h hVar2 = new q1.h(); hVar2.d(this.f13827o); hVar2.e(gVar, Boolean.valueOf(z10)); return hVar2; } private int m() { return this.f13822j.ordinal(); } private void o(String str, long j10) { p(str, j10, null); } private void p(String str, long j10, String str2) { String str3; StringBuilder sb = new StringBuilder(); sb.append(str); sb.append(" in "); sb.append(m2.f.a(j10)); sb.append(", load key: "); sb.append(this.f13823k); if (str2 != null) { str3 = ", " + str2; } else { str3 = RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED; } sb.append(str3); sb.append(", thread: "); sb.append(Thread.currentThread().getName()); Log.v("DecodeJob", sb.toString()); } private void q(v vVar, q1.a aVar, boolean z10) { B(); this.f13828p.b(vVar, aVar, z10); } /* JADX WARN: Multi-variable type inference failed */ private void r(v vVar, q1.a aVar, boolean z10) { u uVar; if (vVar instanceof r) { ((r) vVar).initialize(); } if (this.f13818f.c()) { vVar = u.f(vVar); uVar = vVar; } else { uVar = 0; } q(vVar, aVar, z10); this.f13830r = EnumC0227h.ENCODE; try { if (this.f13818f.c()) { this.f13818f.b(this.f13816d, this.f13827o); } t(); } finally { if (uVar != 0) { uVar.h(); } } } private void s() { B(); this.f13828p.e(new q("Failed to load resource", new ArrayList(this.f13814b))); u(); } private void t() { if (this.f13819g.b()) { x(); } } private void u() { if (this.f13819g.c()) { x(); } } private void x() { this.f13819g.e(); this.f13818f.a(); this.f13813a.a(); this.D = false; this.f13820h = null; this.f13821i = null; this.f13827o = null; this.f13822j = null; this.f13823k = null; this.f13828p = null; this.f13830r = null; this.C = null; this.f13835w = null; this.f13836x = null; this.f13838z = null; this.A = null; this.B = null; this.f13832t = 0L; this.E = false; this.f13834v = null; this.f13814b.clear(); this.f13817e.a(this); } private void y() { this.f13835w = Thread.currentThread(); this.f13832t = m2.f.b(); boolean z10 = false; while (!this.E && this.C != null && !(z10 = this.C.d())) { this.f13830r = k(this.f13830r); this.C = j(); if (this.f13830r == EnumC0227h.SOURCE) { b(); return; } } if ((this.f13830r == EnumC0227h.FINISHED || this.E) && !z10) { s(); } } private v z(Object obj, q1.a aVar, t tVar) { q1.h l10 = l(aVar); com.bumptech.glide.load.data.e l11 = this.f13820h.i().l(obj); try { return tVar.a(l11, l10, this.f13824l, this.f13825m, new c(aVar)); } finally { l11.b(); } } boolean C() { EnumC0227h k10 = k(EnumC0227h.INITIALIZE); return k10 == EnumC0227h.RESOURCE_CACHE || k10 == EnumC0227h.DATA_CACHE; } @Override // s1.f.a public void a(q1.f fVar, Object obj, com.bumptech.glide.load.data.d dVar, q1.a aVar, q1.f fVar2) { this.f13836x = fVar; this.f13838z = obj; this.B = dVar; this.A = aVar; this.f13837y = fVar2; this.F = fVar != this.f13813a.c().get(0); if (Thread.currentThread() != this.f13835w) { this.f13831s = g.DECODE_DATA; this.f13828p.a(this); } else { n2.b.a("DecodeJob.decodeFromRetrievedData"); try { i(); } finally { n2.b.d(); } } } @Override // s1.f.a public void b() { this.f13831s = g.SWITCH_TO_SOURCE_SERVICE; this.f13828p.a(this); } @Override // n2.a.f public n2.c c() { return this.f13815c; } public void d() { this.E = true; s1.f fVar = this.C; if (fVar != null) { fVar.cancel(); } } @Override // s1.f.a public void e(q1.f fVar, Exception exc, com.bumptech.glide.load.data.d dVar, q1.a aVar) { dVar.b(); q qVar = new q("Fetching data failed", exc); qVar.j(fVar, aVar, dVar.a()); this.f13814b.add(qVar); if (Thread.currentThread() == this.f13835w) { y(); } else { this.f13831s = g.SWITCH_TO_SOURCE_SERVICE; this.f13828p.a(this); } } @Override // java.lang.Comparable /* renamed from: f, reason: merged with bridge method [inline-methods] */ public int compareTo(h hVar) { int m10 = m() - hVar.m(); return m10 == 0 ? this.f13829q - hVar.f13829q : m10; } h n(com.bumptech.glide.d dVar, Object obj, n nVar, q1.f fVar, int i10, int i11, Class cls, Class cls2, com.bumptech.glide.g gVar, j jVar, Map map, boolean z10, boolean z11, boolean z12, q1.h hVar, b bVar, int i12) { this.f13813a.u(dVar, obj, fVar, i10, i11, jVar, cls, cls2, gVar, hVar, map, z10, z11, this.f13816d); this.f13820h = dVar; this.f13821i = fVar; this.f13822j = gVar; this.f13823k = nVar; this.f13824l = i10; this.f13825m = i11; this.f13826n = jVar; this.f13833u = z12; this.f13827o = hVar; this.f13828p = bVar; this.f13829q = i12; this.f13831s = g.INITIALIZE; this.f13834v = obj; return this; } @Override // java.lang.Runnable public void run() { n2.b.b("DecodeJob#run(model=%s)", this.f13834v); com.bumptech.glide.load.data.d dVar = this.B; try { try { try { if (this.E) { s(); if (dVar != null) { dVar.b(); } n2.b.d(); return; } A(); if (dVar != null) { dVar.b(); } n2.b.d(); } catch (s1.b e10) { throw e10; } } catch (Throwable th) { if (Log.isLoggable("DecodeJob", 3)) { Log.d("DecodeJob", "DecodeJob threw unexpectedly, isCancelled: " + this.E + ", stage: " + this.f13830r, th); } if (this.f13830r != EnumC0227h.ENCODE) { this.f13814b.add(th); s(); } if (!this.E) { throw th; } throw th; } } catch (Throwable th2) { if (dVar != null) { dVar.b(); } n2.b.d(); throw th2; } } v v(q1.a aVar, v vVar) { v vVar2; q1.l lVar; q1.c cVar; q1.f dVar; Class cls = vVar.get().getClass(); q1.k kVar = null; if (aVar != q1.a.RESOURCE_DISK_CACHE) { q1.l r10 = this.f13813a.r(cls); lVar = r10; vVar2 = r10.b(this.f13820h, vVar, this.f13824l, this.f13825m); } else { vVar2 = vVar; lVar = null; } if (!vVar.equals(vVar2)) { vVar.a(); } if (this.f13813a.v(vVar2)) { kVar = this.f13813a.n(vVar2); cVar = kVar.a(this.f13827o); } else { cVar = q1.c.NONE; } q1.k kVar2 = kVar; if (!this.f13826n.d(!this.f13813a.x(this.f13836x), aVar, cVar)) { return vVar2; } if (kVar2 == null) { throw new i.d(vVar2.get().getClass()); } int i10 = a.f13841c[cVar.ordinal()]; if (i10 == 1) { dVar = new s1.d(this.f13836x, this.f13821i); } else { if (i10 != 2) { throw new IllegalArgumentException("Unknown strategy: " + cVar); } dVar = new x(this.f13813a.b(), this.f13836x, this.f13821i, this.f13824l, this.f13825m, lVar, cls, this.f13827o); } u f10 = u.f(vVar2); this.f13818f.d(dVar, kVar2, f10); return f10; } void w(boolean z10) { if (this.f13819g.d(z10)) { x(); } } }