package o;

import android.content.Context;
import android.content.Intent;
import android.os.Looper;
import android.os.PowerManager;
import android.text.TextUtils;
import androidx.work.impl.background.systemalarm.SystemAlarmService;
import java.util.ArrayList;
import java.util.Objects;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.fc0, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C1205fc0 implements InterfaceC0645Yw {
    public static final /* synthetic */ int v = 0;
    public final Context l;
    public final C2062oc0 m;
    public final Jm0 n;

    /* renamed from: o, reason: collision with root package name */
    public final XY f526o;
    public final C2651um0 p;
    public final C1218fj q;
    public final ArrayList r;
    public Intent s;
    public SystemAlarmService t;
    public final C1390hY u;

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

    public C1205fc0(SystemAlarmService systemAlarmService) {
        Context applicationContext = systemAlarmService.getApplicationContext();
        this.l = applicationContext;
        C3031ym0 c3031ym0 = new C3031ym0(10);
        C2651um0 c2651um0H = C2651um0.H(systemAlarmService);
        C1414hl c1414hl = c2651um0H.l;
        this.p = c2651um0H;
        this.q = new C1218fj(applicationContext, (BP) c1414hl.f, c3031ym0);
        this.n = new Jm0((C0247Jn) c1414hl.i);
        XY xy = c2651um0H.p;
        this.f526o = xy;
        C2062oc0 c2062oc0 = c2651um0H.n;
        this.m = c2062oc0;
        this.u = new C1390hY(14, xy, c2062oc0);
        xy.a(this);
        this.r = new ArrayList();
        this.s = null;
    }

    public static void c() {
        if (Looper.getMainLooper().getThread() != Thread.currentThread()) {
            throw new IllegalStateException("Needs to be invoked on the main thread.");
        }
    }

    public final void a(Intent intent, int i) {
        C0669Zu c0669ZuE = C0669Zu.e();
        Objects.toString(intent);
        c0669ZuE.getClass();
        c();
        String action = intent.getAction();
        if (TextUtils.isEmpty(action)) {
            C0669Zu.e().getClass();
            return;
        }
        if ("ACTION_CONSTRAINTS_CHANGED".equals(action)) {
            c();
            synchronized (this.r) {
                try {
                    ArrayList arrayList = this.r;
                    int size = arrayList.size();
                    int i2 = 0;
                    while (i2 < size) {
                        Object obj = arrayList.get(i2);
                        i2++;
                        if ("ACTION_CONSTRAINTS_CHANGED".equals(((Intent) obj).getAction())) {
                            return;
                        }
                    }
                } finally {
                }
            }
        }
        intent.putExtra("KEY_START_ID", i);
        synchronized (this.r) {
            try {
                boolean zIsEmpty = this.r.isEmpty();
                this.r.add(intent);
                if (zIsEmpty) {
                    d();
                }
            } finally {
            }
        }
    }

    @Override // o.InterfaceC0645Yw
    public final void b(C2366rm0 c2366rm0, boolean z) {
        ExecutorC1921n20 executorC1921n20 = (ExecutorC1921n20) this.m.d;
        int i = C1218fj.q;
        Intent intent = new Intent(this.l, (Class<?>) SystemAlarmService.class);
        intent.setAction("ACTION_EXECUTION_COMPLETED");
        intent.putExtra("KEY_NEEDS_RESCHEDULE", z);
        C1218fj.d(intent, c2366rm0);
        executorC1921n20.execute(new RunnableC2786w8(0, 2, this, intent));
    }

    public final void d() {
        c();
        PowerManager.WakeLock wakeLockA = Mk0.a(this.l, "ProcessCommand");
        try {
            wakeLockA.acquire();
            this.p.n.c(new RunnableC1109ec0(this, 0));
        } finally {
            wakeLockA.release();
        }
    }
}
