diff options
| author | Albin <albin@mullvad.net> | 2022-05-12 09:25:59 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2022-05-12 15:02:31 +0200 |
| commit | 06cf165320c79a34d9207f534d268056ec71abcb (patch) | |
| tree | d921aca6d5b9a177ab168223f7e8c37a6ba9b6f2 /android | |
| parent | 115f3d51994602485f70b318ca7245a85c41778c (diff) | |
| download | mullvadvpn-06cf165320c79a34d9207f534d268056ec71abcb.tar.xz mullvadvpn-06cf165320c79a34d9207f534d268056ec71abcb.zip | |
Adapt new device event/state to Android
Diffstat (limited to 'android')
8 files changed, 31 insertions, 25 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceEvent.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceEvent.kt index 1f2b68fbe5..3156b98833 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceEvent.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceEvent.kt @@ -5,6 +5,6 @@ import kotlinx.parcelize.Parcelize @Parcelize data class DeviceEvent( - val device: AccountAndDevice?, - val remote: Boolean + val cause: DeviceEventCause, + val newState: DeviceState ) : Parcelable diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceEventCause.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceEventCause.kt new file mode 100644 index 0000000000..b4c1d21761 --- /dev/null +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceEventCause.kt @@ -0,0 +1,13 @@ +package net.mullvad.mullvadvpn.model + +import android.os.Parcelable +import kotlinx.parcelize.Parcelize + +@Parcelize +enum class DeviceEventCause : Parcelable { + LoggedIn, + LoggedOut, + Revoked, + Updated, + RotatedKey +} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceState.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceState.kt index 1ae927a9b3..567f5f233f 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceState.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceState.kt @@ -8,26 +8,23 @@ sealed class DeviceState : Parcelable { object InitialState : DeviceState() @Parcelize - data class DeviceRegistered(val accountAndDevice: AccountAndDevice) : DeviceState() + class LoggedIn(val accountAndDevice: AccountAndDevice) : DeviceState() @Parcelize - object DeviceNotRegistered : DeviceState() + object LoggedOut : DeviceState() + + @Parcelize + object Revoked : DeviceState() fun isInitialState(): Boolean { return this is InitialState } fun deviceName(): String? { - return (this as? DeviceRegistered)?.accountAndDevice?.device?.name + return (this as? LoggedIn)?.accountAndDevice?.device?.name } fun token(): String? { - return (this as? DeviceRegistered)?.accountAndDevice?.account_token - } - - companion object { - fun from(accountAndDevice: AccountAndDevice?): DeviceState { - return accountAndDevice?.let { DeviceRegistered(it) } ?: DeviceNotRegistered - } + return (this as? LoggedIn)?.accountAndDevice?.account_token } } 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 9c02fc551f..649ddd65b1 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 @@ -3,7 +3,6 @@ package net.mullvad.mullvadvpn.service import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow -import net.mullvad.mullvadvpn.model.AccountAndDevice import net.mullvad.mullvadvpn.model.AppVersionInfo import net.mullvad.mullvadvpn.model.Device import net.mullvad.mullvadvpn.model.DeviceEvent @@ -126,7 +125,7 @@ class MullvadDaemon(vpnService: MullvadVpnService) { return listDevices(daemonInterfaceAddress, accountToken) } - fun getDevice(): AccountAndDevice? = getDevice(daemonInterfaceAddress) + fun getDevice(): DeviceState = getDevice(daemonInterfaceAddress) fun updateDevice() = updateDevice(daemonInterfaceAddress) @@ -216,7 +215,7 @@ class MullvadDaemon(vpnService: MullvadVpnService) { accountToken: String? ): List<Device>? - private external fun getDevice(daemonInterfaceAddress: Long): AccountAndDevice? + private external fun getDevice(daemonInterfaceAddress: Long): DeviceState private external fun updateDevice(daemonInterfaceAddress: Long) private external fun removeDevice( daemonInterfaceAddress: Long, @@ -262,7 +261,7 @@ class MullvadDaemon(vpnService: MullvadVpnService) { } private fun notifyDeviceEvent(event: DeviceEvent) { - _deviceStateUpdates.tryEmit(DeviceState.from(event.device)) + _deviceStateUpdates.tryEmit(event.newState) } private fun notifyRemoveDeviceEvent(event: RemoveDeviceEvent) { 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 c782999f6a..a61bb15ed2 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 @@ -3,7 +3,6 @@ package net.mullvad.mullvadvpn.service.endpoint import kotlinx.coroutines.flow.collect import net.mullvad.mullvadvpn.ipc.Event import net.mullvad.mullvadvpn.ipc.Request -import net.mullvad.mullvadvpn.model.DeviceState import net.mullvad.mullvadvpn.service.MullvadDaemon import net.mullvad.mullvadvpn.util.JobTracker @@ -32,9 +31,7 @@ class DaemonDeviceDataSource( endpoint.dispatcher.registerHandler(Request.RefreshDeviceState::class) { tracker.newBackgroundJob("refreshDeviceJob") { daemon.getDevice() - .let { accountAndDevice -> - Event.DeviceStateEvent(DeviceState.from(accountAndDevice)) - } + .let { deviceState -> Event.DeviceStateEvent(deviceState) } .also { event -> endpoint.sendEvent(event) } } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/AccountFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/AccountFragment.kt index d94a88ee3c..4b76bb2b6a 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/AccountFragment.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/AccountFragment.kt @@ -102,8 +102,8 @@ class AccountFragment : ServiceDependentFragment(OnNoService.GoBack) { .onEach { state -> if (state.isInitialState()) deviceRepository.refreshDeviceState() } - .collect { - accountNumberView.information = it.token() + .collect { state -> + accountNumberView.information = state.token() } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/LaunchFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/LaunchFragment.kt index 1d1065f81d..f2e441d96a 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/LaunchFragment.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/LaunchFragment.kt @@ -45,8 +45,8 @@ class LaunchFragment : ServiceAwareFragment() { .first { state -> state.isInitialState().not() } .let { deviceState -> when (deviceState) { - is DeviceState.DeviceRegistered -> advanceToConnectScreen() - is DeviceState.DeviceNotRegistered -> advanceToLoginScreen() + is DeviceState.LoggedIn -> advanceToConnectScreen() + is DeviceState.LoggedOut -> advanceToLoginScreen() else -> Unit } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/SettingsFragment.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/SettingsFragment.kt index 9afd5bdb2c..dea5d900db 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/SettingsFragment.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/SettingsFragment.kt @@ -137,7 +137,7 @@ class SettingsFragment : ServiceAwareFragment(), StatusBarPainter, NavigationBar repository.deviceState .onEach { state -> if (state.isInitialState()) repository.refreshDeviceState() } .collect { device -> - updateLoggedInStatus(device is DeviceState.DeviceRegistered) + updateLoggedInStatus(device is DeviceState.LoggedIn) } } } |
