diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt index 7b9e8f2c5550..e15b299b1604 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt @@ -316,7 +316,7 @@ class VpnSettingsScreenTest { VpnSettingsScreen( state = VpnSettingsUiState.createDefault( - customWireguardPort = Constraint.Only(Port(4000)) + customWireguardPort = Port(4000) ) ) } @@ -339,7 +339,7 @@ class VpnSettingsScreenTest { state = VpnSettingsUiState.createDefault( selectedWireguardPort = Constraint.Only(Port(4000)), - customWireguardPort = Constraint.Only(Port(4000)), + customWireguardPort = Port(4000), ), onWireguardPortSelected = onWireguardPortSelected, ) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/SelectObfuscationCell.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/ObfuscationModeCell.kt similarity index 80% rename from android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/SelectObfuscationCell.kt rename to android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/ObfuscationModeCell.kt index 7722f12bf790..495b9d61b39c 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/SelectObfuscationCell.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/ObfuscationModeCell.kt @@ -21,8 +21,8 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import net.mullvad.mullvadvpn.R import net.mullvad.mullvadvpn.compose.preview.SelectObfuscationCellPreviewParameterProvider import net.mullvad.mullvadvpn.lib.model.Constraint +import net.mullvad.mullvadvpn.lib.model.ObfuscationMode import net.mullvad.mullvadvpn.lib.model.Port -import net.mullvad.mullvadvpn.lib.model.SelectedObfuscation import net.mullvad.mullvadvpn.lib.theme.AppTheme import net.mullvad.mullvadvpn.lib.theme.Dimens import net.mullvad.mullvadvpn.lib.theme.color.selected @@ -31,13 +31,13 @@ import net.mullvad.mullvadvpn.lib.theme.typeface.listItemText @Preview @Composable -private fun PreviewSelectObfuscationCellCell( +private fun PreviewObfuscationCell( @PreviewParameter(SelectObfuscationCellPreviewParameterProvider::class) - selectedObfuscationCellData: Triple, Boolean> + selectedObfuscationCellData: Triple, Boolean> ) { AppTheme { - SelectObfuscationCell( - selectedObfuscation = selectedObfuscationCellData.first, + ObfuscationModeCell( + obfuscationMode = selectedObfuscationCellData.first, port = selectedObfuscationCellData.second, isSelected = selectedObfuscationCellData.third, onSelected = {}, @@ -47,11 +47,11 @@ private fun PreviewSelectObfuscationCellCell( } @Composable -fun SelectObfuscationCell( - selectedObfuscation: SelectedObfuscation, +fun ObfuscationModeCell( + obfuscationMode: ObfuscationMode, port: Constraint, isSelected: Boolean, - onSelected: (SelectedObfuscation) -> Unit, + onSelected: (ObfuscationMode) -> Unit, onNavigate: () -> Unit = {}, ) { Row( @@ -66,9 +66,9 @@ fun SelectObfuscationCell( titleColor = MaterialTheme.colorScheme.onSurface, subtitleStyle = MaterialTheme.typography.listItemSubText, subtitleColor = MaterialTheme.colorScheme.onSurface, - titleText = selectedObfuscation.toTitle(), + titleText = obfuscationMode.toTitle(), subtitleText = stringResource(id = R.string.port_x, port.toSubTitle()), - onCellClicked = { onSelected(selectedObfuscation) }, + onCellClicked = { onSelected(obfuscationMode) }, minHeight = Dimens.cellHeight, background = if (isSelected) { @@ -101,12 +101,12 @@ fun SelectObfuscationCell( } @Composable -private fun SelectedObfuscation.toTitle() = +private fun ObfuscationMode.toTitle() = when (this) { - SelectedObfuscation.Auto -> stringResource(id = R.string.automatic) - SelectedObfuscation.Off -> stringResource(id = R.string.off) - SelectedObfuscation.Udp2Tcp -> stringResource(id = R.string.upd_over_tcp) - SelectedObfuscation.Shadowsocks -> stringResource(id = R.string.shadowsocks) + ObfuscationMode.Auto -> stringResource(id = R.string.automatic) + ObfuscationMode.Off -> stringResource(id = R.string.off) + ObfuscationMode.Udp2Tcp -> stringResource(id = R.string.upd_over_tcp) + ObfuscationMode.Shadowsocks -> stringResource(id = R.string.shadowsocks) } @Composable diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/preview/SelectObfuscationCellPreviewParameterProvider.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/preview/SelectObfuscationCellPreviewParameterProvider.kt index b77efdba4fc8..646d4eb6e401 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/preview/SelectObfuscationCellPreviewParameterProvider.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/preview/SelectObfuscationCellPreviewParameterProvider.kt @@ -2,21 +2,21 @@ package net.mullvad.mullvadvpn.compose.preview import androidx.compose.ui.tooling.preview.PreviewParameterProvider import net.mullvad.mullvadvpn.lib.model.Constraint +import net.mullvad.mullvadvpn.lib.model.ObfuscationMode import net.mullvad.mullvadvpn.lib.model.Port -import net.mullvad.mullvadvpn.lib.model.SelectedObfuscation class SelectObfuscationCellPreviewParameterProvider : - PreviewParameterProvider, Boolean>> { - override val values: Sequence, Boolean>> = + PreviewParameterProvider, Boolean>> { + override val values: Sequence, Boolean>> = sequenceOf( - Triple(SelectedObfuscation.Shadowsocks, Constraint.Any, false), - Triple(SelectedObfuscation.Shadowsocks, Constraint.Any, true), - Triple(SelectedObfuscation.Shadowsocks, Constraint.Only(Port(PORT)), false), - Triple(SelectedObfuscation.Shadowsocks, Constraint.Only(Port(PORT)), true), - Triple(SelectedObfuscation.Udp2Tcp, Constraint.Any, false), - Triple(SelectedObfuscation.Udp2Tcp, Constraint.Any, true), - Triple(SelectedObfuscation.Udp2Tcp, Constraint.Only(Port(PORT)), false), - Triple(SelectedObfuscation.Udp2Tcp, Constraint.Only(Port(PORT)), true), + Triple(ObfuscationMode.Shadowsocks, Constraint.Any, false), + Triple(ObfuscationMode.Shadowsocks, Constraint.Any, true), + Triple(ObfuscationMode.Shadowsocks, Constraint.Only(Port(PORT)), false), + Triple(ObfuscationMode.Shadowsocks, Constraint.Only(Port(PORT)), true), + Triple(ObfuscationMode.Udp2Tcp, Constraint.Any, false), + Triple(ObfuscationMode.Udp2Tcp, Constraint.Any, true), + Triple(ObfuscationMode.Udp2Tcp, Constraint.Only(Port(PORT)), false), + Triple(ObfuscationMode.Udp2Tcp, Constraint.Only(Port(PORT)), true), ) } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreen.kt index 77123142cd9d..1a0a330bfc0b 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreen.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreen.kt @@ -65,7 +65,7 @@ import net.mullvad.mullvadvpn.compose.cell.MtuComposeCell import net.mullvad.mullvadvpn.compose.cell.MtuSubtitle import net.mullvad.mullvadvpn.compose.cell.NavigationComposeCell import net.mullvad.mullvadvpn.compose.cell.NormalSwitchComposeCell -import net.mullvad.mullvadvpn.compose.cell.SelectObfuscationCell +import net.mullvad.mullvadvpn.compose.cell.ObfuscationModeCell import net.mullvad.mullvadvpn.compose.cell.SelectableCell import net.mullvad.mullvadvpn.compose.cell.SwitchComposeSubtitleCell import net.mullvad.mullvadvpn.compose.communication.DnsDialogResult @@ -93,10 +93,10 @@ import net.mullvad.mullvadvpn.compose.util.showSnackbarImmediately import net.mullvad.mullvadvpn.constant.WIREGUARD_PRESET_PORTS import net.mullvad.mullvadvpn.lib.model.Constraint import net.mullvad.mullvadvpn.lib.model.Mtu +import net.mullvad.mullvadvpn.lib.model.ObfuscationMode import net.mullvad.mullvadvpn.lib.model.Port import net.mullvad.mullvadvpn.lib.model.PortRange import net.mullvad.mullvadvpn.lib.model.QuantumResistantState -import net.mullvad.mullvadvpn.lib.model.SelectedObfuscation import net.mullvad.mullvadvpn.lib.theme.AppTheme import net.mullvad.mullvadvpn.lib.theme.Dimens import net.mullvad.mullvadvpn.viewmodel.CustomDnsItem @@ -129,7 +129,7 @@ private fun PreviewVpnSettings() { navigateToDns = { _, _ -> }, onToggleDnsClick = {}, onBackClick = {}, - onSelectObfuscationSetting = {}, + onSelectObfuscationMode = {}, onSelectQuantumResistanceSetting = {}, onWireguardPortSelected = {}, ) @@ -264,7 +264,7 @@ fun VpnSettings( }, onToggleDnsClick = vm::onToggleCustomDns, onBackClick = dropUnlessResumed { navigator.navigateUp() }, - onSelectObfuscationSetting = vm::onSelectObfuscationSetting, + onSelectObfuscationMode = vm::onSelectObfuscationMode, onSelectQuantumResistanceSetting = vm::onSelectQuantumResistanceSetting, onWireguardPortSelected = vm::onWireguardPortSelected, navigateToShadowSocksSettings = @@ -305,7 +305,7 @@ fun VpnSettingsScreen( navigateToDns: (index: Int?, address: String?) -> Unit = { _, _ -> }, onToggleDnsClick: (Boolean) -> Unit = {}, onBackClick: () -> Unit = {}, - onSelectObfuscationSetting: (selectedObfuscation: SelectedObfuscation) -> Unit = {}, + onSelectObfuscationMode: (obfuscationMode: ObfuscationMode) -> Unit = {}, onSelectQuantumResistanceSetting: (quantumResistant: QuantumResistantState) -> Unit = {}, onWireguardPortSelected: (port: Constraint) -> Unit = {}, navigateToShadowSocksSettings: () -> Unit = {}, @@ -593,33 +593,33 @@ fun VpnSettingsScreen( itemWithDivider { SelectableCell( title = stringResource(id = R.string.automatic), - isSelected = state.selectedObfuscation == SelectedObfuscation.Auto, - onCellClicked = { onSelectObfuscationSetting(SelectedObfuscation.Auto) }, + isSelected = state.obfuscationMode == ObfuscationMode.Auto, + onCellClicked = { onSelectObfuscationMode(ObfuscationMode.Auto) }, ) } itemWithDivider { - SelectObfuscationCell( - selectedObfuscation = SelectedObfuscation.Shadowsocks, - isSelected = state.selectedObfuscation == SelectedObfuscation.Shadowsocks, + ObfuscationModeCell( + obfuscationMode = ObfuscationMode.Shadowsocks, + isSelected = state.obfuscationMode == ObfuscationMode.Shadowsocks, port = state.selectedShadowsSocksObfuscationPort, - onSelected = onSelectObfuscationSetting, + onSelected = onSelectObfuscationMode, onNavigate = navigateToShadowSocksSettings, ) } itemWithDivider { - SelectObfuscationCell( - selectedObfuscation = SelectedObfuscation.Udp2Tcp, - isSelected = state.selectedObfuscation == SelectedObfuscation.Udp2Tcp, + ObfuscationModeCell( + obfuscationMode = ObfuscationMode.Udp2Tcp, + isSelected = state.obfuscationMode == ObfuscationMode.Udp2Tcp, port = state.selectedUdp2TcpObfuscationPort, - onSelected = onSelectObfuscationSetting, + onSelected = onSelectObfuscationMode, onNavigate = navigateToUdp2TcpSettings, ) } itemWithDivider { SelectableCell( title = stringResource(id = R.string.off), - isSelected = state.selectedObfuscation == SelectedObfuscation.Off, - onCellClicked = { onSelectObfuscationSetting(SelectedObfuscation.Off) }, + isSelected = state.obfuscationMode == ObfuscationMode.Off, + onCellClicked = { onSelectObfuscationMode(ObfuscationMode.Off) }, ) } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/VpnSettingsUiState.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/VpnSettingsUiState.kt index ae51dde98802..7884f199f2c4 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/VpnSettingsUiState.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/VpnSettingsUiState.kt @@ -3,10 +3,10 @@ package net.mullvad.mullvadvpn.compose.state import net.mullvad.mullvadvpn.lib.model.Constraint import net.mullvad.mullvadvpn.lib.model.DefaultDnsOptions import net.mullvad.mullvadvpn.lib.model.Mtu +import net.mullvad.mullvadvpn.lib.model.ObfuscationMode import net.mullvad.mullvadvpn.lib.model.Port import net.mullvad.mullvadvpn.lib.model.PortRange import net.mullvad.mullvadvpn.lib.model.QuantumResistantState -import net.mullvad.mullvadvpn.lib.model.SelectedObfuscation import net.mullvad.mullvadvpn.viewmodel.CustomDnsItem data class VpnSettingsUiState( @@ -17,7 +17,7 @@ data class VpnSettingsUiState( val isCustomDnsEnabled: Boolean, val customDnsItems: List, val contentBlockersOptions: DefaultDnsOptions, - val selectedObfuscation: SelectedObfuscation, + val obfuscationMode: ObfuscationMode, val selectedUdp2TcpObfuscationPort: Constraint, val selectedShadowsSocksObfuscationPort: Constraint, val quantumResistant: QuantumResistantState, @@ -39,7 +39,7 @@ data class VpnSettingsUiState( isCustomDnsEnabled: Boolean = false, customDnsItems: List = emptyList(), contentBlockersOptions: DefaultDnsOptions = DefaultDnsOptions(), - selectedObfuscation: SelectedObfuscation = SelectedObfuscation.Off, + obfuscationMode: ObfuscationMode = ObfuscationMode.Off, selectedUdp2TcpObfuscationPort: Constraint = Constraint.Any, selectedShadowsSocksObfuscationPort: Constraint = Constraint.Any, quantumResistant: QuantumResistantState = QuantumResistantState.Off, @@ -56,7 +56,7 @@ data class VpnSettingsUiState( isCustomDnsEnabled, customDnsItems, contentBlockersOptions, - selectedObfuscation, + obfuscationMode, selectedUdp2TcpObfuscationPort, selectedShadowsSocksObfuscationPort, quantumResistant, diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/SettingsRepository.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/SettingsRepository.kt index ef384f57a573..b99b73339940 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/SettingsRepository.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/SettingsRepository.kt @@ -14,9 +14,9 @@ import net.mullvad.mullvadvpn.lib.model.DefaultDnsOptions import net.mullvad.mullvadvpn.lib.model.DnsOptions import net.mullvad.mullvadvpn.lib.model.DnsState import net.mullvad.mullvadvpn.lib.model.Mtu +import net.mullvad.mullvadvpn.lib.model.ObfuscationMode import net.mullvad.mullvadvpn.lib.model.Port import net.mullvad.mullvadvpn.lib.model.QuantumResistantState -import net.mullvad.mullvadvpn.lib.model.SelectedObfuscation import net.mullvad.mullvadvpn.lib.model.Settings class SettingsRepository( @@ -65,7 +65,7 @@ class SettingsRepository( suspend fun setWireguardQuantumResistant(value: QuantumResistantState) = managementService.setWireguardQuantumResistant(value) - suspend fun setObfuscation(value: SelectedObfuscation) = managementService.setObfuscation(value) + suspend fun setObfuscation(value: ObfuscationMode) = managementService.setObfuscation(value) suspend fun setAutoConnect(isEnabled: Boolean) = managementService.setAutoConnect(isEnabled) 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 189d06cdfac0..3baeda244a10 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 @@ -23,9 +23,9 @@ import net.mullvad.mullvadvpn.constant.WIREGUARD_PRESET_PORTS import net.mullvad.mullvadvpn.lib.model.Constraint import net.mullvad.mullvadvpn.lib.model.DefaultDnsOptions import net.mullvad.mullvadvpn.lib.model.DnsState +import net.mullvad.mullvadvpn.lib.model.ObfuscationMode import net.mullvad.mullvadvpn.lib.model.Port import net.mullvad.mullvadvpn.lib.model.QuantumResistantState -import net.mullvad.mullvadvpn.lib.model.SelectedObfuscation import net.mullvad.mullvadvpn.lib.model.Settings import net.mullvad.mullvadvpn.lib.model.WireguardConstraints import net.mullvad.mullvadvpn.repository.RelayListRepository @@ -68,8 +68,7 @@ class VpnSettingsViewModel( customDnsList = settings?.addresses()?.asStringAddressList() ?: listOf(), contentBlockersOptions = settings?.contentBlockersSettings() ?: DefaultDnsOptions(), - selectedObfuscation = - settings?.selectedObfuscationSettings() ?: SelectedObfuscation.Off, + obfuscationMode = settings?.selectedObfuscationMode() ?: ObfuscationMode.Off, selectedUdp2TcpObfuscationPort = settings?.obfuscationSettings?.udp2tcp?.port ?: Constraint.Any, selectedShadowsocksObfuscationPort = @@ -211,9 +210,9 @@ class VpnSettingsViewModel( } } - fun onSelectObfuscationSetting(selectedObfuscation: SelectedObfuscation) { + fun onSelectObfuscationMode(obfuscationMode: ObfuscationMode) { viewModelScope.launch(dispatcher) { - repository.setObfuscation(selectedObfuscation).onLeft { + repository.setObfuscation(obfuscationMode).onLeft { _uiSideEffect.send(VpnSettingsSideEffect.ShowToast.GenericError) } } @@ -289,7 +288,7 @@ class VpnSettingsViewModel( private fun Settings.contentBlockersSettings() = tunnelOptions.dnsOptions.defaultOptions - private fun Settings.selectedObfuscationSettings() = obfuscationSettings.selectedObfuscation + private fun Settings.selectedObfuscationMode() = obfuscationSettings.selectedObfuscationMode private fun Settings.getWireguardPort() = relaySettings.relayConstraints.wireguardConstraints.port diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelState.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelState.kt index e98431d59f26..31d5515a3c90 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelState.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelState.kt @@ -4,10 +4,10 @@ import net.mullvad.mullvadvpn.compose.state.VpnSettingsUiState import net.mullvad.mullvadvpn.lib.model.Constraint import net.mullvad.mullvadvpn.lib.model.DefaultDnsOptions import net.mullvad.mullvadvpn.lib.model.Mtu +import net.mullvad.mullvadvpn.lib.model.ObfuscationMode import net.mullvad.mullvadvpn.lib.model.Port import net.mullvad.mullvadvpn.lib.model.PortRange import net.mullvad.mullvadvpn.lib.model.QuantumResistantState -import net.mullvad.mullvadvpn.lib.model.SelectedObfuscation data class VpnSettingsViewModelState( val mtuValue: Mtu?, @@ -17,7 +17,7 @@ data class VpnSettingsViewModelState( val isCustomDnsEnabled: Boolean, val customDnsList: List, val contentBlockersOptions: DefaultDnsOptions, - val selectedObfuscation: SelectedObfuscation, + val obfuscationMode: ObfuscationMode, val selectedUdp2TcpObfuscationPort: Constraint, val selectedShadowsocksObfuscationPort: Constraint, val quantumResistant: QuantumResistantState, @@ -39,7 +39,7 @@ data class VpnSettingsViewModelState( isCustomDnsEnabled, customDnsList, contentBlockersOptions, - selectedObfuscation, + obfuscationMode, selectedUdp2TcpObfuscationPort, selectedShadowsocksObfuscationPort, quantumResistant, @@ -59,7 +59,7 @@ data class VpnSettingsViewModelState( isCustomDnsEnabled = false, customDnsList = listOf(), contentBlockersOptions = DefaultDnsOptions(), - selectedObfuscation = SelectedObfuscation.Auto, + obfuscationMode = ObfuscationMode.Auto, selectedUdp2TcpObfuscationPort = Constraint.Any, selectedShadowsocksObfuscationPort = Constraint.Any, quantumResistant = QuantumResistantState.Off, diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ShadowsocksSettingsViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ShadowsocksSettingsViewModelTest.kt index 178bce365bc8..5340914aaf76 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ShadowsocksSettingsViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ShadowsocksSettingsViewModelTest.kt @@ -65,10 +65,13 @@ class ShadowsocksSettingsViewModelTest { @Test fun `uiState should reflect latest port range value from relay list`() = runTest { // Arrange + val mockSettings: Settings = mockk() + val port = Port(123) + every { mockSettings.obfuscationSettings.shadowsocks.port } returns Constraint.Only(port) val mockPortRange: List = listOf(mockk()) portRangesFlow.update { mockPortRange } - settingsFlow.update { mockk(relaxed = true) } + settingsFlow.update { mockSettings } // Act, Assert viewModel.uiState.test { 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 5ed7cf5b8470..1e15b1956a31 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 @@ -122,6 +122,8 @@ class VpnSettingsViewModelTest { every { mockSettings.tunnelOptions } returns mockTunnelOptions every { mockTunnelOptions.wireguard } returns mockWireguardTunnelOptions every { mockSettings.relaySettings } returns mockk(relaxed = true) + every { mockSettings.relaySettings.relayConstraints.wireguardConstraints.port } returns + Constraint.Any viewModel.uiState.test { assertEquals(defaultResistantState, awaitItem().quantumResistant) @@ -134,7 +136,7 @@ class VpnSettingsViewModelTest { fun `when SettingsRepository emits Constraint Only then uiState should emit custom and selectedWireguardPort with port of Constraint`() = runTest { // Arrange - val expectedPort: Constraint = Constraint.Only(Port(99)) + val expectedPort = Constraint.Only(Port(99)) val mockSettings: Settings = mockk(relaxed = true) val mockRelaySettings: RelaySettings = mockk() val mockRelayConstraints: RelayConstraints = mockk() @@ -159,7 +161,7 @@ class VpnSettingsViewModelTest { viewModel.uiState.test { assertIs(awaitItem().selectedWireguardPort) mockSettingsUpdate.value = mockSettings - assertEquals(expectedPort, awaitItem().customWireguardPort) + assertEquals(expectedPort.value, awaitItem().customWireguardPort) assertEquals(expectedPort, awaitItem().selectedWireguardPort) } } diff --git a/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt b/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt index 7b885d960621..514d4f83aa6b 100644 --- a/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt +++ b/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt @@ -81,6 +81,7 @@ import net.mullvad.mullvadvpn.lib.model.LoginAccountError import net.mullvad.mullvadvpn.lib.model.LogoutAccountError import net.mullvad.mullvadvpn.lib.model.NameAlreadyExists import net.mullvad.mullvadvpn.lib.model.NewAccessMethodSetting +import net.mullvad.mullvadvpn.lib.model.ObfuscationMode import net.mullvad.mullvadvpn.lib.model.ObfuscationSettings import net.mullvad.mullvadvpn.lib.model.Ownership as ModelOwnership import net.mullvad.mullvadvpn.lib.model.PlayPurchase @@ -100,7 +101,6 @@ import net.mullvad.mullvadvpn.lib.model.RelayList import net.mullvad.mullvadvpn.lib.model.RelaySettings import net.mullvad.mullvadvpn.lib.model.RemoveApiAccessMethodError import net.mullvad.mullvadvpn.lib.model.RemoveSplitTunnelingAppError -import net.mullvad.mullvadvpn.lib.model.SelectedObfuscation import net.mullvad.mullvadvpn.lib.model.SetAllowLanError import net.mullvad.mullvadvpn.lib.model.SetApiAccessMethodError import net.mullvad.mullvadvpn.lib.model.SetAutoConnectError @@ -129,7 +129,7 @@ import net.mullvad.mullvadvpn.lib.model.location import net.mullvad.mullvadvpn.lib.model.ownership import net.mullvad.mullvadvpn.lib.model.providers import net.mullvad.mullvadvpn.lib.model.relayConstraints -import net.mullvad.mullvadvpn.lib.model.selectedObfuscation +import net.mullvad.mullvadvpn.lib.model.selectedObfuscationMode import net.mullvad.mullvadvpn.lib.model.shadowsocks import net.mullvad.mullvadvpn.lib.model.state import net.mullvad.mullvadvpn.lib.model.udp2tcp @@ -461,12 +461,10 @@ class ManagementService( .mapLeft(SetWireguardQuantumResistantError::Unknown) .mapEmpty() - suspend fun setObfuscation( - value: SelectedObfuscation - ): Either = + suspend fun setObfuscation(value: ObfuscationMode): Either = Either.catch { val updatedObfuscationSettings = - ObfuscationSettings.selectedObfuscation.modify( + ObfuscationSettings.selectedObfuscationMode.modify( getSettings().obfuscationSettings ) { value diff --git a/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/mapper/FromDomain.kt b/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/mapper/FromDomain.kt index d6e7888fd0c5..84a826f10452 100644 --- a/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/mapper/FromDomain.kt +++ b/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/mapper/FromDomain.kt @@ -13,6 +13,7 @@ import net.mullvad.mullvadvpn.lib.model.DnsOptions import net.mullvad.mullvadvpn.lib.model.DnsState import net.mullvad.mullvadvpn.lib.model.GeoLocationId import net.mullvad.mullvadvpn.lib.model.NewAccessMethodSetting +import net.mullvad.mullvadvpn.lib.model.ObfuscationMode import net.mullvad.mullvadvpn.lib.model.ObfuscationSettings import net.mullvad.mullvadvpn.lib.model.Ownership import net.mullvad.mullvadvpn.lib.model.PlayPurchase @@ -21,7 +22,6 @@ import net.mullvad.mullvadvpn.lib.model.Port import net.mullvad.mullvadvpn.lib.model.Providers import net.mullvad.mullvadvpn.lib.model.RelayItemId import net.mullvad.mullvadvpn.lib.model.RelaySettings -import net.mullvad.mullvadvpn.lib.model.SelectedObfuscation import net.mullvad.mullvadvpn.lib.model.ShadowsocksSettings import net.mullvad.mullvadvpn.lib.model.SocksAuth import net.mullvad.mullvadvpn.lib.model.TransportProtocol @@ -79,20 +79,20 @@ internal fun DefaultDnsOptions.fromDomain(): ManagementInterface.DefaultDnsOptio internal fun ObfuscationSettings.fromDomain(): ManagementInterface.ObfuscationSettings = ManagementInterface.ObfuscationSettings.newBuilder() - .setSelectedObfuscation(selectedObfuscation.fromDomain()) + .setSelectedObfuscation(selectedObfuscationMode.fromDomain()) .setUdp2Tcp(udp2tcp.fromDomain()) .setShadowsocks(shadowsocks.fromDomain()) .build() -internal fun SelectedObfuscation.fromDomain(): +internal fun ObfuscationMode.fromDomain(): ManagementInterface.ObfuscationSettings.SelectedObfuscation = when (this) { - SelectedObfuscation.Udp2Tcp -> + ObfuscationMode.Udp2Tcp -> ManagementInterface.ObfuscationSettings.SelectedObfuscation.UDP2TCP - SelectedObfuscation.Shadowsocks -> + ObfuscationMode.Shadowsocks -> ManagementInterface.ObfuscationSettings.SelectedObfuscation.SHADOWSOCKS - SelectedObfuscation.Auto -> ManagementInterface.ObfuscationSettings.SelectedObfuscation.AUTO - SelectedObfuscation.Off -> ManagementInterface.ObfuscationSettings.SelectedObfuscation.OFF + ObfuscationMode.Auto -> ManagementInterface.ObfuscationSettings.SelectedObfuscation.AUTO + ObfuscationMode.Off -> ManagementInterface.ObfuscationSettings.SelectedObfuscation.OFF } internal fun Udp2TcpObfuscationSettings.fromDomain(): diff --git a/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/mapper/ToDomain.kt b/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/mapper/ToDomain.kt index 764ebe1d94d9..212b93fc682a 100644 --- a/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/mapper/ToDomain.kt +++ b/android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/mapper/ToDomain.kt @@ -7,7 +7,6 @@ import java.net.InetAddress import java.net.InetSocketAddress import java.util.UUID import mullvad_daemon.management_interface.ManagementInterface -import mullvad_daemon.management_interface.shadowsocks import net.mullvad.mullvadvpn.lib.daemon.grpc.GrpcConnectivityState import net.mullvad.mullvadvpn.lib.daemon.grpc.RelayNameComparator import net.mullvad.mullvadvpn.lib.model.AccountData @@ -40,6 +39,7 @@ import net.mullvad.mullvadvpn.lib.model.GeoIpLocation import net.mullvad.mullvadvpn.lib.model.GeoLocationId import net.mullvad.mullvadvpn.lib.model.Mtu import net.mullvad.mullvadvpn.lib.model.ObfuscationEndpoint +import net.mullvad.mullvadvpn.lib.model.ObfuscationMode import net.mullvad.mullvadvpn.lib.model.ObfuscationSettings import net.mullvad.mullvadvpn.lib.model.ObfuscationType import net.mullvad.mullvadvpn.lib.model.Ownership @@ -58,7 +58,6 @@ import net.mullvad.mullvadvpn.lib.model.RelayItemId import net.mullvad.mullvadvpn.lib.model.RelayList import net.mullvad.mullvadvpn.lib.model.RelayOverride import net.mullvad.mullvadvpn.lib.model.RelaySettings -import net.mullvad.mullvadvpn.lib.model.SelectedObfuscation import net.mullvad.mullvadvpn.lib.model.Settings import net.mullvad.mullvadvpn.lib.model.ShadowsocksSettings import net.mullvad.mullvadvpn.lib.model.SocksAuth @@ -336,20 +335,20 @@ internal fun ManagementInterface.Ownership.toDomain(): Constraint = internal fun ManagementInterface.ObfuscationSettings.toDomain(): ObfuscationSettings = ObfuscationSettings( - selectedObfuscation = selectedObfuscation.toDomain(), + selectedObfuscationMode = selectedObfuscation.toDomain(), udp2tcp = udp2Tcp.toDomain(), shadowsocks = shadowsocks.toDomain(), ) internal fun ManagementInterface.ObfuscationSettings.SelectedObfuscation.toDomain(): - SelectedObfuscation = + ObfuscationMode = when (this) { - ManagementInterface.ObfuscationSettings.SelectedObfuscation.AUTO -> SelectedObfuscation.Auto - ManagementInterface.ObfuscationSettings.SelectedObfuscation.OFF -> SelectedObfuscation.Off + ManagementInterface.ObfuscationSettings.SelectedObfuscation.AUTO -> ObfuscationMode.Auto + ManagementInterface.ObfuscationSettings.SelectedObfuscation.OFF -> ObfuscationMode.Off ManagementInterface.ObfuscationSettings.SelectedObfuscation.UDP2TCP -> - SelectedObfuscation.Udp2Tcp + ObfuscationMode.Udp2Tcp ManagementInterface.ObfuscationSettings.SelectedObfuscation.SHADOWSOCKS -> - SelectedObfuscation.Shadowsocks + ObfuscationMode.Shadowsocks ManagementInterface.ObfuscationSettings.SelectedObfuscation.UNRECOGNIZED -> throw IllegalArgumentException("Unrecognized selected obfuscation") } diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/SelectedObfuscation.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/ObfuscationMode.kt similarity index 73% rename from android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/SelectedObfuscation.kt rename to android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/ObfuscationMode.kt index 3429f7cacbd2..7e4101e97313 100644 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/SelectedObfuscation.kt +++ b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/ObfuscationMode.kt @@ -1,6 +1,6 @@ package net.mullvad.mullvadvpn.lib.model -enum class SelectedObfuscation { +enum class ObfuscationMode { Auto, Off, Udp2Tcp, diff --git a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/ObfuscationSettings.kt b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/ObfuscationSettings.kt index 4522164b1cc3..4425abd39b7c 100644 --- a/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/ObfuscationSettings.kt +++ b/android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/lib/model/ObfuscationSettings.kt @@ -4,7 +4,7 @@ import arrow.optics.optics @optics data class ObfuscationSettings( - val selectedObfuscation: SelectedObfuscation, + val selectedObfuscationMode: ObfuscationMode, val udp2tcp: Udp2TcpObfuscationSettings, val shadowsocks: ShadowsocksSettings, ) {