Modify the initialization logic for A2DP role 47/218747/3 accepted/tizen/unified/20191128.161921 submit/tizen/20191128.024748
authorDoHyun Pyun <dh79.pyun@samsung.com>
Wed, 27 Nov 2019 22:22:28 +0000 (07:22 +0900)
committerPyun DoHyun <dh79.pyun@samsung.com>
Thu, 28 Nov 2019 00:54:56 +0000 (00:54 +0000)
Change-Id: Id03706dc12aa3f14ac6966fcf54db40f40309cba
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
12 files changed:
bt-oal/bluez_hal/inc/bt-hal-msg.h
bt-oal/bluez_hal/src/bt-hal-a2dp-sink-dbus-handler.c
bt-oal/bluez_hal/src/bt-hal-a2dp-sink.c
bt-oal/bluez_hal/src/bt-hal-av-dbus-handler.c
bt-oal/bluez_hal/src/bt-hal-av.c
bt-oal/bluez_hal/src/bt-hal-event-receiver.c
bt-oal/hardware/bluetooth.h
bt-oal/include/oal-event.h
bt-oal/oal-adapter-mgr.c
bt-service-adaptation/services/adapter/bt-service-core-adapter.c
bt-service-adaptation/services/bt-service-event-receiver.c
bt-service-adaptation/services/include/bt-service-audio-common.h

