device: Remove device after all bearers are disconnected
authorCheng Jiang <quic_chejiang@quicinc.com>
Sun, 29 Sep 2024 02:22:56 +0000 (10:22 +0800)
committerWootak Jung <wootak.jung@samsung.com>
Thu, 20 Feb 2025 07:43:23 +0000 (16:43 +0900)
For a dual-mode remote, both BR/EDR and BLE may be connected,
RemoveDevice should be handled after all bearers are disconnects.
Otherwise, if msg is removed, but not all connection are dropped,
this function returns before *remove is updated, then after all
connections are dropped, but device->disconnects is NULL,
remove_device is not updated. Consequently *remove is not set to
true. Remove device is not performed in adapter_remove_connection.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
src/device.c

index ddc3e41557deaa4b6c60920c912bd6181e282b10..1093e4fffa73b3c9f622a2a12789c1155fa9bc96 100644 (file)
@@ -6038,19 +6038,6 @@ void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type,
                device->connect = NULL;
        }
 
-       while (device->disconnects) {
-               DBusMessage *msg = device->disconnects->data;
-
-#ifndef TIZEN_FEATURE_BLUEZ_MODIFY
-               if (dbus_message_is_method_call(msg, ADAPTER_INTERFACE,
-                                                               "RemoveDevice"))
-                       remove_device = true;
-#endif
-               g_dbus_send_reply(dbus_conn, msg, DBUS_TYPE_INVALID);
-               device->disconnects = g_slist_remove(device->disconnects, msg);
-               dbus_message_unref(msg);
-       }
-
        /* Check paired status of both bearers since it's possible to be
         * paired but not connected via link key to LTK conversion.
         */
@@ -6096,6 +6083,20 @@ void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type,
        g_dbus_emit_property_changed(dbus_conn, device->path,
                                                DEVICE_INTERFACE, "Connected");
 
+       /* remove device only if both bearers are disconnected */
+       while (device->disconnects) {
+               DBusMessage *msg = device->disconnects->data;
+
+#ifndef TIZEN_FEATURE_BLUEZ_MODIFY
+               if (dbus_message_is_method_call(msg, ADAPTER_INTERFACE,
+                                       "RemoveDevice"))
+                       remove_device = true;
+#endif
+               g_dbus_send_reply(dbus_conn, msg, DBUS_TYPE_INVALID);
+               device->disconnects = g_slist_remove(device->disconnects, msg);
+               dbus_message_unref(msg);
+       }
+
        if (remove_device)
                *remove = remove_device;
 #else