android: add ExitNodeAllowLANAccess toggle in exit node picker (#241)

Updates ENG-3011

Just like on iOS, we should show a switch to toggle the ExitNodeAllowLANAccess preference.

Signed-off-by: Andrea Gottardo <andrea@gottardo.me>
pull/244/head
Andrea Gottardo 2 months ago committed by GitHub
parent 28d0ab4dd6
commit bf74edd551
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -42,7 +42,7 @@ class Ipn {
var LocalTCPPort: Int? = null, var LocalTCPPort: Int? = null,
var IncomingFiles: List<PartialFile>? = null, var IncomingFiles: List<PartialFile>? = null,
var ClientVersion: Tailcfg.ClientVersion? = null, var ClientVersion: Tailcfg.ClientVersion? = null,
var TailFSShares: Map<String, String>? = null, var TailFSShares: List<String>? = null,
) )
@Serializable @Serializable

@ -109,6 +109,8 @@ fun ExitNodePicker(
}) })
} }
} }
item("allowLANAccessToggle") { SettingRow(model.allowLANAccessSetting) }
} }
} }
} }

@ -210,7 +210,7 @@ fun SettingsButton(user: IpnLocal.LoginProfile?, action: () -> Unit) {
fun StartingView() { fun StartingView() {
// (jonathan) TODO: On iOS this is the game-of-life Tailscale animation. // (jonathan) TODO: On iOS this is the game-of-life Tailscale animation.
Column( Column(
modifier = Modifier.fillMaxSize().background(MaterialTheme.colorScheme.background), modifier = Modifier.fillMaxSize().background(MaterialTheme.colorScheme.secondaryContainer),
verticalArrangement = Arrangement.Center, verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally) { horizontalAlignment = Alignment.CenterHorizontally) {
Text( Text(

@ -43,10 +43,7 @@ class DNSSettingsViewModel() : IpnViewModel() {
isOn = MutableStateFlow(Notifier.prefs.value?.CorpDNS), isOn = MutableStateFlow(Notifier.prefs.value?.CorpDNS),
onToggle = { onToggle = {
LoadingIndicator.start() LoadingIndicator.start()
toggleCorpDNS { toggleCorpDNS { LoadingIndicator.stop() }
LoadingIndicator.stop()
// (jonathan) TODO: Error handling
}
}) })
init { init {

@ -6,6 +6,7 @@ package com.tailscale.ipn.ui.viewModel
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.tailscale.ipn.R
import com.tailscale.ipn.ui.localapi.Client import com.tailscale.ipn.ui.localapi.Client
import com.tailscale.ipn.ui.model.Ipn import com.tailscale.ipn.ui.model.Ipn
import com.tailscale.ipn.ui.model.StableNodeID import com.tailscale.ipn.ui.model.StableNodeID
@ -51,7 +52,18 @@ class ExitNodePickerViewModel(private val nav: ExitNodePickerNav) : IpnViewModel
MutableStateFlow(TreeMap()) MutableStateFlow(TreeMap())
val mullvadBestAvailableByCountry: StateFlow<Map<String, ExitNode>> = MutableStateFlow(TreeMap()) val mullvadBestAvailableByCountry: StateFlow<Map<String, ExitNode>> = MutableStateFlow(TreeMap())
val anyActive: StateFlow<Boolean> = MutableStateFlow(false) val anyActive: StateFlow<Boolean> = MutableStateFlow(false)
val isRunningExitNode: StateFlow<Boolean> = MutableStateFlow(false) val isRunningExitNode: StateFlow<Boolean> = MutableStateFlow(false)
val allowLANAccessSetting =
Setting(
R.string.allow_lan_access,
SettingType.SWITCH,
isOn = MutableStateFlow(Notifier.prefs.value?.ExitNodeAllowLANAccess),
enabled = MutableStateFlow(true),
onToggle = {
LoadingIndicator.start()
toggleAllowLANAccess { LoadingIndicator.stop() }
})
init { init {
viewModelScope.launch { viewModelScope.launch {
@ -59,7 +71,7 @@ class ExitNodePickerViewModel(private val nav: ExitNodePickerNav) : IpnViewModel
.combine(Notifier.prefs) { netmap, prefs -> Pair(netmap, prefs) } .combine(Notifier.prefs) { netmap, prefs -> Pair(netmap, prefs) }
.stateIn(viewModelScope) .stateIn(viewModelScope)
.collect { (netmap, prefs) -> .collect { (netmap, prefs) ->
isRunningExitNode.set(prefs?.let { AdvertisedRoutesHelper.exitNodeOnFromPrefs(it) }) isRunningExitNode.set(prefs?.let { AdvertisedRoutesHelper.exitNodeOnFromPrefs(it) })
val exitNodeId = prefs?.ExitNodeID val exitNodeId = prefs?.ExitNodeID
netmap?.Peers?.let { peers -> netmap?.Peers?.let { peers ->
val allNodes = val allNodes =
@ -137,4 +149,17 @@ class ExitNodePickerViewModel(private val nav: ExitNodePickerNav) : IpnViewModel
LoadingIndicator.stop() LoadingIndicator.stop()
} }
} }
fun toggleAllowLANAccess(callback: (Result<Ipn.Prefs>) -> Unit) {
val prefs =
Notifier.prefs.value
?: run {
callback(Result.failure(Exception("no prefs")))
return@toggleAllowLANAccess
}
val prefsOut = Ipn.MaskedPrefs()
prefsOut.ExitNodeAllowLANAccess = !prefs.ExitNodeAllowLANAccess
Client(viewModelScope).editPrefs(prefsOut, callback)
}
} }

@ -124,5 +124,6 @@
<string name="tailscale_is_not_running_this_device_is_using_the_system_dns_resolver">Tailscale is not running. This device is using the system\'s DNS resolver.</string> <string name="tailscale_is_not_running_this_device_is_using_the_system_dns_resolver">Tailscale is not running. This device is using the system\'s DNS resolver.</string>
<string name="this_device_is_using_the_system_dns_resolver">This device is using the system DNS resolver.</string> <string name="this_device_is_using_the_system_dns_resolver">This device is using the system DNS resolver.</string>
<string name="not_using_tailscale_dns">Not Using Tailscale DNS</string> <string name="not_using_tailscale_dns">Not Using Tailscale DNS</string>
<string name="allow_lan_access">Allow LAN Access</string>
</resources> </resources>

Loading…
Cancel
Save