Skip to content

Ensure blocklist is updated always #5989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ class AppTrackerListUpdateWorker(context: Context, workerParameters: WorkerParam
vpnDatabase.vpnAppTrackerBlockingDao().getTrackerBlocklistMetadata()?.eTag
val updatedEtag = blocklist.etag.value

if (updatedEtag == currentEtag) {
logcat { "Downloaded blocklist has same eTag, noop" }
return Result.success()
}

logcat { "Updating the app tracker blocklist, eTag: ${blocklist.etag.value}" }
logcat { "Updating the app tracker blocklist, previous/new eTag: $currentEtag / $updatedEtag}" }

vpnDatabase
.vpnAppTrackerBlockingDao()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ class ExceptionListsSettingStore @Inject constructor(
override fun store(jsonString: String) {
logcat { "Received configuration: $jsonString" }
runCatching {
jsonAdapter.fromJson(jsonString)?.let { model ->

val exceptionLists = model.exceptionLists
jsonAdapter.fromJson(jsonString)?.exceptionLists?.let { exceptionLists ->

val appTrackerExceptionRuleList = exceptionLists.appTrackerAllowList.map { appTrackerAllowRule ->
AppTrackerExceptionRule(
Expand All @@ -78,7 +76,7 @@ class ExceptionListsSettingStore @Inject constructor(
}

private data class JsonConfigModel(
val exceptionLists: JsonExceptionListsModel,
val exceptionLists: JsonExceptionListsModel?,
)

private data class JsonExceptionListsModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ class ExceptionListsSettingStoreTest {

@Test
fun whenEmptyJsonStoreNothing() {
exceptionListsSettingStore.store("{}")
verifyNoInteractions(mockVpnDatabase)
}

@Test
fun whenInvalidJsonStoreNothingAndDoNotCrash() {
exceptionListsSettingStore.store("")
verifyNoInteractions(mockVpnDatabase)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ interface VpnAppTrackerBlockingDao {
@Insert
fun setTrackerBlocklistMetadata(appTrackerMetadata: AppTrackerMetadata)

@Query("DELETE from vpn_app_tracker_blocking_list_metadata")
fun deleteTrackerBlocklistMetadata()

@Query("DELETE from vpn_app_tracker_blocking_list")
fun deleteTrackerBlockList()

Expand All @@ -63,6 +66,7 @@ interface VpnAppTrackerBlockingDao {
metadata: AppTrackerMetadata,
entities: List<AppTrackerEntity>,
) {
deleteTrackerBlocklistMetadata()
setTrackerBlocklistMetadata(metadata)

deleteTrackerBlockList()
Expand Down
Loading