fix: try to query ssid if we don't have a valid one yet
This commit is contained in:
parent
2c04b9d69c
commit
ba064b267f
|
@ -22,6 +22,7 @@ import com.zaneschepke.wireguardautotunnel.service.foreground.autotunnel.model.A
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.autotunnel.model.AutoTunnelState
|
import com.zaneschepke.wireguardautotunnel.service.foreground.autotunnel.model.AutoTunnelState
|
||||||
import com.zaneschepke.wireguardautotunnel.service.foreground.autotunnel.model.NetworkState
|
import com.zaneschepke.wireguardautotunnel.service.foreground.autotunnel.model.NetworkState
|
||||||
import com.zaneschepke.wireguardautotunnel.service.network.NetworkService
|
import com.zaneschepke.wireguardautotunnel.service.network.NetworkService
|
||||||
|
import com.zaneschepke.wireguardautotunnel.service.network.WifiService
|
||||||
import com.zaneschepke.wireguardautotunnel.service.notification.NotificationAction
|
import com.zaneschepke.wireguardautotunnel.service.notification.NotificationAction
|
||||||
import com.zaneschepke.wireguardautotunnel.service.notification.NotificationService
|
import com.zaneschepke.wireguardautotunnel.service.notification.NotificationService
|
||||||
import com.zaneschepke.wireguardautotunnel.service.notification.WireGuardNotification
|
import com.zaneschepke.wireguardautotunnel.service.notification.WireGuardNotification
|
||||||
|
@ -29,6 +30,7 @@ import com.zaneschepke.wireguardautotunnel.service.tunnel.TunnelService
|
||||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.TunnelConfigs
|
import com.zaneschepke.wireguardautotunnel.util.extensions.TunnelConfigs
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.cancelWithMessage
|
import com.zaneschepke.wireguardautotunnel.util.extensions.cancelWithMessage
|
||||||
|
import com.zaneschepke.wireguardautotunnel.util.extensions.getCurrentWifiName
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isReachable
|
import com.zaneschepke.wireguardautotunnel.util.extensions.isReachable
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.onNotRunning
|
import com.zaneschepke.wireguardautotunnel.util.extensions.onNotRunning
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
@ -240,7 +242,19 @@ class AutoTunnelService : LifecycleService() {
|
||||||
combineSettings(),
|
combineSettings(),
|
||||||
combineNetworkEventsJob(),
|
combineNetworkEventsJob(),
|
||||||
) { double, networkState ->
|
) { double, networkState ->
|
||||||
AutoTunnelState(tunnelService.get().vpnState.value, networkState, double.first, double.second)
|
// quick fix for bug where when first setting up auto tunneling we probably want to query for ssid right away
|
||||||
|
var netState: NetworkState? = null
|
||||||
|
if (networkState.wifiName == Constants.UNREADABLE_SSID && double.first.isTunnelOnWifiEnabled) {
|
||||||
|
if (double.first.isWifiNameByShellEnabled) {
|
||||||
|
netState = networkState.copy(wifiName = rootShell.get().getCurrentWifiName())
|
||||||
|
} else if (networkState.capabilities != null) {
|
||||||
|
netState = networkState.copy(
|
||||||
|
wifiName =
|
||||||
|
WifiService.getNetworkName(networkState.capabilities, this@AutoTunnelService),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AutoTunnelState(tunnelService.get().vpnState.value, netState ?: networkState, double.first, double.second)
|
||||||
}.collect { state ->
|
}.collect { state ->
|
||||||
Timber.d("Network state: ${state.networkState}")
|
Timber.d("Network state: ${state.networkState}")
|
||||||
autoTunnelStateFlow.update {
|
autoTunnelStateFlow.update {
|
||||||
|
@ -265,6 +279,7 @@ class AutoTunnelService : LifecycleService() {
|
||||||
mobileData.available,
|
mobileData.available,
|
||||||
false,
|
false,
|
||||||
wifi.name,
|
wifi.name,
|
||||||
|
wifi.capabilities,
|
||||||
)
|
)
|
||||||
}.distinctUntilChanged().filterNot { it.isWifiConnected && it.wifiName == null }
|
}.distinctUntilChanged().filterNot { it.isWifiConnected && it.wifiName == null }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package com.zaneschepke.wireguardautotunnel.service.foreground.autotunnel.model
|
package com.zaneschepke.wireguardautotunnel.service.foreground.autotunnel.model
|
||||||
|
|
||||||
|
import android.net.NetworkCapabilities
|
||||||
|
|
||||||
data class NetworkState(
|
data class NetworkState(
|
||||||
val isWifiConnected: Boolean = false,
|
val isWifiConnected: Boolean = false,
|
||||||
val isMobileDataConnected: Boolean = false,
|
val isMobileDataConnected: Boolean = false,
|
||||||
val isEthernetConnected: Boolean = false,
|
val isEthernetConnected: Boolean = false,
|
||||||
val wifiName: String? = null,
|
val wifiName: String? = null,
|
||||||
|
val capabilities: NetworkCapabilities? = null,
|
||||||
)
|
)
|
||||||
|
|
|
@ -57,8 +57,8 @@ constructor(
|
||||||
emit(NetworkStatus.Unavailable())
|
emit(NetworkStatus.Unavailable())
|
||||||
}.map {
|
}.map {
|
||||||
when (it) {
|
when (it) {
|
||||||
is NetworkStatus.Available, is NetworkStatus.CapabilitiesChanged -> Status(true, null)
|
is NetworkStatus.Available, is NetworkStatus.CapabilitiesChanged -> Status(true, null, null)
|
||||||
is NetworkStatus.Unavailable -> Status(false, null)
|
is NetworkStatus.Unavailable -> Status(false, null, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,8 +56,8 @@ constructor(
|
||||||
emit(NetworkStatus.Unavailable())
|
emit(NetworkStatus.Unavailable())
|
||||||
}.map {
|
}.map {
|
||||||
when (it) {
|
when (it) {
|
||||||
is NetworkStatus.Available, is NetworkStatus.CapabilitiesChanged -> Status(true, null)
|
is NetworkStatus.Available, is NetworkStatus.CapabilitiesChanged -> Status(true, null, null)
|
||||||
is NetworkStatus.Unavailable -> Status(false, null)
|
is NetworkStatus.Unavailable -> Status(false, null, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package com.zaneschepke.wireguardautotunnel.service.network
|
package com.zaneschepke.wireguardautotunnel.service.network
|
||||||
|
|
||||||
|
import android.net.NetworkCapabilities
|
||||||
|
|
||||||
data class Status(
|
data class Status(
|
||||||
val available: Boolean,
|
val available: Boolean,
|
||||||
val name: String?,
|
val name: String?,
|
||||||
|
val capabilities: NetworkCapabilities?,
|
||||||
)
|
)
|
||||||
|
|
|
@ -114,27 +114,32 @@ constructor(
|
||||||
if (available || ssid == null || ssid == Constants.UNREADABLE_SSID) {
|
if (available || ssid == null || ssid == Constants.UNREADABLE_SSID) {
|
||||||
available = false
|
available = false
|
||||||
Timber.d("Getting SSID from capabilities")
|
Timber.d("Getting SSID from capabilities")
|
||||||
ssid = getNetworkName(it.networkCapabilities)
|
ssid = if (settingsRepository.getSettings().isWifiNameByShellEnabled) {
|
||||||
|
rootShell.get().getCurrentWifiName()
|
||||||
|
} else {
|
||||||
|
getNetworkName(it.networkCapabilities, context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
emit(Status(true, ssid))
|
emit(Status(true, ssid, it.networkCapabilities))
|
||||||
}
|
}
|
||||||
is NetworkStatus.Unavailable -> emit(Status(false, null))
|
is NetworkStatus.Unavailable -> emit(Status(false, null, null))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun getNetworkName(networkCapabilities: NetworkCapabilities): String? {
|
companion object {
|
||||||
if (settingsRepository.getSettings().isWifiNameByShellEnabled) return rootShell.get().getCurrentWifiName()
|
fun getNetworkName(networkCapabilities: NetworkCapabilities, context: Context): String? {
|
||||||
var ssid = networkCapabilities.getWifiName()
|
var ssid = networkCapabilities.getWifiName()
|
||||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S) {
|
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S) {
|
||||||
val wifiManager =
|
val wifiManager =
|
||||||
context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
|
context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
val info = wifiManager.connectionInfo
|
val info = wifiManager.connectionInfo
|
||||||
if (info.supplicantState === SupplicantState.COMPLETED) {
|
if (info.supplicantState === SupplicantState.COMPLETED) {
|
||||||
ssid = info.ssid
|
ssid = info.ssid
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return ssid?.trim('"')
|
||||||
}
|
}
|
||||||
return ssid?.trim('"')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.settings.autotunnel.advanced
|
|
||||||
|
|
||||||
enum class PeerActions {
|
|
||||||
EXCLUDE_LAN,
|
|
||||||
}
|
|
|
@ -66,8 +66,8 @@ import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavControll
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.TopNavBar
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.TopNavBar
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.AuthorizationPrompt
|
import com.zaneschepke.wireguardautotunnel.ui.common.prompt.AuthorizationPrompt
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.autotunnel.advanced.InterfaceActions
|
import com.zaneschepke.wireguardautotunnel.ui.screens.tunneloptions.config.model.InterfaceActions
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.autotunnel.advanced.PeerActions
|
import com.zaneschepke.wireguardautotunnel.ui.screens.tunneloptions.config.model.PeerActions
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunneloptions.config.model.InterfaceProxy
|
import com.zaneschepke.wireguardautotunnel.ui.screens.tunneloptions.config.model.InterfaceProxy
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunneloptions.config.model.PeerProxy
|
import com.zaneschepke.wireguardautotunnel.ui.screens.tunneloptions.config.model.PeerProxy
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.zaneschepke.wireguardautotunnel.ui.screens.settings.autotunnel.advanced
|
package com.zaneschepke.wireguardautotunnel.ui.screens.tunneloptions.config.model
|
||||||
|
|
||||||
enum class InterfaceActions {
|
enum class InterfaceActions {
|
||||||
TOGGLE_AMNEZIA_VALUES,
|
TOGGLE_AMNEZIA_VALUES,
|
|
@ -0,0 +1,5 @@
|
||||||
|
package com.zaneschepke.wireguardautotunnel.ui.screens.tunneloptions.config.model
|
||||||
|
|
||||||
|
enum class PeerActions {
|
||||||
|
EXCLUDE_LAN,
|
||||||
|
}
|
Loading…
Reference in New Issue