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 "AudioPolicyProxy"
17 #endif
18
19
20 #include "audio_policy_log.h"
21 #include "audio_policy_proxy.h"
22
23
24 namespace {
25 constexpr int MAX_PID_COUNT = 1000;
26 }
27
28 namespace OHOS {
29 namespace AudioStandard {
30 using namespace std;
31
AudioPolicyProxy(const sptr<IRemoteObject> & impl)32 AudioPolicyProxy::AudioPolicyProxy(const sptr<IRemoteObject> &impl)
33 : IRemoteProxy<IAudioPolicy>(impl)
34 {
35 }
36
WriteStreamChangeInfo(MessageParcel & data,const AudioMode & mode,const AudioStreamChangeInfo & streamChangeInfo)37 void AudioPolicyProxy::WriteStreamChangeInfo(MessageParcel &data,
38 const AudioMode &mode, const AudioStreamChangeInfo &streamChangeInfo)
39 {
40 if (mode == AUDIO_MODE_PLAYBACK) {
41 streamChangeInfo.audioRendererChangeInfo.Marshalling(data);
42 } else {
43 streamChangeInfo.audioCapturerChangeInfo.Marshalling(data);
44 }
45 }
46
SetRingerModeLegacy(AudioRingerMode ringMode)47 int32_t AudioPolicyProxy::SetRingerModeLegacy(AudioRingerMode ringMode)
48 {
49 MessageParcel data;
50 MessageParcel reply;
51 MessageOption option;
52
53 bool ret = data.WriteInterfaceToken(GetDescriptor());
54 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
55 data.WriteInt32(static_cast<int>(ringMode));
56 int32_t error = Remote()->SendRequest(
57 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_RINGER_MODE_LEGACY), data, reply, option);
58 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set SetRingerModeLegacy failed, error: %d", error);
59
60 return reply.ReadInt32();
61 }
62
SetRingerMode(AudioRingerMode ringMode)63 int32_t AudioPolicyProxy::SetRingerMode(AudioRingerMode ringMode)
64 {
65 MessageParcel data;
66 MessageParcel reply;
67 MessageOption option;
68
69 bool ret = data.WriteInterfaceToken(GetDescriptor());
70 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
71 data.WriteInt32(static_cast<int>(ringMode));
72 int32_t error = Remote()->SendRequest(
73 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_RINGER_MODE), data, reply, option);
74 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set ringermode failed, error: %d", error);
75
76 return reply.ReadInt32();
77 }
78
79 #ifdef FEATURE_DTMF_TONE
GetSupportedTones(const std::string & countryCode)80 std::vector<int32_t> AudioPolicyProxy::GetSupportedTones(const std::string &countryCode)
81 {
82 MessageParcel data;
83 MessageParcel reply;
84 MessageOption option;
85 int32_t lListSize = 0;
86 AUDIO_DEBUG_LOG("get GetSupportedTones,");
87 std::vector<int> lSupportedToneList = {};
88 bool ret = data.WriteInterfaceToken(GetDescriptor());
89 CHECK_AND_RETURN_RET_LOG(ret, lSupportedToneList, "WriteInterfaceToken failed");
90 data.WriteString(countryCode);
91 int32_t error = Remote()->SendRequest(
92 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_SUPPORTED_TONES), data, reply, option);
93 if (error != ERR_NONE) {
94 AUDIO_ERR_LOG("get ringermode failed, error: %d", error);
95 }
96 lListSize = reply.ReadInt32();
97 CHECK_AND_RETURN_RET_LOG(lListSize >= 0 && lListSize <= static_cast<int32_t>(MAX_SUPPORTED_TONEINFO_SIZE),
98 lSupportedToneList, "Using tainted data lListSize:%{public}d as loop bound", lListSize);
99 for (int i = 0; i < lListSize; i++) {
100 lSupportedToneList.push_back(reply.ReadInt32());
101 }
102 AUDIO_DEBUG_LOG("get GetSupportedTones, %{public}d", lListSize);
103 return lSupportedToneList;
104 }
105
GetToneConfig(int32_t ltonetype,const std::string & countryCode)106 std::shared_ptr<ToneInfo> AudioPolicyProxy::GetToneConfig(int32_t ltonetype, const std::string &countryCode)
107 {
108 MessageParcel data;
109 MessageParcel reply;
110 MessageOption option;
111 std::shared_ptr<ToneInfo> spToneInfo = std::make_shared<ToneInfo>();
112 if (spToneInfo == nullptr) {
113 return nullptr;
114 }
115 bool ret = data.WriteInterfaceToken(GetDescriptor());
116 CHECK_AND_RETURN_RET_LOG(ret, spToneInfo, "WriteInterfaceToken failed");
117 data.WriteInt32(ltonetype);
118 data.WriteString(countryCode);
119 int32_t error = Remote()->SendRequest(
120 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_TONEINFO), data, reply, option);
121 if (error != ERR_NONE) {
122 AUDIO_ERR_LOG("get toneinfo failed, error: %d", error);
123 }
124
125 spToneInfo->Unmarshalling(reply);
126 AUDIO_DEBUG_LOG("get rGetToneConfig returned,");
127 return spToneInfo;
128 }
129 #endif
130
GetPersistentMicMuteState()131 bool AudioPolicyProxy::GetPersistentMicMuteState()
132 {
133 MessageParcel data;
134 MessageParcel reply;
135 MessageOption option;
136 bool ret = data.WriteInterfaceToken(GetDescriptor());
137 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
138 int32_t error = Remote()->SendRequest(
139 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_MICROPHONE_MUTE_PERSISTENT), data, reply, option);
140 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "get persistent microphoneMute state failed, error: %d", error);
141
142 return reply.ReadBool();
143 }
144
GetRingerMode()145 AudioRingerMode AudioPolicyProxy::GetRingerMode()
146 {
147 MessageParcel data;
148 MessageParcel reply;
149 MessageOption option;
150
151 bool ret = data.WriteInterfaceToken(GetDescriptor());
152 CHECK_AND_RETURN_RET_LOG(ret, RINGER_MODE_NORMAL, "WriteInterfaceToken failed");
153 int32_t error = Remote()->SendRequest(
154 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_RINGER_MODE), data, reply, option);
155 if (error != ERR_NONE) {
156 AUDIO_ERR_LOG("get ringermode failed, error: %d", error);
157 }
158 return static_cast<AudioRingerMode>(reply.ReadInt32());
159 }
160
SetAudioScene(AudioScene scene)161 int32_t AudioPolicyProxy::SetAudioScene(AudioScene scene)
162 {
163 MessageParcel data;
164 MessageParcel reply;
165 MessageOption option;
166
167 bool ret = data.WriteInterfaceToken(GetDescriptor());
168 CHECK_AND_RETURN_RET_LOG(ret, RINGER_MODE_NORMAL, "WriteInterfaceToken failed");
169 data.WriteInt32(static_cast<int>(scene));
170 int32_t error = Remote()->SendRequest(
171 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_AUDIO_SCENE), data, reply, option);
172 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set audio scene failed, error: %d", error);
173
174 return reply.ReadInt32();
175 }
176
GetAudioScene()177 AudioScene AudioPolicyProxy::GetAudioScene()
178 {
179 MessageParcel data;
180 MessageParcel reply;
181 MessageOption option;
182
183 bool ret = data.WriteInterfaceToken(GetDescriptor());
184 CHECK_AND_RETURN_RET_LOG(ret, AUDIO_SCENE_DEFAULT, "WriteInterfaceToken failed");
185 int32_t error = Remote()->SendRequest(
186 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_AUDIO_SCENE), data, reply, option);
187 if (error != ERR_NONE) {
188 AUDIO_ERR_LOG("get audio scene failed, error: %d", error);
189 }
190 return static_cast<AudioScene>(reply.ReadInt32());
191 }
192
SetStreamMuteLegacy(AudioVolumeType volumeType,bool mute,const DeviceType & deviceType)193 int32_t AudioPolicyProxy::SetStreamMuteLegacy(AudioVolumeType volumeType, bool mute,
194 const DeviceType &deviceType)
195 {
196 MessageParcel data;
197 MessageParcel reply;
198 MessageOption option;
199
200 bool ret = data.WriteInterfaceToken(GetDescriptor());
201 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
202 data.WriteInt32(static_cast<int32_t>(volumeType));
203 data.WriteBool(mute);
204 data.WriteInt32(static_cast<int32_t>(deviceType));
205 int32_t error = Remote()->SendRequest(
206 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_STREAM_MUTE_LEGACY), data, reply, option);
207 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set mute failed, error: %d", error);
208 return reply.ReadInt32();
209 }
210
SetStreamMute(AudioVolumeType volumeType,bool mute,const DeviceType & deviceType)211 int32_t AudioPolicyProxy::SetStreamMute(AudioVolumeType volumeType, bool mute,
212 const DeviceType &deviceType)
213 {
214 MessageParcel data;
215 MessageParcel reply;
216 MessageOption option;
217
218 bool ret = data.WriteInterfaceToken(GetDescriptor());
219 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
220 data.WriteInt32(static_cast<int32_t>(volumeType));
221 data.WriteBool(mute);
222 data.WriteInt32(static_cast<int32_t>(deviceType));
223 int32_t error = Remote()->SendRequest(
224 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_STREAM_MUTE), data, reply, option);
225 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set mute failed, error: %d", error);
226 return reply.ReadInt32();
227 }
228
GetStreamMute(AudioVolumeType volumeType)229 bool AudioPolicyProxy::GetStreamMute(AudioVolumeType volumeType)
230 {
231 MessageParcel data;
232 MessageParcel reply;
233 MessageOption option;
234
235 bool ret = data.WriteInterfaceToken(GetDescriptor());
236 CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
237 data.WriteInt32(static_cast<int32_t>(volumeType));
238 int32_t error = Remote()->SendRequest(
239 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_STREAM_MUTE), data, reply, option);
240 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "get mute failed, error: %d", error);
241 return reply.ReadBool();
242 }
243
IsStreamActive(AudioVolumeType volumeType)244 bool AudioPolicyProxy::IsStreamActive(AudioVolumeType volumeType)
245 {
246 MessageParcel data;
247 MessageParcel reply;
248 MessageOption option;
249
250 bool ret = data.WriteInterfaceToken(GetDescriptor());
251 CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
252 data.WriteInt32(static_cast<int32_t>(volumeType));
253 int32_t error = Remote()->SendRequest(
254 static_cast<uint32_t>(AudioPolicyInterfaceCode::IS_STREAM_ACTIVE), data, reply, option);
255 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "isStreamActive failed, error: %d", error);
256 return reply.ReadBool();
257 }
258
GetDevices(DeviceFlag deviceFlag)259 std::vector<std::shared_ptr<AudioDeviceDescriptor>> AudioPolicyProxy::GetDevices(DeviceFlag deviceFlag)
260 {
261 MessageParcel data;
262 MessageParcel reply;
263 MessageOption option;
264 std::vector<std::shared_ptr<AudioDeviceDescriptor>> deviceInfo;
265
266 bool ret = data.WriteInterfaceToken(GetDescriptor());
267 CHECK_AND_RETURN_RET_LOG(ret, deviceInfo, "WriteInterfaceToken failed");
268 data.WriteInt32(static_cast<int32_t>(deviceFlag));
269 int32_t error = Remote()->SendRequest(
270 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_DEVICES), data, reply, option);
271 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, deviceInfo, "Get devices failed, error: %d", error);
272
273 int32_t size = reply.ReadInt32();
274 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= static_cast<int32_t>(AUDIO_DEVICE_INFO_SIZE_LIMIT),
275 deviceInfo, "Using tainted data size: %{public}d as loop bound", size);
276 for (int32_t i = 0; i < size; i++) {
277 deviceInfo.push_back(AudioDeviceDescriptor::UnmarshallingPtr(reply));
278 }
279
280 return deviceInfo;
281 }
282
GetDevicesInner(DeviceFlag deviceFlag)283 std::vector<std::shared_ptr<AudioDeviceDescriptor>> AudioPolicyProxy::GetDevicesInner(DeviceFlag deviceFlag)
284 {
285 MessageParcel data;
286 MessageParcel reply;
287 MessageOption option;
288 std::vector<std::shared_ptr<AudioDeviceDescriptor>> deviceInfo;
289
290 bool ret = data.WriteInterfaceToken(GetDescriptor());
291 CHECK_AND_RETURN_RET_LOG(ret, deviceInfo, "WriteInterfaceToken failed");
292 data.WriteInt32(static_cast<int32_t>(deviceFlag));
293 int32_t error = Remote()->SendRequest(
294 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_DEVICES_INNER), data, reply, option);
295 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, deviceInfo, "Get devices failed, error: %d", error);
296
297 int32_t size = reply.ReadInt32();
298 CHECK_AND_RETURN_RET_LOG(size > 0 && size <= static_cast<int32_t>(AUDIO_DEVICE_INFO_SIZE_LIMIT),
299 deviceInfo, "Using tainted data size: %{public}d as loop bound", size);
300 for (int32_t i = 0; i < size; i++) {
301 deviceInfo.push_back(AudioDeviceDescriptor::UnmarshallingPtr(reply));
302 }
303
304 return deviceInfo;
305 }
306
GetPreferredOutputDeviceDescriptors(AudioRendererInfo & rendererInfo,bool forceNoBTPermission)307 std::vector<std::shared_ptr<AudioDeviceDescriptor>> AudioPolicyProxy::GetPreferredOutputDeviceDescriptors(
308 AudioRendererInfo &rendererInfo, bool forceNoBTPermission)
309 {
310 MessageParcel data;
311 MessageParcel reply;
312 MessageOption option;
313 std::vector<std::shared_ptr<AudioDeviceDescriptor>> deviceInfo;
314
315 bool ret = data.WriteInterfaceToken(GetDescriptor());
316 CHECK_AND_RETURN_RET_LOG(ret, deviceInfo, "WriteInterfaceToken failed");
317
318 bool res = rendererInfo.Marshalling(data);
319 CHECK_AND_RETURN_RET_LOG(res, deviceInfo, "AudioRendererInfo Marshalling() failed");
320
321 data.WriteBool(forceNoBTPermission);
322
323 int32_t error = Remote()->SendRequest(
324 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_ACTIVE_OUTPUT_DEVICE_DESCRIPTORS), data, reply, option);
325 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, deviceInfo, "Get out devices failed, error: %d", error);
326
327 int32_t size = reply.ReadInt32();
328 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= static_cast<int32_t>(AUDIO_DEVICE_INFO_SIZE_LIMIT),
329 deviceInfo, "Using tainted data size: %{public}d as loop bound", size);
330 for (int32_t i = 0; i < size; i++) {
331 deviceInfo.push_back(AudioDeviceDescriptor::UnmarshallingPtr(reply));
332 }
333
334 return deviceInfo;
335 }
336
GetPreferredInputDeviceDescriptors(AudioCapturerInfo & captureInfo)337 std::vector<std::shared_ptr<AudioDeviceDescriptor>> AudioPolicyProxy::GetPreferredInputDeviceDescriptors(
338 AudioCapturerInfo &captureInfo)
339 {
340 MessageParcel data;
341 MessageParcel reply;
342 MessageOption option;
343 std::vector<std::shared_ptr<AudioDeviceDescriptor>> deviceInfo;
344
345 bool ret = data.WriteInterfaceToken(GetDescriptor());
346 CHECK_AND_RETURN_RET_LOG(ret, deviceInfo, "WriteInterfaceToken failed");
347
348 bool res = captureInfo.Marshalling(data);
349 CHECK_AND_RETURN_RET_LOG(res, deviceInfo, "AudioCapturerInfo Marshalling() failed");
350
351 int32_t error = Remote()->SendRequest(
352 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_PREFERRED_INTPUT_DEVICE_DESCRIPTORS), data, reply, option);
353 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, deviceInfo, "Get preferred input devices failed, error: %d", error);
354
355 int32_t size = reply.ReadInt32();
356 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= static_cast<int32_t>(AUDIO_DEVICE_INFO_SIZE_LIMIT),
357 deviceInfo, "Using tainted data size: %{public}d as loop bound", size);
358 for (int32_t i = 0; i < size; i++) {
359 deviceInfo.push_back(AudioDeviceDescriptor::UnmarshallingPtr(reply));
360 }
361
362 return deviceInfo;
363 }
364
GetOutputDevice(sptr<AudioRendererFilter> audioRendererFilter)365 std::vector<std::shared_ptr<AudioDeviceDescriptor>> AudioPolicyProxy::GetOutputDevice(
366 sptr<AudioRendererFilter> audioRendererFilter)
367 {
368 MessageParcel data;
369 MessageParcel reply;
370 MessageOption option;
371 std::vector<std::shared_ptr<AudioDeviceDescriptor>> deviceInfo;
372
373 bool ret = data.WriteInterfaceToken(GetDescriptor());
374 CHECK_AND_RETURN_RET_LOG(ret, deviceInfo, "WriteInterfaceToken failed");
375
376 bool tmp = audioRendererFilter->Marshalling(data);
377 CHECK_AND_RETURN_RET_LOG(tmp, deviceInfo, "AudioRendererFilter Marshalling() failed");
378
379 int32_t error = Remote()->SendRequest(
380 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_OUTPUT_DEVICE), data, reply, option);
381 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, deviceInfo, "Get preferred input devices failed, error: %d", error);
382
383 int32_t size = reply.ReadInt32();
384 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= static_cast<int32_t>(AUDIO_DEVICE_INFO_SIZE_LIMIT),
385 deviceInfo, "Using tainted data size: %{public}d as loop bound", size);
386 for (int32_t i = 0; i < size; i++) {
387 deviceInfo.push_back(AudioDeviceDescriptor::UnmarshallingPtr(reply));
388 }
389
390 return deviceInfo;
391 }
392
GetInputDevice(sptr<AudioCapturerFilter> audioCapturerFilter)393 std::vector<std::shared_ptr<AudioDeviceDescriptor>> AudioPolicyProxy::GetInputDevice(
394 sptr<AudioCapturerFilter> audioCapturerFilter)
395 {
396 MessageParcel data;
397 MessageParcel reply;
398 MessageOption option;
399 std::vector<std::shared_ptr<AudioDeviceDescriptor>> deviceInfo;
400
401 bool ret = data.WriteInterfaceToken(GetDescriptor());
402 CHECK_AND_RETURN_RET_LOG(ret, deviceInfo, "WriteInterfaceToken failed");
403
404 bool res = audioCapturerFilter->Marshalling(data);
405 CHECK_AND_RETURN_RET_LOG(res, deviceInfo, "AudioCapturerFilter Marshalling() failed");
406
407 int32_t error = Remote()->SendRequest(
408 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_INPUT_DEVICE), data, reply, option);
409 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, deviceInfo, "Get preferred input devices failed, error: %d", error);
410
411 int32_t size = reply.ReadInt32();
412 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= static_cast<int32_t>(AUDIO_DEVICE_INFO_SIZE_LIMIT),
413 deviceInfo, "Using tainted data size: %{public}d as loop bound", size);
414 for (int32_t i = 0; i < size; i++) {
415 deviceInfo.push_back(AudioDeviceDescriptor::UnmarshallingPtr(reply));
416 }
417
418 return deviceInfo;
419 }
420
SetDeviceActive(InternalDeviceType deviceType,bool active,const int32_t uid)421 int32_t AudioPolicyProxy::SetDeviceActive(InternalDeviceType deviceType, bool active, const int32_t uid)
422 {
423 MessageParcel data;
424 MessageParcel reply;
425 MessageOption option;
426
427 bool ret = data.WriteInterfaceToken(GetDescriptor());
428 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
429 data.WriteInt32(static_cast<int32_t>(deviceType));
430 data.WriteBool(active);
431 data.WriteInt32(uid);
432 int32_t error = Remote()->SendRequest(
433 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_DEVICE_ACTIVE), data, reply, option);
434 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set device active failed, error: %d", error);
435 return reply.ReadInt32();
436 }
437
LoadSplitModule(const std::string & splitArgs,const std::string & networkId)438 int32_t AudioPolicyProxy::LoadSplitModule(const std::string &splitArgs, const std::string &networkId)
439 {
440 MessageParcel data;
441 MessageParcel reply;
442 MessageOption option;
443
444 bool ret = data.WriteInterfaceToken(GetDescriptor());
445 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
446 data.WriteString(splitArgs);
447 data.WriteString(networkId);
448 int32_t error = Remote()->SendRequest(
449 static_cast<uint32_t>(AudioPolicyInterfaceCode::LOAD_SPLIT_MODULE), data, reply, option);
450 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "load split module failed, error: %{public}d", error);
451 return reply.ReadInt32();
452 }
453
IsAllowedPlayback(const int32_t & uid,const int32_t & pid)454 bool AudioPolicyProxy::IsAllowedPlayback(const int32_t &uid, const int32_t &pid)
455 {
456 MessageParcel data;
457 MessageParcel reply;
458 MessageOption option;
459
460 bool ret = data.WriteInterfaceToken(GetDescriptor());
461 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
462 data.WriteInt32(uid);
463 data.WriteInt32(pid);
464 int32_t error = Remote()->SendRequest(
465 static_cast<uint32_t>(AudioPolicyInterfaceCode::IS_ALLOWED_PLAYBACK), data, reply, option);
466 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "IsAllowedPlayback failed, error: %{public}d", error);
467 return reply.ReadBool();
468 }
469
SetVoiceRingtoneMute(bool isMute)470 int32_t AudioPolicyProxy::SetVoiceRingtoneMute(bool isMute)
471 {
472 MessageParcel data;
473 MessageParcel reply;
474 MessageOption option;
475
476 bool ret = data.WriteInterfaceToken(GetDescriptor());
477 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
478 data.WriteBool(isMute);
479 int32_t error = Remote()->SendRequest(
480 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_VOICE_RINGTONE_MUTE), data, reply, option);
481 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SetVoiceRingtoneMute failed, error: %{public}d", error);
482 return reply.ReadInt32();
483 }
484
SetVirtualCall(const bool isVirtual)485 int32_t AudioPolicyProxy::SetVirtualCall(const bool isVirtual)
486 {
487 MessageParcel data;
488 MessageParcel reply;
489 MessageOption option;
490
491 bool ret = data.WriteInterfaceToken(GetDescriptor());
492 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
493 data.WriteBool(isVirtual);
494 int32_t error = Remote()->SendRequest(
495 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_VIRTUAL_CALL), data, reply, option);
496 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SetVirtualCall failed, error: %{public}d", error);
497 return reply.ReadInt32();
498 }
499
IsDeviceActive(InternalDeviceType deviceType)500 bool AudioPolicyProxy::IsDeviceActive(InternalDeviceType deviceType)
501 {
502 MessageParcel data;
503 MessageParcel reply;
504 MessageOption option;
505
506 bool ret = data.WriteInterfaceToken(GetDescriptor());
507 CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
508 data.WriteInt32(static_cast<int32_t>(deviceType));
509 int32_t error = Remote()->SendRequest(
510 static_cast<uint32_t>(AudioPolicyInterfaceCode::IS_DEVICE_ACTIVE), data, reply, option);
511 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "is device active failed, error: %d", error);
512 return reply.ReadBool();
513 }
514
GetActiveOutputDevice()515 DeviceType AudioPolicyProxy::GetActiveOutputDevice()
516 {
517 MessageParcel data;
518 MessageParcel reply;
519 MessageOption option;
520
521 bool ret = data.WriteInterfaceToken(GetDescriptor());
522 CHECK_AND_RETURN_RET_LOG(ret, DEVICE_TYPE_INVALID, "WriteInterfaceToken failed");
523
524 int32_t error = Remote()->SendRequest(
525 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_ACTIVE_OUTPUT_DEVICE), data, reply, option);
526 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, DEVICE_TYPE_INVALID,
527 "get active output device failed, error: %d", error);
528
529 return static_cast<DeviceType>(reply.ReadInt32());
530 }
531
GetActiveInputDevice()532 DeviceType AudioPolicyProxy::GetActiveInputDevice()
533 {
534 MessageParcel data;
535 MessageParcel reply;
536 MessageOption option;
537
538 bool ret = data.WriteInterfaceToken(GetDescriptor());
539 CHECK_AND_RETURN_RET_LOG(ret, DEVICE_TYPE_INVALID, "WriteInterfaceToken failed");
540
541 int32_t error = Remote()->SendRequest(
542 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_ACTIVE_INPUT_DEVICE), data, reply, option);
543 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, DEVICE_TYPE_INVALID,
544 "get active input device failed, error: %d", error);
545
546 return static_cast<DeviceType>(reply.ReadInt32());
547 }
548
SelectOutputDevice(sptr<AudioRendererFilter> audioRendererFilter,std::vector<std::shared_ptr<AudioDeviceDescriptor>> audioDeviceDescriptors)549 int32_t AudioPolicyProxy::SelectOutputDevice(sptr<AudioRendererFilter> audioRendererFilter,
550 std::vector<std::shared_ptr<AudioDeviceDescriptor>> audioDeviceDescriptors)
551 {
552 MessageParcel data;
553 MessageParcel reply;
554 MessageOption option;
555
556 bool ret = data.WriteInterfaceToken(GetDescriptor());
557 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
558 bool tmp = audioRendererFilter->Marshalling(data);
559 CHECK_AND_RETURN_RET_LOG(tmp, -1, "AudioRendererFilter Marshalling() failed");
560
561 uint32_t size = audioDeviceDescriptors.size();
562 CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_DEVICE_INFO_SIZE_LIMIT,
563 -1, "SelectOutputDevice get invalid device size.");
564 data.WriteInt32(size);
565 for (auto audioDeviceDescriptor : audioDeviceDescriptors) {
566 bool audioDeviceTmp = audioDeviceDescriptor->Marshalling(data);
567 CHECK_AND_RETURN_RET_LOG(audioDeviceTmp, -1, "AudioDeviceDescriptor Marshalling() failed");
568 }
569 int error = Remote()->SendRequest(
570 static_cast<uint32_t>(AudioPolicyInterfaceCode::SELECT_OUTPUT_DEVICE), data, reply, option);
571 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SelectOutputDevice failed, error: %{public}d", error);
572
573 return reply.ReadInt32();
574 }
GetSelectedDeviceInfo(int32_t uid,int32_t pid,AudioStreamType streamType)575 std::string AudioPolicyProxy::GetSelectedDeviceInfo(int32_t uid, int32_t pid, AudioStreamType streamType)
576 {
577 MessageParcel data;
578 MessageParcel reply;
579 MessageOption option;
580
581 bool ret = data.WriteInterfaceToken(GetDescriptor());
582 CHECK_AND_RETURN_RET_LOG(ret, "", "WriteInterfaceToken failed");
583 data.WriteInt32(uid);
584 data.WriteInt32(pid);
585 data.WriteInt32(static_cast<int32_t>(streamType));
586 int error = Remote()->SendRequest(
587 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_SELECTED_DEVICE_INFO), data, reply, option);
588 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, "", "GetSelectedDeviceInfo failed, error: %{public}d", error);
589
590 return reply.ReadString();
591 }
592
SelectInputDevice(sptr<AudioCapturerFilter> audioCapturerFilter,std::vector<std::shared_ptr<AudioDeviceDescriptor>> audioDeviceDescriptors)593 int32_t AudioPolicyProxy::SelectInputDevice(sptr<AudioCapturerFilter> audioCapturerFilter,
594 std::vector<std::shared_ptr<AudioDeviceDescriptor>> audioDeviceDescriptors)
595 {
596 MessageParcel data;
597 MessageParcel reply;
598 MessageOption option;
599
600 bool ret = data.WriteInterfaceToken(GetDescriptor());
601 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
602 bool tmp = audioCapturerFilter->Marshalling(data);
603 CHECK_AND_RETURN_RET_LOG(tmp, -1, "AudioCapturerFilter Marshalling() failed");
604
605 uint32_t size = audioDeviceDescriptors.size();
606 CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_DEVICE_INFO_SIZE_LIMIT,
607 -1, "SelectOutputDevice get invalid device size.");
608 data.WriteInt32(size);
609 for (auto audioDeviceDescriptor : audioDeviceDescriptors) {
610 bool audioDeviceTmp = audioDeviceDescriptor->Marshalling(data);
611 CHECK_AND_RETURN_RET_LOG(audioDeviceTmp, -1, "AudioDeviceDescriptor Marshalling() failed");
612 }
613 int error = Remote()->SendRequest(
614 static_cast<uint32_t>(AudioPolicyInterfaceCode::SELECT_INPUT_DEVICE), data, reply, option);
615 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SelectInputDevice failed, error: %{public}d", error);
616
617 return reply.ReadInt32();
618 }
619
ExcludeOutputDevices(AudioDeviceUsage audioDevUsage,std::vector<std::shared_ptr<AudioDeviceDescriptor>> & audioDeviceDescriptors)620 int32_t AudioPolicyProxy::ExcludeOutputDevices(AudioDeviceUsage audioDevUsage,
621 std::vector<std::shared_ptr<AudioDeviceDescriptor>> &audioDeviceDescriptors)
622 {
623 MessageParcel data;
624 MessageParcel reply;
625 MessageOption option;
626
627 bool ret = data.WriteInterfaceToken(GetDescriptor());
628 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
629 data.WriteInt32(static_cast<int32_t>(audioDevUsage));
630 uint32_t size = audioDeviceDescriptors.size();
631 CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_DEVICE_INFO_SIZE_LIMIT,
632 -1, "ExcludeOutputDevices get invalid device size.");
633 data.WriteInt32(size);
634 for (auto audioDeviceDescriptor : audioDeviceDescriptors) {
635 bool audioDeviceTmp = audioDeviceDescriptor->Marshalling(data);
636 CHECK_AND_RETURN_RET_LOG(audioDeviceTmp, -1, "AudioDeviceDescriptor Marshalling() failed");
637 }
638 int error = Remote()->SendRequest(
639 static_cast<uint32_t>(AudioPolicyInterfaceCode::EXCLUDE_OUTPUT_DEVICES), data, reply, option);
640 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "ExcludeOutputDevices failed, error: %{public}d", error);
641
642 return reply.ReadInt32();
643 }
644
UnexcludeOutputDevices(AudioDeviceUsage audioDevUsage,std::vector<std::shared_ptr<AudioDeviceDescriptor>> & audioDeviceDescriptors)645 int32_t AudioPolicyProxy::UnexcludeOutputDevices(AudioDeviceUsage audioDevUsage,
646 std::vector<std::shared_ptr<AudioDeviceDescriptor>> &audioDeviceDescriptors)
647 {
648 MessageParcel data;
649 MessageParcel reply;
650 MessageOption option;
651
652 bool ret = data.WriteInterfaceToken(GetDescriptor());
653 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
654 data.WriteInt32(static_cast<int32_t>(audioDevUsage));
655 uint32_t size = audioDeviceDescriptors.size();
656 CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_DEVICE_INFO_SIZE_LIMIT,
657 -1, "UnexcludeOutputDevices get invalid device size.");
658 data.WriteInt32(size);
659 for (auto audioDeviceDescriptor : audioDeviceDescriptors) {
660 bool audioDeviceTmp = audioDeviceDescriptor->Marshalling(data);
661 CHECK_AND_RETURN_RET_LOG(audioDeviceTmp, -1, "AudioDeviceDescriptor Marshalling() failed");
662 }
663 int error = Remote()->SendRequest(
664 static_cast<uint32_t>(AudioPolicyInterfaceCode::UNEXCLUDE_OUTPUT_DEVICES), data, reply, option);
665 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "UnexcludeOutputDevices failed, error: %{public}d", error);
666
667 return reply.ReadInt32();
668 }
669
GetExcludedDevices(AudioDeviceUsage audioDevUsage)670 std::vector<std::shared_ptr<AudioDeviceDescriptor>> AudioPolicyProxy::GetExcludedDevices(
671 AudioDeviceUsage audioDevUsage)
672 {
673 MessageParcel data;
674 MessageParcel reply;
675 MessageOption option;
676 std::vector<std::shared_ptr<AudioDeviceDescriptor>> excludedDevices;
677
678 bool ret = data.WriteInterfaceToken(GetDescriptor());
679 CHECK_AND_RETURN_RET_LOG(ret, excludedDevices, "WriteInterfaceToken failed");
680 data.WriteInt32(static_cast<int32_t>(audioDevUsage));
681 int32_t error = Remote()->SendRequest(
682 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_EXCLUDED_OUTPUT_DEVICES), data, reply, option);
683 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, excludedDevices,
684 "Get excluded output devices failed, error: %d", error);
685
686 int32_t size = reply.ReadInt32();
687 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= static_cast<int32_t>(AUDIO_DEVICE_INFO_SIZE_LIMIT),
688 excludedDevices, "Using tainted data size: %{public}d as loop bound", size);
689 for (int32_t i = 0; i < size; i++) {
690 excludedDevices.push_back(AudioDeviceDescriptor::UnmarshallingPtr(reply));
691 }
692
693 return excludedDevices;
694 }
695
ConfigDistributedRoutingRole(const std::shared_ptr<AudioDeviceDescriptor> descriptor,CastType type)696 int32_t AudioPolicyProxy::ConfigDistributedRoutingRole(
697 const std::shared_ptr<AudioDeviceDescriptor> descriptor, CastType type)
698 {
699 MessageParcel data;
700 MessageParcel reply;
701 MessageOption option;
702
703 bool ret = data.WriteInterfaceToken(GetDescriptor());
704 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
705 CHECK_AND_RETURN_RET_LOG(descriptor != nullptr, -1, "descriptor is null");
706 bool res = descriptor->Marshalling(data);
707 CHECK_AND_RETURN_RET_LOG(res, -1, "AudioDeviceDescriptor marshalling failed");
708 data.WriteInt32(static_cast<int32_t>(type));
709 int error = Remote()->SendRequest(
710 static_cast<uint32_t>(AudioPolicyInterfaceCode::CONFIG_DISTRIBUTED_ROUTING_ROLE), data, reply, option);
711 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "failed error : %{public}d", error);
712 return reply.ReadInt32();
713 }
714
ActivateAudioSession(const AudioSessionStrategy & strategy)715 int32_t AudioPolicyProxy::ActivateAudioSession(const AudioSessionStrategy &strategy)
716 {
717 MessageParcel data;
718 MessageParcel reply;
719 MessageOption option;
720
721 bool ret = data.WriteInterfaceToken(GetDescriptor());
722 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
723 data.WriteInt32(static_cast<int32_t>(strategy.concurrencyMode));
724 int32_t error = Remote()->SendRequest(
725 static_cast<uint32_t>(AudioPolicyInterfaceCode::ACTIVATE_AUDIO_SESSION), data, reply, option);
726 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Failed to activate audio session. Error: %{public}d", error);
727
728 return reply.ReadInt32();
729 }
730
DeactivateAudioSession()731 int32_t AudioPolicyProxy::DeactivateAudioSession()
732 {
733 MessageParcel data;
734 MessageParcel reply;
735 MessageOption option;
736
737 bool ret = data.WriteInterfaceToken(GetDescriptor());
738 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
739 int error = Remote()->SendRequest(
740 static_cast<uint32_t>(AudioPolicyInterfaceCode::DEACTIVATE_AUDIO_SESSION), data, reply, option);
741 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Failed to deactivate audio session. Error: %{public}d", error);
742
743 return reply.ReadInt32();
744 }
745
IsAudioSessionActivated()746 bool AudioPolicyProxy::IsAudioSessionActivated()
747 {
748 MessageParcel data;
749 MessageParcel reply;
750 MessageOption option;
751
752 bool ret = data.WriteInterfaceToken(GetDescriptor());
753 CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
754 int error = Remote()->SendRequest(
755 static_cast<uint32_t>(AudioPolicyInterfaceCode::IS_AUDIO_SESSION_ACTIVATED), data, reply, option);
756 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false,
757 "Failed to query IsAudioSessionActivated, error: %{public}d", error);
758
759 return reply.ReadBool();
760 }
761
ReadAudioFocusInfo(MessageParcel & reply,std::list<std::pair<AudioInterrupt,AudioFocuState>> & focusInfoList)762 void AudioPolicyProxy::ReadAudioFocusInfo(MessageParcel &reply,
763 std::list<std::pair<AudioInterrupt, AudioFocuState>> &focusInfoList)
764 {
765 std::pair<AudioInterrupt, AudioFocuState> focusInfo;
766 AudioInterrupt::Unmarshalling(reply, focusInfo.first);
767 focusInfo.second = static_cast<AudioFocuState>(reply.ReadInt32());
768 focusInfoList.push_back(focusInfo);
769 }
770
GetAudioFocusInfoList(std::list<std::pair<AudioInterrupt,AudioFocuState>> & focusInfoList,const int32_t zoneID)771 int32_t AudioPolicyProxy::GetAudioFocusInfoList(std::list<std::pair<AudioInterrupt, AudioFocuState>> &focusInfoList,
772 const int32_t zoneID)
773 {
774 MessageParcel data;
775 MessageParcel reply;
776 MessageOption option;
777
778 bool res = data.WriteInterfaceToken(GetDescriptor());
779 CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed");
780 data.WriteInt32(zoneID);
781 int32_t error = Remote()->SendRequest(
782 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_AUDIO_FOCUS_INFO_LIST), data, reply, option);
783 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "GetAudioFocusInfoList, error: %d", error);
784 int32_t ret = reply.ReadInt32();
785 int32_t size = reply.ReadInt32();
786 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_INTERRUPT_INFO_SIZE_LIMIT,
787 ERROR, "Using tainted data focusInfoSize:%{public}d as loop bound", size);
788 focusInfoList = {};
789 if (ret < 0) {
790 return ret;
791 } else {
792 for (int32_t i = 0; i < size; i++) {
793 ReadAudioFocusInfo(reply, focusInfoList);
794 }
795 return SUCCESS;
796 }
797 }
798
ActivateAudioInterrupt(AudioInterrupt & audioInterrupt,const int32_t zoneID,const bool isUpdatedAudioStrategy)799 int32_t AudioPolicyProxy::ActivateAudioInterrupt(
800 AudioInterrupt &audioInterrupt, const int32_t zoneID, const bool isUpdatedAudioStrategy)
801 {
802 MessageParcel data;
803 MessageParcel reply;
804 MessageOption option;
805
806 bool ret = data.WriteInterfaceToken(GetDescriptor());
807 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
808 data.WriteInt32(zoneID);
809 data.WriteBool(isUpdatedAudioStrategy);
810 ret = AudioInterrupt::Marshalling(data, audioInterrupt);
811 CHECK_AND_RETURN_RET_LOG(ret, -1, "Marshalling failed");
812
813 int error = Remote()->SendRequest(
814 static_cast<uint32_t>(AudioPolicyInterfaceCode::ACTIVATE_INTERRUPT), data, reply, option);
815 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "activate interrupt failed, error: %{public}d", error);
816
817 return reply.ReadInt32();
818 }
819
DeactivateAudioInterrupt(const AudioInterrupt & audioInterrupt,const int32_t zoneID)820 int32_t AudioPolicyProxy::DeactivateAudioInterrupt(const AudioInterrupt &audioInterrupt, const int32_t zoneID)
821 {
822 MessageParcel data;
823 MessageParcel reply;
824 MessageOption option;
825
826 bool ret = data.WriteInterfaceToken(GetDescriptor());
827 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
828 data.WriteInt32(zoneID);
829 ret = AudioInterrupt::Marshalling(data, audioInterrupt);
830 CHECK_AND_RETURN_RET_LOG(ret, -1, "Marshalling failed");
831
832 int error = Remote()->SendRequest(
833 static_cast<uint32_t>(AudioPolicyInterfaceCode::DEACTIVATE_INTERRUPT), data, reply, option);
834 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "deactivate interrupt failed, error: %{public}d", error);
835
836 return reply.ReadInt32();
837 }
838
RequestAudioFocus(const int32_t clientId,const AudioInterrupt & audioInterrupt)839 int32_t AudioPolicyProxy::RequestAudioFocus(const int32_t clientId, const AudioInterrupt &audioInterrupt)
840 {
841 MessageParcel data;
842 MessageParcel reply;
843 MessageOption option;
844
845 bool ret = data.WriteInterfaceToken(GetDescriptor());
846 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
847
848 data.WriteInt32(clientId);
849 ret = AudioInterrupt::Marshalling(data, audioInterrupt);
850 CHECK_AND_RETURN_RET_LOG(ret, -1, "Marshalling failed");
851
852 int error = Remote()->SendRequest(
853 static_cast<uint32_t>(AudioPolicyInterfaceCode::REQUEST_AUDIO_FOCUS), data, reply, option);
854 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "activate interrupt failed, error: %{public}d", error);
855
856 return reply.ReadInt32();
857 }
858
AbandonAudioFocus(const int32_t clientId,const AudioInterrupt & audioInterrupt)859 int32_t AudioPolicyProxy::AbandonAudioFocus(const int32_t clientId, const AudioInterrupt &audioInterrupt)
860 {
861 MessageParcel data;
862 MessageParcel reply;
863 MessageOption option;
864
865 bool ret = data.WriteInterfaceToken(GetDescriptor());
866 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
867 data.WriteInt32(clientId);
868 ret = AudioInterrupt::Marshalling(data, audioInterrupt);
869 CHECK_AND_RETURN_RET_LOG(ret, -1, "Marshalling failed");
870
871 int error = Remote()->SendRequest(
872 static_cast<uint32_t>(AudioPolicyInterfaceCode::ABANDON_AUDIO_FOCUS), data, reply, option);
873 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "deactivate interrupt failed, error: %{public}d", error);
874
875 return reply.ReadInt32();
876 }
877
GetStreamInFocus(const int32_t zoneID)878 AudioStreamType AudioPolicyProxy::GetStreamInFocus(const int32_t zoneID)
879 {
880 MessageParcel data;
881 MessageParcel reply;
882 MessageOption option;
883
884 bool ret = data.WriteInterfaceToken(GetDescriptor());
885 CHECK_AND_RETURN_RET_LOG(ret, STREAM_DEFAULT, "WriteInterfaceToken failed");
886 data.WriteInt32(zoneID);
887 int32_t error = Remote()->SendRequest(
888 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_STREAM_IN_FOCUS), data, reply, option);
889 if (error != ERR_NONE) {
890 AUDIO_ERR_LOG("get stream in focus failed, error: %d", error);
891 }
892 return static_cast<AudioStreamType>(reply.ReadInt32());
893 }
894
GetStreamInFocusByUid(const int32_t uid,const int32_t zoneID)895 AudioStreamType AudioPolicyProxy::GetStreamInFocusByUid(const int32_t uid, const int32_t zoneID)
896 {
897 MessageParcel data;
898 MessageParcel reply;
899 MessageOption option;
900
901 bool ret = data.WriteInterfaceToken(GetDescriptor());
902 CHECK_AND_RETURN_RET_LOG(ret, STREAM_DEFAULT, "WriteInterfaceToken failed");
903 data.WriteInt32(zoneID);
904 data.WriteInt32(uid);
905 int32_t error = Remote()->SendRequest(
906 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_STREAM_IN_FOCUS_BY_UID), data, reply, option);
907 if (error != ERR_NONE) {
908 AUDIO_ERR_LOG("get stream in focus by uid failed, error: %d", error);
909 }
910 return static_cast<AudioStreamType>(reply.ReadInt32());
911 }
912
GetSessionInfoInFocus(AudioInterrupt & audioInterrupt,const int32_t zoneID)913 int32_t AudioPolicyProxy::GetSessionInfoInFocus(AudioInterrupt &audioInterrupt, const int32_t zoneID)
914 {
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(zoneID);
922 int32_t error = Remote()->SendRequest(
923 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_SESSION_INFO_IN_FOCUS), data, reply, option);
924 if (error != ERR_NONE) {
925 AUDIO_ERR_LOG("AudioPolicyProxy::GetSessionInfoInFocus failed, error: %d", error);
926 }
927 AudioInterrupt::Unmarshalling(reply, audioInterrupt);
928
929 return reply.ReadInt32();
930 }
931
ReconfigureAudioChannel(const uint32_t & count,DeviceType deviceType)932 int32_t AudioPolicyProxy::ReconfigureAudioChannel(const uint32_t &count, DeviceType deviceType)
933 {
934 MessageParcel data;
935 MessageParcel reply;
936 MessageOption option;
937
938 bool ret = data.WriteInterfaceToken(GetDescriptor());
939 CHECK_AND_RETURN_RET_LOG(ret, IPC_PROXY_ERR, "WriteInterfaceToken failed");
940
941 data.WriteUint32(count);
942 data.WriteInt32(deviceType);
943
944 int result = Remote()->SendRequest(
945 static_cast<uint32_t>(AudioPolicyInterfaceCode::RECONFIGURE_CHANNEL), data, reply, option);
946 CHECK_AND_RETURN_RET_LOG(result == ERR_NONE, ERR_TRANSACTION_FAILED,
947 "ReconfigureAudioChannel failed, result: %{public}d", result);
948
949 return reply.ReadInt32();
950 }
951
GetPreferredOutputStreamType(AudioRendererInfo & rendererInfo)952 int32_t AudioPolicyProxy::GetPreferredOutputStreamType(AudioRendererInfo &rendererInfo)
953 {
954 MessageParcel data;
955 MessageParcel reply;
956 MessageOption option;
957
958 bool ret = data.WriteInterfaceToken(GetDescriptor());
959 CHECK_AND_RETURN_RET_LOG(ret, AUDIO_FLAG_INVALID, "WriteInterfaceToken failed");
960
961 ret = rendererInfo.Marshalling(data);
962 CHECK_AND_RETURN_RET_LOG(ret, AUDIO_FLAG_INVALID, "Marshalling rendererInfo failed");
963
964 int32_t error = Remote()->SendRequest(
965 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_PREFERRED_OUTPUT_STREAM_TYPE), data, reply, option);
966 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_FLAG_INVALID, "Failed to send request, error: %{public}d", error);
967
968 return reply.ReadInt32();
969 }
970
GetPreferredInputStreamType(AudioCapturerInfo & capturerInfo)971 int32_t AudioPolicyProxy::GetPreferredInputStreamType(AudioCapturerInfo &capturerInfo)
972 {
973 MessageParcel data;
974 MessageParcel reply;
975 MessageOption option;
976
977 bool ret = data.WriteInterfaceToken(GetDescriptor());
978 CHECK_AND_RETURN_RET_LOG(ret, AUDIO_FLAG_INVALID, "WriteInterfaceToken failed");
979
980 ret = capturerInfo.Marshalling(data);
981 CHECK_AND_RETURN_RET_LOG(ret, AUDIO_FLAG_INVALID, "Marshalling capturerInfo failed");
982
983 int32_t error = Remote()->SendRequest(
984 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_PREFERRED_INPUT_STREAM_TYPE), data, reply, option);
985 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_FLAG_INVALID, "Failed to send request, error: %{public}d", error);
986
987 return reply.ReadInt32();
988 }
989
RegisterTracker(AudioMode & mode,AudioStreamChangeInfo & streamChangeInfo,const sptr<IRemoteObject> & object)990 int32_t AudioPolicyProxy::RegisterTracker(AudioMode &mode, AudioStreamChangeInfo &streamChangeInfo,
991 const sptr<IRemoteObject> &object)
992 {
993 MessageParcel data;
994 MessageParcel reply;
995 MessageOption option;
996
997 bool ret = data.WriteInterfaceToken(GetDescriptor());
998 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
999
1000 CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "Register Tracker Event object is null");
1001
1002 data.WriteUint32(mode);
1003 WriteStreamChangeInfo(data, mode, streamChangeInfo);
1004 data.WriteRemoteObject(object);
1005
1006 int32_t error = Remote()->SendRequest(
1007 static_cast<uint32_t>(AudioPolicyInterfaceCode::REGISTER_TRACKER), data, reply, option);
1008 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "event failed , error: %d", error);
1009
1010 return reply.ReadInt32();
1011 }
1012
UpdateTracker(AudioMode & mode,AudioStreamChangeInfo & streamChangeInfo)1013 int32_t AudioPolicyProxy::UpdateTracker(AudioMode &mode, AudioStreamChangeInfo &streamChangeInfo)
1014 {
1015 MessageParcel data;
1016 MessageParcel reply;
1017 MessageOption option;
1018
1019 bool ret = data.WriteInterfaceToken(GetDescriptor());
1020 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
1021
1022 data.WriteUint32(mode);
1023 WriteStreamChangeInfo(data, mode, streamChangeInfo);
1024
1025 int32_t error = Remote()->SendRequest(
1026 static_cast<uint32_t>(AudioPolicyInterfaceCode::UPDATE_TRACKER), data, reply, option);
1027 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "UpdateTracker event failed , error: %d", error);
1028
1029 return reply.ReadInt32();
1030 }
1031
FetchOutputDeviceForTrack(AudioStreamChangeInfo & streamChangeInfo,const AudioStreamDeviceChangeReasonExt reason)1032 void AudioPolicyProxy::FetchOutputDeviceForTrack(AudioStreamChangeInfo &streamChangeInfo,
1033 const AudioStreamDeviceChangeReasonExt reason)
1034 {
1035 MessageParcel data;
1036 MessageParcel reply;
1037 MessageOption option;
1038
1039 bool ret = data.WriteInterfaceToken(GetDescriptor());
1040 if (!ret) {
1041 AUDIO_ERR_LOG("WriteInterfaceToken failed");
1042 }
1043
1044 streamChangeInfo.audioRendererChangeInfo.Marshalling(data);
1045
1046 data.WriteInt32(static_cast<int32_t>(reason));
1047
1048 int32_t error = Remote()->SendRequest(
1049 static_cast<uint32_t>(AudioPolicyInterfaceCode::FETCH_OUTPUT_DEVICE_FOR_TRACK), data, reply, option);
1050 if (error != ERR_NONE) {
1051 AUDIO_ERR_LOG("event failed , error: %d", error);
1052 }
1053 return;
1054 }
1055
FetchInputDeviceForTrack(AudioStreamChangeInfo & streamChangeInfo)1056 void AudioPolicyProxy::FetchInputDeviceForTrack(AudioStreamChangeInfo &streamChangeInfo)
1057 {
1058 MessageParcel data;
1059 MessageParcel reply;
1060 MessageOption option;
1061
1062 bool ret = data.WriteInterfaceToken(GetDescriptor());
1063 if (!ret) {
1064 AUDIO_ERR_LOG("WriteInterfaceToken failed");
1065 }
1066
1067 streamChangeInfo.audioCapturerChangeInfo.Marshalling(data);
1068
1069 int32_t error = Remote()->SendRequest(
1070 static_cast<uint32_t>(AudioPolicyInterfaceCode::FETCH_INPUT_DEVICE_FOR_TRACK), data, reply, option);
1071 if (error != ERR_NONE) {
1072 AUDIO_ERR_LOG("event failed , error: %d", error);
1073 }
1074 return;
1075 }
1076
GetCurrentRendererChangeInfos(vector<shared_ptr<AudioRendererChangeInfo>> & audioRendererChangeInfos)1077 int32_t AudioPolicyProxy::GetCurrentRendererChangeInfos(
1078 vector<shared_ptr<AudioRendererChangeInfo>> &audioRendererChangeInfos)
1079 {
1080 MessageParcel data;
1081 MessageParcel reply;
1082 MessageOption option;
1083
1084 bool ret = data.WriteInterfaceToken(GetDescriptor());
1085 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
1086
1087 int32_t error = Remote()->SendRequest(
1088 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_RENDERER_CHANGE_INFOS), data, reply, option);
1089 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "Get Renderer change info event failed , error: %d", error);
1090
1091 int32_t size = reply.ReadInt32();
1092 while (size > 0) {
1093 shared_ptr<AudioRendererChangeInfo> rendererChangeInfo = make_shared<AudioRendererChangeInfo>();
1094 CHECK_AND_RETURN_RET_LOG(rendererChangeInfo != nullptr, ERR_MEMORY_ALLOC_FAILED, "No memory!!");
1095 rendererChangeInfo->Unmarshalling(reply);
1096 audioRendererChangeInfos.push_back(move(rendererChangeInfo));
1097 size--;
1098 }
1099
1100 return SUCCESS;
1101 }
1102
GetCurrentCapturerChangeInfos(vector<shared_ptr<AudioCapturerChangeInfo>> & audioCapturerChangeInfos)1103 int32_t AudioPolicyProxy::GetCurrentCapturerChangeInfos(
1104 vector<shared_ptr<AudioCapturerChangeInfo>> &audioCapturerChangeInfos)
1105 {
1106 MessageParcel data;
1107 MessageParcel reply;
1108 MessageOption option;
1109
1110 AUDIO_DEBUG_LOG("AudioPolicyProxy::GetCurrentCapturerChangeInfos");
1111
1112 bool ret = data.WriteInterfaceToken(GetDescriptor());
1113 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
1114
1115 int32_t error = Remote()->SendRequest(
1116 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_CAPTURER_CHANGE_INFOS), data, reply, option);
1117 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "Get capturer change info event failed , error: %d", error);
1118
1119 int32_t size = reply.ReadInt32();
1120 while (size > 0) {
1121 shared_ptr<AudioCapturerChangeInfo> capturerChangeInfo = make_shared<AudioCapturerChangeInfo>();
1122 CHECK_AND_RETURN_RET_LOG(capturerChangeInfo != nullptr, ERR_MEMORY_ALLOC_FAILED, "No memory!!");
1123 capturerChangeInfo->Unmarshalling(reply);
1124 audioCapturerChangeInfos.push_back(move(capturerChangeInfo));
1125 size--;
1126 }
1127
1128 return SUCCESS;
1129 }
1130
UpdateStreamState(const int32_t clientUid,StreamSetState streamSetState,StreamUsage streamUsage)1131 int32_t AudioPolicyProxy::UpdateStreamState(const int32_t clientUid, StreamSetState streamSetState,
1132 StreamUsage streamUsage)
1133 {
1134 MessageParcel data;
1135 MessageParcel reply;
1136 MessageOption option;
1137
1138 bool ret = data.WriteInterfaceToken(GetDescriptor());
1139 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
1140
1141 data.WriteInt32(static_cast<int32_t>(clientUid));
1142 data.WriteInt32(static_cast<int32_t>(streamSetState));
1143 data.WriteInt32(static_cast<int32_t>(streamUsage));
1144
1145 int32_t error = Remote()->SendRequest(
1146 static_cast<uint32_t>(AudioPolicyInterfaceCode::UPDATE_STREAM_STATE), data, reply, option);
1147 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR,
1148 "UPDATE_STREAM_STATE stream changed info event failed , error: %d", error);
1149
1150 return SUCCESS;
1151 }
1152
GetNetworkIdByGroupId(int32_t groupId,std::string & networkId)1153 int32_t AudioPolicyProxy::GetNetworkIdByGroupId(int32_t groupId, std::string &networkId)
1154 {
1155 MessageParcel data;
1156 MessageParcel reply;
1157 MessageOption option;
1158
1159 bool res = data.WriteInterfaceToken(GetDescriptor());
1160 CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed");
1161 data.WriteInt32(groupId);
1162 int32_t error = Remote()->SendRequest(
1163 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_NETWORKID_BY_GROUP_ID), data, reply, option);
1164 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "GetNetworkIdByGroupId, error: %d", error);
1165
1166 networkId = reply.ReadString();
1167 int32_t ret = reply.ReadInt32();
1168 return ret;
1169 }
1170
SetSystemSoundUri(const std::string & key,const std::string & uri)1171 int32_t AudioPolicyProxy::SetSystemSoundUri(const std::string &key, const std::string &uri)
1172 {
1173 MessageParcel data;
1174 MessageParcel reply;
1175 MessageOption option;
1176
1177 bool ret = data.WriteInterfaceToken(GetDescriptor());
1178 CHECK_AND_RETURN_RET_LOG(ret, IPC_PROXY_ERR, "WriteInterfaceToken failed");
1179 data.WriteString(key);
1180 data.WriteString(uri);
1181 int32_t error = Remote()->SendRequest(
1182 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_SYSTEM_SOUND_URI), data, reply, option);
1183 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SetSystemSoundUri failed, error: %d", error);
1184 return reply.ReadInt32();
1185 }
1186
GetSystemSoundUri(const std::string & key)1187 std::string AudioPolicyProxy::GetSystemSoundUri(const std::string &key)
1188 {
1189 MessageParcel data;
1190 MessageParcel reply;
1191 MessageOption option;
1192
1193 bool ret = data.WriteInterfaceToken(GetDescriptor());
1194 CHECK_AND_RETURN_RET_LOG(ret, "", "WriteInterfaceToken failed");
1195 data.WriteString(key);
1196 int32_t error = Remote()->SendRequest(
1197 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_SYSTEM_SOUND_URI), data, reply, option);
1198 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, "", "GetSystemSoundUri failed, error: %d", error);
1199 return reply.ReadString();
1200 }
1201
GetMaxRendererInstances()1202 int32_t AudioPolicyProxy::GetMaxRendererInstances()
1203 {
1204 MessageParcel data;
1205 MessageParcel reply;
1206 MessageOption option;
1207
1208 bool ret = data.WriteInterfaceToken(GetDescriptor());
1209 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
1210 int32_t error = Remote()->SendRequest(
1211 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_MAX_RENDERER_INSTANCES), data, reply, option);
1212 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "GetMaxRendererInstances failed, error: %d", error);
1213 return reply.ReadInt32();
1214 }
1215
PreprocessMode(Stream & stream,MessageParcel & reply,int countMode)1216 static void PreprocessMode(Stream &stream, MessageParcel &reply, int countMode)
1217 {
1218 for (int j = 0; j < countMode; j++) {
1219 StreamEffectMode streamEffectMode;
1220 streamEffectMode.mode = reply.ReadString();
1221 int countDev = reply.ReadInt32();
1222 if (countDev > 0) {
1223 for (int k = 0; k < countDev; k++) {
1224 string type = reply.ReadString();
1225 string chain = reply.ReadString();
1226 streamEffectMode.devicePort.push_back({type, chain});
1227 }
1228 }
1229 stream.streamEffectMode.push_back(streamEffectMode);
1230 }
1231 }
1232
PreprocessProcess(MessageParcel & reply)1233 static Stream PreprocessProcess(MessageParcel &reply)
1234 {
1235 Stream stream;
1236 stream.scene = reply.ReadString();
1237 int countMode = reply.ReadInt32();
1238 if (countMode > 0) {
1239 PreprocessMode(stream, reply, countMode);
1240 }
1241 return stream;
1242 }
1243
PostprocessMode(Stream & stream,MessageParcel & reply,int countMode)1244 static void PostprocessMode(Stream &stream, MessageParcel &reply, int countMode)
1245 {
1246 for (int j = 0; j < countMode; j++) {
1247 StreamEffectMode streamEffectMode;
1248 streamEffectMode.mode = reply.ReadString();
1249 int countDev = reply.ReadInt32();
1250 if (countDev > 0) {
1251 for (int k = 0; k < countDev; k++) {
1252 string type = reply.ReadString();
1253 string chain = reply.ReadString();
1254 streamEffectMode.devicePort.push_back({type, chain});
1255 }
1256 }
1257 stream.streamEffectMode.push_back(streamEffectMode);
1258 }
1259 }
1260
PostprocessProcess(MessageParcel & reply)1261 static Stream PostprocessProcess(MessageParcel &reply)
1262 {
1263 Stream stream;
1264 stream.scene = reply.ReadString();
1265 int countMode = reply.ReadInt32();
1266 if (countMode > 0) {
1267 PostprocessMode(stream, reply, countMode);
1268 }
1269 return stream;
1270 }
1271
QueryEffectSceneModeChkReply(uint32_t countPre,uint32_t countPost)1272 static int32_t QueryEffectSceneModeChkReply(uint32_t countPre, uint32_t countPost)
1273 {
1274 CHECK_AND_RETURN_RET_LOG((countPre >= 0) && (countPre <= AUDIO_EFFECT_COUNT_UPPER_LIMIT), -1,
1275 "QUERY_EFFECT_SCENEMODE read replyParcel failed");
1276 CHECK_AND_RETURN_RET_LOG((countPost >= 0) && (countPost <= AUDIO_EFFECT_COUNT_UPPER_LIMIT), -1,
1277 "QUERY_EFFECT_SCENEMODE read replyParcel failed");
1278 return 0;
1279 }
1280
QueryEffectSceneMode(SupportedEffectConfig & supportedEffectConfig)1281 int32_t AudioPolicyProxy::QueryEffectSceneMode(SupportedEffectConfig &supportedEffectConfig)
1282 {
1283 uint32_t i;
1284 int32_t error;
1285 MessageParcel data;
1286 MessageParcel reply;
1287 MessageOption option;
1288 bool ret = data.WriteInterfaceToken(GetDescriptor());
1289 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
1290 error = Remote()->SendRequest(
1291 static_cast<uint32_t>(AudioPolicyInterfaceCode::QUERY_EFFECT_SCENEMODE), data, reply, option);
1292 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "get scene & mode failed, error: %d", error);
1293 uint32_t countPre = reply.ReadUint32();
1294 uint32_t countPost = reply.ReadUint32();
1295 uint32_t countPostMap = reply.ReadUint32();
1296 error = QueryEffectSceneModeChkReply(countPre, countPost);
1297 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "get scene & mode failed, error: %d", error);
1298 // preprocess
1299 Stream stream;
1300 if (countPre > 0) {
1301 ProcessNew preProcessNew;
1302 for (i = 0; i < countPre; i++) {
1303 stream = PreprocessProcess(reply);
1304 preProcessNew.stream.push_back(stream);
1305 }
1306 supportedEffectConfig.preProcessNew = preProcessNew;
1307 }
1308 // postprocess
1309 if (countPost > 0) {
1310 ProcessNew postProcessNew;
1311 for (i = 0; i < countPost; i++) {
1312 stream = PostprocessProcess(reply);
1313 postProcessNew.stream.push_back(stream);
1314 }
1315 supportedEffectConfig.postProcessNew = postProcessNew;
1316 }
1317 if (countPostMap > 0) {
1318 SceneMappingItem item;
1319 for (i = 0; i < countPostMap; i++) {
1320 item.name = reply.ReadString();
1321 item.sceneType = reply.ReadString();
1322 supportedEffectConfig.postProcessSceneMap.push_back(item);
1323 }
1324 }
1325 return 0;
1326 }
1327
GetHardwareOutputSamplingRate(const std::shared_ptr<AudioDeviceDescriptor> & desc)1328 int32_t AudioPolicyProxy::GetHardwareOutputSamplingRate(const std::shared_ptr<AudioDeviceDescriptor> &desc)
1329 {
1330 MessageParcel data;
1331 MessageParcel reply;
1332 MessageOption option;
1333
1334 bool ret = data.WriteInterfaceToken(GetDescriptor());
1335 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
1336
1337 bool result = desc->Marshalling(data);
1338 CHECK_AND_RETURN_RET_LOG(result, -1, "AudioDeviceDescriptor Marshalling() failed");
1339
1340 int32_t error = Remote()->SendRequest(
1341 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_HARDWARE_OUTPUT_SAMPLING_RATE), data, reply, option);
1342 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "event failed , error: %d", error);
1343
1344 return reply.ReadInt32();
1345 }
1346
GetAvailableDevices(AudioDeviceUsage usage)1347 std::vector<std::shared_ptr<AudioDeviceDescriptor>> AudioPolicyProxy::GetAvailableDevices(AudioDeviceUsage usage)
1348 {
1349 MessageParcel data;
1350 MessageParcel reply;
1351 MessageOption option;
1352 std::vector<std::shared_ptr<AudioDeviceDescriptor>> audioDeviceDescriptors;
1353
1354 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()),
1355 audioDeviceDescriptors, "WriteInterfaceToken failed");
1356
1357 bool token = data.WriteInt32(static_cast<int32_t>(usage));
1358 CHECK_AND_RETURN_RET_LOG(token, audioDeviceDescriptors, "WriteInt32 usage failed");
1359
1360 int32_t error = Remote()->SendRequest(
1361 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_AVAILABLE_DESCRIPTORS), data, reply, option);
1362 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, audioDeviceDescriptors, "GetAvailableDevices failed, error: %d", error);
1363
1364 int32_t size = reply.ReadInt32();
1365 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= static_cast<int32_t>(AUDIO_DEVICE_INFO_SIZE_LIMIT),
1366 audioDeviceDescriptors, "Using tainted data size: %{public}d as loop bound", size);
1367 for (int32_t i = 0; i < size; i++) {
1368 std::shared_ptr<AudioDeviceDescriptor> desc =
1369 std::make_shared<AudioDeviceDescriptor>(AudioDeviceDescriptor::UnmarshallingPtr(reply));
1370 audioDeviceDescriptors.push_back(move(desc));
1371 }
1372 return audioDeviceDescriptors;
1373 }
1374
IsSpatializationEnabled()1375 bool AudioPolicyProxy::IsSpatializationEnabled()
1376 {
1377 MessageParcel data;
1378 MessageParcel reply;
1379 MessageOption option;
1380
1381 bool ret = data.WriteInterfaceToken(GetDescriptor());
1382 CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
1383
1384 int32_t error = Remote()->SendRequest(
1385 static_cast<uint32_t>(AudioPolicyInterfaceCode::IS_SPATIALIZATION_ENABLED), data, reply, option);
1386 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "IsSpatializationEnabled failed, error: %{public}d", error);
1387 return reply.ReadBool();
1388 }
1389
IsSpatializationEnabled(const std::string address)1390 bool AudioPolicyProxy::IsSpatializationEnabled(const std::string address)
1391 {
1392 MessageParcel data;
1393 MessageParcel reply;
1394 MessageOption option;
1395
1396 bool ret = data.WriteInterfaceToken(GetDescriptor());
1397 CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
1398 data.WriteString(address);
1399
1400 int32_t error = Remote()->SendRequest(
1401 static_cast<uint32_t>(AudioPolicyInterfaceCode::IS_SPATIALIZATION_ENABLED_FOR_DEVICE), data, reply, option);
1402 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "IsSpatializationEnabled failed, error: %{public}d", error);
1403 return reply.ReadBool();
1404 }
1405
IsSpatializationEnabledForCurrentDevice()1406 bool AudioPolicyProxy::IsSpatializationEnabledForCurrentDevice()
1407 {
1408 MessageParcel data;
1409 MessageParcel reply;
1410 MessageOption option;
1411
1412 bool ret = data.WriteInterfaceToken(GetDescriptor());
1413 CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
1414
1415 int32_t error = Remote()->SendRequest(
1416 static_cast<uint32_t>(AudioPolicyInterfaceCode::IS_SPATIALIZATION_ENABLED_FOR_CURRENT_DEVICE),
1417 data, reply, option);
1418 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "IsSpatializationEnabled failed, error: %{public}d", error);
1419 return reply.ReadBool();
1420 }
1421
SetSpatializationEnabled(const bool enable)1422 int32_t AudioPolicyProxy::SetSpatializationEnabled(const bool enable)
1423 {
1424 MessageParcel data;
1425 MessageParcel reply;
1426 MessageOption option;
1427
1428 bool ret = data.WriteInterfaceToken(GetDescriptor());
1429 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
1430 data.WriteBool(enable);
1431
1432 int32_t error = Remote()->SendRequest(
1433 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_SPATIALIZATION_ENABLED), data, reply, option);
1434 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SetSpatializationEnabled failed, error: %{public}d", error);
1435 return reply.ReadInt32();
1436 }
1437
SetSpatializationEnabled(const std::shared_ptr<AudioDeviceDescriptor> & selectedAudioDevice,const bool enable)1438 int32_t AudioPolicyProxy::SetSpatializationEnabled(const std::shared_ptr<AudioDeviceDescriptor> &selectedAudioDevice,
1439 const bool enable)
1440 {
1441 MessageParcel data;
1442 MessageParcel reply;
1443 MessageOption option;
1444
1445 bool ret = data.WriteInterfaceToken(GetDescriptor());
1446 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
1447
1448 bool result = selectedAudioDevice->Marshalling(data);
1449 CHECK_AND_RETURN_RET_LOG(result, -1, "SelectedAudioDevice Marshalling() failed");
1450
1451 data.WriteBool(enable);
1452
1453 int32_t error = Remote()->SendRequest(
1454 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_SPATIALIZATION_ENABLED_FOR_DEVICE), data, reply, option);
1455 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SetSpatializationEnabled failed, error: %{public}d", error);
1456 return reply.ReadInt32();
1457 }
1458
IsHeadTrackingEnabled()1459 bool AudioPolicyProxy::IsHeadTrackingEnabled()
1460 {
1461 MessageParcel data;
1462 MessageParcel reply;
1463 MessageOption option;
1464
1465 bool ret = data.WriteInterfaceToken(GetDescriptor());
1466 CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
1467
1468 int32_t error = Remote()->SendRequest(
1469 static_cast<uint32_t>(AudioPolicyInterfaceCode::IS_HEAD_TRACKING_ENABLED), data, reply, option);
1470
1471 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "IsHeadTrackingEnabled failed, error: %{public}d", error);
1472 return reply.ReadBool();
1473 }
1474
IsHeadTrackingEnabled(const std::string address)1475 bool AudioPolicyProxy::IsHeadTrackingEnabled(const std::string address)
1476 {
1477 MessageParcel data;
1478 MessageParcel reply;
1479 MessageOption option;
1480
1481 bool ret = data.WriteInterfaceToken(GetDescriptor());
1482 CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
1483 data.WriteString(address);
1484
1485 int32_t error = Remote()->SendRequest(
1486 static_cast<uint32_t>(AudioPolicyInterfaceCode::IS_HEAD_TRACKING_ENABLED_FOR_DEVICE), data, reply, option);
1487
1488 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "IsHeadTrackingEnabled failed, error: %{public}d", error);
1489 return reply.ReadBool();
1490 }
1491
SetHeadTrackingEnabled(const bool enable)1492 int32_t AudioPolicyProxy::SetHeadTrackingEnabled(const bool enable)
1493 {
1494 MessageParcel data;
1495 MessageParcel reply;
1496 MessageOption option;
1497
1498 bool ret = data.WriteInterfaceToken(GetDescriptor());
1499 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
1500 data.WriteBool(enable);
1501
1502 int32_t error = Remote()->SendRequest(
1503 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_HEAD_TRACKING_ENABLED), data, reply, option);
1504 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SetHeadTrackingEnabled failed, error: %{public}d", error);
1505 return reply.ReadInt32();
1506 }
1507
SetHeadTrackingEnabled(const std::shared_ptr<AudioDeviceDescriptor> & selectedAudioDevice,const bool enable)1508 int32_t AudioPolicyProxy::SetHeadTrackingEnabled(const std::shared_ptr<AudioDeviceDescriptor> &selectedAudioDevice,
1509 const bool enable)
1510 {
1511 MessageParcel data;
1512 MessageParcel reply;
1513 MessageOption option;
1514
1515 bool ret = data.WriteInterfaceToken(GetDescriptor());
1516 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
1517
1518 bool result = selectedAudioDevice->Marshalling(data);
1519 CHECK_AND_RETURN_RET_LOG(result, -1, "SelectedAudioDevice Marshalling() failed");
1520 data.WriteBool(enable);
1521
1522 int32_t error = Remote()->SendRequest(
1523 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_HEAD_TRACKING_ENABLED_FOR_DEVICE), data, reply, option);
1524 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SetHeadTrackingEnabled failed, error: %{public}d", error);
1525 return reply.ReadInt32();
1526 }
1527
GetSpatializationState(const StreamUsage streamUsage)1528 AudioSpatializationState AudioPolicyProxy::GetSpatializationState(const StreamUsage streamUsage)
1529 {
1530 MessageParcel data;
1531 MessageParcel reply;
1532 MessageOption option;
1533 AudioSpatializationState spatializationState = {false, false};
1534
1535 bool ret = data.WriteInterfaceToken(GetDescriptor());
1536 CHECK_AND_RETURN_RET_LOG(ret, spatializationState, "WriteInterfaceToken failed");
1537
1538 data.WriteInt32(static_cast<int32_t>(streamUsage));
1539 int32_t error = Remote() ->SendRequest(
1540 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_SPATIALIZATION_STATE), data, reply, option);
1541 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, spatializationState, "SendRequest failed, error: %{public}d", error);
1542
1543 spatializationState.spatializationEnabled = reply.ReadBool();
1544 spatializationState.headTrackingEnabled = reply.ReadBool();
1545
1546 return spatializationState;
1547 }
1548
IsSpatializationSupported()1549 bool AudioPolicyProxy::IsSpatializationSupported()
1550 {
1551 MessageParcel data;
1552 MessageParcel reply;
1553 MessageOption option;
1554
1555 bool ret = data.WriteInterfaceToken(GetDescriptor());
1556 CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
1557
1558 int32_t error = Remote()->SendRequest(
1559 static_cast<uint32_t>(AudioPolicyInterfaceCode::IS_SPATIALIZATION_SUPPORTED), data, reply, option);
1560 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "IsSpatializationSupported failed, error: %d", error);
1561 return reply.ReadBool();
1562 }
1563
IsSpatializationSupportedForDevice(const std::string address)1564 bool AudioPolicyProxy::IsSpatializationSupportedForDevice(const std::string address)
1565 {
1566 MessageParcel data;
1567 MessageParcel reply;
1568 MessageOption option;
1569
1570 bool ret = data.WriteInterfaceToken(GetDescriptor());
1571 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
1572 data.WriteString(address);
1573
1574 int32_t error = Remote()->SendRequest(
1575 static_cast<uint32_t>(AudioPolicyInterfaceCode::IS_SPATIALIZATION_SUPPORTED_FOR_DEVICE), data, reply, option);
1576 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "IsSpatializationSupportedForDevice failed, error: %d", error);
1577 return reply.ReadBool();
1578 }
1579
IsHeadTrackingSupported()1580 bool AudioPolicyProxy::IsHeadTrackingSupported()
1581 {
1582 MessageParcel data;
1583 MessageParcel reply;
1584 MessageOption option;
1585
1586 bool ret = data.WriteInterfaceToken(GetDescriptor());
1587 CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
1588
1589 int32_t error = Remote()->SendRequest(
1590 static_cast<uint32_t>(AudioPolicyInterfaceCode::IS_HEAD_TRACKING_SUPPORTED), data, reply, option);
1591 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "IsHeadTrackingSupported failed, error: %d", error);
1592 return reply.ReadBool();
1593 }
1594
IsHeadTrackingSupportedForDevice(const std::string address)1595 bool AudioPolicyProxy::IsHeadTrackingSupportedForDevice(const std::string address)
1596 {
1597 MessageParcel data;
1598 MessageParcel reply;
1599 MessageOption option;
1600
1601 bool ret = data.WriteInterfaceToken(GetDescriptor());
1602 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
1603 data.WriteString(address);
1604
1605 int32_t error = Remote()->SendRequest(
1606 static_cast<uint32_t>(AudioPolicyInterfaceCode::IS_HEAD_TRACKING_SUPPORTED_FOR_DEVICE), data, reply, option);
1607 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "IsHeadTrackingSupportedForDevice failed, error: %d", error);
1608 return reply.ReadBool();
1609 }
1610
UpdateSpatialDeviceState(const AudioSpatialDeviceState audioSpatialDeviceState)1611 int32_t AudioPolicyProxy::UpdateSpatialDeviceState(const AudioSpatialDeviceState audioSpatialDeviceState)
1612 {
1613 MessageParcel data;
1614 MessageParcel reply;
1615 MessageOption option;
1616
1617 bool ret = data.WriteInterfaceToken(GetDescriptor());
1618 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
1619 data.WriteString(audioSpatialDeviceState.address);
1620 data.WriteBool(audioSpatialDeviceState.isSpatializationSupported);
1621 data.WriteBool(audioSpatialDeviceState.isHeadTrackingSupported);
1622 data.WriteInt32(static_cast<int32_t>(audioSpatialDeviceState.spatialDeviceType));
1623
1624 int32_t error = Remote()->SendRequest(
1625 static_cast<uint32_t>(AudioPolicyInterfaceCode::UPDATE_SPATIAL_DEVICE_STATE), data, reply, option);
1626 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "UpdateSpatialDeviceState failed, error: %d", error);
1627 return reply.ReadInt32();
1628 }
1629
CreateAudioInterruptZone(const std::set<int32_t> & pids,const int32_t zoneID)1630 int32_t AudioPolicyProxy::CreateAudioInterruptZone(const std::set<int32_t> &pids, const int32_t zoneID)
1631 {
1632 MessageParcel data;
1633 MessageParcel reply;
1634 MessageOption option;
1635 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), -1, "WriteInterfaceToken failed");
1636
1637 data.WriteInt32(zoneID);
1638 data.WriteInt32(pids.size());
1639 int32_t count = 0;
1640 for (int32_t pid : pids) {
1641 data.WriteInt32(pid);
1642 count++;
1643 if (count >= MAX_PID_COUNT) {
1644 break;
1645 }
1646 }
1647
1648 int error = Remote()->SendRequest(
1649 static_cast<uint32_t>(AudioPolicyInterfaceCode::CREATE_AUDIO_INTERRUPT_ZONE), data, reply, option);
1650
1651 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "CreateAudioInterruptZone failed, error: %d", error);
1652 return reply.ReadInt32();
1653 }
1654
AddAudioInterruptZonePids(const std::set<int32_t> & pids,const int32_t zoneID)1655 int32_t AudioPolicyProxy::AddAudioInterruptZonePids(const std::set<int32_t> &pids, const int32_t zoneID)
1656 {
1657 MessageParcel data;
1658 MessageParcel reply;
1659 MessageOption option;
1660 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), -1, "WriteInterfaceToken failed");
1661 data.WriteInt32(zoneID);
1662 data.WriteInt32(pids.size());
1663 int32_t count = 0;
1664 for (int32_t pid : pids) {
1665 data.WriteInt32(pid);
1666 count++;
1667 if (count >= MAX_PID_COUNT) {
1668 break;
1669 }
1670 }
1671
1672 int error = Remote()->SendRequest(
1673 static_cast<uint32_t>(AudioPolicyInterfaceCode::ADD_AUDIO_INTERRUPT_ZONE_PIDS), data, reply, option);
1674 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "AddAudioInterruptZonePids failed, error: %d", error);
1675 return reply.ReadInt32();
1676 }
1677
RemoveAudioInterruptZonePids(const std::set<int32_t> & pids,const int32_t zoneID)1678 int32_t AudioPolicyProxy::RemoveAudioInterruptZonePids(const std::set<int32_t> &pids, const int32_t zoneID)
1679 {
1680 MessageParcel data;
1681 MessageParcel reply;
1682 MessageOption option;
1683 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), -1, "WriteInterfaceToken failed");
1684 data.WriteInt32(zoneID);
1685 data.WriteInt32(pids.size());
1686 int32_t count = 0;
1687 for (int32_t pid : pids) {
1688 data.WriteInt32(pid);
1689 count++;
1690 if (count >= MAX_PID_COUNT) {
1691 break;
1692 }
1693 }
1694 int error = Remote()->SendRequest(
1695 static_cast<uint32_t>(AudioPolicyInterfaceCode::REMOVE_AUDIO_INTERRUPT_ZONE_PIDS), data, reply, option);
1696 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "RemoveAudioInterruptZonePids failed, error: %d", error);
1697
1698 return reply.ReadInt32();
1699 }
1700
ReleaseAudioInterruptZone(const int32_t zoneID)1701 int32_t AudioPolicyProxy::ReleaseAudioInterruptZone(const int32_t zoneID)
1702 {
1703 MessageParcel data;
1704 MessageParcel reply;
1705 MessageOption option;
1706 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), -1, "WriteInterfaceToken failed");
1707 data.WriteInt32(zoneID);
1708 int error = Remote()->SendRequest(
1709 static_cast<uint32_t>(AudioPolicyInterfaceCode::RELEASE_AUDIO_INTERRUPT_ZONE), data, reply, option);
1710 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "ReleaseAudioInterruptZone failed, error: %d", error);
1711 return reply.ReadInt32();
1712 }
1713
SetCallDeviceActive(InternalDeviceType deviceType,bool active,std::string address,const int32_t uid)1714 int32_t AudioPolicyProxy::SetCallDeviceActive(InternalDeviceType deviceType, bool active, std::string address,
1715 const int32_t uid)
1716 {
1717 MessageParcel data;
1718 MessageParcel reply;
1719 MessageOption option;
1720
1721 bool ret = data.WriteInterfaceToken(GetDescriptor());
1722 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
1723 data.WriteInt32(static_cast<int32_t>(deviceType));
1724 data.WriteBool(active);
1725 data.WriteString(address);
1726 data.WriteInt32(uid);
1727 int32_t error = Remote()->SendRequest(
1728 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_CALL_DEVICE_ACTIVE), data, reply, option);
1729 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %d", error);
1730 return reply.ReadInt32();
1731 }
1732
GetActiveBluetoothDevice()1733 std::shared_ptr<AudioDeviceDescriptor> AudioPolicyProxy::GetActiveBluetoothDevice()
1734 {
1735 MessageParcel data;
1736 MessageParcel reply;
1737 MessageOption option;
1738 std::shared_ptr<AudioDeviceDescriptor> audioDeviceDescriptor;
1739
1740 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()),
1741 audioDeviceDescriptor, "WriteInterfaceToken failed");
1742
1743 int32_t error = Remote()->SendRequest(
1744 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_ACTIVE_BLUETOOTH_DESCRIPTOR), data, reply, option);
1745 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, audioDeviceDescriptor,
1746 "GetActiveBluetoothDevice failed, error: %d", error);
1747
1748 std::shared_ptr<AudioDeviceDescriptor> desc =
1749 std::make_shared<AudioDeviceDescriptor>(AudioDeviceDescriptor::UnmarshallingPtr(reply));
1750 return desc;
1751 }
1752
GetConverterConfig()1753 ConverterConfig AudioPolicyProxy::GetConverterConfig()
1754 {
1755 MessageParcel data;
1756 MessageParcel reply;
1757 MessageOption option;
1758 ConverterConfig result;
1759
1760 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), result, "WriteInterfaceToken failed");
1761 int32_t error = Remote()->SendRequest(static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_AUDIO_CONVERTER_CONFIG),
1762 data, reply, option);
1763 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, result, "failed, error: %d", error);
1764
1765 result.library = {reply.ReadString(), reply.ReadString()};
1766 result.outChannelLayout = reply.ReadUint64();
1767 return result;
1768 }
1769
IsHighResolutionExist()1770 bool AudioPolicyProxy::IsHighResolutionExist()
1771 {
1772 MessageParcel data;
1773 MessageParcel reply;
1774 MessageOption option;
1775
1776 bool ret = data.WriteInterfaceToken(GetDescriptor());
1777 CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
1778 int32_t error = Remote()->SendRequest(
1779 static_cast<uint32_t>(AudioPolicyInterfaceCode::IS_HIGH_RESOLUTION_EXIST), data, reply, option);
1780 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERR_TRANSACTION_FAILED, "SendRequest failed, error: %d", error);
1781
1782 bool replyReadBool = reply.ReadBool();
1783 return replyReadBool;
1784 }
1785
SetHighResolutionExist(bool highResExist)1786 int32_t AudioPolicyProxy::SetHighResolutionExist(bool highResExist)
1787 {
1788 MessageParcel data;
1789 MessageParcel reply;
1790 MessageOption option;
1791
1792 bool ret = data.WriteInterfaceToken(GetDescriptor());
1793 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
1794
1795 data.WriteBool(highResExist);
1796 int32_t error = Remote()->SendRequest(
1797 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_HIGH_RESOLUTION_EXIST), data, reply, option);
1798 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %d", error);
1799 return SUCCESS;
1800 }
1801
GetSpatializationSceneType()1802 AudioSpatializationSceneType AudioPolicyProxy::GetSpatializationSceneType()
1803 {
1804 MessageParcel data;
1805 MessageParcel reply;
1806 MessageOption option;
1807
1808 bool ret = data.WriteInterfaceToken(GetDescriptor());
1809 CHECK_AND_RETURN_RET_LOG(ret, SPATIALIZATION_SCENE_TYPE_MUSIC, "WriteInterfaceToken failed");
1810
1811 int32_t error = Remote()->SendRequest(
1812 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_SPATIALIZATION_SCENE_TYPE), data, reply, option);
1813 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, SPATIALIZATION_SCENE_TYPE_MUSIC,
1814 "SendRequest failed, error: %{public}d", error);
1815 return static_cast<AudioSpatializationSceneType>(reply.ReadInt32());
1816 }
1817
SetSpatializationSceneType(const AudioSpatializationSceneType spatializationSceneType)1818 int32_t AudioPolicyProxy::SetSpatializationSceneType(const AudioSpatializationSceneType spatializationSceneType)
1819 {
1820 MessageParcel data;
1821 MessageParcel reply;
1822 MessageOption option;
1823
1824 bool ret = data.WriteInterfaceToken(GetDescriptor());
1825 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
1826 data.WriteInt32(static_cast<int32_t>(spatializationSceneType));
1827
1828 int32_t error = Remote()->SendRequest(
1829 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_SPATIALIZATION_SCENE_TYPE), data, reply, option);
1830 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SendRequest failed, error: %{public}d", error);
1831 return reply.ReadInt32();
1832 }
1833
GetMaxAmplitude(const int32_t deviceId)1834 float AudioPolicyProxy::GetMaxAmplitude(const int32_t deviceId)
1835 {
1836 MessageParcel data;
1837 MessageParcel reply;
1838 MessageOption option;
1839
1840 bool ret = data.WriteInterfaceToken(GetDescriptor());
1841 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
1842
1843 data.WriteInt32(deviceId);
1844 int32_t error = Remote()->SendRequest(
1845 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_MAX_AMPLITUDE), data, reply, option);
1846 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
1847 return reply.ReadFloat();
1848 }
1849
IsHeadTrackingDataRequested(const std::string & macAddress)1850 bool AudioPolicyProxy::IsHeadTrackingDataRequested(const std::string &macAddress)
1851 {
1852 MessageParcel data;
1853 MessageParcel reply;
1854 MessageOption option;
1855
1856 bool ret = data.WriteInterfaceToken(GetDescriptor());
1857 CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
1858 data.WriteString(macAddress);
1859
1860 int32_t error = Remote()->SendRequest(
1861 static_cast<uint32_t>(AudioPolicyInterfaceCode::IS_HEAD_TRACKING_DATA_REQUESTED), data, reply, option);
1862 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "SendRequest failed, error: %d", error);
1863 return reply.ReadBool();
1864 }
1865
TriggerFetchDevice(AudioStreamDeviceChangeReasonExt reason)1866 int32_t AudioPolicyProxy::TriggerFetchDevice(AudioStreamDeviceChangeReasonExt reason)
1867 {
1868 MessageParcel data;
1869 MessageParcel reply;
1870 MessageOption option;
1871
1872 bool ret = data.WriteInterfaceToken(GetDescriptor());
1873 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
1874
1875 data.WriteInt32(static_cast<int>(reason));
1876 int32_t error = Remote()->SendRequest(
1877 static_cast<uint32_t>(AudioPolicyInterfaceCode::TRIGGER_FETCH_DEVICE), data, reply, option);
1878 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
1879
1880 return reply.ReadInt32();
1881 }
1882
SetPreferredDevice(const PreferredType preferredType,const std::shared_ptr<AudioDeviceDescriptor> & desc,const int32_t uid)1883 int32_t AudioPolicyProxy::SetPreferredDevice(const PreferredType preferredType,
1884 const std::shared_ptr<AudioDeviceDescriptor> &desc, const int32_t uid)
1885 {
1886 MessageParcel data;
1887 MessageParcel reply;
1888 MessageOption option;
1889
1890 bool ret = data.WriteInterfaceToken(GetDescriptor());
1891 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
1892
1893 data.WriteInt32(static_cast<int32_t>(preferredType));
1894 data.WriteInt32(static_cast<int32_t>(uid));
1895 bool result = desc->Marshalling(data);
1896 CHECK_AND_RETURN_RET_LOG(result, -1, "Desc Marshalling() faild");
1897
1898 int32_t error = Remote()->SendRequest(
1899 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_PREFERRED_DEVICE), data, reply, option);
1900 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "SendRequest failed, error: %d", error);
1901 return reply.ReadInt32();
1902 }
1903
SaveRemoteInfo(const std::string & networkId,DeviceType deviceType)1904 void AudioPolicyProxy::SaveRemoteInfo(const std::string &networkId, DeviceType deviceType)
1905 {
1906 MessageParcel data;
1907 MessageParcel reply;
1908 MessageOption option;
1909
1910 bool ret = data.WriteInterfaceToken(GetDescriptor());
1911 if (!ret) {
1912 AUDIO_ERR_LOG("WriteInterfaceToken failed");
1913 }
1914
1915 data.WriteString(networkId);
1916 data.WriteInt32(static_cast<int32_t>(deviceType));
1917 int32_t error = Remote()->SendRequest(
1918 static_cast<uint32_t>(AudioPolicyInterfaceCode::SAVE_REMOTE_INFO), data, reply, option);
1919 if (error != ERR_NONE) {
1920 AUDIO_ERR_LOG("SendRequest failed, error: %{public}d", error);
1921 }
1922 }
1923
SetAudioDeviceAnahsCallback(const sptr<IRemoteObject> & object)1924 int32_t AudioPolicyProxy::SetAudioDeviceAnahsCallback(const sptr<IRemoteObject> &object)
1925 {
1926 MessageParcel data;
1927 MessageParcel reply;
1928 MessageOption option;
1929
1930 CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "object is null");
1931
1932 bool ret = data.WriteInterfaceToken(GetDescriptor());
1933 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
1934
1935 (void)data.WriteRemoteObject(object);
1936 int32_t error = Remote()->SendRequest(
1937 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_AUDIO_DEVICE_ANAHS_CALLBACK), data, reply, option);
1938 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
1939 return reply.ReadInt32();
1940 }
1941
UnsetAudioDeviceAnahsCallback()1942 int32_t AudioPolicyProxy::UnsetAudioDeviceAnahsCallback()
1943 {
1944 MessageParcel data;
1945 MessageParcel reply;
1946 MessageOption option;
1947
1948 bool ret = data.WriteInterfaceToken(GetDescriptor());
1949 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
1950
1951 int32_t error = Remote()->SendRequest(
1952 static_cast<uint32_t>(AudioPolicyInterfaceCode::UNSET_AUDIO_DEVICE_ANAHS_CALLBACK), data, reply, option);
1953 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
1954 return reply.ReadInt32();
1955 }
1956
MoveToNewPipe(const uint32_t sessionId,const AudioPipeType pipeType)1957 int32_t AudioPolicyProxy::MoveToNewPipe(const uint32_t sessionId, const AudioPipeType pipeType)
1958 {
1959 MessageParcel data;
1960 MessageParcel reply;
1961 MessageOption option;
1962
1963 bool ret = data.WriteInterfaceToken(GetDescriptor());
1964 CHECK_AND_RETURN_RET_LOG(ret, false, "WriteInterfaceToken failed");
1965 data.WriteUint32(sessionId);
1966 data.WriteInt32(pipeType);
1967
1968 int32_t error = Remote()->SendRequest(
1969 static_cast<uint32_t>(AudioPolicyInterfaceCode::MOVE_TO_NEW_PIPE), data, reply, option);
1970 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, false, "SendRequest failed, error: %d", error);
1971 return reply.ReadInt32();
1972 }
1973
ActivateAudioConcurrency(const AudioPipeType & pipeType)1974 int32_t AudioPolicyProxy::ActivateAudioConcurrency(const AudioPipeType &pipeType)
1975 {
1976 MessageParcel data;
1977 MessageParcel reply;
1978 MessageOption option;
1979
1980 bool ret = data.WriteInterfaceToken(GetDescriptor());
1981 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
1982 data.WriteInt32(pipeType);
1983 int error = Remote()->SendRequest(
1984 static_cast<uint32_t>(AudioPolicyInterfaceCode::ACTIVATE_AUDIO_CONCURRENCY), data, reply, option);
1985 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "activate concurrency failed, error: %{public}d", error);
1986 return reply.ReadInt32();
1987 }
1988
GetSupportedAudioEffectProperty(AudioEffectPropertyArrayV3 & propertyArray)1989 int32_t AudioPolicyProxy::GetSupportedAudioEffectProperty(AudioEffectPropertyArrayV3 &propertyArray)
1990 {
1991 MessageParcel data;
1992 MessageParcel reply;
1993 MessageOption option;
1994
1995 bool res = data.WriteInterfaceToken(GetDescriptor());
1996 CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed");
1997
1998 int32_t error = Remote()->SendRequest(
1999 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_SUPPORT_AUDIO_EFFECT_PROPERTY_V3), data, reply, option);
2000 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Supported Audio Effect Property, error: %d", error);
2001 int32_t result = reply.ReadInt32();
2002 int32_t size = reply.ReadInt32();
2003 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
2004 ERROR_INVALID_PARAM, "get audio supported effect property array size invalid");
2005 for (int32_t i = 0; i < size; i++) {
2006 AudioEffectPropertyV3 prop = {};
2007 prop.Unmarshalling(reply);
2008 // write and read must keep same order
2009 propertyArray.property.push_back(prop);
2010 }
2011 return result;
2012 }
2013
GetAudioEffectProperty(AudioEffectPropertyArrayV3 & propertyArray)2014 int32_t AudioPolicyProxy::GetAudioEffectProperty(AudioEffectPropertyArrayV3 &propertyArray)
2015 {
2016 MessageParcel data;
2017 MessageParcel reply;
2018 MessageOption option;
2019
2020 bool res = data.WriteInterfaceToken(GetDescriptor());
2021 CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed");
2022
2023 int32_t error = Remote()->SendRequest(
2024 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_AUDIO_EFFECT_PROPERTY_V3), data, reply, option);
2025 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Audio Effect Property, error: %d", error);
2026 int32_t result = reply.ReadInt32();
2027 int32_t size = reply.ReadInt32();
2028 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
2029 ERROR_INVALID_PARAM, "get audio effect property array size invalid");
2030 for (int32_t i = 0; i < size; i++) {
2031 AudioEffectPropertyV3 prop = {};
2032 prop.Unmarshalling(reply);
2033 // write and read must keep same order
2034 propertyArray.property.push_back(prop);
2035 }
2036 return result;
2037 }
2038
SetAudioEffectProperty(const AudioEffectPropertyArrayV3 & propertyArray)2039 int32_t AudioPolicyProxy::SetAudioEffectProperty(const AudioEffectPropertyArrayV3 &propertyArray)
2040 {
2041 MessageParcel data;
2042 MessageParcel reply;
2043 MessageOption option;
2044
2045 bool ret = data.WriteInterfaceToken(GetDescriptor());
2046 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
2047
2048 int32_t size = static_cast<int32_t>(propertyArray.property.size());
2049 data.WriteInt32(size);
2050 CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
2051 ERROR_INVALID_PARAM, "set audio effect property array size invalid");
2052 for (int32_t i = 0; i < size; i++) {
2053 propertyArray.property[i].Marshalling(data);
2054 }
2055 int32_t error = Remote()->SendRequest(
2056 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_AUDIO_EFFECT_PROPERTY_V3), data, reply, option);
2057 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
2058 return reply.ReadInt32();
2059 }
2060
GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray & propertyArray)2061 int32_t AudioPolicyProxy::GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray)
2062 {
2063 MessageParcel data;
2064 MessageParcel reply;
2065 MessageOption option;
2066
2067 bool res = data.WriteInterfaceToken(GetDescriptor());
2068 CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed");
2069
2070 int32_t error = Remote()->SendRequest(
2071 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_SUPPORT_AUDIO_ENHANCE_PROPERTY), data, reply, option);
2072 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Supported Audio Enhance Property, error: %d", error);
2073
2074 int32_t size = reply.ReadInt32();
2075 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
2076 ERROR_INVALID_PARAM, "get audio supported enhance property array size invalid");
2077 for (int32_t i = 0; i < size; i++) {
2078 // write and read must keep same order
2079 AudioEnhanceProperty prop = {};
2080 prop.Unmarshalling(reply);
2081 propertyArray.property.push_back(prop);
2082 }
2083 return AUDIO_OK;
2084 }
2085
GetSupportedAudioEffectProperty(AudioEffectPropertyArray & propertyArray)2086 int32_t AudioPolicyProxy::GetSupportedAudioEffectProperty(AudioEffectPropertyArray &propertyArray)
2087 {
2088 MessageParcel data;
2089 MessageParcel reply;
2090 MessageOption option;
2091
2092 bool res = data.WriteInterfaceToken(GetDescriptor());
2093 CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed");
2094
2095 int32_t error = Remote()->SendRequest(
2096 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_SUPPORT_AUDIO_EFFECT_PROPERTY), data, reply, option);
2097 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Supported Audio Effect Property, error: %d", error);
2098
2099 int32_t size = reply.ReadInt32();
2100 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
2101 ERROR_INVALID_PARAM, "get audio supported effect property array size invalid");
2102 for (int32_t i = 0; i < size; i++) {
2103 AudioEffectProperty prop = {};
2104 prop.Unmarshalling(reply);
2105 // write and read must keep same order
2106 propertyArray.property.push_back(prop);
2107 }
2108 return AUDIO_OK;
2109 }
2110
GetAudioEnhanceProperty(AudioEnhancePropertyArray & propertyArray)2111 int32_t AudioPolicyProxy::GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray)
2112 {
2113 MessageParcel data;
2114 MessageParcel reply;
2115 MessageOption option;
2116
2117 bool res = data.WriteInterfaceToken(GetDescriptor());
2118 CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed");
2119
2120 int32_t error = Remote()->SendRequest(
2121 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_AUDIO_ENHANCE_PROPERTY), data, reply, option);
2122 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Audio Enhance Property, error: %d", error);
2123
2124 int32_t size = reply.ReadInt32();
2125 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
2126 ERROR_INVALID_PARAM, "get audio enhance property array size invalid");
2127 for (int32_t i = 0; i < size; i++) {
2128 // write and read must keep same order
2129 AudioEnhanceProperty prop = {};
2130 prop.Unmarshalling(reply);
2131 propertyArray.property.push_back(prop);
2132 }
2133 return AUDIO_OK;
2134 }
2135
GetAudioEffectProperty(AudioEffectPropertyArray & propertyArray)2136 int32_t AudioPolicyProxy::GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray)
2137 {
2138 MessageParcel data;
2139 MessageParcel reply;
2140 MessageOption option;
2141
2142 bool res = data.WriteInterfaceToken(GetDescriptor());
2143 CHECK_AND_RETURN_RET_LOG(res, ERROR, "WriteInterfaceToken failed");
2144
2145 int32_t error = Remote()->SendRequest(
2146 static_cast<uint32_t>(AudioPolicyInterfaceCode::GET_AUDIO_EFFECT_PROPERTY), data, reply, option);
2147 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Get Audio Effect Property, error: %d", error);
2148
2149 int32_t size = reply.ReadInt32();
2150 CHECK_AND_RETURN_RET_LOG(size >= 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
2151 ERROR_INVALID_PARAM, "get audio effect property array size invalid");
2152 for (int32_t i = 0; i < size; i++) {
2153 AudioEffectProperty prop = {};
2154 prop.Unmarshalling(reply);
2155 // write and read must keep same order
2156 propertyArray.property.push_back(prop);
2157 }
2158 return AUDIO_OK;
2159 }
2160
SetAudioEnhanceProperty(const AudioEnhancePropertyArray & propertyArray)2161 int32_t AudioPolicyProxy::SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray)
2162 {
2163 MessageParcel data;
2164 MessageParcel reply;
2165 MessageOption option;
2166
2167 bool ret = data.WriteInterfaceToken(GetDescriptor());
2168 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
2169
2170 int32_t size = static_cast<int32_t>(propertyArray.property.size());
2171 data.WriteInt32(size);
2172 CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
2173 ERROR_INVALID_PARAM, "set audio enhance property array size invalid");
2174 for (int32_t i = 0; i < size; i++) {
2175 // write and read must keep same order
2176 propertyArray.property[i].Marshalling(data);
2177 }
2178 int32_t error = Remote()->SendRequest(
2179 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_AUDIO_ENHANCE_PROPERTY), data, reply, option);
2180 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SendRequest failed, error: %{public}d", error);
2181 return reply.ReadInt32();
2182 }
2183
SetAudioEffectProperty(const AudioEffectPropertyArray & propertyArray)2184 int32_t AudioPolicyProxy::SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray)
2185 {
2186 MessageParcel data;
2187 MessageParcel reply;
2188 MessageOption option;
2189
2190 bool ret = data.WriteInterfaceToken(GetDescriptor());
2191 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
2192
2193 int32_t size = static_cast<int32_t>(propertyArray.property.size());
2194 data.WriteInt32(size);
2195 CHECK_AND_RETURN_RET_LOG(size > 0 && size <= AUDIO_EFFECT_COUNT_UPPER_LIMIT,
2196 ERROR_INVALID_PARAM, "set audio effect property array size invalid");
2197 for (int32_t i = 0; i < size; i++) {
2198 propertyArray.property[i].Marshalling(data);
2199 }
2200 int32_t error = Remote()->SendRequest(
2201 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_AUDIO_EFFECT_PROPERTY), data, reply, option);
2202 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SendRequest failed, error: %{public}d", error);
2203 return reply.ReadInt32();
2204 }
2205
InjectInterruption(const std::string networkId,InterruptEvent & event)2206 int32_t AudioPolicyProxy::InjectInterruption(const std::string networkId, InterruptEvent &event)
2207 {
2208 MessageParcel data;
2209 MessageParcel reply;
2210 MessageOption option;
2211
2212 bool ret = data.WriteInterfaceToken(GetDescriptor());
2213 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
2214 data.WriteString(networkId);
2215 data.WriteInt32(event.eventType);
2216 data.WriteInt32(event.forceType);
2217 data.WriteInt32(event.hintType);
2218
2219 int error = Remote()->SendRequest(
2220 static_cast<uint32_t>(AudioPolicyInterfaceCode::INJECT_INTERRUPTION), data, reply, option);
2221 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
2222 return reply.ReadInt32();
2223 }
2224
SetDeviceConnectionStatus(const std::shared_ptr<AudioDeviceDescriptor> & desc,const bool isConnected)2225 int32_t AudioPolicyProxy::SetDeviceConnectionStatus(const std::shared_ptr<AudioDeviceDescriptor> &desc,
2226 const bool isConnected)
2227 {
2228 MessageParcel data;
2229 MessageParcel reply;
2230 MessageOption option;
2231
2232 bool ret = data.WriteInterfaceToken(GetDescriptor());
2233 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
2234
2235 bool res = desc->Marshalling(data);
2236 CHECK_AND_RETURN_RET_LOG(res, -1, "Desc Marshalling() failed");
2237 data.WriteBool(isConnected);
2238
2239 int error = Remote()->SendRequest(
2240 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_DEVICE_CONNECTION_STATUS), data, reply, option);
2241 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %d", error);
2242 return reply.ReadInt32();
2243 }
2244 } // namespace AudioStandard
2245 } // namespace OHOS
2246