"libcutils",
"libfmq",
"libhidlbase",
+ "libhidltransport",
"liblog",
"libutils",
],
// initialized
uint16_t remote_delay = 0;
-bool btaudio_a2dp_supported = false;
+bool btaudio_a2dp_disabled = false;
bool is_configured = false;
BluetoothAudioCtrlAck a2dp_ack_to_bt_audio_ctrl_ack(tA2DP_CTRL_ACK ack) {
pcm_config->channelMode != ChannelMode::UNKNOWN);
}
-} // namespace
-
-namespace bluetooth {
-namespace audio {
-namespace a2dp {
-
// Checking if new bluetooth_audio is supported
-bool is_hal_2_0_supported() {
+bool is_hal_2_0_force_disabled() {
if (!is_configured) {
- btaudio_a2dp_supported = !osi_property_get_bool(BLUETOOTH_AUDIO_HAL_PROP_DISABLED, false);
+ btaudio_a2dp_disabled = osi_property_get_bool(BLUETOOTH_AUDIO_HAL_PROP_DISABLED, false);
is_configured = true;
}
- return btaudio_a2dp_supported;
+ return btaudio_a2dp_disabled;
}
+} // namespace
+
+namespace bluetooth {
+namespace audio {
+namespace a2dp {
+
// Checking if new bluetooth_audio is enabled
bool is_hal_2_0_enabled() { return a2dp_hal_clientif != nullptr; }
bool init(bluetooth::common::MessageLoopThread* message_loop) {
LOG(INFO) << __func__;
- if (!is_hal_2_0_supported()) {
- LOG(ERROR) << __func__ << ": BluetoothAudio HAL is not supported";
+ if (is_hal_2_0_force_disabled()) {
+ LOG(ERROR) << __func__ << ": BluetoothAudio HAL is disabled";
return false;
}
a2dp_sink = new A2dpTransport(session_type);
a2dp_hal_clientif = new bluetooth::audio::BluetoothAudioClientInterface(
a2dp_sink, message_loop);
+ if (!a2dp_hal_clientif->IsValid()) {
+ LOG(WARNING) << __func__ << ": BluetoothAudio HAL for A2DP session=" << toString(session_type) << " is invalid?!";
+ delete a2dp_hal_clientif;
+ a2dp_hal_clientif = nullptr;
+ delete a2dp_sink;
+ a2dp_sink = nullptr;
+ return false;
+ }
+
if (remote_delay != 0) {
LOG(INFO) << __func__ << ": restore DELAY "
<< static_cast<float>(remote_delay / 10.0) << " ms";
namespace audio {
namespace a2dp {
-bool is_hal_2_0_supported();
-
// Check if new bluetooth_audio is enabled
bool is_hal_2_0_enabled();
#include <android/hardware/bluetooth/audio/2.0/IBluetoothAudioPort.h>
#include <android/hardware/bluetooth/audio/2.0/IBluetoothAudioProvidersFactory.h>
+#include <android/hidl/manager/1.2/IServiceManager.h>
#include <base/logging.h>
#include <hidl/MQDescriptor.h>
+#include <hidl/ServiceManagement.h>
#include <future>
#include "osi/include/log.h"
static constexpr int kDefaultDataReadTimeoutMs = 10; // 10 ms
static constexpr int kDefaultDataReadPollIntervalMs = 1; // non-blocking poll
+static constexpr char kFullyQualifiedInterfaceName[] =
+ "android.hardware.bluetooth.audio@2.0::IBluetoothAudioProvidersFactory";
std::ostream& operator<<(std::ostream& os, const BluetoothAudioCtrlAck& ack) {
switch (ack) {
}
};
-BluetoothAudioClientInterface::BluetoothAudioClientInterface(
- IBluetoothTransportInstance* sink,
- bluetooth::common::MessageLoopThread* message_loop)
- : sink_(sink),
- session_started_(false),
- mDataMQ(nullptr),
+BluetoothAudioClientInterface::BluetoothAudioClientInterface(IBluetoothTransportInstance* sink,
+ bluetooth::common::MessageLoopThread* message_loop)
+ : sink_(sink), provider_(nullptr), session_started_(false), mDataMQ(nullptr),
death_recipient_(new BluetoothAudioDeathRecipient(this, message_loop)) {
- fetch_audio_provider();
+ auto service_manager = android::hardware::defaultServiceManager1_2();
+ CHECK(service_manager != nullptr);
+ size_t instance_count = 0;
+ auto listManifestByInterface_cb = [&instance_count](const hidl_vec<android::hardware::hidl_string>& instanceNames) {
+ instance_count = instanceNames.size();
+ LOG(INFO) << "listManifestByInterface_cb returns " << instance_count << " instance(s)";
+ };
+ auto hidl_retval = service_manager->listManifestByInterface(kFullyQualifiedInterfaceName, listManifestByInterface_cb);
+ if (!hidl_retval.isOk()) {
+ LOG(FATAL) << __func__ << ": IServiceManager::listByInterface failure: " << hidl_retval.description();
+ }
+ if (instance_count > 0) {
+ fetch_audio_provider();
+ } else {
+ LOG(WARNING) << "IBluetoothAudioProvidersFactory not declared";
+ }
}
BluetoothAudioClientInterface::~BluetoothAudioClientInterface() {
android::sp<IBluetoothAudioProvidersFactory> providersFactory =
IBluetoothAudioProvidersFactory::getService();
- CHECK(providersFactory != nullptr);
+ CHECK(providersFactory != nullptr) << "IBluetoothAudioProvidersFactory::getService() failed";
LOG(INFO) << "IBluetoothAudioProvidersFactory::getService() returned "
<< providersFactory.get()
<< (providersFactory->isRemote() ? " (remote)" : " (local)");
~BluetoothAudioClientInterface();
+ bool IsValid() const {
+ return provider_ != nullptr;
+ }
+
std::vector<AudioCapabilities> GetAudioCapabilities() const;
bool UpdateAudioConfig(const AudioConfiguration& audioConfig);
// Common interface to call-out into Bluetooth Audio Hal
bluetooth::audio::BluetoothAudioClientInterface*
hearing_aid_hal_clientinterface = nullptr;
-bool btaudio_hearing_aid_supported = false;
+bool btaudio_hearing_aid_disabled = false;
bool is_configured = false;
+bool is_hal_2_0_force_disabled() {
+ if (!is_configured) {
+ btaudio_hearing_aid_disabled = osi_property_get_bool(BLUETOOTH_AUDIO_HAL_PROP_DISABLED, false);
+ is_configured = true;
+ }
+ return btaudio_hearing_aid_disabled;
+}
+
} // namespace
namespace bluetooth {
namespace audio {
namespace hearing_aid {
-bool is_hal_2_0_supported() {
- if (!is_configured) {
- btaudio_hearing_aid_supported = !osi_property_get_bool(BLUETOOTH_AUDIO_HAL_PROP_DISABLED, false);
- is_configured = true;
- }
- return btaudio_hearing_aid_supported;
-}
-
bool is_hal_2_0_enabled() { return hearing_aid_hal_clientinterface != nullptr; }
bool init(StreamCallbacks stream_cb,
bluetooth::common::MessageLoopThread* message_loop) {
LOG(INFO) << __func__;
- if (!is_hal_2_0_supported()) return false;
+ if (is_hal_2_0_force_disabled()) {
+ LOG(ERROR) << __func__ << ": BluetoothAudio HAL is disabled";
+ return false;
+ }
hearing_aid_sink = new HearingAidTransport(std::move(stream_cb));
hearing_aid_hal_clientinterface =
new bluetooth::audio::BluetoothAudioClientInterface(hearing_aid_sink,
message_loop);
+ if (!hearing_aid_hal_clientinterface->IsValid()) {
+ LOG(WARNING) << __func__ << ": BluetoothAudio HAL for Hearing Aid is invalid?!";
+ delete hearing_aid_hal_clientinterface;
+ hearing_aid_hal_clientinterface = nullptr;
+ delete hearing_aid_sink;
+ hearing_aid_sink = nullptr;
+ return false;
+ }
return true;
}
LOG(INFO) << __func__;
if (!is_hal_2_0_enabled()) return;
end_session();
+ delete hearing_aid_hal_clientinterface;
hearing_aid_hal_clientinterface = nullptr;
+ delete hearing_aid_sink;
hearing_aid_sink = nullptr;
}
std::function<bool(void)> on_suspend_;
};
-bool is_hal_2_0_supported();
-
// Check if new bluetooth_audio is enabled
bool is_hal_2_0_enabled();
}
void HearingAidAudioSource::Initialize() {
- if (bluetooth::audio::hearing_aid::is_hal_2_0_supported()) {
- auto stream_cb = bluetooth::audio::hearing_aid::StreamCallbacks{
- .on_resume_ = hearing_aid_on_resume_req,
- .on_suspend_ = hearing_aid_on_suspend_req,
- };
- bluetooth::audio::hearing_aid::init(stream_cb, get_main_thread());
- } else {
+ auto stream_cb = bluetooth::audio::hearing_aid::StreamCallbacks{
+ .on_resume_ = hearing_aid_on_resume_req,
+ .on_suspend_ = hearing_aid_on_suspend_req,
+ };
+ if (!bluetooth::audio::hearing_aid::init(stream_cb, get_main_thread())) {
+ LOG(WARNING) << __func__ << ": Using legacy HAL";
uipc_hearing_aid = UIPC_Init();
- UIPC_Open(*uipc_hearing_aid, UIPC_CH_ID_AV_CTRL, hearing_aid_ctrl_cb,
- HEARING_AID_CTRL_PATH);
+ UIPC_Open(*uipc_hearing_aid, UIPC_CH_ID_AV_CTRL, hearing_aid_ctrl_cb, HEARING_AID_CTRL_PATH);
}
}
"android.hardware.bluetooth.audio@2.0",
"libfmq",
"libhidlbase",
+ "libhidltransport",
"liblog",
"libprotobuf-cpp-lite",
"libcutils",
if (!btif_a2dp_source_thread.EnableRealTimeScheduling()) {
LOG(FATAL) << __func__ << ": unable to enable real time scheduling";
}
- if (bluetooth::audio::a2dp::is_hal_2_0_supported()) {
- bluetooth::audio::a2dp::init(&btif_a2dp_source_thread);
- } else {
+ if (!bluetooth::audio::a2dp::init(&btif_a2dp_source_thread)) {
+ LOG(WARNING) << __func__ << ": Using legacy HAL";
btif_a2dp_control_init();
}
btif_a2dp_source_cb.SetState(BtifA2dpSource::kStateRunning);