summaryrefslogtreecommitdiffhomepage
path: root/android/app
diff options
context:
space:
mode:
authorJonatan Rhodin <jonatan.rhodin@mullvad.net>2025-03-04 00:46:40 +0100
committerJonatan Rhodin <jonatan.rhodin@mullvad.net>2025-03-07 11:27:47 +0100
commit090031ba37c2b324ff764ee2b4f7c214dccbe740 (patch)
tree17874a400d906b7f89882520a3669c3072a796ca /android/app
parent22024b10974af49762a60700110e7bf9b8d4398a (diff)
downloadmullvadvpn-090031ba37c2b324ff764ee2b4f7c214dccbe740.tar.xz
mullvadvpn-090031ba37c2b324ff764ee2b4f7c214dccbe740.zip
Implement device ip version ui
Diffstat (limited to 'android/app')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreen.kt30
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/VpnSettingsUiState.kt4
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt25
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelState.kt4
4 files changed, 53 insertions, 10 deletions
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 779b4792b4..2989dba047 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
@@ -93,6 +93,7 @@ import net.mullvad.mullvadvpn.compose.util.OnNavResultValue
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.IpVersion
import net.mullvad.mullvadvpn.lib.model.Mtu
import net.mullvad.mullvadvpn.lib.model.ObfuscationMode
import net.mullvad.mullvadvpn.lib.model.Port
@@ -140,6 +141,7 @@ private fun PreviewVpnSettings(
navigateToLocalNetworkSharingInfo = {},
navigateToWireguardPortDialog = {},
navigateToServerIpOverrides = {},
+ onSelectDeviceIpVersion = {},
)
}
}
@@ -268,6 +270,7 @@ fun VpnSettings(
navigateToUdp2TcpSettings =
dropUnlessResumed { navigator.navigate(Udp2TcpSettingsDestination) },
onToggleAutoStartAndConnectOnBoot = vm::onToggleAutoStartAndConnectOnBoot,
+ onSelectDeviceIpVersion = vm::onDeviceIpVersionSelected,
)
}
@@ -304,6 +307,7 @@ fun VpnSettingsScreen(
navigateToShadowSocksSettings: () -> Unit,
navigateToUdp2TcpSettings: () -> Unit,
onToggleAutoStartAndConnectOnBoot: (Boolean) -> Unit,
+ onSelectDeviceIpVersion: (ipVersion: Constraint<IpVersion>) -> Unit,
) {
var expandContentBlockersState by rememberSaveable { mutableStateOf(false) }
val biggerPadding = 54.dp
@@ -651,6 +655,32 @@ fun VpnSettingsScreen(
Spacer(modifier = Modifier.height(Dimens.cellVerticalSpacing))
}
+ itemWithDivider {
+ InformationComposeCell(title = stringResource(R.string.device_ip_version_title))
+ }
+ itemWithDivider {
+ SelectableCell(
+ title = stringResource(id = R.string.automatic),
+ isSelected = state.deviceIpVersion == Constraint.Any,
+ onCellClicked = { onSelectDeviceIpVersion(Constraint.Any) },
+ )
+ }
+ itemWithDivider {
+ SelectableCell(
+ title = stringResource(id = R.string.device_ip_version_ipv4),
+ isSelected = state.deviceIpVersion.getOrNull() == IpVersion.IPV4,
+ onCellClicked = { onSelectDeviceIpVersion(Constraint.Only(IpVersion.IPV4)) },
+ )
+ }
+ item {
+ SelectableCell(
+ title = stringResource(id = R.string.device_ip_version_ipv6),
+ isSelected = state.deviceIpVersion.getOrNull() == IpVersion.IPV6,
+ onCellClicked = { onSelectDeviceIpVersion(Constraint.Only(IpVersion.IPV6)) },
+ )
+ Spacer(modifier = Modifier.height(Dimens.cellVerticalSpacing))
+ }
+
item {
MtuComposeCell(mtuValue = state.mtu, onEditMtu = { navigateToMtuDialog(state.mtu) })
}
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 c9fd0257c0..ec069001cc 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
@@ -2,6 +2,7 @@ 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.IpVersion
import net.mullvad.mullvadvpn.lib.model.Mtu
import net.mullvad.mullvadvpn.lib.model.ObfuscationMode
import net.mullvad.mullvadvpn.lib.model.Port
@@ -24,6 +25,7 @@ data class VpnSettingsUiState(
val availablePortRanges: List<PortRange>,
val systemVpnSettingsAvailable: Boolean,
val autoStartAndConnectOnBoot: Boolean,
+ val deviceIpVersion: Constraint<IpVersion>,
) {
val isCustomWireguardPort =
selectedWireguardPort is Constraint.Only &&
@@ -48,6 +50,7 @@ data class VpnSettingsUiState(
availablePortRanges: List<PortRange> = emptyList(),
systemVpnSettingsAvailable: Boolean = false,
autoStartAndConnectOnBoot: Boolean = false,
+ deviceIpVersion: Constraint<IpVersion> = Constraint.Any,
) =
VpnSettingsUiState(
mtu,
@@ -64,6 +67,7 @@ data class VpnSettingsUiState(
availablePortRanges,
systemVpnSettingsAvailable,
autoStartAndConnectOnBoot,
+ deviceIpVersion,
)
}
}
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 90f98fceaa..2273ada5e0 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,6 +23,7 @@ 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.IpVersion
import net.mullvad.mullvadvpn.lib.model.ObfuscationMode
import net.mullvad.mullvadvpn.lib.model.Port
import net.mullvad.mullvadvpn.lib.model.QuantumResistantState
@@ -46,7 +47,7 @@ sealed interface VpnSettingsSideEffect {
@Suppress("TooManyFunctions")
class VpnSettingsViewModel(
private val repository: SettingsRepository,
- private val relayListRepository: RelayListRepository,
+ relayListRepository: RelayListRepository,
private val systemVpnSettingsUseCase: SystemVpnSettingsAvailableUseCase,
private val autoStartAndConnectOnBootRepository: AutoStartAndConnectOnBootRepository,
private val wireguardConstraintsRepository: WireguardConstraintsRepository,
@@ -83,6 +84,7 @@ class VpnSettingsViewModel(
availablePortRanges = portRanges,
systemVpnSettingsAvailable = systemVpnSettingsUseCase(),
autoStartAndConnectOnBoot = autoStartAndConnectOnBoot,
+ deviceIpVersion = settings?.getDeviceIpVersion() ?: Constraint.Any,
)
}
.stateIn(
@@ -122,14 +124,6 @@ class VpnSettingsViewModel(
}
}
- fun onToggleDaita(enable: Boolean) {
- viewModelScope.launch(dispatcher) {
- repository.setDaitaEnabled(enable).onLeft {
- _uiSideEffect.send(VpnSettingsSideEffect.ShowToast.GenericError)
- }
- }
- }
-
fun onDnsDialogDismissed() {
if (vmState.value.customDnsList.isEmpty()) {
onToggleCustomDns(enable = false)
@@ -251,6 +245,14 @@ class VpnSettingsViewModel(
}
}
+ fun onDeviceIpVersionSelected(ipVersion: Constraint<IpVersion>) {
+ viewModelScope.launch(dispatcher) {
+ wireguardConstraintsRepository.setDeviceIpVersion(ipVersion).onLeft {
+ _uiSideEffect.send(VpnSettingsSideEffect.ShowToast.GenericError)
+ }
+ }
+ }
+
private fun updateDefaultDnsOptionsViaRepository(contentBlockersOption: DefaultDnsOptions) =
viewModelScope.launch(dispatcher) {
repository
@@ -265,7 +267,7 @@ class VpnSettingsViewModel(
private fun List<String>.asInetAddressList(): List<InetAddress> {
return try {
map { InetAddress.getByName(it) }
- } catch (ex: UnknownHostException) {
+ } catch (_: UnknownHostException) {
Logger.e("Error parsing the DNS address list.")
emptyList()
}
@@ -290,6 +292,9 @@ class VpnSettingsViewModel(
private fun Settings.getWireguardPort() =
relaySettings.relayConstraints.wireguardConstraints.port
+ private fun Settings.getDeviceIpVersion() =
+ relaySettings.relayConstraints.wireguardConstraints.ipVersion
+
private fun InetAddress.isLocalAddress(): Boolean {
return isLinkLocalAddress || isSiteLocalAddress
}
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 e8ccf8f4a0..6e91294257 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
@@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.viewmodel
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.IpVersion
import net.mullvad.mullvadvpn.lib.model.Mtu
import net.mullvad.mullvadvpn.lib.model.ObfuscationMode
import net.mullvad.mullvadvpn.lib.model.Port
@@ -24,6 +25,7 @@ data class VpnSettingsViewModelState(
val availablePortRanges: List<PortRange>,
val systemVpnSettingsAvailable: Boolean,
val autoStartAndConnectOnBoot: Boolean,
+ val deviceIpVersion: Constraint<IpVersion>,
) {
val isCustomWireguardPort =
selectedWireguardPort is Constraint.Only &&
@@ -45,6 +47,7 @@ data class VpnSettingsViewModelState(
availablePortRanges,
systemVpnSettingsAvailable,
autoStartAndConnectOnBoot,
+ deviceIpVersion,
)
companion object {
@@ -64,6 +67,7 @@ data class VpnSettingsViewModelState(
availablePortRanges = emptyList(),
systemVpnSettingsAvailable = false,
autoStartAndConnectOnBoot = false,
+ deviceIpVersion = Constraint.Any,
)
}
}