[PATCH 08/16] android/gatt: Unsubscribe from autoconnect on unregister

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When application does unregister, lets make sure that BfA does not keep
any auto connect devices for this app.
---
 android/gatt.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/android/gatt.c b/android/gatt.c
index 0d0b56d..348a2a2 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -370,6 +370,13 @@ static bool match_device_by_state(const void *data, const void *user_data)
 	return true;
 }
 
+static bool match_device_by_ac_id(const void *data, const void *user_data)
+{
+	const struct gatt_device *dev = data;
+
+	return queue_find(dev->autoconnect_apps, match_by_value, user_data);
+}
+
 static bool match_pending_device(const void *data, const void *user_data)
 {
 	const struct gatt_device *dev = data;
@@ -442,6 +449,11 @@ static struct gatt_device *find_device_by_state(uint32_t state)
 							UINT_TO_PTR(state));
 }
 
+static struct gatt_device *find_device_by_autoconnect_app_id(uint32_t id)
+{
+	return queue_find(gatt_devices, match_device_by_ac_id,
+							UINT_TO_PTR(id));
+}
 static bool match_srvc_by_element_id(const void *data, const void *user_data)
 {
 	const struct element_id *exp_id = user_data;
@@ -1825,10 +1837,40 @@ static bool trigger_connection(struct app_connection *connection)
 	return ret;
 }
 
+static void clear_autoconnect_devices(int app_id)
+{
+	struct gatt_device *dev;
+
+	/*
+	 * Check if application was registered for any devices to
+	 * reconnect
+	 */
+	dev = find_device_by_autoconnect_app_id(app_id);
+	while (dev) {
+		queue_remove(dev->autoconnect_apps, INT_TO_PTR(app_id));
+
+		if (queue_isempty(dev->autoconnect_apps)) {
+			bt_auto_connect_remove(&dev->bdaddr);
+			device_unref(dev);
+
+			if (dev->state == DEVICE_CONNECT_INIT)
+				device_set_state(dev, DEVICE_DISCONNECTED);
+		}
+
+		dev = find_device_by_autoconnect_app_id(app_id);
+	};
+}
+
 static uint8_t unregister_app(int client_if)
 {
 	struct gatt_app *cl;
 
+	/*
+	 * Make sure that there is no devices in auto connect list for this
+	 * application
+	 */
+	clear_autoconnect_devices(client_if);
+
 	cl = queue_remove_if(gatt_apps, match_app_by_id, INT_TO_PTR(client_if));
 	if (!cl) {
 		error("gatt: client_if=%d not found", client_if);
-- 
1.8.4

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux