1 /*
2 * Copyright (c) 2023 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 "AudioPolicyClientProxy"
17 #endif
18
19 #include "audio_policy_client_proxy.h"
20 #include "audio_policy_log.h"
21
22 namespace OHOS {
23 namespace AudioStandard {
AudioPolicyClientProxy(const sptr<IRemoteObject> & impl)24 AudioPolicyClientProxy::AudioPolicyClientProxy(const sptr<IRemoteObject> &impl)
25 : IRemoteProxy<IAudioPolicyClient>(impl)
26 {}
27
~AudioPolicyClientProxy()28 AudioPolicyClientProxy::~AudioPolicyClientProxy()
29 {}
30
OnVolumeKeyEvent(VolumeEvent volumeEvent)31 void AudioPolicyClientProxy::OnVolumeKeyEvent(VolumeEvent volumeEvent)
32 {
33 MessageParcel data;
34 MessageParcel reply;
35 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
36 if (!data.WriteInterfaceToken(GetDescriptor())) {
37 AUDIO_ERR_LOG("WriteInterfaceToken failed");
38 return;
39 }
40 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_VOLUME_KEY_EVENT));
41 data.WriteInt32(static_cast<int32_t>(volumeEvent.volumeType));
42 data.WriteInt32(volumeEvent.volume);
43 data.WriteBool(volumeEvent.updateUi);
44 data.WriteInt32(volumeEvent.volumeGroupId);
45 data.WriteString(volumeEvent.networkId);
46 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
47 if (error != 0) {
48 AUDIO_ERR_LOG("Error while sending volume key event %{public}d", error);
49 }
50 reply.ReadInt32();
51 }
52
OnAudioFocusInfoChange(const std::list<std::pair<AudioInterrupt,AudioFocuState>> & focusInfoList)53 void AudioPolicyClientProxy::OnAudioFocusInfoChange(
54 const std::list<std::pair<AudioInterrupt, AudioFocuState>> &focusInfoList)
55 {
56 MessageParcel data;
57 MessageParcel reply;
58 MessageOption option(MessageOption::TF_ASYNC);
59 if (!data.WriteInterfaceToken(GetDescriptor())) {
60 AUDIO_ERR_LOG("WriteInterfaceToken failed");
61 return;
62 }
63 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_FOCUS_INFO_CHANGED));
64 size_t size = focusInfoList.size();
65 data.WriteInt32(static_cast<int32_t>(size));
66 for (auto iter = focusInfoList.begin(); iter != focusInfoList.end(); ++iter) {
67 AudioInterrupt::Marshalling(data, iter->first);
68 data.WriteInt32(iter->second);
69 }
70 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
71 if (error != 0) {
72 AUDIO_ERR_LOG("Error while sending focus change info: %{public}d", error);
73 }
74 reply.ReadInt32();
75 }
76
OnAudioFocusRequested(const AudioInterrupt & requestFocus)77 void AudioPolicyClientProxy::OnAudioFocusRequested(const AudioInterrupt &requestFocus)
78 {
79 MessageParcel data;
80 MessageParcel reply;
81 MessageOption option(MessageOption::TF_ASYNC);
82 if (!data.WriteInterfaceToken(GetDescriptor())) {
83 AUDIO_ERR_LOG("WriteInterfaceToken failed");
84 return;
85 }
86
87 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_FOCUS_REQUEST_CHANGED));
88 AudioInterrupt::Marshalling(data, requestFocus);
89 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
90 if (error != ERR_NONE) {
91 AUDIO_ERR_LOG("OnAudioFocusRequested failed, error: %{public}d", error);
92 }
93 }
94
OnAudioFocusAbandoned(const AudioInterrupt & abandonFocus)95 void AudioPolicyClientProxy::OnAudioFocusAbandoned(const AudioInterrupt &abandonFocus)
96 {
97 MessageParcel data;
98 MessageParcel reply;
99 MessageOption option(MessageOption::TF_ASYNC);
100 if (!data.WriteInterfaceToken(GetDescriptor())) {
101 AUDIO_ERR_LOG("WriteInterfaceToken failed");
102 return;
103 }
104
105 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_FOCUS_ABANDON_CHANGED));
106 AudioInterrupt::Marshalling(data, abandonFocus);
107 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
108 if (error != ERR_NONE) {
109 AUDIO_ERR_LOG("OnAudioFocusAbandoned failed, error: %{public}d", error);
110 }
111 }
112
OnAppVolumeChanged(int32_t appUid,const VolumeEvent & volumeEvent)113 void AudioPolicyClientProxy::OnAppVolumeChanged(int32_t appUid, const VolumeEvent& volumeEvent)
114 {
115 MessageParcel data;
116 MessageParcel reply;
117 MessageOption option(MessageOption::TF_ASYNC);
118 if (!data.WriteInterfaceToken(GetDescriptor())) {
119 AUDIO_ERR_LOG("WriteInterfaceToken failed");
120 return;
121 }
122 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_APP_VOLUME_CHANGE));
123 data.WriteInt32(appUid);
124 volumeEvent.Marshalling(data);
125 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
126 if (error != ERR_NONE) {
127 AUDIO_ERR_LOG("OnAudioFocusAbandoned failed, error: %{public}d", error);
128 }
129 }
130
OnDeviceChange(const DeviceChangeAction & deviceChangeAction)131 void AudioPolicyClientProxy::OnDeviceChange(const DeviceChangeAction &deviceChangeAction)
132 {
133 MessageParcel data;
134 MessageParcel reply;
135 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
136 if (!data.WriteInterfaceToken(GetDescriptor())) {
137 AUDIO_ERR_LOG("WriteInterfaceToken failed");
138 return;
139 }
140
141 auto devices = deviceChangeAction.deviceDescriptors;
142 size_t size = deviceChangeAction.deviceDescriptors.size();
143 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_DEVICE_CHANGE));
144 data.WriteInt32(deviceChangeAction.type);
145 data.WriteInt32(deviceChangeAction.flag);
146 data.WriteInt32(static_cast<int32_t>(size));
147 for (size_t i = 0; i < size; i++) {
148 devices[i]->Marshalling(data);
149 }
150 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
151 if (error != 0) {
152 AUDIO_ERR_LOG("Error while sending device change info: %{public}d", error);
153 }
154 reply.ReadInt32();
155 }
156
OnMicrophoneBlocked(const MicrophoneBlockedInfo & microphoneBlockedInfo)157 void AudioPolicyClientProxy::OnMicrophoneBlocked(const MicrophoneBlockedInfo µphoneBlockedInfo)
158 {
159 MessageParcel data;
160 MessageParcel reply;
161 MessageOption option(MessageOption::TF_ASYNC);
162 if (!data.WriteInterfaceToken(GetDescriptor())) {
163 AUDIO_ERR_LOG("WriteInterfaceToken failed");
164 return;
165 }
166
167 size_t size = microphoneBlockedInfo.devices.size();
168 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_MICRO_PHONE_BLOCKED));
169 data.WriteInt32(microphoneBlockedInfo.blockStatus);
170 data.WriteInt32(static_cast<int32_t>(size));
171 for (size_t i = 0; i < size; i++) {
172 microphoneBlockedInfo.devices[i]->Marshalling(data);
173 }
174 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
175 if (error != 0) {
176 AUDIO_ERR_LOG("Error while sending microphoneBlocked info: %{public}d", error);
177 }
178 reply.ReadInt32();
179 }
180
OnRingerModeUpdated(const AudioRingerMode & ringerMode)181 void AudioPolicyClientProxy::OnRingerModeUpdated(const AudioRingerMode &ringerMode)
182 {
183 MessageParcel data;
184 MessageParcel reply;
185 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
186 if (!data.WriteInterfaceToken(GetDescriptor())) {
187 AUDIO_ERR_LOG("AudioPolicyClientProxy::OnRingerModeUpdated: WriteInterfaceToken failed");
188 return;
189 }
190
191 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_RINGERMODE_UPDATE));
192 data.WriteInt32(static_cast<int32_t>(ringerMode));
193 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
194 if (error != 0) {
195 AUDIO_ERR_LOG("Error while sending ringer mode updated info: %{public}d", error);
196 }
197 reply.ReadInt32();
198 }
199
OnMicStateUpdated(const MicStateChangeEvent & micStateChangeEvent)200 void AudioPolicyClientProxy::OnMicStateUpdated(const MicStateChangeEvent &micStateChangeEvent)
201 {
202 MessageParcel data;
203 MessageParcel reply;
204 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
205 if (!data.WriteInterfaceToken(GetDescriptor())) {
206 AUDIO_ERR_LOG("WriteInterfaceToken failed");
207 return;
208 }
209
210 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_MIC_STATE_UPDATED));
211 data.WriteBool(micStateChangeEvent.mute);
212 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
213 if (error != 0) {
214 AUDIO_ERR_LOG("Error while sending ringer mode updated info: %{public}d", error);
215 }
216 reply.ReadInt32();
217 }
218
OnPreferredOutputDeviceUpdated(const AudioRendererInfo & rendererInfo,const std::vector<std::shared_ptr<AudioDeviceDescriptor>> & desc)219 void AudioPolicyClientProxy::OnPreferredOutputDeviceUpdated(const AudioRendererInfo &rendererInfo,
220 const std::vector<std::shared_ptr<AudioDeviceDescriptor>> &desc)
221 {
222 MessageParcel data;
223 MessageParcel reply;
224 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
225 if (!data.WriteInterfaceToken(GetDescriptor())) {
226 AUDIO_ERR_LOG("WriteInterfaceToken failed");
227 return;
228 }
229
230 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_ACTIVE_OUTPUT_DEVICE_UPDATED));
231 rendererInfo.Marshalling(data);
232 int32_t size = static_cast<int32_t>(desc.size());
233 data.WriteInt32(size);
234 for (int i = 0; i < size; i++) {
235 desc[i]->Marshalling(data);
236 }
237
238 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
239 if (error != 0) {
240 AUDIO_ERR_LOG("Error while sending preferred output device updated info: %{public}d", error);
241 }
242 reply.ReadInt32();
243 }
244
OnPreferredInputDeviceUpdated(const AudioCapturerInfo & capturerInfo,const std::vector<std::shared_ptr<AudioDeviceDescriptor>> & desc)245 void AudioPolicyClientProxy::OnPreferredInputDeviceUpdated(const AudioCapturerInfo &capturerInfo,
246 const std::vector<std::shared_ptr<AudioDeviceDescriptor>> &desc)
247 {
248 MessageParcel data;
249 MessageParcel reply;
250 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
251 if (!data.WriteInterfaceToken(GetDescriptor())) {
252 AUDIO_ERR_LOG("WriteInterfaceToken failed");
253 return;
254 }
255
256 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_ACTIVE_INPUT_DEVICE_UPDATED));
257 capturerInfo.Marshalling(data);
258 int32_t size = static_cast<int32_t>(desc.size());
259 data.WriteInt32(size);
260 for (int i = 0; i < size; i++) {
261 desc[i]->Marshalling(data);
262 }
263
264 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
265 if (error != 0) {
266 AUDIO_ERR_LOG("Error while sending preferred input device updated info: %{public}d", error);
267 }
268 reply.ReadInt32();
269 }
270
OnRendererStateChange(std::vector<std::shared_ptr<AudioRendererChangeInfo>> & audioRendererChangeInfos)271 void AudioPolicyClientProxy::OnRendererStateChange(
272 std::vector<std::shared_ptr<AudioRendererChangeInfo>> &audioRendererChangeInfos)
273 {
274 MessageParcel data;
275 MessageParcel reply;
276 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
277 if (!data.WriteInterfaceToken(GetDescriptor())) {
278 AUDIO_ERR_LOG("WriteInterfaceToken failed");
279 return;
280 }
281
282 size_t size = audioRendererChangeInfos.size();
283 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_RENDERERSTATE_CHANGE));
284 data.WriteInt32(size);
285 for (const std::shared_ptr<AudioRendererChangeInfo> &rendererChangeInfo: audioRendererChangeInfos) {
286 if (!rendererChangeInfo) {
287 AUDIO_ERR_LOG("Renderer change info null, something wrong!!");
288 continue;
289 }
290 rendererChangeInfo->Marshalling(data, hasBTPermission_, hasSystemPermission_, apiVersion_);
291 }
292 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
293 if (error != 0) {
294 AUDIO_ERR_LOG("Error while sending renderer state change info: %{public}d", error);
295 }
296 reply.ReadInt32();
297 }
298
OnCapturerStateChange(std::vector<std::shared_ptr<AudioCapturerChangeInfo>> & audioCapturerChangeInfos)299 void AudioPolicyClientProxy::OnCapturerStateChange(
300 std::vector<std::shared_ptr<AudioCapturerChangeInfo>> &audioCapturerChangeInfos)
301 {
302 MessageParcel data;
303 MessageParcel reply;
304 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
305 if (!data.WriteInterfaceToken(GetDescriptor())) {
306 AUDIO_ERR_LOG("WriteInterfaceToken failed");
307 return;
308 }
309
310 size_t size = audioCapturerChangeInfos.size();
311 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_CAPTURERSTATE_CHANGE));
312 data.WriteInt32(size);
313 for (const std::shared_ptr<AudioCapturerChangeInfo> &capturerChangeInfo: audioCapturerChangeInfos) {
314 if (!capturerChangeInfo) {
315 AUDIO_ERR_LOG("Capturer change info null, something wrong!!");
316 continue;
317 }
318 capturerChangeInfo->Marshalling(data, hasBTPermission_, hasSystemPermission_, apiVersion_);
319 }
320
321 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
322 if (error != 0) {
323 AUDIO_ERR_LOG("Error while sending capturer state change info: %{public}d", error);
324 }
325 reply.ReadInt32();
326 }
327
OnRendererDeviceChange(const uint32_t sessionId,const AudioDeviceDescriptor & deviceInfo,const AudioStreamDeviceChangeReasonExt reason)328 void AudioPolicyClientProxy::OnRendererDeviceChange(const uint32_t sessionId,
329 const AudioDeviceDescriptor &deviceInfo, const AudioStreamDeviceChangeReasonExt reason)
330 {
331 MessageParcel data;
332 MessageParcel reply;
333 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
334 if (!data.WriteInterfaceToken(GetDescriptor())) {
335 AUDIO_ERR_LOG("WriteInterfaceToken failed");
336 return;
337 }
338
339 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_RENDERER_DEVICE_CHANGE));
340
341 data.WriteUint32(sessionId);
342 deviceInfo.Marshalling(data);
343 data.WriteInt32(static_cast<int32_t>(reason));
344 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
345 if (error != 0) {
346 AUDIO_ERR_LOG("Error while sending DeviceChange: %{public}d", error);
347 }
348 reply.ReadInt32();
349 }
350
OnDistribuitedOutputChange(const AudioDeviceDescriptor & deviceDesc,bool isRemote)351 void AudioPolicyClientProxy::OnDistribuitedOutputChange(const AudioDeviceDescriptor &deviceDesc, bool isRemote)
352 {
353 MessageParcel data;
354 MessageParcel reply;
355 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
356 if (!data.WriteInterfaceToken(GetDescriptor())) {
357 AUDIO_ERR_LOG("WriteInterfaceToken failed");
358 return;
359 }
360
361 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_DISTRIBUTED_OUTPUT_CHANGE));
362
363 deviceDesc.Marshalling(data);
364 data.WriteBool(isRemote);
365 auto error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
366 if (error != 0) {
367 AUDIO_ERR_LOG("Error while sending DistribuitedOutputChange: %{public}d", error);
368 }
369 reply.ReadInt32();
370 }
371
OnRecreateRendererStreamEvent(const uint32_t sessionId,const int32_t streamFlag,const AudioStreamDeviceChangeReasonExt reason)372 void AudioPolicyClientProxy::OnRecreateRendererStreamEvent(const uint32_t sessionId, const int32_t streamFlag,
373 const AudioStreamDeviceChangeReasonExt reason)
374 {
375 MessageParcel data;
376 MessageParcel reply;
377 MessageOption option(MessageOption::TF_ASYNC);
378 if (!data.WriteInterfaceToken(GetDescriptor())) {
379 AUDIO_ERR_LOG("WriteInterfaceToken failed");
380 return;
381 }
382
383 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_RECREATE_RENDERER_STREAM_EVENT));
384
385 data.WriteUint32(sessionId);
386 data.WriteInt32(streamFlag);
387 data.WriteInt32(static_cast<int32_t>(reason));
388 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
389 if (error != 0) {
390 AUDIO_ERR_LOG("Error while sending recreate stream event: %{public}d", error);
391 }
392 reply.ReadInt32();
393 }
394
OnRecreateCapturerStreamEvent(const uint32_t sessionId,const int32_t streamFlag,const AudioStreamDeviceChangeReasonExt reason)395 void AudioPolicyClientProxy::OnRecreateCapturerStreamEvent(const uint32_t sessionId, const int32_t streamFlag,
396 const AudioStreamDeviceChangeReasonExt reason)
397 {
398 MessageParcel data;
399 MessageParcel reply;
400 MessageOption option(MessageOption::TF_ASYNC);
401 if (!data.WriteInterfaceToken(GetDescriptor())) {
402 AUDIO_ERR_LOG("WriteInterfaceToken failed");
403 return;
404 }
405
406 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_RECREATE_CAPTURER_STREAM_EVENT));
407
408 data.WriteUint32(sessionId);
409 data.WriteInt32(streamFlag);
410 data.WriteInt32(static_cast<int32_t>(reason));
411 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
412 if (error != 0) {
413 AUDIO_ERR_LOG("Error while sending recreate stream event: %{public}d", error);
414 }
415 reply.ReadInt32();
416 }
417
OnHeadTrackingDeviceChange(const std::unordered_map<std::string,bool> & changeInfo)418 void AudioPolicyClientProxy::OnHeadTrackingDeviceChange(const std::unordered_map<std::string, bool> &changeInfo)
419 {
420 MessageParcel data;
421 MessageParcel reply;
422 MessageOption option(MessageOption::TF_ASYNC);
423 if (!data.WriteInterfaceToken(GetDescriptor())) {
424 AUDIO_ERR_LOG("WriteInterfaceToken failed");
425 return;
426 }
427
428 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_HEAD_TRACKING_DEVICE_CHANGE));
429
430 int32_t size = static_cast<int32_t>(changeInfo.size());
431 data.WriteInt32(size);
432
433 for (const auto &pair : changeInfo) {
434 data.WriteString(pair.first);
435 data.WriteBool(pair.second);
436 }
437
438 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
439 if (error != 0) {
440 AUDIO_ERR_LOG("Error while sending change info: %{public}d", error);
441 }
442 reply.ReadInt32();
443 }
444
OnSpatializationEnabledChange(const bool & enabled)445 void AudioPolicyClientProxy::OnSpatializationEnabledChange(const bool &enabled)
446 {
447 MessageParcel data;
448 MessageParcel reply;
449 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
450 if (!data.WriteInterfaceToken(GetDescriptor())) {
451 AUDIO_ERR_LOG("WriteInterfaceToken failed");
452 return;
453 }
454
455 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_SPATIALIZATION_ENABLED_CHANGE));
456
457 if (hasSystemPermission_) {
458 data.WriteBool(enabled);
459 } else {
460 data.WriteBool(false);
461 }
462
463 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
464 if (error != 0) {
465 AUDIO_ERR_LOG("Error while sending enabled info: %{public}d", error);
466 }
467 reply.ReadInt32();
468 }
469
OnSpatializationEnabledChangeForAnyDevice(const std::shared_ptr<AudioDeviceDescriptor> & deviceDescriptor,const bool & enabled)470 void AudioPolicyClientProxy::OnSpatializationEnabledChangeForAnyDevice(const std::shared_ptr<AudioDeviceDescriptor>
471 &deviceDescriptor, const bool &enabled)
472 {
473 MessageParcel data;
474 MessageParcel reply;
475 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
476 if (!data.WriteInterfaceToken(GetDescriptor())) {
477 AUDIO_ERR_LOG("WriteInterfaceToken failed");
478 return;
479 }
480
481 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_SPATIALIZATION_ENABLED_CHANGE_FOR_ANY_DEVICE));
482
483 if (hasSystemPermission_) {
484 deviceDescriptor->Marshalling(data);
485 data.WriteBool(enabled);
486 } else {
487 data.WriteBool(false);
488 }
489
490 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
491 if (error != 0) {
492 AUDIO_ERR_LOG("Error while sending enabled info: %{public}d", error);
493 }
494 reply.ReadInt32();
495 }
496
OnSpatializationEnabledChangeForCurrentDevice(const bool & enabled)497 void AudioPolicyClientProxy::OnSpatializationEnabledChangeForCurrentDevice(const bool &enabled)
498 {
499 MessageParcel data;
500 MessageParcel reply;
501 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
502 if (!data.WriteInterfaceToken(GetDescriptor())) {
503 AUDIO_ERR_LOG("WriteInterfaceToken failed");
504 return;
505 }
506
507 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_SPATIALIZATION_ENABLED_CHANGE_FOR_CURRENT_DEVICE));
508
509 data.WriteBool(enabled);
510
511 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
512 if (error != 0) {
513 AUDIO_ERR_LOG("Error while sending enabled info: %{public}d", error);
514 }
515 reply.ReadInt32();
516 }
517
OnHeadTrackingEnabledChange(const bool & enabled)518 void AudioPolicyClientProxy::OnHeadTrackingEnabledChange(const bool &enabled)
519 {
520 MessageParcel data;
521 MessageParcel reply;
522 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
523 if (!data.WriteInterfaceToken(GetDescriptor())) {
524 AUDIO_ERR_LOG("WriteInterfaceToken failed");
525 return;
526 }
527
528 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_HEAD_TRACKING_ENABLED_CHANGE));
529
530 if (hasSystemPermission_) {
531 data.WriteBool(enabled);
532 } else {
533 data.WriteBool(false);
534 }
535
536 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
537 if (error != 0) {
538 AUDIO_ERR_LOG("Error while sending enabled info: %{public}d", error);
539 }
540 reply.ReadInt32();
541 }
542
OnAudioSceneChange(const AudioScene & audioScene)543 void AudioPolicyClientProxy::OnAudioSceneChange(const AudioScene &audioScene)
544 {
545 MessageParcel data;
546 MessageParcel reply;
547 MessageOption option(MessageOption::TF_ASYNC);
548 if (!data.WriteInterfaceToken(GetDescriptor())) {
549 AUDIO_ERR_LOG("WriteInterfaceToken failed");
550 return;
551 }
552
553 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_AUDIO_SCENE_CHANGED));
554 data.WriteInt32(static_cast<int32_t>(audioScene));
555
556 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
557 if (error != 0) {
558 AUDIO_ERR_LOG("Error while sending enabled info: %{public}d", error);
559 }
560 reply.ReadInt32();
561 }
562
OnHeadTrackingEnabledChangeForAnyDevice(const std::shared_ptr<AudioDeviceDescriptor> & deviceDescriptor,const bool & enabled)563 void AudioPolicyClientProxy::OnHeadTrackingEnabledChangeForAnyDevice(const std::shared_ptr<AudioDeviceDescriptor>
564 &deviceDescriptor, const bool &enabled)
565 {
566 MessageParcel data;
567 MessageParcel reply;
568 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
569 if (!data.WriteInterfaceToken(GetDescriptor())) {
570 AUDIO_ERR_LOG("WriteInterfaceToken failed");
571 return;
572 }
573
574 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_HEAD_TRACKING_ENABLED_CHANGE_FOR_ANY_DEVICE));
575
576 if (hasSystemPermission_) {
577 deviceDescriptor->Marshalling(data);
578 data.WriteBool(enabled);
579 } else {
580 data.WriteBool(false);
581 }
582
583 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
584 if (error != 0) {
585 AUDIO_ERR_LOG("Error while sending enabled info: %{public}d", error);
586 }
587 reply.ReadInt32();
588 }
589
OnNnStateChange(const int32_t & state)590 void AudioPolicyClientProxy::OnNnStateChange(const int32_t &state)
591 {
592 MessageParcel data;
593 MessageParcel reply;
594 MessageOption option(MessageOption::TF_ASYNC);
595 if (!data.WriteInterfaceToken(GetDescriptor())) {
596 AUDIO_ERR_LOG("WriteInterfaceToken failed");
597 return;
598 }
599
600 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_NN_STATE_CHANGE));
601 data.WriteInt32(state);
602
603 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
604 if (error != 0) {
605 AUDIO_ERR_LOG("Error while sending enabled info: %{public}d", error);
606 }
607 reply.ReadInt32();
608 }
609
OnAudioSessionDeactive(const AudioSessionDeactiveEvent & deactiveEvent)610 void AudioPolicyClientProxy::OnAudioSessionDeactive(const AudioSessionDeactiveEvent &deactiveEvent)
611 {
612 MessageParcel data;
613 MessageParcel reply;
614 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
615 if (!data.WriteInterfaceToken(GetDescriptor())) {
616 AUDIO_ERR_LOG("WriteInterfaceToken failed");
617 return;
618 }
619 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_AUDIO_SESSION_DEACTIVE));
620 data.WriteInt32(static_cast<int32_t>(deactiveEvent.deactiveReason));
621 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
622 if (error != 0) {
623 AUDIO_ERR_LOG("Error while sending volume key event %{public}d", error);
624 }
625 reply.ReadInt32();
626 }
627 } // namespace AudioStandard
628 } // namespace OHOS
629