From: Gowtham Anandha Babu Date: Thu, 29 Dec 2016 13:45:09 +0000 (+0530) Subject: [Audio] Add API to switch between headsets X-Git-Tag: submit/tizen_3.0/20170118.073413~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=60917c572645deda222f4e63aa9fb47412dc83bc;p=platform%2Fcore%2Fapi%2Fbluetooth.git [Audio] Add API to switch between headsets Change-Id: I5ddd2fa99eb7c35d4b51ae2802f390034215a50d Signed-off-by: Gowtham Anandha Babu --- diff --git a/include/mobile/bluetooth_internal.h b/include/mobile/bluetooth_internal.h index 44c1acb..1d04b1e 100644 --- a/include/mobile/bluetooth_internal.h +++ b/include/mobile/bluetooth_internal.h @@ -2098,6 +2098,23 @@ int bt_ag_is_wbs_mode(bool *wbs_mode); */ int bt_ag_is_connected(bool *connected); +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Switch between the connected headsets for AG role. + * @since_tizen 3.0 + * @param[out] + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Not connected + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_ag_switch_headset(const char *remote_addr); + /** * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_A2DP_MODULE * @brief Sets copy protection. streaming application that needs to have the copy protection for the streaming data, shall invoke this API. diff --git a/include/tv/bluetooth_internal.h b/include/tv/bluetooth_internal.h index 44c1acb..1d04b1e 100644 --- a/include/tv/bluetooth_internal.h +++ b/include/tv/bluetooth_internal.h @@ -2098,6 +2098,23 @@ int bt_ag_is_wbs_mode(bool *wbs_mode); */ int bt_ag_is_connected(bool *connected); +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Switch between the connected headsets for AG role. + * @since_tizen 3.0 + * @param[out] + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Not connected + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_ag_switch_headset(const char *remote_addr); + /** * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_A2DP_MODULE * @brief Sets copy protection. streaming application that needs to have the copy protection for the streaming data, shall invoke this API. diff --git a/include/wearable/bluetooth_internal.h b/include/wearable/bluetooth_internal.h index 057310c..c2fe26d 100644 --- a/include/wearable/bluetooth_internal.h +++ b/include/wearable/bluetooth_internal.h @@ -2068,6 +2068,23 @@ int bt_ag_is_wbs_mode(bool *wbs_mode); */ int bt_ag_is_connected(bool *connected); +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Switch between the connected headsets for AG role. + * @since_tizen 3.0 + * @param[out] + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Not connected + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_ag_switch_headset(const char *remote_addr); + /** * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_HF_MODULE * @brief Registers a callback function that will be invoked when the SCO(Synchronous Connection Oriented link) state is changed. diff --git a/src/bluetooth-audio.c b/src/bluetooth-audio.c index 5115a73..d7d2955 100644 --- a/src/bluetooth-audio.c +++ b/src/bluetooth-audio.c @@ -743,6 +743,27 @@ int bt_ag_is_connected(bool *connected) return error; } +int bt_ag_switch_headset(const char *remote_addr) +{ + int error; + + BT_CHECK_HFP_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_AG_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_addr); + + char *addr = g_strdup(remote_addr); + BT_INFO("Remote address = %s", addr); + + error = bluetooth_telephony_set_active_headset(addr); + error = _bt_get_error_code(error); + + if (error != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error), error); + + return error; +} + int bt_call_list_create(bt_call_list_h *list) { call_list_s *handle; diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c index 2097dfd..1bd548f 100644 --- a/test/bt_unit_test.c +++ b/test/bt_unit_test.c @@ -523,6 +523,8 @@ tc_table_t tc_audio[] = { , BT_UNIT_TEST_FUNCTION_AG_SET_CALL_HANDLING_EVENT_CB}, {"bt_ag_is_nrec_enabled" , BT_UNIT_TEST_FUNCTION_AG_IS_NREC_ENABLED}, + {"bt_ag_switch_headset" + , BT_UNIT_TEST_FUNCTION_AG_SWITCH_HEADSET}, /* A2DP SCMS-T functions */ {"Select this menu to set parameters and then select the function again." @@ -3638,6 +3640,35 @@ int test_set_params(int test_id, char *param) break; } + case BT_UNIT_TEST_FUNCTION_AG_SWITCH_HEADSET: { + if (param_index == 0) { + g_test_param.param_count = 1; + g_test_param.params = g_malloc0(sizeof(char *) *g_test_param.param_count); + param_type = BT_UNIT_TEST_PARAM_TYPE_STRING; + } + + if (param_index > 0) { + g_test_param.params[param_index - 1] = g_malloc0(strlen(param) + 1); + strncpy(g_test_param.params[param_index - 1], param, strlen(param)); + } + + if (param_index == g_test_param.param_count) { + need_to_set_params = false; +#ifdef ARCH64 + test_input_callback((void *)(uintptr_t)test_id); +#else + test_input_callback((void *)test_id); +#endif + param_index = 0; + return 0; + } + + TC_PRT("Input param(%d) type:%s", + param_index + 1, param_type); + param_index++; + + break; + } default: TC_PRT("There is no param to set\n"); @@ -6149,6 +6180,19 @@ int test_input_callback(void *data) TC_PRT("returns %s\n", __bt_get_error_message(ret)); break; } + case BT_UNIT_TEST_FUNCTION_AG_SWITCH_HEADSET: { + if (g_test_param.param_count < 0) { + TC_PRT("Input parameters first"); + break; + } + + ret = bt_ag_switch_headset(g_test_param.params[0]); + __bt_free_test_param(&g_test_param); + + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: need_to_set_params = true; TC_PRT("Select the function again"); diff --git a/test/bt_unit_test.h b/test/bt_unit_test.h index 37318a5..62e7b3f 100644 --- a/test/bt_unit_test.h +++ b/test/bt_unit_test.h @@ -211,6 +211,7 @@ typedef enum { BT_UNIT_TEST_FUNCTION_AG_NOTIFY_CALL_LIST, BT_UNIT_TEST_FUNCTION_AG_SET_CALL_HANDLING_EVENT_CB, BT_UNIT_TEST_FUNCTION_AG_IS_NREC_ENABLED, + BT_UNIT_TEST_FUNCTION_AG_SWITCH_HEADSET, BT_UNIT_TEST_FUNCTION_AG_IS_WBS_MODE, BT_UNIT_TEST_FUNCTION_AG_SET_VENDOR_CMD_CB, BT_UNIT_TEST_FUNCTION_AG_UNSET_VENDOR_CMD_CB,