[Audio] Add API to switch between headsets 27/108027/2
authorGowtham Anandha Babu <gowtham.ab@samsung.com>
Thu, 29 Dec 2016 13:45:09 +0000 (19:15 +0530)
committerPyun DoHyun <dh79.pyun@samsung.com>
Mon, 16 Jan 2017 03:37:51 +0000 (19:37 -0800)
Change-Id: I5ddd2fa99eb7c35d4b51ae2802f390034215a50d
Signed-off-by: Gowtham Anandha Babu <gowtham.ab@samsung.com>
include/mobile/bluetooth_internal.h
include/tv/bluetooth_internal.h
include/wearable/bluetooth_internal.h
src/bluetooth-audio.c
test/bt_unit_test.c
test/bt_unit_test.h

index 44c1acbfdfc77d468124cdcb50736dbbe5887a03..1d04b1e7f92249eef8321b2fd734d382c1d37a1e 100644 (file)
@@ -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.
index 44c1acbfdfc77d468124cdcb50736dbbe5887a03..1d04b1e7f92249eef8321b2fd734d382c1d37a1e 100644 (file)
@@ -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.
index 057310cc617d6c9d15986757f3f6fa1dbccebf48..c2fe26d8efb5df83e8c5f6138d3dd9312b7d31f6 100644 (file)
@@ -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.
index 5115a73488eac88b43fa9bed3f7f0102e07ee420..d7d29557d22333a8b096c2dc61623e7b7f442bc4 100644 (file)
@@ -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;
index 2097dfdbfd1f2835b6325b88efadb57692c2418b..1bd548f171cd004575f5dae20f7b4e969cf9db8b 100644 (file)
@@ -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");
index 37318a528639020949819a0ab68e25c8a916b4f3..62e7b3fd92177f27cd3378b89bca474799fb917e 100644 (file)
@@ -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,