diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-11-13 11:39:31 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-11-13 11:39:31 -0300 |
| commit | 91d7ebf53c5c5f583b6f17812bb61e0e2bf8ad8c (patch) | |
| tree | 09e846d36d3f9ab9483b91ae000f12299b5f7367 | |
| parent | 9371bc70ab7fdada0646c1e1d4a439722e2b7ce1 (diff) | |
| parent | d81910026fa846420585507adae9e35b8e0fd83c (diff) | |
| download | mullvadvpn-91d7ebf53c5c5f583b6f17812bb61e0e2bf8ad8c.tar.xz mullvadvpn-91d7ebf53c5c5f583b6f17812bb61e0e2bf8ad8c.zip | |
Merge branch 'fix-split-tunneling-race-condition-again'
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt index 819886d1f6..4973c7fcc2 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt @@ -9,6 +9,7 @@ import android.os.IBinder import android.util.Log import java.io.File import kotlin.properties.Delegates.observable +import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Job @@ -43,6 +44,8 @@ class MullvadVpnService : TalpidVpnService() { private val binder = LocalBinder() private val serviceNotifier = EventNotifier<ServiceInstance?>(null) + private val splitTunneling = CompletableDeferred<SplitTunneling>() + private var isStopping = false private var shouldStop = false @@ -90,6 +93,8 @@ class MullvadVpnService : TalpidVpnService() { super.onCreate() Log.d(TAG, "Initializing service") + initializeSplitTunneling() + keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager notificationManager = ForegroundNotificationManager(this, serviceNotifier, keyguardManager) tunnelStateUpdater = TunnelStateUpdater(this, serviceNotifier) @@ -179,6 +184,17 @@ class MullvadVpnService : TalpidVpnService() { set(value) { this@MullvadVpnService.isUiVisible = value } } + private fun initializeSplitTunneling() = GlobalScope.launch(Dispatchers.Default) { + splitTunneling.complete( + SplitTunneling(this@MullvadVpnService).apply { + onChange = { excludedApps -> + disallowedApps = excludedApps + markTunAsStale() + } + } + ) + } + private fun setUp() { startDaemonJob?.cancel() startDaemonJob = startDaemon() @@ -187,6 +203,7 @@ class MullvadVpnService : TalpidVpnService() { private fun startDaemon() = GlobalScope.launch(Dispatchers.Default) { Log.d(TAG, "Starting daemon") prepareFiles() + splitTunneling.await() val daemon = MullvadDaemon(this@MullvadVpnService).apply { onDaemonStopped = { @@ -226,16 +243,15 @@ class MullvadVpnService : TalpidVpnService() { } } - private fun setUpInstance(daemon: MullvadDaemon, settings: Settings) { + private suspend fun setUpInstance(daemon: MullvadDaemon, settings: Settings) { val settingsListener = SettingsListener(daemon, settings) val connectionProxy = ConnectionProxy(this, daemon) + val splitTunneling = splitTunneling.await() - val splitTunneling = SplitTunneling(this).apply { - onChange = { excludedApps -> - disallowedApps = excludedApps - markTunAsStale() - connectionProxy.reconnect() - } + splitTunneling.onChange = { excludedApps -> + disallowedApps = excludedApps + markTunAsStale() + connectionProxy.reconnect() } handlePendingAction(connectionProxy, settings) |
