diff options
| author | Albin <albin@mullvad.net> | 2022-01-19 16:10:18 +0100 |
|---|---|---|
| committer | Albin <albin@mullvad.net> | 2022-01-20 15:14:17 +0100 |
| commit | 4daa49677fae05048a5863b34239d6865a33e32e (patch) | |
| tree | ba318a6c40b7aa53d6e63c4b21a27bb18c7c8db4 /android | |
| parent | 19386d5a70c52618badfeb670c603bb708fab8c5 (diff) | |
| download | mullvadvpn-4daa49677fae05048a5863b34239d6865a33e32e.tar.xz mullvadvpn-4daa49677fae05048a5863b34239d6865a33e32e.zip | |
Fix auto-connect on app removed from recent apps
By default in Android, a service will be automatically killed if it
belongs to a task that was removed (i.e. from recent apps) without a
chance to run any cleanup logic.
In this case, the lack of cleanup would lead to a crash and auto-restart
(triggered by the system) resulting in a auto-connect. To fix this, a
graceful stop will be ran if the task is removed while the tunnel is
disconnected (service not running as foreground). However if the tunnel
is in other states than disconnected (service running as foreground),
the service should continue to run as it's bound by the system.
Diffstat (limited to 'android')
| -rw-r--r-- | android/app/src/main/AndroidManifest.xml | 3 | ||||
| -rw-r--r-- | android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt | 10 |
2 files changed, 12 insertions, 1 deletions
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index e309f71016..5216de46d2 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -51,7 +51,8 @@ </activity> <service android:name="net.mullvad.mullvadvpn.service.MullvadVpnService" android:permission="android.permission.BIND_VPN_SERVICE" - android:process=":mullvadvpn_daemon"> + android:process=":mullvadvpn_daemon" + android:stopWithTask="false"> <intent-filter> <action android:name="android.net.VpnService" /> </intent-filter> diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt index 71067c44d7..d09472fa3d 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt @@ -13,6 +13,7 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Job import kotlinx.coroutines.launch import net.mullvad.mullvadvpn.model.Settings +import net.mullvad.mullvadvpn.model.TunnelState import net.mullvad.mullvadvpn.service.endpoint.ServiceEndpoint import net.mullvad.mullvadvpn.service.notifications.AccountExpiryNotification import net.mullvad.mullvadvpn.ui.MainActivity @@ -169,6 +170,15 @@ class MullvadVpnService : TalpidVpnService() { super.onDestroy() } + override fun onTaskRemoved(rootIntent: Intent?) { + connectionProxy.onStateChange.latestEvent.let { tunnelState -> + Log.d(TAG, "Task removed (tunnelState=$tunnelState)") + if (tunnelState == TunnelState.Disconnected) { + stop() + } + } + } + private fun handleDaemonInstance(daemon: MullvadDaemon?) { setUpDaemonJob?.cancel() |
