diff options
| author | Albin <albin@mullvad.net> | 2022-07-28 08:00:35 +0200 |
|---|---|---|
| committer | Albin <albin@mullvad.net> | 2022-07-29 13:01:20 +0200 |
| commit | 45eaba30c34d303dd26103bca42c65fc62775ea9 (patch) | |
| tree | 730343b62a0c9a7b37774740c6ef1a30aefc3254 /android | |
| parent | e94358c508335b69826137b3d1da0062e7b797a7 (diff) | |
| download | mullvadvpn-45eaba30c34d303dd26103bca42c65fc62775ea9.tar.xz mullvadvpn-45eaba30c34d303dd26103bca42c65fc62775ea9.zip | |
Propagate device removal event
Diffstat (limited to 'android')
4 files changed, 34 insertions, 1 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Event.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Event.kt index c351cc8130..ea7ecdcd7b 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Event.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Event.kt @@ -12,6 +12,7 @@ import net.mullvad.mullvadvpn.model.DeviceState import net.mullvad.mullvadvpn.model.GeoIpLocation import net.mullvad.mullvadvpn.model.LoginResult import net.mullvad.mullvadvpn.model.RelayList +import net.mullvad.mullvadvpn.model.RemoveDeviceResult import net.mullvad.mullvadvpn.model.Settings import net.mullvad.mullvadvpn.model.TunnelState import net.mullvad.mullvadvpn.model.VoucherSubmissionResult as VoucherSubmissionResultData @@ -45,6 +46,9 @@ sealed class Event : Message.EventMessage() { data class DeviceListUpdate(val event: DeviceListEvent) : Event() @Parcelize + data class DeviceRemovalEvent(val deviceId: String, val result: RemoveDeviceResult) : Event() + + @Parcelize data class ListenerReady(val connection: Messenger, val listenerId: Int) : Event() @Parcelize 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 cb290a6d27..9bdf30de21 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 @@ -48,7 +48,9 @@ class DaemonDeviceDataSource( endpoint.dispatcher.registerHandler(Request.RemoveDevice::class) { request -> tracker.newBackgroundJob("removeDeviceJob") { - daemon.removeDevice(request.accountToken, request.deviceId) + daemon.removeDevice(request.accountToken, request.deviceId).also { result -> + endpoint.sendEvent(Event.DeviceRemovalEvent(request.deviceId, result)) + } } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/DeviceRepository.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/DeviceRepository.kt index 790c2404f2..42c296159c 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/DeviceRepository.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/DeviceRepository.kt @@ -4,6 +4,7 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.emptyFlow import kotlinx.coroutines.flow.firstOrNull @@ -12,8 +13,10 @@ import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onStart +import kotlinx.coroutines.flow.shareIn import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.withTimeoutOrNull +import net.mullvad.mullvadvpn.ipc.Event import net.mullvad.mullvadvpn.model.Device import net.mullvad.mullvadvpn.model.DeviceListEvent import net.mullvad.mullvadvpn.model.DeviceState @@ -60,6 +63,20 @@ class DeviceRepository( } .stateIn(CoroutineScope(Dispatchers.IO), SharingStarted.WhileSubscribed(), emptyList()) + val deviceRemovalEvent: SharedFlow<Event.DeviceRemovalEvent> = + serviceConnectionManager.connectionState + .flatMapLatest { state -> + if (state is ServiceConnectionState.ConnectedReady) { + state.container.deviceDataSource.deviceRemovalResult + } else { + emptyFlow() + } + } + .shareIn( + CoroutineScope(dispatcher), + SharingStarted.WhileSubscribed() + ) + fun refreshDeviceState() { serviceConnectionManager.deviceDataSource()?.refreshDevice() } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionDeviceDataSource.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionDeviceDataSource.kt index 6f018a27b1..6e445a6d34 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionDeviceDataSource.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnectionDeviceDataSource.kt @@ -31,6 +31,16 @@ class ServiceConnectionDeviceDataSource( } } + val deviceRemovalResult = callbackFlow { + val handler: (Event.DeviceRemovalEvent) -> Unit = { event -> + trySend(event) + } + dispatcher.registerHandler(Event.DeviceRemovalEvent::class, handler) + awaitClose { + // The current dispatcher doesn't support unregistration of handlers. + } + } + // Async result: Event.DeviceChanged fun refreshDevice() { connection.send(Request.RefreshDeviceState.message) |
