Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac3c7e64 authored by Bao Do's avatar Bao Do
Browse files

Add lock_guard to FetchAudioProvider.

Audio provider are refetched mainly due to the service being restarted.
Adding lock_guard to this function prevent service access while
refetching for other important functions (StartSession, EndSession, ...)
to prevent BT crashes.

Also add lock_guard access to some other important functions.

Bug: 341856622
Test: mmm packages/modules/Bluetooth
Flag: EXEMPT trivial change

Change-Id: I0e8ad04414dd79105ad8339e866b82a7d2ab8ad2
parent a5df47c6
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -135,6 +135,8 @@ void BluetoothAudioClientInterface::FetchAudioProvider() {
  if (provider_ != nullptr) {
    log::warn("refetch");
  }
  // Prevent other access to the AIDL if currently fetching new service
  std::lock_guard<std::mutex> guard(internal_mutex_);
  // Retry if audioserver restarts in the middle of fetching.
  // When audioserver restarts, IBluetoothAudioProviderFactory service is also
  // re-registered, so we need to re-fetch the service.
@@ -164,7 +166,7 @@ void BluetoothAudioClientInterface::FetchAudioProvider() {
              toString(transport_->GetSessionType()), capabilities_.size());

    aidl_retval = provider_factory->openProvider(transport_->GetSessionType(), &provider_);
    if (!aidl_retval.isOk()) {
    if (!aidl_retval.isOk() || provider_ == nullptr) {
      log::error("BluetoothAudioHal::openProvider failure: {}, retry number {}",
                 aidl_retval.getDescription(), retry_no + 1);
    } else {
@@ -220,6 +222,7 @@ void BluetoothAudioClientInterface::binderDiedCallbackAidl(void* ptr) {
}

bool BluetoothAudioClientInterface::UpdateAudioConfig(const AudioConfiguration& audio_config) {
  std::lock_guard<std::mutex> guard(internal_mutex_);
  bool is_software_session =
          (transport_->GetSessionType() == SessionType::A2DP_SOFTWARE_ENCODING_DATAPATH ||
           transport_->GetSessionType() == SessionType::HEARING_AID_SOFTWARE_ENCODING_DATAPATH ||
@@ -603,6 +606,7 @@ BluetoothAudioClientInterface::GetLeAudioAseConfiguration(
                std::vector<std::optional<IBluetoothAudioProvider::LeAudioDeviceCapabilities>>>&
                remoteSourceAudioCapabilities,
        std::vector<IBluetoothAudioProvider::LeAudioConfigurationRequirement>& requirements) {
  std::lock_guard<std::mutex> guard(internal_mutex_);
  log::assert_that(provider_ != nullptr, "assert failed: provider_ != nullptr");

  std::vector<IBluetoothAudioProvider::LeAudioAseConfigurationSetting> configurations;
@@ -670,6 +674,7 @@ BluetoothAudioClientInterface::getLeAudioBroadcastConfiguration(
                std::vector<std::optional<IBluetoothAudioProvider::LeAudioDeviceCapabilities>>>&
                remoteSinkAudioCapabilities,
        const IBluetoothAudioProvider::LeAudioBroadcastConfigurationRequirement& requirement) {
  std::lock_guard<std::mutex> guard(internal_mutex_);
  log::assert_that(provider_ != nullptr, "assert failed: provider_ != nullptr");

  IBluetoothAudioProvider::LeAudioBroadcastConfigurationSetting setting;