index 19ea3b7..e42f101 100644 (file)
@@ -79,6 +79,7 @@ struct hal_prop_device_service_rec {
 #define HAL_PROP_DEVICE_IS_ALIAS_SET           0x19
 #define HAL_PROP_ADAPTER_LE_DISCOVERY_STARTED   0x1a
 #define HAL_PROP_ADAPTER_LE_DISCOVERY_STOPPED  0x1b
+#define HAL_PROP_ADAPTER_A2DP_ROLE              0x1c
 
 struct hal_prop_device_info {
        uint8_t version;
index e64f19a..383a336 100644 (file)
@@ -230,11 +230,6 @@ bt_status_t _bt_hal_dbus_handler_enable_a2dp_sink(void)
 
        DBG("+");
 
-       if (_bt_hal_is_service_enabled(A2DP_SINK_UUID)) {
-               ERR("Audio sink role already enabled, return");
-               return BT_STATUS_SUCCESS;
-       }
-
        gconn = _bt_hal_get_system_gconn();
        if (!gconn) {
                ERR("_bt_hal_get_system_gconn returned NULL, return");
@@ -273,7 +268,7 @@ bt_status_t _bt_hal_dbus_handler_enable_a2dp_sink(void)
                        /* Add the exception case for Already Exists */
                        if (g_strrstr(error->message, "Already Exists")) {
                                g_clear_error(&error);
-                               return BT_STATUS_SUCCESS;
+                               return BT_STATUS_DONE;
                        }
 
                        g_clear_error(&error);
index dbe7829..0d80fce 100644 (file)
@@ -91,10 +91,14 @@ static bt_status_t init(btav_callbacks_t* callbacks)
 {
        DBG("");
 
+       int ret = BT_STATUS_SUCCESS;
+
        if (interface_ready())
                return BT_STATUS_DONE;
 
-       if (BT_STATUS_SUCCESS != _bt_hal_dbus_handler_enable_a2dp_sink()) {
+       ret = _bt_hal_dbus_handler_enable_a2dp_sink();
+
+       if (ret != BT_STATUS_SUCCESS && ret != BT_STATUS_DONE) {
                ERR("_bt_hal_dbus_handler_enable_a2dp_sink failed");
                return BT_STATUS_FAIL;
        }
index 2e53a49..598dc25 100644 (file)
@@ -230,11 +230,6 @@ bt_status_t _bt_hal_dbus_handler_enable_a2dp_source(void)
 
        DBG("+");
 
-       if (_bt_hal_is_service_enabled(A2DP_SOURCE_UUID)) {
-               ERR("Audio sink role already enabled, return");
-               return BT_STATUS_SUCCESS;
-       }
-
        gconn = _bt_hal_get_system_gconn();
        if (!gconn) {
                ERR("_bt_hal_get_system_gconn returned NULL, return");
@@ -273,7 +268,7 @@ bt_status_t _bt_hal_dbus_handler_enable_a2dp_source(void)
                        /* Add the exception case for Already Exists */
                        if (g_strrstr(error->message, "Already Exists")) {
                                g_clear_error(&error);
-                               return BT_STATUS_SUCCESS;
+                               return BT_STATUS_DONE;
                        }
 
                        g_clear_error(&error);
index 7cfa029..fdb121d 100644 (file)
@@ -92,10 +92,14 @@ static bt_status_t init(btav_callbacks_t* callbacks)
 {
        DBG("");
 
+       int ret = BT_STATUS_SUCCESS;
+
        if (interface_ready())
                return BT_STATUS_DONE;
 
-       if (BT_STATUS_SUCCESS != _bt_hal_dbus_handler_enable_a2dp_source()) {
+       ret = _bt_hal_dbus_handler_enable_a2dp_source();
+
+       if (ret != BT_STATUS_SUCCESS && ret != BT_STATUS_DONE) {
                ERR("_bt_hal_dbus_handler_enable_a2dp_source failed");
                return BT_STATUS_FAIL;
        }
index 35627d7..9572875 100644 (file)
@@ -205,6 +205,7 @@ static void __bt_hal_adapter_property_changed_event(GVariant *msg)
        const gchar *address = NULL;
        gchar *name = NULL;
        unsigned int cod = 0;
+       unsigned int a2dp_role = 0;
        gboolean discoverable;
        gboolean connectable;
        unsigned int scan_mode = BT_SCAN_MODE_NONE;
@@ -478,6 +479,12 @@ static void __bt_hal_adapter_property_changed_event(GVariant *msg)
                } else if (!g_strcmp0(key, "IpspInitStateChanged")) {
                        g_variant_get(value, "b" , &ipsp_initialized);
                        DBG("##IPSP Initialized = %d", ipsp_initialized);
+               } else if (!g_strcmp0(key, "A2dpRole")) {
+                       a2dp_role = g_variant_get_uint32(value);
+                       DBG("##A2dp Role [%d]", a2dp_role);
+                       size += __bt_insert_hal_properties(buf + size,
+                                       HAL_PROP_ADAPTER_A2DP_ROLE, sizeof(unsigned int), &a2dp_role);
+                       ev->num_props++;
                } else {
                        ERR("Unhandled Property:[%s]", key);
                }
index a803394..affaa83 100644 (file)
@@ -386,6 +386,13 @@ typedef enum {
         */
        BT_PROPERTY_ADAPTER_LE_DISCOVERY_STOPPED,
 
+       /**
+       * Description - A2DP role of media endpoint
+       * Access mode - Only GET.
+       * Data type   - uint32_t.
+       */
+       BT_PROPERTY_A2DP_ROLE = 0x1c,
+
        BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP = 0xFF,
 } bt_property_type_t;
 
index 96e93e6..b14dbeb 100644 (file)
@@ -40,6 +40,7 @@ extern "C" {
        EVENT(OAL_EVENT_ADAPTER_PROPERTY_NAME)                          /* char string */\
        EVENT(OAL_EVENT_ADAPTER_PROPERTY_VERSION)                       /* char string */\
        EVENT(OAL_EVENT_ADAPTER_PROPERTY_SERVICES)                      /* event_adapter_services_t */\
+       EVENT(OAL_EVENT_ADAPTER_PROPERTY_A2DP_ROLE)                     /* uint32_t */\
        EVENT(OAL_EVENT_ADAPTER_MODE_NON_CONNECTABLE)   \
        EVENT(OAL_EVENT_ADAPTER_MODE_CONNECTABLE)       \
        EVENT(OAL_EVENT_ADAPTER_MODE_DISCOVERABLE)      \
index e32572c..7fa21df 100644 (file)
@@ -932,6 +932,18 @@ static void cb_adapter_properties(bt_status_t status,
                                        event_data, (sizeof(event_device_list_t) + num_bonded * sizeof(bt_bdaddr_t)));
                        break;
                }
+               case BT_PROPERTY_A2DP_ROLE: {
+                       unsigned int a2dp_role;
+
+                       a2dp_role = *((uint32_t*)properties[i].val);
+
+                       BT_INFO("A2DP role: %u", a2dp_role);
+
+                       send_event(OAL_EVENT_ADAPTER_PROPERTY_A2DP_ROLE,
+                                       g_memdup(properties[i].val, sizeof(uint32_t)),
+                                       sizeof(uint32_t));
+                       break;
+               }
                case BT_PROPERTY_LOCAL_LE_FEATURES: {
                        event_adapter_le_features_t *le_features;
 
index 8698fcb..e240822 100644 (file)
@@ -745,40 +745,33 @@ int _bt_get_profile_connected_devices(char *profile_uuid, GArray **addr_list)
        return BLUETOOTH_ERROR_NONE;
 }
 
-static void __bt_handle_pending_a2dp_init(service_uuid_t *service_list, unsigned int count)
+static void __bt_handle_pending_a2dp_init(unsigned int a2dp_role)
 {
        int ret;
-       unsigned int i;
-       unsigned char *uuid;
-       char uuid_str[BT_UUID_STRING_SIZE];
 
        if (!a2dp_init_pending)
                return;
 
        BT_DBG("+");
        a2dp_init_pending = FALSE;
-       for (i = 0; i < count; i++) {
-               uuid = service_list[i].uuid;
-               _bt_service_convert_uuid_type_to_string(uuid_str, uuid);
-               BT_INFO("Adapter Service: [%s]", uuid_str);
-               if (!strcasecmp(uuid_str, A2DP_SINK_UUID)) {
-                       BT_INFO("Enable A2DP Sink role");
-                       /* Initialize A2DP Sink */
-                       ret = _bt_audio_initialize(BT_A2DP_SINK_MODULE);
-                       if (ret != BLUETOOTH_ERROR_NONE)
-                               BT_ERR("_bt_audio_initialize(BT_A2DP_SINK_MODULE) Failed");
-
-                       /* Initialize AVRCP Controller */
-                       ret = _bt_audio_initialize(BT_AVRCP_CTRL_MODULE);
-                       if (ret != BLUETOOTH_ERROR_NONE)
-                               BT_ERR("_bt_audio_initialize(BT_AVRCP_CTRL_MODULE) Failed");
-
-                       _bt_audio_set_current_role(BLUETOOTH_A2DP_SINK);
-                       return;
-               }
+
+       if (a2dp_role == BT_A2DP_SINK_ROLE) {
+               BT_INFO("Enable A2DP Sink role");
+               /* Initialize A2DP Sink */
+               ret = _bt_audio_initialize(BT_A2DP_SINK_MODULE);
+               if (ret != BLUETOOTH_ERROR_NONE)
+                       BT_ERR("_bt_audio_initialize(BT_A2DP_SINK_MODULE) Failed");
+
+               /* Initialize AVRCP Controller */
+               ret = _bt_audio_initialize(BT_AVRCP_CTRL_MODULE);
+               if (ret != BLUETOOTH_ERROR_NONE)
+                       BT_ERR("_bt_audio_initialize(BT_AVRCP_CTRL_MODULE) Failed");
+
+               _bt_audio_set_current_role(BLUETOOTH_A2DP_SINK);
+               return;
        }
 
-       BT_INFO("Enable A2DP Source role by default");
+       BT_INFO("Enable A2DP Source role");
        /* Initialize A2DP Source */
        ret = _bt_audio_initialize(BT_A2DP_SOURCE_MODULE);
        if (ret != BLUETOOTH_ERROR_NONE)
@@ -928,7 +921,6 @@ static void __bt_adapter_event_handler(int event_type, gpointer event_data)
 
                count = list->num;
                service_list = list->service_list;
-               __bt_handle_pending_a2dp_init(service_list, count);
                __bt_adapter_handle_pending_requests(BT_IS_SERVICE_USED, service_list, count);
                break;
        }
@@ -952,6 +944,15 @@ static void __bt_adapter_event_handler(int event_type, gpointer event_data)
                g_free(addr_list);
                break;
        }
+       case OAL_EVENT_ADAPTER_PROPERTY_A2DP_ROLE: {
+               unsigned int *a2dp_role = event_data;
+
+               BT_INFO("a2dp role: [%u]", *a2dp_role);
+
+               __bt_handle_pending_a2dp_init(*a2dp_role);
+
+               break;
+       }
        default:
                BT_ERR("Unhandled event..");
                break;
index c2eae2b..e8d572e 100644 (file)
@@ -194,6 +194,7 @@ static gboolean __bt_handle_oal_events(gpointer data)
        case OAL_EVENT_ADAPTER_PROPERTY_NAME:
        case OAL_EVENT_ADAPTER_PROPERTY_VERSION:
        case OAL_EVENT_ADAPTER_PROPERTY_SERVICES:
+       case OAL_EVENT_ADAPTER_PROPERTY_A2DP_ROLE:
        case OAL_EVENT_ADAPTER_BONDED_DEVICE_LIST:
        case OAL_EVENT_ADAPTER_MODE_NON_CONNECTABLE:
        case OAL_EVENT_ADAPTER_MODE_CONNECTABLE:
index 176ce4d..99b44f5 100644 (file)
@@ -48,6 +48,11 @@ typedef enum {
 } bt_audio_type_t;
 
 typedef enum {
+       BT_A2DP_SOURCE_ROLE = 0,
+       BT_A2DP_SINK_ROLE,
+} bt_a2dp_role_t;
+
+typedef enum {
        SERVICE_SEARCH_NOT_STARTED,
        SERVICE_SEARCH_STARTED,
        SERVICE_SEARCH_DONE,