Add more frequent auto-updates on unmetered networks

This commit is contained in:
xynngh 2020-05-06 17:39:59 +04:00
parent 731c35434e
commit 146acd4483
1 changed files with 16 additions and 0 deletions

View File

@ -36,6 +36,7 @@ public class UpdateScheduler {
Constraints constraints = new Constraints.Builder() Constraints constraints = new Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED) .setRequiredNetworkType(NetworkType.CONNECTED)
.setRequiresBatteryNotLow(true)
.build(); .build();
PeriodicWorkRequest updateRequest = PeriodicWorkRequest updateRequest =
@ -45,6 +46,21 @@ public class UpdateScheduler {
.build(); .build();
getWorkManager().enqueue(updateRequest); getWorkManager().enqueue(updateRequest);
constraints = new Constraints.Builder()
.setRequiredNetworkType(NetworkType.UNMETERED)
.setRequiresBatteryNotLow(true)
.setRequiresDeviceIdle(true)
.build();
updateRequest =
new PeriodicWorkRequest.Builder(UpdateWorker.class, 6, TimeUnit.HOURS)
.addTag(AUTO_UPDATE_WORK_TAG)
.setInitialDelay(6, TimeUnit.HOURS)
.setConstraints(constraints)
.build();
getWorkManager().enqueue(updateRequest);
} }
public void cancelAutoUpdateWorker() { public void cancelAutoUpdateWorker() {