package com.applovin.impl; import java.lang.Thread; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; /* loaded from: classes.dex */ public class tm { private static final ExecutorService o = Executors.newFixedThreadPool(4); private final com.applovin.impl.sdk.j a; private final com.applovin.impl.sdk.n b; private final ScheduledThreadPoolExecutor c; private final ScheduledThreadPoolExecutor d; private final ScheduledThreadPoolExecutor e; private final ScheduledThreadPoolExecutor f; private final ScheduledThreadPoolExecutor g; private final ScheduledThreadPoolExecutor h; private final ScheduledThreadPoolExecutor i; private final Map j = new HashMap(); private final List k = new ArrayList(5); private final Object l = new Object(); private boolean m; private boolean n; public static /* synthetic */ class a { static final /* synthetic */ int[] a; static { int[] iArr = new int[b.values().length]; a = iArr; try { iArr[b.CORE.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { a[b.CACHING.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } try { a[b.MEDIATION.ordinal()] = 3; } catch (NoSuchFieldError unused3) { } try { a[b.TIMEOUT.ordinal()] = 4; } catch (NoSuchFieldError unused4) { } } } public enum b { CORE, CACHING, MEDIATION, TIMEOUT, OTHER } public ExecutorService a() { return this.n ? this.i : this.c; } public ExecutorService b() { return this.n ? this.g : o; } public Executor c() { return this.n ? this.e : this.d; } public boolean d() { return this.m; } public tm(com.applovin.impl.sdk.j jVar) { this.a = jVar; this.b = jVar.J(); this.n = ((Boolean) jVar.a(sj.X)).booleanValue(); this.c = b("auxiliary_operations", ((Integer) jVar.a(sj.S)).intValue()); this.d = b("shared_thread_pool", ((Integer) jVar.a(sj.R)).intValue()); this.e = b("core", ((Integer) jVar.a(sj.Y)).intValue()); this.g = b("caching", ((Integer) jVar.a(sj.Z)).intValue()); this.h = b("mediation", ((Integer) jVar.a(sj.a0)).intValue()); this.f = b("timeout", ((Integer) jVar.a(sj.b0)).intValue()); this.i = b("other", ((Integer) jVar.a(sj.c0)).intValue()); } public void f() { synchronized (this.l) { this.m = false; } } public ExecutorService a(String str, int i) { return Executors.newFixedThreadPool(i, new c(str)); } public void e() { synchronized (this.l) { try { this.m = true; for (d dVar : this.k) { a(dVar.d, dVar.f); } this.k.clear(); } catch (Throwable th) { throw th; } } } public static class d implements Runnable { private final com.applovin.impl.sdk.j a; private final String b; private final com.applovin.impl.sdk.n c; private final yl d; private final b f; /* JADX WARN: Removed duplicated region for block: B:14:0x0061 A[DONT_GENERATE] */ /* JADX WARN: Removed duplicated region for block: B:17:? A[RETURN, SYNTHETIC] */ @Override // java.lang.Runnable /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public void run() { /* r6 = this; java.lang.String r0 = " queue finished task " com.applovin.impl.z3.a() // Catch: java.lang.Throwable -> L26 com.applovin.impl.sdk.j r1 = r6.a // Catch: java.lang.Throwable -> L26 boolean r1 = r1.x0() // Catch: java.lang.Throwable -> L26 if (r1 == 0) goto L38 com.applovin.impl.yl r1 = r6.d // Catch: java.lang.Throwable -> L26 boolean r1 = r1.d() // Catch: java.lang.Throwable -> L26 if (r1 == 0) goto L16 goto L38 L16: boolean r1 = com.applovin.impl.sdk.n.a() // Catch: java.lang.Throwable -> L26 if (r1 == 0) goto L28 com.applovin.impl.sdk.n r1 = r6.c // Catch: java.lang.Throwable -> L26 java.lang.String r2 = r6.b // Catch: java.lang.Throwable -> L26 java.lang.String r3 = "Task re-scheduled..." r1.d(r2, r3) // Catch: java.lang.Throwable -> L26 goto L28 L26: r1 = move-exception goto L83 L28: com.applovin.impl.sdk.j r1 = r6.a // Catch: java.lang.Throwable -> L26 com.applovin.impl.tm r1 = r1.j0() // Catch: java.lang.Throwable -> L26 com.applovin.impl.yl r2 = r6.d // Catch: java.lang.Throwable -> L26 com.applovin.impl.tm$b r3 = r6.f // Catch: java.lang.Throwable -> L26 r4 = 2000(0x7d0, double:9.88E-321) r1.a(r2, r3, r4) // Catch: java.lang.Throwable -> L26 goto L5b L38: com.applovin.impl.yl r1 = r6.d // Catch: java.lang.Throwable -> L26 java.lang.Thread r2 = java.lang.Thread.currentThread() // Catch: java.lang.Throwable -> L26 com.applovin.impl.sdk.j r3 = r6.a // Catch: java.lang.Throwable -> L26 com.applovin.impl.sj r4 = com.applovin.impl.sj.C // Catch: java.lang.Throwable -> L26 java.lang.Object r3 = r3.a(r4) // Catch: java.lang.Throwable -> L26 java.lang.Long r3 = (java.lang.Long) r3 // Catch: java.lang.Throwable -> L26 long r3 = r3.longValue() // Catch: java.lang.Throwable -> L26 java.util.concurrent.ScheduledFuture r1 = r1.b(r2, r3) // Catch: java.lang.Throwable -> L26 com.applovin.impl.yl r2 = r6.d // Catch: java.lang.Throwable -> L26 r2.run() // Catch: java.lang.Throwable -> L26 if (r1 == 0) goto L5b r2 = 0 r1.cancel(r2) // Catch: java.lang.Throwable -> L26 L5b: boolean r1 = com.applovin.impl.sdk.n.a() if (r1 == 0) goto Lc1 com.applovin.impl.sdk.n r1 = r6.c java.lang.String r2 = r6.b java.lang.StringBuilder r3 = new java.lang.StringBuilder r3.() com.applovin.impl.tm$b r4 = r6.f r3.append(r4) r3.append(r0) com.applovin.impl.yl r0 = r6.d java.lang.String r0 = r0.c() r3.append(r0) java.lang.String r0 = r3.toString() r1.d(r2, r0) goto Lc1 L83: boolean r2 = com.applovin.impl.sdk.n.a() // Catch: java.lang.Throwable -> L93 if (r2 == 0) goto L95 com.applovin.impl.sdk.n r2 = r6.c // Catch: java.lang.Throwable -> L93 java.lang.String r3 = r6.b // Catch: java.lang.Throwable -> L93 java.lang.String r4 = "Task failed execution" r2.a(r3, r4, r1) // Catch: java.lang.Throwable -> L93 goto L95 L93: r1 = move-exception goto Lc2 L95: com.applovin.impl.yl r2 = r6.d // Catch: java.lang.Throwable -> L93 r2.a(r1) // Catch: java.lang.Throwable -> L93 boolean r1 = com.applovin.impl.sdk.n.a() if (r1 == 0) goto Lc1 com.applovin.impl.sdk.n r1 = r6.c java.lang.String r2 = r6.b java.lang.StringBuilder r3 = new java.lang.StringBuilder r3.() com.applovin.impl.tm$b r4 = r6.f r3.append(r4) r3.append(r0) com.applovin.impl.yl r0 = r6.d java.lang.String r0 = r0.c() r3.append(r0) java.lang.String r0 = r3.toString() r1.d(r2, r0) Lc1: return Lc2: boolean r2 = com.applovin.impl.sdk.n.a() if (r2 == 0) goto Le9 com.applovin.impl.sdk.n r2 = r6.c java.lang.String r3 = r6.b java.lang.StringBuilder r4 = new java.lang.StringBuilder r4.() com.applovin.impl.tm$b r5 = r6.f r4.append(r5) r4.append(r0) com.applovin.impl.yl r0 = r6.d java.lang.String r0 = r0.c() r4.append(r0) java.lang.String r0 = r4.toString() r2.d(r3, r0) Le9: throw r1 */ throw new UnsupportedOperationException("Method not decompiled: com.applovin.impl.tm.d.run():void"); } public d(com.applovin.impl.sdk.j jVar, yl ylVar, b bVar) { this.a = jVar; this.c = jVar.J(); this.b = ylVar.c(); this.d = ylVar; this.f = bVar; } } public class c implements ThreadFactory { private final String a; @Override // java.util.concurrent.ThreadFactory public Thread newThread(Runnable runnable) { Thread thread = new Thread(runnable, "AppLovinSdk:" + this.a); thread.setDaemon(true); thread.setPriority(((Integer) tm.this.a.a(sj.U)).intValue()); thread.setUncaughtExceptionHandler(new a()); return thread; } public c(String str) { this.a = str; } public class a implements Thread.UncaughtExceptionHandler { public a() { } @Override // java.lang.Thread.UncaughtExceptionHandler public void uncaughtException(Thread thread, Throwable th) { com.applovin.impl.sdk.n unused = tm.this.b; if (com.applovin.impl.sdk.n.a()) { tm.this.b.a("TaskManager", "Caught unhandled exception", th); } } } } public void a(yl ylVar, b bVar) { a(ylVar, bVar, 0L); } public void a(yl ylVar, b bVar, long j) { a(ylVar, bVar, j, false); } private boolean b(d dVar) { if (dVar.d.d()) { return false; } synchronized (this.l) { try { if (this.m) { return false; } this.k.add(dVar); return true; } catch (Throwable th) { throw th; } } } public void a(yl ylVar, b bVar, long j, boolean z) { if (ylVar == null) { throw new IllegalArgumentException("No task specified"); } if (j >= 0) { d dVar = new d(this.a, ylVar, bVar); if (!b(dVar)) { a(dVar, j, z); return; } else { if (com.applovin.impl.sdk.n.a()) { this.b.d(ylVar.c(), "Task execution delayed until after init"); return; } return; } } throw new IllegalArgumentException("Invalid delay (millis) specified: " + j); } public ScheduledFuture b(yl ylVar, b bVar, long j) { if (this.n) { return a(new d(this.a, ylVar, bVar)).schedule(ylVar, j, TimeUnit.MILLISECONDS); } return this.c.schedule(ylVar, j, TimeUnit.MILLISECONDS); } private ScheduledThreadPoolExecutor b(String str, int i) { return new ScheduledThreadPoolExecutor(i, new c(str)); } public void a(yl ylVar, pe peVar) { String b2 = peVar.b(); ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = (ScheduledThreadPoolExecutor) this.j.get(b2); if (scheduledThreadPoolExecutor == null) { scheduledThreadPoolExecutor = b(b2, 1); this.j.put(b2, scheduledThreadPoolExecutor); } scheduledThreadPoolExecutor.submit(new d(this.a, ylVar, b.MEDIATION)); } public void a(Runnable runnable, b bVar) { if (this.n) { com.applovin.impl.sdk.j jVar = this.a; d dVar = new d(jVar, new jn(jVar, "auxiliaryOperation", runnable), bVar); a(dVar).submit(dVar); return; } this.c.submit(runnable); } public void a(yl ylVar) { if (ylVar != null) { ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = this.n ? this.e : this.d; try { if (yp.h()) { scheduledThreadPoolExecutor.submit(new d(this.a, ylVar, b.CORE)); return; } ScheduledFuture b2 = ylVar.b(Thread.currentThread(), ((Long) this.a.a(sj.C)).longValue()); ylVar.run(); if (b2 != null) { b2.cancel(false); return; } return; } catch (Throwable th) { if (com.applovin.impl.sdk.n.a()) { this.b.a(ylVar.c(), "Task failed execution", th); } ylVar.a(th); return; } } throw new IllegalArgumentException("No task specified"); } private void a(final d dVar, long j, boolean z) { final ScheduledThreadPoolExecutor a2 = this.n ? a(dVar) : this.d; if (j <= 0) { a2.submit(dVar); } else if (z) { x1.a(j, this.a, new Runnable() { // from class: com.applovin.impl.tm$$ExternalSyntheticLambda0 @Override // java.lang.Runnable public final void run() { a2.execute(dVar); } }); } else { a2.schedule(dVar, j, TimeUnit.MILLISECONDS); } } private ScheduledThreadPoolExecutor a(d dVar) { int i = a.a[dVar.f.ordinal()]; return i != 1 ? i != 2 ? i != 3 ? i != 4 ? this.i : this.f : this.h : this.g : this.e; } public List a(List list, ExecutorService executorService) { try { if (com.applovin.impl.sdk.n.a()) { this.b.a("TaskManager", "Awaiting " + list.size() + " tasks..."); } return executorService.invokeAll(list); } catch (Throwable th) { if (!com.applovin.impl.sdk.n.a()) { return null; } this.b.a("TaskManager", "Awaiting tasks were interrupted", th); return null; } } }