Search in sources :

Example 11 with OneTimeWorkRequest

use of androidx.work.OneTimeWorkRequest 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)

Example 12 with OneTimeWorkRequest

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

the class OSNotificationWorkManager method beginEnqueueingWork.

static void beginEnqueueingWork(Context context, String osNotificationId, int androidNotificationId, String jsonPayload, long timestamp, boolean isRestoring, boolean isHighPriority) {
    // TODO: Need to figure out how to implement the isHighPriority param
    Data inputData = new Data.Builder().putInt(ANDROID_NOTIF_ID_WORKER_DATA_PARAM, androidNotificationId).putString(JSON_PAYLOAD_WORKER_DATA_PARAM, jsonPayload).putLong(TIMESTAMP_WORKER_DATA_PARAM, timestamp).putBoolean(IS_RESTORING_WORKER_DATA_PARAM, isRestoring).build();
    OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(NotificationWorker.class).setInputData(inputData).build();
    OneSignal.Log(OneSignal.LOG_LEVEL.DEBUG, "OSNotificationWorkManager enqueueing notification work with notificationId: " + osNotificationId + " and jsonPayload: " + jsonPayload);
    WorkManager.getInstance(context).enqueueUniqueWork(osNotificationId, ExistingWorkPolicy.KEEP, workRequest);
}
Also used : Data(androidx.work.Data) OneTimeWorkRequest(androidx.work.OneTimeWorkRequest)

Example 13 with OneTimeWorkRequest

use of androidx.work.OneTimeWorkRequest in project fdroidclient by f-droid.

the class CleanCacheWorkerTest method testWorkRequest.

@Test
public void testWorkRequest() throws ExecutionException, InterruptedException {
    OneTimeWorkRequest request = new OneTimeWorkRequest.Builder(CleanCacheWorker.class).build();
    workManagerTestRule.workManager.enqueue(request).getResult();
    ListenableFuture<WorkInfo> workInfo = workManagerTestRule.workManager.getWorkInfoById(request.getId());
    assertEquals(WorkInfo.State.SUCCEEDED, workInfo.get().getState());
}
Also used : WorkInfo(androidx.work.WorkInfo) OneTimeWorkRequest(androidx.work.OneTimeWorkRequest) Test(org.junit.Test) FileCompatTest(org.fdroid.fdroid.compat.FileCompatTest) LargeTest(androidx.test.filters.LargeTest)

Example 14 with OneTimeWorkRequest

use of androidx.work.OneTimeWorkRequest in project fdroidclient by f-droid.

the class CleanCacheWorker method force.

/**
 * Force a cache cleanup.  Since {@link #deleteOldInstallerFiles(Context)}
 * only deletes files older than an hour, any ongoing APK install processes
 * should not have their APKs are deleted out from under them.
 */
public static void force(@NonNull final Context context) {
    OneTimeWorkRequest cleanCache = new OneTimeWorkRequest.Builder(CleanCacheWorker.class).build();
    WorkManager workManager = WorkManager.getInstance(context);
    workManager.enqueueUniqueWork(TAG + ".force", ExistingWorkPolicy.KEEP, cleanCache);
    Utils.debugLog(TAG, "Enqueued forced run for cleaning the cache.");
}
Also used : WorkManager(androidx.work.WorkManager) OneTimeWorkRequest(androidx.work.OneTimeWorkRequest)

Aggregations

OneTimeWorkRequest (androidx.work.OneTimeWorkRequest)14 Data (androidx.work.Data)3 LargeTest (androidx.test.filters.LargeTest)2 Constraints (androidx.work.Constraints)2 WorkInfo (androidx.work.WorkInfo)2 WorkManager (androidx.work.WorkManager)2 Test (org.junit.Test)2 JobProxyIllegalStateException (com.evernote.android.job.JobProxyIllegalStateException)1 FeedUpdateWorker (de.danoeh.antennapod.core.service.FeedUpdateWorker)1 Calendar (java.util.Calendar)1 FileCompatTest (org.fdroid.fdroid.compat.FileCompatTest)1