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

Commit c68c86c4 authored by Grzegorz Kołodziejczyk's avatar Grzegorz Kołodziejczyk Committed by Jakub Pawlowski
Browse files

BluetoothAudioHAL: Avoid deadlock for get Providers Factory 2.1

Single instance of mutex is used for getting all Providers Factories.
Calling GetProvidersFactory 2.0 but having 2.1 instance can cause dead
lock scenario.

Bug: 173538746
Tag: #feature
Test: start Bluetooth with set vinf ProvidersFactory set to 2.1
Sponsor: jpawlowski@
Change-Id: I642adb779391196296dfe8db2a352ebdcf711070
parent 69ef8ad7
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -69,8 +69,9 @@ class HalVersionManager {

  static android::sp<IBluetoothAudioProvidersFactory_2_0>
  GetProvidersFactory_2_0() {
    std::lock_guard<std::mutex> guard(instance_ptr->mutex_);
    std::unique_lock<std::mutex> guard(instance_ptr->mutex_);
    if (instance_ptr->hal_version_ == BluetoothAudioHalVersion::VERSION_2_1) {
      guard.unlock();
      return instance_ptr->GetProvidersFactory_2_1();
    }
    android::sp<IBluetoothAudioProvidersFactory_2_0> providers_factory =
@@ -81,6 +82,7 @@ class HalVersionManager {
    LOG(INFO) << "V2_0::IBluetoothAudioProvidersFactory::getService() returned "
              << providers_factory.get()
              << (providers_factory->isRemote() ? " (remote)" : " (local)");
    guard.unlock();
    return providers_factory;
  }