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);
}
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);
}
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());
}
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.");
}
Aggregations