package androidx.work.impl.background.systemalarm;

import a6.i;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import androidx.work.impl.WorkDatabase;
import h6.j;
import z5.k;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public abstract class a {

    /* renamed from: a, reason: collision with root package name */
    private static final String f5928a = k.f("Alarms");

    public static void a(Context context, i iVar, String str) {
        j L = iVar.s().L();
        h6.i c10 = L.c(str);
        if (c10 != null) {
            b(context, str, c10.f20868b);
            k.c().a(f5928a, String.format("Removing SystemIdInfo for workSpecId (%s)", str), new Throwable[0]);
            L.d(str);
        }
    }

    private static void b(Context context, String str, int i10) {
        AlarmManager alarmManager = (AlarmManager) context.getSystemService("alarm");
        PendingIntent service = PendingIntent.getService(context, i10, b.b(context, str), 603979776);
        if (service == null || alarmManager == null) {
            return;
        }
        k.c().a(f5928a, String.format("Cancelling existing alarm with (workSpecId, systemId) (%s, %s)", str, Integer.valueOf(i10)), new Throwable[0]);
        alarmManager.cancel(service);
    }

    public static void c(Context context, i iVar, String str, long j10) {
        WorkDatabase s10 = iVar.s();
        j L = s10.L();
        h6.i c10 = L.c(str);
        if (c10 != null) {
            b(context, str, c10.f20868b);
            d(context, str, c10.f20868b, j10);
        } else {
            int b10 = new i6.c(s10).b();
            L.b(new h6.i(str, b10));
            d(context, str, b10, j10);
        }
    }

    private static void d(Context context, String str, int i10, long j10) {
        AlarmManager alarmManager = (AlarmManager) context.getSystemService("alarm");
        PendingIntent service = PendingIntent.getService(context, i10, b.b(context, str), 201326592);
        if (alarmManager != null) {
            alarmManager.setExact(0, j10, service);
        }
    }
}
