Loading system/service/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ btserviceBaseTestSrc = [ "hal/fake_bluetooth_gatt_interface.cc", "hal/fake_bluetooth_interface.cc", "test/a2dp_sink_unittest.cc", "test/a2dp_source_unittest.cc", "test/adapter_unittest.cc", "test/advertise_data_unittest.cc", "test/fake_hal_util.cc", Loading system/service/a2dp_source.cc +7 −0 Original line number Diff line number Diff line Loading @@ -199,6 +199,13 @@ void A2dpSource::AudioConfigCallback( codecs_selectable_capabilities); } bool A2dpSource::MandatoryCodecPreferredCallback(BluetoothAvInterface* iface, const RawAddress& bd_addr) { LockGuard lock(delegate_mutex_); // Do nothing. Optional codecs are preferred by default. return false; } // A2dpSourceFactory implementation // ======================================================== A2dpSourceFactory::A2dpSourceFactory() = default; Loading system/service/a2dp_source.h +2 −0 Original line number Diff line number Diff line Loading @@ -82,6 +82,8 @@ class A2dpSource : public BluetoothInstance, const std::vector<btav_a2dp_codec_config_t> codecs_local_capabilities, const std::vector<btav_a2dp_codec_config_t> codecs_selectable_capabilities) override; bool MandatoryCodecPreferredCallback(hal::BluetoothAvInterface* iface, const RawAddress& bd_addr) override; // For |GetAppIdentifier|. const Uuid app_identifier_; Loading system/service/hal/bluetooth_av_interface.cc +20 −2 Original line number Diff line number Diff line Loading @@ -46,11 +46,11 @@ GetA2dpSourceObservers(); base::ObserverList<BluetoothAvInterface::A2dpSinkObserver>* GetA2dpSinkObservers(); #define VERIFY_INTERFACE_OR_RETURN() \ #define VERIFY_INTERFACE_OR_RETURN(...) \ do { \ if (!g_interface) { \ LOG(WARNING) << "Callback received while |g_interface| is NULL"; \ return; \ return __VA_ARGS__; \ } \ } while (0) Loading Loading @@ -88,6 +88,17 @@ void SourceAudioConfigCallback( } } bool SourceMandatoryCodecPreferredCallback(const RawAddress& bd_addr) { VERIFY_INTERFACE_OR_RETURN(false); // The mandatory codec is preferred only when all observers disable their // optional codecs. for (auto& observer : *GetA2dpSourceObservers()) { if (!observer.MandatoryCodecPreferredCallback(g_interface, bd_addr)) return false; } return true; } void SinkConnectionStateCallback(const RawAddress& bd_addr, btav_connection_state_t state) { std::shared_lock<shared_mutex_impl> lock(g_instance_lock); Loading Loading @@ -121,6 +132,7 @@ btav_source_callbacks_t av_source_callbacks = { .connection_state_cb = SourceConnectionStateCallback, .audio_state_cb = SourceAudioStateCallback, .audio_config_cb = SourceAudioConfigCallback, .mandatory_codec_preferred_cb = SourceMandatoryCodecPreferredCallback, }; btav_sink_callbacks_t av_sink_callbacks = { Loading Loading @@ -297,6 +309,12 @@ void BluetoothAvInterface::A2dpSourceObserver::AudioConfigCallback( // Do nothing. } bool BluetoothAvInterface::A2dpSourceObserver::MandatoryCodecPreferredCallback( BluetoothAvInterface* iface, const RawAddress& bd_addr) { // Do nothing. return false; } void BluetoothAvInterface::A2dpSinkObserver::ConnectionStateCallback( BluetoothAvInterface* iface, const RawAddress& bd_addr, btav_connection_state_t state) { Loading system/service/hal/bluetooth_av_interface.h +2 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,8 @@ class BluetoothAvInterface { const std::vector<btav_a2dp_codec_config_t> codecs_local_capabilities, const std::vector<btav_a2dp_codec_config_t> codecs_selectable_capabilities); virtual bool MandatoryCodecPreferredCallback(BluetoothAvInterface* iface, const RawAddress& bd_addr); protected: virtual ~A2dpSourceObserver() = default; Loading Loading
system/service/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ btserviceBaseTestSrc = [ "hal/fake_bluetooth_gatt_interface.cc", "hal/fake_bluetooth_interface.cc", "test/a2dp_sink_unittest.cc", "test/a2dp_source_unittest.cc", "test/adapter_unittest.cc", "test/advertise_data_unittest.cc", "test/fake_hal_util.cc", Loading
system/service/a2dp_source.cc +7 −0 Original line number Diff line number Diff line Loading @@ -199,6 +199,13 @@ void A2dpSource::AudioConfigCallback( codecs_selectable_capabilities); } bool A2dpSource::MandatoryCodecPreferredCallback(BluetoothAvInterface* iface, const RawAddress& bd_addr) { LockGuard lock(delegate_mutex_); // Do nothing. Optional codecs are preferred by default. return false; } // A2dpSourceFactory implementation // ======================================================== A2dpSourceFactory::A2dpSourceFactory() = default; Loading
system/service/a2dp_source.h +2 −0 Original line number Diff line number Diff line Loading @@ -82,6 +82,8 @@ class A2dpSource : public BluetoothInstance, const std::vector<btav_a2dp_codec_config_t> codecs_local_capabilities, const std::vector<btav_a2dp_codec_config_t> codecs_selectable_capabilities) override; bool MandatoryCodecPreferredCallback(hal::BluetoothAvInterface* iface, const RawAddress& bd_addr) override; // For |GetAppIdentifier|. const Uuid app_identifier_; Loading
system/service/hal/bluetooth_av_interface.cc +20 −2 Original line number Diff line number Diff line Loading @@ -46,11 +46,11 @@ GetA2dpSourceObservers(); base::ObserverList<BluetoothAvInterface::A2dpSinkObserver>* GetA2dpSinkObservers(); #define VERIFY_INTERFACE_OR_RETURN() \ #define VERIFY_INTERFACE_OR_RETURN(...) \ do { \ if (!g_interface) { \ LOG(WARNING) << "Callback received while |g_interface| is NULL"; \ return; \ return __VA_ARGS__; \ } \ } while (0) Loading Loading @@ -88,6 +88,17 @@ void SourceAudioConfigCallback( } } bool SourceMandatoryCodecPreferredCallback(const RawAddress& bd_addr) { VERIFY_INTERFACE_OR_RETURN(false); // The mandatory codec is preferred only when all observers disable their // optional codecs. for (auto& observer : *GetA2dpSourceObservers()) { if (!observer.MandatoryCodecPreferredCallback(g_interface, bd_addr)) return false; } return true; } void SinkConnectionStateCallback(const RawAddress& bd_addr, btav_connection_state_t state) { std::shared_lock<shared_mutex_impl> lock(g_instance_lock); Loading Loading @@ -121,6 +132,7 @@ btav_source_callbacks_t av_source_callbacks = { .connection_state_cb = SourceConnectionStateCallback, .audio_state_cb = SourceAudioStateCallback, .audio_config_cb = SourceAudioConfigCallback, .mandatory_codec_preferred_cb = SourceMandatoryCodecPreferredCallback, }; btav_sink_callbacks_t av_sink_callbacks = { Loading Loading @@ -297,6 +309,12 @@ void BluetoothAvInterface::A2dpSourceObserver::AudioConfigCallback( // Do nothing. } bool BluetoothAvInterface::A2dpSourceObserver::MandatoryCodecPreferredCallback( BluetoothAvInterface* iface, const RawAddress& bd_addr) { // Do nothing. return false; } void BluetoothAvInterface::A2dpSinkObserver::ConnectionStateCallback( BluetoothAvInterface* iface, const RawAddress& bd_addr, btav_connection_state_t state) { Loading
system/service/hal/bluetooth_av_interface.h +2 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,8 @@ class BluetoothAvInterface { const std::vector<btav_a2dp_codec_config_t> codecs_local_capabilities, const std::vector<btav_a2dp_codec_config_t> codecs_selectable_capabilities); virtual bool MandatoryCodecPreferredCallback(BluetoothAvInterface* iface, const RawAddress& bd_addr); protected: virtual ~A2dpSourceObserver() = default; Loading