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
OnDeviceChange(const DeviceChangeAction & deviceChangeAction)113 void AudioPolicyClientProxy::OnDeviceChange(const DeviceChangeAction &deviceChangeAction)
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
123 auto devices = deviceChangeAction.deviceDescriptors;
124 size_t size = deviceChangeAction.deviceDescriptors.size();
125 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_DEVICE_CHANGE));
126 data.WriteInt32(deviceChangeAction.type);
127 data.WriteInt32(deviceChangeAction.flag);
128 data.WriteInt32(static_cast<int32_t>(size));
129 for (size_t i = 0; i < size; i++) {
130 devices[i]->Marshalling(data);
131 }
132 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
133 if (error != 0) {
134 AUDIO_ERR_LOG("Error while sending device change info: %{public}d", error);
135 }
136 reply.ReadInt32();
137 }
138
OnMicrophoneBlocked(const MicrophoneBlockedInfo & microphoneBlockedInfo)139 void AudioPolicyClientProxy::OnMicrophoneBlocked(const MicrophoneBlockedInfo µphoneBlockedInfo)
140 {
141 MessageParcel data;
142 MessageParcel reply;
143 MessageOption option(MessageOption::TF_ASYNC);
144 if (!data.WriteInterfaceToken(GetDescriptor())) {
145 AUDIO_ERR_LOG("WriteInterfaceToken failed");
146 return;
147 }
148
149 size_t size = microphoneBlockedInfo.devices.size();
150 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_MICRO_PHONE_BLOCKED));
151 data.WriteInt32(microphoneBlockedInfo.blockStatus);
152 data.WriteInt32(static_cast<int32_t>(size));
153 for (size_t i = 0; i < size; i++) {
154 microphoneBlockedInfo.devices[i]->Marshalling(data);
155 }
156 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
157 if (error != 0) {
158 AUDIO_ERR_LOG("Error while sending microphoneBlocked info: %{public}d", error);
159 }
160 reply.ReadInt32();
161 }
162
OnRingerModeUpdated(const AudioRingerMode & ringerMode)163 void AudioPolicyClientProxy::OnRingerModeUpdated(const AudioRingerMode &ringerMode)
164 {
165 MessageParcel data;
166 MessageParcel reply;
167 MessageOption option(MessageOption::TF_ASYNC);
168 if (!data.WriteInterfaceToken(GetDescriptor())) {
169 AUDIO_ERR_LOG("AudioPolicyClientProxy::OnRingerModeUpdated: WriteInterfaceToken failed");
170 return;
171 }
172
173 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_RINGERMODE_UPDATE));
174 data.WriteInt32(static_cast<int32_t>(ringerMode));
175 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
176 if (error != 0) {
177 AUDIO_ERR_LOG("Error while sending ringer mode updated info: %{public}d", error);
178 }
179 reply.ReadInt32();
180 }
181
OnMicStateUpdated(const MicStateChangeEvent & micStateChangeEvent)182 void AudioPolicyClientProxy::OnMicStateUpdated(const MicStateChangeEvent &micStateChangeEvent)
183 {
184 MessageParcel data;
185 MessageParcel reply;
186 MessageOption option(MessageOption::TF_ASYNC);
187 if (!data.WriteInterfaceToken(GetDescriptor())) {
188 AUDIO_ERR_LOG("WriteInterfaceToken failed");
189 return;
190 }
191
192 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_MIC_STATE_UPDATED));
193 data.WriteBool(micStateChangeEvent.mute);
194 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
195 if (error != 0) {
196 AUDIO_ERR_LOG("Error while sending ringer mode updated info: %{public}d", error);
197 }
198 reply.ReadInt32();
199 }
200
OnPreferredOutputDeviceUpdated(const std::vector<sptr<AudioDeviceDescriptor>> & desc)201 void AudioPolicyClientProxy::OnPreferredOutputDeviceUpdated(const std::vector<sptr<AudioDeviceDescriptor>> &desc)
202 {
203 MessageParcel data;
204 MessageParcel reply;
205 MessageOption option(MessageOption::TF_ASYNC);
206 if (!data.WriteInterfaceToken(GetDescriptor())) {
207 AUDIO_ERR_LOG("WriteInterfaceToken failed");
208 return;
209 }
210
211 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_ACTIVE_OUTPUT_DEVICE_UPDATED));
212 int32_t size = static_cast<int32_t>(desc.size());
213 data.WriteInt32(size);
214 for (int i = 0; i < size; i++) {
215 desc[i]->Marshalling(data);
216 }
217
218 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
219 if (error != 0) {
220 AUDIO_ERR_LOG("Error while sending preferred output device updated info: %{public}d", error);
221 }
222 reply.ReadInt32();
223 }
224
OnPreferredInputDeviceUpdated(const std::vector<sptr<AudioDeviceDescriptor>> & desc)225 void AudioPolicyClientProxy::OnPreferredInputDeviceUpdated(const std::vector<sptr<AudioDeviceDescriptor>> &desc)
226 {
227 MessageParcel data;
228 MessageParcel reply;
229 MessageOption option(MessageOption::TF_ASYNC);
230 if (!data.WriteInterfaceToken(GetDescriptor())) {
231 AUDIO_ERR_LOG("WriteInterfaceToken failed");
232 return;
233 }
234
235 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_ACTIVE_INPUT_DEVICE_UPDATED));
236 int32_t size = static_cast<int32_t>(desc.size());
237 data.WriteInt32(size);
238 for (int i = 0; i < size; i++) {
239 desc[i]->Marshalling(data);
240 }
241
242 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
243 if (error != 0) {
244 AUDIO_ERR_LOG("Error while sending preferred input device updated info: %{public}d", error);
245 }
246 reply.ReadInt32();
247 }
248
OnRendererStateChange(std::vector<std::unique_ptr<AudioRendererChangeInfo>> & audioRendererChangeInfos)249 void AudioPolicyClientProxy::OnRendererStateChange(
250 std::vector<std::unique_ptr<AudioRendererChangeInfo>> &audioRendererChangeInfos)
251 {
252 MessageParcel data;
253 MessageParcel reply;
254 MessageOption option(MessageOption::TF_ASYNC);
255 if (!data.WriteInterfaceToken(GetDescriptor())) {
256 AUDIO_ERR_LOG("WriteInterfaceToken failed");
257 return;
258 }
259
260 size_t size = audioRendererChangeInfos.size();
261 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_RENDERERSTATE_CHANGE));
262 data.WriteInt32(size);
263 for (const std::unique_ptr<AudioRendererChangeInfo> &rendererChangeInfo: audioRendererChangeInfos) {
264 if (!rendererChangeInfo) {
265 AUDIO_ERR_LOG("Renderer change info null, something wrong!!");
266 continue;
267 }
268 rendererChangeInfo->Marshalling(data, hasBTPermission_, hasSystemPermission_, apiVersion_);
269 }
270 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
271 if (error != 0) {
272 AUDIO_ERR_LOG("Error while sending renderer state change info: %{public}d", error);
273 }
274 reply.ReadInt32();
275 }
276
OnCapturerStateChange(std::vector<std::unique_ptr<AudioCapturerChangeInfo>> & audioCapturerChangeInfos)277 void AudioPolicyClientProxy::OnCapturerStateChange(
278 std::vector<std::unique_ptr<AudioCapturerChangeInfo>> &audioCapturerChangeInfos)
279 {
280 MessageParcel data;
281 MessageParcel reply;
282 MessageOption option(MessageOption::TF_ASYNC);
283 if (!data.WriteInterfaceToken(GetDescriptor())) {
284 AUDIO_ERR_LOG("WriteInterfaceToken failed");
285 return;
286 }
287
288 size_t size = audioCapturerChangeInfos.size();
289 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_CAPTURERSTATE_CHANGE));
290 data.WriteInt32(size);
291 for (const std::unique_ptr<AudioCapturerChangeInfo> &capturerChangeInfo: audioCapturerChangeInfos) {
292 if (!capturerChangeInfo) {
293 AUDIO_ERR_LOG("Capturer change info null, something wrong!!");
294 continue;
295 }
296 capturerChangeInfo->Marshalling(data, hasBTPermission_, hasSystemPermission_, apiVersion_);
297 }
298
299 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
300 if (error != 0) {
301 AUDIO_ERR_LOG("Error while sending capturer state change info: %{public}d", error);
302 }
303 reply.ReadInt32();
304 }
305
OnRendererDeviceChange(const uint32_t sessionId,const DeviceInfo & deviceInfo,const AudioStreamDeviceChangeReasonExt reason)306 void AudioPolicyClientProxy::OnRendererDeviceChange(const uint32_t sessionId,
307 const DeviceInfo &deviceInfo, const AudioStreamDeviceChangeReasonExt reason)
308 {
309 MessageParcel data;
310 MessageParcel reply;
311 MessageOption option(MessageOption::TF_ASYNC);
312 if (!data.WriteInterfaceToken(GetDescriptor())) {
313 AUDIO_ERR_LOG("WriteInterfaceToken failed");
314 return;
315 }
316
317 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_RENDERER_DEVICE_CHANGE));
318
319 data.WriteUint32(sessionId);
320 deviceInfo.Marshalling(data);
321 data.WriteInt32(static_cast<int32_t>(reason));
322 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
323 if (error != 0) {
324 AUDIO_ERR_LOG("Error while sending DeviceChange: %{public}d", error);
325 }
326 reply.ReadInt32();
327 }
328
OnRecreateRendererStreamEvent(const uint32_t sessionId,const int32_t streamFlag,const AudioStreamDeviceChangeReasonExt reason)329 void AudioPolicyClientProxy::OnRecreateRendererStreamEvent(const uint32_t sessionId, const int32_t streamFlag,
330 const AudioStreamDeviceChangeReasonExt reason)
331 {
332 MessageParcel data;
333 MessageParcel reply;
334 MessageOption option(MessageOption::TF_ASYNC);
335 if (!data.WriteInterfaceToken(GetDescriptor())) {
336 AUDIO_ERR_LOG("WriteInterfaceToken failed");
337 return;
338 }
339
340 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_RECREATE_RENDERER_STREAM_EVENT));
341
342 data.WriteUint32(sessionId);
343 data.WriteInt32(streamFlag);
344 data.WriteInt32(static_cast<int32_t>(reason));
345 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
346 if (error != 0) {
347 AUDIO_ERR_LOG("Error while sending recreate stream event: %{public}d", error);
348 }
349 reply.ReadInt32();
350 }
351
OnRecreateCapturerStreamEvent(const uint32_t sessionId,const int32_t streamFlag,const AudioStreamDeviceChangeReasonExt reason)352 void AudioPolicyClientProxy::OnRecreateCapturerStreamEvent(const uint32_t sessionId, const int32_t streamFlag,
353 const AudioStreamDeviceChangeReasonExt reason)
354 {
355 MessageParcel data;
356 MessageParcel reply;
357 MessageOption option(MessageOption::TF_ASYNC);
358 if (!data.WriteInterfaceToken(GetDescriptor())) {
359 AUDIO_ERR_LOG("WriteInterfaceToken failed");
360 return;
361 }
362
363 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_RECREATE_CAPTURER_STREAM_EVENT));
364
365 data.WriteUint32(sessionId);
366 data.WriteInt32(streamFlag);
367 data.WriteInt32(static_cast<int32_t>(reason));
368 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
369 if (error != 0) {
370 AUDIO_ERR_LOG("Error while sending recreate stream event: %{public}d", error);
371 }
372 reply.ReadInt32();
373 }
374
OnHeadTrackingDeviceChange(const std::unordered_map<std::string,bool> & changeInfo)375 void AudioPolicyClientProxy::OnHeadTrackingDeviceChange(const std::unordered_map<std::string, bool> &changeInfo)
376 {
377 MessageParcel data;
378 MessageParcel reply;
379 MessageOption option(MessageOption::TF_ASYNC);
380 if (!data.WriteInterfaceToken(GetDescriptor())) {
381 AUDIO_ERR_LOG("WriteInterfaceToken failed");
382 return;
383 }
384
385 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_HEAD_TRACKING_DEVICE_CHANGE));
386
387 int32_t size = static_cast<int32_t>(changeInfo.size());
388 data.WriteInt32(size);
389
390 for (const auto &pair : changeInfo) {
391 data.WriteString(pair.first);
392 data.WriteBool(pair.second);
393 }
394
395 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
396 if (error != 0) {
397 AUDIO_ERR_LOG("Error while sending change info: %{public}d", error);
398 }
399 reply.ReadInt32();
400 }
401
OnSpatializationEnabledChange(const bool & enabled)402 void AudioPolicyClientProxy::OnSpatializationEnabledChange(const bool &enabled)
403 {
404 MessageParcel data;
405 MessageParcel reply;
406 MessageOption option(MessageOption::TF_ASYNC);
407 if (!data.WriteInterfaceToken(GetDescriptor())) {
408 AUDIO_ERR_LOG("WriteInterfaceToken failed");
409 return;
410 }
411
412 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_SPATIALIZATION_ENABLED_CHANGE));
413
414 if (hasSystemPermission_) {
415 data.WriteBool(enabled);
416 } else {
417 data.WriteBool(false);
418 }
419
420 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
421 if (error != 0) {
422 AUDIO_ERR_LOG("Error while sending enabled info: %{public}d", error);
423 }
424 reply.ReadInt32();
425 }
426
OnSpatializationEnabledChangeForAnyDevice(const sptr<AudioDeviceDescriptor> & deviceDescriptor,const bool & enabled)427 void AudioPolicyClientProxy::OnSpatializationEnabledChangeForAnyDevice(const sptr<AudioDeviceDescriptor>
428 &deviceDescriptor, const bool &enabled)
429 {
430 MessageParcel data;
431 MessageParcel reply;
432 MessageOption option(MessageOption::TF_ASYNC);
433 if (!data.WriteInterfaceToken(GetDescriptor())) {
434 AUDIO_ERR_LOG("WriteInterfaceToken failed");
435 return;
436 }
437
438 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_SPATIALIZATION_ENABLED_CHANGE_FOR_ANY_DEVICE));
439
440 if (hasSystemPermission_) {
441 deviceDescriptor->Marshalling(data);
442 data.WriteBool(enabled);
443 } else {
444 data.WriteBool(false);
445 }
446
447 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
448 if (error != 0) {
449 AUDIO_ERR_LOG("Error while sending enabled info: %{public}d", error);
450 }
451 reply.ReadInt32();
452 }
453
OnHeadTrackingEnabledChange(const bool & enabled)454 void AudioPolicyClientProxy::OnHeadTrackingEnabledChange(const bool &enabled)
455 {
456 MessageParcel data;
457 MessageParcel reply;
458 MessageOption option(MessageOption::TF_ASYNC);
459 if (!data.WriteInterfaceToken(GetDescriptor())) {
460 AUDIO_ERR_LOG("WriteInterfaceToken failed");
461 return;
462 }
463
464 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_HEAD_TRACKING_ENABLED_CHANGE));
465
466 if (hasSystemPermission_) {
467 data.WriteBool(enabled);
468 } else {
469 data.WriteBool(false);
470 }
471
472 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
473 if (error != 0) {
474 AUDIO_ERR_LOG("Error while sending enabled info: %{public}d", error);
475 }
476 reply.ReadInt32();
477 }
478
OnHeadTrackingEnabledChangeForAnyDevice(const sptr<AudioDeviceDescriptor> & deviceDescriptor,const bool & enabled)479 void AudioPolicyClientProxy::OnHeadTrackingEnabledChangeForAnyDevice(const sptr<AudioDeviceDescriptor>
480 &deviceDescriptor, const bool &enabled)
481 {
482 MessageParcel data;
483 MessageParcel reply;
484 MessageOption option(MessageOption::TF_ASYNC);
485 if (!data.WriteInterfaceToken(GetDescriptor())) {
486 AUDIO_ERR_LOG("WriteInterfaceToken failed");
487 return;
488 }
489
490 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_HEAD_TRACKING_ENABLED_CHANGE_FOR_ANY_DEVICE));
491
492 if (hasSystemPermission_) {
493 deviceDescriptor->Marshalling(data);
494 data.WriteBool(enabled);
495 } else {
496 data.WriteBool(false);
497 }
498
499 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
500 if (error != 0) {
501 AUDIO_ERR_LOG("Error while sending enabled info: %{public}d", error);
502 }
503 reply.ReadInt32();
504 }
505
OnAudioSessionDeactive(const AudioSessionDeactiveEvent & deactiveEvent)506 void AudioPolicyClientProxy::OnAudioSessionDeactive(const AudioSessionDeactiveEvent &deactiveEvent)
507 {
508 MessageParcel data;
509 MessageParcel reply;
510 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
511 if (!data.WriteInterfaceToken(GetDescriptor())) {
512 AUDIO_ERR_LOG("WriteInterfaceToken failed");
513 return;
514 }
515 data.WriteInt32(static_cast<int32_t>(AudioPolicyClientCode::ON_AUDIO_SESSION_DEACTIVE));
516 data.WriteInt32(static_cast<int32_t>(deactiveEvent.deactiveReason));
517 int error = Remote()->SendRequest(static_cast<uint32_t>(UPDATE_CALLBACK_CLIENT), data, reply, option);
518 if (error != 0) {
519 AUDIO_ERR_LOG("Error while sending volume key event %{public}d", error);
520 }
521 reply.ReadInt32();
522 }
523 } // namespace AudioStandard
524 } // namespace OHOS
525