xref: /aosp_15_r20/hardware/interfaces/bluetooth/audio/aidl/default/HfpOffloadAudioProvider.cpp (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
1 /*
2  * Copyright (C) 2023 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 "BTAudioProviderHfpHW"
18 
19 #include "HfpOffloadAudioProvider.h"
20 
21 #include <BluetoothAudioCodecs.h>
22 #include <BluetoothAudioSessionReport.h>
23 #include <android-base/logging.h>
24 
25 namespace aidl {
26 namespace android {
27 namespace hardware {
28 namespace bluetooth {
29 namespace audio {
30 
HfpOffloadAudioProvider()31 HfpOffloadAudioProvider::HfpOffloadAudioProvider() {
32   session_type_ = SessionType::HFP_HARDWARE_OFFLOAD_DATAPATH;
33 }
34 
isValid(const SessionType & session_type)35 bool HfpOffloadAudioProvider::isValid(const SessionType& session_type) {
36   return (session_type == session_type_);
37 }
38 
startSession(const std::shared_ptr<IBluetoothAudioPort> & host_if,const AudioConfiguration & audio_config,const std::vector<LatencyMode> & latency_modes,DataMQDesc * _aidl_return)39 ndk::ScopedAStatus HfpOffloadAudioProvider::startSession(
40     const std::shared_ptr<IBluetoothAudioPort>& host_if,
41     const AudioConfiguration& audio_config,
42     const std::vector<LatencyMode>& latency_modes, DataMQDesc* _aidl_return) {
43   if (audio_config.getTag() != AudioConfiguration::hfpConfig) {
44     LOG(WARNING) << __func__ << " - Invalid Audio Configuration="
45                  << audio_config.toString();
46     *_aidl_return = DataMQDesc();
47     return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
48   }
49   return BluetoothAudioProvider::startSession(host_if, audio_config,
50                                               latency_modes, _aidl_return);
51 }
52 
onSessionReady(DataMQDesc * _aidl_return)53 ndk::ScopedAStatus HfpOffloadAudioProvider::onSessionReady(
54     DataMQDesc* _aidl_return) {
55   *_aidl_return = DataMQDesc();
56   BluetoothAudioSessionReport::OnSessionStarted(
57       session_type_, stack_iface_, nullptr, *audio_config_, latency_modes_);
58   return ndk::ScopedAStatus::ok();
59 }
60 
61 }  // namespace audio
62 }  // namespace bluetooth
63 }  // namespace hardware
64 }  // namespace android
65 }  // namespace aidl
66