OSDN Git Service

A2DP: Workaround to clean up previous AVDTP instance while re-enabling
authorCheney Ni <cheneyni@google.com>
Wed, 18 Mar 2020 08:37:29 +0000 (16:37 +0800)
committerCheney Ni <cheneyni@google.com>
Tue, 14 Apr 2020 09:44:03 +0000 (17:44 +0800)
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

index 8367747..44da99e 100644 (file)
@@ -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));