fix(android): keep selected server across VPN consent dialog#8905
fix(android): keep selected server across VPN consent dialog#8905garmr-ulfr wants to merge 3 commits into
Conversation
On the first connect of a session, connectToServer(tag) bailed at the isVPNServiceReady() check that shows the OS VPN-consent dialog and discarded the tag. onActivityResult then resumed unconditionally with startVPN() (auto-select), so the tunnel connected to the nearest exit while the UI still showed the tapped server. Record the pending selection when the consent dialog interrupts the connect and replay it after consent via resumePendingConnect(), which dispatches to the tag-preserving connectToServer() path instead of auto. connectToServer owns the pendingTag lifecycle: it is set only when deferring for consent and cleared only after a successful dispatch, so a failed start preserves the selection for retry. Both permission callbacks now route through resumePendingConnect.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesVPN server selection persistence
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Fixes an Android first-connect behavior where a user-selected server tag was lost when the OS VPN-consent dialog interrupted the flow, causing the tunnel to connect via auto-select while the UI still reflected the tapped server.
Changes:
- Introduces a
pendingTagfield to persist the selected server tag across the VPN-consent round trip. - Adds
resumePendingConnect()to replay the deferred connect (tagged connect vs auto connect) after permission callbacks. - Routes both
onActivityResult(VPN consent) andonRequestPermissionsResultthroughresumePendingConnect().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
connectToServer/startVPN run on MethodHandler's Dispatchers.IO coroutine, while pendingTag is read on the main thread in the permission callbacks. As a plain var there is no happens-before guarantee, so a stale read after consent could fall back to auto-select. Volatile gives the needed visibility; accesses are single-variable so no atomicity is required.
Problem
On the first connect of a session, tapping a specific server routes the tunnel to the nearest exit instead. In
MainActivity,connectToServer(tag)bails at theisVPNServiceReady()check that shows the OS VPN-consent dialog and discards the tag.onActivityResultthen resumes unconditionally withstartVPN()(auto-select), so the tunnel connects to the nearest server while the UI still shows the tapped one.Fix
pendingTag) when the consent dialog interrupts the connect.resumePendingConnect()replays it via the tag-preservingconnectToServer()path instead of falling back to auto.connectToServerowns thependingTaglifecycle: set only when deferring for consent, cleared only after a successful dispatch — so a failed service start preserves the selection for retry.onActivityResult,onRequestPermissionsResult) route throughresumePendingConnect().The service side already handled
ACTION_CONNECT_TO_SERVERcorrectly; the bug was entirelyMainActivitydropping the tag across the consent round-trip.Summary by CodeRabbit