device: don't wait for timeout if RemoveDevice is called
authorArchie Pusaka <apusaka@chromium.org>
Tue, 15 Sep 2020 03:04:19 +0000 (11:04 +0800)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:32 +0000 (19:08 +0530)
RemoveDevice on adapter interface used to remove a device, even when
the device is connected. However, since the introduction of the new
30 seconds timeout when setting a device as temporary, RemoveDevice
doesn't immediately remove a connected device, but only disconnects
it and waits for the timer to expire before effectively removes it.

This patch removes the device as soon as it gets disconnected,
provided the disconnection is triggered by a call to RemoveDevice.
The regular timeout still applies for other cases.

Tested manually by calling RemoveDevice on a connected device,
and with ChromeOS autotest setup.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/adapter.c
src/adapter.h
src/device.c

index a681742..ba96f46 100644 (file)
@@ -85,8 +85,6 @@
 #include "../profile.h"
 #endif
 
-#define ADAPTER_INTERFACE      "org.bluez.Adapter1"
-
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
 #ifdef TIZEN_FEATURE_BLUEZ_BATTERY_WATCH
 #define DEVICED_DEST                   "org.tizen.system.deviced"
index 31c87b0..efe6133 100644 (file)
@@ -27,6 +27,9 @@
 #include <glib.h>
 #include <lib/bluetooth.h>
 #include <lib/sdp.h>
+
+#define ADAPTER_INTERFACE      "org.bluez.Adapter1"
+
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/sdp.h>
index 2f8a291..f8d1f66 100644 (file)
@@ -5438,6 +5438,7 @@ void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type)
 {
        struct bearer_state *state = get_state(device, bdaddr_type);
        DBusMessage *reply;
+       bool remove_device = false;
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        char *dev_name = device->name;
 #endif
@@ -5482,6 +5483,10 @@ void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type)
        while (device->disconnects) {
                DBusMessage *msg = device->disconnects->data;
 
+               if (dbus_message_is_method_call(msg, ADAPTER_INTERFACE,
+                                                               "RemoveDevice"))
+                       remove_device = true;
+
                g_dbus_send_reply(dbus_conn, msg, DBUS_TYPE_INVALID);
                device->disconnects = g_slist_remove(device->disconnects, msg);
                dbus_message_unref(msg);
@@ -5508,6 +5513,9 @@ void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type)
 
        g_dbus_emit_property_changed(dbus_conn, device->path,
                                                DEVICE_INTERFACE, "Connected");
+
+       if (remove_device)
+               btd_adapter_remove_device(device->adapter, device);
 #else
        g_dbus_emit_signal(dbus_conn, device->path,
                DEVICE_INTERFACE, "Disconnected",
@@ -7210,6 +7218,9 @@ void device_remove(struct btd_device *device, gboolean remove_stored)
                disconnect_all(device);
        }
 
+       if (device->temporary_timer > 0)
+               g_source_remove(device->temporary_timer);
+
        if (device->store_id > 0) {
                g_source_remove(device->store_id);
                device->store_id = 0;