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 androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import java.util.UUID
import libtailscale.Libtailscale
import java.util.UUID
open class IPNService : VpnService(), libtailscale.IPNService {
private val randomID: String = UUID.randomUUID().toString()
@ -44,9 +44,11 @@ open class IPNService : VpnService(), libtailscale.IPNService {
return START_STICKY
}
private fun close() {
override public fun close() {
stopForeground(true)
Libtailscale.serviceDisconnect(this)
val app = applicationContext as App
app.setWantRunning(false)
}
override fun onDestroy() {

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

@ -10,9 +10,6 @@ import (
var (
// onVPNPrepared is notified when VpnService.prepare succeeds.
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 = make(chan struct{}, 1)
@ -51,13 +48,6 @@ func notifyVPNRevoked() {
}
}
func notifyVPNClosed() {
select {
case onVPNClosed <- struct{}{}:
default:
}
}
var android struct {
// mu protects all fields of this structure. However, once a
// 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
// the Android VPN.
NewBuilder() VPNServiceBuilder
Close()
}
// VPNServiceBuilder corresponds to Android's VpnService.Builder.

Loading…
Cancel
Save