summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-01-28 15:05:15 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-03-29 14:22:55 +0000
commit94c32794769d59472829295aab95c3361a948349 (patch)
tree72906f5b7a5b7841ac4ad8633ea73201b3324b1c /android/src
parent6fcbd86d90fbbf250ebb00bb088a42acdb23cd65 (diff)
downloadmullvadvpn-94c32794769d59472829295aab95c3361a948349.tar.xz
mullvadvpn-94c32794769d59472829295aab95c3361a948349.zip
Reduce service side `KeyStatusListener` interface
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/KeyStatusListener.kt17
1 files changed, 6 insertions, 11 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/KeyStatusListener.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/KeyStatusListener.kt
index 2c506aa6cf..e5a4e9e0d2 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/KeyStatusListener.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/KeyStatusListener.kt
@@ -7,16 +7,12 @@ import kotlinx.coroutines.launch
import net.mullvad.mullvadvpn.ipc.Event
import net.mullvad.mullvadvpn.ipc.Request
import net.mullvad.mullvadvpn.model.KeygenEvent
-import net.mullvad.talpid.util.EventNotifier
class KeyStatusListener(endpoint: ServiceEndpoint) {
private val daemon = endpoint.intermittentDaemon
- val onKeyStatusChange = EventNotifier<KeygenEvent?>(null)
-
var keyStatus by observable<KeygenEvent?>(null) { _, _, status ->
endpoint.sendEvent(Event.WireGuardKeyStatus(status))
- onKeyStatusChange.notify(status)
}
private set
@@ -42,7 +38,11 @@ class KeyStatusListener(endpoint: ServiceEndpoint) {
}
}
- fun generateKey() = GlobalScope.launch(Dispatchers.Default) {
+ fun onDestroy() {
+ daemon.unregisterListener(this)
+ }
+
+ private fun generateKey() = GlobalScope.launch(Dispatchers.Default) {
val oldStatus = keyStatus
val newStatus = daemon.await().generateWireguardKey()
val newFailure = newStatus?.failure()
@@ -57,7 +57,7 @@ class KeyStatusListener(endpoint: ServiceEndpoint) {
}
}
- fun verifyKey() = GlobalScope.launch(Dispatchers.Default) {
+ private fun verifyKey() = GlobalScope.launch(Dispatchers.Default) {
// Only update verification status if the key is actually there
(keyStatus as? KeygenEvent.NewKey)?.let { currentStatus ->
keyStatus = KeygenEvent.NewKey(
@@ -67,9 +67,4 @@ class KeyStatusListener(endpoint: ServiceEndpoint) {
)
}
}
-
- fun onDestroy() {
- daemon.unregisterListener(this)
- onKeyStatusChange.unsubscribeAll()
- }
}