package h6; import android.os.Build; import android.util.Log; import b6.h; import c7.a; import com.google.android.gms.ads.RequestConfiguration; import h6.a; import h6.b; import java.util.ArrayList; import java.util.List; import java.util.Map; /* loaded from: classes2.dex */ class o implements a.InterfaceC0152a, Runnable, Comparable, a.b { private e6.a A; private f6.d B; private volatile h6.a C; private volatile boolean D; private volatile boolean E; private boolean F; /* renamed from: d, reason: collision with root package name */ private final e f10427d; /* renamed from: e, reason: collision with root package name */ private final y.e f10428e; /* renamed from: h, reason: collision with root package name */ private b6.c f10431h; /* renamed from: i, reason: collision with root package name */ private e6.h f10432i; /* renamed from: j, reason: collision with root package name */ private b6.g f10433j; /* renamed from: k, reason: collision with root package name */ private r f10434k; /* renamed from: l, reason: collision with root package name */ private int f10435l; /* renamed from: m, reason: collision with root package name */ private int f10436m; /* renamed from: n, reason: collision with root package name */ private h6.c f10437n; /* renamed from: o, reason: collision with root package name */ private e6.j f10438o; /* renamed from: p, reason: collision with root package name */ private b f10439p; /* renamed from: q, reason: collision with root package name */ private int f10440q; /* renamed from: r, reason: collision with root package name */ private h f10441r; /* renamed from: s, reason: collision with root package name */ private g f10442s; /* renamed from: t, reason: collision with root package name */ private long f10443t; /* renamed from: u, reason: collision with root package name */ private boolean f10444u; /* renamed from: v, reason: collision with root package name */ private Object f10445v; /* renamed from: w, reason: collision with root package name */ private Thread f10446w; /* renamed from: x, reason: collision with root package name */ private e6.h f10447x; /* renamed from: y, reason: collision with root package name */ private e6.h f10448y; /* renamed from: z, reason: collision with root package name */ private Object f10449z; /* renamed from: a, reason: collision with root package name */ private final n f10424a = new n(); /* renamed from: b, reason: collision with root package name */ private final List f10425b = new ArrayList(); /* renamed from: c, reason: collision with root package name */ private final c7.c f10426c = c7.c.b(); /* renamed from: f, reason: collision with root package name */ private final d f10429f = new d(); /* renamed from: g, reason: collision with root package name */ private final f f10430g = new f(); static /* synthetic */ class a { /* renamed from: a, reason: collision with root package name */ static final /* synthetic */ int[] f10450a; /* renamed from: b, reason: collision with root package name */ static final /* synthetic */ int[] f10451b; /* renamed from: c, reason: collision with root package name */ static final /* synthetic */ int[] f10452c; static { int[] iArr = new int[e6.c.values().length]; f10452c = iArr; try { iArr[e6.c.SOURCE.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { f10452c[e6.c.TRANSFORMED.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } int[] iArr2 = new int[h.values().length]; f10451b = iArr2; try { iArr2[h.RESOURCE_CACHE.ordinal()] = 1; } catch (NoSuchFieldError unused3) { } try { f10451b[h.DATA_CACHE.ordinal()] = 2; } catch (NoSuchFieldError unused4) { } try { f10451b[h.SOURCE.ordinal()] = 3; } catch (NoSuchFieldError unused5) { } try { f10451b[h.FINISHED.ordinal()] = 4; } catch (NoSuchFieldError unused6) { } try { f10451b[h.INITIALIZE.ordinal()] = 5; } catch (NoSuchFieldError unused7) { } int[] iArr3 = new int[g.values().length]; f10450a = iArr3; try { iArr3[g.INITIALIZE.ordinal()] = 1; } catch (NoSuchFieldError unused8) { } try { f10450a[g.SWITCH_TO_SOURCE_SERVICE.ordinal()] = 2; } catch (NoSuchFieldError unused9) { } try { f10450a[g.DECODE_DATA.ordinal()] = 3; } catch (NoSuchFieldError unused10) { } } } interface b { void b(h6.e eVar); void e(h6.h hVar, e6.a aVar, boolean z10); void f(o oVar); } private final class c implements b.a { /* renamed from: a, reason: collision with root package name */ private final e6.a f10453a; c(e6.a aVar) { this.f10453a = aVar; } @Override // h6.b.a public h6.h a(h6.h hVar) { return o.this.g(this.f10453a, hVar); } } private static class d { /* renamed from: a, reason: collision with root package name */ private e6.h f10455a; /* renamed from: b, reason: collision with root package name */ private e6.m f10456b; /* renamed from: c, reason: collision with root package name */ private v f10457c; d() { } void a() { this.f10455a = null; this.f10456b = null; this.f10457c = null; } void b(e6.h hVar, e6.m mVar, v vVar) { this.f10455a = hVar; this.f10456b = mVar; this.f10457c = vVar; } void c(e eVar, e6.j jVar) { c7.b.a("DecodeJob.encode"); try { eVar.a().a(this.f10455a, new m(this.f10456b, this.f10457c, jVar)); } finally { this.f10457c.h(); c7.b.d(); } } boolean d() { return this.f10457c != null; } } interface e { j6.a a(); } private static class f { /* renamed from: a, reason: collision with root package name */ private boolean f10458a; /* renamed from: b, reason: collision with root package name */ private boolean f10459b; /* renamed from: c, reason: collision with root package name */ private boolean f10460c; f() { } private boolean b(boolean z10) { return (this.f10460c || z10 || this.f10459b) && this.f10458a; } synchronized boolean a() { this.f10459b = true; return b(false); } synchronized boolean c() { this.f10460c = true; return b(false); } synchronized boolean d(boolean z10) { this.f10458a = true; return b(z10); } synchronized void e() { this.f10459b = false; this.f10458a = false; this.f10460c = false; } } private enum g { INITIALIZE, SWITCH_TO_SOURCE_SERVICE, DECODE_DATA } private enum h { INITIALIZE, RESOURCE_CACHE, DATA_CACHE, SOURCE, ENCODE, FINISHED } o(e eVar, y.e eVar2) { this.f10427d = eVar; this.f10428e = eVar2; } private void A() { int i10 = a.f10450a[this.f10442s.ordinal()]; if (i10 == 1) { this.f10441r = k(h.INITIALIZE); this.C = t(); } else if (i10 != 2) { if (i10 == 3) { r(); return; } throw new IllegalStateException("Unrecognized run reason: " + this.f10442s); } z(); } private void B() { Throwable th; this.f10426c.c(); if (!this.D) { this.D = true; return; } if (this.f10425b.isEmpty()) { th = null; } else { List list = this.f10425b; th = (Throwable) list.get(list.size() - 1); } throw new IllegalStateException("Already notified", th); } private e6.j f(e6.a aVar) { e6.j jVar = this.f10438o; if (Build.VERSION.SDK_INT < 26) { return jVar; } boolean z10 = aVar == e6.a.RESOURCE_DISK_CACHE || this.f10424a.x(); e6.i iVar = o6.m.f12755j; Boolean bool = (Boolean) jVar.d(iVar); if (bool != null && (!bool.booleanValue() || z10)) { return jVar; } e6.j jVar2 = new e6.j(); jVar2.e(this.f10438o); jVar2.f(iVar, Boolean.valueOf(z10)); return jVar2; } private h6.h h(f6.d dVar, Object obj, e6.a aVar) { if (obj == null) { dVar.b(); return null; } try { long b10 = b7.f.b(); h6.h i10 = i(obj, aVar); if (Log.isLoggable("DecodeJob", 2)) { o("Decoded result " + i10, b10); } return i10; } finally { dVar.b(); } } private h6.h i(Object obj, e6.a aVar) { return j(obj, aVar, this.f10424a.c(obj.getClass())); } private h6.h j(Object obj, e6.a aVar, h6.g gVar) { e6.j f10 = f(aVar); f6.e l10 = this.f10431h.i().l(obj); try { return gVar.b(l10, f10, this.f10435l, this.f10436m, new c(aVar)); } finally { l10.b(); } } private h k(h hVar) { int i10 = a.f10451b[hVar.ordinal()]; if (i10 == 1) { return this.f10437n.a() ? h.DATA_CACHE : k(h.DATA_CACHE); } if (i10 == 2) { return this.f10444u ? h.FINISHED : h.SOURCE; } if (i10 == 3 || i10 == 4) { return h.FINISHED; } if (i10 == 5) { return this.f10437n.b() ? h.RESOURCE_CACHE : k(h.RESOURCE_CACHE); } throw new IllegalArgumentException("Unrecognized stage: " + hVar); } private void n(h6.h hVar, e6.a aVar, boolean z10) { B(); this.f10439p.e(hVar, aVar, z10); } 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(b7.f.a(j10)); sb.append(", load key: "); sb.append(this.f10434k); 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 r() { h6.h hVar; if (Log.isLoggable("DecodeJob", 2)) { p("Retrieved data", this.f10443t, "data: " + this.f10449z + ", cache key: " + this.f10447x + ", fetcher: " + this.B); } try { hVar = h(this.B, this.f10449z, this.A); } catch (h6.e e10) { e10.a(this.f10448y, this.A); this.f10425b.add(e10); hVar = null; } if (hVar != null) { s(hVar, this.A, this.F); } else { z(); } } /* JADX WARN: Multi-variable type inference failed */ private void s(h6.h hVar, e6.a aVar, boolean z10) { v vVar; if (hVar instanceof h6.f) { ((h6.f) hVar).initialize(); } if (this.f10429f.d()) { hVar = v.g(hVar); vVar = hVar; } else { vVar = 0; } n(hVar, aVar, z10); this.f10441r = h.ENCODE; try { if (this.f10429f.d()) { this.f10429f.c(this.f10427d, this.f10438o); } w(); } finally { if (vVar != 0) { vVar.h(); } } } private h6.a t() { int i10 = a.f10451b[this.f10441r.ordinal()]; if (i10 == 1) { return new w(this.f10424a, this); } if (i10 == 2) { return new k(this.f10424a, this); } if (i10 == 3) { return new z(this.f10424a, this); } if (i10 == 4) { return null; } throw new IllegalStateException("Unrecognized stage: " + this.f10441r); } private int u() { return this.f10433j.ordinal(); } private void v() { B(); this.f10439p.b(new h6.e("Failed to load resource", new ArrayList(this.f10425b))); x(); } private void w() { if (this.f10430g.a()) { y(); } } private void x() { if (this.f10430g.c()) { y(); } } private void y() { this.f10430g.e(); this.f10429f.a(); this.f10424a.e(); this.D = false; this.f10431h = null; this.f10432i = null; this.f10438o = null; this.f10433j = null; this.f10434k = null; this.f10439p = null; this.f10441r = null; this.C = null; this.f10446w = null; this.f10447x = null; this.f10449z = null; this.A = null; this.B = null; this.f10443t = 0L; this.E = false; this.f10445v = null; this.f10425b.clear(); this.f10428e.a(this); } private void z() { this.f10446w = Thread.currentThread(); this.f10443t = b7.f.b(); boolean z10 = false; while (!this.E && this.C != null && !(z10 = this.C.a())) { this.f10441r = k(this.f10441r); this.C = t(); if (this.f10441r == h.SOURCE) { b(); return; } } if ((this.f10441r == h.FINISHED || this.E) && !z10) { v(); } } boolean C() { h k10 = k(h.INITIALIZE); return k10 == h.RESOURCE_CACHE || k10 == h.DATA_CACHE; } @Override // java.lang.Comparable /* renamed from: a, reason: merged with bridge method [inline-methods] */ public int compareTo(o oVar) { int u10 = u() - oVar.u(); return u10 == 0 ? this.f10440q - oVar.f10440q : u10; } @Override // h6.a.InterfaceC0152a public void b() { this.f10442s = g.SWITCH_TO_SOURCE_SERVICE; this.f10439p.f(this); } @Override // c7.a.b public c7.c c() { return this.f10426c; } @Override // h6.a.InterfaceC0152a public void d(e6.h hVar, Exception exc, f6.d dVar, e6.a aVar) { dVar.b(); h6.e eVar = new h6.e("Fetching data failed", exc); eVar.b(hVar, aVar, dVar.a()); this.f10425b.add(eVar); if (Thread.currentThread() == this.f10446w) { z(); } else { this.f10442s = g.SWITCH_TO_SOURCE_SERVICE; this.f10439p.f(this); } } @Override // h6.a.InterfaceC0152a public void e(e6.h hVar, Object obj, f6.d dVar, e6.a aVar, e6.h hVar2) { this.f10447x = hVar; this.f10449z = obj; this.B = dVar; this.A = aVar; this.f10448y = hVar2; this.F = hVar != this.f10424a.k().get(0); if (Thread.currentThread() != this.f10446w) { this.f10442s = g.DECODE_DATA; this.f10439p.f(this); } else { c7.b.a("DecodeJob.decodeFromRetrievedData"); try { r(); } finally { c7.b.d(); } } } h6.h g(e6.a aVar, h6.h hVar) { h6.h hVar2; e6.n nVar; e6.c cVar; e6.h lVar; Class cls = hVar.get().getClass(); e6.m mVar = null; if (aVar != e6.a.RESOURCE_DISK_CACHE) { e6.n h10 = this.f10424a.h(cls); nVar = h10; hVar2 = h10.b(this.f10431h, hVar, this.f10435l, this.f10436m); } else { hVar2 = hVar; nVar = null; } if (!hVar.equals(hVar2)) { hVar.a(); } if (this.f10424a.j(hVar2)) { mVar = this.f10424a.b(hVar2); cVar = mVar.b(this.f10438o); } else { cVar = e6.c.NONE; } e6.m mVar2 = mVar; if (!this.f10437n.d(!this.f10424a.g(this.f10447x), aVar, cVar)) { return hVar2; } if (mVar2 == null) { throw new h.d(hVar2.get().getClass()); } int i10 = a.f10452c[cVar.ordinal()]; if (i10 == 1) { lVar = new l(this.f10447x, this.f10432i); } else { if (i10 != 2) { throw new IllegalArgumentException("Unknown strategy: " + cVar); } lVar = new x(this.f10424a.i(), this.f10447x, this.f10432i, this.f10435l, this.f10436m, nVar, cls, this.f10438o); } v g10 = v.g(hVar2); this.f10429f.b(lVar, mVar2, g10); return g10; } o l(b6.c cVar, Object obj, r rVar, e6.h hVar, int i10, int i11, Class cls, Class cls2, b6.g gVar, h6.c cVar2, Map map, boolean z10, boolean z11, boolean z12, e6.j jVar, b bVar, int i12) { this.f10424a.f(cVar, obj, hVar, i10, i11, cVar2, cls, cls2, gVar, jVar, map, z10, z11, this.f10427d); this.f10431h = cVar; this.f10432i = hVar; this.f10433j = gVar; this.f10434k = rVar; this.f10435l = i10; this.f10436m = i11; this.f10437n = cVar2; this.f10444u = z12; this.f10438o = jVar; this.f10439p = bVar; this.f10440q = i12; this.f10442s = g.INITIALIZE; this.f10445v = obj; return this; } public void m() { this.E = true; h6.a aVar = this.C; if (aVar != null) { aVar.cancel(); } } void q(boolean z10) { if (this.f10430g.d(z10)) { y(); } } @Override // java.lang.Runnable public void run() { c7.b.b("DecodeJob#run(model=%s)", this.f10445v); f6.d dVar = this.B; try { try { try { if (this.E) { v(); if (dVar != null) { dVar.b(); } c7.b.d(); return; } A(); if (dVar != null) { dVar.b(); } c7.b.d(); } catch (Throwable th) { if (Log.isLoggable("DecodeJob", 3)) { Log.d("DecodeJob", "DecodeJob threw unexpectedly, isCancelled: " + this.E + ", stage: " + this.f10441r, th); } if (this.f10441r != h.ENCODE) { this.f10425b.add(th); v(); } throw th; } } catch (j e10) { throw e10; } } catch (Throwable th2) { if (dVar != null) { dVar.b(); } c7.b.d(); throw th2; } } }