From dccdd2eeba465ee8a53a24a101ea5b4e76be6d4e Mon Sep 17 00:00:00 2001 From: Seb3thehacker Date: Sun, 29 Nov 2026 16:10:29 -0800 Subject: [PATCH] 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 --- .../gearslip/car/CarBluetooth.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarBluetooth.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarBluetooth.kt index f38a339..aa7f057 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarBluetooth.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarBluetooth.kt @@ -189,6 +189,7 @@ object CarBluetooth { device.bondState == BluetoothDevice.BOND_BONDED -> { askForAddress(device, c.service.carAddress) announce("the car is keeping its screen") + sayIfNotConnected(device) true } 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() { car = null pairing = false