sixaxis: Fix fliping device.trusted automatically
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 2 Aug 2022 00:05:36 +0000 (17:05 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
device.trusted is a user preference which controls if the devices needs
to be authorized or not so the plugin shall not overwrite it and instead
just honor what user has set and skip authorizing if already trusted.

Fixes: https://github.com/bluez/bluez/issues/372
Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
plugins/sixaxis.c
src/device.c
src/device.h

index ec5910d..7e2936a 100755 (executable)
@@ -293,7 +293,6 @@ static void agent_auth_cb(DBusError *derr, void *user_data)
        }
 
        remove_device = false;
-       btd_device_set_trusted(closure->device, true);
        btd_device_set_temporary(closure->device, false);
 
        if (closure->type == CABLE_PAIRING_SIXAXIS)
@@ -335,10 +334,9 @@ static bool setup_device(int fd, const char *sysfs_path,
         * connected eg. to charge up battery. */
        device = btd_adapter_find_device(adapter, &device_bdaddr,
                                                        BDADDR_BREDR);
-       if (device != NULL &&
-               btd_device_is_connected(device) &&
-               g_slist_find_custom(btd_device_get_uuids(device), HID_UUID,
-                                               (GCompareFunc)strcasecmp)) {
+       if (device && btd_device_has_uuid(device, HID_UUID) &&
+                       (btd_device_is_connected(device) ||
+                        btd_device_is_trusted(device))) {
                char device_addr[18];
                ba2str(&device_bdaddr, device_addr);
                DBG("device %s already known, skipping", device_addr);
@@ -351,7 +349,6 @@ static bool setup_device(int fd, const char *sysfs_path,
 
        btd_device_device_set_name(device, cp->name);
        btd_device_set_pnpid(device, cp->source, cp->vid, cp->pid, cp->version);
-       btd_device_set_trusted(device, false);
        btd_device_set_temporary(device, true);
 
        closure = g_new0(struct authentication_closure, 1);
index d00a95a..d0a0dad 100644 (file)
@@ -7422,6 +7422,12 @@ GSList *btd_device_get_uuids(struct btd_device *device)
        return device->uuids;
 }
 
+bool btd_device_has_uuid(struct btd_device *device, const char *uuid)
+{
+       return g_slist_find_custom(device->uuids, uuid,
+                                               (GCompareFunc)strcasecmp);
+}
+
 struct probe_data {
        struct btd_device *dev;
        GSList *uuids;
index ad92087..5045143 100644 (file)
@@ -74,6 +74,7 @@ struct device_addr_type {
 int device_addr_type_strict_cmp(gconstpointer a, gconstpointer b);
 #endif
 int device_addr_type_cmp(gconstpointer a, gconstpointer b);
+bool btd_device_has_uuid(struct btd_device *device, const char *uuid);
 GSList *btd_device_get_uuids(struct btd_device *device);
 void device_probe_profiles(struct btd_device *device, GSList *profiles);