From: Atul Rai Date: Tue, 5 Jul 2016 06:30:01 +0000 (+0900) Subject: [Adapt] Set remote device friendly name X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F77%2F78377%2F1;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git [Adapt] Set remote device friendly name This patch adds implementation for _bt_set_alias API to enable friendly name (alias) setting for the bonded devices. Change-Id: I900fb8a25d4b30c3ebe0a7af5a50a378c5703286 Signed-off-by: Atul Rai --- diff --git a/bt-oal/bluez_hal/src/bt-hal-bluetooth.c b/bt-oal/bluez_hal/src/bt-hal-bluetooth.c index 47f1a2f..043ff5f 100644 --- a/bt-oal/bluez_hal/src/bt-hal-bluetooth.c +++ b/bt-oal/bluez_hal/src/bt-hal-bluetooth.c @@ -137,7 +137,7 @@ static int get_remote_device_property(bt_bdaddr_t *remote_addr, static int set_remote_device_property(bt_bdaddr_t *remote_addr, const bt_property_t *property) { - return BT_STATUS_UNSUPPORTED; + return _bt_hal_dbus_set_remote_device_property(remote_addr, property); } static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid) diff --git a/bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.c b/bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.c index bfb3639..859ccd4 100644 --- a/bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.c +++ b/bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.c @@ -562,3 +562,97 @@ int _bt_hal_dbus_get_remote_device_properties(bt_bdaddr_t *remote_addr) DBG("-"); return BT_STATUS_SUCCESS; } + +static int __bt_hal_dbus_set_remote_device_alias(bt_bdaddr_t *remote_addr, char *alias) +{ + char address[BT_HAL_ADDRESS_STRING_SIZE]; + gchar *device_path = NULL; + GDBusProxy *adapter_proxy; + GDBusProxy *device_proxy; + GError *error = NULL; + GDBusConnection *conn; + GVariant *result; + + adapter_proxy = _bt_get_adapter_proxy(); + if (!adapter_proxy) { + ERR("Could not get Adapter Proxy"); + return BT_STATUS_FAIL; + } + + conn = _bt_get_system_gconn(); + if (!conn) { + ERR("_bt_get_system_gconn failed"); + return BT_STATUS_FAIL; + } + + _bt_convert_addr_type_to_string(address, remote_addr->address); + INFO("Address: %s, Alias: %s", address, alias); + + device_path = _bt_get_device_object_path(address); + if (device_path == NULL) { + ERR("No paired device"); + return BT_STATUS_FAIL; + } + + device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, + NULL, BT_HAL_BLUEZ_NAME, device_path, + BT_HAL_PROPERTIES_INTERFACE, NULL, NULL); + g_free(device_path); + if (!device_proxy) { + ERR("Error creating device_proxy"); + return BT_STATUS_FAIL; + } + + result = g_dbus_proxy_call_sync(device_proxy, "Set", + g_variant_new("(ssv)", + BT_HAL_DEVICE_INTERFACE, + "Alias", g_variant_new("s", alias)), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + g_object_unref(device_proxy); + if (!result) { + ERR("Error occured in Proxy call"); + if (error != NULL) { + ERR("Error occured in Proxy call (Error: %s)", error->message); + g_clear_error(&error); + } + return BT_STATUS_FAIL; + } + g_variant_unref(result); + + return BT_STATUS_SUCCESS; +} + +/* Set Remote Device Properties */ +int _bt_hal_dbus_set_remote_device_property( + bt_bdaddr_t *remote_addr, const bt_property_t *property) +{ + int result; + + DBG("+"); + + if (remote_addr == NULL) { + ERR("Invalid parameters received"); + return BT_STATUS_PARM_INVALID; + } + + if (property == NULL || property->val == NULL) { + ERR("Invalid parameters received"); + return BT_STATUS_PARM_INVALID; + } + + switch (property->type) { + case BT_PROPERTY_REMOTE_FRIENDLY_NAME: + result = __bt_hal_dbus_set_remote_device_alias( + remote_addr, (char *) property->val); + break; + default: + result = BT_STATUS_UNSUPPORTED; + } + + DBG("Result= [%d]", result); + DBG("-"); + return result; +} diff --git a/bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.h b/bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.h index a7841fb..28a0543 100644 --- a/bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.h +++ b/bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.h @@ -42,6 +42,9 @@ int _bt_hal_device_remove_bond(const bt_bdaddr_t *bd_addr); int _bt_hal_dbus_get_remote_device_properties(bt_bdaddr_t *remote_addr); +int _bt_hal_dbus_set_remote_device_property( + bt_bdaddr_t *remote_addr, const bt_property_t *property); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/bt-oal/include/oal-device-mgr.h b/bt-oal/include/oal-device-mgr.h index 22b4524..63662da 100755 --- a/bt-oal/include/oal-device-mgr.h +++ b/bt-oal/include/oal-device-mgr.h @@ -45,6 +45,19 @@ extern "C" { */ oal_status_t device_query_attributes(bt_address_t * addr); +/** + * @brief Set alias for remote device + * + * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value. + * @retval #OAL_STATUS_SUCCESS Successful + * + * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED + * + * @see remote_device_t + */ +oal_status_t device_set_alias(bt_address_t * addr, char * alias); + + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/bt-oal/oal-device-mgr.c b/bt-oal/oal-device-mgr.c index 84218e5..ac9135b 100755 --- a/bt-oal/oal-device-mgr.c +++ b/bt-oal/oal-device-mgr.c @@ -62,6 +62,31 @@ oal_status_t device_query_attributes(bt_address_t *addr) return OAL_STATUS_SUCCESS; } +oal_status_t device_set_alias(bt_address_t * addr, char * alias) +{ + int res; + bt_property_t prop; + bdstr_t bdstr; + + CHECK_OAL_INITIALIZED(); + OAL_CHECK_PARAMETER(addr, return); + OAL_CHECK_PARAMETER(alias, return); + + API_TRACE("%s ->Alias: %s", bdt_bd2str(addr, &bdstr), alias); + + prop.type = BT_PROPERTY_REMOTE_FRIENDLY_NAME; + prop.len = strlen(alias); + prop.val = alias; + res = blued_api->set_remote_device_property((bt_bdaddr_t*)addr, &prop); + if (res != BT_STATUS_SUCCESS) { + BT_ERR("set_remote_device_property error: [%s]", status2string(res)); + BT_ERR("Alias: %s", alias); + return convert_to_oal_status(res); + } + + return OAL_STATUS_SUCCESS; +} + void cb_device_properties(bt_status_t status, bt_bdaddr_t *bd_addr, int num_properties, bt_property_t *properties) { diff --git a/bt-service-adaptation/services/bt-request-handler.c b/bt-service-adaptation/services/bt-request-handler.c index 6a62353..3ee932c 100644 --- a/bt-service-adaptation/services/bt-request-handler.c +++ b/bt-service-adaptation/services/bt-request-handler.c @@ -522,6 +522,17 @@ int __bt_bluez_request(int function_name, } break; } + case BT_SET_ALIAS: { + bluetooth_device_address_t address = { {0} }; + const char *local_name; + + __bt_service_get_parameters(in_param1, + &address, sizeof(bluetooth_device_address_t)); + local_name = (const char *)g_variant_get_data(in_param2); + + result = _bt_set_alias(&address, local_name); + break; + } default: BT_INFO("UnSupported function [%d]", function_name); result = BLUETOOTH_ERROR_NOT_SUPPORT; diff --git a/bt-service-adaptation/services/device/bt-service-core-device.c b/bt-service-adaptation/services/device/bt-service-core-device.c index 966b415..21bd662 100644 --- a/bt-service-adaptation/services/device/bt-service-core-device.c +++ b/bt-service-adaptation/services/device/bt-service-core-device.c @@ -328,3 +328,20 @@ int _bt_device_get_bonded_device_info(bluetooth_device_address_t *addr) BT_DBG("-"); return BLUETOOTH_ERROR_NONE; } + +int _bt_set_alias(bluetooth_device_address_t *device_address, const char *alias) +{ + int ret; + + BT_DBG("+"); + BT_CHECK_PARAMETER(alias, return); + + ret = device_set_alias((bt_address_t *)device_address, (char *)alias); + if (ret != OAL_STATUS_SUCCESS) { + BT_ERR("device_set_alias: %d", ret); + return BLUETOOTH_ERROR_INTERNAL; + } + + BT_DBG("-"); + return BLUETOOTH_ERROR_NONE; +} diff --git a/bt-service-adaptation/services/include/bt-service-core-device.h b/bt-service-adaptation/services/include/bt-service-core-device.h index 6fc9468..674a67a 100755 --- a/bt-service-adaptation/services/include/bt-service-core-device.h +++ b/bt-service-adaptation/services/include/bt-service-core-device.h @@ -30,6 +30,8 @@ void _bt_device_state_handle_callback_set_request(void); int _bt_device_get_bonded_device_info(bluetooth_device_address_t *addr); +int _bt_set_alias(bluetooth_device_address_t *device_address, const char *alias); + #ifdef __cplusplus } #endif /* __cplusplus */