diff options
| author | David Lönnhager <david.l@mullvad.net> | 2024-08-09 15:39:32 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2024-08-13 13:39:54 +0200 |
| commit | bb9597f7e4d1ac0c690526851bbc3e745cd8e815 (patch) | |
| tree | b23c61a4dbabf4967060c45bd1a95ed934fc9161 /android/lib/talpid/src | |
| parent | 7928cf5c31b93f333c628285b6e15a11ae7bf4e8 (diff) | |
| download | mullvadvpn-bb9597f7e4d1ac0c690526851bbc3e745cd8e815.tar.xz mullvadvpn-bb9597f7e4d1ac0c690526851bbc3e745cd8e815.zip | |
Refactor tunnel provider and TalpidVpnService
This also fixes the issue of the VPN service being restarted
unnecessarily
Diffstat (limited to 'android/lib/talpid/src')
| -rw-r--r-- | android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt b/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt index 2a854f7e5c..1c4b51a520 100644 --- a/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt +++ b/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt @@ -26,10 +26,7 @@ open class TalpidVpnService : LifecycleVpnService() { } } - private val tunIsOpen - get() = activeTunStatus?.isOpen ?: false - - private var currentTunConfig = defaultTunConfig() + private var currentTunConfig: TunConfig? = null // Used by JNI val connectivityListener = ConnectivityListener() @@ -46,36 +43,33 @@ open class TalpidVpnService : LifecycleVpnService() { connectivityListener.unregister() } - fun getTun(config: TunConfig): CreateTunResult { + fun openTun(config: TunConfig): CreateTunResult { synchronized(this) { val tunStatus = activeTunStatus - if (config == currentTunConfig && tunIsOpen) { - return tunStatus!! + if (config == currentTunConfig && tunStatus != null && tunStatus.isOpen) { + return tunStatus } else { - val newTunStatus = createTun(config) - - currentTunConfig = config - activeTunStatus = newTunStatus - - return newTunStatus + return openTunImpl(config) } } } - fun createTun() { - synchronized(this) { activeTunStatus = createTun(currentTunConfig) } - } - - fun recreateTunIfOpen(config: TunConfig) { + fun openTunForced(config: TunConfig): CreateTunResult { synchronized(this) { - if (tunIsOpen) { - currentTunConfig = config - activeTunStatus = createTun(config) - } + return openTunImpl(config) } } + private fun openTunImpl(config: TunConfig): CreateTunResult { + val newTunStatus = createTun(config) + + currentTunConfig = config + activeTunStatus = newTunStatus + + return newTunStatus + } + fun closeTun() { synchronized(this) { activeTunStatus = null } } @@ -151,8 +145,6 @@ open class TalpidVpnService : LifecycleVpnService() { } } - private external fun defaultTunConfig(): TunConfig - private external fun waitForTunnelUp(tunFd: Int, isIpv6Enabled: Boolean) companion object { |
