Loading system/btif/include/stack_manager.h +5 −2 Original line number Diff line number Diff line Loading @@ -22,10 +22,13 @@ #include "osi/include/future.h" using ProfileStartCallback = void(); using ProfileStopCallback = void(); typedef struct { void (*init_stack)(void); void (*start_up_stack_async)(void); void (*shut_down_stack_async)(void); void (*start_up_stack_async)(ProfileStartCallback, ProfileStopCallback); void (*shut_down_stack_async)(ProfileStopCallback); void (*clean_up_stack)(void); bool (*get_stack_is_running)(void); Loading system/btif/src/bluetooth.cc +32 −2 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ #include "audio_hal_interface/a2dp_encoding.h" #include "bt_utils.h" #include "bta/include/bta_ar_api.h" #include "bta/include/bta_csis_api.h" #include "bta/include/bta_has_api.h" #include "bta/include/bta_hearing_aid_api.h" Loading @@ -66,9 +67,14 @@ #include "btif_bqr.h" #include "btif_config.h" #include "btif_debug_conn.h" #include "btif_dm.h" #include "btif_hd.h" #include "btif_hf.h" #include "btif_hh.h" #include "btif_keystore.h" #include "btif_metrics_logging.h" #include "btif_pan.h" #include "btif_sock.h" #include "btif_storage.h" #include "common/address_obfuscator.h" #include "common/metric_id_allocator.h" Loading @@ -87,9 +93,12 @@ #include "osi/include/wakelock.h" #include "stack/btm/btm_sco_hfp_hal.h" #include "stack/gatt/connection_manager.h" #include "stack/include/a2dp_api.h" #include "stack/include/avdt_api.h" #include "stack/include/btm_api.h" #include "stack/include/btu.h" #include "stack/include/hidh_api.h" #include "stack/include/pan_api.h" #include "types/raw_address.h" using bluetooth::csis::CsisClientInterface; Loading Loading @@ -226,17 +235,38 @@ static int init(bt_callbacks_t* callbacks, bool start_restricted, return BT_STATUS_SUCCESS; } static void start_profiles() { #if (BNEP_INCLUDED == TRUE) BNEP_Init(); #if (PAN_INCLUDED == TRUE) PAN_Init(); #endif /* PAN */ #endif /* BNEP Included */ A2DP_Init(); AVRC_Init(); #if (HID_HOST_INCLUDED == TRUE) HID_HostInit(); #endif bta_ar_init(); } static void stop_profiles() { btif_sock_cleanup(); btif_pan_cleanup(); } static int enable() { if (!interface_ready()) return BT_STATUS_NOT_READY; stack_manager_get_interface()->start_up_stack_async(); stack_manager_get_interface()->start_up_stack_async(&start_profiles, &stop_profiles); return BT_STATUS_SUCCESS; } static int disable(void) { if (!interface_ready()) return BT_STATUS_NOT_READY; stack_manager_get_interface()->shut_down_stack_async(); stack_manager_get_interface()->shut_down_stack_async(&stop_profiles); return BT_STATUS_SUCCESS; } Loading system/btif/src/stack_manager.cc +17 −24 Original line number Diff line number Diff line Loading @@ -134,8 +134,9 @@ static bool stack_is_initialized; static bool stack_is_running; static void event_init_stack(void* context); static void event_start_up_stack(void* context); static void event_shut_down_stack(void* context); static void event_start_up_stack(ProfileStartCallback startProfiles, ProfileStopCallback stopProfiles); static void event_shut_down_stack(ProfileStopCallback stopProfiles); static void event_clean_up_stack(std::promise<void> promise); static void event_signal_stack_up(void* context); Loading @@ -160,14 +161,15 @@ static void init_stack() { semaphore_free(semaphore); } static void start_up_stack_async() { management_thread.DoInThread(FROM_HERE, base::Bind(event_start_up_stack, nullptr)); static void start_up_stack_async(ProfileStartCallback startProfiles, ProfileStopCallback stopProfiles) { management_thread.DoInThread( FROM_HERE, base::Bind(event_start_up_stack, startProfiles, stopProfiles)); } static void shut_down_stack_async() { static void shut_down_stack_async(ProfileStopCallback stopProfiles) { management_thread.DoInThread(FROM_HERE, base::Bind(event_shut_down_stack, nullptr)); base::Bind(event_shut_down_stack, stopProfiles)); } static void clean_up_stack() { Loading Loading @@ -272,7 +274,8 @@ static void ensure_stack_is_initialized() { } // Synchronous function to start up the stack static void event_start_up_stack(UNUSED_ATTR void* context) { static void event_start_up_stack(ProfileStartCallback startProfiles, ProfileStopCallback stopProfiles) { if (stack_is_running) { LOG_INFO("%s stack already brought up", __func__); return; Loading @@ -297,21 +300,12 @@ static void event_start_up_stack(UNUSED_ATTR void* context) { get_btm_client_interface().lifecycle.btm_ble_init(); RFCOMM_Init(); #if (BNEP_INCLUDED == TRUE) BNEP_Init(); #if (PAN_INCLUDED == TRUE) PAN_Init(); #endif /* PAN */ #endif /* BNEP Included */ A2DP_Init(); AVRC_Init(); GAP_Init(); #if (HID_HOST_INCLUDED == TRUE) HID_HostInit(); #endif startProfiles(); bta_sys_init(); bta_ar_init(); module_init(get_local_module(BTE_LOGMSG_MODULE)); main_thread_start_up(); Loading @@ -330,7 +324,7 @@ static void event_start_up_stack(UNUSED_ATTR void* context) { if (future_await(local_hack_future) != FUTURE_SUCCESS) { LOG_ERROR("%s failed to start up the stack", __func__); stack_is_running = true; // So stack shutdown actually happens event_shut_down_stack(nullptr); event_shut_down_stack(stopProfiles); return; } Loading @@ -340,7 +334,7 @@ static void event_start_up_stack(UNUSED_ATTR void* context) { } // Synchronous function to shut down the stack static void event_shut_down_stack(UNUSED_ATTR void* context) { static void event_shut_down_stack(ProfileStopCallback stopProfiles) { if (!stack_is_running) { LOG_INFO("%s stack is already brought down", __func__); return; Loading @@ -356,8 +350,7 @@ static void event_shut_down_stack(UNUSED_ATTR void* context) { do_in_main_thread(FROM_HERE, base::Bind(&btm_ble_scanner_cleanup)); btif_dm_on_disable(); btif_sock_cleanup(); btif_pan_cleanup(); stopProfiles(); do_in_main_thread(FROM_HERE, base::Bind(bta_dm_disable)); Loading Loading
system/btif/include/stack_manager.h +5 −2 Original line number Diff line number Diff line Loading @@ -22,10 +22,13 @@ #include "osi/include/future.h" using ProfileStartCallback = void(); using ProfileStopCallback = void(); typedef struct { void (*init_stack)(void); void (*start_up_stack_async)(void); void (*shut_down_stack_async)(void); void (*start_up_stack_async)(ProfileStartCallback, ProfileStopCallback); void (*shut_down_stack_async)(ProfileStopCallback); void (*clean_up_stack)(void); bool (*get_stack_is_running)(void); Loading
system/btif/src/bluetooth.cc +32 −2 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ #include "audio_hal_interface/a2dp_encoding.h" #include "bt_utils.h" #include "bta/include/bta_ar_api.h" #include "bta/include/bta_csis_api.h" #include "bta/include/bta_has_api.h" #include "bta/include/bta_hearing_aid_api.h" Loading @@ -66,9 +67,14 @@ #include "btif_bqr.h" #include "btif_config.h" #include "btif_debug_conn.h" #include "btif_dm.h" #include "btif_hd.h" #include "btif_hf.h" #include "btif_hh.h" #include "btif_keystore.h" #include "btif_metrics_logging.h" #include "btif_pan.h" #include "btif_sock.h" #include "btif_storage.h" #include "common/address_obfuscator.h" #include "common/metric_id_allocator.h" Loading @@ -87,9 +93,12 @@ #include "osi/include/wakelock.h" #include "stack/btm/btm_sco_hfp_hal.h" #include "stack/gatt/connection_manager.h" #include "stack/include/a2dp_api.h" #include "stack/include/avdt_api.h" #include "stack/include/btm_api.h" #include "stack/include/btu.h" #include "stack/include/hidh_api.h" #include "stack/include/pan_api.h" #include "types/raw_address.h" using bluetooth::csis::CsisClientInterface; Loading Loading @@ -226,17 +235,38 @@ static int init(bt_callbacks_t* callbacks, bool start_restricted, return BT_STATUS_SUCCESS; } static void start_profiles() { #if (BNEP_INCLUDED == TRUE) BNEP_Init(); #if (PAN_INCLUDED == TRUE) PAN_Init(); #endif /* PAN */ #endif /* BNEP Included */ A2DP_Init(); AVRC_Init(); #if (HID_HOST_INCLUDED == TRUE) HID_HostInit(); #endif bta_ar_init(); } static void stop_profiles() { btif_sock_cleanup(); btif_pan_cleanup(); } static int enable() { if (!interface_ready()) return BT_STATUS_NOT_READY; stack_manager_get_interface()->start_up_stack_async(); stack_manager_get_interface()->start_up_stack_async(&start_profiles, &stop_profiles); return BT_STATUS_SUCCESS; } static int disable(void) { if (!interface_ready()) return BT_STATUS_NOT_READY; stack_manager_get_interface()->shut_down_stack_async(); stack_manager_get_interface()->shut_down_stack_async(&stop_profiles); return BT_STATUS_SUCCESS; } Loading
system/btif/src/stack_manager.cc +17 −24 Original line number Diff line number Diff line Loading @@ -134,8 +134,9 @@ static bool stack_is_initialized; static bool stack_is_running; static void event_init_stack(void* context); static void event_start_up_stack(void* context); static void event_shut_down_stack(void* context); static void event_start_up_stack(ProfileStartCallback startProfiles, ProfileStopCallback stopProfiles); static void event_shut_down_stack(ProfileStopCallback stopProfiles); static void event_clean_up_stack(std::promise<void> promise); static void event_signal_stack_up(void* context); Loading @@ -160,14 +161,15 @@ static void init_stack() { semaphore_free(semaphore); } static void start_up_stack_async() { management_thread.DoInThread(FROM_HERE, base::Bind(event_start_up_stack, nullptr)); static void start_up_stack_async(ProfileStartCallback startProfiles, ProfileStopCallback stopProfiles) { management_thread.DoInThread( FROM_HERE, base::Bind(event_start_up_stack, startProfiles, stopProfiles)); } static void shut_down_stack_async() { static void shut_down_stack_async(ProfileStopCallback stopProfiles) { management_thread.DoInThread(FROM_HERE, base::Bind(event_shut_down_stack, nullptr)); base::Bind(event_shut_down_stack, stopProfiles)); } static void clean_up_stack() { Loading Loading @@ -272,7 +274,8 @@ static void ensure_stack_is_initialized() { } // Synchronous function to start up the stack static void event_start_up_stack(UNUSED_ATTR void* context) { static void event_start_up_stack(ProfileStartCallback startProfiles, ProfileStopCallback stopProfiles) { if (stack_is_running) { LOG_INFO("%s stack already brought up", __func__); return; Loading @@ -297,21 +300,12 @@ static void event_start_up_stack(UNUSED_ATTR void* context) { get_btm_client_interface().lifecycle.btm_ble_init(); RFCOMM_Init(); #if (BNEP_INCLUDED == TRUE) BNEP_Init(); #if (PAN_INCLUDED == TRUE) PAN_Init(); #endif /* PAN */ #endif /* BNEP Included */ A2DP_Init(); AVRC_Init(); GAP_Init(); #if (HID_HOST_INCLUDED == TRUE) HID_HostInit(); #endif startProfiles(); bta_sys_init(); bta_ar_init(); module_init(get_local_module(BTE_LOGMSG_MODULE)); main_thread_start_up(); Loading @@ -330,7 +324,7 @@ static void event_start_up_stack(UNUSED_ATTR void* context) { if (future_await(local_hack_future) != FUTURE_SUCCESS) { LOG_ERROR("%s failed to start up the stack", __func__); stack_is_running = true; // So stack shutdown actually happens event_shut_down_stack(nullptr); event_shut_down_stack(stopProfiles); return; } Loading @@ -340,7 +334,7 @@ static void event_start_up_stack(UNUSED_ATTR void* context) { } // Synchronous function to shut down the stack static void event_shut_down_stack(UNUSED_ATTR void* context) { static void event_shut_down_stack(ProfileStopCallback stopProfiles) { if (!stack_is_running) { LOG_INFO("%s stack is already brought down", __func__); return; Loading @@ -356,8 +350,7 @@ static void event_shut_down_stack(UNUSED_ATTR void* context) { do_in_main_thread(FROM_HERE, base::Bind(&btm_ble_scanner_cleanup)); btif_dm_on_disable(); btif_sock_cleanup(); btif_pan_cleanup(); stopProfiles(); do_in_main_thread(FROM_HERE, base::Bind(bta_dm_disable)); Loading