Add decompiled APK source code (JADX)

- 28,932 files
- Full Java source code
- Smali files
- Resources

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-02-18 14:52:23 -08:00
parent cc210a65ea
commit f9d20bb3fc
26991 changed files with 2541449 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
package androidx.work.impl.background.systemjob;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import androidx.annotation.RequiresApi;
import java.util.List;
import kotlin.jvm.internal.Intrinsics;
@RequiresApi(21)
/* loaded from: classes.dex */
final class JobScheduler21 {
public static final JobScheduler21 INSTANCE = new JobScheduler21();
private JobScheduler21() {
}
public final List<JobInfo> getAllPendingJobs(JobScheduler jobScheduler) {
Intrinsics.checkNotNullParameter(jobScheduler, "jobScheduler");
List<JobInfo> allPendingJobs = jobScheduler.getAllPendingJobs();
Intrinsics.checkNotNullExpressionValue(allPendingJobs, "jobScheduler.allPendingJobs");
return allPendingJobs;
}
}

View File

@@ -0,0 +1,5 @@
package androidx.work.impl.background.systemjob;
/* loaded from: classes.dex */
public abstract /* synthetic */ class JobScheduler34$$ExternalSyntheticApiModelOutline0 {
}

View File

@@ -0,0 +1,22 @@
package androidx.work.impl.background.systemjob;
import android.app.job.JobScheduler;
import androidx.annotation.RequiresApi;
import kotlin.jvm.internal.Intrinsics;
@RequiresApi(34)
/* loaded from: classes.dex */
final class JobScheduler34 {
public static final JobScheduler34 INSTANCE = new JobScheduler34();
private JobScheduler34() {
}
public final JobScheduler forNamespace(JobScheduler jobScheduler) {
JobScheduler forNamespace;
Intrinsics.checkNotNullParameter(jobScheduler, "jobScheduler");
forNamespace = jobScheduler.forNamespace(JobSchedulerExtKt.WORKMANAGER_NAMESPACE);
Intrinsics.checkNotNullExpressionValue(forNamespace, "jobScheduler.forNamespace(WORKMANAGER_NAMESPACE)");
return forNamespace;
}
}

View File

