diff options
Diffstat (limited to 'android')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt | 31 |
1 files changed, 16 insertions, 15 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 c3749c17f4..6920a85b4c 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt @@ -38,11 +38,16 @@ class MullvadVpnService : TalpidVpnService() { Disconnect, } + private enum class State { + Running, + Stopping, + Stopped, + } + private val binder = LocalBinder() private val serviceNotifier = EventNotifier<ServiceInstance?>(null) - private var isStopping = false - private var shouldStop = false + private var state = State.Running private var setUpDaemonJob: Job? = null @@ -126,13 +131,9 @@ class MullvadVpnService : TalpidVpnService() { } } - if (shouldStop && !quitCommand) { - shouldStop = false - - if (isStopping) { - restart() - isStopping = false - } + if (state == State.Stopping && !quitCommand) { + state = State.Running + restart() } return startResult @@ -149,9 +150,9 @@ class MullvadVpnService : TalpidVpnService() { Log.d(TAG, "Connection to service restored") isBound = true - if (isStopping) { + if (state == State.Stopping) { + state = State.Running restart() - isStopping = false } } @@ -163,7 +164,7 @@ class MullvadVpnService : TalpidVpnService() { Log.d(TAG, "Closed all connections to service") isBound = false - if (shouldStop) { + if (state != State.Running) { stop() } @@ -172,6 +173,7 @@ class MullvadVpnService : TalpidVpnService() { override fun onDestroy() { Log.d(TAG, "Service has stopped") + state = State.Stopped notificationManager.onDestroy() daemonInstance.onDestroy() super.onDestroy() @@ -206,7 +208,7 @@ class MullvadVpnService : TalpidVpnService() { Log.d(TAG, "Daemon has stopped") instance = null - if (!isStopping) { + if (state == State.Running) { restart() } } @@ -246,8 +248,7 @@ class MullvadVpnService : TalpidVpnService() { private fun stop() { Log.d(TAG, "Stopping service") - isStopping = true - shouldStop = true + state = State.Stopping daemonInstance.stop() stopSelf() } |
