package o;

import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.content.ComponentName;
import android.content.Context;
import android.os.PersistableBundle;
import androidx.work.impl.WorkDatabase;
import androidx.work.impl.WorkDatabase_Impl;
import androidx.work.impl.background.systemjob.SystemJobService;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.Callable;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.qc0, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C2252qc0 implements D40 {
    public static final /* synthetic */ int q = 0;
    public final Context l;
    public final JobScheduler m;
    public final C2157pc0 n;

    /* renamed from: o, reason: collision with root package name */
    public final WorkDatabase f691o;
    public final C1414hl p;

    static {
        C0669Zu.l("SystemJobScheduler");
    }

    public C2252qc0(Context context, WorkDatabase workDatabase, C1414hl c1414hl) {
        JobScheduler jobScheduler = (JobScheduler) context.getSystemService("jobscheduler");
        C2157pc0 c2157pc0 = new C2157pc0(context, (BP) c1414hl.f);
        this.l = context;
        this.m = jobScheduler;
        this.n = c2157pc0;
        this.f691o = workDatabase;
        this.p = c1414hl;
    }

    public static void b(JobScheduler jobScheduler, int i) {
        try {
            jobScheduler.cancel(i);
        } catch (Throwable unused) {
            C0669Zu c0669ZuE = C0669Zu.e();
            String.format(Locale.getDefault(), "Exception while trying to cancel job (%d)", Integer.valueOf(i));
            c0669ZuE.getClass();
        }
    }

    public static ArrayList c(Context context, JobScheduler jobScheduler) {
        List<JobInfo> allPendingJobs;
        try {
            allPendingJobs = jobScheduler.getAllPendingJobs();
        } catch (Throwable unused) {
            C0669Zu.e().getClass();
            allPendingJobs = null;
        }
        if (allPendingJobs == null) {
            return null;
        }
        ArrayList arrayList = new ArrayList(allPendingJobs.size());
        ComponentName componentName = new ComponentName(context, (Class<?>) SystemJobService.class);
        for (JobInfo jobInfo : allPendingJobs) {
            if (componentName.equals(jobInfo.getService())) {
                arrayList.add(jobInfo);
            }
        }
        return arrayList;
    }

    public static C2366rm0 f(JobInfo jobInfo) {
        PersistableBundle extras = jobInfo.getExtras();
        if (extras == null) {
            return null;
        }
        try {
            if (!extras.containsKey("EXTRA_WORK_SPEC_ID")) {
                return null;
            }
            return new C2366rm0(extras.getString("EXTRA_WORK_SPEC_ID"), extras.getInt("EXTRA_WORK_SPEC_GENERATION", 0));
        } catch (NullPointerException unused) {
            return null;
        }
    }

    @Override // o.D40
    public final void a(String str) {
        ArrayList arrayList;
        Context context = this.l;
        JobScheduler jobScheduler = this.m;
        ArrayList arrayListC = c(context, jobScheduler);
        int i = 0;
        if (arrayListC == null) {
            arrayList = null;
        } else {
            ArrayList arrayList2 = new ArrayList(2);
            int size = arrayListC.size();
            int i2 = 0;
            while (i2 < size) {
                Object obj = arrayListC.get(i2);
                i2++;
                JobInfo jobInfo = (JobInfo) obj;
                C2366rm0 c2366rm0F = f(jobInfo);
                if (c2366rm0F != null && str.equals(c2366rm0F.a)) {
                    arrayList2.add(Integer.valueOf(jobInfo.getId()));
                }
            }
            arrayList = arrayList2;
        }
        if (arrayList == null || arrayList.isEmpty()) {
            return;
        }
        int size2 = arrayList.size();
        while (i < size2) {
            Object obj2 = arrayList.get(i);
            i++;
            b(jobScheduler, ((Integer) obj2).intValue());
        }
        C2062oc0 c2062oc0O = this.f691o.o();
        WorkDatabase_Impl workDatabase_Impl = (WorkDatabase_Impl) c2062oc0O.a;
        workDatabase_Impl.b();
        C1967nc0 c1967nc0 = (C1967nc0) c2062oc0O.d;
        LC lcA = c1967nc0.a();
        if (str == null) {
            lcA.r(1);
        } else {
            lcA.k(1, str);
        }
        workDatabase_Impl.c();
        try {
            lcA.b();
            workDatabase_Impl.n();
        } finally {
            workDatabase_Impl.j();
            c1967nc0.c(lcA);
        }
    }

    @Override // o.D40
    public final void d(Dm0... dm0Arr) {
        int iIntValue;
        C1414hl c1414hl = this.p;
        WorkDatabase workDatabase = this.f691o;
        final C2132pG c2132pG = new C2132pG(workDatabase);
        for (Dm0 dm0 : dm0Arr) {
            workDatabase.c();
            try {
                Dm0 dm0H = workDatabase.s().h(dm0.a);
                if (dm0H != null && dm0H.b == 1) {
                    C2366rm0 c2366rm0O = C2887xC.o(dm0);
                    C1872mc0 c1872mc0D = workDatabase.o().d(c2366rm0O);
                    if (c1872mc0D != null) {
                        iIntValue = c1872mc0D.c;
                    } else {
                        c1414hl.getClass();
                        final int i = c1414hl.a;
                        iIntValue = ((Number) c2132pG.a.m(new Callable() { // from class: o.oG
                            @Override // java.util.concurrent.Callable
                            public final Object call() {
                                WorkDatabase workDatabase2 = c2132pG.a;
                                Long lU = workDatabase2.k().u("next_job_scheduler_id");
                                int i2 = 0;
                                int iLongValue = lU != null ? (int) lU.longValue() : 0;
                                workDatabase2.k().v(new C1294gY("next_job_scheduler_id", Long.valueOf(iLongValue == Integer.MAX_VALUE ? 0 : iLongValue + 1)));
                                if (iLongValue < 0 || iLongValue > i) {
                                    workDatabase2.k().v(new C1294gY("next_job_scheduler_id", Long.valueOf(1)));
                                } else {
                                    i2 = iLongValue;
                                }
                                return Integer.valueOf(i2);
                            }
                        })).intValue();
                    }
                    if (c1872mc0D == null) {
                        workDatabase.o().f(new C1872mc0(c2366rm0O.b, c2366rm0O.a, iIntValue));
                    }
                    g(dm0, iIntValue);
                    workDatabase.n();
                } else {
                    C0669Zu.e().getClass();
                    workDatabase.n();
                }
            } finally {
                workDatabase.j();
            }
        }
    }

    @Override // o.D40
    public final boolean e() {
        return true;
    }

    /*  JADX ERROR: JadxRuntimeException in pass: RegionMakerVisitor
        jadx.core.utils.exceptions.JadxRuntimeException: Failed to find switch 'out' block (already processed)
        	at jadx.core.dex.visitors.regions.maker.SwitchRegionMaker.calcSwitchOut(SwitchRegionMaker.java:200)
        	at jadx.core.dex.visitors.regions.maker.SwitchRegionMaker.process(SwitchRegionMaker.java:61)
        	at jadx.core.dex.visitors.regions.maker.RegionMaker.traverse(RegionMaker.java:112)
        	at jadx.core.dex.visitors.regions.maker.RegionMaker.makeRegion(RegionMaker.java:66)
        	at jadx.core.dex.visitors.regions.maker.IfRegionMaker.process(IfRegionMaker.java:95)
        	at jadx.core.dex.visitors.regions.maker.RegionMaker.traverse(RegionMaker.java:106)
        	at jadx.core.dex.visitors.regions.maker.RegionMaker.makeRegion(RegionMaker.java:66)
        	at jadx.core.dex.visitors.regions.maker.IfRegionMaker.process(IfRegionMaker.java:95)
        	at jadx.core.dex.visitors.regions.maker.RegionMaker.traverse(RegionMaker.java:106)
        	at jadx.core.dex.visitors.regions.maker.RegionMaker.makeRegion(RegionMaker.java:66)
        	at jadx.core.dex.visitors.regions.maker.IfRegionMaker.process(IfRegionMaker.java:95)
        	at jadx.core.dex.visitors.regions.maker.RegionMaker.traverse(RegionMaker.java:106)
        	at jadx.core.dex.visitors.regions.maker.RegionMaker.makeRegion(RegionMaker.java:66)
        	at jadx.core.dex.visitors.regions.maker.IfRegionMaker.process(IfRegionMaker.java:101)
        	at jadx.core.dex.visitors.regions.maker.RegionMaker.traverse(RegionMaker.java:106)
        	at jadx.core.dex.visitors.regions.maker.RegionMaker.makeRegion(RegionMaker.java:66)
        	at jadx.core.dex.visitors.regions.maker.IfRegionMaker.process(IfRegionMaker.java:95)
        	at jadx.core.dex.visitors.regions.maker.RegionMaker.traverse(RegionMaker.java:106)
        	at jadx.core.dex.visitors.regions.maker.RegionMaker.makeRegion(RegionMaker.java:66)
        	at jadx.core.dex.visitors.regions.maker.IfRegionMaker.process(IfRegionMaker.java:95)
        	at jadx.core.dex.visitors.regions.maker.RegionMaker.traverse(RegionMaker.java:106)
        	at jadx.core.dex.visitors.regions.maker.RegionMaker.makeRegion(RegionMaker.java:66)
        	at jadx.core.dex.visitors.regions.maker.RegionMaker.makeMthRegion(RegionMaker.java:48)
        	at jadx.core.dex.visitors.regions.RegionMakerVisitor.visit(RegionMakerVisitor.java:25)
        */
    /* JADX WARN: Multi-variable type inference failed */
    public final void g(o.Dm0 r19, int r20) {
        /*
            Method dump skipped, instructions count: 444
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: o.C2252qc0.g(o.Dm0, int):void");
    }
}
