package h4;

import android.content.Context;
import android.text.TextUtils;
import androidx.work.WorkInfo$State;
import androidx.work.e0;
import androidx.work.impl.e;
import androidx.work.impl.o;
import androidx.work.u;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import k4.c;
import k4.d;
import l.l;
import o4.i;

/* JADX INFO: loaded from: classes.dex */
public final class b implements e, c, androidx.work.impl.b {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f26421a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final o f26422b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final d f26423c;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final a f26425e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public boolean f26426f;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public Boolean f26428h;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final HashSet f26424d = new HashSet();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final Object f26427g = new Object();

    static {
        u.e("GreedyScheduler");
    }

    public b(Context context, androidx.work.c cVar, p4.c cVar2, o oVar) {
        this.f26421a = context;
        this.f26422b = oVar;
        this.f26423c = new d(context, cVar2, this);
        this.f26425e = new a(this, cVar.f4542e);
    }

    @Override // androidx.work.impl.e
    public final void a(n4.o... oVarArr) {
        if (this.f26428h == null) {
            androidx.work.c cVar = this.f26422b.f4624b;
            Context context = this.f26421a;
            String processName = i.getProcessName(context);
            this.f26428h = Boolean.valueOf(!TextUtils.isEmpty(cVar.getDefaultProcessName()) ? TextUtils.equals(processName, cVar.getDefaultProcessName()) : TextUtils.equals(processName, context.getApplicationInfo().processName));
        }
        if (!this.f26428h.booleanValue()) {
            u.c().d(new Throwable[0]);
            return;
        }
        if (!this.f26426f) {
            this.f26422b.f4628f.a(this);
            this.f26426f = true;
        }
        HashSet hashSet = new HashSet();
        HashSet hashSet2 = new HashSet();
        for (n4.o oVar : oVarArr) {
            long jA = oVar.a();
            long jCurrentTimeMillis = System.currentTimeMillis();
            if (oVar.f30819b == WorkInfo$State.f4516a) {
                if (jCurrentTimeMillis < jA) {
                    a aVar = this.f26425e;
                    if (aVar != null) {
                        HashMap map = aVar.f26420c;
                        Runnable runnable = (Runnable) map.remove(oVar.f30818a);
                        e0 e0Var = aVar.f26419b;
                        if (runnable != null) {
                            ((androidx.work.impl.a) e0Var).f4569a.removeCallbacks(runnable);
                        }
                        l lVar = new l(aVar, oVar, 8);
                        map.put(oVar.f30818a, lVar);
                        ((androidx.work.impl.a) e0Var).f4569a.postDelayed(lVar, oVar.a() - System.currentTimeMillis());
                    }
                } else if (oVar.b()) {
                    androidx.work.e eVar = oVar.f30827j;
                    if (eVar.f4551c) {
                        u uVarC = u.c();
                        String.format("Ignoring WorkSpec %s, Requires device idle.", oVar);
                        uVarC.a(new Throwable[0]);
                    } else if (eVar.f4556h.f4559a.size() > 0) {
                        u uVarC2 = u.c();
                        String.format("Ignoring WorkSpec %s, Requires ContentUri triggers.", oVar);
                        uVarC2.a(new Throwable[0]);
                    } else {
                        hashSet.add(oVar);
                        hashSet2.add(oVar.f30818a);
                    }
                } else {
                    u uVarC3 = u.c();
                    String.format("Starting work for %s", oVar.f30818a);
                    uVarC3.a(new Throwable[0]);
                    this.f26422b.startWork(oVar.f30818a, null);
                }
            }
        }
        synchronized (this.f26427g) {
            try {
                if (!hashSet.isEmpty()) {
                    u uVarC4 = u.c();
                    String.format("Starting tracking for [%s]", TextUtils.join(",", hashSet2));
                    uVarC4.a(new Throwable[0]);
                    this.f26424d.addAll(hashSet);
                    this.f26423c.d(this.f26424d);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override // androidx.work.impl.e
    public final boolean b() {
        return false;
    }

    @Override // androidx.work.impl.e
    public final void c(String str) {
        Runnable runnable;
        Boolean bool = this.f26428h;
        o oVar = this.f26422b;
        if (bool == null) {
            androidx.work.c cVar = oVar.f4624b;
            Context context = this.f26421a;
            String processName = i.getProcessName(context);
            this.f26428h = Boolean.valueOf(!TextUtils.isEmpty(cVar.getDefaultProcessName()) ? TextUtils.equals(processName, cVar.getDefaultProcessName()) : TextUtils.equals(processName, context.getApplicationInfo().processName));
        }
        if (!this.f26428h.booleanValue()) {
            u.c().d(new Throwable[0]);
            return;
        }
        if (!this.f26426f) {
            oVar.f4628f.a(this);
            this.f26426f = true;
        }
        u uVarC = u.c();
        String.format("Cancelling work ID %s", str);
        uVarC.a(new Throwable[0]);
        a aVar = this.f26425e;
        if (aVar != null && (runnable = (Runnable) aVar.f26420c.remove(str)) != null) {
            ((androidx.work.impl.a) aVar.f26419b).f4569a.removeCallbacks(runnable);
        }
        oVar.f(str);
    }

    @Override // k4.c
    public final void d(ArrayList arrayList) {
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            String str = (String) it.next();
            u uVarC = u.c();
            String.format("Constraints not met: Cancelling work ID %s", str);
            uVarC.a(new Throwable[0]);
            this.f26422b.f(str);
        }
    }

    @Override // k4.c
    public final void e(List list) {
        for (String str : (ArrayList) list) {
            u uVarC = u.c();
            String.format("Constraints met: Scheduling work ID %s", str);
            uVarC.a(new Throwable[0]);
            this.f26422b.startWork(str, null);
        }
    }

    @Override // androidx.work.impl.b
    public final void onExecuted(String str, boolean z10) {
        synchronized (this.f26427g) {
            try {
                Iterator it = this.f26424d.iterator();
                while (true) {
                    if (!it.hasNext()) {
                        break;
                    }
                    n4.o oVar = (n4.o) it.next();
                    if (oVar.f30818a.equals(str)) {
                        u uVarC = u.c();
                        String.format("Stopping tracking for %s", str);
                        uVarC.a(new Throwable[0]);
                        this.f26424d.remove(oVar);
                        this.f26423c.d(this.f26424d);
                        break;
                    }
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
