summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2022-05-02 08:44:35 +0200
committerAlbin <albin@mullvad.net>2022-05-17 15:06:04 +0200
commit2bdb7b8f45bba452ce3861b33c426f8a52808923 (patch)
tree9d2c08e148771c2340a619e193e2a5b571e3b4ed /android
parent7f8ad3e7dfe097580e48ce2567111fb0d47962da (diff)
downloadmullvadvpn-2bdb7b8f45bba452ce3861b33c426f8a52808923.tar.xz
mullvadvpn-2bdb7b8f45bba452ce3861b33c426f8a52808923.zip
Fix Android device state refresh
Diffstat (limited to 'android')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt23
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/DaemonDeviceDataSource.kt4
2 files changed, 14 insertions, 13 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt
index 649ddd65b1..a7ad35ef6d 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt
@@ -1,8 +1,7 @@
package net.mullvad.mullvadvpn.service
-import kotlinx.coroutines.channels.BufferOverflow
-import kotlinx.coroutines.flow.MutableSharedFlow
-import kotlinx.coroutines.flow.asSharedFlow
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.asStateFlow
import net.mullvad.mullvadvpn.model.AppVersionInfo
import net.mullvad.mullvadvpn.model.Device
import net.mullvad.mullvadvpn.model.DeviceEvent
@@ -34,11 +33,8 @@ class MullvadDaemon(vpnService: MullvadVpnService) {
var onRelayListChange: ((RelayList) -> Unit)? = null
var onDaemonStopped: (() -> Unit)? = null
- private val _deviceStateUpdates = MutableSharedFlow<DeviceState>(
- extraBufferCapacity = 1,
- onBufferOverflow = BufferOverflow.DROP_OLDEST
- )
- val deviceStateUpdates = _deviceStateUpdates.asSharedFlow()
+ private val _deviceStateUpdates = MutableStateFlow<DeviceState>(DeviceState.InitialState)
+ val deviceStateUpdates = _deviceStateUpdates.asStateFlow()
init {
System.loadLibrary("mullvad_jni")
@@ -125,9 +121,16 @@ class MullvadDaemon(vpnService: MullvadVpnService) {
return listDevices(daemonInterfaceAddress, accountToken)
}
- fun getDevice(): DeviceState = getDevice(daemonInterfaceAddress)
+ fun getAndEmitDeviceState(): DeviceState {
+ return getDevice(daemonInterfaceAddress).also { deviceState ->
+ _deviceStateUpdates.tryEmit(deviceState)
+ }
+ }
- fun updateDevice() = updateDevice(daemonInterfaceAddress)
+ fun refreshDevice() {
+ updateDevice(daemonInterfaceAddress)
+ getAndEmitDeviceState()
+ }
fun removeDevice(accountToken: String, deviceId: String): RemoveDeviceResult {
return removeDevice(daemonInterfaceAddress, accountToken, deviceId)
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/DaemonDeviceDataSource.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/DaemonDeviceDataSource.kt
index a61bb15ed2..cc23b3fe01 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/DaemonDeviceDataSource.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/DaemonDeviceDataSource.kt
@@ -30,9 +30,7 @@ class DaemonDeviceDataSource(
endpoint.dispatcher.registerHandler(Request.RefreshDeviceState::class) {
tracker.newBackgroundJob("refreshDeviceJob") {
- daemon.getDevice()
- .let { deviceState -> Event.DeviceStateEvent(deviceState) }
- .also { event -> endpoint.sendEvent(event) }
+ daemon.refreshDevice()
}
}
}