mirror of
https://github.com/wgtunnel/android.git
synced 2026-06-02 00:29:08 +02:00
fix: wifi name surrounding quotes, prevent multiple auto-tunnel jobs
#768 #797
This commit is contained in:
+5
@@ -73,6 +73,8 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
|
|
||||||
private val binder = LocalBinder(this)
|
private val binder = LocalBinder(this)
|
||||||
|
|
||||||
|
private var isServiceRunning = false
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
launchWatcherNotification()
|
launchWatcherNotification()
|
||||||
@@ -91,6 +93,8 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
|
if (isServiceRunning) return
|
||||||
|
isServiceRunning = true
|
||||||
kotlin
|
kotlin
|
||||||
.runCatching {
|
.runCatching {
|
||||||
launchWatcherNotification()
|
launchWatcherNotification()
|
||||||
@@ -103,6 +107,7 @@ class AutoTunnelService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
|
isServiceRunning = false
|
||||||
wakeLock?.let { if (it.isHeld) it.release() }
|
wakeLock?.let { if (it.isHeld) it.release() }
|
||||||
stopSelf()
|
stopSelf()
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-9
@@ -181,8 +181,16 @@ class AndroidNetworkMonitor(context: Context, val wifiDetectionMethod: WifiDetec
|
|||||||
activeWifiNetworks.add(network.toString())
|
activeWifiNetworks.add(network.toString())
|
||||||
currentSsid =
|
currentSsid =
|
||||||
when (wifiDetectionMethod) {
|
when (wifiDetectionMethod) {
|
||||||
WifiDetectionMethod.DEFAULT ->
|
WifiDetectionMethod.DEFAULT -> {
|
||||||
networkCapabilities?.getWifiSsid() ?: getWifiSsid()
|
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.LEGACY -> getWifiSsid()
|
||||||
WifiDetectionMethod.ROOT -> rootShell.getCurrentWifiName()
|
WifiDetectionMethod.ROOT -> rootShell.getCurrentWifiName()
|
||||||
// TODO implement Shizuku
|
// TODO implement Shizuku
|
||||||
@@ -212,18 +220,12 @@ class AndroidNetworkMonitor(context: Context, val wifiDetectionMethod: WifiDetec
|
|||||||
}
|
}
|
||||||
else ->
|
else ->
|
||||||
object : ConnectivityManager.NetworkCallback(FLAG_INCLUDE_LOCATION_INFO) {
|
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(
|
override fun onCapabilitiesChanged(
|
||||||
network: Network,
|
network: Network,
|
||||||
networkCapabilities: NetworkCapabilities,
|
networkCapabilities: NetworkCapabilities,
|
||||||
) {
|
) {
|
||||||
launch { wifiMutex.withLock { netCapabilities = networkCapabilities } }
|
launch { handleOnWifiAvailable(network, networkCapabilities) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLost(network: Network) {
|
override fun onLost(network: Network) {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ fun NetworkCapabilities.getWifiSsid(): String? {
|
|||||||
val info: WifiInfo
|
val info: WifiInfo
|
||||||
if (transportInfo is WifiInfo) {
|
if (transportInfo is WifiInfo) {
|
||||||
info = transportInfo as WifiInfo
|
info = transportInfo as WifiInfo
|
||||||
return info.ssid
|
return info.ssid.removeSurrounding("\"").trim()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
|
|||||||
Reference in New Issue
Block a user