Search in sources :

Example 1 with Constraints

use of androidx.work.Constraints in project AntennaPod by AntennaPod.

the class SyncService method getWorkRequest.

private static OneTimeWorkRequest.Builder getWorkRequest() {
    Constraints.Builder constraints = new Constraints.Builder();
    if (UserPreferences.isAllowMobileFeedRefresh()) {
        constraints.setRequiredNetworkType(NetworkType.CONNECTED);
    } else {
        constraints.setRequiredNetworkType(NetworkType.UNMETERED);
    }
    OneTimeWorkRequest.Builder builder = new OneTimeWorkRequest.Builder(SyncService.class).setConstraints(constraints.build()).setBackoffCriteria(BackoffPolicy.EXPONENTIAL, 10, TimeUnit.MINUTES);
    if (isCurrentlyActive) {
        // Debounce: don't start sync again immediately after it was finished.
        builder.setInitialDelay(2L, TimeUnit.MINUTES);
    } else {
        // Give it some time, so other possible actions can be queued.
        builder.setInitialDelay(20L, TimeUnit.SECONDS);
        EventBus.getDefault().postSticky(new SyncServiceEvent(R.string.sync_status_started));
    }
    return builder;
}
Also used : Constraints(androidx.work.Constraints) SyncServiceEvent(de.danoeh.antennapod.event.SyncServiceEvent) OneTimeWorkRequest(androidx.work.OneTimeWorkRequest)

Example 2 with Constraints

use of androidx.work.Constraints in project ExoPlayer by google.

the class WorkManagerScheduler method schedule.

@Override
public boolean schedule(Requirements requirements, String servicePackage, String serviceAction) {
    Constraints constraints = buildConstraints(requirements);
    Data inputData = buildInputData(requirements, servicePackage, serviceAction);
    OneTimeWorkRequest workRequest = buildWorkRequest(constraints, inputData);
    workManager.enqueueUniqueWork(workName, ExistingWorkPolicy.REPLACE, workRequest);
    return true;
}
Also used : Constraints(androidx.work.Constraints) Data(androidx.work.Data) OneTimeWorkRequest(androidx.work.OneTimeWorkRequest)

Example 3 with Constraints

use of androidx.work.Constraints in project ExoPlayer by google.

the class WorkManagerScheduler method buildConstraints.

private static Constraints buildConstraints(Requirements requirements) {
    Requirements filteredRequirements = requirements.filterRequirements(SUPPORTED_REQUIREMENTS);
    if (!filteredRequirements.equals(requirements)) {
        Log.w(TAG, "Ignoring unsupported requirements: " + (filteredRequirements.getRequirements() ^ requirements.getRequirements()));
    }
    Constraints.Builder builder = new Constraints.Builder();
    if (requirements.isUnmeteredNetworkRequired()) {
        builder.setRequiredNetworkType(NetworkType.UNMETERED);
    } else if (requirements.isNetworkRequired()) {
        builder.setRequiredNetworkType(NetworkType.CONNECTED);
    } else {
        builder.setRequiredNetworkType(NetworkType.NOT_REQUIRED);
    }
    if (Util.SDK_INT >= 23 && requirements.isIdleRequired()) {
        setRequiresDeviceIdle(builder);
    }
    if (requirements.isChargingRequired()) {
        builder.setRequiresCharging(true);
    }
    if (requirements.isStorageNotLowRequired()) {
        builder.setRequiresStorageNotLow(true);
    }
    return builder.build();
}
Also used : Constraints(androidx.work.Constraints) Requirements(com.google.android.exoplayer2.scheduler.Requirements)

Example 4 with Constraints

use of androidx.work.Constraints in project OneSignal-Android-SDK by OneSignal.

the class OSReceiveReceiptController method beginEnqueueingWork.

void beginEnqueueingWork(Context context, String osNotificationId) {
    if (!remoteParamController.isReceiveReceiptEnabled()) {
        OneSignal.Log(OneSignal.LOG_LEVEL.DEBUG, "sendReceiveReceipt disabled");
        return;
    }
    int delay = OSUtils.getRandomDelay(minDelay, maxDelay);
    Data inputData = new Data.Builder().putString(OS_NOTIFICATION_ID, osNotificationId).build();
    Constraints constraints = buildConstraints();
    OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(ReceiveReceiptWorker.class).setConstraints(constraints).setInitialDelay(delay, TimeUnit.SECONDS).setInputData(inputData).build();
    OneSignal.Log(OneSignal.LOG_LEVEL.DEBUG, "OSReceiveReceiptController enqueueing send receive receipt work with notificationId: " + osNotificationId + " and delay: " + delay + " seconds");
    WorkManager.getInstance(context).enqueueUniqueWork(osNotificationId + "_receive_receipt", ExistingWorkPolicy.KEEP, workRequest);
}
Also used : Constraints(androidx.work.Constraints) Data(androidx.work.Data) OneTimeWorkRequest(androidx.work.OneTimeWorkRequest)

Aggregations

Constraints (androidx.work.Constraints)4 OneTimeWorkRequest (androidx.work.OneTimeWorkRequest)3 Data (androidx.work.Data)2 Requirements (com.google.android.exoplayer2.scheduler.Requirements)1 SyncServiceEvent (de.danoeh.antennapod.event.SyncServiceEvent)1