From 81ff79be038dcd4abecd6adfe9e0b5b193ec2356 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Wed, 1 Nov 2023 03:44:44 +0000 Subject: [PATCH] CRAS: reset active a2dp device only when inactivating We used to call |reset_active_device| whenever there is a call to change the |active| state of an A2DP iodev, as a precautionary measure to cleanup internal states in the BT stack. However, this could be an issue when the transition is |active->active| because by resetting the device there will be a short time where the socket cannot be written. Since we have sufficient understanding of the specific internal states that need to be cleaned up, after this CL we will only reset when inactivating. BUG=b:307228349 TEST=Verify bug cannot be reproduced Change-Id: I76d244a569244d552d3a3131d28f1d533d39b798 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/4997244 Auto-Submit: Jeremy Wu Reviewed-by: En-Shuo Hsu Commit-Queue: En-Shuo Hsu Tested-by: Jeremy Wu --- cras/src/server/cras_a2dp_manager.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cras/src/server/cras_a2dp_manager.c b/cras/src/server/cras_a2dp_manager.c index 552f46722..3f6985d7a 100644 --- a/cras/src/server/cras_a2dp_manager.c +++ b/cras/src/server/cras_a2dp_manager.c @@ -688,13 +688,14 @@ int cras_floss_a2dp_start(struct cras_a2dp* a2dp, } void cras_floss_a2dp_set_active(struct cras_a2dp* a2dp, unsigned enabled) { - /* Clear session. */ - floss_media_a2dp_reset_active_device(a2dp->fm); if (enabled) { /* Set the connected a2dp device to be active. This is required * for other profiles (e.g., AVRCP) depending on the active a2dp * status to work. */ floss_media_a2dp_set_active_device(a2dp->fm, a2dp->addr); + } else { + /* Clear session. */ + floss_media_a2dp_reset_active_device(a2dp->fm); } }