summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2022-05-12 09:25:59 +0200
committerDavid Lönnhager <david.l@mullvad.net>2022-05-12 15:02:31 +0200
commit06cf165320c79a34d9207f534d268056ec71abcb (patch)
treed921aca6d5b9a177ab168223f7e8c37a6ba9b6f2
parent115f3d51994602485f70b318ca7245a85c41778c (diff)
downloadmullvadvpn-06cf165320c79a34d9207f534d268056ec71abcb.tar.xz
mullvadvpn-06cf165320c79a34d9207f534d268056ec71abcb.zip
Adapt new device event/state to Android
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceEvent.kt4
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceEventCause.kt13
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/DeviceState.kt17
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt7
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/DaemonDeviceDataSource.kt5
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/AccountFragment.kt4
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/LaunchFragment.kt4
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/SettingsFragment.kt2
-rw-r--r--mullvad-jni/src/classes.rs4
-rw-r--r--mullvad-jni/src/daemon_interface.rs4
-rw-r--r--mullvad-types/src/device.rs1
11 files changed, 38 insertions, 27 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)
}
}
}
diff --git a/mullvad-jni/src/classes.rs b/mullvad-jni/src/classes.rs
index a453b4ad6c..4b8132a8de 100644
--- a/mullvad-jni/src/classes.rs
+++ b/mullvad-jni/src/classes.rs
@@ -11,6 +11,10 @@ pub const CLASSES: &[&str] = &[
"net/mullvad/mullvadvpn/model/DnsOptions",
"net/mullvad/mullvadvpn/model/Device",
"net/mullvad/mullvadvpn/model/DeviceEvent",
+ "net/mullvad/mullvadvpn/model/DeviceEventCause",
+ "net/mullvad/mullvadvpn/model/DeviceState$LoggedIn",
+ "net/mullvad/mullvadvpn/model/DeviceState$LoggedOut",
+ "net/mullvad/mullvadvpn/model/DeviceState$Revoked",
"net/mullvad/mullvadvpn/model/RemoveDeviceEvent",
"net/mullvad/mullvadvpn/model/GeoIpLocation",
"net/mullvad/mullvadvpn/model/GetAccountDataResult$Ok",
diff --git a/mullvad-jni/src/daemon_interface.rs b/mullvad-jni/src/daemon_interface.rs
index f429201e88..d23e7b8be4 100644
--- a/mullvad-jni/src/daemon_interface.rs
+++ b/mullvad-jni/src/daemon_interface.rs
@@ -2,7 +2,7 @@ use futures::{channel::oneshot, executor::block_on};
use mullvad_daemon::{device, DaemonCommand, DaemonCommandSender};
use mullvad_types::{
account::{AccountData, AccountToken, VoucherSubmission},
- device::{AccountAndDevice, Device},
+ device::{Device, DeviceState},
location::GeoIpLocation,
relay_constraints::RelaySettingsUpdate,
relay_list::RelayList,
@@ -212,7 +212,7 @@ impl DaemonInterface {
.map_err(Error::from)
}
- pub fn get_device(&self) -> Result<Option<AccountAndDevice>> {
+ pub fn get_device(&self) -> Result<DeviceState> {
let (tx, rx) = oneshot::channel();
self.send_command(DaemonCommand::GetDevice(tx))?;
diff --git a/mullvad-types/src/device.rs b/mullvad-types/src/device.rs
index b39690f603..df7ba7bef0 100644
--- a/mullvad-types/src/device.rs
+++ b/mullvad-types/src/device.rs
@@ -64,6 +64,7 @@ impl fmt::Display for DevicePort {
/// Contains a device state.
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "snake_case")]
+#[cfg_attr(target_os = "android", derive(IntoJava))]
#[cfg_attr(target_os = "android", jnix(package = "net.mullvad.mullvadvpn.model"))]
pub enum DeviceState {
LoggedIn(AccountAndDevice),