package w0; import android.content.Context; import android.os.Build; import android.text.TextUtils; import androidx.work.m; import androidx.work.v; import c1.p; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import v0.e; import v0.j; import y0.c; import y0.d; /* loaded from: classes.dex */ public class b implements e, c, v0.b { /* renamed from: i, reason: collision with root package name */ private static final String f14997i = m.f("GreedyScheduler"); /* renamed from: a, reason: collision with root package name */ private final Context f14998a; /* renamed from: b, reason: collision with root package name */ private final j f14999b; /* renamed from: c, reason: collision with root package name */ private final d f15000c; /* renamed from: e, reason: collision with root package name */ private a f15002e; /* renamed from: f, reason: collision with root package name */ private boolean f15003f; /* renamed from: h, reason: collision with root package name */ Boolean f15005h; /* renamed from: d, reason: collision with root package name */ private final Set f15001d = new HashSet(); /* renamed from: g, reason: collision with root package name */ private final Object f15004g = new Object(); public b(Context context, androidx.work.b bVar, e1.a aVar, j jVar) { this.f14998a = context; this.f14999b = jVar; this.f15000c = new d(context, aVar, this); this.f15002e = new a(this, bVar.k()); } private void g() { this.f15005h = Boolean.valueOf(d1.j.b(this.f14998a, this.f14999b.i())); } private void h() { if (this.f15003f) { return; } this.f14999b.m().c(this); this.f15003f = true; } private void i(String str) { synchronized (this.f15004g) { Iterator it = this.f15001d.iterator(); while (true) { if (!it.hasNext()) { break; } p pVar = (p) it.next(); if (pVar.f3397a.equals(str)) { m.c().a(f14997i, String.format("Stopping tracking for %s", str), new Throwable[0]); this.f15001d.remove(pVar); this.f15000c.d(this.f15001d); break; } } } } @Override // v0.e public void a(p... pVarArr) { if (this.f15005h == null) { g(); } if (!this.f15005h.booleanValue()) { m.c().d(f14997i, "Ignoring schedule request in a secondary process", new Throwable[0]); return; } h(); HashSet hashSet = new HashSet(); HashSet hashSet2 = new HashSet(); for (p pVar : pVarArr) { long a10 = pVar.a(); long currentTimeMillis = System.currentTimeMillis(); if (pVar.f3398b == v.ENQUEUED) { if (currentTimeMillis < a10) { a aVar = this.f15002e; if (aVar != null) { aVar.a(pVar); } } else if (pVar.b()) { int i10 = Build.VERSION.SDK_INT; if (i10 >= 23 && pVar.f3406j.h()) { m.c().a(f14997i, String.format("Ignoring WorkSpec %s, Requires device idle.", pVar), new Throwable[0]); } else if (i10 < 24 || !pVar.f3406j.e()) { hashSet.add(pVar); hashSet2.add(pVar.f3397a); } else { m.c().a(f14997i, String.format("Ignoring WorkSpec %s, Requires ContentUri triggers.", pVar), new Throwable[0]); } } else { m.c().a(f14997i, String.format("Starting work for %s", pVar.f3397a), new Throwable[0]); this.f14999b.u(pVar.f3397a); } } } synchronized (this.f15004g) { if (!hashSet.isEmpty()) { m.c().a(f14997i, String.format("Starting tracking for [%s]", TextUtils.join(",", hashSet2)), new Throwable[0]); this.f15001d.addAll(hashSet); this.f15000c.d(this.f15001d); } } } @Override // y0.c public void b(List list) { Iterator it = list.iterator(); while (it.hasNext()) { String str = (String) it.next(); m.c().a(f14997i, String.format("Constraints not met: Cancelling work ID %s", str), new Throwable[0]); this.f14999b.x(str); } } @Override // v0.e public boolean c() { return false; } @Override // v0.b public void d(String str, boolean z10) { i(str); } @Override // v0.e public void e(String str) { if (this.f15005h == null) { g(); } if (!this.f15005h.booleanValue()) { m.c().d(f14997i, "Ignoring schedule request in non-main process", new Throwable[0]); return; } h(); m.c().a(f14997i, String.format("Cancelling work ID %s", str), new Throwable[0]); a aVar = this.f15002e; if (aVar != null) { aVar.b(str); } this.f14999b.x(str); } @Override // y0.c public void f(List list) { Iterator it = list.iterator(); while (it.hasNext()) { String str = (String) it.next(); m.c().a(f14997i, String.format("Constraints met: Scheduling work ID %s", str), new Throwable[0]); this.f14999b.u(str); } } }