1 /*
2 * Copyright (c) 2021-2025 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 #ifndef LOG_TAG
16 #define LOG_TAG "AudioManagerProxy"
17 #endif
18
19 #include "audio_manager_proxy.h"
20
21 #include <cinttypes>
22
23 #include <audio_errors.h>
24 #include "audio_system_manager.h"
25 #include "audio_service_log.h"
26 #include "audio_utils.h"
27 #include "i_audio_process.h"
28
29 using namespace std;
30
31 namespace OHOS {
32 namespace AudioStandard {
33 namespace {
34 constexpr int32_t MAX_OFFLINE_EFFECT_CHAIN_NUM = 10;
35 const size_t DEFAULT_MAX_RENDERER_INSTANCES = 1000;
36 }
AudioManagerProxy(const sptr<IRemoteObject> & impl)37 AudioManagerProxy::AudioManagerProxy(const sptr<IRemoteObject> &impl)
38 : IRemoteProxy<IStandardAudioService>(impl)
39 {
40 }
41
SetMicrophoneMute(bool isMute)42 int32_t AudioManagerProxy::SetMicrophoneMute(bool isMute)
43 {
44 MessageParcel data;
45 MessageParcel reply;
46 MessageOption option;
47
48 bool ret = data.WriteInterfaceToken(GetDescriptor());
49 CHECK_AND_RETURN_RET_LOG(ret, -1, "AudioManagerProxy: WriteInterfaceToken failed");
50 data.WriteBool(isMute);
51 int32_t error = Remote()->SendRequest(
52 static_cast<uint32_t>(AudioServerInterfaceCode::SET_MICROPHONE_MUTE), data, reply, option);
53 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
54 "SetMicrophoneMute failed, error: %d", error);
55
56 int32_t result = reply.ReadInt32();
57 return result;
58 }
59
SetVoiceVolume(float volume)60 int32_t AudioManagerProxy::SetVoiceVolume(float volume)
61 {
62 MessageParcel data;
63 MessageParcel reply;
64 MessageOption option;
65
66 bool ret = data.WriteInterfaceToken(GetDescriptor());
67 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
68
69 data.WriteFloat(volume);
70
71 int32_t error = Remote()->SendRequest(
72 static_cast<uint32_t>(AudioServerInterfaceCode::SET_VOICE_VOLUME), data, reply, option);
73 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false,
74 "SetVoiceVolume failed, error: %d", error);
75
76 int32_t result = reply.ReadInt32();
77 return result;
78 }
79
OffloadSetVolume(float volume)80 int32_t AudioManagerProxy::OffloadSetVolume(float volume)
81 {
82 MessageParcel data;
83 MessageParcel reply;
84 MessageOption option;
85
86 bool ret = data.WriteInterfaceToken(GetDescriptor());
87 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
88
89 data.WriteFloat(volume);
90
91 int32_t error = Remote()->SendRequest(
92 static_cast<uint32_t>(AudioServerInterfaceCode::OFFLOAD_SET_VOLUME), data, reply, option);
93 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "OffloadSetVolume failed, error: %d", error);
94
95 int32_t result = reply.ReadInt32();
96 return result;
97 }
98
SetAudioScene(AudioScene audioScene,std::vector<DeviceType> & activeOutputDevices,DeviceType activeInputDevice,BluetoothOffloadState a2dpOffloadFlag)99 int32_t AudioManagerProxy::SetAudioScene(AudioScene audioScene, std::vector<DeviceType> &activeOutputDevices,
100 DeviceType activeInputDevice, BluetoothOffloadState a2dpOffloadFlag)
101 {
102 CHECK_AND_RETURN_RET_LOG(!activeOutputDevices.empty() &&
103 activeOutputDevices.size() <= AUDIO_CONCURRENT_ACTIVE_DEVICES_LIMIT,
104 ERR_NONE, "Invalid active output devices.");
105 MessageParcel data;
106 MessageParcel reply;
107 MessageOption option;
108
109 bool ret = data.WriteInterfaceToken(GetDescriptor());
110 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
111
112 data.WriteInt32(static_cast<int32_t>(audioScene));
113
114 data.WriteInt32(static_cast<int32_t>(activeOutputDevices.size()));
115 for (auto activeOutputDevice : activeOutputDevices) {
116 data.WriteInt32(static_cast<int32_t>(activeOutputDevice));
117 }
118 data.WriteInt32(static_cast<int32_t>(activeInputDevice));
119 data.WriteInt32(static_cast<int32_t>(a2dpOffloadFlag));
120
121 int32_t error = Remote()->SendRequest(
122 static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_SCENE), data, reply, option);
123 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "SetAudioScene failed, error: %d", error);
124
125 int32_t result = reply.ReadInt32();
126 return result;
127 }
128
GetAudioParameter(const std::string & key)129 const std::string AudioManagerProxy::GetAudioParameter(const std::string &key)
130 {
131 MessageParcel data;
132 MessageParcel reply;
133 MessageOption option;
134
135 bool ret = data.WriteInterfaceToken(GetDescriptor());
136 CHECK_AND_RETURN_RET_LOG(ret, "", "WriteInterfaceToken failed");
137 data.WriteString(static_cast<std::string>(key));
138 int32_t error = Remote()->SendRequest(
139 static_cast<uint32_t>(AudioServerInterfaceCode::GET_AUDIO_PARAMETER), data, reply, option);
140 if (error != ERR_NONE) {
141 AUDIO_ERR_LOG("Get audio parameter failed, error: %d", error);
142 const std::string value = "";
143 return value;
144 }
145
146 const std::string value = reply.ReadString();
147 return value;
148 }
149
GetAudioParameter(const std::string & networkId,const AudioParamKey key,const std::string & condition)150 const std::string AudioManagerProxy::GetAudioParameter(const std::string& networkId, const AudioParamKey key,
151 const std::string& condition)
152 {
153 MessageParcel data;
154 MessageParcel reply;
155 MessageOption option;
156
157 bool ret = data.WriteInterfaceToken(GetDescriptor());
158 CHECK_AND_RETURN_RET_LOG(ret, "", "WriteInterfaceToken failed");
159 data.WriteString(static_cast<std::string>(networkId));
160 data.WriteInt32(static_cast<int32_t>(key));
161 data.WriteString(static_cast<std::string>(condition));
162 int32_t error = Remote()->SendRequest(
163 static_cast<uint32_t>(AudioServerInterfaceCode::GET_REMOTE_AUDIO_PARAMETER), data, reply, option);
164 if (error != ERR_NONE) {
165 AUDIO_ERR_LOG("Get audio parameter failed, error: %d", error);
166 const std::string value = "";
167 return value;
168 }
169
170 const std::string value = reply.ReadString();
171 return value;
172 }
173
GetExtraParameters(const std::string & mainKey,const std::vector<std::string> & subKeys,std::vector<std::pair<std::string,std::string>> & result)174 int32_t AudioManagerProxy::GetExtraParameters(const std::string &mainKey, const std::vector<std::string> &subKeys,
175 std::vector<std::pair<std::string, std::string>> &result)
176 {
177 MessageParcel data;
178 MessageParcel reply;
179 MessageOption option;
180
181 bool ret = data.WriteInterfaceToken(GetDescriptor());
182 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
183 data.WriteString(static_cast<std::string>(mainKey));
184 data.WriteInt32(static_cast<int32_t>(subKeys.size()));
185 for (std::string subKey : subKeys) {
186 data.WriteString(static_cast<std::string>(subKey));
187 }
188 int32_t error = Remote()->SendRequest(
189 static_cast<uint32_t>(AudioServerInterfaceCode::GET_EXTRA_AUDIO_PARAMETERS), data, reply, option);
190 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get extra audio parameters failed, error: %d", error);
191
192 int32_t num = reply.ReadInt32();
193 for (auto i = 0; i < num; i++) {
194 const std::string key = reply.ReadString();
195 const std::string value = reply.ReadString();
196 result.push_back(std::make_pair(key, value));
197 }
198 return reply.ReadInt32();
199 }
200
SetAudioParameter(const std::string & key,const std::string & value)201 void AudioManagerProxy::SetAudioParameter(const std::string &key, const std::string &value)
202 {
203 MessageParcel data;
204 MessageParcel reply;
205 MessageOption option;
206
207 bool ret = data.WriteInterfaceToken(GetDescriptor());
208 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
209 data.WriteString(static_cast<std::string>(key));
210 data.WriteString(static_cast<std::string>(value));
211 int32_t error = Remote()->SendRequest(
212 static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_PARAMETER), data, reply, option);
213 CHECK_AND_RETURN_LOG(error == ERR_NONE, "Get audio parameter failed, error: %d", error);
214 }
215
SetAudioParameter(const std::string & networkId,const AudioParamKey key,const std::string & condition,const std::string & value)216 void AudioManagerProxy::SetAudioParameter(const std::string& networkId, const AudioParamKey key,
217 const std::string& condition, const std::string& value)
218 {
219 MessageParcel data;
220 MessageParcel reply;
221 MessageOption option;
222
223 bool ret = data.WriteInterfaceToken(GetDescriptor());
224 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
225 data.WriteString(static_cast<std::string>(networkId));
226 data.WriteInt32(static_cast<int32_t>(key));
227 data.WriteString(static_cast<std::string>(condition));
228 data.WriteString(static_cast<std::string>(value));
229 int32_t error = Remote()->SendRequest(
230 static_cast<uint32_t>(AudioServerInterfaceCode::SET_REMOTE_AUDIO_PARAMETER), data, reply, option);
231 CHECK_AND_RETURN_LOG(error == ERR_NONE, "Get audio parameter failed, error: %d", error);
232 }
233
SetExtraParameters(const std::string & key,const std::vector<std::pair<std::string,std::string>> & kvpairs)234 int32_t AudioManagerProxy::SetExtraParameters(const std::string &key,
235 const std::vector<std::pair<std::string, std::string>> &kvpairs)
236 {
237 MessageParcel data;
238 MessageParcel reply;
239 MessageOption option;
240
241 bool ret = data.WriteInterfaceToken(GetDescriptor());
242 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
243 data.WriteString(static_cast<std::string>(key));
244 data.WriteInt32(static_cast<int32_t>(kvpairs.size()));
245 for (auto it = kvpairs.begin(); it != kvpairs.end(); it++) {
246 data.WriteString(static_cast<std::string>(it->first));
247 data.WriteString(static_cast<std::string>(it->second));
248 }
249
250 int32_t error = Remote()->SendRequest(
251 static_cast<uint32_t>(AudioServerInterfaceCode::SET_EXTRA_AUDIO_PARAMETERS), data, reply, option);
252 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Set extra audio parameters failed, error: %d", error);
253 return reply.ReadInt32();
254 }
255
SetAsrAecMode(AsrAecMode asrAecMode)256 int32_t AudioManagerProxy::SetAsrAecMode(AsrAecMode asrAecMode)
257 {
258 MessageParcel data;
259 MessageParcel reply;
260 MessageOption option;
261
262 bool ret = data.WriteInterfaceToken(GetDescriptor());
263 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
264 data.WriteInt32(static_cast<int32_t>(asrAecMode));
265
266 int32_t error = Remote()->SendRequest(
267 static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_AEC_MODE), data, reply, option);
268 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, -1, "failed,error:%d", error);
269 int32_t result = reply.ReadInt32();
270 return result;
271 }
272
GetAsrAecMode(AsrAecMode & asrAecMode)273 int32_t AudioManagerProxy::GetAsrAecMode(AsrAecMode &asrAecMode)
274 {
275 MessageParcel data;
276 MessageParcel reply;
277 MessageOption option;
278
279 bool ret = data.WriteInterfaceToken(GetDescriptor());
280 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
281 data.WriteInt32(static_cast<int32_t>(asrAecMode));
282
283 int32_t error = Remote()->SendRequest(
284 static_cast<uint32_t>(AudioServerInterfaceCode::GET_ASR_AEC_MODE), data, reply, option);
285 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, -1, "failed,error:%d", error);
286 int32_t result = reply.ReadInt32();
287 asrAecMode = static_cast<AsrAecMode>(result);
288 return 0;
289 }
290
SetAsrNoiseSuppressionMode(AsrNoiseSuppressionMode asrNoiseSuppressionMode)291 int32_t AudioManagerProxy::SetAsrNoiseSuppressionMode(AsrNoiseSuppressionMode asrNoiseSuppressionMode)
292 {
293 MessageParcel data;
294 MessageParcel reply;
295 MessageOption option;
296
297 bool ret = data.WriteInterfaceToken(GetDescriptor());
298 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
299 data.WriteInt32(static_cast<int32_t>(asrNoiseSuppressionMode));
300
301 int32_t error = Remote()->SendRequest(
302 static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_NOISE_SUPPRESSION_MODE), data, reply, option);
303 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, -1, "failed,error:%d", error);
304 int32_t result = reply.ReadInt32();
305 return result;
306 }
307
GetAsrNoiseSuppressionMode(AsrNoiseSuppressionMode & asrNoiseSuppressionMode)308 int32_t AudioManagerProxy::GetAsrNoiseSuppressionMode(AsrNoiseSuppressionMode &asrNoiseSuppressionMode)
309 {
310 MessageParcel data;
311 MessageParcel reply;
312 MessageOption option;
313
314 bool ret = data.WriteInterfaceToken(GetDescriptor());
315 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
316 data.WriteInt32(static_cast<int32_t>(asrNoiseSuppressionMode));
317
318 int32_t error = Remote()->SendRequest(
319 static_cast<uint32_t>(AudioServerInterfaceCode::GET_ASR_NOISE_SUPPRESSION_MODE), data, reply, option);
320 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, -1, "failed,error:%d", error);
321 int32_t result = reply.ReadInt32();
322 asrNoiseSuppressionMode = static_cast<AsrNoiseSuppressionMode>(result);
323 return 0;
324 }
325
SetAsrWhisperDetectionMode(AsrWhisperDetectionMode asrWhisperDetectionMode)326 int32_t AudioManagerProxy::SetAsrWhisperDetectionMode(AsrWhisperDetectionMode asrWhisperDetectionMode)
327 {
328 MessageParcel data;
329 MessageParcel reply;
330 MessageOption option;
331
332 bool ret = data.WriteInterfaceToken(GetDescriptor());
333 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
334 data.WriteInt32(static_cast<int32_t>(asrWhisperDetectionMode));
335
336 int32_t error = Remote()->SendRequest(static_cast<uint32_t>(
337 AudioServerInterfaceCode::SET_ASR_WHISPER_DETECTION_MODE), data, reply, option);
338 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, -1, "failed,error:%d", error);
339 int32_t result = reply.ReadInt32();
340 return result;
341 }
342
GetAsrWhisperDetectionMode(AsrWhisperDetectionMode & asrWhisperDetectionMode)343 int32_t AudioManagerProxy::GetAsrWhisperDetectionMode(AsrWhisperDetectionMode &asrWhisperDetectionMode)
344 {
345 MessageParcel data;
346 MessageParcel reply;
347 MessageOption option;
348
349 bool ret = data.WriteInterfaceToken(GetDescriptor());
350 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
351 data.WriteInt32(static_cast<int32_t>(asrWhisperDetectionMode));
352
353 int32_t error = Remote()->SendRequest(
354 static_cast<uint32_t>(AudioServerInterfaceCode::GET_ASR_WHISPER_DETECTION_MODE), data, reply, option);
355 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, -1, "failed,error:%d", error);
356 int32_t result = reply.ReadInt32();
357 asrWhisperDetectionMode = static_cast<AsrWhisperDetectionMode>(result);
358 return 0;
359 }
360
SetAsrVoiceControlMode(AsrVoiceControlMode asrVoiceControlMode,bool on)361 int32_t AudioManagerProxy::SetAsrVoiceControlMode(AsrVoiceControlMode asrVoiceControlMode, bool on)
362 {
363 MessageParcel data;
364 MessageParcel reply;
365 MessageOption option;
366
367 bool ret = data.WriteInterfaceToken(GetDescriptor());
368 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
369 data.WriteInt32(static_cast<int32_t>(asrVoiceControlMode));
370 data.WriteBool(on);
371
372 int32_t error = Remote()->SendRequest(static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_VOICE_CONTROL_MODE),
373 data, reply, option);
374 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, -1, "failed,error:%d", error);
375 int32_t result = reply.ReadInt32();
376 return result;
377 }
378
SetAsrVoiceMuteMode(AsrVoiceMuteMode asrVoiceMuteMode,bool on)379 int32_t AudioManagerProxy::SetAsrVoiceMuteMode(AsrVoiceMuteMode asrVoiceMuteMode, bool on)
380 {
381 MessageParcel data;
382 MessageParcel reply;
383 MessageOption option;
384
385 bool ret = data.WriteInterfaceToken(GetDescriptor());
386 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
387 data.WriteInt32(static_cast<int32_t>(asrVoiceMuteMode));
388 data.WriteBool(on);
389
390 int32_t error = Remote()->SendRequest(static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_VOICE_MUTE_MODE),
391 data, reply, option);
392 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, -1, "failed,error:%d", error);
393 int32_t result = reply.ReadInt32();
394 return result;
395 }
396
IsWhispering()397 int32_t AudioManagerProxy::IsWhispering()
398 {
399 MessageParcel data;
400 MessageParcel reply;
401 MessageOption option;
402
403 bool ret = data.WriteInterfaceToken(GetDescriptor());
404 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
405
406 int32_t result = Remote()->SendRequest(
407 static_cast<uint32_t>(AudioServerInterfaceCode::IS_WHISPERING), data, reply, option);
408 return result;
409 }
410
GetEffectOffloadEnabled()411 bool AudioManagerProxy::GetEffectOffloadEnabled()
412 {
413 MessageParcel data;
414 MessageParcel reply;
415 MessageOption option;
416
417 bool ret = data.WriteInterfaceToken(GetDescriptor());
418 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
419
420 int32_t error = Remote()->SendRequest(
421 static_cast<uint32_t>(AudioServerInterfaceCode::GET_EFFECT_OFFLOAD_ENABLED), data, reply, option);
422 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "failed,error:%d", error);
423 bool result = reply.ReadBool();
424 return result;
425 }
426
GetTransactionId(DeviceType deviceType,DeviceRole deviceRole)427 uint64_t AudioManagerProxy::GetTransactionId(DeviceType deviceType, DeviceRole deviceRole)
428 {
429 MessageParcel data;
430 MessageParcel reply;
431 MessageOption option;
432 uint32_t transactionId = 0;
433
434 bool ret = data.WriteInterfaceToken(GetDescriptor());
435 CHECK_AND_RETURN_RET_LOG(ret, transactionId, "WriteInterfaceToken failed");
436
437 data.WriteInt32(static_cast<int32_t>(deviceType));
438 data.WriteInt32(static_cast<int32_t>(deviceRole));
439
440 int32_t error = Remote()->SendRequest(
441 static_cast<uint32_t>(AudioServerInterfaceCode::GET_TRANSACTION_ID), data, reply, option);
442 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, transactionId, "get transaction id failed, error: %d", error);
443
444 transactionId = reply.ReadUint64();
445
446 return transactionId;
447 }
448
NotifyDeviceInfo(std::string networkId,bool connected)449 void AudioManagerProxy::NotifyDeviceInfo(std::string networkId, bool connected)
450 {
451 MessageParcel data;
452 MessageParcel reply;
453 MessageOption option;
454
455 bool ret = data.WriteInterfaceToken(GetDescriptor());
456 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
457 data.WriteString(networkId);
458 data.WriteBool(connected);
459 int32_t error = Remote()->SendRequest(
460 static_cast<uint32_t>(AudioServerInterfaceCode::NOTIFY_DEVICE_INFO), data, reply, option);
461 CHECK_AND_RETURN_LOG(error == ERR_NONE, "Get audio parameter failed, error: %d", error);
462 }
463
CheckRemoteDeviceState(std::string networkId,DeviceRole deviceRole,bool isStartDevice)464 int32_t AudioManagerProxy::CheckRemoteDeviceState(std::string networkId, DeviceRole deviceRole, bool isStartDevice)
465 {
466 MessageParcel data;
467 MessageParcel reply;
468 MessageOption option;
469
470 bool ret = data.WriteInterfaceToken(GetDescriptor());
471 CHECK_AND_RETURN_RET_LOG(ret, ERR_TRANSACTION_FAILED, "WriteInterfaceToken failed");
472 data.WriteString(networkId);
473 data.WriteInt32(static_cast<int32_t>(deviceRole));
474 data.WriteBool(isStartDevice);
475 int32_t error = Remote()->SendRequest(
476 static_cast<uint32_t>(AudioServerInterfaceCode::CHECK_REMOTE_DEVICE_STATE), data, reply, option);
477 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "CheckRemoteDeviceState failed in proxy, error: %d", error);
478 return reply.ReadInt32();
479 }
480
UpdateActiveDeviceRoute(DeviceType type,DeviceFlag flag,BluetoothOffloadState a2dpOffloadFlag)481 int32_t AudioManagerProxy::UpdateActiveDeviceRoute(DeviceType type, DeviceFlag flag,
482 BluetoothOffloadState a2dpOffloadFlag)
483 {
484 MessageParcel data;
485 MessageParcel reply;
486 MessageOption option;
487
488 bool ret = data.WriteInterfaceToken(GetDescriptor());
489 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
490
491 data.WriteInt32(type);
492 data.WriteInt32(flag);
493 data.WriteInt32(static_cast<int32_t>(a2dpOffloadFlag));
494
495 auto error = Remote()->SendRequest(
496 static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_ROUTE_REQ), data, reply, option);
497 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "UpdateActiveDeviceRoute failed, error: %{public}d", error);
498
499 auto result = reply.ReadInt32();
500 AUDIO_DEBUG_LOG("[UPDATE_ROUTE_REQ] result %{public}d", result);
501 return result;
502 }
503
UpdateActiveDevicesRoute(std::vector<std::pair<DeviceType,DeviceFlag>> & activeDevices,BluetoothOffloadState a2dpOffloadFlag,const std::string & deviceName)504 int32_t AudioManagerProxy::UpdateActiveDevicesRoute(std::vector<std::pair<DeviceType, DeviceFlag>> &activeDevices,
505 BluetoothOffloadState a2dpOffloadFlag, const std::string &deviceName)
506 {
507 CHECK_AND_RETURN_RET_LOG(!activeDevices.empty() && activeDevices.size() <= AUDIO_CONCURRENT_ACTIVE_DEVICES_LIMIT,
508 ERR_NONE, "Invalid active output devices.");
509 MessageParcel data;
510 MessageParcel reply;
511 MessageOption option;
512
513 bool ret = data.WriteInterfaceToken(GetDescriptor());
514 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
515 data.WriteInt32(static_cast<int32_t>(activeDevices.size()));
516 for (auto it = activeDevices.begin(); it != activeDevices.end(); it++) {
517 data.WriteInt32(static_cast<int32_t>(it->first));
518 data.WriteInt32(static_cast<int32_t>(it->second));
519 }
520 data.WriteInt32(static_cast<int32_t>(a2dpOffloadFlag));
521 data.WriteString(deviceName);
522
523 auto error = Remote()->SendRequest(
524 static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_ROUTES_REQ), data, reply, option);
525 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "UpdateActiveDevicesRoute failed, error: %{public}d", error);
526
527 auto result = reply.ReadInt32();
528 AUDIO_DEBUG_LOG("[UPDATE_ROUTES_REQ] result %{public}d", result);
529 return result;
530 }
531
UpdateDualToneState(bool enable,int32_t sessionId)532 int32_t AudioManagerProxy::UpdateDualToneState(bool enable, int32_t sessionId)
533 {
534 MessageParcel data;
535 MessageParcel reply;
536 MessageOption option;
537
538 bool ret = data.WriteInterfaceToken(GetDescriptor());
539 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
540
541 data.WriteBool(enable);
542 data.WriteInt32(sessionId);
543 auto error = Remote()->SendRequest(
544 static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_DUAL_TONE_REQ), data, reply, option);
545 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "UpdateDualToneState failed, error: %{public}d", error);
546
547 auto result = reply.ReadInt32();
548 AUDIO_DEBUG_LOG("[UPDATE_DUAL_TONE_REQ] result %{public}d", result);
549 return result;
550 }
551
SetParameterCallback(const sptr<IRemoteObject> & object)552 int32_t AudioManagerProxy::SetParameterCallback(const sptr<IRemoteObject>& object)
553 {
554 MessageParcel data;
555 MessageParcel reply;
556 MessageOption option;
557
558 CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "object is null");
559
560 bool ret = data.WriteInterfaceToken(GetDescriptor());
561 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
562
563 (void)data.WriteRemoteObject(object);
564 int error = Remote()->SendRequest(
565 static_cast<uint32_t>(AudioServerInterfaceCode::SET_PARAMETER_CALLBACK), data, reply, option);
566 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
567 "SetParameterCallback failed, error: %{public}d", error);
568
569 return reply.ReadInt32();
570 }
571
RegiestPolicyProvider(const sptr<IRemoteObject> & object)572 int32_t AudioManagerProxy::RegiestPolicyProvider(const sptr<IRemoteObject> &object)
573 {
574 MessageParcel data;
575 MessageParcel reply;
576 MessageOption option(MessageOption::TF_ASYNC);
577
578 CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "object is null");
579 bool ret = data.WriteInterfaceToken(GetDescriptor());
580 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
581
582 (void)data.WriteRemoteObject(object);
583 int error = Remote()->SendRequest(static_cast<uint32_t>(AudioServerInterfaceCode::REGISET_POLICY_PROVIDER), data,
584 reply, option);
585 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
586 "RegiestPolicyProvider failed, error: %{public}d", error);
587
588 return reply.ReadInt32();
589 }
590
SetWakeupSourceCallback(const sptr<IRemoteObject> & object)591 int32_t AudioManagerProxy::SetWakeupSourceCallback(const sptr<IRemoteObject>& object)
592 {
593 MessageParcel data;
594 MessageParcel reply;
595 MessageOption option;
596
597 CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "object is null");
598 bool ret = data.WriteInterfaceToken(GetDescriptor());
599 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
600
601 (void)data.WriteRemoteObject(object);
602 int error = Remote()->SendRequest(
603 static_cast<uint32_t>(AudioServerInterfaceCode::SET_WAKEUP_CLOSE_CALLBACK), data, reply, option);
604 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
605 "SetWakeupCloseCallback failed, error: %{public}d", error);
606
607 return reply.ReadInt32();
608 }
609
SetAudioMonoState(bool audioMono)610 void AudioManagerProxy::SetAudioMonoState(bool audioMono)
611 {
612 MessageParcel data;
613 MessageParcel reply;
614 MessageOption option;
615
616 bool ret = data.WriteInterfaceToken(GetDescriptor());
617 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
618 (void)data.WriteBool(audioMono);
619 int error = Remote()->SendRequest(
620 static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_MONO_STATE), data, reply, option);
621 CHECK_AND_RETURN_LOG(error == ERR_NONE, "SetAudioMonoState failed, error: %{public}d", error);
622 }
623
SetAudioBalanceValue(float audioBalance)624 void AudioManagerProxy::SetAudioBalanceValue(float audioBalance)
625 {
626 MessageParcel data;
627 MessageParcel reply;
628 MessageOption option;
629
630 bool ret = data.WriteInterfaceToken(GetDescriptor());
631 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
632 (void)data.WriteFloat(audioBalance);
633 int error = Remote()->SendRequest(
634 static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_BALANCE_VALUE), data, reply, option);
635 CHECK_AND_RETURN_LOG(error == ERR_NONE, "SetAudioBalanceValue failed, error: %{public}d", error);
636 }
637
CreateAudioProcess(const AudioProcessConfig & config,int32_t & errorCode,const AudioPlaybackCaptureConfig & filterConfig)638 sptr<IRemoteObject> AudioManagerProxy::CreateAudioProcess(const AudioProcessConfig &config, int32_t &errorCode,
639 const AudioPlaybackCaptureConfig &filterConfig)
640 {
641 MessageParcel data;
642 MessageParcel reply;
643 MessageOption option;
644
645 bool ret = data.WriteInterfaceToken(GetDescriptor());
646 CHECK_AND_RETURN_RET_LOG(ret, nullptr, "WriteInterfaceToken failed");
647 ProcessConfig::WriteConfigToParcel(config, data);
648 ProcessConfig::WriteInnerCapConfigToParcel(filterConfig, data);
649 int error = Remote()->SendRequest(
650 static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_AUDIOPROCESS), data, reply, option);
651 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, nullptr, "CreateAudioProcess failed, error: %{public}d", error);
652 errorCode = reply.ReadInt32();
653 CHECK_AND_RETURN_RET_LOG(errorCode == SUCCESS, nullptr, "errcode: %{public}d", errorCode);
654 sptr<IRemoteObject> process = reply.ReadRemoteObject();
655 return process;
656 }
657
LoadAudioEffectLibraries(const vector<Library> libraries,const vector<Effect> effects,vector<Effect> & successEffects)658 bool AudioManagerProxy::LoadAudioEffectLibraries(const vector<Library> libraries, const vector<Effect> effects,
659 vector<Effect> &successEffects)
660 {
661 int32_t error;
662 int32_t i;
663
664 MessageParcel dataParcel;
665 MessageParcel replyParcel;
666 MessageOption option;
667 bool ret = dataParcel.WriteInterfaceToken(GetDescriptor());
668 CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
669
670 uint32_t countLib = libraries.size();
671 uint32_t countEff = effects.size();
672
673 dataParcel.WriteInt32(countLib);
674 dataParcel.WriteInt32(countEff);
675
676 for (Library x : libraries) {
677 dataParcel.WriteString(x.name);
678 dataParcel.WriteString(x.path);
679 }
680
681 for (Effect x : effects) {
682 dataParcel.WriteString(x.name);
683 dataParcel.WriteString(x.libraryName);
684 }
685
686 error = Remote()->SendRequest(
687 static_cast<uint32_t>(AudioServerInterfaceCode::LOAD_AUDIO_EFFECT_LIBRARIES), dataParcel, replyParcel, option);
688 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "LoadAudioEffectLibraries failed, error: %{public}d", error);
689
690 int32_t successEffSize = replyParcel.ReadInt32();
691 CHECK_AND_RETURN_RET_LOG((successEffSize >= 0) && (successEffSize <= AUDIO_EFFECT_COUNT_UPPER_LIMIT),
692 false, "LOAD_AUDIO_EFFECT_LIBRARIES read replyParcel failed");
693
694 for (i = 0; i < successEffSize; i++) {
695 string effectName = replyParcel.ReadString();
696 string libName = replyParcel.ReadString();
697 successEffects.push_back({effectName, libName});
698 }
699
700 return true;
701 }
MarshallEffectChainMgrParam(const EffectChainManagerParam & effectChainMgrParam,MessageParcel & data)702 static void MarshallEffectChainMgrParam(const EffectChainManagerParam &effectChainMgrParam, MessageParcel &data)
703 {
704 data.WriteInt32(effectChainMgrParam.maxExtraNum);
705 data.WriteString(effectChainMgrParam.defaultSceneName);
706 data.WriteInt32(effectChainMgrParam.priorSceneList.size());
707 for (const auto &priorScene : effectChainMgrParam.priorSceneList) {
708 data.WriteString(priorScene);
709 }
710
711 data.WriteInt32(effectChainMgrParam.sceneTypeToChainNameMap.size());
712 for (const auto &[scene, chain] : effectChainMgrParam.sceneTypeToChainNameMap) {
713 data.WriteString(scene);
714 data.WriteString(chain);
715 }
716
717 data.WriteInt32(effectChainMgrParam.effectDefaultProperty.size());
718 for (const auto &[effect, prop] : effectChainMgrParam.effectDefaultProperty) {
719 data.WriteString(effect);
720 data.WriteString(prop);
721 }
722 }
723
CreateEffectChainManager(std::vector<EffectChain> & effectChains,const EffectChainManagerParam & effectParam,const EffectChainManagerParam & enhanceParam)724 bool AudioManagerProxy::CreateEffectChainManager(std::vector<EffectChain> &effectChains,
725 const EffectChainManagerParam &effectParam, const EffectChainManagerParam &enhanceParam)
726 {
727 int32_t error;
728
729 MessageParcel dataParcel;
730 MessageParcel replyParcel;
731 MessageOption option;
732
733 bool ret = dataParcel.WriteInterfaceToken(GetDescriptor());
734 CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
735
736 uint32_t countEffectChains = effectChains.size();
737 std::vector<int32_t> listCountEffects;
738
739 for (EffectChain &effectChain: effectChains) {
740 listCountEffects.emplace_back(effectChain.apply.size());
741 }
742
743 dataParcel.WriteInt32(countEffectChains);
744 for (int32_t countEffects: listCountEffects) {
745 dataParcel.WriteInt32(countEffects);
746 }
747
748 for (EffectChain &effectChain: effectChains) {
749 dataParcel.WriteString(effectChain.name);
750 for (std::string applyName: effectChain.apply) {
751 dataParcel.WriteString(applyName);
752 }
753 }
754
755 MarshallEffectChainMgrParam(effectParam, dataParcel);
756 MarshallEffectChainMgrParam(enhanceParam, dataParcel);
757
758 error = Remote()->SendRequest(
759 static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_AUDIO_EFFECT_CHAIN_MANAGER),
760 dataParcel, replyParcel, option);
761 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false,
762 "CreateAudioEffectChainManager failed, error: %{public}d", error);
763 return true;
764 }
765
SetOutputDeviceSink(int32_t deviceType,std::string & sinkName)766 void AudioManagerProxy::SetOutputDeviceSink(int32_t deviceType, std::string &sinkName)
767 {
768 int32_t error;
769
770 MessageParcel dataParcel;
771 MessageParcel replyParcel;
772 MessageOption option;
773 bool ret = dataParcel.WriteInterfaceToken(GetDescriptor());
774 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
775 dataParcel.WriteInt32(deviceType);
776 dataParcel.WriteString(sinkName);
777
778 error = Remote()->SendRequest(
779 static_cast<uint32_t>(AudioServerInterfaceCode::SET_OUTPUT_DEVICE_SINK), dataParcel, replyParcel, option);
780 CHECK_AND_RETURN_LOG(error == ERR_NONE, "SetOutputDeviceSink failed, error: %{public}d", error);
781 return;
782 }
783
CreatePlaybackCapturerManager()784 bool AudioManagerProxy::CreatePlaybackCapturerManager()
785 {
786 #ifdef HAS_FEATURE_INNERCAPTURER
787 int32_t error;
788 MessageParcel data;
789 MessageParcel reply;
790 MessageOption option;
791 bool ret = data.WriteInterfaceToken(GetDescriptor());
792 CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
793
794 error = Remote()->SendRequest(
795 static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_PLAYBACK_CAPTURER_MANAGER), data, reply, option);
796 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false,
797 "CreatePlaybackCapturerManager failed, error: %{public}d", error);
798
799 return reply.ReadBool();
800 #else
801 return false;
802 #endif
803 }
804
NotifyStreamVolumeChanged(AudioStreamType streamType,float volume)805 int32_t AudioManagerProxy::NotifyStreamVolumeChanged(AudioStreamType streamType, float volume)
806 {
807 int32_t error;
808 MessageParcel data;
809 MessageParcel reply;
810 MessageOption option;
811
812 if (!data.WriteInterfaceToken(GetDescriptor())) {
813 AUDIO_ERR_LOG("NotifyStreamVolumeChanged: WriteInterfaceToken failed");
814 return -1;
815 }
816
817 data.WriteInt32(static_cast<int32_t>(streamType));
818 data.WriteFloat(volume);
819 error = Remote()->SendRequest(static_cast<uint32_t>(AudioServerInterfaceCode::NOTIFY_STREAM_VOLUME_CHANGED),
820 data, reply, option);
821 if (error != ERR_NONE) {
822 AUDIO_ERR_LOG("NotifyStreamVolumeChanged failed, error: %{public}d", error);
823 return error;
824 }
825 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "NotifyStreamVolumeChanged failed, error: %{public}d", error);
826 return reply.ReadInt32();
827 }
828
UpdateSpatializationState(AudioSpatializationState spatializationState)829 int32_t AudioManagerProxy::UpdateSpatializationState(AudioSpatializationState spatializationState)
830 {
831 int32_t error;
832 MessageParcel data;
833 MessageParcel reply;
834 MessageOption option;
835
836 bool ret = data.WriteInterfaceToken(GetDescriptor());
837 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
838 data.WriteBool(spatializationState.spatializationEnabled);
839 data.WriteBool(spatializationState.headTrackingEnabled);
840
841 error = Remote()->SendRequest(
842 static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_SPATIALIZATION_STATE), data, reply, option);
843 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
844 "UpdateSpatializationState failed, error: %{public}d", error);
845
846 return reply.ReadInt32();
847 }
848
UpdateSpatialDeviceType(AudioSpatialDeviceType spatialDeviceType)849 int32_t AudioManagerProxy::UpdateSpatialDeviceType(AudioSpatialDeviceType spatialDeviceType)
850 {
851 int32_t error;
852 MessageParcel data;
853 MessageParcel reply;
854 MessageOption option;
855
856 bool ret = data.WriteInterfaceToken(GetDescriptor());
857 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
858 data.WriteInt32(spatialDeviceType);
859
860 error = Remote()->SendRequest(
861 static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_SPATIAL_DEVICE_TYPE), data, reply, option);
862 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "UpdateSpatialDeviceType failed, error: %{public}d", error);
863
864 return reply.ReadInt32();
865 }
866
SetSpatializationSceneType(AudioSpatializationSceneType spatializationSceneType)867 int32_t AudioManagerProxy::SetSpatializationSceneType(AudioSpatializationSceneType spatializationSceneType)
868 {
869 int32_t error;
870 MessageParcel data;
871 MessageParcel reply;
872 MessageOption option;
873
874 bool ret = data.WriteInterfaceToken(GetDescriptor());
875 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
876 data.WriteInt32(static_cast<int32_t>(spatializationSceneType));
877
878 error = Remote()->SendRequest(
879 static_cast<uint32_t>(AudioServerInterfaceCode::SET_SPATIALIZATION_SCENE_TYPE), data, reply, option);
880 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
881
882 return reply.ReadInt32();
883 }
884
ResetRouteForDisconnect(DeviceType type)885 int32_t AudioManagerProxy::ResetRouteForDisconnect(DeviceType type)
886 {
887 int32_t error;
888 MessageParcel data;
889 MessageParcel reply;
890 MessageOption option;
891
892 bool ret = data.WriteInterfaceToken(GetDescriptor());
893 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
894 data.WriteInt32(static_cast<int32_t>(type));
895
896 error = Remote()->SendRequest(
897 static_cast<uint32_t>(AudioServerInterfaceCode::RESET_ROUTE_FOR_DISCONNECT), data, reply, option);
898 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "error: %{public}d", error);
899
900 return reply.ReadInt32();
901 }
902
GetEffectLatency(const std::string & sessionId)903 uint32_t AudioManagerProxy::GetEffectLatency(const std::string &sessionId)
904 {
905 int32_t error;
906 MessageParcel data;
907 MessageParcel reply;
908 MessageOption option;
909
910 bool ret = data.WriteInterfaceToken(GetDescriptor());
911 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
912 data.WriteString(sessionId);
913
914 error = Remote()->SendRequest(
915 static_cast<uint32_t>(AudioServerInterfaceCode::GET_EFFECT_LATENCY), data, reply, option);
916 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "error: %{public}d", error);
917
918 return reply.ReadUint32();
919 }
920
GetMaxAmplitude(bool isOutputDevice,std::string deviceClass,SourceType sourceType)921 float AudioManagerProxy::GetMaxAmplitude(bool isOutputDevice, std::string deviceClass, SourceType sourceType)
922 {
923 int32_t error;
924 MessageParcel data;
925 MessageParcel reply;
926 MessageOption option;
927
928 bool ret = data.WriteInterfaceToken(GetDescriptor());
929 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
930 data.WriteBool(isOutputDevice);
931 data.WriteString(deviceClass);
932 data.WriteInt32(static_cast<int32_t>(sourceType));
933
934 error = Remote()->SendRequest(
935 static_cast<uint32_t>(AudioServerInterfaceCode::GET_MAX_AMPLITUDE), data, reply, option);
936 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
937
938 return reply.ReadFloat();
939 }
940
ResetAudioEndpoint()941 void AudioManagerProxy::ResetAudioEndpoint()
942 {
943 int32_t error;
944 MessageParcel data;
945 MessageParcel reply;
946 MessageOption option;
947
948 bool ret = data.WriteInterfaceToken(GetDescriptor());
949 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
950 error = Remote()->SendRequest(
951 static_cast<uint32_t>(AudioServerInterfaceCode::RESET_AUDIO_ENDPOINT), data, reply, option);
952 CHECK_AND_RETURN_LOG(error == ERR_NONE, "Send request failed, error:%{public}d", error);
953 }
954
SuspendRenderSink(const std::string & sinkName)955 int32_t AudioManagerProxy::SuspendRenderSink(const std::string &sinkName)
956 {
957 int32_t error;
958 MessageParcel data;
959 MessageParcel reply;
960 MessageOption option;
961
962 bool ret = data.WriteInterfaceToken(GetDescriptor());
963 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
964 data.WriteString(sinkName);
965
966 error = Remote()->SendRequest(
967 static_cast<uint32_t>(AudioServerInterfaceCode::SUSPEND_RENDERSINK), data, reply, option);
968 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
969
970 return reply.ReadInt32();
971 }
972
RestoreRenderSink(const std::string & sinkName)973 int32_t AudioManagerProxy::RestoreRenderSink(const std::string &sinkName)
974 {
975 int32_t error;
976 MessageParcel data;
977 MessageParcel reply;
978 MessageOption option;
979
980 bool ret = data.WriteInterfaceToken(GetDescriptor());
981 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
982 data.WriteString(sinkName);
983
984 error = Remote()->SendRequest(
985 static_cast<uint32_t>(AudioServerInterfaceCode::RESTORE_RENDERSINK), data, reply, option);
986 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
987
988 return reply.ReadInt32();
989 }
990
UpdateLatencyTimestamp(std::string & timestamp,bool isRenderer)991 void AudioManagerProxy::UpdateLatencyTimestamp(std::string ×tamp, bool isRenderer)
992 {
993 int32_t error;
994 MessageParcel data;
995 MessageParcel reply;
996 MessageOption option;
997
998 bool ret = data.WriteInterfaceToken(GetDescriptor());
999 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1000 data.WriteString(timestamp);
1001 data.WriteBool(isRenderer);
1002
1003 error = Remote()->SendRequest(
1004 static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_LATENCY_TIMESTAMP), data, reply, option);
1005 CHECK_AND_RETURN_LOG(error == ERR_NONE,
1006 "LatencyMeas UpdateLatencyTimestamp failed, error:%{public}d", error);
1007 }
1008
GetAudioEffectProperty(AudioEffectPropertyArrayV3 & propertyArray,const DeviceType & deviceType)1009 int32_t AudioManagerProxy::GetAudioEffectProperty(AudioEffectPropertyArrayV3 &propertyArray,
1010 const DeviceType& deviceType)
1011 {
1012 MessageParcel data;
1013 MessageParcel reply;
1014 MessageOption option;
1015
1016 bool res = data.WriteInterfaceToken(GetDescriptor());
1017 CHECK_AND_RETURN_RET_LOG(res, ERR_INVALID_OPERATION, "WriteInterfaceToken failed");
1018 data.WriteInt32(static_cast<int32_t>(deviceType));
1019 int32_t error = Remote()->SendRequest(
1020 static_cast<uint32_t>(AudioServerInterfaceCode::GET_AUDIO_EFFECT_PROPERTY_V3), data, reply, option);
1021 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Audio Effect Property, error: %d", error);
1022
1023 int32_t size = reply.ReadInt32();
1024 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
1025 ERROR_INVALID_PARAM, "get audio effect property size invalid.");
1026 for (int32_t i = 0; i < size; i++) {
1027 // write and read must keep same order
1028 AudioEffectPropertyV3 prop = {};
1029 prop.Unmarshalling(reply);
1030 propertyArray.property.push_back(prop);
1031 }
1032 return AUDIO_OK;
1033 }
1034
SetAudioEffectProperty(const AudioEffectPropertyArrayV3 & propertyArray,const DeviceType & deviceType)1035 int32_t AudioManagerProxy::SetAudioEffectProperty(const AudioEffectPropertyArrayV3 &propertyArray,
1036 const DeviceType& deviceType)
1037 {
1038 MessageParcel data;
1039 MessageParcel reply;
1040 MessageOption option;
1041
1042 bool ret = data.WriteInterfaceToken(GetDescriptor());
1043 CHECK_AND_RETURN_RET_LOG(ret, ERR_INVALID_OPERATION, "WriteInterfaceToken failed");
1044
1045 int32_t size = static_cast<int32_t>(propertyArray.property.size());
1046 CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
1047 ERROR_INVALID_PARAM, "set audio effect property size invalid.");
1048 data.WriteInt32(size);
1049 for (int32_t i = 0; i < size; i++) {
1050 // write and read must keep same order
1051 propertyArray.property[i].Marshalling(data);
1052 }
1053 data.WriteInt32(static_cast<int32_t>(deviceType));
1054 int32_t error = Remote()->SendRequest(
1055 static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_EFFECT_PROPERTY_V3), data, reply, option);
1056 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
1057 return reply.ReadInt32();
1058 }
1059
GetAudioEnhanceProperty(AudioEnhancePropertyArray & propertyArray,DeviceType deviceType)1060 int32_t AudioManagerProxy::GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray,
1061 DeviceType deviceType)
1062 {
1063 MessageParcel data;
1064 MessageParcel reply;
1065 MessageOption option;
1066
1067 bool res = data.WriteInterfaceToken(GetDescriptor());
1068 CHECK_AND_RETURN_RET_LOG(res, ERR_INVALID_OPERATION, "WriteInterfaceToken failed");
1069 data.WriteInt32(static_cast<int32_t>(deviceType));
1070 int32_t error = Remote()->SendRequest(
1071 static_cast<uint32_t>(AudioServerInterfaceCode::GET_AUDIO_ENHANCE_PROPERTY), data, reply, option);
1072 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Audio Enhance Property, error: %d", error);
1073
1074 int32_t size = reply.ReadInt32();
1075 for (int32_t i = 0; i < size; i++) {
1076 // write and read must keep same order
1077 AudioEnhanceProperty prop = {};
1078 prop.Unmarshalling(reply);
1079 propertyArray.property.push_back(prop);
1080 }
1081 return AUDIO_OK;
1082 }
1083
GetAudioEffectProperty(AudioEffectPropertyArray & propertyArray)1084 int32_t AudioManagerProxy::GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray)
1085 {
1086 MessageParcel data;
1087 MessageParcel reply;
1088 MessageOption option;
1089
1090 bool res = data.WriteInterfaceToken(GetDescriptor());
1091 CHECK_AND_RETURN_RET_LOG(res, ERR_INVALID_OPERATION, "WriteInterfaceToken failed");
1092
1093 int32_t error = Remote()->SendRequest(
1094 static_cast<uint32_t>(AudioServerInterfaceCode::GET_AUDIO_EFFECT_PROPERTY), data, reply, option);
1095 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Audio Effect Property, error: %d", error);
1096
1097 int32_t size = reply.ReadInt32();
1098 for (int32_t i = 0; i < size; i++) {
1099 AudioEffectProperty prop = {};
1100 prop.Unmarshalling(reply);
1101 // write and read must keep same order
1102 propertyArray.property.push_back(prop);
1103 }
1104 return AUDIO_OK;
1105 }
1106
SetAudioEnhanceProperty(const AudioEnhancePropertyArray & propertyArray,DeviceType deviceType)1107 int32_t AudioManagerProxy::SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray,
1108 DeviceType deviceType)
1109 {
1110 MessageParcel data;
1111 MessageParcel reply;
1112 MessageOption option;
1113
1114 bool ret = data.WriteInterfaceToken(GetDescriptor());
1115 CHECK_AND_RETURN_RET_LOG(ret, ERR_INVALID_OPERATION, "WriteInterfaceToken failed");
1116
1117 int32_t size = static_cast<int32_t>(propertyArray.property.size());
1118 data.WriteInt32(size);
1119 for (int32_t i = 0; i < size; i++) {
1120 // write and read must keep same order
1121 propertyArray.property[i].Marshalling(data);
1122 }
1123 data.WriteInt32(static_cast<int32_t>(deviceType));
1124 int32_t error = Remote()->SendRequest(
1125 static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_ENHANCE_PROPERTY), data, reply, option);
1126 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
1127 return reply.ReadInt32();
1128 }
1129
SetAudioEffectProperty(const AudioEffectPropertyArray & propertyArray)1130 int32_t AudioManagerProxy::SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray)
1131 {
1132 MessageParcel data;
1133 MessageParcel reply;
1134 MessageOption option;
1135
1136 bool ret = data.WriteInterfaceToken(GetDescriptor());
1137 CHECK_AND_RETURN_RET_LOG(ret, ERR_INVALID_OPERATION, "WriteInterfaceToken failed");
1138
1139 int32_t size = static_cast<int32_t>(propertyArray.property.size());
1140 data.WriteInt32(size);
1141 for (int32_t i = 0; i < size; i++) {
1142 propertyArray.property[i].Marshalling(data);
1143 }
1144 int32_t error = Remote()->SendRequest(
1145 static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_EFFECT_PROPERTY), data, reply, option);
1146 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
1147 return reply.ReadInt32();
1148 }
1149
LoadHdiEffectModel()1150 void AudioManagerProxy::LoadHdiEffectModel()
1151 {
1152 MessageParcel data;
1153 MessageParcel reply;
1154 MessageOption option;
1155
1156 bool ret = data.WriteInterfaceToken(GetDescriptor());
1157 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1158
1159 int32_t error = Remote()->SendRequest(
1160 static_cast<uint32_t>(AudioServerInterfaceCode::LOAD_HDI_EFFECT_MODEL), data, reply, option);
1161 CHECK_AND_RETURN_LOG(error == ERR_NONE, "failed,error:%d", error);
1162 }
1163
UpdateEffectBtOffloadSupported(const bool & isSupported)1164 void AudioManagerProxy::UpdateEffectBtOffloadSupported(const bool &isSupported)
1165 {
1166 MessageParcel data;
1167 MessageParcel reply;
1168 MessageOption option;
1169
1170 bool ret = data.WriteInterfaceToken(GetDescriptor());
1171 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1172 data.WriteBool(isSupported);
1173
1174 int32_t error = Remote()->SendRequest(
1175 static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_EFFECT_BT_OFFLOAD_SUPPORTED), data, reply, option);
1176 CHECK_AND_RETURN_LOG(error == ERR_NONE, "failed, error:%{public}d", error);
1177 }
1178
SetSinkMuteForSwitchDevice(const std::string & devceClass,int32_t durationUs,bool mute)1179 int32_t AudioManagerProxy::SetSinkMuteForSwitchDevice(const std::string &devceClass, int32_t durationUs, bool mute)
1180 {
1181 MessageParcel data;
1182 MessageParcel reply;
1183 MessageOption option;
1184
1185 bool ret = data.WriteInterfaceToken(GetDescriptor());
1186 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
1187 data.WriteString(devceClass);
1188 data.WriteInt32(durationUs);
1189 data.WriteInt32(mute);
1190
1191 int32_t error = Remote()->SendRequest(
1192 static_cast<uint32_t>(AudioServerInterfaceCode::SET_SINK_MUTE_FOR_SWITCH_DEVICE), data, reply, option);
1193 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "failed, error:%{public}d", error);
1194 return reply.ReadInt32();
1195 }
1196
SetRotationToEffect(const uint32_t rotate)1197 void AudioManagerProxy::SetRotationToEffect(const uint32_t rotate)
1198 {
1199 MessageParcel data;
1200 MessageParcel reply;
1201 MessageOption option;
1202
1203 bool ret = data.WriteInterfaceToken(GetDescriptor());
1204 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1205 data.WriteUint32(rotate);
1206
1207 int32_t error = Remote()->SendRequest(
1208 static_cast<uint32_t>(AudioServerInterfaceCode::SET_ROTATION_TO_EFFECT), data, reply, option);
1209 CHECK_AND_RETURN_LOG(error == ERR_NONE, "failed, error:%{public}d", error);
1210 }
1211
UpdateSessionConnectionState(const int32_t & sessionID,const int32_t & state)1212 void AudioManagerProxy::UpdateSessionConnectionState(const int32_t &sessionID, const int32_t &state)
1213 {
1214 MessageParcel data;
1215 MessageParcel reply;
1216 MessageOption option;
1217
1218 bool ret = data.WriteInterfaceToken(GetDescriptor());
1219 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1220 data.WriteInt32(sessionID);
1221 data.WriteInt32(state);
1222
1223 int32_t error = Remote()->SendRequest(
1224 static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_SESSION_CONNECTION_STATE), data, reply, option);
1225 CHECK_AND_RETURN_LOG(error == ERR_NONE, "failed, error:%{public}d", error);
1226 }
1227
SetNonInterruptMute(const uint32_t sessionId,const bool muteFlag)1228 void AudioManagerProxy::SetNonInterruptMute(const uint32_t sessionId, const bool muteFlag)
1229 {
1230 MessageParcel data;
1231 MessageParcel reply;
1232 MessageOption option;
1233
1234 bool ret = data.WriteInterfaceToken(GetDescriptor());
1235 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1236 data.WriteUint32(sessionId);
1237 data.WriteBool(muteFlag);
1238
1239 int32_t error = Remote()->SendRequest(
1240 static_cast<uint32_t>(AudioServerInterfaceCode::SET_SINGLE_STREAM_MUTE), data, reply, option);
1241 CHECK_AND_RETURN_LOG(error == ERR_NONE, "failed, error:%{public}d", error);
1242 }
1243
SetOffloadMode(uint32_t sessionId,int32_t state,bool isAppBack)1244 int32_t AudioManagerProxy::SetOffloadMode(uint32_t sessionId, int32_t state, bool isAppBack)
1245 {
1246 MessageParcel data;
1247 MessageParcel reply;
1248 MessageOption option;
1249
1250 bool ret = data.WriteInterfaceToken(GetDescriptor());
1251 CHECK_AND_RETURN_RET_LOG(ret, -1, "AudioManagerProxy: WriteInterfaceToken failed");
1252 data.WriteUint32(sessionId);
1253 data.WriteInt32(state);
1254 data.WriteBool(isAppBack);
1255
1256 int32_t error = Remote()->SendRequest(
1257 static_cast<uint32_t>(AudioServerInterfaceCode::SET_OFFLOAD_MODE), data, reply, option);
1258 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SetOffloadMode failed, error: %{public}d", error);
1259 return reply.ReadInt32();
1260 }
1261
UnsetOffloadMode(uint32_t sessionId)1262 int32_t AudioManagerProxy::UnsetOffloadMode(uint32_t sessionId)
1263 {
1264 MessageParcel data;
1265 MessageParcel reply;
1266 MessageOption option;
1267
1268 bool ret = data.WriteInterfaceToken(GetDescriptor());
1269 CHECK_AND_RETURN_RET_LOG(ret, -1, "AudioManagerProxy: WriteInterfaceToken failed");
1270 data.WriteUint32(sessionId);
1271
1272 int32_t error = Remote()->SendRequest(
1273 static_cast<uint32_t>(AudioServerInterfaceCode::UNSET_OFFLOAD_MODE), data, reply, option);
1274 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "UnsetOffloadMode failed, error: %{public}d", error);
1275 return reply.ReadInt32();
1276 }
1277
RestoreSession(const uint32_t & sessionID,RestoreInfo restoreInfo)1278 void AudioManagerProxy::RestoreSession(const uint32_t &sessionID, RestoreInfo restoreInfo)
1279 {
1280 MessageParcel data;
1281 MessageParcel reply;
1282 MessageOption option;
1283
1284 bool ret = data.WriteInterfaceToken(GetDescriptor());
1285 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1286 data.WriteUint32(sessionID);
1287 data.WriteInt32(restoreInfo.restoreReason);
1288 data.WriteInt32(restoreInfo.deviceChangeReason);
1289 data.WriteInt32(restoreInfo.targetStreamFlag);
1290
1291 int32_t error = Remote()->SendRequest(
1292 static_cast<uint32_t>(AudioServerInterfaceCode::RESTORE_SESSION), data, reply, option);
1293 CHECK_AND_RETURN_LOG(error == ERR_NONE, "failed, error:%{public}d", error);
1294 }
1295
CreateIpcOfflineStream(int32_t & errorCode)1296 sptr<IRemoteObject> AudioManagerProxy::CreateIpcOfflineStream(int32_t &errorCode)
1297 {
1298 MessageParcel data;
1299 MessageParcel reply;
1300 MessageOption option;
1301
1302 bool ret = data.WriteInterfaceToken(GetDescriptor());
1303 CHECK_AND_RETURN_RET_LOG(ret, nullptr, "WriteInterfaceToken failed");
1304 int error = Remote()->SendRequest(
1305 static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_IPC_OFFLINE_STREAM), data, reply, option);
1306 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, nullptr, "CreateIpcOfflineStream failed, error: %{public}d", error);
1307 sptr<IRemoteObject> process = reply.ReadRemoteObject();
1308 errorCode = reply.ReadInt32();
1309 return process;
1310 }
1311
GetOfflineAudioEffectChains(vector<string> & effectChains)1312 int32_t AudioManagerProxy::GetOfflineAudioEffectChains(vector<string> &effectChains)
1313 {
1314 MessageParcel data;
1315 MessageParcel reply;
1316 MessageOption option;
1317
1318 bool ret = data.WriteInterfaceToken(GetDescriptor());
1319 CHECK_AND_RETURN_RET_LOG(ret, AUDIO_ERR, "WriteInterfaceToken failed");
1320 int error = Remote()->SendRequest(
1321 static_cast<uint32_t>(AudioServerInterfaceCode::GET_OFFLINE_AUDIO_EFFECT_CHAINS), data, reply, option);
1322 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "GetOfflineAudioEffectChains failed, error: %{public}d", error);
1323 int32_t vecSize = reply.ReadInt32();
1324 CHECK_AND_RETURN_RET_LOG(vecSize >= 0 && vecSize <= MAX_OFFLINE_EFFECT_CHAIN_NUM, AUDIO_ERR,
1325 "invalid offline effect chain num:%{public}d", vecSize);
1326 for (int i = 0; i < vecSize; i++) {
1327 effectChains.emplace_back(reply.ReadString());
1328 }
1329 return reply.ReadInt32();
1330 }
1331
CheckHibernateState(bool onHibernate)1332 void AudioManagerProxy::CheckHibernateState(bool onHibernate)
1333 {
1334 MessageParcel data;
1335 MessageParcel reply;
1336 MessageOption option;
1337
1338 bool ret = data.WriteInterfaceToken(GetDescriptor());
1339 CHECK_AND_RETURN_LOG(ret, "AudioManagerProxy: WriteInterfaceToken failed");
1340 data.WriteBool(onHibernate);
1341
1342 int32_t error = Remote()->SendRequest(
1343 static_cast<uint32_t>(AudioServerInterfaceCode::CHECK_HIBERNATE_STATE), data, reply, option);
1344 CHECK_AND_RETURN_LOG(error == ERR_NONE, "CheckHibernateState failed, error: %{public}d", error);
1345 return;
1346 }
1347
GetStandbyStatus(uint32_t sessionId,bool & isStandby,int64_t & enterStandbyTime)1348 int32_t AudioManagerProxy::GetStandbyStatus(uint32_t sessionId, bool &isStandby, int64_t &enterStandbyTime)
1349 {
1350 MessageParcel data;
1351 MessageParcel reply;
1352 MessageOption option;
1353
1354 int32_t result = ERROR;
1355 bool ret = data.WriteInterfaceToken(GetDescriptor());
1356 CHECK_AND_RETURN_RET_LOG(ret, result, "WriteInterfaceToken failed");
1357
1358 data.WriteUint32(sessionId);
1359
1360 int32_t error = Remote()->SendRequest(static_cast<uint32_t>(AudioServerInterfaceCode::GET_STANDBY_STATUS), data,
1361 reply, option);
1362 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, result, "get transaction id failed, error: %d", error);
1363
1364 result = reply.ReadInt32();
1365 isStandby = reply.ReadBool();
1366 enterStandbyTime = reply.ReadInt64();
1367
1368 return result;
1369 }
1370
GenerateSessionId(uint32_t & sessionId)1371 int32_t AudioManagerProxy::GenerateSessionId(uint32_t &sessionId)
1372 {
1373 MessageParcel data;
1374 MessageParcel reply;
1375 MessageOption option;
1376
1377 bool ret = data.WriteInterfaceToken(GetDescriptor());
1378 CHECK_AND_RETURN_RET_LOG(ret, AUDIO_ERR, "WriteInterfaceToken failed");
1379 data.WriteUint32(sessionId);
1380
1381 int32_t error = Remote()->SendRequest(
1382 static_cast<uint32_t>(AudioServerInterfaceCode::GENERATE_SESSION_ID), data, reply, option);
1383 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "generate sessionid failed,error:%{public}d", error);
1384 sessionId = reply.ReadUint32();
1385 return 0;
1386 }
1387
NotifyAccountsChanged()1388 void AudioManagerProxy::NotifyAccountsChanged()
1389 {
1390 MessageParcel data;
1391 MessageParcel reply;
1392 MessageOption option;
1393
1394 bool ret = data.WriteInterfaceToken(GetDescriptor());
1395 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1396
1397 int32_t error = Remote()->SendRequest(
1398 static_cast<uint32_t>(AudioServerInterfaceCode::NOTIFY_ACCOUNTS_CHANGED), data, reply, option);
1399 CHECK_AND_RETURN_LOG(error == ERR_NONE, "failed,error:%d", error);
1400 }
1401
GetAllSinkInputs(std::vector<SinkInput> & sinkInputs)1402 void AudioManagerProxy::GetAllSinkInputs(std::vector<SinkInput> &sinkInputs)
1403 {
1404 MessageParcel data;
1405 MessageParcel reply;
1406 MessageOption option;
1407
1408 bool ret = data.WriteInterfaceToken(GetDescriptor());
1409 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1410
1411 int32_t error = Remote()->SendRequest(
1412 static_cast<uint32_t>(AudioServerInterfaceCode::GET_ALL_SINK_INPUTS), data, reply, option);
1413 CHECK_AND_RETURN_LOG(error == ERR_NONE, "getallsinkinputs failed, error: %{public}d", error);
1414 size_t size = reply.ReadUint64();
1415 CHECK_AND_RETURN_LOG(size <= DEFAULT_MAX_RENDERER_INSTANCES, "getallsinkinputs failed, size: %{public}zu", size);
1416 while (size > 0) {
1417 SinkInput sinkInput;
1418 sinkInput.Unmarshalling(reply);
1419 sinkInputs.push_back(sinkInput);
1420 size--;
1421 }
1422 }
1423
SetDefaultAdapterEnable(bool isEnable)1424 void AudioManagerProxy::SetDefaultAdapterEnable(bool isEnable)
1425 {
1426 MessageParcel data;
1427 MessageParcel reply;
1428 MessageOption option;
1429
1430 bool ret = data.WriteInterfaceToken(GetDescriptor());
1431 CHECK_AND_RETURN_LOG(ret, "AudioManagerProxy: WriteInterfaceToken failed");
1432 data.WriteBool(isEnable);
1433
1434 int32_t error = Remote()->SendRequest(
1435 static_cast<uint32_t>(AudioServerInterfaceCode::SET_DEFAULT_ADAPTER_ENABLE), data, reply, option);
1436 CHECK_AND_RETURN_LOG(error == ERR_NONE, "SetDefaultAdapterEnable failed, error: %{public}d", error);
1437 return;
1438 }
1439
NotifyAudioPolicyReady()1440 void AudioManagerProxy::NotifyAudioPolicyReady()
1441 {
1442 MessageParcel data;
1443 MessageParcel reply;
1444 MessageOption option;
1445
1446 bool ret = data.WriteInterfaceToken(GetDescriptor());
1447 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1448
1449 int32_t error = Remote()->SendRequest(
1450 static_cast<uint32_t>(AudioServerInterfaceCode::NOTIFY_AUDIO_POLICY_READY), data, reply, option);
1451 CHECK_AND_RETURN_LOG(error == ERR_NONE, "failed,error:%d", error);
1452 }
1453
1454 #ifdef HAS_FEATURE_INNERCAPTURER
SetInnerCapLimit(uint32_t innerCapLimit)1455 int32_t AudioManagerProxy::SetInnerCapLimit(uint32_t innerCapLimit)
1456 {
1457 MessageParcel data;
1458 MessageParcel reply;
1459 MessageOption option;
1460 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), AUDIO_ERR, "Write descriptor failed!");
1461 data.WriteUint32(innerCapLimit);
1462 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(AudioServerInterfaceCode::SET_CAPTURE_LIMIT),
1463 data, reply, option);
1464 CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK, ret, "Failed, ipc error: %{public}d", ret);
1465 return reply.ReadInt32();
1466 }
1467
1468 // for DT test
CheckCaptureLimit(const AudioPlaybackCaptureConfig & config,int32_t & innerCapId)1469 int32_t AudioManagerProxy::CheckCaptureLimit(const AudioPlaybackCaptureConfig &config, int32_t &innerCapId)
1470 {
1471 MessageParcel data;
1472 MessageParcel reply;
1473 MessageOption option;
1474 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), AUDIO_ERR, "Write descriptor failed!");
1475 ProcessConfig::WriteInnerCapConfigToParcel(config, data);
1476 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(AudioServerInterfaceCode::CHECK_CAPTURE_LIMIT),
1477 data, reply, option);
1478 CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK, ret, "Failed, ipc error: %{public}d", ret);
1479 return reply.ReadInt32();
1480 }
1481
1482 // for DT test
ReleaseCaptureLimit(int32_t innerCapId)1483 int32_t AudioManagerProxy::ReleaseCaptureLimit(int32_t innerCapId)
1484 {
1485 MessageParcel data;
1486 MessageParcel reply;
1487 MessageOption option;
1488 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), AUDIO_ERR, "Write descriptor failed!");
1489 data.WriteInt32(innerCapId);
1490 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(AudioServerInterfaceCode::RELEASE_CAPTURE_LIMIT),
1491 data, reply, option);
1492 CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK, ret, "Failed, ipc error: %{public}d", ret);
1493 return reply.ReadInt32();
1494 }
1495 #endif
1496
LoadHdiAdapter(uint32_t devMgrType,const std::string & adapterName)1497 int32_t AudioManagerProxy::LoadHdiAdapter(uint32_t devMgrType, const std::string &adapterName)
1498 {
1499 MessageParcel data;
1500 MessageParcel reply;
1501 MessageOption option;
1502
1503 bool ret = data.WriteInterfaceToken(GetDescriptor());
1504 CHECK_AND_RETURN_RET_LOG(ret, AUDIO_ERR, "WriteInterfaceToken failed");
1505 data.WriteUint32(devMgrType);
1506 data.WriteString(adapterName);
1507
1508 int32_t error = Remote()->SendRequest(
1509 static_cast<uint32_t>(AudioServerInterfaceCode::LOAD_HDI_ADAPTER), data, reply, option);
1510 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "LoadHdiAdapter failed, error: %{public}d", error);
1511 return reply.ReadInt32();
1512 }
1513
UnloadHdiAdapter(uint32_t devMgrType,const std::string & adapterName,bool force)1514 void AudioManagerProxy::UnloadHdiAdapter(uint32_t devMgrType, const std::string &adapterName, bool force)
1515 {
1516 MessageParcel data;
1517 MessageParcel reply;
1518 MessageOption option;
1519
1520 bool ret = data.WriteInterfaceToken(GetDescriptor());
1521 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1522 data.WriteUint32(devMgrType);
1523 data.WriteString(adapterName);
1524 data.WriteBool(force);
1525
1526 int32_t error = Remote()->SendRequest(
1527 static_cast<uint32_t>(AudioServerInterfaceCode::UNLOAD_HDI_ADAPTER), data, reply, option);
1528 CHECK_AND_RETURN_LOG(error == ERR_NONE, "UnloadHdiAdapter failed, error: %{public}d", error);
1529 }
1530
SetDeviceConnectedFlag(bool flag)1531 void AudioManagerProxy::SetDeviceConnectedFlag(bool flag)
1532 {
1533 MessageParcel data;
1534 MessageParcel reply;
1535 MessageOption option;
1536
1537 bool ret = data.WriteInterfaceToken(GetDescriptor());
1538 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1539
1540 data.WriteBool(flag);
1541
1542 int32_t error = Remote()->SendRequest(
1543 static_cast<uint32_t>(AudioServerInterfaceCode::DEVICE_CONNECTED_FLAG), data, reply, option);
1544 CHECK_AND_RETURN_LOG(error == ERR_NONE, "failed,error:%d", error);
1545 }
1546
NotifySettingsDataReady()1547 void AudioManagerProxy::NotifySettingsDataReady()
1548 {
1549 MessageParcel data;
1550 MessageParcel reply;
1551 MessageOption option;
1552
1553 bool ret = data.WriteInterfaceToken(GetDescriptor());
1554 CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1555
1556 int32_t error = Remote()->SendRequest(
1557 static_cast<uint32_t>(AudioServerInterfaceCode::NOTIFY_SETTINGS_DATA_READY), data, reply, option);
1558 CHECK_AND_RETURN_LOG(error == ERR_NONE, "failed,error:%d", error);
1559 }
1560 } // namespace AudioStandard
1561 } // namespace OHOS
1562