1 /*
2  * Copyright 2022 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 #include "hearing_aid_software_encoding.h"
18 
19 #include "aidl/hearing_aid_software_encoding_aidl.h"
20 #include "hal_version_manager.h"
21 #include "hidl/hearing_aid_software_encoding_hidl.h"
22 
23 namespace bluetooth {
24 namespace audio {
25 namespace hearing_aid {
26 
27 // Check if new bluetooth_audio is enabled
is_hal_enabled()28 bool is_hal_enabled() {
29   if (HalVersionManager::GetHalTransport() == BluetoothAudioHalTransport::HIDL) {
30     return hidl::hearing_aid::is_hal_2_0_enabled();
31   }
32   return aidl::hearing_aid::is_hal_enabled();
33 }
34 
35 // Initialize BluetoothAudio HAL: openProvider
init(StreamCallbacks stream_cb,bluetooth::common::MessageLoopThread * message_loop)36 bool init(StreamCallbacks stream_cb, bluetooth::common::MessageLoopThread* message_loop) {
37   if (HalVersionManager::GetHalTransport() == BluetoothAudioHalTransport::HIDL) {
38     return hidl::hearing_aid::init(stream_cb, message_loop);
39   }
40   return aidl::hearing_aid::init(stream_cb, message_loop);
41 }
42 
43 // Clean up BluetoothAudio HAL
cleanup()44 void cleanup() {
45   if (HalVersionManager::GetHalTransport() == BluetoothAudioHalTransport::HIDL) {
46     hidl::hearing_aid::cleanup();
47     return;
48   }
49   aidl::hearing_aid::cleanup();
50 }
51 
52 // Send command to the BluetoothAudio HAL: StartSession, EndSession
start_session()53 void start_session() {
54   if (HalVersionManager::GetHalTransport() == BluetoothAudioHalTransport::HIDL) {
55     hidl::hearing_aid::start_session();
56     return;
57   }
58   aidl::hearing_aid::start_session();
59 }
60 
end_session()61 void end_session() {
62   if (HalVersionManager::GetHalTransport() == BluetoothAudioHalTransport::HIDL) {
63     hidl::hearing_aid::end_session();
64     return;
65   }
66   aidl::hearing_aid::end_session();
67 }
68 
set_remote_delay(uint16_t delay_report_ms)69 void set_remote_delay(uint16_t delay_report_ms) {
70   if (HalVersionManager::GetHalTransport() == BluetoothAudioHalTransport::HIDL) {
71     hidl::hearing_aid::set_remote_delay(delay_report_ms);
72     return;
73   }
74   aidl::hearing_aid::set_remote_delay(delay_report_ms);
75 }
76 
77 // Read from the FMQ of BluetoothAudio HAL
read(uint8_t * p_buf,uint32_t len)78 size_t read(uint8_t* p_buf, uint32_t len) {
79   if (HalVersionManager::GetHalTransport() == BluetoothAudioHalTransport::HIDL) {
80     return hidl::hearing_aid::read(p_buf, len);
81   }
82   return aidl::hearing_aid::read(p_buf, len);
83 }
84 
85 }  // namespace hearing_aid
86 }  // namespace audio
87 }  // namespace bluetooth
88