Remove After tag to remove cyclic dependency
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-device.c
index 32297fc..e7002e9 100644 (file)
@@ -19,6 +19,7 @@
 #include <gio/gio.h>
 #include <dlog.h>
 #include <string.h>
+#include <syspopup_caller.h>
 #include <vconf.h>
 #include <bundle_internal.h>
 
@@ -36,7 +37,6 @@
 #include "bt-service-network.h"
 #include "bt-service-adapter.h"
 #include "bt-service-gap-agent.h"
-#include "bt-service-pbap.h"
 
 #define BT_SYSPOPUP_IPC_RESPONSE_OBJECT "/org/projectx/bt_syspopup_res"
 #define BT_SYSPOPUP_INTERFACE "User.Bluetooth.syspopup"
@@ -66,9 +66,6 @@
 #define BT_LE_CONN_PARAM_LOW_POWER_SLAVE_LATENCY       2       /* event */
 
 #define PROFILE_SUPPORTED 0x3 /* This corresponds to binary 0b11*/
-#define PROFILE_TRUSTED 0x2 /* This corresponds to binary 0b10*/
-#define PROFILE_BLOCKED 0x1 /* This corresponds to binary 0b01*/
-#define PROFILE_SHOW_AUTH 0x0 /* This corresponds to binary 0b00*/
 
 typedef struct {
        int req_id;
@@ -125,9 +122,6 @@ static guint pending_le_conn_timer_id = 0;
 static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
                                        gpointer user_data);
 
-static int __bt_retry_bond(void);
-
-
 /*static void __bt_decline_pair_request()
 {
        GVariant *out_param1;
@@ -211,6 +205,63 @@ done:
        BT_DBG("-");
 } */
 
+#ifdef TIZEN_PROFILE_WEARABLE
+static gboolean __bt_syspopup_timer_cb(gpointer user_data)
+{
+       int ret;
+       bundle *b;
+       retv_if(user_data == NULL, FALSE);
+
+       b = (bundle *)user_data;
+
+       ret = syspopup_launch("bt-syspopup", b);
+       if (ret < 0) {
+               BT_ERR("Sorry!! Cannot launch popup return = %d, Retrying...", ret);
+       } else {
+               BT_DBG("Hurray!!! Finally Popup launched");
+               bundle_free(b);
+       }
+       return (ret < 0) ? TRUE : FALSE;
+}
+
+static gboolean __bt_launch_unable_to_pairing_syspopup(int result)
+{
+       BT_DBG("+");
+       int ret = 0;
+       bundle *b = NULL;
+       GDBusConnection *conn;
+
+       conn = _bt_gdbus_get_system_gconn();
+       if (conn == NULL)
+               return FALSE;
+
+       b = bundle_create();
+       if (b == NULL)
+               return FALSE;
+
+       bundle_add(b, "event-type", "unable-to-pairing");
+
+       if (result == BLUETOOTH_ERROR_TIMEOUT)
+               bundle_add(b, "error", "timeout");
+       else if (result == BLUETOOTH_ERROR_AUTHENTICATION_FAILED)
+               bundle_add(b, "error", "authfailed");
+       else
+               bundle_add(b, "error", "error");
+
+       ret = syspopup_launch("bt-syspopup", b);
+       if (0 > ret) {
+               BT_ERR("Popup launch failed...retry %d \n", ret);
+               g_timeout_add(200, (GSourceFunc) __bt_syspopup_timer_cb,
+                               b);
+       } else {
+               bundle_free(b);
+       }
+
+       BT_DBG("-");
+       return TRUE;
+}
+#endif
+
 gboolean _bt_is_device_creating(void)
 {
        return is_device_creating;
@@ -279,12 +330,8 @@ static void __bt_get_uuids(GVariant *value, bt_remote_dev_info_t *info)
        ret_if(value == NULL);
        ret_if(info == NULL);
 
-       gsize uuid_count = 0;
-
-       info->uuids = g_variant_dup_strv(value, &uuid_count);
-       info->uuid_count = (unsigned int)uuid_count;
-
-       BT_DBG("uuid count : %d", uuid_count);
+       info->uuid_count = g_variant_get_size(value);
+       info->uuids = g_variant_dup_strv(value, &info->uuid_count);
 }
 
 bt_remote_dev_info_t *_bt_get_remote_device_info(char *address)
