package androidx.work.impl.background.systemjob;

import android.app.Application;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.os.Build;
import android.os.PersistableBundle;
import java.util.Arrays;
import java.util.HashMap;
import o.AbstractC2346rc0;
import o.AbstractC2441sc0;
import o.AbstractC2536tc0;
import o.BP;
import o.C0669Zu;
import o.C1390hY;
import o.C2366rm0;
import o.C2627ua0;
import o.C2651um0;
import o.C3031ym0;
import o.InterfaceC0645Yw;
import o.XY;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public class SystemJobService extends JobService implements InterfaceC0645Yw {
    public static final /* synthetic */ int p = 0;
    public C2651um0 l;
    public final HashMap m = new HashMap();
    public final C3031ym0 n = new C3031ym0(10);

    /* renamed from: o, reason: collision with root package name */
    public C1390hY f22o;

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

    public static C2366rm0 a(JobParameters jobParameters) {
        try {
            PersistableBundle extras = jobParameters.getExtras();
            if (extras == null || !extras.containsKey("EXTRA_WORK_SPEC_ID")) {
                return null;
            }
            return new C2366rm0(extras.getString("EXTRA_WORK_SPEC_ID"), extras.getInt("EXTRA_WORK_SPEC_GENERATION"));
        } catch (NullPointerException unused) {
            return null;
        }
    }

    @Override // o.InterfaceC0645Yw
    public final void b(C2366rm0 c2366rm0, boolean z) {
        JobParameters jobParameters;
        C0669Zu.e().getClass();
        synchronized (this.m) {
            jobParameters = (JobParameters) this.m.remove(c2366rm0);
        }
        this.n.e(c2366rm0);
        if (jobParameters != null) {
            jobFinished(jobParameters, z);
        }
    }

    @Override // android.app.Service
    public final void onCreate() {
        super.onCreate();
        try {
            C2651um0 c2651um0H = C2651um0.H(getApplicationContext());
            this.l = c2651um0H;
            XY xy = c2651um0H.p;
            this.f22o = new C1390hY(14, xy, c2651um0H.n);
            xy.a(this);
        } catch (IllegalStateException e) {
            if (!Application.class.equals(getApplication().getClass())) {
                throw new IllegalStateException("WorkManager needs to be initialized via a ContentProvider#onCreate() or an Application#onCreate().", e);
            }
            C0669Zu.e().getClass();
        }
    }

    @Override // android.app.Service
    public final void onDestroy() {
        super.onDestroy();
        C2651um0 c2651um0 = this.l;
        if (c2651um0 != null) {
            c2651um0.p.e(this);
        }
    }

    @Override // android.app.job.JobService
    public final boolean onStartJob(JobParameters jobParameters) {
        if (this.l == null) {
            C0669Zu.e().getClass();
            jobFinished(jobParameters, true);
            return false;
        }
        C2366rm0 c2366rm0A = a(jobParameters);
        if (c2366rm0A == null) {
            C0669Zu.e().getClass();
            return false;
        }
        synchronized (this.m) {
            try {
                if (this.m.containsKey(c2366rm0A)) {
                    C0669Zu c0669ZuE = C0669Zu.e();
                    c2366rm0A.toString();
                    c0669ZuE.getClass();
                    return false;
                }
                C0669Zu c0669ZuE2 = C0669Zu.e();
                c2366rm0A.toString();
                c0669ZuE2.getClass();
                this.m.put(c2366rm0A, jobParameters);
                int i = Build.VERSION.SDK_INT;
                BP bp = new BP();
                if (AbstractC2346rc0.b(jobParameters) != null) {
                    Arrays.asList(AbstractC2346rc0.b(jobParameters));
                }
                if (AbstractC2346rc0.a(jobParameters) != null) {
                    Arrays.asList(AbstractC2346rc0.a(jobParameters));
                }
                if (i >= 28) {
                    AbstractC2441sc0.a(jobParameters);
                }
                this.f22o.D(this.n.f(c2366rm0A), bp);
                return true;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override // android.app.job.JobService
    public final boolean onStopJob(JobParameters jobParameters) {
        boolean zContains;
        if (this.l == null) {
            C0669Zu.e().getClass();
            return true;
        }
        C2366rm0 c2366rm0A = a(jobParameters);
        if (c2366rm0A == null) {
            C0669Zu.e().getClass();
            return false;
        }
        C0669Zu c0669ZuE = C0669Zu.e();
        c2366rm0A.toString();
        c0669ZuE.getClass();
        synchronized (this.m) {
            this.m.remove(c2366rm0A);
        }
        C2627ua0 c2627ua0E = this.n.e(c2366rm0A);
        if (c2627ua0E != null) {
            this.f22o.E(c2627ua0E, Build.VERSION.SDK_INT >= 31 ? AbstractC2536tc0.a(jobParameters) : -512);
        }
        XY xy = this.l.p;
        String str = c2366rm0A.a;
        synchronized (xy.k) {
            zContains = xy.i.contains(str);
        }
        return !zContains;
    }
}
