summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-11-25 09:26:34 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-11-25 09:26:34 -0300
commitf4e5137301ec48f48885266937ee6435b0c50301 (patch)
treed829c3a18b9ab9a09c3fe4531139a288e88a1205
parent2233e4af385102d60f2f828ccbf03b8a1080c44d (diff)
parent525cb6745c070786750663f689fa5d0b1c4c0b4d (diff)
downloadmullvadvpn-f4e5137301ec48f48885266937ee6435b0c50301.tar.xz
mullvadvpn-f4e5137301ec48f48885266937ee6435b0c50301.zip
Merge branch 'fix-unexpected-daemon-restart'
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadVpnService.kt31
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()
}