package com.bumptech.glide.load.engine; import android.os.Build; import android.util.Log; import androidx.core.util.Pools$Pool; import com.bumptech.glide.GlideContext; import com.bumptech.glide.Priority; import com.bumptech.glide.Registry; import com.bumptech.glide.load.DataSource; import com.bumptech.glide.load.EncodeStrategy; import com.bumptech.glide.load.Key; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.ResourceEncoder; import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.data.DataFetcher; import com.bumptech.glide.load.data.DataRewinder; import com.bumptech.glide.load.engine.DataFetcherGenerator; import com.bumptech.glide.load.engine.DecodePath; import com.bumptech.glide.load.engine.cache.DiskCache; import com.bumptech.glide.load.resource.bitmap.Downsampler; import com.bumptech.glide.util.LogTime; import com.bumptech.glide.util.pool.FactoryPools; import com.bumptech.glide.util.pool.GlideTrace; import com.bumptech.glide.util.pool.StateVerifier; import java.util.ArrayList; import java.util.List; import java.util.Map; /* loaded from: classes.dex */ class DecodeJob implements DataFetcherGenerator.FetcherReadyCallback, Runnable, Comparable>, FactoryPools.Poolable { private Object A; private DataSource B; private DataFetcher C; private volatile DataFetcherGenerator D; private volatile boolean E; private volatile boolean F; private final DiskCacheProvider d; private final Pools$Pool> e; private GlideContext h; private Key i; private Priority j; private EngineKey k; private int l; private int m; private DiskCacheStrategy n; private Options o; private Callback p; private int q; private Stage r; private RunReason s; private long t; private boolean u; private Object v; private Thread x; private Key y; private Key z; private final DecodeHelper a = new DecodeHelper<>(); private final List b = new ArrayList(); private final StateVerifier c = StateVerifier.b(); private final DeferredEncodeManager f = new DeferredEncodeManager<>(); private final ReleaseManager g = new ReleaseManager(); /* renamed from: com.bumptech.glide.load.engine.DecodeJob$1, reason: invalid class name */ static /* synthetic */ class AnonymousClass1 { static final /* synthetic */ int[] a; static final /* synthetic */ int[] b; static final /* synthetic */ int[] c = new int[EncodeStrategy.values().length]; static { try { c[EncodeStrategy.SOURCE.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { c[EncodeStrategy.TRANSFORMED.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } b = new int[Stage.values().length]; try { b[Stage.RESOURCE_CACHE.ordinal()] = 1; } catch (NoSuchFieldError unused3) { } try { b[Stage.DATA_CACHE.ordinal()] = 2; } catch (NoSuchFieldError unused4) { } try { b[Stage.SOURCE.ordinal()] = 3; } catch (NoSuchFieldError unused5) { } try { b[Stage.FINISHED.ordinal()] = 4; } catch (NoSuchFieldError unused6) { } try { b[Stage.INITIALIZE.ordinal()] = 5; } catch (NoSuchFieldError unused7) { } a = new int[RunReason.values().length]; try { a[RunReason.INITIALIZE.ordinal()] = 1; } catch (NoSuchFieldError unused8) { } try { a[RunReason.SWITCH_TO_SOURCE_SERVICE.ordinal()] = 2; } catch (NoSuchFieldError unused9) { } try { a[RunReason.DECODE_DATA.ordinal()] = 3; } catch (NoSuchFieldError unused10) { } } } interface Callback { void a(DecodeJob decodeJob); void a(GlideException glideException); void a(Resource resource, DataSource dataSource); } private final class DecodeCallback implements DecodePath.DecodeCallback { private final DataSource a; DecodeCallback(DataSource dataSource) { this.a = dataSource; } @Override // com.bumptech.glide.load.engine.DecodePath.DecodeCallback public Resource a(Resource resource) { return DecodeJob.this.a(this.a, resource); } } interface DiskCacheProvider { DiskCache a(); } private enum RunReason { INITIALIZE, SWITCH_TO_SOURCE_SERVICE, DECODE_DATA } private enum Stage { INITIALIZE, RESOURCE_CACHE, DATA_CACHE, SOURCE, ENCODE, FINISHED } DecodeJob(DiskCacheProvider diskCacheProvider, Pools$Pool> pools$Pool) { this.d = diskCacheProvider; this.e = pools$Pool; } /* JADX WARN: Multi-variable type inference failed */ private void b(Resource resource, DataSource dataSource) { if (resource instanceof Initializable) { ((Initializable) resource).c(); } LockedResource lockedResource = 0; if (this.f.b()) { resource = LockedResource.b(resource); lockedResource = resource; } a((Resource) resource, dataSource); this.r = Stage.ENCODE; try { if (this.f.b()) { this.f.a(this.d, this.o); } o(); } finally { if (lockedResource != 0) { lockedResource.d(); } } } private void f() { if (Log.isLoggable("DecodeJob", 2)) { a("Retrieved data", this.t, "data: " + this.A + ", cache key: " + this.y + ", fetcher: " + this.C); } Resource resource = null; try { resource = a(this.C, (DataFetcher) this.A, this.B); } catch (GlideException e) { e.setLoggingDetails(this.z, this.B); this.b.add(e); } if (resource != null) { b(resource, this.B); } else { r(); } } private DataFetcherGenerator m() { int i = AnonymousClass1.b[this.r.ordinal()]; if (i == 1) { return new ResourceCacheGenerator(this.a, this); } if (i == 2) { return new DataCacheGenerator(this.a, this); } if (i == 3) { return new SourceGenerator(this.a, this); } if (i == 4) { return null; } throw new IllegalStateException("Unrecognized stage: " + this.r); } private void n() { t(); this.p.a(new GlideException("Failed to load resource", new ArrayList(this.b))); p(); } private void o() { if (this.g.a()) { q(); } } private void p() { if (this.g.b()) { q(); } } private void q() { this.g.c(); this.f.a(); this.a.a(); this.E = false; this.h = null; this.i = null; this.o = null; this.j = null; this.k = null; this.p = null; this.r = null; this.D = null; this.x = null; this.y = null; this.A = null; this.B = null; this.C = null; this.t = 0L; this.F = false; this.v = null; this.b.clear(); this.e.a(this); } private void r() { this.x = Thread.currentThread(); this.t = LogTime.a(); boolean z = false; while (!this.F && this.D != null && !(z = this.D.a())) { this.r = a(this.r); this.D = m(); if (this.r == Stage.SOURCE) { d(); return; } } if ((this.r == Stage.FINISHED || this.F) && !z) { n(); } } private void s() { int i = AnonymousClass1.a[this.s.ordinal()]; if (i == 1) { this.r = a(Stage.INITIALIZE); this.D = m(); r(); } else if (i == 2) { r(); } else { if (i == 3) { f(); return; } throw new IllegalStateException("Unrecognized run reason: " + this.s); } } private void t() { this.c.a(); if (this.E) { throw new IllegalStateException("Already notified"); } this.E = true; } DecodeJob a(GlideContext glideContext, Object obj, EngineKey engineKey, Key key, int i, int i2, Class cls, Class cls2, Priority priority, DiskCacheStrategy diskCacheStrategy, Map, Transformation> map, boolean z, boolean z2, boolean z3, Options options, Callback callback, int i3) { this.a.a(glideContext, obj, key, i, i2, diskCacheStrategy, cls, cls2, priority, options, map, z, z2, this.d); this.h = glideContext; this.i = key; this.j = priority; this.k = engineKey; this.l = i; this.m = i2; this.n = diskCacheStrategy; this.u = z3; this.o = options; this.p = callback; this.q = i3; this.s = RunReason.INITIALIZE; this.v = obj; return this; } @Override // com.bumptech.glide.util.pool.FactoryPools.Poolable public StateVerifier c() { return this.c; } public void cancel() { this.F = true; DataFetcherGenerator dataFetcherGenerator = this.D; if (dataFetcherGenerator != null) { dataFetcherGenerator.cancel(); } } @Override // com.bumptech.glide.load.engine.DataFetcherGenerator.FetcherReadyCallback public void d() { this.s = RunReason.SWITCH_TO_SOURCE_SERVICE; this.p.a((DecodeJob) this); } boolean e() { Stage a = a(Stage.INITIALIZE); return a == Stage.RESOURCE_CACHE || a == Stage.DATA_CACHE; } /* JADX WARN: Code restructure failed: missing block: B:12:0x001e, code lost: if (r1 != null) goto L12; */ @Override // java.lang.Runnable /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public void run() { /* r5 = this; java.lang.String r0 = "DecodeJob" java.lang.Object r1 = r5.v java.lang.String r2 = "DecodeJob#run(model=%s)" com.bumptech.glide.util.pool.GlideTrace.a(r2, r1) com.bumptech.glide.load.data.DataFetcher r1 = r5.C boolean r2 = r5.F // Catch: java.lang.Throwable -> L27 if (r2 == 0) goto L1b r5.n() // Catch: java.lang.Throwable -> L27 if (r1 == 0) goto L17 r1.b() L17: com.bumptech.glide.util.pool.GlideTrace.a() return L1b: r5.s() // Catch: java.lang.Throwable -> L27 if (r1 == 0) goto L23 L20: r1.b() L23: com.bumptech.glide.util.pool.GlideTrace.a() goto L64 L27: r2 = move-exception r3 = 3 boolean r3 = android.util.Log.isLoggable(r0, r3) // Catch: java.lang.Throwable -> L66 if (r3 == 0) goto L4f java.lang.StringBuilder r3 = new java.lang.StringBuilder // Catch: java.lang.Throwable -> L66 r3.() // Catch: java.lang.Throwable -> L66 java.lang.String r4 = "DecodeJob threw unexpectedly, isCancelled: " r3.append(r4) // Catch: java.lang.Throwable -> L66 boolean r4 = r5.F // Catch: java.lang.Throwable -> L66 r3.append(r4) // Catch: java.lang.Throwable -> L66 java.lang.String r4 = ", stage: " r3.append(r4) // Catch: java.lang.Throwable -> L66 com.bumptech.glide.load.engine.DecodeJob$Stage r4 = r5.r // Catch: java.lang.Throwable -> L66 r3.append(r4) // Catch: java.lang.Throwable -> L66 java.lang.String r3 = r3.toString() // Catch: java.lang.Throwable -> L66 android.util.Log.d(r0, r3, r2) // Catch: java.lang.Throwable -> L66 L4f: com.bumptech.glide.load.engine.DecodeJob$Stage r0 = r5.r // Catch: java.lang.Throwable -> L66 com.bumptech.glide.load.engine.DecodeJob$Stage r3 = com.bumptech.glide.load.engine.DecodeJob.Stage.ENCODE // Catch: java.lang.Throwable -> L66 if (r0 == r3) goto L5d java.util.List r0 = r5.b // Catch: java.lang.Throwable -> L66 r0.add(r2) // Catch: java.lang.Throwable -> L66 r5.n() // Catch: java.lang.Throwable -> L66 L5d: boolean r0 = r5.F // Catch: java.lang.Throwable -> L66 if (r0 == 0) goto L65 if (r1 == 0) goto L23 goto L20 L64: return L65: throw r2 // Catch: java.lang.Throwable -> L66 L66: r0 = move-exception if (r1 == 0) goto L6c r1.b() L6c: com.bumptech.glide.util.pool.GlideTrace.a() throw r0 */ throw new UnsupportedOperationException("Method not decompiled: com.bumptech.glide.load.engine.DecodeJob.run():void"); } private static class ReleaseManager { private boolean a; private boolean b; private boolean c; ReleaseManager() { } synchronized boolean a(boolean z) { this.a = true; return b(z); } synchronized boolean b() { this.c = true; return b(false); } synchronized void c() { this.b = false; this.a = false; this.c = false; } private boolean b(boolean z) { return (this.c || z || this.b) && this.a; } synchronized boolean a() { this.b = true; return b(false); } } private static class DeferredEncodeManager { private Key a; private ResourceEncoder b; private LockedResource c; DeferredEncodeManager() { } /* JADX WARN: Multi-variable type inference failed */ void a(Key key, ResourceEncoder resourceEncoder, LockedResource lockedResource) { this.a = key; this.b = resourceEncoder; this.c = lockedResource; } boolean b() { return this.c != null; } void a(DiskCacheProvider diskCacheProvider, Options options) { GlideTrace.a("DecodeJob.encode"); try { diskCacheProvider.a().a(this.a, new DataCacheWriter(this.b, this.c, options)); } finally { this.c.d(); GlideTrace.a(); } } void a() { this.a = null; this.b = null; this.c = null; } } void a(boolean z) { if (this.g.a(z)) { q(); } } @Override // java.lang.Comparable /* renamed from: a, reason: merged with bridge method [inline-methods] */ public int compareTo(DecodeJob decodeJob) { int a = a() - decodeJob.a(); return a == 0 ? this.q - decodeJob.q : a; } private int a() { return this.j.ordinal(); } private void a(Resource resource, DataSource dataSource) { t(); this.p.a(resource, dataSource); } private Stage a(Stage stage) { int i = AnonymousClass1.b[stage.ordinal()]; if (i == 1) { return this.n.a() ? Stage.DATA_CACHE : a(Stage.DATA_CACHE); } if (i == 2) { return this.u ? Stage.FINISHED : Stage.SOURCE; } if (i == 3 || i == 4) { return Stage.FINISHED; } if (i == 5) { return this.n.b() ? Stage.RESOURCE_CACHE : a(Stage.RESOURCE_CACHE); } throw new IllegalArgumentException("Unrecognized stage: " + stage); } @Override // com.bumptech.glide.load.engine.DataFetcherGenerator.FetcherReadyCallback public void a(Key key, Object obj, DataFetcher dataFetcher, DataSource dataSource, Key key2) { this.y = key; this.A = obj; this.C = dataFetcher; this.B = dataSource; this.z = key2; if (Thread.currentThread() != this.x) { this.s = RunReason.DECODE_DATA; this.p.a((DecodeJob) this); } else { GlideTrace.a("DecodeJob.decodeFromRetrievedData"); try { f(); } finally { GlideTrace.a(); } } } @Override // com.bumptech.glide.load.engine.DataFetcherGenerator.FetcherReadyCallback public void a(Key key, Exception exc, DataFetcher dataFetcher, DataSource dataSource) { dataFetcher.b(); GlideException glideException = new GlideException("Fetching data failed", exc); glideException.setLoggingDetails(key, dataSource, dataFetcher.a()); this.b.add(glideException); if (Thread.currentThread() != this.x) { this.s = RunReason.SWITCH_TO_SOURCE_SERVICE; this.p.a((DecodeJob) this); } else { r(); } } private Resource a(DataFetcher dataFetcher, Data data, DataSource dataSource) throws GlideException { if (data == null) { return null; } try { long a = LogTime.a(); Resource a2 = a((DecodeJob) data, dataSource); if (Log.isLoggable("DecodeJob", 2)) { a("Decoded result " + a2, a); } return a2; } finally { dataFetcher.b(); } } private Resource a(Data data, DataSource dataSource) throws GlideException { return a((DecodeJob) data, dataSource, (LoadPath, ResourceType, R>) this.a.a((Class) data.getClass())); } private Options a(DataSource dataSource) { Options options = this.o; if (Build.VERSION.SDK_INT < 26 || options.a(Downsampler.h) != null) { return options; } if (dataSource != DataSource.RESOURCE_DISK_CACHE && !this.a.n()) { return options; } Options options2 = new Options(); options2.a(this.o); options2.a(Downsampler.h, true); return options2; } private Resource a(Data data, DataSource dataSource, LoadPath loadPath) throws GlideException { Options a = a(dataSource); DataRewinder b = this.h.e().b((Registry) data); try { return loadPath.a(b, a, this.l, this.m, new DecodeCallback(dataSource)); } finally { b.b(); } } private void a(String str, long j) { a(str, j, (String) null); } private void a(String str, long j, String str2) { String str3; StringBuilder sb = new StringBuilder(); sb.append(str); sb.append(" in "); sb.append(LogTime.a(j)); sb.append(", load key: "); sb.append(this.k); if (str2 != null) { str3 = ", " + str2; } else { str3 = ""; } sb.append(str3); sb.append(", thread: "); sb.append(Thread.currentThread().getName()); Log.v("DecodeJob", sb.toString()); } Resource a(DataSource dataSource, Resource resource) { Resource resource2; Transformation transformation; EncodeStrategy encodeStrategy; Key dataCacheKey; Class cls = resource.get().getClass(); ResourceEncoder resourceEncoder = null; if (dataSource != DataSource.RESOURCE_DISK_CACHE) { Transformation b = this.a.b(cls); transformation = b; resource2 = b.a(this.h, resource, this.l, this.m); } else { resource2 = resource; transformation = null; } if (!resource.equals(resource2)) { resource.a(); } if (this.a.b((Resource) resource2)) { resourceEncoder = this.a.a((Resource) resource2); encodeStrategy = resourceEncoder.a(this.o); } else { encodeStrategy = EncodeStrategy.NONE; } ResourceEncoder resourceEncoder2 = resourceEncoder; if (!this.n.a(!this.a.a(this.y), dataSource, encodeStrategy)) { return resource2; } if (resourceEncoder2 != null) { int i = AnonymousClass1.c[encodeStrategy.ordinal()]; if (i == 1) { dataCacheKey = new DataCacheKey(this.y, this.i); } else if (i == 2) { dataCacheKey = new ResourceCacheKey(this.a.b(), this.y, this.i, this.l, this.m, transformation, cls, this.o); } else { throw new IllegalArgumentException("Unknown strategy: " + encodeStrategy); } LockedResource b2 = LockedResource.b(resource2); this.f.a(dataCacheKey, resourceEncoder2, b2); return b2; } throw new Registry.NoResultEncoderAvailableException(resource2.get().getClass()); } }