mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-11-10 16:02:25 +01:00
wireless: auto-connect after the car ended the last session
A session the car ended left Gearslip thinking one was still running, so the next time the car came back nothing happened. Only a live session counts now, and each reason not to connect is logged.
This commit is contained in:
1 parent
75d0df19c3
commit
2c1fad6f8c
1 file changed
+20
-4
@@ -345,18 +345,34 @@ class GearslipActivity : ComponentActivity(), Projection {
|
|||||||
|
|
||||||
/** A known car came up over Bluetooth: connect wirelessly, unless USB or another try is already on it. */
|
/** A known car came up over Bluetooth: connect wirelessly, unless USB or another try is already on it. */
|
||||||
private fun connectToNearbyCar(address: String?) {
|
private fun connectToNearbyCar(address: String?) {
|
||||||
if (address == null || !AppSettings.gearslipEnabled(this)) return
|
if (address == null) return
|
||||||
|
if (!AppSettings.gearslipEnabled(this)) {
|
||||||
|
GearslipLog.i("auto-connect: Gearslip is switched off - not connecting")
|
||||||
|
return
|
||||||
|
}
|
||||||
if (descriptor != null) {
|
if (descriptor != null) {
|
||||||
GearslipLog.i("auto-connect: the car is on USB already - staying on USB")
|
GearslipLog.i("auto-connect: the car is on USB already - staying on USB")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (runner != null || app.seb3thehacker.gearslip.wireless.WirelessLink.busy) return
|
// Only a session that's still running counts. One the car ended (a ByeBye, a dropped
|
||||||
|
// network) leaves its runner behind, since only Gearslip ending a session clears it, and
|
||||||
|
// that used to make every later auto-connect quietly do nothing.
|
||||||
|
if (worker?.isAlive == true || app.seb3thehacker.gearslip.wireless.WirelessLink.busy) {
|
||||||
|
GearslipLog.i("auto-connect: a session is already running")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (runner != null) closeAccessory(stopWireless = false)
|
||||||
if (checkSelfPermission(android.Manifest.permission.BLUETOOTH_CONNECT) != android.content.pm.PackageManager.PERMISSION_GRANTED) {
|
if (checkSelfPermission(android.Manifest.permission.BLUETOOTH_CONNECT) != android.content.pm.PackageManager.PERMISSION_GRANTED) {
|
||||||
GearslipLog.w("auto-connect: needs the Nearby devices permission")
|
GearslipLog.w("auto-connect: needs the Nearby devices permission")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val adapter = getSystemService(android.bluetooth.BluetoothManager::class.java)?.adapter ?: return
|
val adapter = getSystemService(android.bluetooth.BluetoothManager::class.java)?.adapter
|
||||||
val device = runCatching { adapter.getRemoteDevice(address) }.getOrNull() ?: return
|
val device = adapter?.let { runCatching { it.getRemoteDevice(address) }.getOrNull() }
|
||||||
|
if (device == null) {
|
||||||
|
GearslipLog.w("auto-connect: Bluetooth couldn't hand over the car")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
GearslipLog.i("auto-connect: connecting")
|
||||||
app.seb3thehacker.gearslip.wireless.WirelessLink.start(this, device)
|
app.seb3thehacker.gearslip.wireless.WirelessLink.start(this, device)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user