package a6;

import android.content.BroadcastReceiver;
import android.content.Context;
import androidx.work.WorkerParameters;
import androidx.work.impl.WorkDatabase;
import androidx.work.impl.utils.ForceStopRunnable;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import z5.k;
import z5.n;
import z5.q;
import z5.s;
import z5.u;
import z5.v;

/* loaded from: classes.dex */
public class i extends u {

    /* renamed from: j, reason: collision with root package name */
    private static final String f219j = z5.k.f("WorkManagerImpl");

    /* renamed from: k, reason: collision with root package name */
    private static i f220k = null;

    /* renamed from: l, reason: collision with root package name */
    private static i f221l = null;

    /* renamed from: m, reason: collision with root package name */
    private static final Object f222m = new Object();

    /* renamed from: a, reason: collision with root package name */
    private Context f223a;

    /* renamed from: b, reason: collision with root package name */
    private androidx.work.a f224b;

    /* renamed from: c, reason: collision with root package name */
    private WorkDatabase f225c;

    /* renamed from: d, reason: collision with root package name */
    private j6.a f226d;

    /* renamed from: e, reason: collision with root package name */
    private List f227e;

    /* renamed from: f, reason: collision with root package name */
    private d f228f;

    /* renamed from: g, reason: collision with root package name */
    private i6.e f229g;

    /* renamed from: h, reason: collision with root package name */
    private boolean f230h;

    /* renamed from: i, reason: collision with root package name */
    private BroadcastReceiver.PendingResult f231i;

    public i(Context context, androidx.work.a aVar, j6.a aVar2) {
        this(context, aVar, aVar2, context.getResources().getBoolean(q.f53257a));
    }

    /* JADX WARN: Code restructure failed: missing block: B:13:0x0016, code lost:
    
        r4 = r4.getApplicationContext();
     */
    /* JADX WARN: Code restructure failed: missing block: B:14:0x001c, code lost:
    
        if (a6.i.f221l != null) goto L15;
     */
    /* JADX WARN: Code restructure failed: missing block: B:15:0x001e, code lost:
    
        a6.i.f221l = new a6.i(r4, r5, new j6.b(r5.l()));
     */
    /* JADX WARN: Code restructure failed: missing block: B:16:0x002e, code lost:
    
        a6.i.f220k = a6.i.f221l;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static void f(Context context, androidx.work.a aVar) {
        synchronized (f222m) {
            i iVar = f220k;
            if (iVar != null && f221l != null) {
                throw new IllegalStateException("WorkManager is already initialized.  Did you try to initialize it manually without disabling WorkManagerInitializer? See WorkManager#initialize(Context, Configuration) or the class level Javadoc for more information.");
            }
        }
    }

    public static i n() {
        synchronized (f222m) {
            i iVar = f220k;
            if (iVar != null) {
                return iVar;
            }
            return f221l;
        }
    }

    public static i o(Context context) {
        i n10;
        synchronized (f222m) {
            n10 = n();
            if (n10 == null) {
                context.getApplicationContext();
                throw new IllegalStateException("WorkManager is not initialized properly.  You have explicitly disabled WorkManagerInitializer in your manifest, have not manually called WorkManager#initialize at this point, and your Application does not implement Configuration.Provider.");
            }
        }
        return n10;
    }

    private void v(Context context, androidx.work.a aVar, j6.a aVar2, WorkDatabase workDatabase, List list, d dVar) {
        Context applicationContext = context.getApplicationContext();
        this.f223a = applicationContext;
        this.f224b = aVar;
        this.f226d = aVar2;
        this.f225c = workDatabase;
        this.f227e = list;
        this.f228f = dVar;
        this.f229g = new i6.e(workDatabase);
        this.f230h = false;
        if (applicationContext.isDeviceProtectedStorage()) {
            throw new IllegalStateException("Cannot initialize WorkManager in direct boot mode");
        }
        this.f226d.b(new ForceStopRunnable(applicationContext, this));
    }

    public void A(String str, WorkerParameters.a aVar) {
        this.f226d.b(new i6.i(this, str, aVar));
    }

    public void B(String str) {
        this.f226d.b(new i6.k(this, str, true));
    }

    public void C(String str) {
        this.f226d.b(new i6.k(this, str, false));
    }

    @Override // z5.u
    public s a(List list) {
        if (list.isEmpty()) {
            throw new IllegalArgumentException("beginWith needs at least one OneTimeWorkRequest.");
        }
        return new g(this, list);
    }

    @Override // z5.u
    public n c(List list) {
        if (list.isEmpty()) {
            throw new IllegalArgumentException("enqueue needs at least one WorkRequest.");
        }
        return new g(this, list).a();
    }

    public n g() {
        i6.a b10 = i6.a.b(this);
        this.f226d.b(b10);
        return b10.f();
    }

    public n h(String str) {
        i6.a e10 = i6.a.e(str, this);
        this.f226d.b(e10);
        return e10.f();
    }

    public n i(String str) {
        i6.a d10 = i6.a.d(str, this, true);
        this.f226d.b(d10);
        return d10.f();
    }

    public n j(UUID uuid) {
        i6.a c10 = i6.a.c(uuid, this);
        this.f226d.b(c10);
        return c10.f();
    }

    public List k(Context context, androidx.work.a aVar, j6.a aVar2) {
        return Arrays.asList(f.a(context, this), new b6.b(context, aVar, aVar2, this));
    }

    public Context l() {
        return this.f223a;
    }

    public androidx.work.a m() {
        return this.f224b;
    }

    public i6.e p() {
        return this.f229g;
    }

    public d q() {
        return this.f228f;
    }

    public List r() {
        return this.f227e;
    }

    public WorkDatabase s() {
        return this.f225c;
    }

    public ek.d t(v vVar) {
        i6.j a10 = i6.j.a(this, vVar);
        this.f226d.c().execute(a10);
        return a10.b();
    }

    public j6.a u() {
        return this.f226d;
    }

    public void w() {
        synchronized (f222m) {
            this.f230h = true;
            BroadcastReceiver.PendingResult pendingResult = this.f231i;
            if (pendingResult != null) {
                pendingResult.finish();
                this.f231i = null;
            }
        }
    }

    public void x() {
        c6.c.a(l());
        s().O().v();
        f.b(m(), s(), r());
    }

    public void y(BroadcastReceiver.PendingResult pendingResult) {
        synchronized (f222m) {
            this.f231i = pendingResult;
            if (this.f230h) {
                pendingResult.finish();
                this.f231i = null;
            }
        }
    }

    public void z(String str) {
        A(str, null);
    }

    public i(Context context, androidx.work.a aVar, j6.a aVar2, boolean z10) {
        this(context, aVar, aVar2, WorkDatabase.E(context.getApplicationContext(), aVar2.c(), z10));
    }

    public i(Context context, androidx.work.a aVar, j6.a aVar2, WorkDatabase workDatabase) {
        Context applicationContext = context.getApplicationContext();
        z5.k.e(new k.a(aVar.j()));
        List k10 = k(applicationContext, aVar, aVar2);
        v(context, aVar, aVar2, workDatabase, k10, new d(context, aVar, aVar2, workDatabase, k10));
    }
}
