Skip to content

android: add Wi-Fi auto-connect feature#813

Open
achanu wants to merge 1 commit into
tailscale:mainfrom
achanu:wifi-auto-connect
Open

android: add Wi-Fi auto-connect feature#813
achanu wants to merge 1 commit into
tailscale:mainfrom
achanu:wifi-auto-connect

Conversation

@achanu

@achanu achanu commented Jun 21, 2026

Copy link
Copy Markdown

Summary

Implements automatic VPN control based on Wi-Fi network name (SSID), accessible from Settings → Wi-Fi auto-connect.

Three-tier behavior:

  • Safe networks (whitelist): VPN stops automatically when joining; restarts when leaving if "unknown networks" auto-start is enabled
  • Unsafe networks (blacklist): VPN starts automatically when joining; stops when leaving
  • Unknown networks toggle: VPN starts on any network not in either list; stops when leaving

User manual overrides are respected per-session (suppress auto-action until next reconnect).

Implementation

  • NetworkChangeCallback.kt: second NetworkCallback registration monitors WiFi; whitelist/blacklist/defaultOn logic in onCapabilitiesChanged and onLost
  • App.kt: getWhitelistSsids(), getBlacklistSsids(), getWifiAutoConnectDefaultOn() backed by SharedPreferences("unencrypted")
  • MainViewModel.kt: userStoppedVpn() / userStartedVpn() latches wired to manual toggle
  • WifiAutoConnectView.kt + WifiAutoConnectViewModel.kt: new Compose screen with two SSID lists and a toggle
  • AndroidManifest.xml: ACCESS_FINE_LOCATION for SSID access on Android < 12 via WifiManager fallback (runtime request included in UI)

SSID reading uses NetworkCapabilities.getTransportInfo() as? WifiInfo (available API 29+; no location permission required on API 31+ per Android 12 docs) with WifiManager.connectionInfo fallback for older APIs or when transport info is redacted.

Test plan

  • Connect to a whitelisted network → VPN stops; disconnect → VPN restarts (if unknown-network toggle ON)
  • Connect to a blacklisted network → VPN starts; disconnect → VPN stops
  • Connect to unknown network with toggle ON → VPN starts; disconnect → VPN stops
  • Connect to unknown network with toggle OFF → no action
  • Manual stop on blacklisted network → no auto-restart until next reconnect
  • Manual start on whitelisted network → no auto-stop
  • "Use current network" button in add dialog prefills SSID (requires location permission)
  • Tested on Android 16 (API 36)

🤖 Generated with Claude Code

@achanu achanu marked this pull request as draft June 21, 2026 16:11
@achanu achanu force-pushed the wifi-auto-connect branch from 0af82dc to 0fb3fc5 Compare June 21, 2026 16:17
Adds per-SSID VPN control with three modes:
- Whitelist (safe networks): VPN stops automatically on join, restarts
  on leave if unknown-network auto-start is enabled
- Blacklist (unsafe networks): VPN starts automatically on join, stops
  on leave
- Default-on: VPN starts on any network not in either list

New screen under Settings → Wi-Fi auto-connect lets users manage both
lists and toggle default-on. Location permission is requested to
pre-fill the current SSID in the add-network dialog.

Requires ACCESS_FINE_LOCATION for SSID detection on Android < 12.
On API 29+ the SSID is read from NetworkCapabilities.transportInfo
without a location permission prompt.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@achanu achanu force-pushed the wifi-auto-connect branch from 0fb3fc5 to e0145bc Compare June 21, 2026 20:13
@achanu achanu marked this pull request as ready for review June 21, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant