diff options
| author | David Lönnhager <david.l@mullvad.net> | 2023-10-31 15:24:22 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2023-10-31 15:24:22 +0100 |
| commit | f073ef8c37ecc4a0cd3d4525ed3bc310cfd2f7e0 (patch) | |
| tree | f817e43aa5b924bf1b56aeb03e941913fa35e339 /android | |
| parent | 9b33f4440fd35d01eea663df5de7d83f65d96918 (diff) | |
| parent | 3cedaf529da04bbd25fee4829fad4cc0ae2f561f (diff) | |
| download | mullvadvpn-f073ef8c37ecc4a0cd3d4525ed3bc310cfd2f7e0.tar.xz mullvadvpn-f073ef8c37ecc4a0cd3d4525ed3bc310cfd2f7e0.zip | |
Merge branch 'refactor-relay-settings-update' into main
Diffstat (limited to 'android')
11 files changed, 47 insertions, 61 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/RelayListListener.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/RelayListListener.kt index d0f54a0cf6..5c6e765b4e 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/RelayListListener.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/RelayListListener.kt @@ -28,28 +28,13 @@ class RelayListListener( var selectedRelayItem: RelayItem? = null private set - var selectedRelayLocation: GeographicLocationConstraint? - get() { - val settings = relaySettings as? RelaySettings.Normal - val location = settings?.relayConstraints?.location as? Constraint.Only - - return location?.value?.toGeographicLocationConstraint() - } - set(value) { - connection.send(Request.SetRelayLocation(value).message) - } - - var selectedWireguardConstraints: WireguardConstraints? - get() { - val settings = relaySettings as? RelaySettings.Normal + fun updateSelectedRelayLocation(value: GeographicLocationConstraint) { + connection.send(Request.SetRelayLocation(value).message) + } - return settings?.relayConstraints?.wireguardConstraints?.port?.let { port -> - WireguardConstraints(port) - } - } - set(value) { - connection.send(Request.SetWireguardConstraints(value).message) - } + fun updateSelectedWireguardConstraints(value: WireguardConstraints) { + connection.send(Request.SetWireguardConstraints(value).message) + } var onRelayCountriesChange: ((List<RelayCountry>, RelayItem?) -> Unit)? = null set(value) { diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt index 2507e9fb19..0d8f753d8f 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt @@ -71,8 +71,10 @@ class SelectLocationViewModel(private val serviceConnectionManager: ServiceConne @Suppress("konsist.ensure public properties use permitted names") val enterTransitionEndAction = _enterTransitionEndAction.asSharedFlow() - fun selectRelay(relayItem: RelayItem?) { - serviceConnectionManager.relayListListener()?.selectedRelayLocation = relayItem?.location + fun selectRelay(relayItem: RelayItem) { + serviceConnectionManager + .relayListListener() + ?.updateSelectedRelayLocation(relayItem.location) serviceConnectionManager.connectionProxy()?.connect() viewModelScope.launch { _closeAction.emit(Unit) } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt index 0827c81e99..94abf1da90 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt @@ -352,8 +352,9 @@ class VpnSettingsViewModel( fun onWireguardPortSelected(port: Constraint<Port>) { viewModelScope.launch(dispatcher) { - serviceConnectionManager.relayListListener()?.selectedWireguardConstraints = - WireguardConstraints(port = port) + serviceConnectionManager + .relayListListener() + ?.updateSelectedWireguardConstraints(WireguardConstraints(port = port)) } hideDialog() } diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt index 59cd9f48b5..3cadfe575f 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt @@ -132,7 +132,7 @@ class SelectLocationViewModelTest { assertEquals(Unit, awaitItem()) verify { connectionProxyMock.connect() - mockRelayListListener.selectedRelayLocation = mockLocation + mockRelayListListener.updateSelectedRelayLocation(mockLocation) } } } diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt index 66d301d903..13561737c8 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt @@ -159,7 +159,9 @@ class VpnSettingsViewModelTest { // Arrange val wireguardPort: Constraint<Port> = Constraint.Only(Port(99)) val wireguardConstraints = WireguardConstraints(port = wireguardPort) - every { mockRelayListListener.selectedWireguardConstraints = any() } returns Unit + every { + mockRelayListListener.updateSelectedWireguardConstraints(wireguardConstraints) + } returns Unit // Act mockConnectionState.value = @@ -168,7 +170,7 @@ class VpnSettingsViewModelTest { // Assert verify(exactly = 1) { - mockRelayListListener.selectedWireguardConstraints = wireguardConstraints + mockRelayListListener.updateSelectedWireguardConstraints(wireguardConstraints) } } diff --git a/android/lib/ipc/src/main/kotlin/net/mullvad/mullvadvpn/lib/ipc/Request.kt b/android/lib/ipc/src/main/kotlin/net/mullvad/mullvadvpn/lib/ipc/Request.kt index 2a8636fa95..cbd1f28b27 100644 --- a/android/lib/ipc/src/main/kotlin/net/mullvad/mullvadvpn/lib/ipc/Request.kt +++ b/android/lib/ipc/src/main/kotlin/net/mullvad/mullvadvpn/lib/ipc/Request.kt @@ -74,7 +74,7 @@ sealed class Request : Message.RequestMessage() { @Parcelize data class SetEnableSplitTunneling(val enable: Boolean) : Request() @Parcelize - data class SetRelayLocation(val relayLocation: GeographicLocationConstraint?) : Request() + data class SetRelayLocation(val relayLocation: GeographicLocationConstraint) : Request() @Parcelize data class SetWireGuardMtu(val mtu: Int?) : Request() @@ -89,7 +89,7 @@ sealed class Request : Message.RequestMessage() { @Parcelize data class SetObfuscationSettings(val settings: ObfuscationSettings?) : Request() @Parcelize - data class SetWireguardConstraints(val wireguardConstraints: WireguardConstraints?) : Request() + data class SetWireguardConstraints(val wireguardConstraints: WireguardConstraints) : Request() @Parcelize data class SetWireGuardQuantumResistant(val quantumResistant: QuantumResistantState) : diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraintsUpdate.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraintsUpdate.kt deleted file mode 100644 index 8a382a87d9..0000000000 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraintsUpdate.kt +++ /dev/null @@ -1,8 +0,0 @@ -package net.mullvad.mullvadvpn.model - -data class RelayConstraintsUpdate( - val location: Constraint<LocationConstraint>?, - val providers: Constraint<Providers>?, - val ownership: Constraint<Ownership>?, - val wireguardConstraints: WireguardConstraints? -) diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelaySettings.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelaySettings.kt index 7832a00e77..381305f2c3 100644 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelaySettings.kt +++ b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelaySettings.kt @@ -4,7 +4,7 @@ import android.os.Parcelable import kotlinx.parcelize.Parcelize sealed class RelaySettings : Parcelable { - @Parcelize object CustomTunnelEndpoint : RelaySettings() + @Parcelize data object CustomTunnelEndpoint : RelaySettings() - @Parcelize class Normal(val relayConstraints: RelayConstraints) : RelaySettings() + @Parcelize data class Normal(val relayConstraints: RelayConstraints) : RelaySettings() } diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelaySettingsUpdate.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelaySettingsUpdate.kt deleted file mode 100644 index f8d27f115e..0000000000 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/RelaySettingsUpdate.kt +++ /dev/null @@ -1,7 +0,0 @@ -package net.mullvad.mullvadvpn.model - -sealed class RelaySettingsUpdate { - object CustomTunnelEndpoint : RelaySettingsUpdate() - - data class Normal(val constraints: RelayConstraintsUpdate) : RelaySettingsUpdate() -} diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt index ceb95a48b7..fd734bbeac 100644 --- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt +++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt @@ -19,7 +19,7 @@ import net.mullvad.mullvadvpn.model.PlayPurchaseInitResult import net.mullvad.mullvadvpn.model.PlayPurchaseVerifyResult import net.mullvad.mullvadvpn.model.QuantumResistantState import net.mullvad.mullvadvpn.model.RelayList -import net.mullvad.mullvadvpn.model.RelaySettingsUpdate +import net.mullvad.mullvadvpn.model.RelaySettings import net.mullvad.mullvadvpn.model.RemoveDeviceEvent import net.mullvad.mullvadvpn.model.RemoveDeviceResult import net.mullvad.mullvadvpn.model.Settings @@ -182,8 +182,8 @@ class MullvadDaemon( return verifyPlayPurchase(daemonInterfaceAddress, playPurchase) } - fun updateRelaySettings(update: RelaySettingsUpdate) { - updateRelaySettings(daemonInterfaceAddress, update) + fun setRelaySettings(update: RelaySettings) { + setRelaySettings(daemonInterfaceAddress, update) } fun setObfuscationSettings(settings: ObfuscationSettings?) { @@ -289,10 +289,7 @@ class MullvadDaemon( playPurchase: PlayPurchase, ): PlayPurchaseVerifyResult - private external fun updateRelaySettings( - daemonInterfaceAddress: Long, - update: RelaySettingsUpdate - ) + private external fun setRelaySettings(daemonInterfaceAddress: Long, update: RelaySettings) private external fun setObfuscationSettings( daemonInterfaceAddress: Long, diff --git a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt index 6974d804a1..7a0b3fbe97 100644 --- a/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt +++ b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt @@ -12,9 +12,9 @@ import net.mullvad.mullvadvpn.lib.ipc.Request import net.mullvad.mullvadvpn.model.Constraint import net.mullvad.mullvadvpn.model.GeographicLocationConstraint import net.mullvad.mullvadvpn.model.LocationConstraint -import net.mullvad.mullvadvpn.model.RelayConstraintsUpdate +import net.mullvad.mullvadvpn.model.RelayConstraints import net.mullvad.mullvadvpn.model.RelayList -import net.mullvad.mullvadvpn.model.RelaySettingsUpdate +import net.mullvad.mullvadvpn.model.RelaySettings import net.mullvad.mullvadvpn.model.WireguardConstraints import net.mullvad.mullvadvpn.service.MullvadDaemon @@ -87,16 +87,18 @@ class RelayListListener(endpoint: ServiceEndpoint) { } private suspend fun updateRelayConstraints() { + val currentRelayConstraints = getCurrentRelayConstraints() val location: Constraint<LocationConstraint> = selectedRelayLocation?.let { location -> Constraint.Only(LocationConstraint.Location(location)) } - ?: Constraint.Any() - val wireguardConstraints: WireguardConstraints? = selectedWireguardConstraints + ?: currentRelayConstraints.location + val wireguardConstraints: WireguardConstraints = + selectedWireguardConstraints ?: currentRelayConstraints.wireguardConstraints val update = - RelaySettingsUpdate.Normal( - RelayConstraintsUpdate( + RelaySettings.Normal( + RelayConstraints( location = location, wireguardConstraints = wireguardConstraints, ownership = Constraint.Any(), @@ -104,9 +106,21 @@ class RelayListListener(endpoint: ServiceEndpoint) { ) ) - daemon.await().updateRelaySettings(update) + daemon.await().setRelaySettings(update) } + private suspend fun getCurrentRelayConstraints(): RelayConstraints = + when (val relaySettings = daemon.await().getSettings()?.relaySettings) { + is RelaySettings.Normal -> relaySettings.relayConstraints + else -> + RelayConstraints( + location = Constraint.Any(), + providers = Constraint.Any(), + ownership = Constraint.Any(), + wireguardConstraints = WireguardConstraints(Constraint.Any()) + ) + } + companion object { private enum class Command { SetRelayLocation, |
