package androidx.work.impl.background.systemalarm; import android.content.Context; import android.content.Intent; import androidx.annotation.NonNull; import androidx.annotation.RestrictTo; import androidx.annotation.WorkerThread; import androidx.work.Clock; import androidx.work.Logger; import androidx.work.impl.background.systemalarm.SystemAlarmDispatcher; import androidx.work.impl.constraints.WorkConstraintsTracker; import androidx.work.impl.model.WorkSpec; import androidx.work.impl.model.WorkSpecKt; import java.util.ArrayList; import java.util.List; @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP}) /* loaded from: classes.dex */ class ConstraintsCommandHandler { private static final String TAG = Logger.tagWithPrefix("ConstraintsCmdHandler"); private final Clock mClock; private final Context mContext; private final SystemAlarmDispatcher mDispatcher; private final int mStartId; private final WorkConstraintsTracker mWorkConstraintsTracker; public ConstraintsCommandHandler(@NonNull Context context, Clock clock, int i, @NonNull SystemAlarmDispatcher systemAlarmDispatcher) { this.mContext = context; this.mClock = clock; this.mStartId = i; this.mDispatcher = systemAlarmDispatcher; this.mWorkConstraintsTracker = new WorkConstraintsTracker(systemAlarmDispatcher.getWorkManager().getTrackers()); } @WorkerThread public void handleConstraintsChanged() { List scheduledWork = this.mDispatcher.getWorkManager().getWorkDatabase().workSpecDao().getScheduledWork(); ConstraintProxy.updateAll(this.mContext, scheduledWork); ArrayList arrayList = new ArrayList(scheduledWork.size()); long currentTimeMillis = this.mClock.currentTimeMillis(); for (WorkSpec workSpec : scheduledWork) { if (currentTimeMillis >= workSpec.calculateNextRunTime() && (!workSpec.hasConstraints() || this.mWorkConstraintsTracker.areAllConstraintsMet(workSpec))) { arrayList.add(workSpec); } } for (WorkSpec workSpec2 : arrayList) { String str = workSpec2.id; Intent createDelayMetIntent = CommandHandler.createDelayMetIntent(this.mContext, WorkSpecKt.generationalId(workSpec2)); Logger.get().debug(TAG, "Creating a delay_met command for workSpec with id (" + str + ")"); this.mDispatcher.getTaskExecutor().getMainThreadExecutor().execute(new SystemAlarmDispatcher.AddRunnable(this.mDispatcher, createDelayMetIntent, this.mStartId)); } } }