Check connectable when authorize for HID device is requested.
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-agent.c
index b3cb43a..88aad6c 100644 (file)
@@ -78,7 +78,7 @@
 
 extern guint nap_connected_device_count;
 
-static char *passkey_watcher = NULL;
+static char *passkey_watcher;
 
 #define G_VARIANT_UNREF(variant) \
        g_variant_unref(variant); \
@@ -581,6 +581,37 @@ static gboolean __a2dp_authorize_request_check(void)
        return _bt_is_headset_type_connected(BT_AUDIO_A2DP, NULL);
 }
 
+static gboolean __bt_agent_is_hid_device_connectable(void)
+{
+       GDBusProxy *proxy = NULL;
+       GVariant *reply = NULL;
+       GError *err = NULL;
+       gboolean connectable = FALSE;
+
+       proxy = _bt_gdbus_get_hid_agent_proxy();
+       retv_if(proxy == NULL, FALSE);
+
+       reply = g_dbus_proxy_call_sync(proxy, "IsHidConnectable", NULL,
+                               G_DBUS_CALL_FLAGS_NONE, 2000, NULL, &err);
+       if (reply == NULL) {
+               BT_ERR("Error returned in method call");
+               if (err != NULL) {
+                       BT_ERR("Error message = %s", err->message);
+                       g_error_free(err);
+               }
+               connectable = FALSE;
+       } else {
+               g_variant_get(reply, "(b)", &connectable);
+               g_variant_unref(reply);
+       }
+       g_object_unref(proxy);
+
+       BT_INFO("HID Device is %s",
+                       connectable ? "Connectable" : "Non-connectable");
+
+       return connectable;
+}
+
 static gboolean __authorize_request(GapAgentPrivate *agent, GDBusProxy *device,
                                                        const char *uuid)
 {
@@ -615,12 +646,22 @@ static gboolean __authorize_request(GapAgentPrivate *agent, GDBusProxy *device,
        }
        /* Check completed */
 
+       if (!strcasecmp(uuid, HID_UUID)) {
+               gboolean is_connectable = __bt_agent_is_hid_device_connectable();
+               BT_DBG("Automatically %s authorization for HID",
+                       is_connectable ? "accept" : "reject");
+               if (is_connectable == TRUE)
+                       gap_agent_reply_authorize(agent, GAP_AGENT_ACCEPT, NULL);
+               else
+                       gap_agent_reply_authorize(agent, GAP_AGENT_REJECT, NULL);
+               goto done;
+       }
+
        if (!strcasecmp(uuid, HFP_AUDIO_GATEWAY_UUID) ||
             !strcasecmp(uuid, HSP_AUDIO_GATEWAY_UUID) ||
             !strcasecmp(uuid, HFP_HS_UUID) ||
             !strcasecmp(uuid, HSP_HS_UUID) ||
             !strcasecmp(uuid, A2DP_UUID) ||
-            !strcasecmp(uuid, HID_UUID) ||
             !strcasecmp(uuid, HID_DEVICE_UUID) ||
             !strcasecmp(uuid, SAP_UUID_OLD) ||
             !strcasecmp(uuid, SAP_UUID_NEW) ||
@@ -1138,3 +1179,4 @@ int _bt_set_passkey_notification(const char *sender, gboolean enable)
 
        return BLUETOOTH_ERROR_NONE;
 }
+