Skip to content

Commit e97b114

Browse files
errorcodeQQerrorcodeQQ
authored andcommitted
fix: Persist Global Strict mode across app restarts
1 parent 520001a commit e97b114

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

CSGuard/src/main/kotlin/com/csguard/AllowlistStore.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ object AllowlistStore {
1212
private const val PREFS_NAME = "csguard_allowlist"
1313
private const val KEY_ALWAYS = "always_allow_hosts"
1414
private const val KEY_BLOCKED_PROVIDERS = "blocked_providers"
15+
private const val KEY_GLOBAL_STRICT = "global_strict"
1516
private const val KEY_BLOCKED = "blocked_attempts_log"
1617
private const val MAX_BLOCKED_LOG = 200
1718

@@ -52,6 +53,14 @@ fun alwaysAllow(): Set<String> {
5253
return true
5354
}
5455

56+
fun isGlobalStrict(): Boolean {
57+
return prefs?.getBoolean(KEY_GLOBAL_STRICT, true) ?: true
58+
}
59+
60+
fun setGlobalStrict(strict: Boolean) {
61+
prefs?.edit()?.putBoolean(KEY_GLOBAL_STRICT, strict)?.apply()
62+
}
63+
5564
fun blockedProviders(): Set<String> {
5665
val raw = prefs?.getString(KEY_BLOCKED_PROVIDERS, "[]") ?: "[]"
5766
return try {

CSGuard/src/main/kotlin/com/csguard/CSGuardPlugin.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,16 @@ try {
7474
Log.w(TAG, "VideoClickAction sanitization failed", t)
7575
}
7676

77-
try {
78-
ProviderSanitizer.policy = GuardPolicy.STRICT
77+
try {
78+
val isStrict = AllowlistStore.isGlobalStrict()
79+
ProviderSanitizer.policy = GuardPolicy(
80+
blockKnownAdHosts = true,
81+
blockAdPaths = true,
82+
blockAllUnknown = isStrict,
83+
showToast = false
84+
)
7985
ProviderSanitizer.start(context)
80-
Log.i(TAG, "✓ Started ProviderSanitizer (interval=5s, policy=STRICT)")
86+
Log.i(TAG, "✓ Started ProviderSanitizer (policy.blockAllUnknown=$isStrict)")
8187
} catch (t: Throwable) {
8288
Log.e(TAG, "Failed to start ProviderSanitizer", t)
8389
}

CSGuard/src/main/kotlin/com/csguard/GuardSettingsDialog.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class GuardSettingsDialog(
9595
val currentBlocks = AllowlistStore.blockedProviders()
9696
currentBlocks.forEach { AllowlistStore.removeBlockedProvider(it) }
9797
blockedSet.forEach { AllowlistStore.addBlockedProvider(it) }
98+
99+
AllowlistStore.setGlobalStrict(isGlobalStrict)
98100

99101
val newPolicy = GuardPolicy(
100102
blockKnownAdHosts = true,

0 commit comments

Comments
 (0)