From 7b0c6e5014d0cc641608875d1705eb42c8405c91 Mon Sep 17 00:00:00 2001 From: Jonatan Rhodin Date: Mon, 2 Sep 2024 16:27:44 +0200 Subject: [PATCH] More fixes based on feedback --- .../net/mullvad/mullvadvpn/constant/WireguardConstant.kt | 3 ++- .../mullvadvpn/viewmodel/ShadowsocksSettingsViewModel.kt | 7 ++----- .../mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt | 4 ++-- .../main/kotlin/net/mullvad/mullvadvpn/lib/model/Port.kt | 4 ++-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/constant/WireguardConstant.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/constant/WireguardConstant.kt index b36c3267fc51..716dec302f2b 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/constant/WireguardConstant.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/constant/WireguardConstant.kt @@ -7,4 +7,5 @@ val WIREGUARD_PRESET_PORTS = listOf(Port(51820), Port(53)) val UDP2TCP_PRESET_PORTS = listOf(Port(80), Port(5001)) val SHADOWSOCKS_PRESET_PORTS = emptyList() val SHADOWSOCKS_AVAILABLE_PORTS = - listOf(PortRange(IntRange(0, 65535))) // Currently we consider all ports to be available + // Currently we consider all ports to be available + listOf(PortRange(IntRange(Port.MIN_VALUE, Port.MAX_VALUE))) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ShadowsocksSettingsViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ShadowsocksSettingsViewModel.kt index 9f629b0487af..18197e2e4263 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ShadowsocksSettingsViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ShadowsocksSettingsViewModel.kt @@ -50,7 +50,7 @@ class ShadowsocksSettingsViewModel( val initialSettings = settingsRepository.settingsUpdates.filterNotNull().first() customPort.update { val initialPort = initialSettings.getShadowSocksPort() - if (SHADOWSOCKS_PRESET_PORTS.contains(initialPort.getOrNull()).not()) { + if (initialPort.getOrNull() !in SHADOWSOCKS_PRESET_PORTS) { initialPort.getOrNull() } else { null @@ -65,10 +65,7 @@ class ShadowsocksSettingsViewModel( .setCustomShadowsocksObfuscationPort(port) .onLeft { Logger.e("Select shadowsocks port error $it") } .onRight { - if ( - port is Constraint.Only && - SHADOWSOCKS_PRESET_PORTS.contains(port.value).not() - ) { + if (port is Constraint.Only && port.value !in SHADOWSOCKS_PRESET_PORTS) { customPort.update { port.getOrNull() } } } 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 6b1f34cfa408..189d06cdfac0 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 @@ -101,7 +101,7 @@ class VpnSettingsViewModel( val initialSettings = repository.settingsUpdates.filterNotNull().first() customPort.update { val initialPort = initialSettings.getWireguardPort() - if (WIREGUARD_PRESET_PORTS.contains(initialPort.getOrNull()).not()) { + if (initialPort.getOrNull() !in WIREGUARD_PRESET_PORTS) { initialPort.getOrNull() } else { null @@ -232,7 +232,7 @@ class VpnSettingsViewModel( } fun onWireguardPortSelected(port: Constraint) { - if (port is Constraint.Only && WIREGUARD_PRESET_PORTS.contains(port.value).not()) { + if (port is Constraint.Only && port.value !in WIREGUARD_PRESET_PORTS) { customPort.update { port.value } } viewModelScope.launch { diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/Port.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/Port.kt index e6ca1e01b990..0f8bf37332be 100644 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/Port.kt +++ b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/Port.kt @@ -19,8 +19,8 @@ value class Port(val value: Int) : Parcelable { Port(number) } - private const val MIN_VALUE = 0 - private const val MAX_VALUE = 65535 + const val MIN_VALUE = 0 + const val MAX_VALUE = 65535 } }