summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAayush Gupta <theimpulson@e.email>2022-07-18 05:25:55 +0000
committerAayush Gupta <theimpulson@e.email>2022-07-18 05:25:55 +0000
commit4a18a3431515897a679518a10b097bab021ad8b0 (patch)
tree5b2f4dcb8f9a0ea90564d23107a43b95990d5bac /app/src/main
parent6f845c22a55134d60fdb7710f5c4795e3dea8108 (diff)
parent1a17057ac33dfe608360d2b6f27e92334541c04b (diff)
Merge branch '5619-main-update_tracker_list' into 'main'
advancedPrivacy: Fetch list on 1st start and update it weekly See merge request e/os/advanced-privacy!75
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt15
1 files changed, 10 insertions, 5 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt b/app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt
index ba6bae9..c83d8f9 100644
--- a/app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt
+++ b/app/src/main/java/foundation/e/privacycentralapp/UpdateTrackersWorker.kt
@@ -18,12 +18,14 @@
package foundation.e.privacycentralapp
import android.content.Context
+import androidx.work.Constraints
import androidx.work.CoroutineWorker
import androidx.work.ExistingPeriodicWorkPolicy
+import androidx.work.NetworkType
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.WorkerParameters
-import java.time.temporal.ChronoUnit
+import java.util.concurrent.TimeUnit
class UpdateTrackersWorker(appContext: Context, workerParams: WorkerParameters) :
CoroutineWorker(appContext, workerParams) {
@@ -37,15 +39,18 @@ class UpdateTrackersWorker(appContext: Context, workerParams: WorkerParameters)
}
companion object {
+ private val constraints = Constraints.Builder()
+ .setRequiredNetworkType(NetworkType.CONNECTED)
+ .build()
+
fun periodicUpdate(context: Context) {
val request = PeriodicWorkRequestBuilder<UpdateTrackersWorker>(
- ChronoUnit.WEEKS.duration,
- ChronoUnit.DAYS.duration
- ).build()
+ 7, TimeUnit.DAYS)
+ .setConstraints(constraints).build()
WorkManager.getInstance(context).enqueueUniquePeriodicWork(
UpdateTrackersWorker::class.qualifiedName ?: "",
- ExistingPeriodicWorkPolicy.REPLACE,
+ ExistingPeriodicWorkPolicy.KEEP,
request
)
}