@@ -0,0 +1,91 @@
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, "<this>");
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<JobInfo> getSafePendingJobs(JobScheduler jobScheduler) {
Intrinsics.checkNotNullParameter(jobScheduler, "<this>");
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 = "<faulty JobScheduler failed to getPendingJobs>";
if (i >= 34) {
JobScheduler wmJobScheduler = getWmJobScheduler(context);
List<JobInfo> safePendingJobs = getSafePendingJobs(wmJobScheduler);
if (safePendingJobs != null) {
List<JobInfo> 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<JobInfo> 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<JobInfo> 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() + '.';
}
}

View File

@@ -0,0 +1,5 @@
package androidx.work.impl.background.systemjob;
/* loaded from: classes.dex */
public abstract /* synthetic */ class SystemJobInfoConverter$$ExternalSyntheticApiModelOutline0 {
}

View File

@@ -0,0 +1,5 @@
package androidx.work.impl.background.systemjob;
/* loaded from: classes.dex */
public abstract /* synthetic */ class SystemJobInfoConverter$$ExternalSyntheticApiModelOutline1 {
}

View File

@@ -0,0 +1,5 @@
package androidx.work.impl.background.systemjob;
/* loaded from: classes.dex */
public abstract /* synthetic */ class SystemJobInfoConverter$$ExternalSyntheticApiModelOutline2 {
}

View File

@@ -0,0 +1,152 @@
package androidx.work.impl.background.systemjob;
import android.annotation.SuppressLint;
import android.app.job.JobInfo;
import android.content.ComponentName;
import android.content.Context;
import android.net.NetworkRequest;
import android.os.Build;
import android.os.PersistableBundle;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import androidx.work.BackoffPolicy;
import androidx.work.Clock;
import androidx.work.Constraints;
import androidx.work.Logger;
import androidx.work.NetworkType;
import androidx.work.impl.model.WorkSpec;
import java.util.Iterator;
@RequiresApi(api = 23)
@SuppressLint({"ClassVerificationFailure"})
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
/* loaded from: classes.dex */
class SystemJobInfoConverter {
static final String EXTRA_IS_PERIODIC = "EXTRA_IS_PERIODIC";
static final String EXTRA_WORK_SPEC_GENERATION = "EXTRA_WORK_SPEC_GENERATION";
static final String EXTRA_WORK_SPEC_ID = "EXTRA_WORK_SPEC_ID";
private static final String TAG = Logger.tagWithPrefix("SystemJobInfoConverter");
private final Clock mClock;
private final boolean mMarkImportantWhileForeground;
private final ComponentName mWorkServiceComponent;
public SystemJobInfoConverter(@NonNull Context context, Clock clock, boolean z) {
this.mClock = clock;
this.mWorkServiceComponent = new ComponentName(context.getApplicationContext(), (Class<?>) SystemJobService.class);
this.mMarkImportantWhileForeground = z;
}
public JobInfo convert(WorkSpec workSpec, int i) {
String traceTag;
Constraints constraints = workSpec.constraints;
PersistableBundle persistableBundle = new PersistableBundle();
persistableBundle.putString(EXTRA_WORK_SPEC_ID, workSpec.id);
persistableBundle.putInt(EXTRA_WORK_SPEC_GENERATION, workSpec.getGeneration());
persistableBundle.putBoolean(EXTRA_IS_PERIODIC, workSpec.isPeriodic());
JobInfo.Builder extras = new JobInfo.Builder(i, this.mWorkServiceComponent).setRequiresCharging(constraints.requiresCharging()).setRequiresDeviceIdle(constraints.requiresDeviceIdle()).setExtras(persistableBundle);
NetworkRequest requiredNetworkRequest = constraints.getRequiredNetworkRequest();
int i2 = Build.VERSION.SDK_INT;
if (i2 >= 28 && requiredNetworkRequest != null) {
SystemJobInfoConverterExtKt.setRequiredNetworkRequest(extras, requiredNetworkRequest);
} else {
setRequiredNetwork(extras, constraints.getRequiredNetworkType());
}
if (!constraints.requiresDeviceIdle()) {
extras.setBackoffCriteria(workSpec.backoffDelayDuration, workSpec.backoffPolicy == BackoffPolicy.LINEAR ? 0 : 1);
}
long max = Math.max(workSpec.calculateNextRunTime() - this.mClock.currentTimeMillis(), 0L);
if (i2 <= 28) {
extras.setMinimumLatency(max);
} else if (max > 0) {
extras.setMinimumLatency(max);
} else if (!workSpec.expedited && this.mMarkImportantWhileForeground) {
extras.setImportantWhileForeground(true);
}
if (constraints.hasContentUriTriggers()) {
Iterator<Constraints.ContentUriTrigger> it = constraints.getContentUriTriggers().iterator();
while (it.hasNext()) {
extras.addTriggerContentUri(convertContentUriTrigger(it.next()));
}
extras.setTriggerContentUpdateDelay(constraints.getContentTriggerUpdateDelayMillis());
extras.setTriggerContentMaxDelay(constraints.getContentTriggerMaxDelayMillis());
}
extras.setPersisted(false);
int i3 = Build.VERSION.SDK_INT;
extras.setRequiresBatteryNotLow(constraints.requiresBatteryNotLow());
extras.setRequiresStorageNotLow(constraints.requiresStorageNotLow());
boolean z = workSpec.runAttemptCount > 0;
boolean z2 = max > 0;
if (i3 >= 31 && workSpec.expedited && !z && !z2) {
extras.setExpedited(true);
}
if (i3 >= 35 && (traceTag = workSpec.getTraceTag()) != null) {
extras.setTraceTag(traceTag);
}
return extras.build();
}
@RequiresApi(24)
private static JobInfo.TriggerContentUri convertContentUriTrigger(Constraints.ContentUriTrigger contentUriTrigger) {
return new JobInfo.TriggerContentUri(contentUriTrigger.getUri(), contentUriTrigger.isTriggeredForDescendants() ? 1 : 0);
}
public static void setRequiredNetwork(@NonNull JobInfo.Builder builder, @NonNull NetworkType networkType) {
if (Build.VERSION.SDK_INT >= 30 && networkType == NetworkType.TEMPORARILY_UNMETERED) {
builder.setRequiredNetwork(new NetworkRequest.Builder().addCapability(25).build());
} else {
builder.setRequiredNetworkType(convertNetworkType(networkType));
}
}
/* renamed from: androidx.work.impl.background.systemjob.SystemJobInfoConverter$1, reason: invalid class name */
public static /* synthetic */ class AnonymousClass1 {
static final /* synthetic */ int[] $SwitchMap$androidx$work$NetworkType;
static {
int[] iArr = new int[NetworkType.values().length];
$SwitchMap$androidx$work$NetworkType = iArr;
try {
iArr[NetworkType.NOT_REQUIRED.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$androidx$work$NetworkType[NetworkType.CONNECTED.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
$SwitchMap$androidx$work$NetworkType[NetworkType.UNMETERED.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
try {
$SwitchMap$androidx$work$NetworkType[NetworkType.NOT_ROAMING.ordinal()] = 4;
} catch (NoSuchFieldError unused4) {
}
try {
$SwitchMap$androidx$work$NetworkType[NetworkType.METERED.ordinal()] = 5;
} catch (NoSuchFieldError unused5) {
}
}
}
public static int convertNetworkType(NetworkType networkType) {
int i = AnonymousClass1.$SwitchMap$androidx$work$NetworkType[networkType.ordinal()];
if (i == 1) {
return 0;
}
if (i == 2) {
return 1;
}
if (i == 3) {
return 2;
}
if (i == 4) {
return 3;
}
if (i == 5) {
return 4;
}
Logger.get().debug(TAG, "API version too low. Cannot convert network type value " + networkType);
return 1;
}
}

View File

@@ -0,0 +1,15 @@
package androidx.work.impl.background.systemjob;
import android.app.job.JobInfo;
import android.net.NetworkRequest;
import androidx.annotation.RequiresApi;
import kotlin.jvm.internal.Intrinsics;
@RequiresApi(28)
/* loaded from: classes.dex */
public final class SystemJobInfoConverterExtKt {
public static final void setRequiredNetworkRequest(JobInfo.Builder builder, NetworkRequest networkRequest) {
Intrinsics.checkNotNullParameter(builder, "builder");
builder.setRequiredNetwork(networkRequest);
}
}

View File

@@ -0,0 +1,250 @@
package androidx.work.impl.background.systemjob;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.content.ComponentName;
import android.content.Context;
import android.os.Build;
import android.os.PersistableBundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import androidx.annotation.VisibleForTesting;
import androidx.core.util.Consumer;
import androidx.work.Configuration;
import androidx.work.Logger;
import androidx.work.OutOfQuotaPolicy;
import androidx.work.WorkInfo;
import androidx.work.impl.Scheduler;
import androidx.work.impl.WorkDatabase;
import androidx.work.impl.model.SystemIdInfo;
import androidx.work.impl.model.SystemIdInfoKt;
import androidx.work.impl.model.WorkGenerationalId;
import androidx.work.impl.model.WorkSpec;
import androidx.work.impl.model.WorkSpecDao;
import androidx.work.impl.model.WorkSpecKt;
import androidx.work.impl.utils.IdGenerator;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@RequiresApi(23)
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
/* loaded from: classes.dex */
public class SystemJobScheduler implements Scheduler {
private static final String TAG = Logger.tagWithPrefix("SystemJobScheduler");
private final Configuration mConfiguration;
private final Context mContext;
private final JobScheduler mJobScheduler;
private final SystemJobInfoConverter mSystemJobInfoConverter;
private final WorkDatabase mWorkDatabase;
@Override // androidx.work.impl.Scheduler
public boolean hasLimitedSchedulingSlots() {
return true;
}
public SystemJobScheduler(@NonNull Context context, @NonNull WorkDatabase workDatabase, @NonNull Configuration configuration) {
this(context, workDatabase, configuration, JobSchedulerExtKt.getWmJobScheduler(context), new SystemJobInfoConverter(context, configuration.getClock(), configuration.isMarkingJobsAsImportantWhileForeground()));
}
@VisibleForTesting
public SystemJobScheduler(@NonNull Context context, @NonNull WorkDatabase workDatabase, @NonNull Configuration configuration, @NonNull JobScheduler jobScheduler, @NonNull SystemJobInfoConverter systemJobInfoConverter) {
this.mContext = context;
this.mJobScheduler = jobScheduler;
this.mSystemJobInfoConverter = systemJobInfoConverter;
this.mWorkDatabase = workDatabase;
this.mConfiguration = configuration;
}
@Override // androidx.work.impl.Scheduler
public void schedule(@NonNull WorkSpec... workSpecArr) {
IdGenerator idGenerator = new IdGenerator(this.mWorkDatabase);
for (WorkSpec workSpec : workSpecArr) {
this.mWorkDatabase.beginTransaction();
try {
WorkSpec workSpec2 = this.mWorkDatabase.workSpecDao().getWorkSpec(workSpec.id);
if (workSpec2 == null) {
Logger.get().warning(TAG, "Skipping scheduling " + workSpec.id + " because it's no longer in the DB");
this.mWorkDatabase.setTransactionSuccessful();
} else if (workSpec2.state != WorkInfo.State.ENQUEUED) {
Logger.get().warning(TAG, "Skipping scheduling " + workSpec.id + " because it is no longer enqueued");
this.mWorkDatabase.setTransactionSuccessful();
} else {
WorkGenerationalId generationalId = WorkSpecKt.generationalId(workSpec);
SystemIdInfo systemIdInfo = this.mWorkDatabase.systemIdInfoDao().getSystemIdInfo(generationalId);
int nextJobSchedulerIdWithRange = systemIdInfo != null ? systemIdInfo.systemId : idGenerator.nextJobSchedulerIdWithRange(this.mConfiguration.getMinJobSchedulerId(), this.mConfiguration.getMaxJobSchedulerId());
if (systemIdInfo == null) {
this.mWorkDatabase.systemIdInfoDao().insertSystemIdInfo(SystemIdInfoKt.systemIdInfo(generationalId, nextJobSchedulerIdWithRange));
}
scheduleInternal(workSpec, nextJobSchedulerIdWithRange);
this.mWorkDatabase.setTransactionSuccessful();
}
} finally {
this.mWorkDatabase.endTransaction();
}
}
}
@VisibleForTesting
public void scheduleInternal(@NonNull WorkSpec workSpec, int i) {
JobInfo convert = this.mSystemJobInfoConverter.convert(workSpec, i);
Logger logger = Logger.get();
String str = TAG;
logger.debug(str, "Scheduling work ID " + workSpec.id + "Job ID " + i);
try {
if (this.mJobScheduler.schedule(convert) == 0) {
Logger.get().warning(str, "Unable to schedule work ID " + workSpec.id);
if (workSpec.expedited && workSpec.outOfQuotaPolicy == OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST) {
workSpec.expedited = false;
Logger.get().debug(str, String.format("Scheduling a non-expedited job (work ID %s)", workSpec.id));
scheduleInternal(workSpec, i);
}
}
} catch (IllegalStateException e) {
String createErrorMessage = JobSchedulerExtKt.createErrorMessage(this.mContext, this.mWorkDatabase, this.mConfiguration);
Logger.get().error(TAG, createErrorMessage);
IllegalStateException illegalStateException = new IllegalStateException(createErrorMessage, e);
Consumer<Throwable> schedulingExceptionHandler = this.mConfiguration.getSchedulingExceptionHandler();
if (schedulingExceptionHandler != null) {
schedulingExceptionHandler.accept(illegalStateException);
return;
}
throw illegalStateException;
} catch (Throwable th) {
Logger.get().error(TAG, "Unable to schedule " + workSpec, th);
}
}
@Override // androidx.work.impl.Scheduler
public void cancel(@NonNull String str) {
List<Integer> pendingJobIds = getPendingJobIds(this.mContext, this.mJobScheduler, str);
if (pendingJobIds == null || pendingJobIds.isEmpty()) {
return;
}
Iterator<Integer> it = pendingJobIds.iterator();
while (it.hasNext()) {
cancelJobById(this.mJobScheduler, it.next().intValue());
}
this.mWorkDatabase.systemIdInfoDao().removeSystemIdInfo(str);
}
private static void cancelJobById(@NonNull JobScheduler jobScheduler, int i) {
try {
jobScheduler.cancel(i);
} catch (Throwable th) {
Logger.get().error(TAG, String.format(Locale.getDefault(), "Exception while trying to cancel job (%d)", Integer.valueOf(i)), th);
}
}
public static void cancelAllInAllNamespaces(@NonNull Context context) {
if (Build.VERSION.SDK_INT >= 34) {
JobSchedulerExtKt.getWmJobScheduler(context).cancelAll();
}
JobScheduler jobScheduler = (JobScheduler) context.getSystemService("jobscheduler");
List<JobInfo> pendingJobs = getPendingJobs(context, jobScheduler);
if (pendingJobs == null || pendingJobs.isEmpty()) {
return;
}
Iterator<JobInfo> it = pendingJobs.iterator();
while (it.hasNext()) {
cancelJobById(jobScheduler, it.next().getId());
}
}
public static boolean reconcileJobs(@NonNull Context context, @NonNull WorkDatabase workDatabase) {
JobScheduler wmJobScheduler = JobSchedulerExtKt.getWmJobScheduler(context);
List<JobInfo> pendingJobs = getPendingJobs(context, wmJobScheduler);
List<String> workSpecIds = workDatabase.systemIdInfoDao().getWorkSpecIds();
boolean z = false;
HashSet hashSet = new HashSet(pendingJobs != null ? pendingJobs.size() : 0);
if (pendingJobs != null && !pendingJobs.isEmpty()) {
for (JobInfo jobInfo : pendingJobs) {
WorkGenerationalId workGenerationalIdFromJobInfo = getWorkGenerationalIdFromJobInfo(jobInfo);
if (workGenerationalIdFromJobInfo != null) {
hashSet.add(workGenerationalIdFromJobInfo.getWorkSpecId());
} else {
cancelJobById(wmJobScheduler, jobInfo.getId());
}
}
}
Iterator<String> it = workSpecIds.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
if (!hashSet.contains(it.next())) {
Logger.get().debug(TAG, "Reconciling jobs");
z = true;
break;
}
}
if (z) {
workDatabase.beginTransaction();
try {
WorkSpecDao workSpecDao = workDatabase.workSpecDao();
Iterator<String> it2 = workSpecIds.iterator();
while (it2.hasNext()) {
workSpecDao.markWorkSpecScheduled(it2.next(), -1L);
}
workDatabase.setTransactionSuccessful();
workDatabase.endTransaction();
} catch (Throwable th) {
workDatabase.endTransaction();
throw th;
}
}
return z;
}
@Nullable
public static List<JobInfo> getPendingJobs(@NonNull Context context, @NonNull JobScheduler jobScheduler) {
List<JobInfo> safePendingJobs = JobSchedulerExtKt.getSafePendingJobs(jobScheduler);
if (safePendingJobs == null) {
return null;
}
ArrayList arrayList = new ArrayList(safePendingJobs.size());
ComponentName componentName = new ComponentName(context, (Class<?>) SystemJobService.class);
for (JobInfo jobInfo : safePendingJobs) {
if (componentName.equals(jobInfo.getService())) {
arrayList.add(jobInfo);
}
}
return arrayList;
}
@Nullable
private static List<Integer> getPendingJobIds(@NonNull Context context, @NonNull JobScheduler jobScheduler, @NonNull String str) {
List<JobInfo> pendingJobs = getPendingJobs(context, jobScheduler);
if (pendingJobs == null) {
return null;
}
ArrayList arrayList = new ArrayList(2);
for (JobInfo jobInfo : pendingJobs) {
WorkGenerationalId workGenerationalIdFromJobInfo = getWorkGenerationalIdFromJobInfo(jobInfo);
if (workGenerationalIdFromJobInfo != null && str.equals(workGenerationalIdFromJobInfo.getWorkSpecId())) {
arrayList.add(Integer.valueOf(jobInfo.getId()));
}
}
return arrayList;
}
@Nullable
private static WorkGenerationalId getWorkGenerationalIdFromJobInfo(@NonNull JobInfo jobInfo) {
PersistableBundle extras = jobInfo.getExtras();
if (extras == null) {
return null;
}
try {
if (!extras.containsKey("EXTRA_WORK_SPEC_ID")) {
return null;
}
return new WorkGenerationalId(extras.getString("EXTRA_WORK_SPEC_ID"), extras.getInt("EXTRA_WORK_SPEC_GENERATION", 0));
} catch (NullPointerException unused) {
return null;
}
}
}

View File

@@ -0,0 +1,211 @@
package androidx.work.impl.background.systemjob;
import android.app.Application;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.net.Network;
import android.net.Uri;
import android.os.Build;
import android.os.Looper;
import android.os.PersistableBundle;
import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import androidx.work.Logger;
import androidx.work.WorkInfo;
import androidx.work.WorkerParameters;
import androidx.work.impl.ExecutionListener;
import androidx.work.impl.Processor;
import androidx.work.impl.StartStopToken;
import androidx.work.impl.StartStopTokens;
import androidx.work.impl.WorkLauncher;
import androidx.work.impl.WorkLauncherImpl;
import androidx.work.impl.WorkManagerImpl;
import androidx.work.impl.model.WorkGenerationalId;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@RequiresApi(23)
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
/* loaded from: classes.dex */
public class SystemJobService extends JobService implements ExecutionListener {
private static final String TAG = Logger.tagWithPrefix("SystemJobService");
private final Map<WorkGenerationalId, JobParameters> mJobParameters = new HashMap();
private final StartStopTokens mStartStopTokens = StartStopTokens.create(false);
private WorkLauncher mWorkLauncher;
private WorkManagerImpl mWorkManagerImpl;
public static int stopReason(int i) {
switch (i) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
return i;
default:
return WorkInfo.STOP_REASON_UNKNOWN;
}
}
@Override // android.app.Service
public void onCreate() {
super.onCreate();
try {
WorkManagerImpl workManagerImpl = WorkManagerImpl.getInstance(getApplicationContext());
this.mWorkManagerImpl = workManagerImpl;
Processor processor = workManagerImpl.getProcessor();
this.mWorkLauncher = new WorkLauncherImpl(processor, this.mWorkManagerImpl.getWorkTaskExecutor());
processor.addExecutionListener(this);
} catch (IllegalStateException e) {
if (!Application.class.equals(getApplication().getClass())) {
throw new IllegalStateException("WorkManager needs to be initialized via a ContentProvider#onCreate() or an Application#onCreate().", e);
}
Logger.get().warning(TAG, "Could not find WorkManager instance; this may be because an auto-backup is in progress. Ignoring JobScheduler commands for now. Please make sure that you are initializing WorkManager if you have manually disabled WorkManagerInitializer.");
}
}
@Override // android.app.Service
public void onDestroy() {
super.onDestroy();
WorkManagerImpl workManagerImpl = this.mWorkManagerImpl;
if (workManagerImpl != null) {
workManagerImpl.getProcessor().removeExecutionListener(this);
}
}
@Override // android.app.job.JobService
public boolean onStartJob(@NonNull JobParameters jobParameters) {
assertMainThread("onStartJob");
if (this.mWorkManagerImpl == null) {
Logger.get().debug(TAG, "WorkManager is not initialized; requesting retry.");
jobFinished(jobParameters, true);
return false;
}
WorkGenerationalId workGenerationalIdFromJobParameters = workGenerationalIdFromJobParameters(jobParameters);
if (workGenerationalIdFromJobParameters == null) {
Logger.get().error(TAG, "WorkSpec id not found!");
return false;
}
if (this.mJobParameters.containsKey(workGenerationalIdFromJobParameters)) {
Logger.get().debug(TAG, "Job is already being executed by SystemJobService: " + workGenerationalIdFromJobParameters);
return false;
}
Logger.get().debug(TAG, "onStartJob for " + workGenerationalIdFromJobParameters);
this.mJobParameters.put(workGenerationalIdFromJobParameters, jobParameters);
int i = Build.VERSION.SDK_INT;
WorkerParameters.RuntimeExtras runtimeExtras = new WorkerParameters.RuntimeExtras();
if (Api24Impl.getTriggeredContentUris(jobParameters) != null) {
runtimeExtras.triggeredContentUris = Arrays.asList(Api24Impl.getTriggeredContentUris(jobParameters));
}
if (Api24Impl.getTriggeredContentAuthorities(jobParameters) != null) {
runtimeExtras.triggeredContentAuthorities = Arrays.asList(Api24Impl.getTriggeredContentAuthorities(jobParameters));
}
if (i >= 28) {
runtimeExtras.network = Api28Impl.getNetwork(jobParameters);
}
this.mWorkLauncher.startWork(this.mStartStopTokens.tokenFor(workGenerationalIdFromJobParameters), runtimeExtras);
return true;
}
@Override // android.app.job.JobService
public boolean onStopJob(@NonNull JobParameters jobParameters) {
assertMainThread("onStopJob");
if (this.mWorkManagerImpl == null) {
Logger.get().debug(TAG, "WorkManager is not initialized; requesting retry.");
return true;
}
WorkGenerationalId workGenerationalIdFromJobParameters = workGenerationalIdFromJobParameters(jobParameters);
if (workGenerationalIdFromJobParameters == null) {
Logger.get().error(TAG, "WorkSpec id not found!");
return false;
}
Logger.get().debug(TAG, "onStopJob for " + workGenerationalIdFromJobParameters);
this.mJobParameters.remove(workGenerationalIdFromJobParameters);
StartStopToken remove = this.mStartStopTokens.remove(workGenerationalIdFromJobParameters);
if (remove != null) {
this.mWorkLauncher.stopWorkWithReason(remove, Build.VERSION.SDK_INT >= 31 ? Api31Impl.getStopReason(jobParameters) : WorkInfo.STOP_REASON_UNKNOWN);
}
return !this.mWorkManagerImpl.getProcessor().isCancelled(workGenerationalIdFromJobParameters.getWorkSpecId());
}
@Override // androidx.work.impl.ExecutionListener
@MainThread
public void onExecuted(@NonNull WorkGenerationalId workGenerationalId, boolean z) {
assertMainThread("onExecuted");
Logger.get().debug(TAG, workGenerationalId.getWorkSpecId() + " executed on JobScheduler");
JobParameters remove = this.mJobParameters.remove(workGenerationalId);
this.mStartStopTokens.remove(workGenerationalId);
if (remove != null) {
jobFinished(remove, z);
}
}
@Nullable
private static WorkGenerationalId workGenerationalIdFromJobParameters(@NonNull JobParameters jobParameters) {
try {
PersistableBundle extras = jobParameters.getExtras();
if (extras == null || !extras.containsKey("EXTRA_WORK_SPEC_ID")) {
return null;
}
return new WorkGenerationalId(extras.getString("EXTRA_WORK_SPEC_ID"), extras.getInt("EXTRA_WORK_SPEC_GENERATION"));
} catch (NullPointerException unused) {
return null;
}
}
@RequiresApi(24)
public static class Api24Impl {
private Api24Impl() {
}
public static Uri[] getTriggeredContentUris(JobParameters jobParameters) {
return jobParameters.getTriggeredContentUris();
}
public static String[] getTriggeredContentAuthorities(JobParameters jobParameters) {
return jobParameters.getTriggeredContentAuthorities();
}
}
@RequiresApi(28)
public static class Api28Impl {
private Api28Impl() {
}
public static Network getNetwork(JobParameters jobParameters) {
return jobParameters.getNetwork();
}
}
@RequiresApi(31)
public static class Api31Impl {
private Api31Impl() {
}
public static int getStopReason(JobParameters jobParameters) {
return SystemJobService.stopReason(jobParameters.getStopReason());
}
}
private static void assertMainThread(String str) {
if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
return;
}
throw new IllegalStateException("Cannot invoke " + str + " on a background thread");
}
}

View File

@@ -0,0 +1,5 @@
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
package androidx.work.impl.background.systemjob;
import androidx.annotation.RestrictTo;