package c.o.a.n.v; import androidx.annotation.NonNull; import c.o.a.n.i; import c.o.a.r.g; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.TaskCompletionSource; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.concurrent.Callable; /* compiled from: CameraOrchestrator */ public class a { public static final c.o.a.b a = new c.o.a.b(a.class.getSimpleName()); public final b b; /* renamed from: c reason: collision with root package name */ public final ArrayDeque> f1497c = new ArrayDeque<>(); public boolean d = false; public final Object e = new Object(); /* compiled from: CameraOrchestrator */ /* renamed from: c.o.a.n.v.a$a reason: collision with other inner class name */ public class CallableC0164a implements Callable> { public final /* synthetic */ Runnable i; public CallableC0164a(a aVar, Runnable runnable) { this.i = runnable; } /* Return type fixed from 'java.lang.Object' to match base method */ @Override // java.util.concurrent.Callable public Task call() throws Exception { this.i.run(); return c.i.a.f.e.o.c.F(null); } } /* compiled from: CameraOrchestrator */ public interface b { } /* compiled from: CameraOrchestrator */ public static class c { public final String a; public final TaskCompletionSource b = new TaskCompletionSource<>(); /* renamed from: c reason: collision with root package name */ public final Callable> f1498c; public final boolean d; public final long e; public c(String str, Callable callable, boolean z2, long j, CallableC0164a aVar) { this.a = str; this.f1498c = callable; this.d = z2; this.e = j; } } public a(@NonNull b bVar) { this.b = bVar; } public static void a(a aVar, c cVar) { if (aVar.d) { aVar.d = false; aVar.f1497c.remove(cVar); g gVar = i.this.j; gVar.f.postDelayed(new b(aVar), 0); return; } StringBuilder L = c.d.b.a.a.L("mJobRunning was not true after completing job="); L.append(cVar.a); throw new IllegalStateException(L.toString()); } @NonNull public Task b(@NonNull String str, boolean z2, @NonNull Runnable runnable) { return d(str, z2, 0, new CallableC0164a(this, runnable)); } @NonNull public Task c(@NonNull String str, boolean z2, long j, @NonNull Runnable runnable) { return d(str, z2, j, new CallableC0164a(this, runnable)); } @NonNull public final Task d(@NonNull String str, boolean z2, long j, @NonNull Callable> callable) { a.a(1, str.toUpperCase(), "- Scheduling."); c cVar = new c<>(str, callable, z2, System.currentTimeMillis() + j, null); synchronized (this.e) { this.f1497c.addLast(cVar); i.this.j.f.postDelayed(new b(this), j); } return cVar.b.a; } public void e(@NonNull String str, int i) { synchronized (this.e) { ArrayList arrayList = new ArrayList(); Iterator> it = this.f1497c.iterator(); while (it.hasNext()) { c next = it.next(); if (next.a.equals(str)) { arrayList.add(next); } } a.a(0, "trim: name=", str, "scheduled=", Integer.valueOf(arrayList.size()), "allowed=", Integer.valueOf(i)); int max = Math.max(arrayList.size() - i, 0); if (max > 0) { Collections.reverse(arrayList); for (c cVar : arrayList.subList(0, max)) { this.f1497c.remove(cVar); } } } } }