-
Notifications
You must be signed in to change notification settings - Fork 928
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove embedded dataset and add worker to download data
- Loading branch information
1 parent
39d1235
commit 39c4f03
Showing
12 changed files
with
390 additions
and
470,353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...com/duckduckgo/malicioussiteprotection/impl/MaliciousSiteProtectionFiltersUpdateWorker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright (c) 2025 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.malicioussiteprotection.impl | ||
|
||
import android.content.Context | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.work.BackoffPolicy | ||
import androidx.work.CoroutineWorker | ||
import androidx.work.ExistingPeriodicWorkPolicy | ||
import androidx.work.PeriodicWorkRequestBuilder | ||
import androidx.work.WorkManager | ||
import androidx.work.WorkerParameters | ||
import com.duckduckgo.anvil.annotations.ContributesWorker | ||
import com.duckduckgo.app.lifecycle.MainProcessLifecycleObserver | ||
import com.duckduckgo.common.utils.DispatcherProvider | ||
import com.duckduckgo.di.scopes.AppScope | ||
import com.duckduckgo.malicioussiteprotection.impl.data.MaliciousSiteRepository | ||
import com.squareup.anvil.annotations.ContributesMultibinding | ||
import dagger.SingleInstanceIn | ||
import java.util.concurrent.TimeUnit | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.withContext | ||
import timber.log.Timber | ||
|
||
@ContributesWorker(AppScope::class) | ||
class MaliciousSiteProtectionFiltersUpdateWorker( | ||
context: Context, | ||
workerParameters: WorkerParameters, | ||
) : CoroutineWorker(context, workerParameters) { | ||
@Inject | ||
lateinit var maliciousSiteRepository: MaliciousSiteRepository | ||
|
||
@Inject | ||
lateinit var dispatcherProvider: DispatcherProvider | ||
|
||
@Inject | ||
lateinit var maliciousSiteProtectionFeature: MaliciousSiteProtectionRCFeature | ||
|
||
override suspend fun doWork(): Result { | ||
return withContext(dispatcherProvider.io()) { | ||
Timber.v("Cris. Executing MSP worker") | ||
if (maliciousSiteProtectionFeature.isFeatureEnabled().not()) { | ||
return@withContext Result.success() | ||
} | ||
try { | ||
maliciousSiteRepository.loadFilters() | ||
return@withContext Result.success() | ||
} catch (e: Exception) { | ||
return@withContext Result.retry() | ||
} | ||
} | ||
} | ||
} | ||
|
||
@ContributesMultibinding( | ||
scope = AppScope::class, | ||
boundType = MainProcessLifecycleObserver::class, | ||
) | ||
@SingleInstanceIn(AppScope::class) | ||
class MaliciousSiteProtectionFiltersUpdateWorkerScheduler @Inject constructor( | ||
private val workManager: WorkManager, | ||
private val maliciousSiteProtectionFeature: MaliciousSiteProtectionRCFeature, | ||
|
||
) : MainProcessLifecycleObserver { | ||
|
||
override fun onCreate(owner: LifecycleOwner) { | ||
Timber.v("Cris. SchedulingMSP worker") | ||
val workerRequest = PeriodicWorkRequestBuilder<MaliciousSiteProtectionFiltersUpdateWorker>( | ||
maliciousSiteProtectionFeature.getFilterSetUpdateFrequency(), | ||
TimeUnit.MINUTES, | ||
) | ||
.addTag(MALICIOUS_SITE_PROTECTION_FILTERS_UPDATE_WORKER_TAG) | ||
.setBackoffCriteria(BackoffPolicy.EXPONENTIAL, 1, TimeUnit.MINUTES) | ||
.build() | ||
workManager.enqueueUniquePeriodicWork(MALICIOUS_SITE_PROTECTION_FILTERS_UPDATE_WORKER_TAG, ExistingPeriodicWorkPolicy.UPDATE, workerRequest) | ||
} | ||
|
||
companion object { | ||
private const val MALICIOUS_SITE_PROTECTION_FILTERS_UPDATE_WORKER_TAG = "MALICIOUS_SITE_PROTECTION_FILTERS_UPDATE_WORKER_TAG" | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...uckduckgo/malicioussiteprotection/impl/MaliciousSiteProtectionHashPrefixesUpdateWorker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (c) 2025 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.malicioussiteprotection.impl | ||
|
||
import android.content.Context | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.work.BackoffPolicy | ||
import androidx.work.CoroutineWorker | ||
import androidx.work.ExistingPeriodicWorkPolicy | ||
import androidx.work.PeriodicWorkRequestBuilder | ||
import androidx.work.WorkManager | ||
import androidx.work.WorkerParameters | ||
import com.duckduckgo.anvil.annotations.ContributesWorker | ||
import com.duckduckgo.app.lifecycle.MainProcessLifecycleObserver | ||
import com.duckduckgo.common.utils.DispatcherProvider | ||
import com.duckduckgo.di.scopes.AppScope | ||
import com.duckduckgo.malicioussiteprotection.impl.data.MaliciousSiteRepository | ||
import com.squareup.anvil.annotations.ContributesMultibinding | ||
import dagger.SingleInstanceIn | ||
import java.util.concurrent.TimeUnit | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.withContext | ||
import timber.log.Timber | ||
|
||
@ContributesWorker(AppScope::class) | ||
class MaliciousSiteProtectionHashPrefixesUpdateWorker( | ||
context: Context, | ||
workerParameters: WorkerParameters, | ||
) : CoroutineWorker(context, workerParameters) { | ||
@Inject | ||
lateinit var maliciousSiteRepository: MaliciousSiteRepository | ||
|
||
@Inject | ||
lateinit var dispatcherProvider: DispatcherProvider | ||
|
||
@Inject | ||
lateinit var maliciousSiteProtectionFeature: MaliciousSiteProtectionRCFeature | ||
|
||
override suspend fun doWork(): Result { | ||
return withContext(dispatcherProvider.io()) { | ||
Timber.v("Cris. Executing MSP worker") | ||
if (maliciousSiteProtectionFeature.isFeatureEnabled().not()) { | ||
return@withContext Result.success() | ||
} | ||
try { | ||
maliciousSiteRepository.loadHashPrefixes() | ||
return@withContext Result.success() | ||
} catch (e: Exception) { | ||
return@withContext Result.retry() | ||
} | ||
} | ||
} | ||
} | ||
|
||
@ContributesMultibinding( | ||
scope = AppScope::class, | ||
boundType = MainProcessLifecycleObserver::class, | ||
) | ||
@SingleInstanceIn(AppScope::class) | ||
class MaliciousSiteProtectionHashPrefixesUpdateWorkerScheduler @Inject constructor( | ||
private val workManager: WorkManager, | ||
private val maliciousSiteProtectionFeature: MaliciousSiteProtectionRCFeature, | ||
|
||
) : MainProcessLifecycleObserver { | ||
|
||
override fun onCreate(owner: LifecycleOwner) { | ||
Timber.v("Cris. SchedulingMSP worker") | ||
val workerRequest = PeriodicWorkRequestBuilder<MaliciousSiteProtectionHashPrefixesUpdateWorker>( | ||
maliciousSiteProtectionFeature.getHashPrefixUpdateFrequency(), | ||
TimeUnit.MINUTES, | ||
) | ||
.addTag(MALICIOUS_SITE_PROTECTION_HASH_PREFIXES_UPDATE_WORKER_TAG) | ||
.setBackoffCriteria(BackoffPolicy.EXPONENTIAL, 1, TimeUnit.MINUTES) | ||
.build() | ||
workManager.enqueueUniquePeriodicWork( | ||
MALICIOUS_SITE_PROTECTION_HASH_PREFIXES_UPDATE_WORKER_TAG, | ||
ExistingPeriodicWorkPolicy.UPDATE, | ||
workerRequest, | ||
) | ||
} | ||
|
||
companion object { | ||
private const val MALICIOUS_SITE_PROTECTION_HASH_PREFIXES_UPDATE_WORKER_TAG = "MALICIOUS_SITE_PROTECTION_HASH_PREFIXES_UPDATE_WORKER_TAG" | ||
} | ||
} |
Oops, something went wrong.