Revert "Use FindDevice to get device object path" partially
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-agent.c
index 82e18d1..92ee46f 100644 (file)
@@ -23,8 +23,6 @@
 #include <vconf.h>
 #include <bundle_internal.h>
 
-#include <tethering.h>
-
 #include "bt-internal-types.h"
 #include "bt-service-common.h"
 #include "bt-service-agent.h"
@@ -75,7 +73,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); \
@@ -484,6 +482,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)
 {
@@ -494,10 +523,8 @@ static gboolean __authorize_request(GapAgentPrivate *agent, GDBusProxy *device,
        GVariant *reply = NULL;
        GVariant *reply_temp = NULL;
        GVariant *tmp_value;
-       bool enabled;
        int result = BLUETOOTH_ERROR_NONE;
        int request_type = BT_AGENT_EVENT_AUTHORIZE_REQUEST;
-       tethering_h tethering = NULL;
 
        BT_DBG("+");
 
@@ -516,12 +543,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) ||
@@ -545,24 +582,12 @@ static gboolean __authorize_request(GapAgentPrivate *agent, GDBusProxy *device,
                                BT_ERR("Max connection exceeded");
                                goto fail;
                        }
-                       int ret;
-                       ret = tethering_create(&tethering);
 
-                       if (ret != TETHERING_ERROR_NONE) {
-                               BT_ERR("Fail to create tethering: %d", ret);
-                               goto fail;
-                       }
-
-                       enabled = tethering_is_enabled(tethering, TETHERING_TYPE_BT);
-
-                       ret = tethering_destroy(tethering);
-
-                       if (ret != TETHERING_ERROR_NONE)
-                               BT_ERR("Fail to create tethering: %d", ret);
-
-                       if (enabled != true) {
-                               BT_ERR("BT tethering is not enabled");
-                               goto fail;
+                       if (headed_plugin_info->plugin_headed_enabled) {
+                               if (headed_plugin_info->headed_plugin->bt_is_tethering_enabled() == false) {
+                                       BT_ERR("BT tethering is not enabled");
+                                       goto fail;
+                               }
                        }
                }
 
@@ -642,13 +667,16 @@ fail:
                request_type = BT_AGENT_EVENT_MAP_REQUEST;
        /* TODO: MAP is already here */
 
-       if (trust) {
-               BT_INFO("Trusted device, so authorize\n");
+       if (trust || !headed_plugin_info->plugin_headed_enabled) {
+               BT_INFO("Trusted or Headless device, so authorize\n");
                gap_agent_reply_authorize(agent,
                                GAP_AGENT_ACCEPT, NULL);
-       } else {
-               if (headed_plugin_info->plugin_headed_enabled)
-                       headed_plugin_info->headed_plugin->bt_launch_system_popup(request_type, name, auth_info, NULL, NULL,
+
+               goto done;
+       }
+
+       if (headed_plugin_info->plugin_headed_enabled) {
+               headed_plugin_info->headed_plugin->bt_launch_system_popup(request_type, name, auth_info, NULL, NULL,
                                        _gap_agent_get_path(agent));
        }