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

Commit fc9a0237 authored by Patty Huang's avatar Patty Huang
Browse files

Get exact aidl version in HalVersionManager

1. Move the get aidl version function from codec_manager to hal_version_manager
2. Add the AIDL version v2 and v3
3. Add function SupportsStreamActiveApi to check whether isStreamActive API is supported

Tag: #refactor
Bug: 278988087
Test: atest BluetoothInstrumentationTests
Test: LE audio offload disappear and later join with downmix enable
Change-Id: I0c2a7e463c7693e0752b1aa1ed6ee312e7986231
parent 52f024b8
Loading
Loading
Loading
Loading
+0 −25
Original line number Diff line number Diff line
@@ -258,31 +258,6 @@ bool BluetoothAudioClientInterface::SetLowLatencyModeAllowed(bool allowed) {
  return true;
}

int BluetoothAudioClientInterface::GetAidlInterfaceVersion() {
  int aidl_version = -1;
  if (!is_aidl_available()) {
    return aidl_version;
  }

  auto provider_factory = IBluetoothAudioProviderFactory::fromBinder(
      ::ndk::SpAIBinder(AServiceManager_waitForService(
          kDefaultAudioProviderFactoryInterface.c_str())));

  if (provider_factory == nullptr) {
    LOG(ERROR) << __func__ << ", can't get aidl version from unknown factory";
    return aidl_version;
  }

  auto aidl_retval = provider_factory->getInterfaceVersion(&aidl_version);
  if (!aidl_retval.isOk()) {
    LOG(FATAL) << __func__
               << ": BluetoothAudioHal::getInterfaceVersion failure: "
               << aidl_retval.getDescription();
  }

  return aidl_version;
}

int BluetoothAudioClientInterface::StartSession() {
  std::lock_guard<std::mutex> guard(internal_mutex_);
  if (provider_ == nullptr) {
+0 −2
Original line number Diff line number Diff line
@@ -93,8 +93,6 @@ class BluetoothAudioClientInterface {

  static bool is_aidl_available();

  static int GetAidlInterfaceVersion();

 protected:
  mutable std::mutex internal_mutex_;
  /***
+0 −4
Original line number Diff line number Diff line
@@ -643,10 +643,6 @@ AudioConfiguration offload_config_to_hal_audio_config(
  return AudioConfiguration(ucast_config);
}

int GetAidlInterfaceVersion() {
  return BluetoothAudioSinkClientInterface::GetAidlInterfaceVersion();
}

}  // namespace le_audio
}  // namespace aidl
}  // namespace audio
+0 −1
Original line number Diff line number Diff line
@@ -66,7 +66,6 @@ bool is_source_hal_enabled();
bool is_sink_hal_enabled();

std::vector<AudioSetConfiguration> get_offload_capabilities();
int GetAidlInterfaceVersion();

class LeAudioTransport {
 public:
+38 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <memory>

#include "aidl/audio_aidl_interfaces.h"
#include "osi/include/log.h"

namespace bluetooth {
namespace audio {
@@ -45,6 +46,8 @@ BluetoothAudioHalVersion HalVersionManager::GetHalVersion() {
BluetoothAudioHalTransport HalVersionManager::GetHalTransport() {
  switch (GetHalVersion()) {
    case BluetoothAudioHalVersion::VERSION_AIDL_V1:
    case BluetoothAudioHalVersion::VERSION_AIDL_V2:
    case BluetoothAudioHalVersion::VERSION_AIDL_V3:
      return BluetoothAudioHalTransport::AIDL;
    case BluetoothAudioHalVersion::VERSION_2_0:
    case BluetoothAudioHalVersion::VERSION_2_1:
@@ -90,10 +93,44 @@ HalVersionManager::GetProvidersFactory_2_0() {
  return providers_factory;
}

BluetoothAudioHalVersion GetAidlInterfaceVersion() {
  int aidl_version = 0;

  auto provider_factory = IBluetoothAudioProviderFactory::fromBinder(
      ::ndk::SpAIBinder(AServiceManager_waitForService(
          kDefaultAudioProviderFactoryInterface.c_str())));

  if (provider_factory == nullptr) {
    LOG_ERROR("Can't get aidl version from unknown factory");
    return BluetoothAudioHalVersion::VERSION_UNAVAILABLE;
  }

  auto aidl_retval = provider_factory->getInterfaceVersion(&aidl_version);
  if (!aidl_retval.isOk()) {
    LOG_ERROR("BluetoothAudioHal::getInterfaceVersion failure: %s",
              aidl_retval.getDescription().c_str());
    return BluetoothAudioHalVersion::VERSION_UNAVAILABLE;
  }

  switch (aidl_version) {
    case 1:
      return BluetoothAudioHalVersion::VERSION_AIDL_V1;
    case 2:
      return BluetoothAudioHalVersion::VERSION_AIDL_V2;
    case 3:
      return BluetoothAudioHalVersion::VERSION_AIDL_V3;
    default:
      LOG_ERROR("Unknown AIDL version %d", aidl_version);
      return BluetoothAudioHalVersion::VERSION_UNAVAILABLE;
  }

  return BluetoothAudioHalVersion::VERSION_UNAVAILABLE;
}

HalVersionManager::HalVersionManager() {
  if (AServiceManager_checkService(
          kDefaultAudioProviderFactoryInterface.c_str()) != nullptr) {
    hal_version_ = BluetoothAudioHalVersion::VERSION_AIDL_V1;
    hal_version_ = GetAidlInterfaceVersion();
    return;
  }

Loading