1 /*
2 * Copyright (C) 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 #include "core-mock/ModuleMock.h"
18 #include "core-mock/BluetoothA2dpMock.h"
19 #include "core-mock/BluetoothLeMock.h"
20 #include "core-mock/BluetoothMock.h"
21 #include "core-mock/StreamInMock.h"
22 #include "core-mock/StreamOutMock.h"
23 #include "core-mock/TelephonyMock.h"
24 #include "sounddose-mock/SoundDoseMock.h"
25
26 namespace aidl::android::hardware::audio::core {
27
ModuleMock()28 ModuleMock::ModuleMock() {
29 // Device ports
30 auto outDevice = createPort(/* PortId */ 0, /* Name */ "Default",
31 /* Flags */ 1 << AudioPortDeviceExt::FLAG_INDEX_DEFAULT_DEVICE,
32 /* isInput */ false,
33 createDeviceExt(
34 /* DeviceType */ AudioDeviceType::OUT_DEFAULT,
35 /* Flags */ AudioPortDeviceExt::FLAG_INDEX_DEFAULT_DEVICE));
36 mPorts.push_back(outDevice);
37 auto inDevice = createPort(/* PortId */ 1, /* Name */ "Default",
38 /* Flags */ 1 << AudioPortDeviceExt::FLAG_INDEX_DEFAULT_DEVICE,
39 /* isInput */ true,
40 createDeviceExt(
41 /* DeviceType */ AudioDeviceType::IN_DEFAULT,
42 /* Flags */ 0));
43 mPorts.push_back(outDevice);
44 }
45
getTelephony(std::shared_ptr<ITelephony> * _aidl_return)46 ndk::ScopedAStatus ModuleMock::getTelephony(std::shared_ptr<ITelephony>* _aidl_return) {
47 *_aidl_return = ndk::SharedRefBase::make<TelephonyMock>();
48 return ndk::ScopedAStatus::ok();
49 }
50
getBluetooth(std::shared_ptr<IBluetooth> * _aidl_return)51 ndk::ScopedAStatus ModuleMock::getBluetooth(std::shared_ptr<IBluetooth>* _aidl_return) {
52 *_aidl_return = ndk::SharedRefBase::make<BluetoothMock>();
53 return ndk::ScopedAStatus::ok();
54 }
55
getBluetoothA2dp(std::shared_ptr<IBluetoothA2dp> * _aidl_return)56 ndk::ScopedAStatus ModuleMock::getBluetoothA2dp(std::shared_ptr<IBluetoothA2dp>* _aidl_return) {
57 *_aidl_return = ndk::SharedRefBase::make<BluetoothA2dpMock>();
58 return ndk::ScopedAStatus::ok();
59 }
60
getBluetoothLe(std::shared_ptr<IBluetoothLe> * _aidl_return)61 ndk::ScopedAStatus ModuleMock::getBluetoothLe(std::shared_ptr<IBluetoothLe>* _aidl_return) {
62 *_aidl_return = ndk::SharedRefBase::make<BluetoothLeMock>();
63 return ndk::ScopedAStatus::ok();
64 }
65
openInputStream(const OpenInputStreamArguments &,OpenInputStreamReturn * _aidl_return)66 ndk::ScopedAStatus ModuleMock::openInputStream(const OpenInputStreamArguments&,
67 OpenInputStreamReturn* _aidl_return) {
68 _aidl_return->stream = ndk::SharedRefBase::make<StreamInMock>();
69 return ndk::ScopedAStatus::ok();
70 }
71
openOutputStream(const OpenOutputStreamArguments &,OpenOutputStreamReturn * _aidl_return)72 ndk::ScopedAStatus ModuleMock::openOutputStream(const OpenOutputStreamArguments&,
73 OpenOutputStreamReturn* _aidl_return) {
74 _aidl_return->stream = ndk::SharedRefBase::make<StreamOutMock>();
75 return ndk::ScopedAStatus::ok();
76 }
77
getMasterMute(bool * _aidl_return)78 ndk::ScopedAStatus ModuleMock::getMasterMute(bool* _aidl_return) {
79 *_aidl_return = mMasterMute;
80 return ndk::ScopedAStatus::ok();
81 }
82
setMasterMute(bool masterMute)83 ndk::ScopedAStatus ModuleMock::setMasterMute(bool masterMute) {
84 mMasterMute = masterMute;
85 return ndk::ScopedAStatus::ok();
86 }
87
getMasterVolume(float * _aidl_return)88 ndk::ScopedAStatus ModuleMock::getMasterVolume(float* _aidl_return) {
89 *_aidl_return = mMasterVolume;
90 return ndk::ScopedAStatus::ok();
91 }
92
setMasterVolume(float masterVolume)93 ndk::ScopedAStatus ModuleMock::setMasterVolume(float masterVolume) {
94 mMasterVolume = masterVolume;
95 return ndk::ScopedAStatus::ok();
96 }
97
getMicMute(bool * _aidl_return)98 ndk::ScopedAStatus ModuleMock::getMicMute(bool* _aidl_return) {
99 *_aidl_return = mMicMute;
100 return ndk::ScopedAStatus::ok();
101 }
102
setMicMute(bool micMute)103 ndk::ScopedAStatus ModuleMock::setMicMute(bool micMute) {
104 mMicMute = micMute;
105 return ndk::ScopedAStatus::ok();
106 }
107
getSoundDose(std::shared_ptr<ISoundDose> * _aidl_return)108 ndk::ScopedAStatus ModuleMock::getSoundDose(std::shared_ptr<ISoundDose>* _aidl_return) {
109 *_aidl_return = ndk::SharedRefBase::make<SoundDoseMock>();
110 return ndk::ScopedAStatus::ok();
111 }
112
getMmapPolicyInfos(AudioMMapPolicyType,std::vector<AudioMMapPolicyInfo> * _aidl_return)113 ndk::ScopedAStatus ModuleMock::getMmapPolicyInfos(AudioMMapPolicyType,
114 std::vector<AudioMMapPolicyInfo>* _aidl_return) {
115 AudioMMapPolicyInfo never;
116 never.mmapPolicy = AudioMMapPolicy::NEVER;
117 _aidl_return->push_back(never);
118 return ndk::ScopedAStatus::ok();
119 }
120
supportsVariableLatency(bool * _aidl_return)121 ndk::ScopedAStatus ModuleMock::supportsVariableLatency(bool* _aidl_return) {
122 *_aidl_return = false;
123 return ndk::ScopedAStatus::ok();
124 }
125
createDeviceExt(AudioDeviceType devType,int32_t flags)126 AudioPortExt ModuleMock::createDeviceExt(AudioDeviceType devType, int32_t flags) {
127 AudioPortDeviceExt deviceExt;
128 deviceExt.device.type.type = devType;
129 deviceExt.flags = flags;
130 return AudioPortExt::make<AudioPortExt::Tag::device>(deviceExt);
131 }
132
createPort(int32_t id,const std::string & name,int32_t flags,bool isInput,const AudioPortExt & ext)133 AudioPort ModuleMock::createPort(int32_t id, const std::string& name, int32_t flags, bool isInput,
134 const AudioPortExt& ext) {
135 AudioPort port;
136 port.id = id;
137 port.name = name;
138 port.flags = isInput ? AudioIoFlags::make<AudioIoFlags::Tag::input>(flags)
139 : AudioIoFlags::make<AudioIoFlags::Tag::output>(flags);
140 port.ext = ext;
141 return port;
142 }
143
144 } // namespace aidl::android::hardware::audio::core
145