package h6; import c7.a; import h6.o; import h6.t; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicInteger; /* loaded from: classes2.dex */ class p implements o.b, a.b { /* renamed from: z, reason: collision with root package name */ private static final c f10472z = new c(); /* renamed from: a, reason: collision with root package name */ final e f10473a; /* renamed from: b, reason: collision with root package name */ private final c7.c f10474b; /* renamed from: c, reason: collision with root package name */ private final t.a f10475c; /* renamed from: d, reason: collision with root package name */ private final y.e f10476d; /* renamed from: e, reason: collision with root package name */ private final c f10477e; /* renamed from: f, reason: collision with root package name */ private final q f10478f; /* renamed from: g, reason: collision with root package name */ private final k6.a f10479g; /* renamed from: h, reason: collision with root package name */ private final k6.a f10480h; /* renamed from: i, reason: collision with root package name */ private final k6.a f10481i; /* renamed from: j, reason: collision with root package name */ private final k6.a f10482j; /* renamed from: k, reason: collision with root package name */ private final AtomicInteger f10483k; /* renamed from: l, reason: collision with root package name */ private e6.h f10484l; /* renamed from: m, reason: collision with root package name */ private boolean f10485m; /* renamed from: n, reason: collision with root package name */ private boolean f10486n; /* renamed from: o, reason: collision with root package name */ private boolean f10487o; /* renamed from: p, reason: collision with root package name */ private boolean f10488p; /* renamed from: q, reason: collision with root package name */ private h f10489q; /* renamed from: r, reason: collision with root package name */ e6.a f10490r; /* renamed from: s, reason: collision with root package name */ private boolean f10491s; /* renamed from: t, reason: collision with root package name */ h6.e f10492t; /* renamed from: u, reason: collision with root package name */ private boolean f10493u; /* renamed from: v, reason: collision with root package name */ t f10494v; /* renamed from: w, reason: collision with root package name */ private o f10495w; /* renamed from: x, reason: collision with root package name */ private volatile boolean f10496x; /* renamed from: y, reason: collision with root package name */ private boolean f10497y; private class a implements Runnable { /* renamed from: a, reason: collision with root package name */ private final x6.g f10498a; a(x6.g gVar) { this.f10498a = gVar; } @Override // java.lang.Runnable public void run() { synchronized (this.f10498a.f()) { synchronized (p.this) { if (p.this.f10473a.c(this.f10498a)) { p.this.h(this.f10498a); } p.this.j(); } } } } private class b implements Runnable { /* renamed from: a, reason: collision with root package name */ private final x6.g f10500a; b(x6.g gVar) { this.f10500a = gVar; } @Override // java.lang.Runnable public void run() { synchronized (this.f10500a.f()) { synchronized (p.this) { if (p.this.f10473a.c(this.f10500a)) { p.this.f10494v.c(); p.this.l(this.f10500a); p.this.n(this.f10500a); } p.this.j(); } } } } static class c { c() { } public t a(h hVar, boolean z10, e6.h hVar2, t.a aVar) { return new t(hVar, z10, true, hVar2, aVar); } } static final class d { /* renamed from: a, reason: collision with root package name */ final x6.g f10502a; /* renamed from: b, reason: collision with root package name */ final Executor f10503b; d(x6.g gVar, Executor executor) { this.f10502a = gVar; this.f10503b = executor; } public boolean equals(Object obj) { if (obj instanceof d) { return this.f10502a.equals(((d) obj).f10502a); } return false; } public int hashCode() { return this.f10502a.hashCode(); } } static final class e implements Iterable { /* renamed from: a, reason: collision with root package name */ private final List f10504a; e() { this(new ArrayList(2)); } private static d d(x6.g gVar) { return new d(gVar, b7.e.a()); } e a() { return new e(new ArrayList(this.f10504a)); } void b(x6.g gVar, Executor executor) { this.f10504a.add(new d(gVar, executor)); } boolean c(x6.g gVar) { return this.f10504a.contains(d(gVar)); } void clear() { this.f10504a.clear(); } void e(x6.g gVar) { this.f10504a.remove(d(gVar)); } boolean isEmpty() { return this.f10504a.isEmpty(); } @Override // java.lang.Iterable public Iterator iterator() { return this.f10504a.iterator(); } int size() { return this.f10504a.size(); } e(List list) { this.f10504a = list; } } p(k6.a aVar, k6.a aVar2, k6.a aVar3, k6.a aVar4, q qVar, t.a aVar5, y.e eVar) { this(aVar, aVar2, aVar3, aVar4, qVar, aVar5, eVar, f10472z); } private k6.a m() { return this.f10486n ? this.f10481i : this.f10487o ? this.f10482j : this.f10480h; } private boolean o() { return this.f10493u || this.f10491s || this.f10496x; } private synchronized void s() { if (this.f10484l == null) { throw new IllegalArgumentException(); } this.f10473a.clear(); this.f10484l = null; this.f10494v = null; this.f10489q = null; this.f10493u = false; this.f10496x = false; this.f10491s = false; this.f10497y = false; this.f10495w.q(false); this.f10495w = null; this.f10492t = null; this.f10490r = null; this.f10476d.a(this); } synchronized p a(e6.h hVar, boolean z10, boolean z11, boolean z12, boolean z13) { this.f10484l = hVar; this.f10485m = z10; this.f10486n = z11; this.f10487o = z12; this.f10488p = z13; return this; } @Override // h6.o.b public void b(h6.e eVar) { synchronized (this) { this.f10492t = eVar; } p(); } @Override // c7.a.b public c7.c c() { return this.f10474b; } void d() { if (o()) { return; } this.f10496x = true; this.f10495w.m(); this.f10478f.a(this, this.f10484l); } @Override // h6.o.b public void e(h hVar, e6.a aVar, boolean z10) { synchronized (this) { this.f10489q = hVar; this.f10490r = aVar; this.f10497y = z10; } q(); } @Override // h6.o.b public void f(o oVar) { m().execute(oVar); } synchronized void g(int i10) { t tVar; b7.j.a(o(), "Not yet complete!"); if (this.f10483k.getAndAdd(i10) == 0 && (tVar = this.f10494v) != null) { tVar.c(); } } void h(x6.g gVar) { try { gVar.b(this.f10492t); } catch (Throwable th) { throw new j(th); } } synchronized void i(x6.g gVar, Executor executor) { Runnable aVar; this.f10474b.c(); this.f10473a.b(gVar, executor); if (this.f10491s) { g(1); aVar = new b(gVar); } else if (this.f10493u) { g(1); aVar = new a(gVar); } else { b7.j.a(!this.f10496x, "Cannot add callbacks to a cancelled EngineJob"); } executor.execute(aVar); } void j() { t tVar; synchronized (this) { this.f10474b.c(); b7.j.a(o(), "Not yet complete!"); int decrementAndGet = this.f10483k.decrementAndGet(); b7.j.a(decrementAndGet >= 0, "Can't decrement below 0"); if (decrementAndGet == 0) { tVar = this.f10494v; s(); } else { tVar = null; } } if (tVar != null) { tVar.g(); } } public synchronized void k(o oVar) { this.f10495w = oVar; (oVar.C() ? this.f10479g : m()).execute(oVar); } void l(x6.g gVar) { try { gVar.e(this.f10494v, this.f10490r, this.f10497y); } catch (Throwable th) { throw new j(th); } } synchronized void n(x6.g gVar) { boolean z10; this.f10474b.c(); this.f10473a.e(gVar); if (this.f10473a.isEmpty()) { d(); if (!this.f10491s && !this.f10493u) { z10 = false; if (z10 && this.f10483k.get() == 0) { s(); } } z10 = true; if (z10) { s(); } } } void p() { synchronized (this) { this.f10474b.c(); if (this.f10496x) { s(); return; } if (this.f10473a.isEmpty()) { throw new IllegalStateException("Received an exception without any callbacks to notify"); } if (this.f10493u) { throw new IllegalStateException("Already failed once"); } this.f10493u = true; e6.h hVar = this.f10484l; e a10 = this.f10473a.a(); g(a10.size() + 1); this.f10478f.c(this, hVar, null); Iterator it = a10.iterator(); while (it.hasNext()) { d dVar = (d) it.next(); dVar.f10503b.execute(new a(dVar.f10502a)); } j(); } } void q() { synchronized (this) { this.f10474b.c(); if (this.f10496x) { this.f10489q.a(); s(); return; } if (this.f10473a.isEmpty()) { throw new IllegalStateException("Received a resource without any callbacks to notify"); } if (this.f10491s) { throw new IllegalStateException("Already have resource"); } this.f10494v = this.f10477e.a(this.f10489q, this.f10485m, this.f10484l, this.f10475c); this.f10491s = true; e a10 = this.f10473a.a(); g(a10.size() + 1); this.f10478f.c(this, this.f10484l, this.f10494v); Iterator it = a10.iterator(); while (it.hasNext()) { d dVar = (d) it.next(); dVar.f10503b.execute(new b(dVar.f10502a)); } j(); } } boolean r() { return this.f10488p; } p(k6.a aVar, k6.a aVar2, k6.a aVar3, k6.a aVar4, q qVar, t.a aVar5, y.e eVar, c cVar) { this.f10473a = new e(); this.f10474b = c7.c.b(); this.f10483k = new AtomicInteger(); this.f10479g = aVar; this.f10480h = aVar2; this.f10481i = aVar3; this.f10482j = aVar4; this.f10478f = qVar; this.f10475c = aVar5; this.f10476d = eVar; this.f10477e = cVar; } }