1 /*
2 * Copyright 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define LOG_TAG "AIDLProviderInfo"
18
19 #include "provider_info.h"
20
21 #include <android/binder_manager.h>
22 #include <com_android_bluetooth_flags.h>
23
24 #include <optional>
25
26 #include "client_interface_aidl.h"
27
28 namespace bluetooth::audio::aidl {
29 using ::aidl::android::hardware::bluetooth::audio::CodecId;
30 using ::aidl::android::hardware::bluetooth::audio::CodecInfo;
31 using ::aidl::android::hardware::bluetooth::audio::SessionType;
32
recordHfpCodecInfo(CodecInfo codecInfo)33 static ::hfp::sco_config recordHfpCodecInfo(CodecInfo codecInfo) {
34 auto hfp_transport = codecInfo.transport.get<CodecInfo::Transport::hfp>();
35 ::hfp::sco_config config{
36 .inputDataPath = hfp_transport.inputDataPath,
37 .outputDataPath = hfp_transport.outputDataPath,
38 .useControllerCodec = hfp_transport.useControllerCodec,
39 };
40 return config;
41 }
42
GetProviderInfo(SessionType sessionType)43 std::unique_ptr<ProviderInfo> bluetooth::audio::aidl::ProviderInfo::GetProviderInfo(
44 SessionType sessionType) {
45 auto provider_info = BluetoothAudioClientInterface::GetProviderInfo(sessionType);
46
47 std::vector<CodecInfo> codecInfos;
48 if (provider_info.has_value()) {
49 codecInfos = std::move(provider_info->codecInfos);
50 }
51
52 return std::make_unique<ProviderInfo>(sessionType, std::move(codecInfos));
53 }
54
ProviderInfo(SessionType sessionType,std::vector<CodecInfo> codecs)55 ProviderInfo::ProviderInfo(SessionType sessionType, std::vector<CodecInfo> codecs)
56 : codecInfos(std::move(codecs)) {
57 for (auto codecInfo : codecInfos) {
58 if (codecInfo.id == CodecId::Core::CVSD) {
59 hfpScoConfigMap[tBTA_AG_UUID_CODEC::UUID_CODEC_CVSD] = recordHfpCodecInfo(codecInfo);
60 } else if (codecInfo.id == CodecId::Core::MSBC) {
61 hfpScoConfigMap[tBTA_AG_UUID_CODEC::UUID_CODEC_MSBC] = recordHfpCodecInfo(codecInfo);
62 } else if (codecInfo.id == CodecId::Core::LC3) {
63 if (sessionType == SessionType::HFP_HARDWARE_OFFLOAD_DATAPATH ||
64 sessionType == SessionType::HFP_SOFTWARE_ENCODING_DATAPATH ||
65 sessionType == SessionType::HFP_SOFTWARE_DECODING_DATAPATH) {
66 hfpScoConfigMap[tBTA_AG_UUID_CODEC::UUID_CODEC_LC3] = recordHfpCodecInfo(codecInfo);
67 }
68 }
69 }
70 }
71
GetHfpScoConfig()72 const std::unordered_map<tBTA_AG_UUID_CODEC, ::hfp::sco_config>& ProviderInfo::GetHfpScoConfig() {
73 return hfpScoConfigMap;
74 }
75 } // namespace bluetooth::audio::aidl
76