package d1; import java.util.HashMap; import java.util.Map; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; /* loaded from: classes.dex */ public class r { /* renamed from: f, reason: collision with root package name */ private static final String f9043f = androidx.work.m.f("WorkTimer"); /* renamed from: a, reason: collision with root package name */ private final ThreadFactory f9044a; /* renamed from: b, reason: collision with root package name */ private final ScheduledExecutorService f9045b; /* renamed from: c, reason: collision with root package name */ final Map f9046c; /* renamed from: d, reason: collision with root package name */ final Map f9047d; /* renamed from: e, reason: collision with root package name */ final Object f9048e; class a implements ThreadFactory { /* renamed from: a, reason: collision with root package name */ private int f9049a = 0; a() { } @Override // java.util.concurrent.ThreadFactory public Thread newThread(Runnable runnable) { Thread newThread = Executors.defaultThreadFactory().newThread(runnable); newThread.setName("WorkManager-WorkTimer-thread-" + this.f9049a); this.f9049a = this.f9049a + 1; return newThread; } } public interface b { void a(String str); } public static class c implements Runnable { /* renamed from: a, reason: collision with root package name */ private final r f9051a; /* renamed from: b, reason: collision with root package name */ private final String f9052b; c(r rVar, String str) { this.f9051a = rVar; this.f9052b = str; } @Override // java.lang.Runnable public void run() { synchronized (this.f9051a.f9048e) { if (((c) this.f9051a.f9046c.remove(this.f9052b)) != null) { b bVar = (b) this.f9051a.f9047d.remove(this.f9052b); if (bVar != null) { bVar.a(this.f9052b); } } else { androidx.work.m.c().a("WrkTimerRunnable", String.format("Timer with %s is already marked as complete.", this.f9052b), new Throwable[0]); } } } } public r() { a aVar = new a(); this.f9044a = aVar; this.f9046c = new HashMap(); this.f9047d = new HashMap(); this.f9048e = new Object(); this.f9045b = Executors.newSingleThreadScheduledExecutor(aVar); } public void a() { if (this.f9045b.isShutdown()) { return; } this.f9045b.shutdownNow(); } public void b(String str, long j10, b bVar) { synchronized (this.f9048e) { androidx.work.m.c().a(f9043f, String.format("Starting timer for %s", str), new Throwable[0]); c(str); c cVar = new c(this, str); this.f9046c.put(str, cVar); this.f9047d.put(str, bVar); this.f9045b.schedule(cVar, j10, TimeUnit.MILLISECONDS); } } public void c(String str) { synchronized (this.f9048e) { if (((c) this.f9046c.remove(str)) != null) { androidx.work.m.c().a(f9043f, String.format("Stopping timer for %s", str), new Throwable[0]); this.f9047d.remove(str); } } } }