package androidx.work.impl.background.systemjob; import android.app.job.JobInfo; import android.app.job.JobScheduler; import android.content.Context; import android.os.Build; import androidx.annotation.RequiresApi; import androidx.work.Configuration; import androidx.work.Logger; import androidx.work.impl.WorkDatabase; import com.ironsource.mediationsdk.utils.IronSourceConstants; import java.util.List; import kotlin.collections.CollectionsKt__CollectionsKt; import kotlin.collections.CollectionsKt___CollectionsKt; import kotlin.jvm.internal.Intrinsics; import kotlin.jvm.internal.SourceDebugExtension; @SourceDebugExtension({"SMAP\nJobSchedulerExt.kt\nKotlin\n*S Kotlin\n*F\n+ 1 JobSchedulerExt.kt\nandroidx/work/impl/background/systemjob/JobSchedulerExtKt\n+ 2 LoggerExt.kt\nandroidx/work/LoggerExtKt\n*L\n1#1,127:1\n32#2:128\n*S KotlinDebug\n*F\n+ 1 JobSchedulerExt.kt\nandroidx/work/impl/background/systemjob/JobSchedulerExtKt\n*L\n70#1:128\n*E\n"}) /* loaded from: classes.dex */ public final class JobSchedulerExtKt { private static final String TAG; public static final String WORKMANAGER_NAMESPACE = "androidx.work.systemjobscheduler"; static { String tagWithPrefix = Logger.tagWithPrefix("SystemJobScheduler"); Intrinsics.checkNotNullExpressionValue(tagWithPrefix, "tagWithPrefix(\"SystemJobScheduler\")"); TAG = tagWithPrefix; } @RequiresApi(21) public static final JobScheduler getWmJobScheduler(Context context) { Intrinsics.checkNotNullParameter(context, ""); Object systemService = context.getSystemService("jobscheduler"); Intrinsics.checkNotNull(systemService, "null cannot be cast to non-null type android.app.job.JobScheduler"); JobScheduler jobScheduler = (JobScheduler) systemService; return Build.VERSION.SDK_INT >= 34 ? JobScheduler34.INSTANCE.forNamespace(jobScheduler) : jobScheduler; } @RequiresApi(21) public static final List getSafePendingJobs(JobScheduler jobScheduler) { Intrinsics.checkNotNullParameter(jobScheduler, ""); try { return JobScheduler21.INSTANCE.getAllPendingJobs(jobScheduler); } catch (Throwable th) { Logger.get().error(TAG, "getAllPendingJobs() is not reliable on this device.", th); return null; } } @RequiresApi(23) public static final String createErrorMessage(Context context, WorkDatabase workDatabase, Configuration configuration) { String str; List listOfNotNull; Intrinsics.checkNotNullParameter(context, "context"); Intrinsics.checkNotNullParameter(workDatabase, "workDatabase"); Intrinsics.checkNotNullParameter(configuration, "configuration"); int i = Build.VERSION.SDK_INT; int i2 = i >= 31 ? IronSourceConstants.REWARDED_VIDEO_DAILY_CAPPED : 100; int size = workDatabase.workSpecDao().getScheduledWork().size(); String str2 = ""; if (i >= 34) { JobScheduler wmJobScheduler = getWmJobScheduler(context); List safePendingJobs = getSafePendingJobs(wmJobScheduler); if (safePendingJobs != null) { List pendingJobs = SystemJobScheduler.getPendingJobs(context, wmJobScheduler); int size2 = pendingJobs != null ? safePendingJobs.size() - pendingJobs.size() : 0; String str3 = null; if (size2 == 0) { str = null; } else { str = size2 + " of which are not owned by WorkManager"; } Object systemService = context.getSystemService("jobscheduler"); Intrinsics.checkNotNull(systemService, "null cannot be cast to non-null type android.app.job.JobScheduler"); List pendingJobs2 = SystemJobScheduler.getPendingJobs(context, (JobScheduler) systemService); int size3 = pendingJobs2 != null ? pendingJobs2.size() : 0; if (size3 != 0) { str3 = size3 + " from WorkManager in the default namespace"; } listOfNotNull = CollectionsKt__CollectionsKt.listOfNotNull(safePendingJobs.size() + " jobs in \"androidx.work.systemjobscheduler\" namespace", str, str3); str2 = CollectionsKt___CollectionsKt.joinToString$default(listOfNotNull, ",\n", null, null, 0, null, null, 62, null); } } else { List pendingJobs3 = SystemJobScheduler.getPendingJobs(context, getWmJobScheduler(context)); if (pendingJobs3 != null) { str2 = pendingJobs3.size() + " jobs from WorkManager"; } } return "JobScheduler " + i2 + " job limit exceeded.\nIn JobScheduler there are " + str2 + ".\nThere are " + size + " jobs tracked by WorkManager's database;\nthe Configuration limit is " + configuration.getMaxSchedulerLimit() + '.'; } }