Skip to content

Commit

Permalink
android: start VPN after preparing VPN
Browse files Browse the repository at this point in the history
#398 introduced a bug where we were not calling startVPN after getting (or confirming) VPN.prepare permissions
This resulted in the VPN not being turned on after logging in for the first time

Updates tailscale/tailscale#12148

Signed-off-by: kari-ts <kari@tailscale.com>
  • Loading branch information
kari-ts committed May 28, 2024
1 parent 75db9e6 commit 517dd00
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion android/src/main/java/com/tailscale/ipn/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ class MainActivity : ComponentActivity() {
if (granted) {
Log.d("VpnPermission", "VPN permission granted")
viewModel.setVpnPrepared(true)
App.get().startVPN()
} else {
Log.d("VpnPermission", "VPN permission denied")
viewModel.setVpnPrepared(false)
}
}
viewModel.setVpnPermissionLauncher(vpnPermissionLauncher)
viewModel.setVpnPermissionLauncher(vpnPermissionLauncher)

setContent {
AppTheme {
Expand Down
4 changes: 3 additions & 1 deletion android/src/main/java/com/tailscale/ipn/ui/view/MainView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fun MainView(
Column(
modifier = Modifier.fillMaxWidth().padding(paddingInsets),
verticalArrangement = Arrangement.Center) {
// Assume VPN has been prepared. Whether or not it has been prepared cannot be known
// Assume VPN has been prepared for optimistic UI. Whether or not it has been prepared cannot be known
// until permission has been granted to prepare the VPN.
val isPrepared by viewModel.vpnPrepared.collectAsState(initial = true)
val isOn by viewModel.vpnToggleState.collectAsState(initial = false)
Expand Down Expand Up @@ -170,6 +170,8 @@ fun MainView(

PromptPermissionsIfNecessary()

viewModel.showVPNPermissionLauncherIfUnauthorized()

if (showKeyExpiry) {
ExpiryNotification(netmap = netmap, action = { viewModel.login() })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class MainViewModel : IpnViewModel() {
vpnPermissionLauncher?.launch(vpnIntent)
} else {
setVpnPrepared(true)
startVPN()
}
}

Expand Down

0 comments on commit 517dd00

Please sign in to comment.