IPNService: on close, edit prefs with WantRunning=false (#279)

This fixes the issue where when the VPN was turned off by system settings, the toggle was showing the user as conencted

Updates tailscale/corp#18202
Fixes tailscale/corp#18863

Signed-off-by: kari-ts <kari@tailscale.com>
jonathan/cleanup
kari-ts 8 months ago committed by GitHub
parent ccda0499a7
commit f54e476328
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -10,8 +10,8 @@ import android.os.Build
import android.system.OsConstants import android.system.OsConstants
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import java.util.UUID
import libtailscale.Libtailscale import libtailscale.Libtailscale
import java.util.UUID
open class IPNService : VpnService(), libtailscale.IPNService { open class IPNService : VpnService(), libtailscale.IPNService {
private val randomID: String = UUID.randomUUID().toString() private val randomID: String = UUID.randomUUID().toString()
@ -44,9 +44,11 @@ open class IPNService : VpnService(), libtailscale.IPNService {
return START_STICKY return START_STICKY
} }
private fun close() { override public fun close() {
stopForeground(true) stopForeground(true)
Libtailscale.serviceDisconnect(this) Libtailscale.serviceDisconnect(this)
val app = applicationContext as App
app.setWantRunning(false)
} }
override fun onDestroy() { override fun onDestroy() {

@ -212,7 +212,7 @@ func (a *App) runBackend(ctx context.Context) error {
if cfg.rcfg != nil && state >= ipn.Starting { if cfg.rcfg != nil && state >= ipn.Starting {
if err := b.updateTUN(service, cfg.rcfg, cfg.dcfg); err != nil { if err := b.updateTUN(service, cfg.rcfg, cfg.dcfg); err != nil {
log.Printf("VPN update failed: %v", err) log.Printf("VPN update failed: %v", err)
notifyVPNClosed() service.Close()
} }
} }
case s := <-onDisconnect: case s := <-onDisconnect:
@ -221,9 +221,6 @@ func (a *App) runBackend(ctx context.Context) error {
netns.SetAndroidProtectFunc(nil) netns.SetAndroidProtectFunc(nil)
service = nil service = nil
} }
if state >= ipn.Starting {
notifyVPNClosed()
}
case <-onDNSConfigChanged: case <-onDNSConfigChanged:
if b != nil { if b != nil {
go b.NetworkChanged() go b.NetworkChanged()

@ -10,9 +10,6 @@ import (
var ( var (
// onVPNPrepared is notified when VpnService.prepare succeeds. // onVPNPrepared is notified when VpnService.prepare succeeds.
onVPNPrepared = make(chan struct{}, 1) onVPNPrepared = make(chan struct{}, 1)
// onVPNClosed is notified when VpnService.prepare fails, or when
// the a running VPN connection is closed.
onVPNClosed = make(chan struct{}, 1)
// onVPNRevoked is notified whenever the VPN service is revoked. // onVPNRevoked is notified whenever the VPN service is revoked.
onVPNRevoked = make(chan struct{}, 1) onVPNRevoked = make(chan struct{}, 1)
@ -51,13 +48,6 @@ func notifyVPNRevoked() {
} }
} }
func notifyVPNClosed() {
select {
case onVPNClosed <- struct{}{}:
default:
}
}
var android struct { var android struct {
// mu protects all fields of this structure. However, once a // mu protects all fields of this structure. However, once a
// non-nil jvm is returned from javaVM, all the other fields may // non-nil jvm is returned from javaVM, all the other fields may

@ -61,6 +61,8 @@ type IPNService interface {
// NewBuilder creates a new VPNServiceBuilder in preparation for starting // NewBuilder creates a new VPNServiceBuilder in preparation for starting
// the Android VPN. // the Android VPN.
NewBuilder() VPNServiceBuilder NewBuilder() VPNServiceBuilder
Close()
} }
// VPNServiceBuilder corresponds to Android's VpnService.Builder. // VPNServiceBuilder corresponds to Android's VpnService.Builder.

Loading…
Cancel
Save