package androidx.core.app;

import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Build;
import android.os.IBinder;
import java.util.ArrayList;
import java.util.HashMap;
import o.JobServiceEngineC0801bJ;
import o.WI;
import o.XI;
import o.YI;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
@Deprecated
/* loaded from: classes.dex */
public abstract class JobIntentService extends Service {
    public static final HashMap q = new HashMap();
    public JobServiceEngineC0801bJ l;
    public XI m;
    public WI n;

    /* renamed from: o, reason: collision with root package name */
    public boolean f12o = false;
    public final ArrayList p;

    public JobIntentService() {
        if (Build.VERSION.SDK_INT >= 26) {
            this.p = null;
        } else {
            this.p = new ArrayList();
        }
    }

    public final void a(boolean z) {
        if (this.n == null) {
            this.n = new WI(this);
            XI xi = this.m;
            if (xi != null && z) {
                synchronized (xi) {
                    try {
                        if (!xi.c) {
                            xi.c = true;
                            xi.b.acquire(600000L);
                            xi.a.release();
                        }
                    } finally {
                    }
                }
            }
            this.n.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
        }
    }

    public abstract void b();

    public final void c() {
        ArrayList arrayList = this.p;
        if (arrayList != null) {
            synchronized (arrayList) {
                try {
                    this.n = null;
                    ArrayList arrayList2 = this.p;
                    if (arrayList2 != null && arrayList2.size() > 0) {
                        a(false);
                    } else if (!this.f12o) {
                        this.m.a();
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
    }

    @Override // android.app.Service
    public final IBinder onBind(Intent intent) {
        JobServiceEngineC0801bJ jobServiceEngineC0801bJ = this.l;
        if (jobServiceEngineC0801bJ != null) {
            return jobServiceEngineC0801bJ.getBinder();
        }
        return null;
    }

    @Override // android.app.Service
    public final void onCreate() {
        super.onCreate();
        int i = Build.VERSION.SDK_INT;
        if (i >= 26) {
            this.l = new JobServiceEngineC0801bJ(this);
            this.m = null;
            return;
        }
        this.l = null;
        ComponentName componentName = new ComponentName(this, getClass());
        HashMap map = q;
        XI xi = (XI) map.get(componentName);
        if (xi == null) {
            if (i >= 26) {
                throw new IllegalArgumentException("Can't be here without a job id");
            }
            xi = new XI(this, componentName);
            map.put(componentName, xi);
        }
        this.m = xi;
    }

    @Override // android.app.Service
    public final void onDestroy() {
        super.onDestroy();
        ArrayList arrayList = this.p;
        if (arrayList != null) {
            synchronized (arrayList) {
                this.f12o = true;
                this.m.a();
            }
        }
    }

    @Override // android.app.Service
    public final int onStartCommand(Intent intent, int i, int i2) {
        if (this.p == null) {
            return 2;
        }
        synchronized (this.m) {
        }
        synchronized (this.p) {
            ArrayList arrayList = this.p;
            if (intent == null) {
                intent = new Intent();
            }
            arrayList.add(new YI(this, intent, i2));
            a(true);
        }
        return 3;
    }
}
