From 283fc6758ee6f8f45b6bd1e7da1c0835bad21136 Mon Sep 17 00:00:00 2001 From: Hyuk Lee Date: Fri, 9 Sep 2016 15:51:47 +0900 Subject: [PATCH] Add the audio connection storage Change-Id: I02807a760867c711eeb343bedf382a761f5a0808 Signed-off-by: Hyuk Lee --- src/ui/bt-main-view.c | 19 +++++++++++++++++++ src/ui/bt-profile-view.c | 31 +++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/ui/bt-main-view.c b/src/ui/bt-main-view.c index a92d90b..ee53d74 100644 --- a/src/ui/bt-main-view.c +++ b/src/ui/bt-main-view.c @@ -3404,6 +3404,9 @@ void _bt_main_connect_device(bt_ug_data *ugd, bt_dev_t *dev) FN_START; int headset_type = BT_AUDIO_PROFILE_TYPE_ALL; + int ret; + int hfp_restricted = 0x0; + int a2dp_restricted = 0x0; ret_if(ugd == NULL); ret_if(dev == NULL); @@ -3428,6 +3431,22 @@ void _bt_main_connect_device(bt_ug_data *ugd, bt_dev_t *dev) headset_type = BT_AUDIO_PROFILE_TYPE_HSP_HFP; BT_INFO("Connection type = %d", headset_type); + if (headset_type == BT_AUDIO_PROFILE_TYPE_ALL) { + /* restriction check */ + bt_device_get_profile_restricted(dev->addr_str, BT_RESTRICTED_PROFILE_HFP_HS, &hfp_restricted); + bt_device_get_profile_restricted(dev->addr_str, BT_RESTRICTED_PROFILE_A2DP, &a2dp_restricted); + BT_INFO("Restricted Connection, HFP:%d, A2DP:%d", hfp_restricted, a2dp_restricted); + + if ((hfp_restricted == 0x1) && (a2dp_restricted == 0x1)) { + ret = bt_device_set_profile_restricted(dev->addr_str, BT_RESTRICTED_PROFILE_HFP_HS, 0x0); + if (ret != BT_ERROR_NONE) + BT_ERR("Fail to set profile restriction"); + + ret = bt_device_set_profile_restricted(dev->addr_str, BT_RESTRICTED_PROFILE_A2DP, 0x0); + if (ret != BT_ERROR_NONE) + BT_ERR("Fail to set profile restriction"); + } + } if (bt_audio_connect(dev->addr_str, headset_type) == BT_ERROR_NONE) { diff --git a/src/ui/bt-profile-view.c b/src/ui/bt-profile-view.c index 72dba6a..f5a92d5 100644 --- a/src/ui/bt-profile-view.c +++ b/src/ui/bt-profile-view.c @@ -824,9 +824,11 @@ static void __bt_profile_media_option_checkbox_sel(void *data, Evas_Object *obj, if (dev->connected_mask & BT_STEREO_HEADSET_CONNECTED) { ret = __bt_profile_disconnect_option((bt_ug_data *)dev->ugd, dev, BT_STEREO_HEADSET_DEVICE); + } else { ret = __bt_profile_connect_option((bt_ug_data *)dev->ugd, dev, BT_STEREO_HEADSET_DEVICE); + } #endif @@ -1043,20 +1045,31 @@ int __bt_profile_connect_option(bt_ug_data *ugd, bt_dev_t *dev, FN_START; int audio_profile; + int ret; retv_if(ugd == NULL, BT_UG_FAIL); retv_if(dev == NULL, BT_UG_FAIL); if (type == BT_HEADSET_DEVICE || type == BT_STEREO_HEADSET_DEVICE || type == BT_MUSIC_PLAYER_DEVICE) { - if (type == BT_STEREO_HEADSET_DEVICE) + if (type == BT_STEREO_HEADSET_DEVICE) { audio_profile = BT_AUDIO_PROFILE_TYPE_A2DP; + /* set restriction : allowed */ + ret = bt_device_set_profile_restricted(dev->addr_str, BT_RESTRICTED_PROFILE_A2DP, 0x0); + if (ret != BT_ERROR_NONE) + BT_ERR("Failed to set restriction"); + } #ifdef TIZEN_BT_A2DP_SINK_ENABLE else if (type == BT_MUSIC_PLAYER_DEVICE) audio_profile = BT_AUDIO_PROFILE_TYPE_A2DP_SINK; #endif - else + else { + /* set restriction : allowed */ audio_profile = BT_AUDIO_PROFILE_TYPE_HSP_HFP; + ret = bt_device_set_profile_restricted(dev->addr_str, BT_RESTRICTED_PROFILE_HFP_HS, 0x0); + if (ret != BT_ERROR_NONE) + BT_ERR("Failed to set restriction"); + } if (bt_audio_connect(dev->addr_str, audio_profile) != BT_ERROR_NONE) { @@ -1128,6 +1141,7 @@ int __bt_profile_disconnect_option(bt_ug_data *ugd, bt_dev_t *dev, FN_START; int audio_profile; + int ret; bt_ug_ipc_param_t param; gboolean connected = FALSE; gboolean connected_nap_profile = FALSE; @@ -1168,14 +1182,23 @@ int __bt_profile_disconnect_option(bt_ug_data *ugd, bt_dev_t *dev, if (type == BT_HEADSET_DEVICE || type == BT_STEREO_HEADSET_DEVICE || type == BT_MUSIC_PLAYER_DEVICE) { - if (type == BT_STEREO_HEADSET_DEVICE) + if (type == BT_STEREO_HEADSET_DEVICE) { audio_profile = BT_AUDIO_PROFILE_TYPE_A2DP; + ret = bt_device_set_profile_restricted(dev->addr_str, BT_RESTRICTED_PROFILE_A2DP, 0x1); + if (ret != BT_ERROR_NONE) + BT_ERR("Failed to set restriction"); + } #ifdef TIZEN_BT_A2DP_SINK_ENABLE else if (type == BT_MUSIC_PLAYER_DEVICE) audio_profile = BT_AUDIO_PROFILE_TYPE_A2DP_SINK; #endif - else + else { audio_profile = BT_AUDIO_PROFILE_TYPE_HSP_HFP; + ret = bt_device_set_profile_restricted(dev->addr_str, BT_RESTRICTED_PROFILE_HFP_HS, 0x1); + if (ret != BT_ERROR_NONE) + BT_ERR("Failed to set restriction"); + } + if (bt_audio_disconnect(dev->addr_str, audio_profile) != BT_ERROR_NONE) { -- 2.7.4