Remove unnecessary VPN rebuilds on network changes#541
Open
Remove unnecessary VPN rebuilds on network changes#541
Conversation
TrackerControl doesn't need to rebuild the VPN when the network type changes (WiFi/mobile/2G/3G/4G/hotspot). Unlike NetGuard, TC doesn't apply different blocking rules per network type — tracker blocking is handled dynamically in blockKnownTracker() and the VPN app routing (filter mode) uses rule.apply which is network-independent. Removed reload() calls from three network-change receivers: - connectivityChangedReceiver: no longer rebuilds VPN on WiFi/mobile switch - phoneStateListener: no longer rebuilds VPN on 2G/3G/4G generation change - apStateReceiver: no longer rebuilds VPN on hotspot state change The networkMonitorCallback (connectivity validation), idleStateReceiver, interactiveStateReceiver, and packageChangedReceiver are preserved as they serve purposes beyond network-type differentiation. https://claude.ai/code/session_01PuXevPG3gUKEXWHrgRMptV
TrackerControl always runs in filter mode, making several NetGuard mechanisms dead code: - getAllowedRules(): Removed all wifi/metered/roaming/generation/screen logic. In filter mode, listAllowed doesn't affect VPN routing (builder uses rule.apply) and mapUidAllowed is never read in isAddressAllowed(). Now simply returns all rules for the notification count. - reload() interactive check: Removed the screen_wifi/screen_other optimization that skipped reloads. TC doesn't use screen-based per-network blocking rules. - interactiveStateReceiver: Removed VPN rebuild on screen on/off. Kept last_interactive update for stats handling. - idleStateReceiver: Removed VPN rebuild when exiting Doze mode. TC's tracker blocking doesn't change based on idle state. https://claude.ai/code/session_01PuXevPG3gUKEXWHrgRMptV
- Preserve WiFi metered override in getAllowedRules(): the old code treated WiFi as unmetered unless use_metered was set, which affects isLockedDown() for IP filter rules. Without this, users on metered WiFi networks (hotspots) could see different lockdown behavior. - Remove unused ExecutorService field and imports: was only used by the old interactiveStateReceiver reload logic, now creates a thread pool that's never used. https://claude.ai/code/session_01PuXevPG3gUKEXWHrgRMptV
The native tunnel thread may get into a bad state during Doze's network restrictions. Reloading on Doze exit ensures the tunnel is healthy and packet filtering resumes correctly. Without this, a stuck tunnel could silently stop filtering until the next reload from another trigger. Also removed unused ExecutorService (was only used by old interactiveStateReceiver logic). https://claude.ai/code/session_01PuXevPG3gUKEXWHrgRMptV
df70999 to
7ba263f
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TrackerControl always runs in filter mode and doesn't differentiate blocking rules by network type (WiFi vs mobile), unlike NetGuard. This PR removes the unnecessary VPN rebuilds triggered by network changes, reducing VPN disruptions for users.
reload(). These only mattered for NetGuard's per-network blocking rules which TC doesn't use.getAllowedRules(): Removed all wifi/metered/roaming/generation/screen filtering logic. In filter mode,listAlloweddoesn't affect VPN routing (builder usesrule.apply) andmapUidAllowedis never read inisAddressAllowed(). Now returns all rules.reload()interactive optimization: The screen-based rule check (screen_wifi/screen_other) was dead code — all 49 callers passinteractive=false.ExecutorService: Was only used by oldinteractiveStateReceiverreload logic.last_meteredWiFi override: The metered state adjustment for WiFi is kept to avoid any edge-case behavioral change inisLockedDown().What still triggers VPN rebuilds (intentionally kept)
Test plan
https://claude.ai/code/session_01PuXevPG3gUKEXWHrgRMptV