package androidx.loader.content; import android.os.Binder; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.Process; import android.util.Log; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; import java.util.concurrent.FutureTask; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; /* loaded from: classes.dex */ abstract class c { /* renamed from: f, reason: collision with root package name */ private static final ThreadFactory f2152f; /* renamed from: g, reason: collision with root package name */ private static final BlockingQueue f2153g; /* renamed from: h, reason: collision with root package name */ public static final Executor f2154h; /* renamed from: i, reason: collision with root package name */ private static f f2155i; /* renamed from: j, reason: collision with root package name */ private static volatile Executor f2156j; /* renamed from: a, reason: collision with root package name */ private final h f2157a; /* renamed from: b, reason: collision with root package name */ private final FutureTask f2158b; /* renamed from: c, reason: collision with root package name */ private volatile g f2159c = g.PENDING; /* renamed from: d, reason: collision with root package name */ final AtomicBoolean f2160d = new AtomicBoolean(); /* renamed from: e, reason: collision with root package name */ final AtomicBoolean f2161e = new AtomicBoolean(); static class a implements ThreadFactory { /* renamed from: a, reason: collision with root package name */ private final AtomicInteger f2162a = new AtomicInteger(1); a() { } @Override // java.util.concurrent.ThreadFactory public Thread newThread(Runnable runnable) { return new Thread(runnable, "ModernAsyncTask #" + this.f2162a.getAndIncrement()); } } class b extends h { b() { } @Override // java.util.concurrent.Callable public Object call() { c.this.f2161e.set(true); Object obj = null; try { Process.setThreadPriority(10); obj = c.this.b(this.f2172a); Binder.flushPendingCommands(); return obj; } finally { } } } /* renamed from: androidx.loader.content.c$c, reason: collision with other inner class name */ class C0031c extends FutureTask { C0031c(Callable callable) { super(callable); } @Override // java.util.concurrent.FutureTask protected void done() { try { c.this.l(get()); } catch (InterruptedException e10) { Log.w("AsyncTask", e10); } catch (CancellationException unused) { c.this.l(null); } catch (ExecutionException e11) { throw new RuntimeException("An error occurred while executing doInBackground()", e11.getCause()); } catch (Throwable th) { throw new RuntimeException("An error occurred while executing doInBackground()", th); } } } static /* synthetic */ class d { /* renamed from: a, reason: collision with root package name */ static final /* synthetic */ int[] f2165a; static { int[] iArr = new int[g.values().length]; f2165a = iArr; try { iArr[g.RUNNING.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { f2165a[g.FINISHED.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } } } private static class e { /* renamed from: a, reason: collision with root package name */ final c f2166a; /* renamed from: b, reason: collision with root package name */ final Object[] f2167b; e(c cVar, Object... objArr) { this.f2166a = cVar; this.f2167b = objArr; } } private static class f extends Handler { f() { super(Looper.getMainLooper()); } @Override // android.os.Handler public void handleMessage(Message message) { e eVar = (e) message.obj; int i10 = message.what; if (i10 == 1) { eVar.f2166a.d(eVar.f2167b[0]); } else { if (i10 != 2) { return; } eVar.f2166a.j(eVar.f2167b); } } } public enum g { PENDING, RUNNING, FINISHED } private static abstract class h implements Callable { /* renamed from: a, reason: collision with root package name */ Object[] f2172a; h() { } } static { a aVar = new a(); f2152f = aVar; LinkedBlockingQueue linkedBlockingQueue = new LinkedBlockingQueue(10); f2153g = linkedBlockingQueue; ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 128, 1L, TimeUnit.SECONDS, linkedBlockingQueue, aVar); f2154h = threadPoolExecutor; f2156j = threadPoolExecutor; } c() { b bVar = new b(); this.f2157a = bVar; this.f2158b = new C0031c(bVar); } private static Handler e() { f fVar; synchronized (c.class) { if (f2155i == null) { f2155i = new f(); } fVar = f2155i; } return fVar; } public final boolean a(boolean z10) { this.f2160d.set(true); return this.f2158b.cancel(z10); } protected abstract Object b(Object... objArr); public final c c(Executor executor, Object... objArr) { if (this.f2159c == g.PENDING) { this.f2159c = g.RUNNING; i(); this.f2157a.f2172a = objArr; executor.execute(this.f2158b); return this; } int i10 = d.f2165a[this.f2159c.ordinal()]; if (i10 == 1) { throw new IllegalStateException("Cannot execute task: the task is already running."); } if (i10 != 2) { throw new IllegalStateException("We should never reach this state"); } throw new IllegalStateException("Cannot execute task: the task has already been executed (a task can be executed only once)"); } void d(Object obj) { if (f()) { g(obj); } else { h(obj); } this.f2159c = g.FINISHED; } public final boolean f() { return this.f2160d.get(); } protected abstract void g(Object obj); protected abstract void h(Object obj); protected void i() { } protected void j(Object... objArr) { } Object k(Object obj) { e().obtainMessage(1, new e(this, obj)).sendToTarget(); return obj; } void l(Object obj) { if (this.f2161e.get()) { return; } k(obj); } }