From 66bf76e9b122a63fd4444503d5cd3a497ea75d53 Mon Sep 17 00:00:00 2001 From: xynngh Date: Sat, 30 Oct 2021 15:01:30 +0400 Subject: [PATCH] Schedule updates as unique work requests --- .../yetanothercallblocker/work/UpdateScheduler.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/work/UpdateScheduler.java b/app/src/main/java/dummydomain/yetanothercallblocker/work/UpdateScheduler.java index f16ab61..c467209 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/work/UpdateScheduler.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/work/UpdateScheduler.java @@ -4,6 +4,7 @@ import android.content.Context; import android.os.Build; import androidx.work.Constraints; +import androidx.work.ExistingPeriodicWorkPolicy; import androidx.work.NetworkType; import androidx.work.PeriodicWorkRequest; import androidx.work.WorkInfo; @@ -19,6 +20,8 @@ import java.util.concurrent.TimeUnit; public class UpdateScheduler { private static final String AUTO_UPDATE_WORK_TAG = "autoUpdateWork"; + private static final String MAIN_AUTO_UPDATE_WORK_NAME = "mainAutoUpdateWork"; + private static final String FREQUENT_AUTO_UPDATE_WORK_NAME = "frequentAutoUpdateWork"; private static final Logger LOG = LoggerFactory.getLogger(UpdateScheduler.class); @@ -46,7 +49,8 @@ public class UpdateScheduler { .setConstraints(constraints) .build(); - getWorkManager().enqueue(updateRequest); + getWorkManager().enqueueUniquePeriodicWork(MAIN_AUTO_UPDATE_WORK_NAME, + ExistingPeriodicWorkPolicy.REPLACE, updateRequest); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { constraints = new Constraints.Builder() @@ -62,7 +66,8 @@ public class UpdateScheduler { .setConstraints(constraints) .build(); - getWorkManager().enqueue(updateRequest); + getWorkManager().enqueueUniquePeriodicWork(FREQUENT_AUTO_UPDATE_WORK_NAME, + ExistingPeriodicWorkPolicy.REPLACE, updateRequest); } }