diff options
author | Deokhyun Kim <dukan.kim@samsung.com> | 2020-02-27 15:08:53 +0900 |
---|---|---|
committer | DoHyun Pyun <dh79.pyun@samsung.com> | 2020-02-28 10:27:15 +0900 |
commit | 2c4aa97ca70fe4d7b6d997c185cd3b9d478a155e (patch) | |
tree | 6cae851bb97bb4d9201874ab06b60417df7c3373 | |
parent | 79f102d780b0c5aa627e4e9d0f0124252b2e55db (diff) | |
download | bluetooth-2c4aa97ca70fe4d7b6d997c185cd3b9d478a155e.tar.gz bluetooth-2c4aa97ca70fe4d7b6d997c185cd3b9d478a155e.tar.bz2 bluetooth-2c4aa97ca70fe4d7b6d997c185cd3b9d478a155e.zip |
Apply sound_manager API
- In case launch mode is the headset connect, app is waiting for
sound_manager event and exits right after A2DP routed event is invoked.
Change-Id: I61f4cabaccfa18b0b2549edb434748e8bd00fd76
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | include/bt-main.h | 3 | ||||
-rw-r--r-- | packaging/org.tizen.bluetooth.spec | 1 | ||||
-rw-r--r-- | src/bt-handler.c | 88 | ||||
-rw-r--r-- | src/bt-main.c | 3 |
5 files changed, 78 insertions, 18 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 64f95c0..02563fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ pkg_check_modules(pkgs REQUIRED capi-appfw-application efl-extension appcore-efl + capi-media-sound-manager capi-network-bluetooth syspopup-caller deviced diff --git a/include/bt-main.h b/include/bt-main.h index 11107e0..0538065 100644 --- a/include/bt-main.h +++ b/include/bt-main.h @@ -181,6 +181,9 @@ typedef struct { bt_profile_view_data *profile_vd; bt_confirm_req_t confirm_req; + /* app control reply result */ + app_control_result_e reply_result; + Ecore_Idler *idler; } bt_app_data_t; diff --git a/packaging/org.tizen.bluetooth.spec b/packaging/org.tizen.bluetooth.spec index a209742..43a7f15 100644 --- a/packaging/org.tizen.bluetooth.spec +++ b/packaging/org.tizen.bluetooth.spec @@ -20,6 +20,7 @@ BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(efl-extension) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(syspopup-caller) +BuildRequires: pkgconfig(capi-media-sound-manager) BuildRequires: pkgconfig(capi-network-bluetooth) BuildRequires: pkgconfig(capi-ui-efl-util) BuildRequires: pkgconfig(deviced) diff --git a/src/bt-handler.c b/src/bt-handler.c index dcefd51..ae1b096 100644 --- a/src/bt-handler.c +++ b/src/bt-handler.c @@ -17,6 +17,8 @@ #include <bluetooth.h> +#include <sound_manager.h> + #include "bt-main.h" #include "bt-main-view.h" #include "bt-handler.h" @@ -437,6 +439,18 @@ static void _bt_cb_discovery_state_changed(int result, __bt_cb_search_completed(result, user_data); } +static Eina_Bool __bt_exit_idler(void *data) +{ + FN_START; + bt_app_data_t *ad = data; + retv_if(!ad, ECORE_CALLBACK_CANCEL); + elm_exit(); + + ad->idler = NULL; + FN_END; + return ECORE_CALLBACK_CANCEL; +} + void _bt_cb_bonding_created(int result, bt_device_info_s *dev_info, void *user_data) { @@ -969,6 +983,34 @@ gboolean _bt_send_result(bt_app_data_t *ad, bool result) return TRUE; } +static void __bt_cb_sound_available_route_changed(sound_device_h device, bool is_connected, void *user_data) +{ + FN_START; + int ret; + bt_app_data_t *ad = user_data; + sound_device_type_e device_type; + ret_if(!ad); + + ret = sound_manager_get_current_media_playback_device_type(&device_type); + if (ret != SOUND_MANAGER_ERROR_NONE) + ERR("sound_manager_get_current_media_playback_device_type fail"); + + DBG("ad->launch_mode : %d, device_type = %d", ad->launch_mode, device_type); + + if ((ad->launch_mode == BT_LAUNCH_CONNECT_HEADSET) && + (device_type == SOUND_DEVICE_BLUETOOTH_MEDIA)) { + if (ad->idler) { + ecore_idler_del(ad->idler); + ad->idler = NULL; + } + ad->reply_result = APP_CONTROL_RESULT_SUCCEEDED; + ad->idler = ecore_idler_add(__bt_exit_idler, ad); + } + FN_END; +} + +static int sound_manager_id = -1; + gboolean _bt_init(void *data) { int ret; @@ -1050,6 +1092,13 @@ gboolean _bt_init(void *data) } #endif + if (ad->launch_mode == BT_LAUNCH_CONNECT_HEADSET) { + ret = sound_manager_add_device_connection_changed_cb(SOUND_DEVICE_IO_DIRECTION_OUT_MASK, + __bt_cb_sound_available_route_changed, ad, &sound_manager_id); + if (ret != SOUND_MANAGER_ERROR_NONE) + ERR("sound_manager_set_available_route_changed_cb fail! ret = %d", ret); + } + ret = bt_adapter_get_state(&adapter_state); if (ret != BT_ERROR_NONE) { ERR("bt_adapter_get_state is failed : %d", ret); @@ -1076,10 +1125,28 @@ void _bt_deinit(bt_app_data_t *ad) FN_START; int ret; - if (ad && ad->op_status == BT_SEARCHING) { - ret = bt_adapter_stop_device_discovery(); - if (ret != BT_ERROR_NONE) - ERR("Stop device discovery failed: %d", ret); + if (ad) { + if (ad->op_status == BT_SEARCHING) { + ret = bt_adapter_stop_device_discovery(); + if (ret != BT_ERROR_NONE) + ERR("Stop device discovery failed: %d", ret); + } + + if ((ad->launch_mode == BT_LAUNCH_CONNECT_HEADSET) && + sound_manager_id >= 0) { + sound_manager_remove_device_state_changed_cb(sound_manager_id); + sound_manager_id = -1; + } + +#if 0 + if (ad->weconn) { + ret = weconn_unset_service_state_change_cb(ad->weconn, W_SERVICE_TYPE_BT); + if (ret != BT_ERROR_NONE) + ERR("weconn_unset_service_state_change_cb is failed : %d", ret); + weconn_destroy(ad->weconn); + ad->weconn = NULL; + } +#endif } ret = bt_adapter_unset_state_changed_cb(); @@ -1122,19 +1189,6 @@ void _bt_deinit(bt_app_data_t *ad) if (ret != BT_ERROR_NONE) ERR("bt_adapter_unset_visibility_duration_changed_cb is failed : %d", ret); -#if 0 - if (ad && ad->launch_mode == BT_LAUNCH_CONNECT_HEADSET) - sound_manager_unset_available_route_changed_cb(); - - if (ad && ad->weconn) { - ret = weconn_unset_service_state_change_cb(ad->weconn, W_SERVICE_TYPE_BT); - if (ret != BT_ERROR_NONE) - ERR("weconn_unset_service_state_change_cb is failed : %d", ret); - weconn_destroy(ad->weconn); - ad->weconn = NULL; - } -#endif - ret = bt_deinitialize(); if (ret != BT_ERROR_NONE) ERR("bt_deinitialize is failed : %d", ret); diff --git a/src/bt-main.c b/src/bt-main.c index 1d03f32..d895973 100644 --- a/src/bt-main.c +++ b/src/bt-main.c @@ -36,7 +36,6 @@ static bool app_create(void *data) ad = (bt_app_data_t *)data; - _bt_init(ad); ad->app_status = BT_CREATE; FN_END; return TRUE; @@ -378,6 +377,8 @@ static void app_service(app_control_h service, void *data) return; } + _bt_init(ad); + if (ad->launch_mode == BT_LAUNCH_SETTING) _bt_util_change_discoverable_mode(ad, TRUE); |