summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Henri Chataing <henrichataing@google.com> 2025-03-06 23:00:51 +0000
committer Henri Chataing <henrichataing@google.com> 2025-03-10 21:16:44 +0000
commitadf5df243791a7a51298851b226b0d68a17524ce (patch)
tree0d7ff4713b16b3a47cdd4c3e640213fdfd516fbc
parentb5668684096b2af0a3ae80f7ff73d05fcb823197 (diff)
25Q1: Remove a2dp_source_threading_fix
Bug: 374166531 Test: m com.google.android.bt Flag: com::android::bluetooth::flags::a2dp_source_threading_fix Change-Id: I328d122548bf846e54a17249038dd337ce424a5e
-rw-r--r--flags/a2dp.aconfig10
-rw-r--r--system/btif/src/btif_a2dp_source.cc58
2 files changed, 20 insertions, 48 deletions
diff --git a/flags/a2dp.aconfig b/flags/a2dp.aconfig
index 68b5abf983..53c056ab86 100644
--- a/flags/a2dp.aconfig
+++ b/flags/a2dp.aconfig
@@ -49,16 +49,6 @@ flag {
}
flag {
- name: "a2dp_source_threading_fix"
- namespace: "bluetooth"
- description: "Schedule A2DP source setup operations to bt_main_thread to prevent races"
- bug: "374166531"
- metadata {
- purpose: PURPOSE_BUGFIX
- }
-}
-
-flag {
name: "a2dp_clear_pending_start_on_session_restart"
namespace: "bluetooth"
description: "Clear the kPendingStart flag when the audio session is restarted for codec reconfiguration"
diff --git a/system/btif/src/btif_a2dp_source.cc b/system/btif/src/btif_a2dp_source.cc
index 25a5fe7093..afef1953a2 100644
--- a/system/btif/src/btif_a2dp_source.cc
+++ b/system/btif/src/btif_a2dp_source.cc
@@ -331,19 +331,13 @@ static void btif_a2dp_source_accumulate_stats(BtifMediaStats* src, BtifMediaStat
src->Reset();
}
-/// Select the thread to run a2dp source actions on (a2dp encoder excluded).
-static bluetooth::common::MessageLoopThread* local_thread() {
- return com::android::bluetooth::flags::a2dp_source_threading_fix() ? get_main_thread()
- : &btif_a2dp_source_thread;
-}
-
bool btif_a2dp_source_init(void) {
log::info("");
// Start A2DP Source media task
btif_a2dp_source_thread.StartUp();
- local_thread()->DoInThread(base::BindOnce(&btif_a2dp_source_init_delayed));
+ do_in_main_thread(base::BindOnce(&btif_a2dp_source_init_delayed));
return true;
}
@@ -424,7 +418,7 @@ static void btif_a2dp_source_init_delayed(void) {
// the provider needs to be initialized earlier in order to ensure
// get_a2dp_configuration and parse_a2dp_configuration can be
// invoked before the stream is started.
- bluetooth::audio::a2dp::init(local_thread(), &a2dp_stream_callbacks,
+ bluetooth::audio::a2dp::init(get_main_thread(), &a2dp_stream_callbacks,
btif_av_is_a2dp_offload_enabled());
}
@@ -441,7 +435,7 @@ static bool btif_a2dp_source_startup(void) {
btif_a2dp_source_cb.tx_audio_queue = fixed_queue_new(SIZE_MAX);
// Schedule the rest of the operations
- local_thread()->DoInThread(base::BindOnce(&btif_a2dp_source_startup_delayed));
+ do_in_main_thread(base::BindOnce(&btif_a2dp_source_startup_delayed));
return true;
}
@@ -453,7 +447,7 @@ static void btif_a2dp_source_startup_delayed() {
log::fatal("unable to enable real time scheduling");
#endif
}
- if (!bluetooth::audio::a2dp::init(local_thread(), &a2dp_stream_callbacks,
+ if (!bluetooth::audio::a2dp::init(get_main_thread(), &a2dp_stream_callbacks,
btif_av_is_a2dp_offload_enabled())) {
log::warn("Failed to setup the bluetooth audio HAL");
}
@@ -466,15 +460,14 @@ bool btif_a2dp_source_start_session(const RawAddress& peer_address,
btif_a2dp_source_audio_tx_flush_req();
- if (local_thread()->DoInThread(base::BindOnce(&btif_a2dp_source_start_session_delayed,
- peer_address, std::move(peer_ready_promise)))) {
- return true;
- } else {
- // cannot set promise but triggers crash
+ if (do_in_main_thread(base::BindOnce(&btif_a2dp_source_start_session_delayed, peer_address,
+ std::move(peer_ready_promise))) != BT_STATUS_SUCCESS) {
log::fatal("peer_address={} state={} fails to context switch", peer_address,
btif_a2dp_source_cb.StateStr());
return false;
}
+
+ return true;
}
static void btif_a2dp_source_start_session_delayed(const RawAddress& peer_address,
@@ -530,13 +523,8 @@ bool btif_a2dp_source_restart_session(const RawAddress& old_peer_address,
bool btif_a2dp_source_end_session(const RawAddress& peer_address) {
log::info("peer_address={} state={}", peer_address, btif_a2dp_source_cb.StateStr());
- if (com::android::bluetooth::flags::a2dp_source_threading_fix()) {
- btif_a2dp_source_cleanup_codec();
- btif_a2dp_source_end_session_delayed(peer_address);
- } else {
- local_thread()->DoInThread(base::BindOnce(&btif_a2dp_source_end_session_delayed, peer_address));
- btif_a2dp_source_cleanup_codec();
- }
+ btif_a2dp_source_cleanup_codec();
+ btif_a2dp_source_end_session_delayed(peer_address);
return true;
}
@@ -561,7 +549,7 @@ static void btif_a2dp_source_end_session_delayed(const RawAddress& peer_address)
void btif_a2dp_source_allow_low_latency_audio(bool allowed) {
log::info("allowed={}", allowed);
- local_thread()->DoInThread(
+ do_in_main_thread(
base::BindOnce(bluetooth::audio::a2dp::set_audio_low_latency_mode_allowed, allowed));
}
@@ -576,13 +564,7 @@ void btif_a2dp_source_shutdown(std::promise<void> shutdown_complete_promise) {
/* Make sure no channels are restarted while shutting down */
btif_a2dp_source_cb.SetState(BtifA2dpSource::kStateShuttingDown);
- // TODO(b/374166531) Remove the check for get_main_thread.
- if (local_thread() != get_main_thread()) {
- local_thread()->DoInThread(base::BindOnce(&btif_a2dp_source_shutdown_delayed,
- std::move(shutdown_complete_promise)));
- } else {
- btif_a2dp_source_shutdown_delayed(std::move(shutdown_complete_promise));
- }
+ btif_a2dp_source_shutdown_delayed(std::move(shutdown_complete_promise));
}
static void btif_a2dp_source_shutdown_delayed(std::promise<void> shutdown_complete_promise) {
@@ -692,7 +674,7 @@ static void btif_a2dp_source_cleanup_codec() {
log::info("state={}", btif_a2dp_source_cb.StateStr());
// Must stop media task first before cleaning up the encoder
btif_a2dp_source_stop_audio_req();
- local_thread()->DoInThread(base::BindOnce(&btif_a2dp_source_cleanup_codec_delayed));
+ do_in_main_thread(base::BindOnce(&btif_a2dp_source_cleanup_codec_delayed));
}
static void btif_a2dp_source_cleanup_codec_delayed() {
@@ -706,13 +688,13 @@ static void btif_a2dp_source_cleanup_codec_delayed() {
void btif_a2dp_source_start_audio_req(void) {
log::info("state={}", btif_a2dp_source_cb.StateStr());
- local_thread()->DoInThread(base::BindOnce(&btif_a2dp_source_audio_tx_start_event));
+ do_in_main_thread(base::BindOnce(&btif_a2dp_source_audio_tx_start_event));
}
void btif_a2dp_source_stop_audio_req(void) {
log::info("state={}", btif_a2dp_source_cb.StateStr());
- local_thread()->DoInThread(base::BindOnce(&btif_a2dp_source_audio_tx_stop_event));
+ do_in_main_thread(base::BindOnce(&btif_a2dp_source_audio_tx_stop_event));
}
void btif_a2dp_source_encoder_user_config_update_req(
@@ -722,9 +704,9 @@ void btif_a2dp_source_encoder_user_config_update_req(
log::info("peer_address={} state={} {} codec_preference(s)", peer_address,
btif_a2dp_source_cb.StateStr(), codec_user_preferences.size());
- if (!local_thread()->DoInThread(
- base::BindOnce(&btif_a2dp_source_encoder_user_config_update_event, peer_address,
- codec_user_preferences, std::move(peer_ready_promise)))) {
+ if (do_in_main_thread(base::BindOnce(&btif_a2dp_source_encoder_user_config_update_event,
+ peer_address, codec_user_preferences,
+ std::move(peer_ready_promise))) != BT_STATUS_SUCCESS) {
// cannot set promise but triggers crash
log::fatal("peer_address={} state={} fails to context switch", peer_address,
btif_a2dp_source_cb.StateStr());
@@ -767,7 +749,7 @@ static void btif_a2dp_source_encoder_user_config_update_event(
void btif_a2dp_source_feeding_update_req(const btav_a2dp_codec_config_t& codec_audio_config) {
log::info("state={}", btif_a2dp_source_cb.StateStr());
- local_thread()->DoInThread(
+ do_in_main_thread(
base::BindOnce(&btif_a2dp_source_audio_feeding_update_event, codec_audio_config));
}
@@ -1081,7 +1063,7 @@ static void btif_a2dp_source_audio_tx_flush_event(void) {
static bool btif_a2dp_source_audio_tx_flush_req(void) {
log::info("state={}", btif_a2dp_source_cb.StateStr());
- local_thread()->DoInThread(base::BindOnce(&btif_a2dp_source_audio_tx_flush_event));
+ do_in_main_thread(base::BindOnce(&btif_a2dp_source_audio_tx_flush_event));
return true;
}