diff mbox series

[BlueZ,v1,2/2] device: Consider service state on device_is_connected

Message ID 20240227164403.1904213-2-luiz.dentz@gmail.com
State New
Headers show
Series [BlueZ,v1,1/2] btdev: Fix not resetting big_handle on HCI_Reset | expand

Commit Message

Luiz Augusto von Dentz Feb. 27, 2024, 4:44 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This checks if there is any service connected on device_is_connected
since some profiles maybe probed using advertising data which doesn't
require a connection.
---
 src/device.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/src/device.c b/src/device.c
index 1db96d9a672c..e5191cabe81a 100644
--- a/src/device.c
+++ b/src/device.c
@@ -3225,7 +3225,11 @@  uint8_t btd_device_get_bdaddr_type(struct btd_device *dev)
 
 bool btd_device_is_connected(struct btd_device *dev)
 {
-	return dev->bredr_state.connected || dev->le_state.connected;
+	if (dev->bredr_state.connected || dev->le_state.connected)
+		return true;
+
+	return find_service_with_state(dev->services,
+						BTD_SERVICE_STATE_CONNECTED);
 }
 
 static void clear_temporary_timer(struct btd_device *dev)
@@ -3276,6 +3280,13 @@  static bool device_disappeared(gpointer user_data)
 {
 	struct btd_device *dev = user_data;
 
+	if (btd_device_is_connected(dev)) {
+		char addr[18];
+		ba2str(&dev->bdaddr, addr);
+		DBG("Device %s is marked as connected", dev->path);
+		return TRUE;
+	}
+
 	/* If there are services connecting restart the timer to give more time
 	 * for the service to either complete the connection or disconnect.
 	 */