1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "audio_manager_proxy.h"
17 #include "audio_system_manager.h"
18 #include "audio_log.h"
19 #include "i_audio_process.h"
20
21 using namespace std;
22
23 namespace OHOS {
24 namespace AudioStandard {
AudioManagerProxy(const sptr<IRemoteObject> & impl)25 AudioManagerProxy::AudioManagerProxy(const sptr<IRemoteObject> &impl)
26 : IRemoteProxy<IStandardAudioService>(impl)
27 {
28 }
29
SetMicrophoneMute(bool isMute)30 int32_t AudioManagerProxy::SetMicrophoneMute(bool isMute)
31 {
32 MessageParcel data;
33 MessageParcel reply;
34 MessageOption option;
35
36 if (!data.WriteInterfaceToken(GetDescriptor())) {
37 AUDIO_ERR_LOG("AudioManagerProxy: WriteInterfaceToken failed");
38 return -1;
39 }
40 data.WriteBool(isMute);
41 int32_t error = Remote()->SendRequest(
42 static_cast<uint32_t>(AudioServerInterfaceCode::SET_MICROPHONE_MUTE), data, reply, option);
43 if (error != ERR_NONE) {
44 AUDIO_ERR_LOG("SetMicrophoneMute failed, error: %d", error);
45 return error;
46 }
47
48 int32_t result = reply.ReadInt32();
49 return result;
50 }
51
IsMicrophoneMute()52 bool AudioManagerProxy::IsMicrophoneMute()
53 {
54 MessageParcel data;
55 MessageParcel reply;
56 MessageOption option;
57 if (!data.WriteInterfaceToken(GetDescriptor())) {
58 AUDIO_ERR_LOG("AudioManagerProxy: WriteInterfaceToken failed");
59 return false;
60 }
61 int32_t error = Remote()->SendRequest(
62 static_cast<uint32_t>(AudioServerInterfaceCode::IS_MICROPHONE_MUTE), data, reply, option);
63 if (error != ERR_NONE) {
64 AUDIO_ERR_LOG("IsMicrophoneMute failed, error: %d", error);
65 return false;
66 }
67
68 bool isMute = reply.ReadBool();
69 return isMute;
70 }
71
SetVoiceVolume(float volume)72 int32_t AudioManagerProxy::SetVoiceVolume(float volume)
73 {
74 MessageParcel data;
75 MessageParcel reply;
76 MessageOption option;
77
78 if (!data.WriteInterfaceToken(GetDescriptor())) {
79 AUDIO_ERR_LOG("AudioManagerProxy: WriteInterfaceToken failed");
80 return -1;
81 }
82
83 data.WriteFloat(volume);
84
85 int32_t error = Remote()->SendRequest(
86 static_cast<uint32_t>(AudioServerInterfaceCode::SET_VOICE_VOLUME), data, reply, option);
87 if (error != ERR_NONE) {
88 AUDIO_ERR_LOG("SetVoiceVolume failed, error: %d", error);
89 return false;
90 }
91
92 int32_t result = reply.ReadInt32();
93 return result;
94 }
95
SetAudioScene(AudioScene audioScene,DeviceType activeDevice)96 int32_t AudioManagerProxy::SetAudioScene(AudioScene audioScene, DeviceType activeDevice)
97 {
98 MessageParcel data;
99 MessageParcel reply;
100 MessageOption option;
101
102 if (!data.WriteInterfaceToken(GetDescriptor())) {
103 AUDIO_ERR_LOG("AudioManagerProxy: WriteInterfaceToken failed");
104 return -1;
105 }
106
107 data.WriteInt32(static_cast<int32_t>(audioScene));
108 data.WriteInt32(static_cast<int32_t>(activeDevice));
109
110 int32_t error = Remote()->SendRequest(
111 static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_SCENE), data, reply, option);
112 if (error != ERR_NONE) {
113 AUDIO_ERR_LOG("SetAudioScene failed, error: %d", error);
114 return false;
115 }
116
117 int32_t result = reply.ReadInt32();
118 return result;
119 }
120
GetDevices(DeviceFlag deviceFlag)121 std::vector<sptr<AudioDeviceDescriptor>> AudioManagerProxy::GetDevices(DeviceFlag deviceFlag)
122 {
123 MessageParcel data;
124 MessageParcel reply;
125 MessageOption option;
126 std::vector<sptr<AudioDeviceDescriptor>> deviceInfo;
127
128 if (!data.WriteInterfaceToken(GetDescriptor())) {
129 AUDIO_ERR_LOG("AudioManagerProxy: WriteInterfaceToken failed");
130 return deviceInfo;
131 }
132 data.WriteInt32(static_cast<int32_t>(deviceFlag));
133
134 int32_t error = Remote()->SendRequest(
135 static_cast<uint32_t>(AudioServerInterfaceCode::GET_DEVICES), data, reply, option);
136 if (error != ERR_NONE) {
137 AUDIO_ERR_LOG("Get devices failed, error: %d", error);
138 return deviceInfo;
139 }
140
141 int32_t size = reply.ReadInt32();
142 for (int32_t i = 0; i < size; i++) {
143 deviceInfo.push_back(AudioDeviceDescriptor::Unmarshalling(reply));
144 }
145
146 return deviceInfo;
147 }
148
GetAudioParameter(const std::string & key)149 const std::string AudioManagerProxy::GetAudioParameter(const std::string &key)
150 {
151 MessageParcel data;
152 MessageParcel reply;
153 MessageOption option;
154
155 if (!data.WriteInterfaceToken(GetDescriptor())) {
156 AUDIO_ERR_LOG("AudioManagerProxy: WriteInterfaceToken failed");
157 return "";
158 }
159 data.WriteString(static_cast<std::string>(key));
160 int32_t error = Remote()->SendRequest(
161 static_cast<uint32_t>(AudioServerInterfaceCode::GET_AUDIO_PARAMETER), data, reply, option);
162 if (error != ERR_NONE) {
163 AUDIO_ERR_LOG("Get audio parameter failed, error: %d", error);
164 const std::string value = "";
165 return value;
166 }
167
168 const std::string value = reply.ReadString();
169 return value;
170 }
171
GetAudioParameter(const std::string & networkId,const AudioParamKey key,const std::string & condition)172 const std::string AudioManagerProxy::GetAudioParameter(const std::string& networkId, const AudioParamKey key,
173 const std::string& condition)
174 {
175 MessageParcel data;
176 MessageParcel reply;
177 MessageOption option;
178
179 if (!data.WriteInterfaceToken(GetDescriptor())) {
180 AUDIO_ERR_LOG("AudioManagerProxy: WriteInterfaceToken failed");
181 return "";
182 }
183 data.WriteString(static_cast<std::string>(networkId));
184 data.WriteInt32(static_cast<int32_t>(key));
185 data.WriteString(static_cast<std::string>(condition));
186 int32_t error = Remote()->SendRequest(
187 static_cast<uint32_t>(AudioServerInterfaceCode::GET_REMOTE_AUDIO_PARAMETER), data, reply, option);
188 if (error != ERR_NONE) {
189 AUDIO_ERR_LOG("Get audio parameter failed, error: %d", error);
190 const std::string value = "";
191 return value;
192 }
193
194 const std::string value = reply.ReadString();
195 return value;
196 }
197
SetAudioParameter(const std::string & key,const std::string & value)198 void AudioManagerProxy::SetAudioParameter(const std::string &key, const std::string &value)
199 {
200 MessageParcel data;
201 MessageParcel reply;
202 MessageOption option;
203
204 if (!data.WriteInterfaceToken(GetDescriptor())) {
205 AUDIO_ERR_LOG("AudioManagerProxy: WriteInterfaceToken failed");
206 return;
207 }
208 data.WriteString(static_cast<std::string>(key));
209 data.WriteString(static_cast<std::string>(value));
210 int32_t error = Remote()->SendRequest(
211 static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_PARAMETER), data, reply, option);
212 if (error != ERR_NONE) {
213 AUDIO_ERR_LOG("Get audio parameter failed, error: %d", error);
214 return;
215 }
216 }
217
SetAudioParameter(const std::string & networkId,const AudioParamKey key,const std::string & condition,const std::string & value)218 void AudioManagerProxy::SetAudioParameter(const std::string& networkId, const AudioParamKey key,
219 const std::string& condition, const std::string& value)
220 {
221 MessageParcel data;
222 MessageParcel reply;
223 MessageOption option;
224
225 if (!data.WriteInterfaceToken(GetDescriptor())) {
226 AUDIO_ERR_LOG("AudioManagerProxy: WriteInterfaceToken failed");
227 return;
228 }
229 data.WriteString(static_cast<std::string>(networkId));
230 data.WriteInt32(static_cast<int32_t>(key));
231 data.WriteString(static_cast<std::string>(condition));
232 data.WriteString(static_cast<std::string>(value));
233 int32_t error = Remote()->SendRequest(
234 static_cast<uint32_t>(AudioServerInterfaceCode::SET_REMOTE_AUDIO_PARAMETER), data, reply, option);
235 if (error != ERR_NONE) {
236 AUDIO_ERR_LOG("Get audio parameter failed, error: %d", error);
237 return;
238 }
239 }
240
RetrieveCookie(int32_t & size)241 const char *AudioManagerProxy::RetrieveCookie(int32_t &size)
242 {
243 MessageParcel data;
244 MessageParcel reply;
245 MessageOption option;
246 const char *cookieInfo = nullptr;
247
248 if (!data.WriteInterfaceToken(GetDescriptor())) {
249 AUDIO_ERR_LOG("AudioManagerProxy: WriteInterfaceToken failed");
250 return nullptr;
251 }
252
253 int32_t error = Remote()->SendRequest(
254 static_cast<uint32_t>(AudioServerInterfaceCode::RETRIEVE_COOKIE), data, reply, option);
255 if (error != ERR_NONE) {
256 AUDIO_ERR_LOG("retrieve cookie failed, error: %d", error);
257 return nullptr;
258 }
259
260 size = reply.ReadInt32();
261 if (size > 0) {
262 cookieInfo = reinterpret_cast<const char *>(reply.ReadRawData(size));
263 }
264
265 return cookieInfo;
266 }
267
GetTransactionId(DeviceType deviceType,DeviceRole deviceRole)268 uint64_t AudioManagerProxy::GetTransactionId(DeviceType deviceType, DeviceRole deviceRole)
269 {
270 MessageParcel data;
271 MessageParcel reply;
272 MessageOption option;
273 uint32_t transactionId = 0;
274
275 if (!data.WriteInterfaceToken(GetDescriptor())) {
276 AUDIO_ERR_LOG("AudioManagerProxy: WriteInterfaceToken failed");
277 return transactionId;
278 }
279
280 data.WriteInt32(static_cast<int32_t>(deviceType));
281 data.WriteInt32(static_cast<int32_t>(deviceRole));
282
283 int32_t error = Remote()->SendRequest(
284 static_cast<uint32_t>(AudioServerInterfaceCode::GET_TRANSACTION_ID), data, reply, option);
285 if (error != ERR_NONE) {
286 AUDIO_ERR_LOG("get transaction id failed, error: %d", error);
287 return transactionId;
288 }
289
290 transactionId = reply.ReadUint64();
291
292 return transactionId;
293 }
294
NotifyDeviceInfo(std::string networkId,bool connected)295 void AudioManagerProxy::NotifyDeviceInfo(std::string networkId, bool connected)
296 {
297 MessageParcel data;
298 MessageParcel reply;
299 MessageOption option;
300
301 if (!data.WriteInterfaceToken(GetDescriptor())) {
302 AUDIO_ERR_LOG("AudioManagerProxy: WriteInterfaceToken failed");
303 return;
304 }
305 data.WriteString(networkId);
306 data.WriteBool(connected);
307 int32_t error = Remote()->SendRequest(
308 static_cast<uint32_t>(AudioServerInterfaceCode::NOTIFY_DEVICE_INFO), data, reply, option);
309 if (error != ERR_NONE) {
310 AUDIO_ERR_LOG("Get audio parameter failed, error: %d", error);
311 return;
312 }
313 }
314
CheckRemoteDeviceState(std::string networkId,DeviceRole deviceRole,bool isStartDevice)315 int32_t AudioManagerProxy::CheckRemoteDeviceState(std::string networkId, DeviceRole deviceRole, bool isStartDevice)
316 {
317 MessageParcel data;
318 MessageParcel reply;
319 MessageOption option;
320
321 if (!data.WriteInterfaceToken(GetDescriptor())) {
322 AUDIO_ERR_LOG("AudioManagerProxy: WriteInterfaceToken failed");
323 return ERR_TRANSACTION_FAILED;
324 }
325 data.WriteString(networkId);
326 data.WriteInt32(static_cast<int32_t>(deviceRole));
327 data.WriteBool(isStartDevice);
328 int32_t error = Remote()->SendRequest(
329 static_cast<uint32_t>(AudioServerInterfaceCode::CHECK_REMOTE_DEVICE_STATE), data, reply, option);
330 if (error != ERR_NONE) {
331 AUDIO_ERR_LOG("CheckRemoteDeviceState failed in proxy, error: %d", error);
332 return error;
333 }
334 return reply.ReadInt32();
335 }
336
UpdateActiveDeviceRoute(DeviceType type,DeviceFlag flag)337 int32_t AudioManagerProxy::UpdateActiveDeviceRoute(DeviceType type, DeviceFlag flag)
338 {
339 AUDIO_DEBUG_LOG("[%{public}s]", __func__);
340 MessageParcel data;
341 MessageParcel reply;
342 MessageOption option;
343
344 if (!data.WriteInterfaceToken(GetDescriptor())) {
345 AUDIO_ERR_LOG("AudioManagerProxy: WriteInterfaceToken failed");
346 return -1;
347 }
348 data.WriteInt32(type);
349 data.WriteInt32(flag);
350
351 auto error = Remote()->SendRequest(
352 static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_ROUTE_REQ), data, reply, option);
353 if (error != ERR_NONE) {
354 AUDIO_ERR_LOG("UpdateActiveDeviceRoute failed, error: %{public}d", error);
355 return false;
356 }
357
358 auto result = reply.ReadInt32();
359 AUDIO_DEBUG_LOG("[UPDATE_ROUTE_REQ] result %{public}d", result);
360 return result;
361 }
362
SetParameterCallback(const sptr<IRemoteObject> & object)363 int32_t AudioManagerProxy::SetParameterCallback(const sptr<IRemoteObject>& object)
364 {
365 MessageParcel data;
366 MessageParcel reply;
367 MessageOption option;
368
369 if (object == nullptr) {
370 AUDIO_ERR_LOG("AudioManagerProxy: SetParameterCallback object is null");
371 return ERR_NULL_OBJECT;
372 }
373 if (!data.WriteInterfaceToken(GetDescriptor())) {
374 AUDIO_ERR_LOG("WriteInterfaceToken failed");
375 return -1;
376 }
377
378 (void)data.WriteRemoteObject(object);
379 int error = Remote()->SendRequest(
380 static_cast<uint32_t>(AudioServerInterfaceCode::SET_PARAMETER_CALLBACK), data, reply, option);
381 if (error != ERR_NONE) {
382 AUDIO_ERR_LOG("SetParameterCallback failed, error: %{public}d", error);
383 return error;
384 }
385
386 return reply.ReadInt32();
387 }
388
RegiestPolicyProvider(const sptr<IRemoteObject> & object)389 int32_t AudioManagerProxy::RegiestPolicyProvider(const sptr<IRemoteObject> &object)
390 {
391 MessageParcel data;
392 MessageParcel reply;
393 MessageOption option(MessageOption::TF_ASYNC);
394
395 if (object == nullptr) {
396 AUDIO_ERR_LOG("AudioManagerProxy: RegiestPolicyProvider object is null");
397 return ERR_NULL_OBJECT;
398 }
399 if (!data.WriteInterfaceToken(GetDescriptor())) {
400 AUDIO_ERR_LOG("WriteInterfaceToken failed");
401 return -1;
402 }
403
404 (void)data.WriteRemoteObject(object);
405 int error = Remote()->SendRequest(static_cast<uint32_t>(AudioServerInterfaceCode::REGISET_POLICY_PROVIDER), data,
406 reply, option);
407 if (error != ERR_NONE) {
408 AUDIO_ERR_LOG("RegiestPolicyProvider failed, error: %{public}d", error);
409 return error;
410 }
411
412 return reply.ReadInt32();
413 }
414
SetWakeupSourceCallback(const sptr<IRemoteObject> & object)415 int32_t AudioManagerProxy::SetWakeupSourceCallback(const sptr<IRemoteObject>& object)
416 {
417 MessageParcel data;
418 MessageParcel reply;
419 MessageOption option;
420
421 if (object == nullptr) {
422 AUDIO_ERR_LOG("SetWakeupCloseCallback object is null");
423 return ERR_NULL_OBJECT;
424 }
425 if (!data.WriteInterfaceToken(GetDescriptor())) {
426 AUDIO_ERR_LOG("WriteInterfaceToken failed");
427 return -1;
428 }
429
430 (void)data.WriteRemoteObject(object);
431 int error = Remote()->SendRequest(
432 static_cast<uint32_t>(AudioServerInterfaceCode::SET_WAKEUP_CLOSE_CALLBACK), data, reply, option);
433 if (error != ERR_NONE) {
434 AUDIO_ERR_LOG("SetWakeupCloseCallback failed, error: %{public}d", error);
435 return error;
436 }
437
438 return reply.ReadInt32();
439 }
440
SetAudioMonoState(bool audioMono)441 void AudioManagerProxy::SetAudioMonoState(bool audioMono)
442 {
443 MessageParcel data;
444 MessageParcel reply;
445 MessageOption option;
446
447 if (!data.WriteInterfaceToken(GetDescriptor())) {
448 AUDIO_ERR_LOG("WriteInterfaceToken failed");
449 return;
450 }
451 (void)data.WriteBool(audioMono);
452 int error = Remote()->SendRequest(
453 static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_MONO_STATE), data, reply, option);
454 if (error != ERR_NONE) {
455 AUDIO_ERR_LOG("SetAudioMonoState failed, error: %{public}d", error);
456 return;
457 }
458 }
459
SetAudioBalanceValue(float audioBalance)460 void AudioManagerProxy::SetAudioBalanceValue(float audioBalance)
461 {
462 MessageParcel data;
463 MessageParcel reply;
464 MessageOption option;
465
466 if (!data.WriteInterfaceToken(GetDescriptor())) {
467 AUDIO_ERR_LOG("WriteInterfaceToken failed");
468 return;
469 }
470 (void)data.WriteFloat(audioBalance);
471 int error = Remote()->SendRequest(
472 static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_BALANCE_VALUE), data, reply, option);
473 if (error != ERR_NONE) {
474 AUDIO_ERR_LOG("SetAudioBalanceValue failed, error: %{public}d", error);
475 return;
476 }
477 }
478
CreateAudioProcess(const AudioProcessConfig & config)479 sptr<IRemoteObject> AudioManagerProxy::CreateAudioProcess(const AudioProcessConfig &config)
480 {
481 MessageParcel data;
482 MessageParcel reply;
483 MessageOption option;
484
485 if (!data.WriteInterfaceToken(GetDescriptor())) {
486 AUDIO_ERR_LOG("WriteInterfaceToken failed");
487 return nullptr;
488 }
489 ProcessConfig::WriteConfigToParcel(config, data);
490 int error = Remote()->SendRequest(
491 static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_AUDIOPROCESS), data, reply, option);
492 if (error != ERR_NONE) {
493 AUDIO_ERR_LOG("CreateAudioProcess failed, error: %{public}d", error);
494 return nullptr;
495 }
496 sptr<IRemoteObject> process = reply.ReadRemoteObject();
497 return process;
498 }
499
LoadAudioEffectLibraries(const vector<Library> libraries,const vector<Effect> effects,vector<Effect> & successEffects)500 bool AudioManagerProxy::LoadAudioEffectLibraries(const vector<Library> libraries, const vector<Effect> effects,
501 vector<Effect> &successEffects)
502 {
503 int32_t error, i;
504
505 MessageParcel dataParcel, replyParcel;
506 MessageOption option;
507 if (!dataParcel.WriteInterfaceToken(GetDescriptor())) {
508 AUDIO_ERR_LOG("AudioManagerProxy: WriteInterfaceToken failed");
509 return false;
510 }
511
512 int32_t countLib = libraries.size();
513 int32_t countEff = effects.size();
514
515 dataParcel.WriteInt32(countLib);
516 dataParcel.WriteInt32(countEff);
517
518 for (Library x : libraries) {
519 dataParcel.WriteString(x.name);
520 dataParcel.WriteString(x.path);
521 }
522
523 for (Effect x : effects) {
524 dataParcel.WriteString(x.name);
525 dataParcel.WriteString(x.libraryName);
526 }
527
528 error = Remote()->SendRequest(
529 static_cast<uint32_t>(AudioServerInterfaceCode::LOAD_AUDIO_EFFECT_LIBRARIES), dataParcel, replyParcel, option);
530 if (error != ERR_NONE) {
531 AUDIO_ERR_LOG("LoadAudioEffectLibraries failed, error: %{public}d", error);
532 return false;
533 }
534
535 int32_t successEffSize = replyParcel.ReadInt32();
536 if ((successEffSize < 0) || (successEffSize > AUDIO_EFFECT_COUNT_UPPER_LIMIT)) {
537 AUDIO_ERR_LOG("LOAD_AUDIO_EFFECT_LIBRARIES read replyParcel failed");
538 return false;
539 }
540
541 for (i = 0; i < successEffSize; i++) {
542 string effectName = replyParcel.ReadString();
543 string libName = replyParcel.ReadString();
544 successEffects.push_back({effectName, libName});
545 }
546
547 return true;
548 }
549
RequestThreadPriority(uint32_t tid,string bundleName)550 void AudioManagerProxy::RequestThreadPriority(uint32_t tid, string bundleName)
551 {
552 MessageParcel data;
553 MessageParcel reply;
554 MessageOption option;
555
556 if (!data.WriteInterfaceToken(GetDescriptor())) {
557 AUDIO_ERR_LOG("WriteInterfaceToken failed");
558 return;
559 }
560 (void)data.WriteUint32(tid);
561 (void)data.WriteString(bundleName);
562 int error = Remote()->SendRequest(
563 static_cast<uint32_t>(AudioServerInterfaceCode::REQUEST_THREAD_PRIORITY), data, reply, option);
564 if (error != ERR_NONE) {
565 AUDIO_ERR_LOG("RequestThreadPriority failed, error: %{public}d", error);
566 return;
567 }
568 }
569
CreateEffectChainManager(std::vector<EffectChain> & effectChains,std::unordered_map<std::string,std::string> & map)570 bool AudioManagerProxy::CreateEffectChainManager(std::vector<EffectChain> &effectChains,
571 std::unordered_map<std::string, std::string> &map)
572 {
573 int32_t error;
574
575 MessageParcel dataParcel, replyParcel;
576 MessageOption option;
577 if (!dataParcel.WriteInterfaceToken(GetDescriptor())) {
578 AUDIO_ERR_LOG("AudioManagerProxy: WriteInterfaceToken failed");
579 return false;
580 }
581
582 int32_t countEffectChains = effectChains.size();
583 std::vector<int32_t> listCountEffects;
584
585 for (EffectChain &effectChain: effectChains) {
586 listCountEffects.emplace_back(effectChain.apply.size());
587 }
588
589 dataParcel.WriteInt32(countEffectChains);
590 for (int32_t countEffects: listCountEffects) {
591 dataParcel.WriteInt32(countEffects);
592 }
593
594 for (EffectChain &effectChain: effectChains) {
595 dataParcel.WriteString(effectChain.name);
596 for (std::string applyName: effectChain.apply) {
597 dataParcel.WriteString(applyName);
598 }
599 }
600
601 dataParcel.WriteInt32(map.size());
602 for (auto item = map.begin(); item != map.end(); ++item) {
603 dataParcel.WriteString(item->first);
604 dataParcel.WriteString(item->second);
605 }
606
607 error = Remote()->SendRequest(
608 static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_AUDIO_EFFECT_CHAIN_MANAGER),
609 dataParcel, replyParcel, option);
610 if (error != ERR_NONE) {
611 AUDIO_ERR_LOG("CreateAudioEffectChainManager failed, error: %{public}d", error);
612 return false;
613 }
614 return true;
615 }
616
SetOutputDeviceSink(int32_t deviceType,std::string & sinkName)617 bool AudioManagerProxy::SetOutputDeviceSink(int32_t deviceType, std::string &sinkName)
618 {
619 int32_t error;
620
621 MessageParcel dataParcel, replyParcel;
622 MessageOption option;
623 if (!dataParcel.WriteInterfaceToken(GetDescriptor())) {
624 AUDIO_ERR_LOG("AudioManagerProxy: WriteInterfaceToken failed");
625 return false;
626 }
627 dataParcel.WriteInt32(deviceType);
628 dataParcel.WriteString(sinkName);
629
630 error = Remote()->SendRequest(
631 static_cast<uint32_t>(AudioServerInterfaceCode::SET_OUTPUT_DEVICE_SINK), dataParcel, replyParcel, option);
632 if (error != ERR_NONE) {
633 AUDIO_ERR_LOG("SetOutputDeviceSink failed, error: %{public}d", error);
634 return false;
635 }
636 return true;
637 }
638
CreatePlaybackCapturerManager()639 bool AudioManagerProxy::CreatePlaybackCapturerManager()
640 {
641 int32_t error;
642 MessageParcel data;
643 MessageParcel reply;
644 MessageOption option;
645 if (!data.WriteInterfaceToken(GetDescriptor())) {
646 AUDIO_ERR_LOG("CreatePlaybackCapturerManager: WriteInterfaceToken failed");
647 return false;
648 }
649
650 error = Remote()->SendRequest(
651 static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_PLAYBACK_CAPTURER_MANAGER), data, reply, option);
652 if (error != ERR_NONE) {
653 AUDIO_ERR_LOG("CreatePlaybackCapturerManager failed, error: %{public}d", error);
654 return false;
655 }
656
657 return reply.ReadBool();
658 }
659
SetSupportStreamUsage(std::vector<int32_t> usage)660 int32_t AudioManagerProxy::SetSupportStreamUsage(std::vector<int32_t> usage)
661 {
662 int32_t error;
663 MessageParcel data;
664 MessageParcel reply;
665 MessageOption option;
666
667 if (!data.WriteInterfaceToken(GetDescriptor())) {
668 AUDIO_ERR_LOG("SetSupportStreamUsage: WriteInterfaceToken failed");
669 return -1;
670 }
671
672 int32_t cnt = (int32_t)usage.size();
673 data.WriteInt32(cnt);
674 for (int32_t i = 0; i < cnt; i++) {
675 data.WriteInt32(usage[i]);
676 }
677
678 error = Remote()->SendRequest(
679 static_cast<uint32_t>(AudioServerInterfaceCode::SET_SUPPORT_STREAM_USAGE), data, reply, option);
680 if (error != ERR_NONE) {
681 AUDIO_ERR_LOG("SetSupportStreamUsage failed, error: %{public}d", error);
682 return error;
683 }
684
685 return reply.ReadInt32();
686 }
687
SetCaptureSilentState(bool state)688 int32_t AudioManagerProxy::SetCaptureSilentState(bool state)
689 {
690 int32_t error;
691 MessageParcel data;
692 MessageParcel reply;
693 MessageOption option;
694
695 if (!data.WriteInterfaceToken(GetDescriptor())) {
696 AUDIO_ERR_LOG("SetCaptureSilentState: WriteInterfaceToken failed");
697 return -1;
698 }
699
700 data.WriteInt32(static_cast<int32_t>(state));
701 error = Remote()->SendRequest(static_cast<uint32_t>(AudioServerInterfaceCode::SET_CAPTURE_SILENT_STATE),
702 data, reply, option);
703 if (error != ERR_NONE) {
704 AUDIO_ERR_LOG("SetCaptureSilentState failed, error: %{public}d", error);
705 return error;
706 }
707 return reply.ReadInt32();
708 }
709
710 } // namespace AudioStandard
711 } // namespace OHOS
712