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 android.text.TextUtils;
import androidx.work.WorkerParameters;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import p037.p123.AbstractC2562;
import p037.p123.p124.C2604;
import p037.p123.p124.InterfaceC2586;
import p037.p123.p124.p134.RunnableC2707;
import p037.p123.p124.p134.p136.C2731;

/* JADX INFO: loaded from: classes.dex */
public class SystemJobService extends JobService implements InterfaceC2586 {

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public static final String f1456 = AbstractC2562.m4622("SystemJobService");

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public C2604 f1457;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final Map<String, JobParameters> f1458 = new HashMap();

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static String m869(JobParameters jobParameters) {
        try {
            PersistableBundle extras = jobParameters.getExtras();
            if (extras == null || !extras.containsKey("EXTRA_WORK_SPEC_ID")) {
                return null;
            }
            return extras.getString("EXTRA_WORK_SPEC_ID");
        } catch (NullPointerException unused) {
            return null;
        }
    }

    @Override // android.app.Service
    public void onCreate() {
        super.onCreate();
        try {
            C2604 c2604M4662 = C2604.m4662(getApplicationContext());
            this.f1457 = c2604M4662;
            c2604M4662.f8143.m4642(this);
        } catch (IllegalStateException unused) {
            if (!Application.class.equals(getApplication().getClass())) {
                throw new IllegalStateException("WorkManager needs to be initialized via a ContentProvider#onCreate() or an Application#onCreate().");
            }
            AbstractC2562.m4623().mo4628(f1456, "Could not find WorkManager instance; this may be because an auto-backup is in progress. Ignoring JobScheduler commands for now. Please make sure that you are initializing WorkManager if you have manually disabled WorkManagerInitializer.", new Throwable[0]);
        }
    }

    @Override // android.app.Service
    public void onDestroy() {
        super.onDestroy();
        C2604 c2604 = this.f1457;
        if (c2604 != null) {
            c2604.f8143.m4645(this);
        }
    }

    @Override // android.app.job.JobService
    public boolean onStartJob(JobParameters jobParameters) {
        if (this.f1457 == null) {
            AbstractC2562.m4623().mo4625(f1456, "WorkManager is not initialized; requesting retry.", new Throwable[0]);
            jobFinished(jobParameters, true);
            return false;
        }
        String strM869 = m869(jobParameters);
        if (TextUtils.isEmpty(strM869)) {
            AbstractC2562.m4623().mo4626(f1456, "WorkSpec id not found!", new Throwable[0]);
            return false;
        }
        synchronized (this.f1458) {
            if (this.f1458.containsKey(strM869)) {
                AbstractC2562.m4623().mo4625(f1456, String.format("Job is already being executed by SystemJobService: %s", strM869), new Throwable[0]);
                return false;
            }
            AbstractC2562.m4623().mo4625(f1456, String.format("onStartJob for %s", strM869), new Throwable[0]);
            this.f1458.put(strM869, jobParameters);
            WorkerParameters.C0245 c0245 = null;
            if (Build.VERSION.SDK_INT >= 24) {
                c0245 = new WorkerParameters.C0245();
                if (jobParameters.getTriggeredContentUris() != null) {
                    Arrays.asList(jobParameters.getTriggeredContentUris());
                }
                if (jobParameters.getTriggeredContentAuthorities() != null) {
                    Arrays.asList(jobParameters.getTriggeredContentAuthorities());
                }
                if (Build.VERSION.SDK_INT >= 28) {
                    jobParameters.getNetwork();
                }
            }
            C2604 c2604 = this.f1457;
            ((C2731) c2604.f8141).f8440.execute(new RunnableC2707(c2604, strM869, c0245));
            return true;
        }
    }

    @Override // android.app.job.JobService
    public boolean onStopJob(JobParameters jobParameters) {
        if (this.f1457 == null) {
            AbstractC2562.m4623().mo4625(f1456, "WorkManager is not initialized; requesting retry.", new Throwable[0]);
            return true;
        }
        String strM869 = m869(jobParameters);
        if (TextUtils.isEmpty(strM869)) {
            AbstractC2562.m4623().mo4626(f1456, "WorkSpec id not found!", new Throwable[0]);
            return false;
        }
        AbstractC2562.m4623().mo4625(f1456, String.format("onStopJob for %s", strM869), new Throwable[0]);
        synchronized (this.f1458) {
            this.f1458.remove(strM869);
        }
        this.f1457.m4668(strM869);
        return !this.f1457.f8143.m4643(strM869);
    }

    @Override // p037.p123.p124.InterfaceC2586
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void mo870(String str, boolean z) {
        JobParameters jobParametersRemove;
        AbstractC2562.m4623().mo4625(f1456, String.format("%s executed on JobScheduler", str), new Throwable[0]);
        synchronized (this.f1458) {
            jobParametersRemove = this.f1458.remove(str);
        }
        if (jobParametersRemove != null) {
            jobFinished(jobParametersRemove, z);
        }
    }
}
