use of androidx.work.PeriodicWorkRequest in project android-job by evernote.
the class JobProxyWorkManager method plantPeriodic.
@Override
public void plantPeriodic(JobRequest request) {
PeriodicWorkRequest workRequest = new PeriodicWorkRequest.Builder(PlatformWorker.class, request.getIntervalMs(), TimeUnit.MILLISECONDS, request.getFlexMs(), TimeUnit.MILLISECONDS).setConstraints(buildConstraints(request)).addTag(createTag(request.getJobId())).build();
WorkManager workManager = getWorkManager();
if (workManager == null) {
throw new JobProxyIllegalStateException("WorkManager is null");
}
workManager.enqueue(workRequest);
}
use of androidx.work.PeriodicWorkRequest in project AntennaPod by AntennaPod.
the class AutoUpdateManager method restartUpdateIntervalAlarm.
/**
* Sets the interval in which the feeds are refreshed automatically
*/
private static void restartUpdateIntervalAlarm(long intervalMillis, Context context) {
Log.d(TAG, "Restarting update alarm.");
PeriodicWorkRequest workRequest = new PeriodicWorkRequest.Builder(FeedUpdateWorker.class, intervalMillis, TimeUnit.MILLISECONDS).setConstraints(getConstraints()).build();
WorkManager.getInstance(context).enqueueUniquePeriodicWork(WORK_ID_FEED_UPDATE, ExistingPeriodicWorkPolicy.REPLACE, workRequest);
}
use of androidx.work.PeriodicWorkRequest in project fdroidclient by f-droid.
the class FDroidMetricsWorker method schedule.
/**
* Schedule or cancel a work request to update the app index, according to the
* current preferences. It is meant to run weekly, so it will schedule one week
* from the last run. If it has never been run, it will run as soon as possible.
* <p>
* Although {@link Constraints.Builder#setRequiresDeviceIdle(boolean)} is available
* down to {@link Build.VERSION_CODES#M}, it will cause {@code UpdateService} to
* rarely run, if ever on some devices. So {@link Constraints.Builder#setRequiresDeviceIdle(boolean)}
* should only be used in conjunction with
* {@link Constraints.Builder#setTriggerContentMaxDelay(long, TimeUnit)} to ensure
* that updates actually happen regularly.
*/
public static void schedule(final Context context) {
final WorkManager workManager = WorkManager.getInstance(context);
long interval = TimeUnit.DAYS.toMillis(7);
final Constraints.Builder constraintsBuilder = new Constraints.Builder().setRequiresCharging(true).setRequiresBatteryNotLow(true);
// TODO use the Data/WiFi preferences here
if (Build.VERSION.SDK_INT >= 24) {
constraintsBuilder.setTriggerContentMaxDelay(interval, TimeUnit.MILLISECONDS);
constraintsBuilder.setRequiresDeviceIdle(true);
}
final PeriodicWorkRequest cleanCache = new PeriodicWorkRequest.Builder(FDroidMetricsWorker.class, interval, TimeUnit.MILLISECONDS).setConstraints(constraintsBuilder.build()).build();
workManager.enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.REPLACE, cleanCache);
Utils.debugLog(TAG, "Scheduled periodic work");
}
use of androidx.work.PeriodicWorkRequest in project fdroidclient by f-droid.
the class CleanCacheWorker method schedule.
/**
* Schedule or cancel a work request to clean up caches, according to the
* current preferences. Should be called a) at boot, b) if the preference
* is changed, or c) on startup, in case we get upgraded.
*/
public static void schedule(@NonNull final Context context) {
final WorkManager workManager = WorkManager.getInstance(context);
final long keepTime = Preferences.get().getKeepCacheTime();
long interval = TimeUnit.DAYS.toMillis(1);
if (keepTime < interval) {
interval = keepTime;
}
final Constraints.Builder constraintsBuilder = new Constraints.Builder().setRequiresCharging(true).setRequiresBatteryNotLow(true);
if (Build.VERSION.SDK_INT >= 23) {
constraintsBuilder.setRequiresDeviceIdle(true);
}
final PeriodicWorkRequest cleanCache = new PeriodicWorkRequest.Builder(CleanCacheWorker.class, interval, TimeUnit.MILLISECONDS).setConstraints(constraintsBuilder.build()).build();
workManager.enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.REPLACE, cleanCache);
Utils.debugLog(TAG, "Scheduled periodic work for cleaning the cache.");
}
Aggregations