• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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_system_manager.h"
24 #include "audio_service_log.h"
25 #include "audio_utils.h"
26 #include "i_audio_process.h"
27 
28 using namespace std;
29 
30 namespace OHOS {
31 namespace AudioStandard {
AudioManagerProxy(const sptr<IRemoteObject> & impl)32 AudioManagerProxy::AudioManagerProxy(const sptr<IRemoteObject> &impl)
33     : IRemoteProxy<IStandardAudioService>(impl)
34 {
35 }
36 
SetMicrophoneMute(bool isMute)37 int32_t AudioManagerProxy::SetMicrophoneMute(bool isMute)
38 {
39     MessageParcel data;
40     MessageParcel reply;
41     MessageOption option;
42 
43     bool ret = data.WriteInterfaceToken(GetDescriptor());
44     CHECK_AND_RETURN_RET_LOG(ret, -1, "AudioManagerProxy: WriteInterfaceToken failed");
45     data.WriteBool(isMute);
46     int32_t error = Remote()->SendRequest(
47         static_cast<uint32_t>(AudioServerInterfaceCode::SET_MICROPHONE_MUTE), data, reply, option);
48     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
49         "SetMicrophoneMute failed, error: %d", error);
50 
51     int32_t result = reply.ReadInt32();
52     return result;
53 }
54 
SetVoiceVolume(float volume)55 int32_t AudioManagerProxy::SetVoiceVolume(float volume)
56 {
57     MessageParcel data;
58     MessageParcel reply;
59     MessageOption option;
60 
61     bool ret = data.WriteInterfaceToken(GetDescriptor());
62     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
63 
64     data.WriteFloat(volume);
65 
66     int32_t error = Remote()->SendRequest(
67         static_cast<uint32_t>(AudioServerInterfaceCode::SET_VOICE_VOLUME), data, reply, option);
68     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false,
69         "SetVoiceVolume failed, error: %d", error);
70 
71     int32_t result = reply.ReadInt32();
72     return result;
73 }
74 
OffloadSetVolume(float volume)75 int32_t AudioManagerProxy::OffloadSetVolume(float volume)
76 {
77     MessageParcel data;
78     MessageParcel reply;
79     MessageOption option;
80 
81     bool ret = data.WriteInterfaceToken(GetDescriptor());
82     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
83 
84     data.WriteFloat(volume);
85 
86     int32_t error = Remote()->SendRequest(
87         static_cast<uint32_t>(AudioServerInterfaceCode::OFFLOAD_SET_VOLUME), data, reply, option);
88     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "OffloadSetVolume failed, error: %d", error);
89 
90     int32_t result = reply.ReadInt32();
91     return result;
92 }
93 
SetAudioScene(AudioScene audioScene,std::vector<DeviceType> & activeOutputDevices,DeviceType activeInputDevice,BluetoothOffloadState a2dpOffloadFlag)94 int32_t AudioManagerProxy::SetAudioScene(AudioScene audioScene, std::vector<DeviceType> &activeOutputDevices,
95     DeviceType activeInputDevice, BluetoothOffloadState a2dpOffloadFlag)
96 {
97     CHECK_AND_RETURN_RET_LOG(!activeOutputDevices.empty() &&
98         activeOutputDevices.size() <= AUDIO_CONCURRENT_ACTIVE_DEVICES_LIMIT,
99         ERR_NONE, "Invalid active output devices.");
100     MessageParcel data;
101     MessageParcel reply;
102     MessageOption option;
103 
104     bool ret = data.WriteInterfaceToken(GetDescriptor());
105     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
106 
107     data.WriteInt32(static_cast<int32_t>(audioScene));
108 
109     data.WriteInt32(static_cast<int32_t>(activeOutputDevices.size()));
110     for (auto activeOutputDevice : activeOutputDevices) {
111         data.WriteInt32(static_cast<int32_t>(activeOutputDevice));
112     }
113     data.WriteInt32(static_cast<int32_t>(activeInputDevice));
114     data.WriteInt32(static_cast<int32_t>(a2dpOffloadFlag));
115 
116     int32_t error = Remote()->SendRequest(
117         static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_SCENE), data, reply, option);
118     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "SetAudioScene failed, error: %d", error);
119 
120     int32_t result = reply.ReadInt32();
121     return result;
122 }
123 
GetAudioParameter(const std::string & key)124 const std::string AudioManagerProxy::GetAudioParameter(const std::string &key)
125 {
126     MessageParcel data;
127     MessageParcel reply;
128     MessageOption option;
129 
130     bool ret = data.WriteInterfaceToken(GetDescriptor());
131     CHECK_AND_RETURN_RET_LOG(ret, "", "WriteInterfaceToken failed");
132     data.WriteString(static_cast<std::string>(key));
133     int32_t error = Remote()->SendRequest(
134         static_cast<uint32_t>(AudioServerInterfaceCode::GET_AUDIO_PARAMETER), data, reply, option);
135     if (error != ERR_NONE) {
136         AUDIO_ERR_LOG("Get audio parameter failed, error: %d", error);
137         const std::string value = "";
138         return value;
139     }
140 
141     const std::string value = reply.ReadString();
142     return value;
143 }
144 
GetAudioParameter(const std::string & networkId,const AudioParamKey key,const std::string & condition)145 const std::string AudioManagerProxy::GetAudioParameter(const std::string& networkId, const AudioParamKey key,
146     const std::string& condition)
147 {
148     MessageParcel data;
149     MessageParcel reply;
150     MessageOption option;
151 
152     bool ret = data.WriteInterfaceToken(GetDescriptor());
153     CHECK_AND_RETURN_RET_LOG(ret, "", "WriteInterfaceToken failed");
154     data.WriteString(static_cast<std::string>(networkId));
155     data.WriteInt32(static_cast<int32_t>(key));
156     data.WriteString(static_cast<std::string>(condition));
157     int32_t error = Remote()->SendRequest(
158         static_cast<uint32_t>(AudioServerInterfaceCode::GET_REMOTE_AUDIO_PARAMETER), data, reply, option);
159     if (error != ERR_NONE) {
160         AUDIO_ERR_LOG("Get audio parameter failed, error: %d", error);
161         const std::string value = "";
162         return value;
163     }
164 
165     const std::string value = reply.ReadString();
166     return value;
167 }
168 
GetExtraParameters(const std::string & mainKey,const std::vector<std::string> & subKeys,std::vector<std::pair<std::string,std::string>> & result)169 int32_t AudioManagerProxy::GetExtraParameters(const std::string &mainKey, const std::vector<std::string> &subKeys,
170     std::vector<std::pair<std::string, std::string>> &result)
171 {
172     MessageParcel data;
173     MessageParcel reply;
174     MessageOption option;
175 
176     bool ret = data.WriteInterfaceToken(GetDescriptor());
177     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
178     data.WriteString(static_cast<std::string>(mainKey));
179     data.WriteInt32(static_cast<int32_t>(subKeys.size()));
180     for (std::string subKey : subKeys) {
181         data.WriteString(static_cast<std::string>(subKey));
182     }
183     int32_t error = Remote()->SendRequest(
184         static_cast<uint32_t>(AudioServerInterfaceCode::GET_EXTRA_AUDIO_PARAMETERS), data, reply, option);
185     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get extra audio parameters failed, error: %d", error);
186 
187     int32_t num = reply.ReadInt32();
188     for (auto i = 0; i < num; i++) {
189         const std::string key = reply.ReadString();
190         const std::string value = reply.ReadString();
191         result.push_back(std::make_pair(key, value));
192     }
193     return reply.ReadInt32();
194 }
195 
SetAudioParameter(const std::string & key,const std::string & value)196 void AudioManagerProxy::SetAudioParameter(const std::string &key, const std::string &value)
197 {
198     MessageParcel data;
199     MessageParcel reply;
200     MessageOption option;
201 
202     bool ret = data.WriteInterfaceToken(GetDescriptor());
203     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
204     data.WriteString(static_cast<std::string>(key));
205     data.WriteString(static_cast<std::string>(value));
206     int32_t error = Remote()->SendRequest(
207         static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_PARAMETER), data, reply, option);
208     CHECK_AND_RETURN_LOG(error == ERR_NONE, "Get audio parameter failed, error: %d", error);
209 }
210 
SetAudioParameter(const std::string & networkId,const AudioParamKey key,const std::string & condition,const std::string & value)211 void AudioManagerProxy::SetAudioParameter(const std::string& networkId, const AudioParamKey key,
212     const std::string& condition, const std::string& value)
213 {
214     MessageParcel data;
215     MessageParcel reply;
216     MessageOption option;
217 
218     bool ret = data.WriteInterfaceToken(GetDescriptor());
219     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
220     data.WriteString(static_cast<std::string>(networkId));
221     data.WriteInt32(static_cast<int32_t>(key));
222     data.WriteString(static_cast<std::string>(condition));
223     data.WriteString(static_cast<std::string>(value));
224     int32_t error = Remote()->SendRequest(
225         static_cast<uint32_t>(AudioServerInterfaceCode::SET_REMOTE_AUDIO_PARAMETER), data, reply, option);
226     CHECK_AND_RETURN_LOG(error == ERR_NONE, "Get audio parameter failed, error: %d", error);
227 }
228 
SetExtraParameters(const std::string & key,const std::vector<std::pair<std::string,std::string>> & kvpairs)229 int32_t AudioManagerProxy::SetExtraParameters(const std::string &key,
230     const std::vector<std::pair<std::string, std::string>> &kvpairs)
231 {
232     MessageParcel data;
233     MessageParcel reply;
234     MessageOption option;
235 
236     bool ret = data.WriteInterfaceToken(GetDescriptor());
237     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
238     data.WriteString(static_cast<std::string>(key));
239     data.WriteInt32(static_cast<int32_t>(kvpairs.size()));
240     for (auto it = kvpairs.begin(); it != kvpairs.end(); it++) {
241         data.WriteString(static_cast<std::string>(it->first));
242         data.WriteString(static_cast<std::string>(it->second));
243     }
244 
245     int32_t error = Remote()->SendRequest(
246         static_cast<uint32_t>(AudioServerInterfaceCode::SET_EXTRA_AUDIO_PARAMETERS), data, reply, option);
247     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Set extra audio parameters failed, error: %d", error);
248     return reply.ReadInt32();
249 }
250 
SetAsrAecMode(AsrAecMode asrAecMode)251 int32_t AudioManagerProxy::SetAsrAecMode(AsrAecMode asrAecMode)
252 {
253     MessageParcel data;
254     MessageParcel reply;
255     MessageOption option;
256 
257     bool ret = data.WriteInterfaceToken(GetDescriptor());
258     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
259     data.WriteInt32(static_cast<int32_t>(asrAecMode));
260 
261     int32_t error = Remote()->SendRequest(
262         static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_AEC_MODE), data, reply, option);
263     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, -1, "failed,error:%d", error);
264     int32_t result = reply.ReadInt32();
265     return result;
266 }
267 
GetAsrAecMode(AsrAecMode & asrAecMode)268 int32_t AudioManagerProxy::GetAsrAecMode(AsrAecMode &asrAecMode)
269 {
270     MessageParcel data;
271     MessageParcel reply;
272     MessageOption option;
273 
274     bool ret = data.WriteInterfaceToken(GetDescriptor());
275     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
276     data.WriteInt32(static_cast<int32_t>(asrAecMode));
277 
278     int32_t error = Remote()->SendRequest(
279         static_cast<uint32_t>(AudioServerInterfaceCode::GET_ASR_AEC_MODE), data, reply, option);
280     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, -1, "failed,error:%d", error);
281     int32_t result = reply.ReadInt32();
282     asrAecMode = static_cast<AsrAecMode>(result);
283     return 0;
284 }
285 
SetAsrNoiseSuppressionMode(AsrNoiseSuppressionMode asrNoiseSuppressionMode)286 int32_t AudioManagerProxy::SetAsrNoiseSuppressionMode(AsrNoiseSuppressionMode asrNoiseSuppressionMode)
287 {
288     MessageParcel data;
289     MessageParcel reply;
290     MessageOption option;
291 
292     bool ret = data.WriteInterfaceToken(GetDescriptor());
293     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
294     data.WriteInt32(static_cast<int32_t>(asrNoiseSuppressionMode));
295 
296     int32_t error = Remote()->SendRequest(
297         static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_NOISE_SUPPRESSION_MODE), data, reply, option);
298     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, -1, "failed,error:%d", error);
299     int32_t result = reply.ReadInt32();
300     return result;
301 }
302 
GetAsrNoiseSuppressionMode(AsrNoiseSuppressionMode & asrNoiseSuppressionMode)303 int32_t AudioManagerProxy::GetAsrNoiseSuppressionMode(AsrNoiseSuppressionMode &asrNoiseSuppressionMode)
304 {
305     MessageParcel data;
306     MessageParcel reply;
307     MessageOption option;
308 
309     bool ret = data.WriteInterfaceToken(GetDescriptor());
310     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
311     data.WriteInt32(static_cast<int32_t>(asrNoiseSuppressionMode));
312 
313     int32_t error = Remote()->SendRequest(
314         static_cast<uint32_t>(AudioServerInterfaceCode::GET_ASR_NOISE_SUPPRESSION_MODE), data, reply, option);
315     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, -1, "failed,error:%d", error);
316     int32_t result = reply.ReadInt32();
317     asrNoiseSuppressionMode = static_cast<AsrNoiseSuppressionMode>(result);
318     return 0;
319 }
320 
SetAsrWhisperDetectionMode(AsrWhisperDetectionMode asrWhisperDetectionMode)321 int32_t AudioManagerProxy::SetAsrWhisperDetectionMode(AsrWhisperDetectionMode asrWhisperDetectionMode)
322 {
323     MessageParcel data;
324     MessageParcel reply;
325     MessageOption option;
326 
327     bool ret = data.WriteInterfaceToken(GetDescriptor());
328     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
329     data.WriteInt32(static_cast<int32_t>(asrWhisperDetectionMode));
330 
331     int32_t error = Remote()->SendRequest(static_cast<uint32_t>(
332         AudioServerInterfaceCode::SET_ASR_WHISPER_DETECTION_MODE), data, reply, option);
333     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, -1, "failed,error:%d", error);
334     int32_t result = reply.ReadInt32();
335     return result;
336 }
337 
GetAsrWhisperDetectionMode(AsrWhisperDetectionMode & asrWhisperDetectionMode)338 int32_t AudioManagerProxy::GetAsrWhisperDetectionMode(AsrWhisperDetectionMode &asrWhisperDetectionMode)
339 {
340     MessageParcel data;
341     MessageParcel reply;
342     MessageOption option;
343 
344     bool ret = data.WriteInterfaceToken(GetDescriptor());
345     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
346     data.WriteInt32(static_cast<int32_t>(asrWhisperDetectionMode));
347 
348     int32_t error = Remote()->SendRequest(
349         static_cast<uint32_t>(AudioServerInterfaceCode::GET_ASR_WHISPER_DETECTION_MODE), data, reply, option);
350     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, -1, "failed,error:%d", error);
351     int32_t result = reply.ReadInt32();
352     asrWhisperDetectionMode = static_cast<AsrWhisperDetectionMode>(result);
353     return 0;
354 }
355 
SetAsrVoiceControlMode(AsrVoiceControlMode asrVoiceControlMode,bool on)356 int32_t AudioManagerProxy::SetAsrVoiceControlMode(AsrVoiceControlMode asrVoiceControlMode, bool on)
357 {
358     MessageParcel data;
359     MessageParcel reply;
360     MessageOption option;
361 
362     bool ret = data.WriteInterfaceToken(GetDescriptor());
363     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
364     data.WriteInt32(static_cast<int32_t>(asrVoiceControlMode));
365     data.WriteBool(on);
366 
367     int32_t error = Remote()->SendRequest(static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_VOICE_CONTROL_MODE),
368         data, reply, option);
369     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, -1, "failed,error:%d", error);
370     int32_t result = reply.ReadInt32();
371     return result;
372 }
373 
SetAsrVoiceMuteMode(AsrVoiceMuteMode asrVoiceMuteMode,bool on)374 int32_t AudioManagerProxy::SetAsrVoiceMuteMode(AsrVoiceMuteMode asrVoiceMuteMode, bool on)
375 {
376     MessageParcel data;
377     MessageParcel reply;
378     MessageOption option;
379 
380     bool ret = data.WriteInterfaceToken(GetDescriptor());
381     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
382     data.WriteInt32(static_cast<int32_t>(asrVoiceMuteMode));
383     data.WriteBool(on);
384 
385     int32_t error = Remote()->SendRequest(static_cast<uint32_t>(AudioServerInterfaceCode::SET_ASR_VOICE_MUTE_MODE),
386         data, reply, option);
387     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, -1, "failed,error:%d", error);
388     int32_t result = reply.ReadInt32();
389     return result;
390 }
391 
IsWhispering()392 int32_t AudioManagerProxy::IsWhispering()
393 {
394     MessageParcel data;
395     MessageParcel reply;
396     MessageOption option;
397 
398     bool ret = data.WriteInterfaceToken(GetDescriptor());
399     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
400 
401     int32_t result = Remote()->SendRequest(
402         static_cast<uint32_t>(AudioServerInterfaceCode::IS_WHISPERING), data, reply, option);
403     return result;
404 }
405 
GetEffectOffloadEnabled()406 bool AudioManagerProxy::GetEffectOffloadEnabled()
407 {
408     MessageParcel data;
409     MessageParcel reply;
410     MessageOption option;
411 
412     bool ret = data.WriteInterfaceToken(GetDescriptor());
413     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
414 
415     int32_t error = Remote()->SendRequest(
416         static_cast<uint32_t>(AudioServerInterfaceCode::GET_EFFECT_OFFLOAD_ENABLED), data, reply, option);
417     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "failed,error:%d", error);
418     bool result = reply.ReadBool();
419     return result;
420 }
421 
GetTransactionId(DeviceType deviceType,DeviceRole deviceRole)422 uint64_t AudioManagerProxy::GetTransactionId(DeviceType deviceType, DeviceRole deviceRole)
423 {
424     MessageParcel data;
425     MessageParcel reply;
426     MessageOption option;
427     uint32_t transactionId = 0;
428 
429     bool ret = data.WriteInterfaceToken(GetDescriptor());
430     CHECK_AND_RETURN_RET_LOG(ret, transactionId, "WriteInterfaceToken failed");
431 
432     data.WriteInt32(static_cast<int32_t>(deviceType));
433     data.WriteInt32(static_cast<int32_t>(deviceRole));
434 
435     int32_t error = Remote()->SendRequest(
436         static_cast<uint32_t>(AudioServerInterfaceCode::GET_TRANSACTION_ID), data, reply, option);
437     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, transactionId, "get transaction id failed, error: %d", error);
438 
439     transactionId = reply.ReadUint64();
440 
441     return transactionId;
442 }
443 
NotifyDeviceInfo(std::string networkId,bool connected)444 void AudioManagerProxy::NotifyDeviceInfo(std::string networkId, bool connected)
445 {
446     MessageParcel data;
447     MessageParcel reply;
448     MessageOption option;
449 
450     bool ret = data.WriteInterfaceToken(GetDescriptor());
451     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
452     data.WriteString(networkId);
453     data.WriteBool(connected);
454     int32_t error = Remote()->SendRequest(
455         static_cast<uint32_t>(AudioServerInterfaceCode::NOTIFY_DEVICE_INFO), data, reply, option);
456     CHECK_AND_RETURN_LOG(error == ERR_NONE, "Get audio parameter failed, error: %d", error);
457 }
458 
CheckRemoteDeviceState(std::string networkId,DeviceRole deviceRole,bool isStartDevice)459 int32_t AudioManagerProxy::CheckRemoteDeviceState(std::string networkId, DeviceRole deviceRole, bool isStartDevice)
460 {
461     MessageParcel data;
462     MessageParcel reply;
463     MessageOption option;
464 
465     bool ret = data.WriteInterfaceToken(GetDescriptor());
466     CHECK_AND_RETURN_RET_LOG(ret, ERR_TRANSACTION_FAILED, "WriteInterfaceToken failed");
467     data.WriteString(networkId);
468     data.WriteInt32(static_cast<int32_t>(deviceRole));
469     data.WriteBool(isStartDevice);
470     int32_t error = Remote()->SendRequest(
471         static_cast<uint32_t>(AudioServerInterfaceCode::CHECK_REMOTE_DEVICE_STATE), data, reply, option);
472     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "CheckRemoteDeviceState failed in proxy, error: %d", error);
473     return reply.ReadInt32();
474 }
475 
UpdateActiveDeviceRoute(DeviceType type,DeviceFlag flag,BluetoothOffloadState a2dpOffloadFlag)476 int32_t AudioManagerProxy::UpdateActiveDeviceRoute(DeviceType type, DeviceFlag flag,
477     BluetoothOffloadState a2dpOffloadFlag)
478 {
479     MessageParcel data;
480     MessageParcel reply;
481     MessageOption option;
482 
483     bool ret = data.WriteInterfaceToken(GetDescriptor());
484     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
485 
486     data.WriteInt32(type);
487     data.WriteInt32(flag);
488     data.WriteInt32(static_cast<int32_t>(a2dpOffloadFlag));
489 
490     auto error = Remote()->SendRequest(
491         static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_ROUTE_REQ), data, reply, option);
492     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "UpdateActiveDeviceRoute failed, error: %{public}d", error);
493 
494     auto result = reply.ReadInt32();
495     AUDIO_DEBUG_LOG("[UPDATE_ROUTE_REQ] result %{public}d", result);
496     return result;
497 }
498 
UpdateActiveDevicesRoute(std::vector<std::pair<DeviceType,DeviceFlag>> & activeDevices,BluetoothOffloadState a2dpOffloadFlag)499 int32_t AudioManagerProxy::UpdateActiveDevicesRoute(std::vector<std::pair<DeviceType, DeviceFlag>> &activeDevices,
500     BluetoothOffloadState a2dpOffloadFlag)
501 {
502     CHECK_AND_RETURN_RET_LOG(!activeDevices.empty() && activeDevices.size() <= AUDIO_CONCURRENT_ACTIVE_DEVICES_LIMIT,
503         ERR_NONE, "Invalid active output devices.");
504     MessageParcel data;
505     MessageParcel reply;
506     MessageOption option;
507 
508     bool ret = data.WriteInterfaceToken(GetDescriptor());
509     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
510     data.WriteInt32(static_cast<int32_t>(activeDevices.size()));
511     for (auto it = activeDevices.begin(); it != activeDevices.end(); it++) {
512         data.WriteInt32(static_cast<int32_t>(it->first));
513         data.WriteInt32(static_cast<int32_t>(it->second));
514     }
515     data.WriteInt32(static_cast<int32_t>(a2dpOffloadFlag));
516 
517     auto error = Remote()->SendRequest(
518         static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_ROUTES_REQ), data, reply, option);
519     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "UpdateActiveDevicesRoute failed, error: %{public}d", error);
520 
521     auto result = reply.ReadInt32();
522     AUDIO_DEBUG_LOG("[UPDATE_ROUTES_REQ] result %{public}d", result);
523     return result;
524 }
525 
UpdateDualToneState(bool enable,int32_t sessionId)526 int32_t AudioManagerProxy::UpdateDualToneState(bool enable, int32_t sessionId)
527 {
528     MessageParcel data;
529     MessageParcel reply;
530     MessageOption option;
531 
532     bool ret = data.WriteInterfaceToken(GetDescriptor());
533     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
534 
535     data.WriteBool(enable);
536     data.WriteInt32(sessionId);
537     auto error = Remote()->SendRequest(
538         static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_DUAL_TONE_REQ), data, reply, option);
539     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "UpdateDualToneState failed, error: %{public}d", error);
540 
541     auto result = reply.ReadInt32();
542     AUDIO_DEBUG_LOG("[UPDATE_DUAL_TONE_REQ] result %{public}d", result);
543     return result;
544 }
545 
SetParameterCallback(const sptr<IRemoteObject> & object)546 int32_t AudioManagerProxy::SetParameterCallback(const sptr<IRemoteObject>& object)
547 {
548     MessageParcel data;
549     MessageParcel reply;
550     MessageOption option;
551 
552     CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "object is null");
553 
554     bool ret = data.WriteInterfaceToken(GetDescriptor());
555     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
556 
557     (void)data.WriteRemoteObject(object);
558     int error = Remote()->SendRequest(
559         static_cast<uint32_t>(AudioServerInterfaceCode::SET_PARAMETER_CALLBACK), data, reply, option);
560     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
561         "SetParameterCallback failed, error: %{public}d", error);
562 
563     return reply.ReadInt32();
564 }
565 
RegiestPolicyProvider(const sptr<IRemoteObject> & object)566 int32_t AudioManagerProxy::RegiestPolicyProvider(const sptr<IRemoteObject> &object)
567 {
568     MessageParcel data;
569     MessageParcel reply;
570     MessageOption option(MessageOption::TF_ASYNC);
571 
572     CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "object is null");
573     bool ret = data.WriteInterfaceToken(GetDescriptor());
574     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
575 
576     (void)data.WriteRemoteObject(object);
577     int error = Remote()->SendRequest(static_cast<uint32_t>(AudioServerInterfaceCode::REGISET_POLICY_PROVIDER), data,
578         reply, option);
579     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
580         "RegiestPolicyProvider failed, error: %{public}d", error);
581 
582     return reply.ReadInt32();
583 }
584 
SetWakeupSourceCallback(const sptr<IRemoteObject> & object)585 int32_t AudioManagerProxy::SetWakeupSourceCallback(const sptr<IRemoteObject>& object)
586 {
587     MessageParcel data;
588     MessageParcel reply;
589     MessageOption option;
590 
591     CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "object is null");
592     bool ret = data.WriteInterfaceToken(GetDescriptor());
593     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
594 
595     (void)data.WriteRemoteObject(object);
596     int error = Remote()->SendRequest(
597         static_cast<uint32_t>(AudioServerInterfaceCode::SET_WAKEUP_CLOSE_CALLBACK), data, reply, option);
598     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
599         "SetWakeupCloseCallback failed, error: %{public}d", error);
600 
601     return reply.ReadInt32();
602 }
603 
SetAudioMonoState(bool audioMono)604 void AudioManagerProxy::SetAudioMonoState(bool audioMono)
605 {
606     MessageParcel data;
607     MessageParcel reply;
608     MessageOption option;
609 
610     bool ret = data.WriteInterfaceToken(GetDescriptor());
611     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
612     (void)data.WriteBool(audioMono);
613     int error = Remote()->SendRequest(
614         static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_MONO_STATE), data, reply, option);
615     CHECK_AND_RETURN_LOG(error == ERR_NONE, "SetAudioMonoState failed, error: %{public}d", error);
616 }
617 
SetAudioBalanceValue(float audioBalance)618 void AudioManagerProxy::SetAudioBalanceValue(float audioBalance)
619 {
620     MessageParcel data;
621     MessageParcel reply;
622     MessageOption option;
623 
624     bool ret = data.WriteInterfaceToken(GetDescriptor());
625     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
626     (void)data.WriteFloat(audioBalance);
627     int error = Remote()->SendRequest(
628         static_cast<uint32_t>(AudioServerInterfaceCode::SET_AUDIO_BALANCE_VALUE), data, reply, option);
629     CHECK_AND_RETURN_LOG(error == ERR_NONE, "SetAudioBalanceValue failed, error: %{public}d", error);
630 }
631 
CreateAudioProcess(const AudioProcessConfig & config,int32_t & errorCode)632 sptr<IRemoteObject> AudioManagerProxy::CreateAudioProcess(const AudioProcessConfig &config, int32_t &errorCode)
633 {
634     MessageParcel data;
635     MessageParcel reply;
636     MessageOption option;
637 
638     bool ret = data.WriteInterfaceToken(GetDescriptor());
639     CHECK_AND_RETURN_RET_LOG(ret, nullptr, "WriteInterfaceToken failed");
640     ProcessConfig::WriteConfigToParcel(config, data);
641     int error = Remote()->SendRequest(
642         static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_AUDIOPROCESS), data, reply, option);
643     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, nullptr, "CreateAudioProcess failed, error: %{public}d", error);
644     sptr<IRemoteObject> process = reply.ReadRemoteObject();
645     errorCode = reply.ReadInt32();
646     return process;
647 }
648 
LoadAudioEffectLibraries(const vector<Library> libraries,const vector<Effect> effects,vector<Effect> & successEffects)649 bool AudioManagerProxy::LoadAudioEffectLibraries(const vector<Library> libraries, const vector<Effect> effects,
650     vector<Effect> &successEffects)
651 {
652     int32_t error;
653     int32_t i;
654 
655     MessageParcel dataParcel;
656     MessageParcel replyParcel;
657     MessageOption option;
658     bool ret = dataParcel.WriteInterfaceToken(GetDescriptor());
659     CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
660 
661     uint32_t countLib = libraries.size();
662     uint32_t countEff = effects.size();
663 
664     dataParcel.WriteInt32(countLib);
665     dataParcel.WriteInt32(countEff);
666 
667     for (Library x : libraries) {
668         dataParcel.WriteString(x.name);
669         dataParcel.WriteString(x.path);
670     }
671 
672     for (Effect x : effects) {
673         dataParcel.WriteString(x.name);
674         dataParcel.WriteString(x.libraryName);
675     }
676 
677     error = Remote()->SendRequest(
678         static_cast<uint32_t>(AudioServerInterfaceCode::LOAD_AUDIO_EFFECT_LIBRARIES), dataParcel, replyParcel, option);
679     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "LoadAudioEffectLibraries failed, error: %{public}d", error);
680 
681     int32_t successEffSize = replyParcel.ReadInt32();
682     CHECK_AND_RETURN_RET_LOG((successEffSize >= 0) && (successEffSize <= AUDIO_EFFECT_COUNT_UPPER_LIMIT),
683         false, "LOAD_AUDIO_EFFECT_LIBRARIES read replyParcel failed");
684 
685     for (i = 0; i < successEffSize; i++) {
686         string effectName = replyParcel.ReadString();
687         string libName = replyParcel.ReadString();
688         successEffects.push_back({effectName, libName});
689     }
690 
691     return true;
692 }
693 
RequestThreadPriority(uint32_t tid,string bundleName)694 void AudioManagerProxy::RequestThreadPriority(uint32_t tid, string bundleName)
695 {
696     MessageParcel data;
697     MessageParcel reply;
698     MessageOption option;
699 
700     bool ret = data.WriteInterfaceToken(GetDescriptor());
701     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
702     (void)data.WriteUint32(tid);
703     (void)data.WriteString(bundleName);
704     int error = Remote()->SendRequest(
705         static_cast<uint32_t>(AudioServerInterfaceCode::REQUEST_THREAD_PRIORITY), data, reply, option);
706     CHECK_AND_RETURN_LOG(error == ERR_NONE, "RequestThreadPriority failed, error: %{public}d", error);
707 }
708 
MarshellEffectChainMgrParam(const EffectChainManagerParam & effectChainMgrParam,MessageParcel & data)709 static void MarshellEffectChainMgrParam(const EffectChainManagerParam &effectChainMgrParam, MessageParcel &data)
710 {
711     data.WriteInt32(effectChainMgrParam.maxExtraNum);
712     data.WriteString(effectChainMgrParam.defaultSceneName);
713     data.WriteInt32(effectChainMgrParam.priorSceneList.size());
714     for (const auto &prioScene : effectChainMgrParam.priorSceneList) {
715         data.WriteString(prioScene);
716     }
717 
718     data.WriteInt32(effectChainMgrParam.sceneTypeToChainNameMap.size());
719     for (const auto &[scene, chain] : effectChainMgrParam.sceneTypeToChainNameMap) {
720         data.WriteString(scene);
721         data.WriteString(chain);
722     }
723 
724     data.WriteInt32(effectChainMgrParam.effectDefaultProperty.size());
725     for (const auto &[effect, prop] : effectChainMgrParam.effectDefaultProperty) {
726         data.WriteString(effect);
727         data.WriteString(prop);
728     }
729 }
730 
CreateEffectChainManager(std::vector<EffectChain> & effectChains,const EffectChainManagerParam & effectParam,const EffectChainManagerParam & enhanceParam)731 bool AudioManagerProxy::CreateEffectChainManager(std::vector<EffectChain> &effectChains,
732     const EffectChainManagerParam &effectParam, const EffectChainManagerParam &enhanceParam)
733 {
734     int32_t error;
735 
736     MessageParcel dataParcel;
737     MessageParcel replyParcel;
738     MessageOption option;
739 
740     bool ret = dataParcel.WriteInterfaceToken(GetDescriptor());
741     CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
742 
743     uint32_t countEffectChains = effectChains.size();
744     std::vector<int32_t> listCountEffects;
745 
746     for (EffectChain &effectChain: effectChains) {
747         listCountEffects.emplace_back(effectChain.apply.size());
748     }
749 
750     dataParcel.WriteInt32(countEffectChains);
751     for (int32_t countEffects: listCountEffects) {
752         dataParcel.WriteInt32(countEffects);
753     }
754 
755     for (EffectChain &effectChain: effectChains) {
756         dataParcel.WriteString(effectChain.name);
757         for (std::string applyName: effectChain.apply) {
758             dataParcel.WriteString(applyName);
759         }
760     }
761 
762     MarshellEffectChainMgrParam(effectParam, dataParcel);
763     MarshellEffectChainMgrParam(enhanceParam, dataParcel);
764 
765     error = Remote()->SendRequest(
766         static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_AUDIO_EFFECT_CHAIN_MANAGER),
767         dataParcel, replyParcel, option);
768     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false,
769         "CreateAudioEffectChainManager failed, error: %{public}d", error);
770     return true;
771 }
772 
SetOutputDeviceSink(int32_t deviceType,std::string & sinkName)773 void AudioManagerProxy::SetOutputDeviceSink(int32_t deviceType, std::string &sinkName)
774 {
775     int32_t error;
776 
777     MessageParcel dataParcel;
778     MessageParcel replyParcel;
779     MessageOption option;
780     bool ret = dataParcel.WriteInterfaceToken(GetDescriptor());
781     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
782     dataParcel.WriteInt32(deviceType);
783     dataParcel.WriteString(sinkName);
784 
785     error = Remote()->SendRequest(
786         static_cast<uint32_t>(AudioServerInterfaceCode::SET_OUTPUT_DEVICE_SINK), dataParcel, replyParcel, option);
787         CHECK_AND_RETURN_LOG(error == ERR_NONE, "SetOutputDeviceSink failed, error: %{public}d", error);
788     return;
789 }
790 
CreatePlaybackCapturerManager()791 bool AudioManagerProxy::CreatePlaybackCapturerManager()
792 {
793     int32_t error;
794     MessageParcel data;
795     MessageParcel reply;
796     MessageOption option;
797     bool ret = data.WriteInterfaceToken(GetDescriptor());
798     CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
799 
800     error = Remote()->SendRequest(
801         static_cast<uint32_t>(AudioServerInterfaceCode::CREATE_PLAYBACK_CAPTURER_MANAGER), data, reply, option);
802     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false,
803         "CreatePlaybackCapturerManager failed, error: %{public}d", error);
804 
805     return reply.ReadBool();
806 }
807 
SetSupportStreamUsage(std::vector<int32_t> usage)808 int32_t AudioManagerProxy::SetSupportStreamUsage(std::vector<int32_t> usage)
809 {
810     int32_t error;
811     MessageParcel data;
812     MessageParcel reply;
813     MessageOption option;
814 
815     bool ret = data.WriteInterfaceToken(GetDescriptor());
816     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
817 
818     int32_t cnt = (int32_t)usage.size();
819     data.WriteInt32(cnt);
820     for (int32_t i = 0; i < cnt; i++) {
821         data.WriteInt32(usage[i]);
822     }
823 
824     error = Remote()->SendRequest(
825         static_cast<uint32_t>(AudioServerInterfaceCode::SET_SUPPORT_STREAM_USAGE), data, reply, option);
826     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
827         "SetSupportStreamUsage failed, error: %{public}d", error);
828 
829     return reply.ReadInt32();
830 }
831 
SetCaptureSilentState(bool state)832 int32_t AudioManagerProxy::SetCaptureSilentState(bool state)
833 {
834     int32_t error;
835     MessageParcel data;
836     MessageParcel reply;
837     MessageOption option;
838 
839     bool ret = data.WriteInterfaceToken(GetDescriptor());
840     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
841 
842     data.WriteInt32(static_cast<int32_t>(state));
843     error = Remote()->SendRequest(static_cast<uint32_t>(AudioServerInterfaceCode::SET_CAPTURE_SILENT_STATE),
844         data, reply, option);
845     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
846         "SetCaptureSilentState failed, error: %{public}d", error);
847     return reply.ReadInt32();
848 }
849 
NotifyStreamVolumeChanged(AudioStreamType streamType,float volume)850 int32_t AudioManagerProxy::NotifyStreamVolumeChanged(AudioStreamType streamType, float volume)
851 {
852     int32_t error;
853     MessageParcel data;
854     MessageParcel reply;
855     MessageOption option;
856 
857     if (!data.WriteInterfaceToken(GetDescriptor())) {
858         AUDIO_ERR_LOG("NotifyStreamVolumeChanged: WriteInterfaceToken failed");
859         return -1;
860     }
861 
862     data.WriteInt32(static_cast<int32_t>(streamType));
863     data.WriteFloat(volume);
864     error = Remote()->SendRequest(static_cast<uint32_t>(AudioServerInterfaceCode::NOTIFY_STREAM_VOLUME_CHANGED),
865         data, reply, option);
866     if (error != ERR_NONE) {
867         AUDIO_ERR_LOG("NotifyStreamVolumeChanged failed, error: %{public}d", error);
868         return error;
869     }
870     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "NotifyStreamVolumeChanged failed, error: %{public}d", error);
871     return reply.ReadInt32();
872 }
873 
UpdateSpatializationState(AudioSpatializationState spatializationState)874 int32_t AudioManagerProxy::UpdateSpatializationState(AudioSpatializationState spatializationState)
875 {
876     int32_t error;
877     MessageParcel data;
878     MessageParcel reply;
879     MessageOption option;
880 
881     bool ret = data.WriteInterfaceToken(GetDescriptor());
882     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
883     data.WriteBool(spatializationState.spatializationEnabled);
884     data.WriteBool(spatializationState.headTrackingEnabled);
885 
886     error = Remote()->SendRequest(
887         static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_SPATIALIZATION_STATE), data, reply, option);
888     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
889         "UpdateSpatializationState failed, error: %{public}d", error);
890 
891     return reply.ReadInt32();
892 }
893 
UpdateSpatialDeviceType(AudioSpatialDeviceType spatialDeviceType)894 int32_t AudioManagerProxy::UpdateSpatialDeviceType(AudioSpatialDeviceType spatialDeviceType)
895 {
896     int32_t error;
897     MessageParcel data;
898     MessageParcel reply;
899     MessageOption option;
900 
901     bool ret = data.WriteInterfaceToken(GetDescriptor());
902     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
903     data.WriteInt32(spatialDeviceType);
904 
905     error = Remote()->SendRequest(
906         static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_SPATIAL_DEVICE_TYPE), data, reply, option);
907     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "UpdateSpatialDeviceType failed, error: %{public}d", error);
908 
909     return reply.ReadInt32();
910 }
911 
SetSpatializationSceneType(AudioSpatializationSceneType spatializationSceneType)912 int32_t AudioManagerProxy::SetSpatializationSceneType(AudioSpatializationSceneType spatializationSceneType)
913 {
914     int32_t error;
915     MessageParcel data;
916     MessageParcel reply;
917     MessageOption option;
918 
919     bool ret = data.WriteInterfaceToken(GetDescriptor());
920     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
921     data.WriteInt32(static_cast<int32_t>(spatializationSceneType));
922 
923     error = Remote()->SendRequest(
924         static_cast<uint32_t>(AudioServerInterfaceCode::SET_SPATIALIZATION_SCENE_TYPE), data, reply, option);
925     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
926 
927     return reply.ReadInt32();
928 }
929 
ResetRouteForDisconnect(DeviceType type)930 int32_t AudioManagerProxy::ResetRouteForDisconnect(DeviceType type)
931 {
932     int32_t error;
933     MessageParcel data;
934     MessageParcel reply;
935     MessageOption option;
936 
937     bool ret = data.WriteInterfaceToken(GetDescriptor());
938     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
939     data.WriteInt32(static_cast<int32_t>(type));
940 
941     error = Remote()->SendRequest(
942         static_cast<uint32_t>(AudioServerInterfaceCode::RESET_ROUTE_FOR_DISCONNECT), data, reply, option);
943     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "error: %{public}d", error);
944 
945     return reply.ReadInt32();
946 }
947 
GetEffectLatency(const std::string & sessionId)948 uint32_t AudioManagerProxy::GetEffectLatency(const std::string &sessionId)
949 {
950     int32_t error;
951     MessageParcel data;
952     MessageParcel reply;
953     MessageOption option;
954 
955     bool ret = data.WriteInterfaceToken(GetDescriptor());
956     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
957     data.WriteString(sessionId);
958 
959     error = Remote()->SendRequest(
960         static_cast<uint32_t>(AudioServerInterfaceCode::GET_EFFECT_LATENCY), data, reply, option);
961     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "error: %{public}d", error);
962 
963     return reply.ReadUint32();
964 }
965 
UpdateLatencyTimestamp(std::string & timestamp,bool isRenderer)966 void AudioManagerProxy::UpdateLatencyTimestamp(std::string &timestamp, bool isRenderer)
967 {
968     int32_t error;
969     MessageParcel data;
970     MessageParcel reply;
971     MessageOption option;
972 
973     bool ret = data.WriteInterfaceToken(GetDescriptor());
974     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
975     data.WriteString(timestamp);
976     data.WriteBool(isRenderer);
977 
978     error = Remote()->SendRequest(
979         static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_LATENCY_TIMESTAMP), data, reply, option);
980     CHECK_AND_RETURN_LOG(error == ERR_NONE,
981         "LatencyMeas UpdateLatencyTimestamp failed, error:%{public}d", error);
982 }
983 
GetMaxAmplitude(bool isOutputDevice,int32_t deviceType)984 float AudioManagerProxy::GetMaxAmplitude(bool isOutputDevice, int32_t deviceType)
985 {
986     int32_t error;
987     MessageParcel data;
988     MessageParcel reply;
989     MessageOption option;
990 
991     bool ret = data.WriteInterfaceToken(GetDescriptor());
992     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
993     data.WriteBool(isOutputDevice);
994     data.WriteInt32(deviceType);
995 
996     error = Remote()->SendRequest(
997         static_cast<uint32_t>(AudioServerInterfaceCode::GET_MAX_AMPLITUDE), data, reply, option);
998     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
999 
1000     return reply.ReadFloat();
1001 }
1002 
ResetAudioEndpoint()1003 void AudioManagerProxy::ResetAudioEndpoint()
1004 {
1005     int32_t error;
1006     MessageParcel data;
1007     MessageParcel reply;
1008     MessageOption option;
1009 
1010     bool ret = data.WriteInterfaceToken(GetDescriptor());
1011     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1012     error = Remote()->SendRequest(
1013         static_cast<uint32_t>(AudioServerInterfaceCode::RESET_AUDIO_ENDPOINT), data, reply, option);
1014     CHECK_AND_RETURN_LOG(error == ERR_NONE, "Send request failed, error:%{public}d", error);
1015 }
1016 
SuspendRenderSink(const std::string & sinkName)1017 int32_t AudioManagerProxy::SuspendRenderSink(const std::string &sinkName)
1018 {
1019     int32_t error;
1020     MessageParcel data;
1021     MessageParcel reply;
1022     MessageOption option;
1023 
1024     bool ret = data.WriteInterfaceToken(GetDescriptor());
1025     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
1026     data.WriteString(sinkName);
1027 
1028     error = Remote()->SendRequest(
1029         static_cast<uint32_t>(AudioServerInterfaceCode::SUSPEND_RENDERSINK), data, reply, option);
1030     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
1031 
1032     return reply.ReadInt32();
1033 }
1034 
RestoreRenderSink(const std::string & sinkName)1035 int32_t AudioManagerProxy::RestoreRenderSink(const std::string &sinkName)
1036 {
1037     int32_t error;
1038     MessageParcel data;
1039     MessageParcel reply;
1040     MessageOption option;
1041 
1042     bool ret = data.WriteInterfaceToken(GetDescriptor());
1043     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
1044     data.WriteString(sinkName);
1045 
1046     error = Remote()->SendRequest(
1047         static_cast<uint32_t>(AudioServerInterfaceCode::RESTORE_RENDERSINK), data, reply, option);
1048     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
1049 
1050     return reply.ReadInt32();
1051 }
1052 
LoadHdiEffectModel()1053 void AudioManagerProxy::LoadHdiEffectModel()
1054 {
1055     MessageParcel data;
1056     MessageParcel reply;
1057     MessageOption option;
1058 
1059     bool ret = data.WriteInterfaceToken(GetDescriptor());
1060     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1061 
1062     int32_t error = Remote()->SendRequest(
1063         static_cast<uint32_t>(AudioServerInterfaceCode::LOAD_HDI_EFFECT_MODEL), data, reply, option);
1064     CHECK_AND_RETURN_LOG(error == ERR_NONE, "failed,error:%d", error);
1065 }
1066 
UpdateEffectBtOffloadSupported(const bool & isSupported)1067 void AudioManagerProxy::UpdateEffectBtOffloadSupported(const bool &isSupported)
1068 {
1069     MessageParcel data;
1070     MessageParcel reply;
1071     MessageOption option;
1072 
1073     bool ret = data.WriteInterfaceToken(GetDescriptor());
1074     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1075     data.WriteBool(isSupported);
1076 
1077     int32_t error = Remote()->SendRequest(
1078         static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_EFFECT_BT_OFFLOAD_SUPPORTED), data, reply, option);
1079     CHECK_AND_RETURN_LOG(error == ERR_NONE, "failed, error:%{public}d", error);
1080 }
1081 
SetSinkMuteForSwitchDevice(const std::string & devceClass,int32_t durationUs,bool mute)1082 int32_t AudioManagerProxy::SetSinkMuteForSwitchDevice(const std::string &devceClass, int32_t durationUs, bool mute)
1083 {
1084     MessageParcel data;
1085     MessageParcel reply;
1086     MessageOption option;
1087 
1088     bool ret = data.WriteInterfaceToken(GetDescriptor());
1089     CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
1090     data.WriteString(devceClass);
1091     data.WriteInt32(durationUs);
1092     data.WriteInt32(mute);
1093 
1094     int32_t error = Remote()->SendRequest(
1095         static_cast<uint32_t>(AudioServerInterfaceCode::SET_SINK_MUTE_FOR_SWITCH_DEVICE), data, reply, option);
1096     CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "failed, error:%{public}d", error);
1097     return reply.ReadInt32();
1098 }
1099 
SetRotationToEffect(const uint32_t rotate)1100 void AudioManagerProxy::SetRotationToEffect(const uint32_t rotate)
1101 {
1102     MessageParcel data;
1103     MessageParcel reply;
1104     MessageOption option;
1105 
1106     bool ret = data.WriteInterfaceToken(GetDescriptor());
1107     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1108     data.WriteUint32(rotate);
1109 
1110     int32_t error = Remote()->SendRequest(
1111         static_cast<uint32_t>(AudioServerInterfaceCode::SET_ROTATION_TO_EFFECT), data, reply, option);
1112     CHECK_AND_RETURN_LOG(error == ERR_NONE, "failed, error:%{public}d", error);
1113 }
1114 
UpdateSessionConnectionState(const int32_t & sessionID,const int32_t & state)1115 void AudioManagerProxy::UpdateSessionConnectionState(const int32_t &sessionID, const int32_t &state)
1116 {
1117     MessageParcel data;
1118     MessageParcel reply;
1119     MessageOption option;
1120 
1121     bool ret = data.WriteInterfaceToken(GetDescriptor());
1122     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1123     data.WriteInt32(sessionID);
1124     data.WriteInt32(state);
1125 
1126     int32_t error = Remote()->SendRequest(
1127         static_cast<uint32_t>(AudioServerInterfaceCode::UPDATE_SESSION_CONNECTION_STATE), data, reply, option);
1128     CHECK_AND_RETURN_LOG(error == ERR_NONE, "failed, error:%{public}d", error);
1129 }
1130 
SetNonInterruptMute(const uint32_t sessionId,const bool muteFlag)1131 void AudioManagerProxy::SetNonInterruptMute(const uint32_t sessionId, const bool muteFlag)
1132 {
1133     MessageParcel data;
1134     MessageParcel reply;
1135     MessageOption option;
1136 
1137     bool ret = data.WriteInterfaceToken(GetDescriptor());
1138     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
1139     data.WriteUint32(sessionId);
1140     data.WriteBool(muteFlag);
1141 
1142     int32_t error = Remote()->SendRequest(
1143         static_cast<uint32_t>(AudioServerInterfaceCode::SET_SINGLE_STREAM_MUTE), data, reply, option);
1144     CHECK_AND_RETURN_LOG(error == ERR_NONE, "failed, error:%{public}d", error);
1145 }
1146 } // namespace AudioStandard
1147 } // namespace OHOS
1148