1 /*
2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #ifndef LOG_TAG
16 #define LOG_TAG "AudioPolicyProxy"
17 #endif
18
19
20 #include "audio_policy_log.h"
21 #include "audio_policy_proxy.h"
22
23
24 namespace OHOS {
25 namespace AudioStandard {
26 using namespace std;
27
SetAudioInterruptCallback(const uint32_t sessionID,const sptr<IRemoteObject> & object,uint32_t clientUid,const int32_t zoneID)28 int32_t AudioPolicyProxy::SetAudioInterruptCallback(const uint32_t sessionID, const sptr<IRemoteObject> &object,
29 uint32_t clientUid, const int32_t zoneID)
30 {
31 MessageParcel data;
32 MessageParcel reply;
33 MessageOption option;
34
35 CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT,
36 "SetAudioInterruptCallback object is null");
37 bool ret = data.WriteInterfaceToken(GetDescriptor());
38 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
39 data.WriteUint32(sessionID);
40 (void)data.WriteRemoteObject(object);
41 data.WriteInt32(zoneID);
42 data.WriteUint32(clientUid);
43 int error = Remote()->SendRequest(
44 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_CALLBACK), data, reply, option);
45 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
46 "set callback failed, error: %{public}d", error);
47
48 return reply.ReadInt32();
49 }
50
UnsetAudioInterruptCallback(const uint32_t sessionID,const int32_t zoneID)51 int32_t AudioPolicyProxy::UnsetAudioInterruptCallback(const uint32_t sessionID,
52 const int32_t zoneID)
53 {
54 MessageParcel data;
55 MessageParcel reply;
56 MessageOption option;
57
58 bool ret = data.WriteInterfaceToken(GetDescriptor());
59 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
60 data.WriteUint32(sessionID);
61 data.WriteInt32(zoneID);
62 int error = Remote()->SendRequest(
63 static_cast<uint32_t>(AudioPolicyInterfaceCode::UNSET_CALLBACK), data, reply, option);
64 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
65 "unset callback failed, error: %{public}d", error);
66
67 return reply.ReadInt32();
68 }
69
SetAudioManagerInterruptCallback(const int32_t clientId,const sptr<IRemoteObject> & object)70 int32_t AudioPolicyProxy::SetAudioManagerInterruptCallback(const int32_t clientId, const sptr<IRemoteObject> &object)
71 {
72 MessageParcel data;
73 MessageParcel reply;
74 MessageOption option;
75
76 CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT,
77 "SetAudioManagerInterruptCallback object is null");
78 bool ret = data.WriteInterfaceToken(GetDescriptor());
79 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
80 data.WriteInt32(clientId);
81 (void)data.WriteRemoteObject(object);
82 int error = Remote()->SendRequest(
83 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_INTERRUPT_CALLBACK), data, reply, option);
84 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
85 "set callback failed, error: %{public}d", error);
86
87 return reply.ReadInt32();
88 }
89
UnsetAudioManagerInterruptCallback(const int32_t clientId)90 int32_t AudioPolicyProxy::UnsetAudioManagerInterruptCallback(const int32_t clientId)
91 {
92 MessageParcel data;
93 MessageParcel reply;
94 MessageOption option;
95
96 bool ret = data.WriteInterfaceToken(GetDescriptor());
97 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
98
99 data.WriteInt32(clientId);
100
101 int error = Remote()->SendRequest(
102 static_cast<uint32_t>(AudioPolicyInterfaceCode::UNSET_INTERRUPT_CALLBACK), data, reply, option);
103 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
104 "unset callback failed, error: %{public}d", error);
105
106 return reply.ReadInt32();
107 }
108
SetQueryClientTypeCallback(const sptr<IRemoteObject> & object)109 int32_t AudioPolicyProxy::SetQueryClientTypeCallback(const sptr<IRemoteObject> &object)
110 {
111 MessageParcel data;
112 MessageParcel reply;
113 MessageOption option;
114
115 CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT,
116 "SetQueryClientTypeCallback object is null");
117 bool ret = data.WriteInterfaceToken(GetDescriptor());
118 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
119 (void)data.WriteRemoteObject(object);
120 int error = Remote()->SendRequest(
121 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_QUERY_CLIENT_TYPE_CALLBACK), data, reply, option);
122 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
123 "set callback failed, error: %{public}d", error);
124
125 return reply.ReadInt32();
126 }
127
SetAudioClientInfoMgrCallback(const sptr<IRemoteObject> & object)128 int32_t AudioPolicyProxy::SetAudioClientInfoMgrCallback(const sptr<IRemoteObject> &object)
129 {
130 MessageParcel data;
131 MessageParcel reply;
132 MessageOption option;
133
134 CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT,
135 "SetAudioClientInfoMgrCallback object is null");
136 bool ret = data.WriteInterfaceToken(GetDescriptor());
137 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
138 (void)data.WriteRemoteObject(object);
139 int error = Remote()->SendRequest(
140 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_CLIENT_INFO_MGR_CALLBACK), data, reply, option);
141 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
142 "set callback failed, error: %{public}d", error);
143
144 return reply.ReadInt32();
145 }
146
SetAvailableDeviceChangeCallback(const int32_t clientId,const AudioDeviceUsage usage,const sptr<IRemoteObject> & object)147 int32_t AudioPolicyProxy::SetAvailableDeviceChangeCallback(const int32_t clientId, const AudioDeviceUsage usage,
148 const sptr<IRemoteObject> &object)
149 {
150 MessageParcel data;
151 MessageParcel reply;
152 MessageOption option;
153
154 CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "SetAvailableDeviceChangeCallback object is null");
155
156 bool token = data.WriteInterfaceToken(GetDescriptor());
157 CHECK_AND_RETURN_RET_LOG(token, ERROR, "data WriteInterfaceToken failed");
158 token = data.WriteInt32(clientId) && data.WriteInt32(usage);
159 CHECK_AND_RETURN_RET_LOG(token, ERROR, "data write failed");
160
161 token = data.WriteRemoteObject(object);
162 CHECK_AND_RETURN_RET_LOG(token, ERROR, "data WriteRemoteObject failed");
163
164 int error = Remote()->SendRequest(
165 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_AVAILABLE_DEVICE_CHANGE_CALLBACK), data, reply, option);
166 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
167 "SetAvailableDeviceChangeCallback failed, error: %{public}d", error);
168
169 return reply.ReadInt32();
170 }
171
UnsetAvailableDeviceChangeCallback(const int32_t clientId,AudioDeviceUsage usage)172 int32_t AudioPolicyProxy::UnsetAvailableDeviceChangeCallback(const int32_t clientId, AudioDeviceUsage usage)
173 {
174 MessageParcel data;
175 MessageParcel reply;
176 MessageOption option;
177
178 bool token = data.WriteInterfaceToken(GetDescriptor());
179 CHECK_AND_RETURN_RET_LOG(token, ERROR, "data WriteInterfaceToken failed");
180 token = data.WriteInt32(clientId) && data.WriteInt32(usage);
181 CHECK_AND_RETURN_RET_LOG(token, ERROR, "data write failed");
182
183 int error = Remote()->SendRequest(
184 static_cast<uint32_t>(AudioPolicyInterfaceCode::UNSET_AVAILABLE_DEVICE_CHANGE_CALLBACK), data, reply, option);
185 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
186 "UnsetAvailableDeviceChangeCallback failed, error: %{public}d", error);
187
188 return reply.ReadInt32();
189 }
190
191
SetAudioConcurrencyCallback(const uint32_t sessionID,const sptr<IRemoteObject> & object)192 int32_t AudioPolicyProxy::SetAudioConcurrencyCallback(const uint32_t sessionID,
193 const sptr<IRemoteObject> &object)
194 {
195 MessageParcel data;
196 MessageParcel reply;
197 MessageOption option;
198
199 CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT,
200 "SetAudioConcurrencyCallback object is null");
201 bool ret = data.WriteInterfaceToken(GetDescriptor());
202 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
203
204 data.WriteUint32(sessionID);
205 (void)data.WriteRemoteObject(object);
206 int32_t error = Remote()->SendRequest(
207 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_AUDIO_CONCURRENCY_CALLBACK), data, reply, option);
208 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
209
210 return reply.ReadInt32();
211 }
212
UnsetAudioConcurrencyCallback(const uint32_t sessionID)213 int32_t AudioPolicyProxy::UnsetAudioConcurrencyCallback(const uint32_t sessionID)
214 {
215 MessageParcel data;
216 MessageParcel reply;
217 MessageOption option;
218
219 bool ret = data.WriteInterfaceToken(GetDescriptor());
220 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
221 data.WriteUint32(sessionID);
222 int error = Remote()->SendRequest(
223 static_cast<uint32_t>(AudioPolicyInterfaceCode::UNSET_AUDIO_CONCURRENCY_CALLBACK), data, reply, option);
224 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
225 "unset concurrency callback failed, error: %{public}d", error);
226
227 return reply.ReadInt32();
228 }
229
SetDistributedRoutingRoleCallback(const sptr<IRemoteObject> & object)230 int32_t AudioPolicyProxy::SetDistributedRoutingRoleCallback(const sptr<IRemoteObject> &object)
231 {
232 MessageParcel data;
233 MessageParcel reply;
234 MessageOption option;
235
236 CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "object is null");
237 bool ret = data.WriteInterfaceToken(GetDescriptor());
238 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
239 (void)data.WriteRemoteObject(object);
240 int error = Remote()->SendRequest(
241 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_DISTRIBUTED_ROUTING_ROLE_CALLBACK), data, reply, option);
242 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "failed error : %{public}d", error);
243 return reply.ReadInt32();
244 }
245
UnsetDistributedRoutingRoleCallback()246 int32_t AudioPolicyProxy::UnsetDistributedRoutingRoleCallback()
247 {
248 MessageParcel data;
249 MessageParcel reply;
250 MessageOption option;
251
252 bool token = data.WriteInterfaceToken(GetDescriptor());
253 CHECK_AND_RETURN_RET_LOG(token, ERROR, "data writeInterfaceToken failed");
254
255 int error = Remote()->SendRequest(
256 static_cast<uint32_t>(AudioPolicyInterfaceCode::UNSET_DISTRIBUTED_ROUTING_ROLE_CALLBACK), data, reply, option);
257 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error,
258 "AudioPolicyProxy UnsetDistributedRoutingRoleCallback failed error : %{public}d", error);
259 return reply.ReadInt32();
260 }
261
SetClientCallbacksEnable(const CallbackChange & callbackchange,const bool & enable)262 int32_t AudioPolicyProxy::SetClientCallbacksEnable(const CallbackChange &callbackchange, const bool &enable)
263 {
264 MessageParcel data;
265 MessageParcel reply;
266 MessageOption option;
267
268 bool ret = data.WriteInterfaceToken(GetDescriptor());
269 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
270 data.WriteInt32(static_cast<int32_t>(callbackchange));
271 data.WriteBool(enable);
272
273 int error = Remote()->SendRequest(
274 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_CALLBACKS_ENABLE), data, reply, option);
275 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Set client callback failed, error: %{public}d", error);
276
277 return reply.ReadInt32();
278 }
279
SetCallbackRendererInfo(const AudioRendererInfo & rendererInfo)280 int32_t AudioPolicyProxy::SetCallbackRendererInfo(const AudioRendererInfo &rendererInfo)
281 {
282 MessageParcel data;
283 MessageParcel reply;
284 MessageOption option;
285
286 bool ret = data.WriteInterfaceToken(GetDescriptor());
287 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
288 rendererInfo.Marshalling(data);
289
290 int error = Remote()->SendRequest(
291 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_CALLBACK_RENDERER_INFO), data, reply, option);
292 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Set renderer info failed, error: %{public}d", error);
293
294 return reply.ReadInt32();
295 }
296
SetCallbackCapturerInfo(const AudioCapturerInfo & capturerInfo)297 int32_t AudioPolicyProxy::SetCallbackCapturerInfo(const AudioCapturerInfo &capturerInfo)
298 {
299 MessageParcel data;
300 MessageParcel reply;
301 MessageOption option;
302
303 bool ret = data.WriteInterfaceToken(GetDescriptor());
304 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
305 capturerInfo.Marshalling(data);
306
307 int error = Remote()->SendRequest(
308 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_CALLBACK_CAPTURER_INFO), data, reply, option);
309 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "Set capturer info failed, error: %{public}d", error);
310
311 return reply.ReadInt32();
312 }
313
RegisterPolicyCallbackClient(const sptr<IRemoteObject> & object,const int32_t zoneID)314 int32_t AudioPolicyProxy::RegisterPolicyCallbackClient(const sptr<IRemoteObject> &object, const int32_t zoneID)
315 {
316 MessageParcel data;
317 MessageParcel reply;
318 MessageOption option;
319
320 CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "RegisterPolicyCallbackClient object is null");
321 bool ret = data.WriteInterfaceToken(GetDescriptor());
322 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
323
324 data.WriteRemoteObject(object);
325 data.WriteInt32(zoneID);
326 int error = Remote()->SendRequest(
327 static_cast<uint32_t>(AudioPolicyInterfaceCode::REGISTER_POLICY_CALLBACK_CLIENT), data, reply, option);
328 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SendRequest failed , error: %{public}d", error);
329 return reply.ReadInt32();
330 }
331
SetAudioDeviceRefinerCallback(const sptr<IRemoteObject> & object)332 int32_t AudioPolicyProxy::SetAudioDeviceRefinerCallback(const sptr<IRemoteObject> &object)
333 {
334 MessageParcel data;
335 MessageParcel reply;
336 MessageOption option;
337
338 CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "object is null");
339
340 bool ret = data.WriteInterfaceToken(GetDescriptor());
341 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
342
343 (void)data.WriteRemoteObject(object);
344 int32_t error = Remote()->SendRequest(
345 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_AUDIO_DEVICE_REFINER_CALLBACK), data, reply, option);
346 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
347 return reply.ReadInt32();
348 }
349
UnsetAudioDeviceRefinerCallback()350 int32_t AudioPolicyProxy::UnsetAudioDeviceRefinerCallback()
351 {
352 MessageParcel data;
353 MessageParcel reply;
354 MessageOption option;
355
356 bool ret = data.WriteInterfaceToken(GetDescriptor());
357 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
358
359 int32_t error = Remote()->SendRequest(
360 static_cast<uint32_t>(AudioPolicyInterfaceCode::UNSET_AUDIO_DEVICE_REFINER_CALLBACK), data, reply, option);
361 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "SendRequest failed, error: %{public}d", error);
362 return reply.ReadInt32();
363 }
364
365
RegisterSpatializationStateEventListener(const uint32_t sessionID,const StreamUsage streamUsage,const sptr<IRemoteObject> & object)366 int32_t AudioPolicyProxy::RegisterSpatializationStateEventListener(const uint32_t sessionID,
367 const StreamUsage streamUsage, const sptr<IRemoteObject> &object)
368 {
369 MessageParcel data;
370 MessageParcel reply;
371 MessageOption option;
372
373 bool ret = data.WriteInterfaceToken(GetDescriptor());
374 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
375 CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "SpatializationStateEventListener object is null");
376
377 data.WriteInt32(static_cast<int32_t>(sessionID));
378 data.WriteInt32(static_cast<int32_t>(streamUsage));
379 data.WriteRemoteObject(object);
380 int32_t error = Remote() ->SendRequest(
381 static_cast<uint32_t>(AudioPolicyInterfaceCode::REGISTER_SPATIALIZATION_STATE_EVENT), data, reply, option);
382 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SendRequest failed , error: %{public}d", error);
383
384 return reply.ReadInt32();
385 }
386
UnregisterSpatializationStateEventListener(const uint32_t sessionID)387 int32_t AudioPolicyProxy::UnregisterSpatializationStateEventListener(const uint32_t sessionID)
388 {
389 MessageParcel data;
390 MessageParcel reply;
391 MessageOption option;
392
393 bool ret = data.WriteInterfaceToken(GetDescriptor());
394 CHECK_AND_RETURN_RET_LOG(ret, ERROR, "WriteInterfaceToken failed");
395
396 data.WriteInt32(static_cast<int32_t>(sessionID));
397 int32_t error = Remote() ->SendRequest(
398 static_cast<uint32_t>(AudioPolicyInterfaceCode::UNREGISTER_SPATIALIZATION_STATE_EVENT), data, reply, option);
399 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, ERROR, "SendRequest failed , error: %{public}d", error);
400
401 return reply.ReadInt32();
402 }
403
SetQueryAllowedPlaybackCallback(const sptr<IRemoteObject> & object)404 int32_t AudioPolicyProxy::SetQueryAllowedPlaybackCallback(const sptr<IRemoteObject> &object)
405 {
406 MessageParcel data;
407 MessageParcel reply;
408 MessageOption option;
409
410 CHECK_AND_RETURN_RET_LOG(object != nullptr, ERR_NULL_OBJECT, "SetQueryAllowedPlaybackCallback object is null");
411 bool ret = data.WriteInterfaceToken(GetDescriptor());
412 CHECK_AND_RETURN_RET_LOG(ret, -1, "WriteInterfaceToken failed");
413 (void)data.WriteRemoteObject(object);
414 int error = Remote()->SendRequest(
415 static_cast<uint32_t>(AudioPolicyInterfaceCode::SET_QUERY_ALLOWED_PLAYBACK_CALLBACK), data, reply, option);
416 CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, error, "set callback failed, error: %{public}d", error);
417
418 return reply.ReadInt32();
419 }
420 } // namespace AudioStandard
421 } // namespace OHOS