Add the audio connection storage 23/87423/3
authorHyuk Lee <hyuk0512.lee@samsung.com>
Thu, 8 Sep 2016 02:40:00 +0000 (11:40 +0900)
committerPyun DoHyun <dh79.pyun@samsung.com>
Fri, 9 Sep 2016 02:31:20 +0000 (19:31 -0700)
Change-Id: I757b63c1754cd65e3451ccfb208bb37ed8c104cf
Signed-off-by: Hyuk Lee <hyuk0512.lee@samsung.com>
bt-service/bt-service-audio.c
bt-service/bt-service-event-receiver.c
bt-service/include/bt-service-device.h
include/bluetooth-api.h

index 03bd39b..2f02c95 100644 (file)
@@ -693,6 +693,8 @@ int _bt_audio_connect(int request_id, int type,
        char *uuid;
        int value = BLUETOOTH_ERROR_NONE;
        bt_audio_function_data_t *func_data;
+       guint hfp_hs_restricted = 0x0; /* set default "allowed" */
+       guint a2dp_restricted = 0x0;
 
        BT_CHECK_PARAMETER(device_address, return);
 
@@ -717,6 +719,14 @@ int _bt_audio_connect(int request_id, int type,
        func_data->pending = BT_PENDING_NONE;
        func_data->out_param = out_param1;
 
+       result = _bt_get_restrict_profile(device_address, RESTRICTED_PROFILE_HFP_HS, &hfp_hs_restricted);
+       if (result != BLUETOOTH_ERROR_NONE)
+               BT_ERR("Can't get hfp_hs restriction info");
+
+       result = _bt_get_restrict_profile(device_address, RESTRICTED_PROFILE_A2DP, &a2dp_restricted);
+       if (result != BLUETOOTH_ERROR_NONE)
+               BT_ERR("Can't get a2dp restriction info");
+
        switch (type) {
        case BT_AUDIO_HSP:
                uuid = HFP_HS_UUID;
@@ -731,17 +741,41 @@ int _bt_audio_connect(int request_id, int type,
                uuid = A2DP_SOURCE_UUID;
                break;
        case BT_AUDIO_ALL:
-               if (__bt_device_support_uuid(address, BT_AUDIO_HSP)) {
-                       uuid = HFP_HS_UUID;
-                       func_data->pending = BT_PENDING_CONNECT;
-                       type = BT_AUDIO_HSP;
-               } else if (__bt_device_support_uuid(address, BT_AUDIO_A2DP)) {
-                       uuid = A2DP_SINK_UUID;
-                       type = BT_AUDIO_A2DP;
-               } else {
-                       BT_ERR("No audio role supported");
-                       result = BLUETOOTH_ERROR_SERVICE_NOT_FOUND;
+               if ((hfp_hs_restricted == 0x0) && (a2dp_restricted == 0x0)) { /* in case of both profiles are not restricted */
+                       if (__bt_device_support_uuid(address, BT_AUDIO_HSP)) {
+                               uuid = HFP_HS_UUID;
+                               func_data->pending = BT_PENDING_CONNECT;
+                               type = BT_AUDIO_HSP;
+                       } else if (__bt_device_support_uuid(address, BT_AUDIO_A2DP)) {
+                               uuid = A2DP_SINK_UUID;
+                               type = BT_AUDIO_A2DP;
+                       } else {
+                               BT_ERR("No audio role supported");
+                               result = BLUETOOTH_ERROR_SERVICE_NOT_FOUND;
+                               goto fail;
+                       }
+               } else if ((hfp_hs_restricted == 0x1) && (a2dp_restricted == 0x1)) { /* in case of both profiles are restricted */
+                       BT_ERR("All profiles are restricted");
+                       result = BLUETOOTH_ERROR_INTERNAL;
                        goto fail;
+               } else if (a2dp_restricted == 0x01) { /* in case of a2dp is restricted, only connection for hfp_hs */
+                       if (__bt_device_support_uuid(address, BT_AUDIO_HSP)) {
+                               uuid = HFP_HS_UUID;
+                               type = BT_AUDIO_HSP;
+                       } else {
+                               BT_ERR("HFP_HS role is not supported");
+                               result = BLUETOOTH_ERROR_SERVICE_NOT_FOUND;
+                               goto fail;
+                       }
+               } else if (hfp_hs_restricted == 0x01) { /* in case of hfp_hs is restricted, only connection for a2dp */
+                       if (__bt_device_support_uuid(address, BT_AUDIO_A2DP)) {
+                               uuid = A2DP_SINK_UUID;
+                               type = BT_AUDIO_A2DP;
+                       } else {
+                               BT_ERR("A2DP role is not supported");
+                               result = BLUETOOTH_ERROR_SERVICE_NOT_FOUND;
+                               goto fail;
+                       }
                }
                break;
        case BT_AVRCP_TARGET:
index 0f31857..b55b6c5 100644 (file)
@@ -1844,6 +1844,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                int state = 0;
                char *profile_uuid = NULL;
                bt_headset_wait_t *wait_list;
+               bluetooth_device_address_t bd_addr;
 
                g_variant_get(msg, "(si)", &profile_uuid, &state);
 
@@ -1851,6 +1852,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                ret_if(address == NULL);
 
                _bt_convert_device_path_to_address(path, address);
+               _bt_convert_addr_string_to_type(bd_addr.addr, address);
 
                _bt_convert_addr_string_to_secure_string(secure_address, address);
                BT_DBG("Address: %s", secure_address);
@@ -1865,15 +1867,19 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                        bluetooth_device_address_t device_address;
                        gboolean connected;
                        bt_headset_wait_t *wait_list;
+                       guint restricted = 0x0;
 
                        __bt_set_device_values(TRUE,
                                VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
 
                        __bt_connection_manager_set_state(address, event);
 
-                       if (_bt_headset_get_local_connection() == FALSE)
-                               _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
-                       else {
+                       _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_HFP_HS, &restricted);
+
+                       if (_bt_headset_get_local_connection() == FALSE) {
+                               if (restricted == 0x0) /* not restricted*/
+                                       _bt_start_timer_for_connection(address, BT_AUDIO_HSP);
+                       } else {
                                /* Connection Started from local device therefore no need to
                                 * intiate connection for pending profile */
                                _bt_headset_set_local_connection(FALSE);
@@ -2217,6 +2223,7 @@ void _bt_handle_headset_event(GVariant *msg, const char *path)
        GVariant *value = NULL;
        GVariant *param = NULL;
        g_variant_get(msg, "(sv)", &property, &value);
+       bluetooth_device_address_t bd_addr;
 
        ret_if(property == NULL);
 
@@ -2226,6 +2233,7 @@ void _bt_handle_headset_event(GVariant *msg, const char *path)
                int event = BLUETOOTH_EVENT_NONE;
                bt_headset_wait_t *wait_list;
                char *address;
+               guint restricted = 0x0;
                g_variant_get(value, "b", &property_flag);
 
                address = g_malloc0(BT_ADDRESS_STRING_SIZE);
@@ -2233,12 +2241,16 @@ void _bt_handle_headset_event(GVariant *msg, const char *path)
                        return;
 
                _bt_convert_device_path_to_address(path, address);
+               _bt_convert_addr_string_to_type(bd_addr.addr, address);
 
                if (property_flag == TRUE) {
                        event = BLUETOOTH_EVENT_AG_CONNECTED;
-                       if (_bt_headset_get_local_connection() == FALSE)
-                               _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
-                       else
+                       _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_A2DP, &restricted);
+
+                       if (_bt_headset_get_local_connection() == FALSE) {
+                               if (restricted == 0x0) /* not restricted*/
+                                       _bt_start_timer_for_connection(address, BT_AUDIO_A2DP);
+                       } else
                                _bt_headset_set_local_connection(FALSE);
                } else {
                        int previous_state;
index 8b96333..a364cfd 100644 (file)
@@ -114,6 +114,12 @@ int _bt_set_trust_profile(bluetooth_device_address_t *bd_addr,
 int _bt_get_trust_profile(bluetooth_device_address_t *bd_addr,
                bluetooth_trusted_profile_t profile, guint *trust);
 
+int _bt_set_restrict_profile(bluetooth_device_address_t *bd_addr,
+               bluetooth_restricted_profile_t profile, gboolean restricted);
+
+int _bt_get_restrict_profile(bluetooth_device_address_t *bd_addr,
+               bluetooth_restricted_profile_t profile, guint *restricted);
+
 bluetooth_trusted_profile_t _bt_get_trusted_profile_enum(const char *uuid);
 
 int _bt_connect_le_ipsp_device(const bluetooth_device_address_t *bd_addr);
index 2a68318..6251311 100644 (file)
@@ -2331,7 +2331,7 @@ int bluetooth_get_profile_trusted(
  *
  * @param[in]  device_address  a device address of remote bluetooth device
  * @param[in]  profile profile which is to be set as restricted[1-HFP_HS, 2-A2DP]
- * @param[in]  restricted      to set as restricted or not[1-not 0-restricted]
+ * @param[in]  restricted      to set as restricted or not[1-restricted 0-permitted]
  *
  * @return     BLUETOOTH_ERROR_NONE - Success \n
  *             BLUETOOTH_ERROR_DEVICE_NOT_ENABLED - Adapter is not enabled \n
@@ -2354,7 +2354,7 @@ int bluetooth_set_profile_restricted(
  *
  * @param[in]  device_address  a device address of remote bluetooth device
  * @param[in]  profile profile whose restricted status is needed[1-HFP_HS, 2-A2DP]
- * @param[out] restricted      profile is set as restricted or not[1-not 0-restricted]
+ * @param[out] restricted      profile is set as restricted or not[1-restricted 0-permitted]
  *
  * @return     BLUETOOTH_ERROR_NONE - Success \n
  *             BLUETOOTH_ERROR_DEVICE_NOT_ENABLED - Adapter is not enabled \n