package x6; import android.content.Context; import android.graphics.drawable.Drawable; import android.util.Log; import b6.b; import b7.k; import com.google.android.gms.ads.RequestConfiguration; import h6.d; import java.util.Iterator; import java.util.List; import java.util.concurrent.Executor; /* loaded from: classes2.dex */ public final class h implements c, y6.g, g { private static final boolean D = Log.isLoggable("Request", 2); private int A; private boolean B; private RuntimeException C; /* renamed from: a, reason: collision with root package name */ private final String f15407a; /* renamed from: b, reason: collision with root package name */ private final c7.c f15408b; /* renamed from: c, reason: collision with root package name */ private final Object f15409c; /* renamed from: d, reason: collision with root package name */ private final e f15410d; /* renamed from: e, reason: collision with root package name */ private final d f15411e; /* renamed from: f, reason: collision with root package name */ private final Context f15412f; /* renamed from: g, reason: collision with root package name */ private final b6.c f15413g; /* renamed from: h, reason: collision with root package name */ private final Object f15414h; /* renamed from: i, reason: collision with root package name */ private final Class f15415i; /* renamed from: j, reason: collision with root package name */ private final x6.a f15416j; /* renamed from: k, reason: collision with root package name */ private final int f15417k; /* renamed from: l, reason: collision with root package name */ private final int f15418l; /* renamed from: m, reason: collision with root package name */ private final b6.g f15419m; /* renamed from: n, reason: collision with root package name */ private final y6.h f15420n; /* renamed from: o, reason: collision with root package name */ private final List f15421o; /* renamed from: p, reason: collision with root package name */ private final z6.e f15422p; /* renamed from: q, reason: collision with root package name */ private final Executor f15423q; /* renamed from: r, reason: collision with root package name */ private h6.h f15424r; /* renamed from: s, reason: collision with root package name */ private d.a f15425s; /* renamed from: t, reason: collision with root package name */ private long f15426t; /* renamed from: u, reason: collision with root package name */ private volatile h6.d f15427u; /* renamed from: v, reason: collision with root package name */ private a f15428v; /* renamed from: w, reason: collision with root package name */ private Drawable f15429w; /* renamed from: x, reason: collision with root package name */ private Drawable f15430x; /* renamed from: y, reason: collision with root package name */ private Drawable f15431y; /* renamed from: z, reason: collision with root package name */ private int f15432z; private enum a { PENDING, RUNNING, WAITING_FOR_SIZE, COMPLETE, FAILED, CLEARED } private h(Context context, b6.c cVar, Object obj, Object obj2, Class cls, x6.a aVar, int i10, int i11, b6.g gVar, y6.h hVar, e eVar, List list, d dVar, h6.d dVar2, z6.e eVar2, Executor executor) { this.f15407a = D ? String.valueOf(super.hashCode()) : null; this.f15408b = c7.c.b(); this.f15409c = obj; this.f15412f = context; this.f15413g = cVar; this.f15414h = obj2; this.f15415i = cls; this.f15416j = aVar; this.f15417k = i10; this.f15418l = i11; this.f15419m = gVar; this.f15420n = hVar; this.f15410d = eVar; this.f15421o = list; this.f15411e = dVar; this.f15427u = dVar2; this.f15422p = eVar2; this.f15423q = executor; this.f15428v = a.PENDING; if (this.C == null && cVar.g().a(b.a.class)) { this.C = new RuntimeException("ImageModule request origin trace"); } } public static h A(Context context, b6.c cVar, Object obj, Object obj2, Class cls, x6.a aVar, int i10, int i11, b6.g gVar, y6.h hVar, e eVar, List list, d dVar, h6.d dVar2, z6.e eVar2, Executor executor) { return new h(context, cVar, obj, obj2, cls, aVar, i10, i11, gVar, hVar, eVar, list, dVar, dVar2, eVar2, executor); } private static int j(int i10, float f10) { return i10 == Integer.MIN_VALUE ? i10 : Math.round(f10 * i10); } private Drawable k(int i10) { return q6.a.d(this.f15413g, i10, this.f15416j.P() != null ? this.f15416j.P() : this.f15412f.getTheme()); } private void l() { if (this.B) { throw new IllegalStateException("You can't start or clear loads in RequestListener or Target callbacks. If you're trying to start a fallback request when a load fails, use RequestBuilder#error(RequestBuilder). Otherwise consider posting your into() or clear() calls to the main thread using a Handler instead."); } } private void m(h6.e eVar, int i10) { boolean z10; this.f15408b.c(); synchronized (this.f15409c) { eVar.k(this.C); int h10 = this.f15413g.h(); if (h10 <= i10) { Log.w("ImageModule", "Load failed for " + this.f15414h + " with size [" + this.f15432z + "x" + this.A + "]", eVar); if (h10 <= 4) { eVar.j("ImageModule"); } } this.f15425s = null; this.f15428v = a.FAILED; boolean z11 = true; this.B = true; try { List list = this.f15421o; if (list != null) { Iterator it = list.iterator(); z10 = false; while (it.hasNext()) { z10 |= ((e) it.next()).a(eVar, this.f15414h, this.f15420n, w()); } } else { z10 = false; } e eVar2 = this.f15410d; if (eVar2 == null || !eVar2.a(eVar, this.f15414h, this.f15420n, w())) { z11 = false; } if (!(z10 | z11)) { z(); } this.B = false; x(); } catch (Throwable th) { this.B = false; throw th; } } } private void n(h6.h hVar, Object obj, e6.a aVar, boolean z10) { boolean z11; boolean w10 = w(); this.f15428v = a.COMPLETE; this.f15424r = hVar; if (this.f15413g.h() <= 3) { Log.d("ImageModule", "Finished loading " + obj.getClass().getSimpleName() + " from " + aVar + " for " + this.f15414h + " with size [" + this.f15432z + "x" + this.A + "] in " + b7.f.a(this.f15426t) + " ms"); } boolean z12 = true; this.B = true; try { List list = this.f15421o; if (list != null) { Iterator it = list.iterator(); z11 = false; while (it.hasNext()) { z11 |= ((e) it.next()).b(obj, this.f15414h, this.f15420n, aVar, w10); } } else { z11 = false; } e eVar = this.f15410d; if (eVar == null || !eVar.b(obj, this.f15414h, this.f15420n, aVar, w10)) { z12 = false; } if (!(z12 | z11)) { this.f15420n.h(obj, this.f15422p.a(aVar, w10)); } this.B = false; y(); } catch (Throwable th) { this.B = false; throw th; } } private void o(String str) { Log.v("Request", str + " this: " + this.f15407a); } private boolean p() { d dVar = this.f15411e; return dVar == null || dVar.f(this); } private boolean q() { d dVar = this.f15411e; return dVar == null || dVar.k(this); } private boolean r() { d dVar = this.f15411e; return dVar == null || dVar.e(this); } private void s() { l(); this.f15408b.c(); this.f15420n.j(this); d.a aVar = this.f15425s; if (aVar != null) { aVar.a(); this.f15425s = null; } } private Drawable t() { if (this.f15429w == null) { Drawable B = this.f15416j.B(); this.f15429w = B; if (B == null && this.f15416j.A() > 0) { this.f15429w = k(this.f15416j.A()); } } return this.f15429w; } private Drawable u() { if (this.f15431y == null) { Drawable C = this.f15416j.C(); this.f15431y = C; if (C == null && this.f15416j.D() > 0) { this.f15431y = k(this.f15416j.D()); } } return this.f15431y; } private Drawable v() { if (this.f15430x == null) { Drawable J = this.f15416j.J(); this.f15430x = J; if (J == null && this.f15416j.K() > 0) { this.f15430x = k(this.f15416j.K()); } } return this.f15430x; } private boolean w() { d dVar = this.f15411e; return dVar == null || !dVar.b().a(); } private void x() { d dVar = this.f15411e; if (dVar != null) { dVar.j(this); } } private void y() { d dVar = this.f15411e; if (dVar != null) { dVar.c(this); } } private void z() { if (q()) { Drawable u10 = this.f15414h == null ? u() : null; if (u10 == null) { u10 = t(); } if (u10 == null) { u10 = v(); } this.f15420n.a(u10); } } @Override // x6.c public boolean a() { boolean z10; synchronized (this.f15409c) { z10 = this.f15428v == a.COMPLETE; } return z10; } @Override // x6.g public void b(h6.e eVar) { m(eVar, 5); } @Override // y6.g public void c(int i10, int i11) { Object obj; this.f15408b.c(); Object obj2 = this.f15409c; synchronized (obj2) { try { try { boolean z10 = D; if (z10) { o("Got onSizeReady in " + b7.f.a(this.f15426t)); } if (this.f15428v == a.WAITING_FOR_SIZE) { a aVar = a.RUNNING; this.f15428v = aVar; float O = this.f15416j.O(); this.f15432z = j(i10, O); this.A = j(i11, O); if (z10) { o("finished setup for calling load in " + b7.f.a(this.f15426t)); } obj = obj2; try { this.f15425s = this.f15427u.k(this.f15413g, this.f15414h, this.f15416j.N(), this.f15432z, this.A, this.f15416j.M(), this.f15415i, this.f15419m, this.f15416j.y(), this.f15416j.Q(), this.f15416j.W(), this.f15416j.l(), this.f15416j.F(), this.f15416j.T(), this.f15416j.S(), this.f15416j.R(), this.f15416j.E(), this, this.f15423q); if (this.f15428v != aVar) { this.f15425s = null; } if (z10) { o("finished onSizeReady in " + b7.f.a(this.f15426t)); } } catch (Throwable th) { th = th; throw th; } } } catch (Throwable th2) { th = th2; obj = obj2; } } catch (Throwable th3) { th = th3; } } } @Override // x6.c public void clear() { synchronized (this.f15409c) { l(); this.f15408b.c(); a aVar = this.f15428v; a aVar2 = a.CLEARED; if (aVar == aVar2) { return; } s(); h6.h hVar = this.f15424r; if (hVar != null) { this.f15424r = null; } else { hVar = null; } if (p()) { this.f15420n.d(v()); } this.f15428v = aVar2; if (hVar != null) { this.f15427u.l(hVar); } } } @Override // x6.c public boolean d() { boolean z10; synchronized (this.f15409c) { z10 = this.f15428v == a.CLEARED; } return z10; } @Override // x6.g public void e(h6.h hVar, e6.a aVar, boolean z10) { this.f15408b.c(); h6.h hVar2 = null; try { synchronized (this.f15409c) { try { this.f15425s = null; if (hVar == null) { b(new h6.e("Expected to receive a Resource with an object of " + this.f15415i + " inside, but instead got null.")); return; } Object obj = hVar.get(); try { if (obj != null && this.f15415i.isAssignableFrom(obj.getClass())) { if (r()) { n(hVar, obj, aVar, z10); return; } this.f15424r = null; this.f15428v = a.COMPLETE; this.f15427u.l(hVar); return; } this.f15424r = null; StringBuilder sb = new StringBuilder(); sb.append("Expected to receive an object of "); sb.append(this.f15415i); sb.append(" but instead got "); sb.append(obj != null ? obj.getClass() : RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED); sb.append("{"); sb.append(obj); sb.append("} inside Resource{"); sb.append(hVar); sb.append("}."); sb.append(obj != null ? RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED : " To indicate failure return a null Resource object, rather than a Resource object containing null data."); b(new h6.e(sb.toString())); this.f15427u.l(hVar); } catch (Throwable th) { hVar2 = hVar; th = th; throw th; } } catch (Throwable th2) { th = th2; } } } catch (Throwable th3) { if (hVar2 != null) { this.f15427u.l(hVar2); } throw th3; } } @Override // x6.g public Object f() { this.f15408b.c(); return this.f15409c; } @Override // x6.c public void g() { synchronized (this.f15409c) { l(); this.f15408b.c(); this.f15426t = b7.f.b(); if (this.f15414h == null) { if (k.s(this.f15417k, this.f15418l)) { this.f15432z = this.f15417k; this.A = this.f15418l; } m(new h6.e("Received null model"), u() == null ? 5 : 3); return; } a aVar = this.f15428v; a aVar2 = a.RUNNING; if (aVar == aVar2) { throw new IllegalArgumentException("Cannot restart a running request"); } if (aVar == a.COMPLETE) { e(this.f15424r, e6.a.MEMORY_CACHE, false); return; } a aVar3 = a.WAITING_FOR_SIZE; this.f15428v = aVar3; if (k.s(this.f15417k, this.f15418l)) { c(this.f15417k, this.f15418l); } else { this.f15420n.e(this); } a aVar4 = this.f15428v; if ((aVar4 == aVar2 || aVar4 == aVar3) && q()) { this.f15420n.b(v()); } if (D) { o("finished run method in " + b7.f.a(this.f15426t)); } } } @Override // x6.c public boolean h() { boolean z10; synchronized (this.f15409c) { z10 = this.f15428v == a.COMPLETE; } return z10; } @Override // x6.c public boolean i(c cVar) { int i10; int i11; Object obj; Class cls; x6.a aVar; b6.g gVar; int size; int i12; int i13; Object obj2; Class cls2; x6.a aVar2; b6.g gVar2; int size2; if (!(cVar instanceof h)) { return false; } synchronized (this.f15409c) { i10 = this.f15417k; i11 = this.f15418l; obj = this.f15414h; cls = this.f15415i; aVar = this.f15416j; gVar = this.f15419m; List list = this.f15421o; size = list != null ? list.size() : 0; } h hVar = (h) cVar; synchronized (hVar.f15409c) { i12 = hVar.f15417k; i13 = hVar.f15418l; obj2 = hVar.f15414h; cls2 = hVar.f15415i; aVar2 = hVar.f15416j; gVar2 = hVar.f15419m; List list2 = hVar.f15421o; size2 = list2 != null ? list2.size() : 0; } return i10 == i12 && i11 == i13 && k.f(obj, obj2) && cls.equals(cls2) && aVar.equals(aVar2) && gVar == gVar2 && size == size2; } @Override // x6.c public boolean isRunning() { boolean z10; synchronized (this.f15409c) { a aVar = this.f15428v; z10 = aVar == a.RUNNING || aVar == a.WAITING_FOR_SIZE; } return z10; } @Override // x6.c public void pause() { synchronized (this.f15409c) { if (isRunning()) { clear(); } } } }