@@ -422,7 +469,7 @@ bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path(
                        g_variant_unref(tmp_value);
                }
 
-               tmp_value = g_variant_lookup_value(value, "ManufacturerDataLen", G_VARIANT_TYPE_UINT16);
+               tmp_value = g_variant_lookup_value(value, "LegacyManufacturerDataLen", G_VARIANT_TYPE_UINT16);
                if (tmp_value) {
                        dev_info->manufacturer_data_len = g_variant_get_uint16(tmp_value);
                        if (dev_info->manufacturer_data_len > BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX) {
@@ -433,7 +480,7 @@ bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path(
                } else
                        dev_info->manufacturer_data_len = 0;
 
-               tmp_value = g_variant_lookup_value(value, "ManufacturerData", G_VARIANT_TYPE_ARRAY);
+               tmp_value = g_variant_lookup_value(value, "LegacyManufacturerData", G_VARIANT_TYPE_ARRAY);
                if (tmp_value) {
                        if ((dev_info->manufacturer_data_len == 0) ||
                                        dev_info->manufacturer_data_len != g_variant_get_size(tmp_value)) {
@@ -457,9 +504,8 @@ bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path(
                g_variant_get(tmp_value, "s", &address);
                g_variant_unref(tmp_value);
 
-               dev_info->address = g_strdup(address);
-               dev_info->name = g_strdup(name);
-               g_free(name);
+               dev_info->address = address;
+               dev_info->name = name;
                g_variant_unref(value);
        } else {
                BT_ERR("result  is NULL\n");
@@ -642,73 +688,6 @@ static int __bt_cancel_bonding(void)
        return BLUETOOTH_ERROR_NONE;
 }
 
-static int __bt_retry_bond(void)
-{
-       BT_CHECK_PARAMETER(bonding_info, return);
-       BT_CHECK_PARAMETER(bonding_info->addr, return);
-
-       is_device_creating = TRUE;
-
-       g_dbus_proxy_call(bonding_info->device_proxy, "Pair",
-                               g_variant_new("(y)", bonding_info->conn_type),
-                               G_DBUS_CALL_FLAGS_NONE,
-                               BT_MAX_DBUS_TIMEOUT,
-                               NULL,
-                               (GAsyncReadyCallback)__bt_bond_device_cb,
-                               NULL);
-
-       return BLUETOOTH_ERROR_NONE;
-}
-
-
-static int __bt_remove_and_bond(void)
-{
-       GDBusProxy *adapter_proxy;
-       GVariant *result = NULL;
-       GError *err = NULL;
-       char *device_path = NULL;
-
-       BT_CHECK_PARAMETER(bonding_info, return);
-       BT_CHECK_PARAMETER(bonding_info->addr, return);
-
-       adapter_proxy = _bt_get_adapter_proxy();
-       retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-       device_path = _bt_get_device_object_path(bonding_info->addr);
-       retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
-
-       result = g_dbus_proxy_call_sync(adapter_proxy, "UnpairDevice",
-                               g_variant_new("(o)", device_path),
-                               G_DBUS_CALL_FLAGS_NONE,
-                               -1,
-                               NULL,
-                               &err);
-       g_free(device_path);
-       if (result == NULL) {
-               if (err != NULL) {
-                       BT_ERR("UnpairDevice Fail: %s", err->message);
-                       g_error_free(err);
-               }
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       g_variant_unref(result);
-       return __bt_retry_bond();
-}
-
-static int __bt_cancel_and_bond(void)
-{
-       int ret = BLUETOOTH_ERROR_NONE;
-
-       ret = _bt_agent_reply_cancellation();
-       if (ret != BLUETOOTH_ERROR_NONE) {
-               BT_ERR("Fail to call reply cancellation");
-               return ret;
-       }
-       return __bt_retry_bond();
-}
-
-
 static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
                                        gpointer user_data)
 {
@@ -723,8 +702,7 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
        GVariant *param;
 
        /* Terminate ALL system popup */
-       if (headed_plugin_info->plugin_headed_enabled)
-               headed_plugin_info->headed_plugin->bt_destroy_popup_all();
+       syspopup_destroy_all();
 
        reply = g_dbus_proxy_call_finish(proxy, res, &err);
        if (reply)
@@ -751,10 +729,8 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
                BT_ERR("Error occured in CreateBonding [%s]", err->message);
 
                if (g_strrstr(err->message, "Already Exists")) {
-                       BT_INFO("Existing Bond, remove and retry");
-                       ret_if(__bt_remove_and_bond() == BLUETOOTH_ERROR_NONE);
-
-                       result = BLUETOOTH_ERROR_PARING_FAILED;
+                       BT_INFO("Existing Bond");
+                       result = BLUETOOTH_ERROR_ALREADY_CONNECT;
                } else if (_bt_agent_is_canceled() ||
                        g_strrstr(err->message, "Authentication Canceled")) {
                        BT_INFO("Cancelled by USER");
@@ -763,10 +739,8 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
                        BT_INFO("REJECTED");
                        result = BLUETOOTH_ERROR_ACCESS_DENIED;
                } else if (g_strrstr(err->message, "In Progress")) {
-                       BT_INFO("Bond in progress, cancel and retry");
-                       ret_if(__bt_cancel_and_bond() == BLUETOOTH_ERROR_NONE);
-
-                       result = BLUETOOTH_ERROR_PARING_FAILED;
+                       BT_INFO("Bond in progress");
+                       result = BLUETOOTH_ERROR_IN_PROGRESS;
                } else if (g_strrstr(err->message, "Authentication Failed")) {
                        BT_INFO("Authentication Failed");
                        if (bonding_info->is_autopair == TRUE) {
@@ -805,19 +779,17 @@ static void __bt_bond_device_cb(GDBusProxy *proxy, GAsyncResult *res,
                        result == BLUETOOTH_ERROR_AUTHENTICATION_FAILED ||
                        result == BLUETOOTH_ERROR_TIMEOUT ||
                        result == BLUETOOTH_ERROR_HOST_DOWN) {
-               if (TIZEN_PROFILE_WEARABLE) {
-                       int is_sw_running = 0;
+#ifdef TIZEN_PROFILE_WEARABLE
+               int is_sw_running = 0;
 
-                       if (vconf_get_int(VCONFKEY_SETUP_WIZARD_STATE, &is_sw_running))
-                               BT_ERR("vconf_get_int for setup wizard state failed");
+               if (vconf_get_int(VCONFKEY_SETUP_WIZARD_STATE, &is_sw_running))
+                       BT_ERR("vconf_get_int for setup wizard state failed");
 
-                       if (!is_sw_running) {
-                               if (headed_plugin_info->plugin_headed_enabled)
-                                       headed_plugin_info->headed_plugin->bt_launch_unable_to_pairing_syspopup(result);
-                       } else {
-                               BT_ERR("Unable to pair");
-                       }
-               }
+               if (!is_sw_running)
+                       __bt_launch_unable_to_pairing_syspopup(result);
+               else
+                       BT_ERR("Unable to pair");
+#endif
                bonding_info->result = result;
        }
 
@@ -920,6 +892,8 @@ dbus_return:
        g_dbus_method_invocation_return_value(req_info->context,
                        g_variant_new("(iv)", result, out_param1));
 
+       g_variant_unref(out_param1);
+
        _bt_delete_request_list(req_info->req_id);
 done:
        if (err)
@@ -1723,12 +1697,8 @@ int _bt_is_device_connected(bluetooth_device_address_t *device_address,
                BT_DBG("uuid %s [%s]", uuid, _bt_convert_uuid_to_string(uuid));
 
                object_path = _bt_get_device_object_path(address);
-               if (!object_path) {
-                       BT_ERR("object_path is NULL");
-                       g_free(uuid);
-                       return BLUETOOTH_ERROR_NOT_PAIRED;
-               }
-
+               retv_if(object_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
+               BT_DBG("object_path: %s", object_path);
                device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
                                                                        NULL, BT_BLUEZ_NAME,
                                                                        object_path, BT_DEVICE_INTERFACE,  NULL, NULL);
@@ -1945,41 +1915,14 @@ fail:
 
 static gboolean __bt_connect_le_timer_cb(gpointer user_data)
 {
-       int ret;
-
        BT_INFO("Try to initiate pending LE connection");
 
        pending_le_conn_timer_id = 0;
 
-       ret = __bt_connect_le_device_internal(pending_le_conn_info->req_id,
-                       &pending_le_conn_info->bd_addr,
-                       pending_le_conn_info->auto_connect);
-       if (ret != BLUETOOTH_ERROR_NONE) {
-               request_info_t *req_info = NULL;
-               GVariant *out_param1;
-
-               req_info = _bt_get_request_info(pending_le_conn_info->req_id);
-               if (req_info == NULL) {
-                       BT_ERR("req_info is NULL");
-                       goto done;
-               }
-
-               if (req_info->context == NULL) {
-                       BT_ERR("req_info->context is NULL");
-                       _bt_delete_request_list(req_info->req_id);
-                       goto done;
-               }
+       __bt_connect_le_device_internal(pending_le_conn_info->req_id,
+               &pending_le_conn_info->bd_addr,
+               pending_le_conn_info->auto_connect);
 
-               out_param1 = g_variant_new_from_data((const GVariantType *)"ay",
-                               &pending_le_conn_info->bd_addr,
-                               sizeof(bluetooth_device_address_t), TRUE,
-                               NULL, NULL);
-
-               g_dbus_method_invocation_return_value(req_info->context,
-                               g_variant_new("(iv)", ret, out_param1));
-       }
-
-done:
        g_free(pending_le_conn_info);
        pending_le_conn_info = NULL;
 
@@ -2133,17 +2076,8 @@ int _bt_connect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
                g_object_unref(device_proxy);
                return BLUETOOTH_ERROR_INTERNAL;
        }
-       g_object_unref(device_proxy);
-
-       /* IPSP daemon launch */
-       GDBusProxy *ipsp_proxy;
-
-       ipsp_proxy = _bt_get_ipsp_proxy();
-       retv_if(ipsp_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       g_dbus_proxy_call(ipsp_proxy, "EnableIpsp",
-                       NULL, G_DBUS_CALL_FLAGS_NONE,
-                       -1, NULL, NULL, NULL);
+       g_object_unref(device_proxy);
 
        return ret;
 }
@@ -2906,7 +2840,7 @@ int _bt_get_le_connection_parameter(bluetooth_le_connection_mode_t mode,
 int _bt_get_trusted_profile_from_flag(bluetooth_trusted_profile_t profile,
                guint trusted_profile_flag, guint *trusted)
 {
-       int trust_profile = FALSE;
+       int trust_profile;
        *trusted = FALSE;
 
        switch (profile) {
@@ -2928,24 +2862,6 @@ int _bt_get_trusted_profile_from_flag(bluetooth_trusted_profile_t profile,
                else
                        return BLUETOOTH_ERROR_NOT_SUPPORT;
                break;
-       case TRUSTED_PROFILE_HFP_HF: {
-               guint flag = (trusted_profile_flag & (PROFILE_SUPPORTED << 6)) >> 6;
-               BT_DBG("trusted_profile_flag %x", trusted_profile_flag);
-               if (flag != PROFILE_BLOCKED)
-                       trust_profile = TRUE;
-               else
-                       *trusted = FALSE;
-               break;
-       }
-       case TRUSTED_PROFILE_A2DP: {
-               guint flag = (trusted_profile_flag & (PROFILE_SUPPORTED << 8)) >> 8;
-               BT_DBG("trusted_profile_flag %x", trusted_profile_flag);
-               if (flag != PROFILE_BLOCKED)
-                       trust_profile = TRUE;
-               else
-                       *trusted = FALSE;
-               break;
-       }
        case TRUSTED_PROFILE_ALL: /* Return Flag for All profiles*/
                *trusted = trusted_profile_flag;
                return BLUETOOTH_ERROR_NONE;
@@ -2959,6 +2875,29 @@ int _bt_get_trusted_profile_from_flag(bluetooth_trusted_profile_t profile,
        return BLUETOOTH_ERROR_NONE;
 }
 
+int _bt_get_restricted_profile_from_flag(bluetooth_restricted_profile_t profile,
+               guint restricted_profile_flag, guint *restricted)
+{
+       int restrict_profile;
+       *restricted = FALSE;
+
+       switch (profile) {
+       case RESTRICTED_PROFILE_HFP_HS:
+                       restrict_profile = restricted_profile_flag & (1 << 0);
+               break;
+       case RESTRICTED_PROFILE_A2DP:
+                       restrict_profile = restricted_profile_flag & (1 << 2);
+               break;
+       default:
+               return BLUETOOTH_ERROR_NOT_SUPPORT;
+       }
+
+       if (restrict_profile)
+               *restricted = TRUE;
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
 char *_bt_get_trusted_profile_uuid(bluetooth_trusted_profile_t profile)
 {
        switch (profile) {
@@ -2968,10 +2907,6 @@ char *_bt_get_trusted_profile_uuid(bluetooth_trusted_profile_t profile)
                return g_strdup("00001134-0000-1000-8000-00805f9b34fb");
        case TRUSTED_PROFILE_SAP:
                return g_strdup("0000112D-0000-1000-8000-00805f9b34fb");
-       case TRUSTED_PROFILE_HFP_HF:
-               return g_strdup("0000111e-0000-1000-8000-00805f9b34fb");
-       case TRUSTED_PROFILE_A2DP:
-               return g_strdup("0000110b-0000-1000-8000-00805f9b34fb");
        case TRUSTED_PROFILE_ALL:
                return NULL;
        }
@@ -2979,6 +2914,18 @@ char *_bt_get_trusted_profile_uuid(bluetooth_trusted_profile_t profile)
        return NULL;
 }
 
+char *_bt_get_restricted_profile_uuid(bluetooth_restricted_profile_t profile)
+{
+       switch (profile) {
+       case RESTRICTED_PROFILE_HFP_HS:
+               return g_strdup("0000111e-0000-1000-8000-00805f9b34fb");
+       case RESTRICTED_PROFILE_A2DP:
+               return g_strdup("0000110b-0000-1000-8000-00805f9b34fb");
+       }
+
+       return NULL;
+}
+
 bluetooth_trusted_profile_t _bt_get_trusted_profile_enum(const char *uuid)
 {
        if (g_strcmp0("0000112f-0000-1000-8000-00805f9b34fb", uuid) == 0)
@@ -3117,6 +3064,132 @@ int _bt_get_trust_profile(bluetooth_device_address_t *bd_addr,
        return ret;
 }
 
+int _bt_set_restrict_profile(bluetooth_device_address_t *bd_addr,
+               bluetooth_restricted_profile_t profile, gboolean restricted)
+{
+       int ret = BLUETOOTH_ERROR_NONE;
+       GDBusConnection *conn;
+       GDBusProxy *proxy;
+       GError *error = NULL;
+       char *device_path = NULL;
+       char *uuid = NULL;
+       char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+       GVariant *reply;
+
+       BT_CHECK_PARAMETER(bd_addr, return);
+       BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X] profile[%d] restricted[%d]",
+                       bd_addr->addr[0], bd_addr->addr[1],
+                       bd_addr->addr[2], bd_addr->addr[3],
+                       bd_addr->addr[4], bd_addr->addr[5],
+                       profile, restricted);
+
+       conn = _bt_gdbus_get_system_gconn();
+       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       _bt_convert_addr_type_to_string(address, bd_addr->addr);
+
+       device_path = _bt_get_device_object_path(address);
+       retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+                       NULL, BT_BLUEZ_NAME, device_path,
+                       BT_DEVICE_INTERFACE, NULL, NULL);
+
+       g_free(device_path);
+       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       uuid = _bt_get_restricted_profile_uuid(profile);
+       if (uuid == NULL) {
+               g_object_unref(proxy);
+               return BLUETOOTH_ERROR_NOT_SUPPORT;
+       }
+
+       reply = g_dbus_proxy_call_sync(proxy, "SetRestrictedProfile",
+                       g_variant_new("(sb)", uuid, restricted),
+                       G_DBUS_CALL_FLAGS_NONE, -1,
+                       NULL, &error);
+       g_object_unref(proxy);
+
+       if (reply == NULL) {
+               BT_ERR("Failed to Set Profile Restricted");
+               ret = BLUETOOTH_ERROR_INTERNAL;
+               if (error) {
+                       BT_ERR("Error %s[%s]", error->message, address);
+                       g_error_free(error);
+               }
+               goto finish;
+       }
+       g_variant_unref(reply);
+
+finish:
+       g_free(uuid);
+       return ret;
+}
+
+int _bt_get_restrict_profile(bluetooth_device_address_t *bd_addr,
+               bluetooth_restricted_profile_t profile, guint *restricted)
+{
+       int ret = BLUETOOTH_ERROR_NONE;
+       GDBusConnection *conn;
+       GDBusProxy *proxy;
+       GError *error = NULL;
+       char *device_path = NULL;
+       guint restricted_profile_flag;
+       char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+       GVariant *reply;
+
+       BT_CHECK_PARAMETER(bd_addr, return);
+       BT_DBG("BD Address [%2.2X %2.2X %2.2X %2.2X %2.2X %2.2X] profile[%d] restricted[%d]",
+                       bd_addr->addr[0], bd_addr->addr[1],
+                       bd_addr->addr[2], bd_addr->addr[3],
+                       bd_addr->addr[4], bd_addr->addr[5],
+                       profile, *restricted);
+
+       conn = _bt_gdbus_get_system_gconn();
+       retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       _bt_convert_addr_type_to_string(address, bd_addr->addr);
+
+       device_path = _bt_get_device_object_path(address);
+       retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+                       NULL, BT_BLUEZ_NAME, device_path,
+                       BT_PROPERTIES_INTERFACE, NULL, NULL);
+
+       g_free(device_path);
+       retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       reply = g_dbus_proxy_call_sync(proxy, "Get",
+                       g_variant_new("(ss)", BT_DEVICE_INTERFACE, "RestrictedProfiles"),
+                       G_DBUS_CALL_FLAGS_NONE, -1,
+                       NULL, &error);
+       g_object_unref(proxy);
+
+       if (reply == NULL) {
+               BT_ERR("Failed to Get Profile Restricted");
+               ret = BLUETOOTH_ERROR_INTERNAL;
+               if (error) {
+                       BT_ERR("Error %s[%s]", error->message, address);
+                       g_error_free(error);
+               }
+               *restricted = 0;
+       } else {
+               GVariant *temp;
+               g_variant_get(reply, "(v)", &temp);
+               restricted_profile_flag = g_variant_get_uint32(temp);
+               BT_DBG("Restricted_FLAG %d", restricted_profile_flag);
+
+               ret = _bt_get_restricted_profile_from_flag(profile,
+                               restricted_profile_flag, restricted);
+               g_variant_unref(temp);
+               g_variant_unref(reply);
+       }
+
+       BT_DBG("TRUST %d", *restricted);
+       return ret;
+}
+
 static void __bt_request_att_mtu_device_cb(GDBusProxy *proxy, GAsyncResult *res,
                                        gpointer user_data)
 {
@@ -3331,47 +3404,37 @@ int _bt_get_device_ida(bluetooth_device_address_t *device_address,
        retv_if(device_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
 
        device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
-                                                               NULL, BT_BLUEZ_NAME,
-                                                               device_path, BT_DEVICE_INTERFACE,  NULL, NULL);
+                       NULL, BT_BLUEZ_NAME,
+                       device_path, BT_DEVICE_INTERFACE,  NULL, NULL);
        g_free(device_path);
        if (!device_proxy) {
                BT_ERR("Unable to get proxy");
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       result = g_dbus_proxy_call_sync(device_proxy, "GetIDAddress",
-                                NULL,
-                                G_DBUS_CALL_FLAGS_NONE,
-                                -1,
-                                NULL,
-                                &error);
-
+       result = g_dbus_proxy_call_sync(device_proxy, "GetIDAddress", NULL,
+                       G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
        if (result == NULL) {
                BT_ERR("Failed to get device ID address");
+
+               ret = BLUETOOTH_ERROR_INTERNAL;
                if (error != NULL) {
-                       BT_ERR("Error occured in Proxy call [%s]\n", error->message);
+                       g_dbus_error_strip_remote_error(error);
+                       BT_ERR("Error occured in Proxy call [%s]", error->message);
+                       if (g_strcmp0(error->message, "Does Not Exist") == 0)
+                               ret = BLUETOOTH_ERROR_NOT_PAIRED;
                        g_error_free(error);
                }
                g_object_unref(device_proxy);
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       g_variant_get(result , "(s)", &idaddress);
-       g_variant_unref(result);
-
-       if (idaddress == NULL) {
-               BT_ERR("No paired device");
-               g_object_unref(device_proxy);
-               return BLUETOOTH_ERROR_NOT_PAIRED;
+               return ret;
        }
 
-       BT_DBG("ID Address:%s", idaddress);
+       g_variant_get(result , "(&s)", &idaddress);
 
-       if (idaddress)
-               _bt_convert_addr_string_to_type(id_address->addr, idaddress);
-       else
-               ret = BLUETOOTH_ERROR_INTERNAL;
+       DBG_SECURE("ID Address : %s", idaddress);
+       _bt_convert_addr_string_to_type(id_address->addr, idaddress);
 
+       g_variant_unref(result);
        g_object_unref(device_proxy);
 
        return ret;