adapter: Check pending when setting DiscoverableTimeout
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 25 Jul 2018 08:39:55 +0000 (11:39 +0300)
committerhimanshu <h.himanshu@samsung.com>
Tue, 14 Jan 2020 08:53:35 +0000 (14:23 +0530)
This makes DiscoverableTimeout check if discoverable is already pending
and don't attempt to set it once again which may cause discoverable to
be re-enabled when in fact the application just want to set the timeout
alone.

Change-Id: I5ffb43845cf90698ed92e0d06301e77d4fbee8b7
Signed-off-by: himanshu <h.himanshu@samsung.com>
src/adapter.c

index f8c057d..b0207e2 100644 (file)
@@ -6638,6 +6638,7 @@ static void property_set_discoverable_timeout(
                                GDBusPendingPropertySet id, void *user_data)
 {
        struct btd_adapter *adapter = user_data;
+       bool enabled;
        dbus_uint32_t value;
 
        dbus_message_iter_get_basic(iter, &value);
@@ -6651,8 +6652,19 @@ static void property_set_discoverable_timeout(
        g_dbus_emit_property_changed(dbus_conn, adapter->path,
                                ADAPTER_INTERFACE, "DiscoverableTimeout");
 
+       if (adapter->pending_settings & MGMT_SETTING_DISCOVERABLE) {
+               if (adapter->current_settings & MGMT_SETTING_DISCOVERABLE)
+                       enabled = false;
+               else
+                       enabled = true;
+       } else {
+               if (adapter->current_settings & MGMT_SETTING_DISCOVERABLE)
+                       enabled = true;
+               else
+                       enabled = false;
+       }
 
-       if (adapter->current_settings & MGMT_SETTING_DISCOVERABLE)
+       if (enabled)
                set_discoverable(adapter, 0x01, adapter->discoverable_timeout);
 }