Skip to content

Commit 8e613bd

Browse files
committed
Remove the auto-connect switch when vpn settings are available
1 parent f5a7735 commit 8e613bd

File tree

7 files changed

+40
-22
lines changed

7 files changed

+40
-22
lines changed

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreen.kt

+16-16
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import androidx.compose.runtime.saveable.rememberSaveable
2323
import androidx.compose.runtime.setValue
2424
import androidx.compose.ui.Modifier
2525
import androidx.compose.ui.graphics.Color
26-
import androidx.compose.ui.platform.LocalContext
2726
import androidx.compose.ui.platform.LocalLifecycleOwner
2827
import androidx.compose.ui.platform.testTag
2928
import androidx.compose.ui.res.stringResource
@@ -78,7 +77,6 @@ import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_CUSTOM_PORT_TEXT_
7877
import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_WIREGUARD_PORT_ITEM_X_TEST_TAG
7978
import net.mullvad.mullvadvpn.compose.transitions.SlideInFromRightTransition
8079
import net.mullvad.mullvadvpn.constant.WIREGUARD_PRESET_PORTS
81-
import net.mullvad.mullvadvpn.lib.common.util.vpnSettingsAvailable
8280
import net.mullvad.mullvadvpn.lib.theme.AppTheme
8381
import net.mullvad.mullvadvpn.lib.theme.Dimens
8482
import net.mullvad.mullvadvpn.model.Constraint
@@ -293,12 +291,11 @@ fun VpnSettingsScreen(
293291
navigationIcon = { NavigateBackIconButton(onBackClick) },
294292
snackbarHostState = snackbarHostState
295293
) { modifier, lazyListState ->
296-
val context = LocalContext.current
297294
LazyColumn(
298295
modifier = modifier.testTag(LAZY_LIST_TEST_TAG).animateContentSize(),
299296
state = lazyListState
300297
) {
301-
if (context.vpnSettingsAvailable()) {
298+
if (uiState.systemVpnSettingsAvailable) {
302299
item {
303300
Spacer(modifier = Modifier.height(Dimens.cellLabelVerticalPadding))
304301
NavigationComposeCell(
@@ -311,18 +308,21 @@ fun VpnSettingsScreen(
311308
text = stringResource(id = R.string.auto_connect_and_lockdown_mode_footer)
312309
)
313310
}
314-
}
315-
item {
316-
Spacer(modifier = Modifier.height(Dimens.cellLabelVerticalPadding))
317-
HeaderSwitchComposeCell(
318-
title = stringResource(R.string.auto_connect),
319-
isToggled = uiState.isAutoConnectEnabled,
320-
isEnabled = true,
321-
onCellClicked = { newValue -> onToggleAutoConnect(newValue) }
322-
)
323-
}
324-
item {
325-
SwitchComposeSubtitleCell(text = stringResource(id = R.string.auto_connect_footer))
311+
} else {
312+
item {
313+
Spacer(modifier = Modifier.height(Dimens.cellLabelVerticalPadding))
314+
HeaderSwitchComposeCell(
315+
title = stringResource(R.string.auto_connect),
316+
isToggled = uiState.isAutoConnectEnabled,
317+
isEnabled = true,
318+
onCellClicked = { newValue -> onToggleAutoConnect(newValue) }
319+
)
320+
}
321+
item {
322+
SwitchComposeSubtitleCell(
323+
text = stringResource(id = R.string.auto_connect_footer)
324+
)
325+
}
326326
}
327327
item {
328328
Spacer(modifier = Modifier.height(Dimens.cellLabelVerticalPadding))

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/VpnSettingsUiState.kt

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ data class VpnSettingsUiState(
2020
val selectedWireguardPort: Constraint<Port>,
2121
val customWireguardPort: Constraint<Port>?,
2222
val availablePortRanges: List<PortRange>,
23+
val systemVpnSettingsAvailable: Boolean,
2324
) {
2425

2526
companion object {
@@ -35,6 +36,7 @@ data class VpnSettingsUiState(
3536
selectedWireguardPort: Constraint<Port> = Constraint.Any(),
3637
customWireguardPort: Constraint.Only<Port>? = null,
3738
availablePortRanges: List<PortRange> = emptyList(),
39+
systemVpnSettingsAvailable: Boolean = false,
3840
) =
3941
VpnSettingsUiState(
4042
mtu,
@@ -48,6 +50,7 @@ data class VpnSettingsUiState(
4850
selectedWireguardPort,
4951
customWireguardPort,
5052
availablePortRanges,
53+
systemVpnSettingsAvailable
5154
)
5255
}
5356
}

android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import net.mullvad.mullvadvpn.usecase.PlayPaymentUseCase
3434
import net.mullvad.mullvadvpn.usecase.PortRangeUseCase
3535
import net.mullvad.mullvadvpn.usecase.RelayListFilterUseCase
3636
import net.mullvad.mullvadvpn.usecase.RelayListUseCase
37+
import net.mullvad.mullvadvpn.usecase.SystemVpnSettingsUseCase
3738
import net.mullvad.mullvadvpn.usecase.TunnelStateNotificationUseCase
3839
import net.mullvad.mullvadvpn.usecase.VersionNotificationUseCase
3940
import net.mullvad.mullvadvpn.util.ChangelogDataProvider
@@ -109,6 +110,7 @@ val uiModule = module {
109110
single { RelayListUseCase(get(), get()) }
110111
single { OutOfTimeUseCase(get(), get()) }
111112
single { ConnectivityUseCase(get()) }
113+
single { SystemVpnSettingsUseCase(androidContext()) }
112114

113115
single { InAppNotificationController(get(), get(), get(), get(), MainScope()) }
114116

@@ -151,7 +153,7 @@ val uiModule = module {
151153
viewModel { SettingsViewModel(get(), get(), IS_PLAY_BUILD) }
152154
viewModel { SplashViewModel(get(), get(), get()) }
153155
viewModel { VoucherDialogViewModel(get(), get()) }
154-
viewModel { VpnSettingsViewModel(get(), get(), get(), get()) }
156+
viewModel { VpnSettingsViewModel(get(), get(), get(), get(), get()) }
155157
viewModel { WelcomeViewModel(get(), get(), get(), get(), get(), isPlayBuild = IS_PLAY_BUILD) }
156158
viewModel { ReportProblemViewModel(get(), get()) }
157159
viewModel { ViewLogsViewModel(get()) }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package net.mullvad.mullvadvpn.usecase
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
6+
class SystemVpnSettingsUseCase(val context: Context) {
7+
fun systemVpnSettingsAvailable(): Boolean =
8+
Intent("android.net.vpn.SETTINGS").resolveActivity(context.packageManager) != null
9+
}

android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import net.mullvad.mullvadvpn.model.WireguardConstraints
3636
import net.mullvad.mullvadvpn.repository.SettingsRepository
3737
import net.mullvad.mullvadvpn.usecase.PortRangeUseCase
3838
import net.mullvad.mullvadvpn.usecase.RelayListUseCase
39+
import net.mullvad.mullvadvpn.usecase.SystemVpnSettingsUseCase
3940
import net.mullvad.mullvadvpn.util.isCustom
4041

4142
sealed interface VpnSettingsSideEffect {
@@ -49,6 +50,7 @@ class VpnSettingsViewModel(
4950
private val resources: Resources,
5051
portRangeUseCase: PortRangeUseCase,
5152
private val relayListUseCase: RelayListUseCase,
53+
private val systemVpnSettingsUseCase: SystemVpnSettingsUseCase,
5254
private val dispatcher: CoroutineDispatcher = Dispatchers.IO
5355
) : ViewModel() {
5456

@@ -75,7 +77,9 @@ class VpnSettingsViewModel(
7577
quantumResistant = settings?.quantumResistant() ?: QuantumResistantState.Off,
7678
selectedWireguardPort = settings?.getWireguardPort() ?: Constraint.Any(),
7779
customWireguardPort = customWgPort,
78-
availablePortRanges = portRanges
80+
availablePortRanges = portRanges,
81+
systemVpnSettingsAvailable =
82+
systemVpnSettingsUseCase.systemVpnSettingsAvailable()
7983
)
8084
}
8185
.stateIn(

android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelState.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ data class VpnSettingsViewModelState(
2020
val selectedWireguardPort: Constraint<Port>,
2121
val customWireguardPort: Constraint<Port>?,
2222
val availablePortRanges: List<PortRange>,
23+
val systemVpnSettingsAvailable: Boolean,
2324
) {
2425
fun toUiState(): VpnSettingsUiState =
2526
VpnSettingsUiState(
@@ -34,6 +35,7 @@ data class VpnSettingsViewModelState(
3435
selectedWireguardPort,
3536
customWireguardPort,
3637
availablePortRanges,
38+
systemVpnSettingsAvailable
3739
)
3840

3941
companion object {
@@ -51,7 +53,8 @@ data class VpnSettingsViewModelState(
5153
quantumResistant = QuantumResistantState.Off,
5254
selectedWireguardPort = Constraint.Any(),
5355
customWireguardPort = null,
54-
availablePortRanges = emptyList()
56+
availablePortRanges = emptyList(),
57+
systemVpnSettingsAvailable = false
5558
)
5659
}
5760
}

android/lib/common/src/main/kotlin/net/mullvad/mullvadvpn/lib/common/util/ContextExtensions.kt

-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,3 @@ fun Context.openVpnSettings() {
4646
val intent = Intent("android.settings.VPN_SETTINGS")
4747
startActivity(intent)
4848
}
49-
50-
fun Context.vpnSettingsAvailable(): Boolean =
51-
Intent("android.net.vpn.SETTINGS").resolveActivity(packageManager) != null

0 commit comments

Comments
 (0)