Disable map-agent in DA profile
[platform/core/connectivity/bluetooth-agent.git] / hid-agent / bluetooth-hid-agent.c
index 323713e..09008d3 100644 (file)
 #include <aul.h>
 
 #include "bluetooth-hid-agent.h"
+#include "bluetooth-hid-manager.h"
 
 static GMainLoop *gmain_loop;
 static char *g_obj_path;
 
 static GDBusConnection *gdbus_conn;
 static GDBusProxy *profile_gproxy;
-static guint owner_sig_id;
+static guint interface_added_sig_id;
+static guint interface_removed_sig_id;
 static guint bluez_device_sig_id;
 static guint name_owner_sig_id;
 
@@ -63,6 +65,7 @@ static int bt_hid_sig_to_handle[] = { SIGABRT, SIGSEGV, SIGTERM };
 static void __bt_hid_agent_sigterm_handler(int signo);
 static GError *__bt_hid_agent_set_error(bt_hid_agent_error_t error);
 
+/* LCOV_EXCL_START */
 static void __on_log_glib(const gchar *log_domain, GLogLevelFlags log_level,
                const gchar *msg, gpointer user_data)
 {
@@ -141,21 +144,23 @@ static void __bt_hid_name_owner_changed_cb(GDBusConnection *connection,
                                        GVariant *parameters,
                                        gpointer user_data)
 {
-       char *name_owner = NULL;
-       char *old_owner = NULL;
-       char *new_owner = NULL;
+       const char *name_owner = NULL;
+       const char *old_owner = NULL;
+       const char *new_owner = NULL;
        int ret = 0;
 
        if (strcasecmp(signal_name, "NameOwnerChanged") == 0) {
-               g_variant_get(parameters, "(sss)", &name_owner, &old_owner, &new_owner);
+               g_variant_get(parameters, "(&s&s&s)", &name_owner, &old_owner, &new_owner);
 
                ret = _bt_hid_register_application(FALSE, name_owner);
                if (ret == BT_HID_AGENT_ERROR_NONE) {
-                       is_hid_connectable = FALSE;
-                       if (name_owner_sig_id > 0) {
-                               g_dbus_connection_signal_unsubscribe(gdbus_conn,
-                                                       name_owner_sig_id);
-                               name_owner_sig_id = 0;
+                       if (_bt_hid_get_sender_list() == NULL) {
+                               is_hid_connectable = FALSE;
+                               if (name_owner_sig_id > 0) {
+                                       g_dbus_connection_signal_unsubscribe(gdbus_conn,
+                                                               name_owner_sig_id);
+                                       name_owner_sig_id = 0;
+                               }
                        }
                }
        }
@@ -195,11 +200,13 @@ static void __hid_agent_method(GDBusConnection *connection,
 
                ret = _bt_hid_register_application(FALSE, sender);
                if (ret == BT_HID_AGENT_ERROR_NONE) {
-                       is_hid_connectable = FALSE;
-                       if (name_owner_sig_id > 0) {
-                               g_dbus_connection_signal_unsubscribe(gdbus_conn,
-                                                       name_owner_sig_id);
-                               name_owner_sig_id = 0;
+                       if (_bt_hid_get_sender_list() == NULL) {
+                               is_hid_connectable = FALSE;
+                               if (name_owner_sig_id > 0) {
+                                       g_dbus_connection_signal_unsubscribe(gdbus_conn,
+                                                               name_owner_sig_id);
+                                       name_owner_sig_id = 0;
+                               }
                        }
                } else {
                        goto fail;
@@ -601,29 +608,6 @@ static void __bt_hid_agent_filter_cb(GDBusConnection *connection,
        FN_END;
 }
 
-void _bt_convert_device_path_to_address(const char *device_path,
-                                               char *device_address)
-{
-       char address[BT_ADDRESS_STRING_SIZE] = { 0 };
-       char *dev_addr;
-
-       ret_if(device_path == NULL);
-       ret_if(device_address == NULL);
-
-       dev_addr = strstr(device_path, "dev_");
-       if (dev_addr != NULL) {
-               char *pos = NULL;
-               dev_addr += 4;
-               g_strlcpy(address, dev_addr, sizeof(address));
-
-               while ((pos = strchr(address, '_')) != NULL) {
-                       *pos = ':';
-               }
-
-               g_strlcpy(device_address, address, BT_ADDRESS_STRING_SIZE);
-       }
-}
-
 static void __bt_hid_device_filter_cb(GDBusConnection *connection,
                                        const gchar *sender_name,
                                        const gchar *object_path,
@@ -738,12 +722,15 @@ static void __bt_hid_agent_dbus_init(void)
                return;
        }
 
-       if (!__bt_hid_agent_get_adapter_path(conn, NULL)) {
+       if (!__bt_hid_agent_get_adapter_path(conn, NULL))
                __bt_hid_agent_register();
-       }
 
-       owner_sig_id = g_dbus_connection_signal_subscribe(conn,
-                               NULL, BT_MANAGER_INTERFACE, NULL, NULL, NULL, 0,
+       interface_added_sig_id = g_dbus_connection_signal_subscribe(conn,
+                               NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_ADDED, NULL, NULL, 0,
+                               __bt_hid_agent_filter_cb, NULL, NULL);
+
+       interface_removed_sig_id = g_dbus_connection_signal_subscribe(conn,
+                               NULL, BT_MANAGER_INTERFACE, BT_INTERFACES_REMOVED, NULL, NULL, 0,
                                __bt_hid_agent_filter_cb, NULL, NULL);
 
        bluez_device_sig_id = g_dbus_connection_signal_subscribe(conn,
@@ -764,9 +751,13 @@ static void __bt_hid_agent_dbus_deinit(void)
        }
 
        if (gdbus_conn) {
-               if (owner_sig_id > 0)
+               if (interface_added_sig_id > 0)
                        g_dbus_connection_signal_unsubscribe(gdbus_conn,
-                                               owner_sig_id);
+                                               interface_added_sig_id);
+
+               if (interface_removed_sig_id > 0)
+                       g_dbus_connection_signal_unsubscribe(gdbus_conn,
+                                               interface_removed_sig_id);
 
                if (bluez_device_sig_id > 0)
                        g_dbus_connection_signal_unsubscribe(gdbus_conn,
@@ -776,7 +767,8 @@ static void __bt_hid_agent_dbus_deinit(void)
                        g_dbus_connection_signal_unsubscribe(gdbus_conn,
                                                name_owner_sig_id);
 
-               owner_sig_id = 0;
+               interface_added_sig_id = 0;
+               interface_removed_sig_id = 0;
                bluez_device_sig_id = 0;
                name_owner_sig_id = 0;
 
@@ -784,22 +776,22 @@ static void __bt_hid_agent_dbus_deinit(void)
                gdbus_conn = NULL;
        }
 }
+/* LCOV_EXCL_STOP */
 
-
-
-
-bt_hid_agent_error_t __bt_hid_disconnect_profile(void)
+bt_hid_agent_error_t _bt_hid_disconnect_profile(void)
 {
        FN_START;
-       GDBusProxy *proxy;
+       GDBusProxy *proxy = NULL;
 
-       proxy = __bt_hid_gdbus_get_device_proxy(bt_hid_info.object_path);
+       if (bt_hid_info.object_path)
+               proxy = __bt_hid_gdbus_get_device_proxy(bt_hid_info.object_path);
 
        if (proxy == NULL) {
                ERR("Error while getting proxy");
                return BT_HID_AGENT_ERROR_INTERNAL;
        }
 
+       /* LCOV_EXCL_START */
        g_dbus_proxy_call(proxy, "DisconnectProfile",
                        g_variant_new("(s)", HID_DEVICE_UUID),
                        G_DBUS_CALL_FLAGS_NONE, 2000,
@@ -808,8 +800,10 @@ bt_hid_agent_error_t __bt_hid_disconnect_profile(void)
        FN_END;
 
        return BT_HID_AGENT_ERROR_NONE;
+       /* LCOV_EXCL_STOP */
 }
 
+/* LCOV_EXCL_START */
 int main(void)
 {
        int i;
@@ -845,4 +839,4 @@ int main(void)
        INFO_C("### Terminating Bluetooth HID agent");
        return 0;
 }
-
+/* LCOV_EXCL_STOP */