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 #include <vector>
18 
19 #define LOG_TAG "AHAL_ModuleStub"
20 #include <Utils.h>
21 #include <android-base/logging.h>
22 
23 #include "core-impl/Bluetooth.h"
24 #include "core-impl/ModuleStub.h"
25 #include "core-impl/StreamStub.h"
26 
27 using aidl::android::hardware::audio::common::SinkMetadata;
28 using aidl::android::hardware::audio::common::SourceMetadata;
29 using aidl::android::media::audio::common::AudioOffloadInfo;
30 using aidl::android::media::audio::common::AudioPort;
31 using aidl::android::media::audio::common::AudioPortConfig;
32 using aidl::android::media::audio::common::MicrophoneInfo;
33 
34 namespace aidl::android::hardware::audio::core {
35 
getBluetooth(std::shared_ptr<IBluetooth> * _aidl_return)36 ndk::ScopedAStatus ModuleStub::getBluetooth(std::shared_ptr<IBluetooth>* _aidl_return) {
37     if (!mBluetooth) {
38         mBluetooth = ndk::SharedRefBase::make<Bluetooth>();
39     }
40     *_aidl_return = mBluetooth.getInstance();
41     LOG(DEBUG) << __func__
42                << ": returning instance of IBluetooth: " << _aidl_return->get()->asBinder().get();
43     return ndk::ScopedAStatus::ok();
44 }
45 
getBluetoothA2dp(std::shared_ptr<IBluetoothA2dp> * _aidl_return)46 ndk::ScopedAStatus ModuleStub::getBluetoothA2dp(std::shared_ptr<IBluetoothA2dp>* _aidl_return) {
47     if (!mBluetoothA2dp) {
48         mBluetoothA2dp = ndk::SharedRefBase::make<BluetoothA2dp>();
49     }
50     *_aidl_return = mBluetoothA2dp.getInstance();
51     LOG(DEBUG) << __func__ << ": returning instance of IBluetoothA2dp: "
52                << _aidl_return->get()->asBinder().get();
53     return ndk::ScopedAStatus::ok();
54 }
55 
getBluetoothLe(std::shared_ptr<IBluetoothLe> * _aidl_return)56 ndk::ScopedAStatus ModuleStub::getBluetoothLe(std::shared_ptr<IBluetoothLe>* _aidl_return) {
57     if (!mBluetoothLe) {
58         mBluetoothLe = ndk::SharedRefBase::make<BluetoothLe>();
59     }
60     *_aidl_return = mBluetoothLe.getInstance();
61     LOG(DEBUG) << __func__
62                << ": returning instance of IBluetoothLe: " << _aidl_return->get()->asBinder().get();
63     return ndk::ScopedAStatus::ok();
64 }
65 
createInputStream(StreamContext && context,const SinkMetadata & sinkMetadata,const std::vector<MicrophoneInfo> & microphones,std::shared_ptr<StreamIn> * result)66 ndk::ScopedAStatus ModuleStub::createInputStream(StreamContext&& context,
67                                                  const SinkMetadata& sinkMetadata,
68                                                  const std::vector<MicrophoneInfo>& microphones,
69                                                  std::shared_ptr<StreamIn>* result) {
70     return createStreamInstance<StreamInStub>(result, std::move(context), sinkMetadata,
71                                               microphones);
72 }
73 
createOutputStream(StreamContext && context,const SourceMetadata & sourceMetadata,const std::optional<AudioOffloadInfo> & offloadInfo,std::shared_ptr<StreamOut> * result)74 ndk::ScopedAStatus ModuleStub::createOutputStream(
75         StreamContext&& context, const SourceMetadata& sourceMetadata,
76         const std::optional<AudioOffloadInfo>& offloadInfo, std::shared_ptr<StreamOut>* result) {
77     return createStreamInstance<StreamOutStub>(result, std::move(context), sourceMetadata,
78                                                offloadInfo);
79 }
80 
81 }  // namespace aidl::android::hardware::audio::core
82