Fix the agent register in multi-user mode 82/30882/1
authorwu zheng <wu.zheng@intel.com>
Wed, 26 Nov 2014 10:49:00 +0000 (18:49 +0800)
committerwu zheng <wu.zheng@intel.com>
Wed, 26 Nov 2014 10:49:00 +0000 (18:49 +0800)
In multi-user mode, register BT agent maybe fail.
Therefore, the related release task need to be done.
In single user mode, it is not very necessary.

Change-Id: I5294b9737349cb3c115093ba2646fb05734df42e
Signed-off-by: Wu Zheng <wu.zheng@intel.com>
capi/bluetooth.c

index 6f53aa07a43e36ed1be51227c94a3fd65d599204..343cbed0f8a6a70a2105ae05a7b847d0d09defef 100644 (file)
@@ -4188,12 +4188,18 @@ static int create_agent(void)
        if (bluetooth_agent_id)
                return BT_ERROR_ALREADY_DONE;
 
+       ret = comms_bluetooth_register_pairing_agent_sync(
+                                       AGENT_OBJECT_PATH, NULL);
+
+       if (ret != BT_SUCCESS)
+               return BT_ERROR_OPERATION_FAILED;
+
        introspection_data =
                g_dbus_node_info_new_for_xml(introspection_xml, NULL);
 
        ret = request_name_on_dbus(BLUEZ_AGENT_SERVICE);
        if (ret != 0)
-               return -1;
+               goto done;
 
        DBG("%s requested success", BLUEZ_AGENT_SERVICE);
 
@@ -4201,15 +4207,15 @@ static int create_agent(void)
                                        AGENT_OBJECT_PATH,
                                        introspection_data->interfaces[0],
                                        &interface_handle, NULL, NULL, NULL);
-       if (bluetooth_agent_id == 0)
-               return -1;
 
-       ret = comms_bluetooth_register_pairing_agent_sync(
-                                       AGENT_OBJECT_PATH, NULL);
-       if (ret != BT_SUCCESS)
-               return BT_ERROR_OPERATION_FAILED;
+       if (bluetooth_agent_id == 0)
+               goto done;
 
        return 0;
+done:
+       comms_bluetooth_unregister_pairing_agent(AGENT_OBJECT_PATH,
+                                                       NULL, NULL);
+       return -1;
 }
 
 int bt_agent_register(bt_agent *agent)