mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-11-11 08:12:26 +01:00
wireless: ignore a head unit's repeated Wi-Fi details instead of rejoining
ZLink head units send InfoResponse again once the stream is up. Rejoining released the network carrying the stream, aborting it a second in, and left the unit stuck waiting for a version request until ZLink was force closed. A session ending mid-teardown no longer crashes the app either.
This commit is contained in:
1 parent
0f2582f638
commit
6751951308
2 files changed
+20
No files matched your search
@@ -153,7 +153,13 @@ class VideoSource(
|
|||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
running = false
|
running = false
|
||||||
|
// Stop is called from threads that are themselves being shut down. An interrupt here
|
||||||
|
// used to escape as an uncaught exception and take the whole app down with the session.
|
||||||
|
try {
|
||||||
worker?.join(1_000)
|
worker?.join(1_000)
|
||||||
|
} catch (e: InterruptedException) {
|
||||||
|
Thread.currentThread().interrupt()
|
||||||
|
}
|
||||||
runCatching { inputSurface?.release() }
|
runCatching { inputSurface?.release() }
|
||||||
inputSurface = null
|
inputSurface = null
|
||||||
runCatching { codec?.stop() }
|
runCatching { codec?.stop() }
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ object WirelessLink {
|
|||||||
val busy: Boolean get() = worker?.isAlive == true
|
val busy: Boolean get() = worker?.isAlive == true
|
||||||
/** Set when Android drops the car's network mid-try, so the rest don't bind to a dead one. */
|
/** Set when Android drops the car's network mid-try, so the rest don't bind to a dead one. */
|
||||||
@Volatile private var lostNetwork: Network? = null
|
@Volatile private var lostNetwork: Network? = null
|
||||||
|
/** The car network asked for or joined, until Android says it's gone or never came. */
|
||||||
|
@Volatile private var activeSsid: String? = null
|
||||||
/** Bumped on each Wi-Fi join and on stop, so an older run of TCP tries ends instead of racing the new one. */
|
/** Bumped on each Wi-Fi join and on stop, so an older run of TCP tries ends instead of racing the new one. */
|
||||||
@Volatile private var tcpRun = 0
|
@Volatile private var tcpRun = 0
|
||||||
private val writeLock = Any()
|
private val writeLock = Any()
|
||||||
@@ -131,6 +133,7 @@ object WirelessLink {
|
|||||||
runCatching { context.getSystemService(ConnectivityManager::class.java).unregisterNetworkCallback(cb) }
|
runCatching { context.getSystemService(ConnectivityManager::class.java).unregisterNetworkCallback(cb) }
|
||||||
}
|
}
|
||||||
network = null
|
network = null
|
||||||
|
activeSsid = null
|
||||||
// Stopped before the car's session began, so nothing else resets Home's card.
|
// Stopped before the car's session began, so nothing else resets Home's card.
|
||||||
if (starting) {
|
if (starting) {
|
||||||
log.i("wireless start-up stopped")
|
log.i("wireless start-up stopped")
|
||||||
@@ -223,6 +226,14 @@ object WirelessLink {
|
|||||||
val bssid = text(3)
|
val bssid = text(3)
|
||||||
val security = Wire.varint(f, 4) ?: -1
|
val security = Wire.varint(f, 4) ?: -1
|
||||||
log.i("<- InfoResponse: ssid=\"$ssid\" bssid=$bssid security=$security password=${if (password.isEmpty()) "none" else "(${password.length} chars)"}")
|
log.i("<- InfoResponse: ssid=\"$ssid\" bssid=$bssid security=$security password=${if (password.isEmpty()) "none" else "(${password.length} chars)"}")
|
||||||
|
// ZLink head units send the Wi-Fi details again once the stream is up.
|
||||||
|
// Asking Android for the network again releases the one carrying the
|
||||||
|
// stream, which aborts its socket; a phone running Android Auto just
|
||||||
|
// carries on, so the repeat is ignored while that network is in use.
|
||||||
|
if (ssid == activeSsid) {
|
||||||
|
log.i("InfoResponse again for \"$ssid\", which the phone is already on - ignoring it")
|
||||||
|
continue
|
||||||
|
}
|
||||||
val join = { ip: String, port: Int -> joinWifi(context, output, name, ssid, password, bssid, ip, port) }
|
val join = { ip: String, port: Int -> joinWifi(context, output, name, ssid, password, bssid, ip, port) }
|
||||||
val known = target
|
val known = target
|
||||||
if (known != null) {
|
if (known != null) {
|
||||||
@@ -332,6 +343,7 @@ object WirelessLink {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onUnavailable() {
|
override fun onUnavailable() {
|
||||||
|
if (activeSsid == ssid) activeSsid = null
|
||||||
log.w("Wi-Fi: couldn't join \"$ssid\" (declined, out of range, or wrong password)")
|
log.w("Wi-Fi: couldn't join \"$ssid\" (declined, out of range, or wrong password)")
|
||||||
runCatching { send(output, MSG_CONNECTION_STATUS, Protobuf.varintField(1, -1)) }
|
runCatching { send(output, MSG_CONNECTION_STATUS, Protobuf.varintField(1, -1)) }
|
||||||
SessionStatus.failed(
|
SessionStatus.failed(
|
||||||
@@ -356,6 +368,7 @@ object WirelessLink {
|
|||||||
|
|
||||||
override fun onLost(net: Network) {
|
override fun onLost(net: Network) {
|
||||||
lostNetwork = net
|
lostNetwork = net
|
||||||
|
if (activeSsid == ssid) activeSsid = null
|
||||||
log.w(
|
log.w(
|
||||||
"Wi-Fi: lost \"$ssid\" - Android dropped the car's network. Picking it by hand " +
|
"Wi-Fi: lost \"$ssid\" - Android dropped the car's network. Picking it by hand " +
|
||||||
"in the Wi-Fi list does this; the remaining tries go over the phone's own Wi-Fi",
|
"in the Wi-Fi list does this; the remaining tries go over the phone's own Wi-Fi",
|
||||||
@@ -364,6 +377,7 @@ object WirelessLink {
|
|||||||
}
|
}
|
||||||
network?.let { runCatching { manager.unregisterNetworkCallback(it) } }
|
network?.let { runCatching { manager.unregisterNetworkCallback(it) } }
|
||||||
network = callback
|
network = callback
|
||||||
|
activeSsid = ssid
|
||||||
manager.requestNetwork(request, callback, WIFI_WAIT_MS)
|
manager.requestNetwork(request, callback, WIFI_WAIT_MS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user