diff mbox series

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

Message ID 20240227164403.1904213-2-luiz.dentz@gmail.com (mailing list archive)
State Accepted
Commit 44d3f67277f83983e1e9697eda7b9aeb40ca231d
Headers show
Series [BlueZ,v1,1/2] btdev: Fix not resetting big_handle on HCI_Reset | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch warning WARNING:LINE_SPACING: Missing a blank line after declarations #127: FILE: src/device.c:3285: + char addr[18]; + ba2str(&dev->bdaddr, addr); /github/workspace/src/src/13574121.patch total: 0 errors, 1 warnings, 25 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /github/workspace/src/src/13574121.patch has style problems, please review. NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.
tedd_an/GitLint success Gitlint PASS
tedd_an/IncrementalBuild success Incremental Build PASS

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.
 	 */