fix: wifi name surrounding quotes, prevent multiple auto-tunnel jobs

#768
#797
This commit is contained in:
Zane Schepke
2025-06-14 15:39:22 -04:00
parent 03345bdf86
commit 599bf9c9e0
3 changed files with 17 additions and 10 deletions
@@ -73,6 +73,8 @@ class AutoTunnelService : LifecycleService() {
private val binder = LocalBinder(this)
private var isServiceRunning = false
override fun onCreate() {
super.onCreate()
launchWatcherNotification()
@@ -91,6 +93,8 @@ class AutoTunnelService : LifecycleService() {
}
fun start() {
if (isServiceRunning) return
isServiceRunning = true
kotlin
.runCatching {
launchWatcherNotification()
@@ -103,6 +107,7 @@ class AutoTunnelService : LifecycleService() {
}
fun stop() {
isServiceRunning = false
wakeLock?.let { if (it.isHeld) it.release() }
stopSelf()
}
@@ -181,8 +181,16 @@ class AndroidNetworkMonitor(context: Context, val wifiDetectionMethod: WifiDetec
activeWifiNetworks.add(network.toString())
currentSsid =
when (wifiDetectionMethod) {
WifiDetectionMethod.DEFAULT ->
networkCapabilities?.getWifiSsid() ?: getWifiSsid()
WifiDetectionMethod.DEFAULT -> {
if (networkCapabilities == null) {
Timber.d("Capabilities not available, getting SSID via legacy API")
getWifiSsid()
} else
networkCapabilities.getWifiSsid().also {
Timber.d("Got SSID from capabilities")
}
}
WifiDetectionMethod.LEGACY -> getWifiSsid()
WifiDetectionMethod.ROOT -> rootShell.getCurrentWifiName()
// TODO implement Shizuku
@@ -212,18 +220,12 @@ class AndroidNetworkMonitor(context: Context, val wifiDetectionMethod: WifiDetec
}
else ->
object : ConnectivityManager.NetworkCallback(FLAG_INCLUDE_LOCATION_INFO) {
private var netCapabilities: NetworkCapabilities? = null
override fun onAvailable(network: Network) {
Timber.i("Wi-Fi change detected using new API")
launch { handleOnWifiAvailable(network, netCapabilities) }
}
override fun onCapabilitiesChanged(
network: Network,
networkCapabilities: NetworkCapabilities,
) {
launch { wifiMutex.withLock { netCapabilities = networkCapabilities } }
launch { handleOnWifiAvailable(network, networkCapabilities) }
}
override fun onLost(network: Network) {
@@ -29,7 +29,7 @@ fun NetworkCapabilities.getWifiSsid(): String? {
val info: WifiInfo
if (transportInfo is WifiInfo) {
info = transportInfo as WifiInfo
return info.ssid
return info.ssid.removeSurrounding("\"").trim()
}
}
return null