When a car keeps its own screen and its Bluetooth isn't connected to the phone, Home says to connect it, as some Hondas and Mazdas wait for that

This commit is contained in:
Seb3thehacker committed 2026-11-29 16:10:29 -08:00
1 parent 694129576e
commit dccdd2eeba
1 file changed
+32
@@ -189,6 +189,7 @@ object CarBluetooth {
device.bondState == BluetoothDevice.BOND_BONDED -> { device.bondState == BluetoothDevice.BOND_BONDED -> {
askForAddress(device, c.service.carAddress) askForAddress(device, c.service.carAddress)
announce("the car is keeping its screen") announce("the car is keeping its screen")
sayIfNotConnected(device)
true true
} }
device.bondState != BluetoothDevice.BOND_NONE -> false device.bondState != BluetoothDevice.BOND_NONE -> false
@@ -201,6 +202,37 @@ object CarBluetooth {
} }
} }
/**
* Paired, but the phone's Bluetooth isn't connected to the car. A 2017 Pilot, a 2020 CR-V and
* a 2021 CX-5 (issues #57, #162, #68) kept their own screen until the driver connected it by
* hand, then showed Gearslip at once. Android doesn't let an app connect it, so Home says so.
*/
@SuppressLint("MissingPermission")
private fun sayIfNotConnected(device: BluetoothDevice) {
val context = appContext ?: return
val adapter = context.getSystemService(BluetoothManager::class.java)?.adapter ?: return
val address = device.address.uppercase()
val asked = adapter.getProfileProxy(context, object : android.bluetooth.BluetoothProfile.ServiceListener {
override fun onServiceConnected(profile: Int, proxy: android.bluetooth.BluetoothProfile) {
val connected = runCatching { proxy.connectedDevices }.getOrDefault(emptyList())
.any { it.address.uppercase() == address }
adapter.closeProfileProxy(profile, proxy)
if (connected || car == null) return
val name = runCatching { device.alias ?: device.name }.getOrNull()?.takeIf { it.isNotBlank() }
?: context.getString(R.string.bt_address_your_car)
log.i("the car is keeping its screen, and its Bluetooth isn't connected to the phone")
if (app.seb3thehacker.gearslip.SessionStatus.state.value.phase == app.seb3thehacker.gearslip.SessionStatus.Phase.CONNECTING) {
app.seb3thehacker.gearslip.SessionStatus.connecting(
"Connect the phone's Bluetooth to $name. Some cars only show Gearslip once it is connected.",
)
}
}
override fun onServiceDisconnected(profile: Int) {}
}, android.bluetooth.BluetoothProfile.HEADSET)
if (!asked) log.i("can't check the car's Bluetooth connection")
}
fun onCarDisconnected() { fun onCarDisconnected() {
car = null car = null
pairing = false pairing = false