From 3537765c21c6adb2fcb44cfff3e7f50e2bc09d59 Mon Sep 17 00:00:00 2001 From: Cheney Ni Date: Wed, 18 Mar 2020 16:37:29 +0800 Subject: [PATCH] A2DP: Workaround to clean up previous AVDTP instance while re-enabling If the user disables and re-enables A2dpService quickly, the stack has chances to be still busy at dropping those out-of-date links, and this is highly dependent on the handset. If the handset responds more slowly, it spends more time to disable, but causes the new AVDTP instance won't work. This change checks the previous disabling flag, and cleans up the old instance up before re-enabling. Bug: 135655859 Test: manually Change-Id: I625cfffab6d4df327fb8159aa4b759a09d90e076 Merged-In: I625cfffab6d4df327fb8159aa4b759a09d90e076 (cherry picked from commit 07689d65f4c6fbc8b20dd0890657936fc6d6cb7b) --- bta/av/bta_av_main.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/bta/av/bta_av_main.cc b/bta/av/bta_av_main.cc index 83677479f..44da99e61 100644 --- a/bta/av/bta_av_main.cc +++ b/bta/av/bta_av_main.cc @@ -218,6 +218,30 @@ static const char* bta_av_st_code(uint8_t state); * ******************************************************************************/ static void bta_av_api_enable(tBTA_AV_DATA* p_data) { + if (bta_av_cb.disabling) { + APPL_TRACE_WARNING("%s: previous (reg_audio=%#x) is still disabling", + __func__, bta_av_cb.reg_audio); + if (bta_av_cb.sdp_a2dp_handle) { + SDP_DeleteRecord(bta_av_cb.sdp_a2dp_handle); + bta_sys_remove_uuid(UUID_SERVCLASS_AUDIO_SOURCE); + } +#if (BTA_AV_SINK_INCLUDED == TRUE) + if (bta_av_cb.sdp_a2dp_snk_handle) { + SDP_DeleteRecord(bta_av_cb.sdp_a2dp_snk_handle); + bta_sys_remove_uuid(UUID_SERVCLASS_AUDIO_SINK); + } +#endif +#if (BTA_AR_INCLUDED == TRUE) + // deregister from AVDT + bta_ar_dereg_avdt(BTA_ID_AV); + + // deregister from AVCT + bta_ar_dereg_avrc(UUID_SERVCLASS_AV_REMOTE_CONTROL, BTA_ID_AV); + bta_ar_dereg_avrc(UUID_SERVCLASS_AV_REM_CTRL_TARGET, BTA_ID_AV); + bta_ar_dereg_avct(BTA_ID_AV); +#endif + } + /* initialize control block */ memset(&bta_av_cb, 0, sizeof(tBTA_AV_CB)); -- 2.11.0