diff options
| author | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2023-10-27 15:12:35 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2023-10-31 00:45:17 +0100 |
| commit | 5c491337ba76b999137fa4c0071ed5b6e0079eb4 (patch) | |
| tree | 8a39c6083bf1831d519bd5b121ab5e7ad5f50017 /android | |
| parent | 6394e37f888b4e1c91cbf34e388daf80764f6ca0 (diff) | |
| download | mullvadvpn-5c491337ba76b999137fa4c0071ed5b6e0079eb4.tar.xz mullvadvpn-5c491337ba76b999137fa4c0071ed5b6e0079eb4.zip | |
Fix bug that would reset location constraint
Diffstat (limited to 'android')
7 files changed, 40 insertions, 39 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..4eb5a35141 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 @@ -77,14 +77,14 @@ class VpnSettingsViewModel( isLocalNetworkSharingEnabled = settings?.allowLan ?: false, isCustomDnsEnabled = settings?.isCustomDnsEnabled() ?: false, customDnsList = settings?.addresses()?.asStringAddressList() ?: listOf(), - contentBlockersOptions = settings?.contentBlockersSettings() - ?: DefaultDnsOptions(), + contentBlockersOptions = + settings?.contentBlockersSettings() ?: DefaultDnsOptions(), isAllowLanEnabled = settings?.allowLan ?: false, - selectedObfuscation = settings?.selectedObfuscationSettings() - ?: SelectedObfuscation.Off, + selectedObfuscation = + settings?.selectedObfuscationSettings() ?: SelectedObfuscation.Off, dialogState = dialogState, - quantumResistant = settings?.quantumResistant() - ?: QuantumResistantState.Off, + quantumResistant = + settings?.quantumResistant() ?: QuantumResistantState.Off, selectedWireguardPort = settings?.getWireguardPort() ?: Constraint.Any(), availablePortRanges = portRanges ) @@ -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/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/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/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt b/android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt index 9110ac08ab..0b9e15774a 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 @@ -289,7 +289,7 @@ class MullvadDaemon( playPurchase: PlayPurchase, ): PlayPurchaseVerifyResult - private external fun updateRelaySettings( + private external fun setRelaySettings( daemonInterfaceAddress: Long, update: RelaySettings ) 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 1884b98737..2fc1e4115a 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 @@ -87,12 +87,13 @@ 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 = RelaySettings.Normal( @@ -107,6 +108,18 @@ class RelayListListener(endpoint: ServiceEndpoint) { 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, |
