Files
rr3-apk/decompiled/sources/androidx/work/impl/WorkerWrapper.java
Daniel Elliott f9d20bb3fc 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>
2026-02-18 14:52:23 -08:00

463 lines
20 KiB
Java

package androidx.work.impl;
import android.annotation.SuppressLint;
import android.content.Context;
import androidx.annotation.RestrictTo;
import androidx.annotation.VisibleForTesting;
import androidx.work.Clock;
import androidx.work.Configuration;
import androidx.work.Data;
import androidx.work.ListenableFutureKt;
import androidx.work.ListenableWorker;
import androidx.work.Logger;
import androidx.work.WorkInfo;
import androidx.work.WorkerParameters;
import androidx.work.impl.foreground.ForegroundProcessor;
import androidx.work.impl.model.DependencyDao;
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.taskexecutor.TaskExecutor;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.List;
import java.util.concurrent.Callable;
import kotlin.collections.CollectionsKt__CollectionsKt;
import kotlin.collections.CollectionsKt__MutableCollectionsKt;
import kotlin.collections.CollectionsKt___CollectionsKt;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.SourceDebugExtension;
import kotlinx.coroutines.CompletableJob;
import kotlinx.coroutines.CoroutineDispatcher;
import kotlinx.coroutines.JobKt__JobKt;
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
@SourceDebugExtension({"SMAP\nWorkerWrapper.kt\nKotlin\n*S Kotlin\n*F\n+ 1 WorkerWrapper.kt\nandroidx/work/impl/WorkerWrapper\n+ 2 LoggerExt.kt\nandroidx/work/LoggerExtKt\n*L\n1#1,607:1\n29#2:608\n29#2:609\n27#2:610\n32#2:611\n19#2:612\n19#2:613\n24#2:614\n24#2:615\n24#2:616\n24#2:617\n19#2:618\n*S KotlinDebug\n*F\n+ 1 WorkerWrapper.kt\nandroidx/work/impl/WorkerWrapper\n*L\n206#1:608\n240#1:609\n315#1:610\n318#1:611\n354#1:612\n367#1:613\n374#1:614\n381#1:615\n384#1:616\n477#1:617\n151#1:618\n*E\n"})
/* loaded from: classes.dex */
public final class WorkerWrapper {
private final Context appContext;
private final ListenableWorker builderWorker;
private final Clock clock;
private final Configuration configuration;
private final DependencyDao dependencyDao;
private final ForegroundProcessor foregroundProcessor;
private final WorkerParameters.RuntimeExtras runtimeExtras;
private final List<String> tags;
private final WorkDatabase workDatabase;
private final String workDescription;
private final WorkSpec workSpec;
private final WorkSpecDao workSpecDao;
private final String workSpecId;
private final TaskExecutor workTaskExecutor;
private final CompletableJob workerJob;
public final WorkSpec getWorkSpec() {
return this.workSpec;
}
public WorkerWrapper(Builder builder) {
CompletableJob Job$default;
Intrinsics.checkNotNullParameter(builder, "builder");
WorkSpec workSpec = builder.getWorkSpec();
this.workSpec = workSpec;
this.appContext = builder.getAppContext();
this.workSpecId = workSpec.id;
this.runtimeExtras = builder.getRuntimeExtras();
this.builderWorker = builder.getWorker();
this.workTaskExecutor = builder.getWorkTaskExecutor();
Configuration configuration = builder.getConfiguration();
this.configuration = configuration;
this.clock = configuration.getClock();
this.foregroundProcessor = builder.getForegroundProcessor();
WorkDatabase workDatabase = builder.getWorkDatabase();
this.workDatabase = workDatabase;
this.workSpecDao = workDatabase.workSpecDao();
this.dependencyDao = workDatabase.dependencyDao();
List<String> tags = builder.getTags();
this.tags = tags;
this.workDescription = createWorkDescription(tags);
Job$default = JobKt__JobKt.Job$default(null, 1, null);
this.workerJob = Job$default;
}
public final WorkGenerationalId getWorkGenerationalId() {
return WorkSpecKt.generationalId(this.workSpec);
}
public final ListenableFuture launch() {
CompletableJob Job$default;
CoroutineDispatcher taskCoroutineDispatcher = this.workTaskExecutor.getTaskCoroutineDispatcher();
Job$default = JobKt__JobKt.Job$default(null, 1, null);
return ListenableFutureKt.launchFuture$default(taskCoroutineDispatcher.plus(Job$default), null, new WorkerWrapper$launch$1(this, null), 2, null);
}
public static abstract class Resolution {
public /* synthetic */ Resolution(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public static final class ResetWorkerStatus extends Resolution {
private final int reason;
public ResetWorkerStatus() {
this(0, 1, null);
}
public final int getReason() {
return this.reason;
}
public ResetWorkerStatus(int i) {
super(null);
this.reason = i;
}
public /* synthetic */ ResetWorkerStatus(int i, int i2, DefaultConstructorMarker defaultConstructorMarker) {
this((i2 & 1) != 0 ? -256 : i);
}
}
private Resolution() {
}
public static final class Failed extends Resolution {
private final ListenableWorker.Result result;
/* JADX WARN: Multi-variable type inference failed */
public Failed() {
this(null, 1, 0 == true ? 1 : 0);
}
public final ListenableWorker.Result getResult() {
return this.result;
}
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
public Failed(ListenableWorker.Result result) {
super(null);
Intrinsics.checkNotNullParameter(result, "result");
this.result = result;
}
public /* synthetic */ Failed(ListenableWorker.Result result, int i, DefaultConstructorMarker defaultConstructorMarker) {
this((i & 1) != 0 ? new ListenableWorker.Result.Failure() : result);
}
}
public static final class Finished extends Resolution {
private final ListenableWorker.Result result;
public final ListenableWorker.Result getResult() {
return this.result;
}
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
public Finished(ListenableWorker.Result result) {
super(null);
Intrinsics.checkNotNullParameter(result, "result");
this.result = result;
}
}
}
/* JADX INFO: Access modifiers changed from: private */
/* JADX WARN: Multi-variable type inference failed */
/* JADX WARN: Removed duplicated region for block: B:22:0x0230 */
/* JADX WARN: Removed duplicated region for block: B:27:0x0045 */
/* JADX WARN: Removed duplicated region for block: B:8:0x0028 */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public final java.lang.Object runWorker(kotlin.coroutines.Continuation r24) {
/*
Method dump skipped, instructions count: 615
To view this dump add '--comments-level debug' option
*/
throw new UnsupportedOperationException("Method not decompiled: androidx.work.impl.WorkerWrapper.runWorker(kotlin.coroutines.Continuation):java.lang.Object");
}
/* JADX INFO: Access modifiers changed from: private */
public static final Boolean runWorker$lambda$1(WorkerWrapper workerWrapper) {
String str;
String str2;
WorkSpec workSpec = workerWrapper.workSpec;
if (workSpec.state != WorkInfo.State.ENQUEUED) {
str2 = WorkerWrapperKt.TAG;
Logger.get().debug(str2, workerWrapper.workSpec.workerClassName + " is not in ENQUEUED state. Nothing more to do");
return Boolean.TRUE;
}
if ((!workSpec.isPeriodic() && !workerWrapper.workSpec.isBackedOff()) || workerWrapper.clock.currentTimeMillis() >= workerWrapper.workSpec.calculateNextRunTime()) {
return Boolean.FALSE;
}
Logger logger = Logger.get();
str = WorkerWrapperKt.TAG;
logger.debug(str, "Delaying execution for " + workerWrapper.workSpec.workerClassName + " because it is being executed before schedule.");
return Boolean.TRUE;
}
/* JADX INFO: Access modifiers changed from: private */
public final boolean onWorkFinished(ListenableWorker.Result result) {
WorkInfo.State state = this.workSpecDao.getState(this.workSpecId);
this.workDatabase.workProgressDao().delete(this.workSpecId);
if (state == null) {
return false;
}
if (state == WorkInfo.State.RUNNING) {
return handleResult(result);
}
if (state.isFinished()) {
return false;
}
return reschedule(WorkInfo.STOP_REASON_UNKNOWN);
}
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
public final void interrupt(int i) {
this.workerJob.cancel(new WorkerStoppedException(i));
}
/* JADX INFO: Access modifiers changed from: private */
public final boolean resetWorkerStatus(int i) {
String str;
String str2;
WorkInfo.State state = this.workSpecDao.getState(this.workSpecId);
if (state == null || state.isFinished()) {
str = WorkerWrapperKt.TAG;
Logger.get().debug(str, "Status for " + this.workSpecId + " is " + state + " ; not doing any work");
return false;
}
str2 = WorkerWrapperKt.TAG;
Logger.get().debug(str2, "Status for " + this.workSpecId + " is " + state + "; not doing any work and rescheduling for later execution");
this.workSpecDao.setState(WorkInfo.State.ENQUEUED, this.workSpecId);
this.workSpecDao.setStopReason(this.workSpecId, i);
this.workSpecDao.markWorkSpecScheduled(this.workSpecId, -1L);
return true;
}
private final boolean handleResult(ListenableWorker.Result result) {
String str;
String str2;
String str3;
if (result instanceof ListenableWorker.Result.Success) {
str3 = WorkerWrapperKt.TAG;
Logger.get().info(str3, "Worker result SUCCESS for " + this.workDescription);
return this.workSpec.isPeriodic() ? resetPeriodic() : setSucceeded(result);
}
if (result instanceof ListenableWorker.Result.Retry) {
str2 = WorkerWrapperKt.TAG;
Logger.get().info(str2, "Worker result RETRY for " + this.workDescription);
return reschedule(-256);
}
str = WorkerWrapperKt.TAG;
Logger.get().info(str, "Worker result FAILURE for " + this.workDescription);
if (this.workSpec.isPeriodic()) {
return resetPeriodic();
}
if (result == null) {
result = new ListenableWorker.Result.Failure();
}
return setFailed(result);
}
private final boolean trySetRunning() {
Object runInTransaction = this.workDatabase.runInTransaction((Callable<Object>) new Callable() { // from class: androidx.work.impl.WorkerWrapper$$ExternalSyntheticLambda1
@Override // java.util.concurrent.Callable
public final Object call() {
Boolean trySetRunning$lambda$11;
trySetRunning$lambda$11 = WorkerWrapper.trySetRunning$lambda$11(WorkerWrapper.this);
return trySetRunning$lambda$11;
}
});
Intrinsics.checkNotNullExpressionValue(runInTransaction, "workDatabase.runInTransa…e\n }\n )");
return ((Boolean) runInTransaction).booleanValue();
}
/* JADX INFO: Access modifiers changed from: private */
public static final Boolean trySetRunning$lambda$11(WorkerWrapper workerWrapper) {
boolean z;
if (workerWrapper.workSpecDao.getState(workerWrapper.workSpecId) == WorkInfo.State.ENQUEUED) {
workerWrapper.workSpecDao.setState(WorkInfo.State.RUNNING, workerWrapper.workSpecId);
workerWrapper.workSpecDao.incrementWorkSpecRunAttemptCount(workerWrapper.workSpecId);
workerWrapper.workSpecDao.setStopReason(workerWrapper.workSpecId, -256);
z = true;
} else {
z = false;
}
return Boolean.valueOf(z);
}
@VisibleForTesting
public final boolean setFailed(ListenableWorker.Result result) {
Intrinsics.checkNotNullParameter(result, "result");
iterativelyFailWorkAndDependents(this.workSpecId);
Data outputData = ((ListenableWorker.Result.Failure) result).getOutputData();
Intrinsics.checkNotNullExpressionValue(outputData, "failure.outputData");
this.workSpecDao.resetWorkSpecNextScheduleTimeOverride(this.workSpecId, this.workSpec.getNextScheduleTimeOverrideGeneration());
this.workSpecDao.setOutput(this.workSpecId, outputData);
return false;
}
private final void iterativelyFailWorkAndDependents(String str) {
List mutableListOf;
Object removeLast;
mutableListOf = CollectionsKt__CollectionsKt.mutableListOf(str);
while (!mutableListOf.isEmpty()) {
removeLast = CollectionsKt__MutableCollectionsKt.removeLast(mutableListOf);
String str2 = (String) removeLast;
if (this.workSpecDao.getState(str2) != WorkInfo.State.CANCELLED) {
this.workSpecDao.setState(WorkInfo.State.FAILED, str2);
}
mutableListOf.addAll(this.dependencyDao.getDependentWorkIds(str2));
}
}
private final boolean reschedule(int i) {
this.workSpecDao.setState(WorkInfo.State.ENQUEUED, this.workSpecId);
this.workSpecDao.setLastEnqueueTime(this.workSpecId, this.clock.currentTimeMillis());
this.workSpecDao.resetWorkSpecNextScheduleTimeOverride(this.workSpecId, this.workSpec.getNextScheduleTimeOverrideGeneration());
this.workSpecDao.markWorkSpecScheduled(this.workSpecId, -1L);
this.workSpecDao.setStopReason(this.workSpecId, i);
return true;
}
private final boolean resetPeriodic() {
this.workSpecDao.setLastEnqueueTime(this.workSpecId, this.clock.currentTimeMillis());
this.workSpecDao.setState(WorkInfo.State.ENQUEUED, this.workSpecId);
this.workSpecDao.resetWorkSpecRunAttemptCount(this.workSpecId);
this.workSpecDao.resetWorkSpecNextScheduleTimeOverride(this.workSpecId, this.workSpec.getNextScheduleTimeOverrideGeneration());
this.workSpecDao.incrementPeriodCount(this.workSpecId);
this.workSpecDao.markWorkSpecScheduled(this.workSpecId, -1L);
return false;
}
private final boolean setSucceeded(ListenableWorker.Result result) {
String str;
this.workSpecDao.setState(WorkInfo.State.SUCCEEDED, this.workSpecId);
Intrinsics.checkNotNull(result, "null cannot be cast to non-null type androidx.work.ListenableWorker.Result.Success");
Data outputData = ((ListenableWorker.Result.Success) result).getOutputData();
Intrinsics.checkNotNullExpressionValue(outputData, "success.outputData");
this.workSpecDao.setOutput(this.workSpecId, outputData);
long currentTimeMillis = this.clock.currentTimeMillis();
for (String str2 : this.dependencyDao.getDependentWorkIds(this.workSpecId)) {
if (this.workSpecDao.getState(str2) == WorkInfo.State.BLOCKED && this.dependencyDao.hasCompletedAllPrerequisites(str2)) {
str = WorkerWrapperKt.TAG;
Logger.get().info(str, "Setting status to enqueued for " + str2);
this.workSpecDao.setState(WorkInfo.State.ENQUEUED, str2);
this.workSpecDao.setLastEnqueueTime(str2, currentTimeMillis);
}
}
return false;
}
private final String createWorkDescription(List<String> list) {
String joinToString$default;
StringBuilder sb = new StringBuilder();
sb.append("Work [ id=");
sb.append(this.workSpecId);
sb.append(", tags={ ");
joinToString$default = CollectionsKt___CollectionsKt.joinToString$default(list, ",", null, null, 0, null, null, 62, null);
sb.append(joinToString$default);
sb.append(" } ]");
return sb.toString();
}
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
public static final class Builder {
private final Context appContext;
private final Configuration configuration;
private final ForegroundProcessor foregroundProcessor;
private WorkerParameters.RuntimeExtras runtimeExtras;
private final List<String> tags;
private final WorkDatabase workDatabase;
private final WorkSpec workSpec;
private final TaskExecutor workTaskExecutor;
private ListenableWorker worker;
public final Context getAppContext() {
return this.appContext;
}
public final Configuration getConfiguration() {
return this.configuration;
}
public final ForegroundProcessor getForegroundProcessor() {
return this.foregroundProcessor;
}
public final WorkerParameters.RuntimeExtras getRuntimeExtras() {
return this.runtimeExtras;
}
public final List<String> getTags() {
return this.tags;
}
public final WorkDatabase getWorkDatabase() {
return this.workDatabase;
}
public final WorkSpec getWorkSpec() {
return this.workSpec;
}
public final TaskExecutor getWorkTaskExecutor() {
return this.workTaskExecutor;
}
public final ListenableWorker getWorker() {
return this.worker;
}
public final void setRuntimeExtras(WorkerParameters.RuntimeExtras runtimeExtras) {
Intrinsics.checkNotNullParameter(runtimeExtras, "<set-?>");
this.runtimeExtras = runtimeExtras;
}
public final void setWorker(ListenableWorker listenableWorker) {
this.worker = listenableWorker;
}
public final Builder withRuntimeExtras(WorkerParameters.RuntimeExtras runtimeExtras) {
if (runtimeExtras != null) {
this.runtimeExtras = runtimeExtras;
}
return this;
}
@VisibleForTesting
public final Builder withWorker(ListenableWorker worker) {
Intrinsics.checkNotNullParameter(worker, "worker");
this.worker = worker;
return this;
}
@SuppressLint({"LambdaLast"})
public Builder(Context context, Configuration configuration, TaskExecutor workTaskExecutor, ForegroundProcessor foregroundProcessor, WorkDatabase workDatabase, WorkSpec workSpec, List<String> tags) {
Intrinsics.checkNotNullParameter(context, "context");
Intrinsics.checkNotNullParameter(configuration, "configuration");
Intrinsics.checkNotNullParameter(workTaskExecutor, "workTaskExecutor");
Intrinsics.checkNotNullParameter(foregroundProcessor, "foregroundProcessor");
Intrinsics.checkNotNullParameter(workDatabase, "workDatabase");
Intrinsics.checkNotNullParameter(workSpec, "workSpec");
Intrinsics.checkNotNullParameter(tags, "tags");
this.configuration = configuration;
this.workTaskExecutor = workTaskExecutor;
this.foregroundProcessor = foregroundProcessor;
this.workDatabase = workDatabase;
this.workSpec = workSpec;
this.tags = tags;
Context applicationContext = context.getApplicationContext();
Intrinsics.checkNotNullExpressionValue(applicationContext, "context.applicationContext");
this.appContext = applicationContext;
this.runtimeExtras = new WorkerParameters.RuntimeExtras();
}
public final WorkerWrapper build() {
return new WorkerWrapper(this);
}
}
}