From 2fa1ab4bd578026d2a913183e6bd6fa781c37206 Mon Sep 17 00:00:00 2001 From: Bao Do Date: Mon, 29 Jan 2024 17:50:34 +0800 Subject: [PATCH] Template and schema of HFP provider info Bug: 322280104 Test: make Change-Id: Iac4f96db08b3b7fb2c5f0b080ba3e972e6020982 --- .../default/BluetoothAudioProviderFactory.cpp | 19 ++++- .../vts/VtsHalBluetoothAudioTargetTest.cpp | 1 + bluetooth/audio/utils/Android.bp | 26 +++++- .../aidl_session/BluetoothAudioCodecs.cpp | 13 +++ .../utils/aidl_session/BluetoothAudioCodecs.h | 2 + .../BluetoothHfpCodecsProvider.cpp | 40 +++++++++ .../aidl_session/BluetoothHfpCodecsProvider.h | 45 ++++++++++ .../hfp_codec_capabilities.xml | 40 +++++++++ .../hfp_codec_capabilities.xsd | 51 ++++++++++++ .../hfp_codec_capabilities/schema/current.txt | 82 +++++++++++++++++++ .../schema/last_current.txt | 1 + .../schema/last_removed.txt | 1 + .../hfp_codec_capabilities/schema/removed.txt | 1 + 13 files changed, 319 insertions(+), 3 deletions(-) create mode 100644 bluetooth/audio/utils/aidl_session/BluetoothHfpCodecsProvider.cpp create mode 100644 bluetooth/audio/utils/aidl_session/BluetoothHfpCodecsProvider.h create mode 100644 bluetooth/audio/utils/hfp_codec_capabilities/hfp_codec_capabilities.xml create mode 100644 bluetooth/audio/utils/hfp_codec_capabilities/hfp_codec_capabilities.xsd create mode 100644 bluetooth/audio/utils/hfp_codec_capabilities/schema/current.txt create mode 100644 bluetooth/audio/utils/hfp_codec_capabilities/schema/last_current.txt create mode 100644 bluetooth/audio/utils/hfp_codec_capabilities/schema/last_removed.txt create mode 100644 bluetooth/audio/utils/hfp_codec_capabilities/schema/removed.txt diff --git a/bluetooth/audio/aidl/default/BluetoothAudioProviderFactory.cpp b/bluetooth/audio/aidl/default/BluetoothAudioProviderFactory.cpp index 584640b232..dc36ac0c1a 100644 --- a/bluetooth/audio/aidl/default/BluetoothAudioProviderFactory.cpp +++ b/bluetooth/audio/aidl/default/BluetoothAudioProviderFactory.cpp @@ -39,6 +39,9 @@ namespace audio { static const std::string kLeAudioOffloadProviderName = "LE_AUDIO_OFFLOAD_HARDWARE_OFFLOAD_PROVIDER"; +static const std::string kHfpOffloadProviderName = + "HFP_OFFLOAD_HARDWARE_OFFLOAD_PROVIDER"; + BluetoothAudioProviderFactory::BluetoothAudioProviderFactory() {} ndk::ScopedAStatus BluetoothAudioProviderFactory::openProvider( @@ -170,6 +173,7 @@ ndk::ScopedAStatus BluetoothAudioProviderFactory::getProviderInfo( provider_info.name = a2dp_offload_codec_factory_.name; for (auto codec : a2dp_offload_codec_factory_.codecs) provider_info.codecInfos.push_back(codec->info); + return ndk::ScopedAStatus::ok(); } if (session_type == @@ -184,12 +188,23 @@ ndk::ScopedAStatus BluetoothAudioProviderFactory::getProviderInfo( auto& provider_info = _aidl_return->emplace(); provider_info.name = kLeAudioOffloadProviderName; provider_info.codecInfos = db_codec_info; - *_aidl_return = provider_info; return ndk::ScopedAStatus::ok(); } } - return ndk::ScopedAStatus::ok(); + if (session_type == SessionType::HFP_HARDWARE_OFFLOAD_DATAPATH) { + std::vector db_codec_info = + BluetoothAudioCodecs::GetHfpOffloadCodecInfo(); + if (!db_codec_info.empty()) { + auto& provider_info = _aidl_return->emplace(); + provider_info.name = kHfpOffloadProviderName; + provider_info.codecInfos = db_codec_info; + return ndk::ScopedAStatus::ok(); + } + } + + // Unsupported for other sessions + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } } // namespace audio diff --git a/bluetooth/audio/aidl/vts/VtsHalBluetoothAudioTargetTest.cpp b/bluetooth/audio/aidl/vts/VtsHalBluetoothAudioTargetTest.cpp index 789e8a1268..c313fb7d0c 100644 --- a/bluetooth/audio/aidl/vts/VtsHalBluetoothAudioTargetTest.cpp +++ b/bluetooth/audio/aidl/vts/VtsHalBluetoothAudioTargetTest.cpp @@ -1944,6 +1944,7 @@ class BluetoothAudioProviderHfpHardwareAidl BluetoothAudioHalVersion::VERSION_AIDL_V4) { GTEST_SKIP(); } + GetProviderInfoHelper(SessionType::HFP_HARDWARE_OFFLOAD_DATAPATH); OpenProviderHelper(SessionType::HFP_HARDWARE_OFFLOAD_DATAPATH); // Can open or empty capability ASSERT_TRUE(temp_provider_capabilities_.empty() || diff --git a/bluetooth/audio/utils/Android.bp b/bluetooth/audio/utils/Android.bp index c0817f54e1..0899441c4e 100644 --- a/bluetooth/audio/utils/Android.bp +++ b/bluetooth/audio/utils/Android.bp @@ -42,6 +42,7 @@ cc_library_shared { "aidl_session/BluetoothAudioSession.cpp", "aidl_session/HidlToAidlMiddleware.cpp", "aidl_session/BluetoothLeAudioCodecsProvider.cpp", + "aidl_session/BluetoothHfpCodecsProvider.cpp", "aidl_session/BluetoothLeAudioAseConfigurationSettingProvider.cpp", ], export_include_dirs: ["aidl_session/"], @@ -68,9 +69,13 @@ cc_library_shared { static_libs: [ "btaudiohal_flags_c_lib", ], - generated_sources: ["le_audio_codec_capabilities"], + generated_sources: [ + "le_audio_codec_capabilities", + "hfp_codec_capabilities", + ], generated_headers: [ "le_audio_codec_capabilities", + "hfp_codec_capabilities", "AIDLLeAudioSetConfigSchemas_h", ], required: [ @@ -78,9 +83,12 @@ cc_library_shared { "aidl_audio_set_configurations_json", "aidl_audio_set_scenarios_bfbs", "aidl_audio_set_scenarios_json", + "hfp_codec_capabilities_xml", ], } +// TODO: Write test for BluetoothHfpCodecsProvider.cpp + cc_test { name: "BluetoothLeAudioCodecsProviderTest", srcs: [ @@ -114,6 +122,14 @@ xsd_config { root_elements: ["leAudioOffloadSetting"], } +xsd_config { + name: "hfp_codec_capabilities", + srcs: ["hfp_codec_capabilities/hfp_codec_capabilities.xsd"], + package_name: "aidl.android.hardware.bluetooth.audio.hfp.setting", + api_dir: "hfp_codec_capabilities/schema", + root_elements: ["hfpOffloadSetting"], +} + genrule { name: "AIDLLeAudioSetConfigSchemas_h", tools: [ @@ -176,6 +192,14 @@ prebuilt_etc { vendor: true, } +prebuilt_etc { + name: "hfp_codec_capabilities_xml", + src: "hfp_codec_capabilities/hfp_codec_capabilities.xml", + filename: "hfp_codec_capabilities.xml", + sub_dir: "aidl/hfp", + vendor: true, +} + prebuilt_etc { name: "aidl_audio_set_configurations_bfbs", src: ":AIDLLeAudioSetConfigsSchema_bfbs", diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.cpp b/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.cpp index d37825a2a1..c25b102e4e 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.cpp +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.cpp @@ -32,6 +32,7 @@ #include #include +#include "BluetoothHfpCodecsProvider.h" #include "BluetoothLeAudioAseConfigurationSettingProvider.h" #include "BluetoothLeAudioCodecsProvider.h" @@ -100,6 +101,7 @@ const std::vector kDefaultOffloadA2dpCodecCapabilities = { std::vector kDefaultOffloadLeAudioCapabilities; std::unordered_map> kDefaultOffloadLeAudioCodecInfoMap; +std::vector kDefaultOffloadHfpCodecInfo; template bool BluetoothAudioCodecs::ContainedInVector( @@ -439,6 +441,17 @@ std::vector BluetoothAudioCodecs::GetLeAudioOffloadCodecInfo( return codec_info_map_iter->second; } +std::vector BluetoothAudioCodecs::GetHfpOffloadCodecInfo() { + if (kDefaultOffloadHfpCodecInfo.empty()) { + auto hfp_offload_setting = + BluetoothHfpCodecsProvider::ParseFromHfpOffloadSettingFile(); + // Load file into list + kDefaultOffloadHfpCodecInfo = + BluetoothHfpCodecsProvider::GetHfpAudioCodecInfo(hfp_offload_setting); + } + return kDefaultOffloadHfpCodecInfo; +} + std::vector BluetoothAudioCodecs::GetLeAudioAseConfigurationSettings() { return AudioSetConfigurationProviderJson:: diff --git a/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.h b/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.h index 057b9a72c8..0a1f7081e5 100644 --- a/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.h +++ b/bluetooth/audio/utils/aidl_session/BluetoothAudioCodecs.h @@ -57,6 +57,8 @@ class BluetoothAudioCodecs { static std::vector GetLeAudioAseConfigurationSettings(); + static std::vector GetHfpOffloadCodecInfo(); + private: template struct identity { diff --git a/bluetooth/audio/utils/aidl_session/BluetoothHfpCodecsProvider.cpp b/bluetooth/audio/utils/aidl_session/BluetoothHfpCodecsProvider.cpp new file mode 100644 index 0000000000..be08a39a74 --- /dev/null +++ b/bluetooth/audio/utils/aidl_session/BluetoothHfpCodecsProvider.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "BluetoothHfpCodecsProvider.h" + +namespace aidl { +namespace android { +namespace hardware { +namespace bluetooth { +namespace audio { + +std::optional +BluetoothHfpCodecsProvider::ParseFromHfpOffloadSettingFile() { + return std::nullopt; +} + +std::vector BluetoothHfpCodecsProvider::GetHfpAudioCodecInfo( + const std::optional& hfp_offload_setting) { + (void)hfp_offload_setting; + return std::vector(); +} + +} // namespace audio +} // namespace bluetooth +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/bluetooth/audio/utils/aidl_session/BluetoothHfpCodecsProvider.h b/bluetooth/audio/utils/aidl_session/BluetoothHfpCodecsProvider.h new file mode 100644 index 0000000000..d2196a2459 --- /dev/null +++ b/bluetooth/audio/utils/aidl_session/BluetoothHfpCodecsProvider.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#include + +#include "aidl/android/hardware/bluetooth/audio/CodecInfo.h" +#include "aidl_android_hardware_bluetooth_audio_hfp_setting.h" + +namespace aidl { +namespace android { +namespace hardware { +namespace bluetooth { +namespace audio { + +using hfp::setting::HfpOffloadSetting; + +class BluetoothHfpCodecsProvider { + public: + static std::optional ParseFromHfpOffloadSettingFile(); + + static std::vector GetHfpAudioCodecInfo( + const std::optional& hfp_offload_setting); +}; +} // namespace audio +} // namespace bluetooth +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/bluetooth/audio/utils/hfp_codec_capabilities/hfp_codec_capabilities.xml b/bluetooth/audio/utils/hfp_codec_capabilities/hfp_codec_capabilities.xml new file mode 100644 index 0000000000..c94843f9c5 --- /dev/null +++ b/bluetooth/audio/utils/hfp_codec_capabilities/hfp_codec_capabilities.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bluetooth/audio/utils/hfp_codec_capabilities/hfp_codec_capabilities.xsd b/bluetooth/audio/utils/hfp_codec_capabilities/hfp_codec_capabilities.xsd new file mode 100644 index 0000000000..c4787b9fbf --- /dev/null +++ b/bluetooth/audio/utils/hfp_codec_capabilities/hfp_codec_capabilities.xsd @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bluetooth/audio/utils/hfp_codec_capabilities/schema/current.txt b/bluetooth/audio/utils/hfp_codec_capabilities/schema/current.txt new file mode 100644 index 0000000000..4b4992971e --- /dev/null +++ b/bluetooth/audio/utils/hfp_codec_capabilities/schema/current.txt @@ -0,0 +1,82 @@ +// Signature format: 2.0 +package aidl.android.hardware.bluetooth.audio.hfp.setting { + + public enum CodecType { + method public String getRawName(); + enum_constant public static final aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType CVSD; + enum_constant public static final aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType LC3; + enum_constant public static final aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType MSBC; + } + + public class Configuration { + ctor public Configuration(); + method public aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType getCodec(); + method public String getInputPathConfiguration(); + method public String getInputTransportConfiguration(); + method public int getMaxLatencyMs(); + method public String getName(); + method public String getOutputPathConfiguration(); + method public String getOutputTransportConfiguration(); + method public int getPacketTypes(); + method public short getRetransmissionEffort(); + method public boolean getUseControllerCodec(); + method public void setCodec(aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType); + method public void setInputPathConfiguration(String); + method public void setInputTransportConfiguration(String); + method public void setMaxLatencyMs(int); + method public void setName(String); + method public void setOutputPathConfiguration(String); + method public void setOutputTransportConfiguration(String); + method public void setPacketTypes(int); + method public void setRetransmissionEffort(short); + method public void setUseControllerCodec(boolean); + } + + public class HfpOffloadSetting { + ctor public HfpOffloadSetting(); + method public java.util.List getConfiguration(); + method public java.util.List getPathConfiguration(); + method public java.util.List getTransportConfiguration(); + } + + public class PathConfiguration { + ctor public PathConfiguration(); + method public long getBandwidth(); + method public aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType getCodec(); + method public int getCodedDataSize(); + method public short getDataPath(); + method public String getName(); + method public short getPcmDataFormat(); + method public short getPcmPayloadMsbPosition(); + method public short getTransportUnitSize(); + method public void setBandwidth(long); + method public void setCodec(aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType); + method public void setCodedDataSize(int); + method public void setDataPath(short); + method public void setName(String); + method public void setPcmDataFormat(short); + method public void setPcmPayloadMsbPosition(short); + method public void setTransportUnitSize(short); + } + + public class TransportConfiguration { + ctor public TransportConfiguration(); + method public long getBandwidth(); + method public aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType getCodec(); + method public int getCodedFrameSize(); + method public String getName(); + method public void setBandwidth(long); + method public void setCodec(aidl.android.hardware.bluetooth.audio.hfp.setting.CodecType); + method public void setCodedFrameSize(int); + method public void setName(String); + } + + public class XmlParser { + ctor public XmlParser(); + method public static aidl.android.hardware.bluetooth.audio.hfp.setting.HfpOffloadSetting readHfpOffloadSetting(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static String readText(org.xmlpull.v1.XmlPullParser) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; + method public static void skip(org.xmlpull.v1.XmlPullParser) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; + } + +} + diff --git a/bluetooth/audio/utils/hfp_codec_capabilities/schema/last_current.txt b/bluetooth/audio/utils/hfp_codec_capabilities/schema/last_current.txt new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/bluetooth/audio/utils/hfp_codec_capabilities/schema/last_current.txt @@ -0,0 +1 @@ + diff --git a/bluetooth/audio/utils/hfp_codec_capabilities/schema/last_removed.txt b/bluetooth/audio/utils/hfp_codec_capabilities/schema/last_removed.txt new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/bluetooth/audio/utils/hfp_codec_capabilities/schema/last_removed.txt @@ -0,0 +1 @@ + diff --git a/bluetooth/audio/utils/hfp_codec_capabilities/schema/removed.txt b/bluetooth/audio/utils/hfp_codec_capabilities/schema/removed.txt new file mode 100644 index 0000000000..d802177e24 --- /dev/null +++ b/bluetooth/audio/utils/hfp_codec_capabilities/schema/removed.txt @@ -0,0 +1 @@ +// Signature format: 2.0