package com.bumptech.glide.load.engine; import android.os.Handler; import android.os.Looper; import android.os.Message; import androidx.core.util.Pools$Pool; import com.bumptech.glide.load.DataSource; import com.bumptech.glide.load.Key; import com.bumptech.glide.load.engine.DecodeJob; import com.bumptech.glide.load.engine.executor.GlideExecutor; import com.bumptech.glide.request.ResourceCallback; import com.bumptech.glide.util.Util; import com.bumptech.glide.util.pool.FactoryPools; import com.bumptech.glide.util.pool.StateVerifier; import java.util.ArrayList; import java.util.List; /* loaded from: classes.dex */ class EngineJob implements DecodeJob.Callback, FactoryPools.Poolable { private static final EngineResourceFactory y = new EngineResourceFactory(); private static final Handler z = new Handler(Looper.getMainLooper(), new MainThreadCallback()); private final List a; private final StateVerifier b; private final Pools$Pool> c; private final EngineResourceFactory d; private final EngineJobListener e; private final GlideExecutor f; private final GlideExecutor g; private final GlideExecutor h; private final GlideExecutor i; private Key j; private boolean k; private boolean l; private boolean m; private boolean n; private Resource o; private DataSource p; private boolean q; private GlideException r; private boolean s; private List t; private EngineResource u; private DecodeJob v; private volatile boolean x; static class EngineResourceFactory { EngineResourceFactory() { } public EngineResource a(Resource resource, boolean z) { return new EngineResource<>(resource, z, true); } } private static class MainThreadCallback implements Handler.Callback { MainThreadCallback() { } @Override // android.os.Handler.Callback public boolean handleMessage(Message message) { EngineJob engineJob = (EngineJob) message.obj; int i = message.what; if (i == 1) { engineJob.e(); } else if (i == 2) { engineJob.d(); } else { if (i != 3) { throw new IllegalStateException("Unrecognized message: " + message.what); } engineJob.b(); } return true; } } EngineJob(GlideExecutor glideExecutor, GlideExecutor glideExecutor2, GlideExecutor glideExecutor3, GlideExecutor glideExecutor4, EngineJobListener engineJobListener, Pools$Pool> pools$Pool) { this(glideExecutor, glideExecutor2, glideExecutor3, glideExecutor4, engineJobListener, pools$Pool, y); } private void c(ResourceCallback resourceCallback) { if (this.t == null) { this.t = new ArrayList(2); } if (this.t.contains(resourceCallback)) { return; } this.t.add(resourceCallback); } private boolean d(ResourceCallback resourceCallback) { List list = this.t; return list != null && list.contains(resourceCallback); } private GlideExecutor g() { return this.l ? this.h : this.m ? this.i : this.g; } EngineJob a(Key key, boolean z2, boolean z3, boolean z4, boolean z5) { this.j = key; this.k = z2; this.l = z3; this.m = z4; this.n = z5; return this; } public void b(DecodeJob decodeJob) { this.v = decodeJob; (decodeJob.e() ? this.f : g()).execute(decodeJob); } void e() { this.b.a(); if (this.x) { this.o.a(); a(false); return; } if (this.a.isEmpty()) { throw new IllegalStateException("Received a resource without any callbacks to notify"); } if (this.q) { throw new IllegalStateException("Already have resource"); } this.u = this.d.a(this.o, this.k); this.q = true; this.u.c(); this.e.a(this, this.j, this.u); int size = this.a.size(); for (int i = 0; i < size; i++) { ResourceCallback resourceCallback = this.a.get(i); if (!d(resourceCallback)) { this.u.c(); resourceCallback.a(this.u, this.p); } } this.u.f(); a(false); } boolean f() { return this.n; } EngineJob(GlideExecutor glideExecutor, GlideExecutor glideExecutor2, GlideExecutor glideExecutor3, GlideExecutor glideExecutor4, EngineJobListener engineJobListener, Pools$Pool> pools$Pool, EngineResourceFactory engineResourceFactory) { this.a = new ArrayList(2); this.b = StateVerifier.b(); this.f = glideExecutor; this.g = glideExecutor2; this.h = glideExecutor3; this.i = glideExecutor4; this.e = engineJobListener; this.c = pools$Pool; this.d = engineResourceFactory; } void d() { this.b.a(); if (this.x) { a(false); return; } if (this.a.isEmpty()) { throw new IllegalStateException("Received an exception without any callbacks to notify"); } if (this.s) { throw new IllegalStateException("Already failed once"); } this.s = true; this.e.a(this, this.j, null); for (ResourceCallback resourceCallback : this.a) { if (!d(resourceCallback)) { resourceCallback.a(this.r); } } a(false); } @Override // com.bumptech.glide.util.pool.FactoryPools.Poolable public StateVerifier c() { return this.b; } void a(ResourceCallback resourceCallback) { Util.b(); this.b.a(); if (this.q) { resourceCallback.a(this.u, this.p); } else if (this.s) { resourceCallback.a(this.r); } else { this.a.add(resourceCallback); } } void b(ResourceCallback resourceCallback) { Util.b(); this.b.a(); if (!this.q && !this.s) { this.a.remove(resourceCallback); if (this.a.isEmpty()) { a(); return; } return; } c(resourceCallback); } void a() { if (this.s || this.q || this.x) { return; } this.x = true; this.v.cancel(); this.e.a(this, this.j); } void b() { this.b.a(); if (this.x) { this.e.a(this, this.j); a(false); return; } throw new IllegalStateException("Not cancelled"); } private void a(boolean z2) { Util.b(); this.a.clear(); this.j = null; this.u = null; this.o = null; List list = this.t; if (list != null) { list.clear(); } this.s = false; this.x = false; this.q = false; this.v.a(z2); this.v = null; this.r = null; this.p = null; this.c.a(this); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.bumptech.glide.load.engine.DecodeJob.Callback public void a(Resource resource, DataSource dataSource) { this.o = resource; this.p = dataSource; z.obtainMessage(1, this).sendToTarget(); } @Override // com.bumptech.glide.load.engine.DecodeJob.Callback public void a(GlideException glideException) { this.r = glideException; z.obtainMessage(2, this).sendToTarget(); } @Override // com.bumptech.glide.load.engine.DecodeJob.Callback public void a(DecodeJob decodeJob) { g().execute(decodeJob); } }