1 /*
2 * Copyright (c) 2022-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
16 #include "avsession_service_proxy.h"
17 #include "avsession_log.h"
18 #include "avsession_proxy.h"
19 #include "avsession_controller_proxy.h"
20
21 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
22 #include "avcast_controller_proxy.h"
23 #endif
24
25 namespace OHOS::AVSession {
AVSessionServiceProxy(const sptr<IRemoteObject> & impl)26 AVSessionServiceProxy::AVSessionServiceProxy(const sptr<IRemoteObject>& impl)
27 : IRemoteProxy<IAVSessionService>(impl)
28 {
29 SLOGI("constructor");
30 }
31
CreateSession(const std::string & tag,int32_t type,const AppExecFwk::ElementName & elementName)32 std::shared_ptr<AVSession> AVSessionServiceProxy::CreateSession(const std::string& tag, int32_t type,
33 const AppExecFwk::ElementName& elementName)
34 {
35 auto object = AVSessionServiceProxy::CreateSessionInner(tag, type, elementName);
36 if (object == nullptr) {
37 SLOGE("object is nullptr");
38 return nullptr;
39 }
40 auto session = iface_cast<AVSessionProxy>(object);
41 if (session == nullptr) {
42 SLOGE("session is nullptr");
43 return nullptr;
44 }
45 return std::shared_ptr<AVSession>(session.GetRefPtr(), [holder = session](const auto*) {});
46 }
47
CreateSession(const std::string & tag,int32_t type,const AppExecFwk::ElementName & elementName,std::shared_ptr<AVSession> & session)48 int32_t AVSessionServiceProxy::CreateSession(const std::string& tag, int32_t type,
49 const AppExecFwk::ElementName& elementName,
50 std::shared_ptr<AVSession>& session)
51 {
52 sptr<IRemoteObject> object;
53 auto ret = AVSessionServiceProxy::CreateSessionInner(tag, type, elementName, object);
54 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "CreateSession failed");
55
56 auto sessionObj = iface_cast<AVSessionProxy>(object);
57 CHECK_AND_RETURN_RET_LOG(sessionObj, AVSESSION_ERROR, "sessionObj is nullptr");
58
59 session = std::shared_ptr<AVSession>(sessionObj.GetRefPtr(), [holder = sessionObj](const auto*) {});
60 return ret;
61 }
62
CreateSessionInner(const std::string & tag,int32_t type,const AppExecFwk::ElementName & elementName)63 sptr<IRemoteObject> AVSessionServiceProxy::CreateSessionInner(const std::string& tag, int32_t type,
64 const AppExecFwk::ElementName& elementName)
65 {
66 sptr<IRemoteObject> object;
67 auto ret = AVSessionServiceProxy::CreateSessionInner(tag, type, elementName, object);
68 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, nullptr, "CreateSessionInner failed");
69 return object;
70 }
71
CreateSessionInner(const std::string & tag,int32_t type,const AppExecFwk::ElementName & elementName,sptr<IRemoteObject> & object)72 int32_t AVSessionServiceProxy::CreateSessionInner(const std::string& tag, int32_t type,
73 const AppExecFwk::ElementName& elementName,
74 sptr<IRemoteObject>& object)
75 {
76 MessageParcel data;
77 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()),
78 ERR_UNMARSHALLING, "write interface token failed");
79 CHECK_AND_RETURN_RET_LOG(data.WriteString(tag), ERR_UNMARSHALLING, "write tag failed");
80 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(type), ERR_UNMARSHALLING, "write type failed");
81 CHECK_AND_RETURN_RET_LOG(data.WriteParcelable(&elementName), ERR_UNMARSHALLING, "write bundleName failed");
82
83 auto remote = Remote();
84 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_UNMARSHALLING, "get remote service failed");
85 MessageParcel reply;
86 MessageOption option;
87 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
88 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_CREATE_SESSION), data, reply, option) == 0,
89 ERR_IPC_SEND_REQUEST, "send request failed");
90
91 int32_t res = AVSESSION_ERROR;
92 CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(res), ERR_UNMARSHALLING, "read res failed");
93 if (res == AVSESSION_SUCCESS) {
94 object = reply.ReadRemoteObject();
95 }
96 return res;
97 }
98
GetAllSessionDescriptors(std::vector<AVSessionDescriptor> & descriptors)99 int32_t AVSessionServiceProxy::GetAllSessionDescriptors(std::vector<AVSessionDescriptor>& descriptors)
100 {
101 MessageParcel data;
102 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
103 "write interface token failed");
104 auto remote = Remote();
105 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
106 MessageParcel reply;
107 MessageOption option;
108 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
109 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_GET_ALL_SESSION_DESCRIPTORS),\
110 data, reply, option) == 0,
111 ERR_IPC_SEND_REQUEST, "send request failed");
112
113 int32_t ret = AVSESSION_ERROR;
114 CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_UNMARSHALLING, "read int32 failed");
115 CHECK_AND_RETURN_RET_LOG(ret != ERR_NO_PERMISSION, ret, "no permission");
116 CHECK_AND_RETURN_RET_LOG(ret != ERR_PERMISSION_DENIED, ret, "permission denied");
117 if (ret == AVSESSION_SUCCESS) {
118 uint32_t size {};
119 CHECK_AND_RETURN_RET_LOG(reply.ReadUint32(size), ERR_UNMARSHALLING, "read vector size failed");
120 CHECK_AND_RETURN_RET_LOG(size, ret, "get all session with true empty");
121
122 std::vector<AVSessionDescriptor> result(size);
123 for (auto& descriptor : result) {
124 CHECK_AND_RETURN_RET_LOG(descriptor.ReadFromParcel(reply), ERR_UNMARSHALLING, "read descriptor failed");
125 }
126 descriptors = result;
127 }
128 return ret;
129 }
130
GetSessionDescriptorsBySessionId(const std::string & sessionId,AVSessionDescriptor & descriptor)131 int32_t AVSessionServiceProxy::GetSessionDescriptorsBySessionId(const std::string& sessionId,
132 AVSessionDescriptor& descriptor)
133 {
134 MessageParcel data;
135 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
136 "write interface token failed");
137 CHECK_AND_RETURN_RET_LOG(data.WriteString(sessionId), ERR_MARSHALLING, "write sessionId failed");
138
139 auto remote = Remote();
140 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
141 MessageParcel reply;
142 MessageOption option;
143 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
144 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_GET_SESSION_DESCRIPTORS_BY_ID),\
145 data, reply, option) == 0,
146 ERR_IPC_SEND_REQUEST, "send request failed");
147 int32_t ret = AVSESSION_ERROR;
148 CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_UNMARSHALLING, "read int32 failed");
149 CHECK_AND_RETURN_RET_LOG(ret != ERR_NO_PERMISSION, ret, "no permission");
150 if (ret == AVSESSION_SUCCESS) {
151 CHECK_AND_RETURN_RET_LOG(descriptor.ReadFromParcel(reply), ERR_UNMARSHALLING, "read descriptor failed");
152 }
153 return ret;
154 }
155
GetHistoricalSessionDescriptors(int32_t maxSize,std::vector<AVSessionDescriptor> & descriptors)156 int32_t AVSessionServiceProxy::GetHistoricalSessionDescriptors(int32_t maxSize,
157 std::vector<AVSessionDescriptor>& descriptors)
158 {
159 MessageParcel data;
160 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
161 "write interface token failed");
162 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(maxSize), ERR_MARSHALLING, "write maxSize failed");
163
164 auto remote = Remote();
165 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
166 MessageParcel reply;
167 MessageOption option;
168 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
169 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_GET_HISTORY_SESSION_DESCRIPTORS),\
170 data, reply, option) == 0,
171 ERR_IPC_SEND_REQUEST, "send request failed");
172
173 int32_t ret = AVSESSION_ERROR;
174 CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_UNMARSHALLING, "read int32 failed");
175 CHECK_AND_RETURN_RET_LOG(ret != ERR_NO_PERMISSION, ret, "no permission");
176 CHECK_AND_RETURN_RET_LOG(ret != ERR_PERMISSION_DENIED, ret, "permission denied");
177 if (ret == AVSESSION_SUCCESS) {
178 uint32_t size {};
179 CHECK_AND_RETURN_RET_LOG(reply.ReadUint32(size), ERR_UNMARSHALLING, "read vector size failed");
180 CHECK_AND_RETURN_RET_LOG(size, ret, "size=0");
181
182 std::vector<AVSessionDescriptor> result(size);
183 for (auto& descriptor : result) {
184 CHECK_AND_RETURN_RET_LOG(descriptor.ReadFromParcel(reply), ERR_UNMARSHALLING, "read descriptor failed");
185 }
186 descriptors = result;
187 }
188 return ret;
189 }
190
UnMarshallingAVQueueInfos(MessageParcel & reply,std::vector<AVQueueInfo> & avQueueInfos)191 void AVSessionServiceProxy::UnMarshallingAVQueueInfos(MessageParcel &reply, std::vector<AVQueueInfo>& avQueueInfos)
192 {
193 uint32_t size {};
194 CHECK_AND_RETURN_LOG(reply.ReadUint32(size), "UnMarshallingAVQueueInfos size failed");
195 CHECK_AND_RETURN_LOG(size, "UnMarshallingAVQueueInfos size=0");
196
197 for (uint32_t i = 0; i < size; i++) {
198 AVQueueInfo avQueueInfo;
199 avQueueInfo.SetBundleName(reply.ReadString());
200 avQueueInfo.SetAVQueueName(reply.ReadString());
201 avQueueInfo.SetAVQueueId(reply.ReadString());
202 avQueueInfo.SetAVQueueImageUri(reply.ReadString());
203 avQueueInfo.SetAVQueueLength(reply.ReadUint32());
204 avQueueInfos.push_back(avQueueInfo);
205 }
206 }
207
BufferToAVQueueInfoImg(const char * buffer,std::vector<AVQueueInfo> & avQueueInfos)208 void AVSessionServiceProxy::BufferToAVQueueInfoImg(const char *buffer, std::vector<AVQueueInfo>& avQueueInfos)
209 {
210 int k = 0;
211 for (auto& avQueueInfo : avQueueInfos) {
212 std::shared_ptr<AVSessionPixelMap> pixelMap = std::make_shared<AVSessionPixelMap>();
213 std::vector<uint8_t> imgBuffer;
214 int avQueueLength = avQueueInfo.GetAVQueueLength();
215 for (int i = 0; i < avQueueLength; i++, k++) {
216 imgBuffer.push_back((uint8_t)buffer[k]);
217 }
218 pixelMap->SetInnerImgBuffer(imgBuffer);
219 avQueueInfo.SetAVQueueImage(pixelMap);
220 }
221 }
222
GetHistoricalAVQueueInfos(int32_t maxSize,int32_t maxAppSize,std::vector<AVQueueInfo> & avQueueInfos)223 int32_t AVSessionServiceProxy::GetHistoricalAVQueueInfos(int32_t maxSize, int32_t maxAppSize,
224 std::vector<AVQueueInfo>& avQueueInfos)
225 {
226 MessageParcel data;
227 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
228 "write interface token failed");
229 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(maxSize), ERR_MARSHALLING, "write maxSize failed");
230 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(maxAppSize), ERR_MARSHALLING, "write maxAppSize failed");
231
232 auto remote = Remote();
233 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
234 MessageParcel reply;
235 MessageOption option;
236 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
237 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_GET_HISTORY_AVQUEUE_INFOS),\
238 data, reply, option) == 0,
239 ERR_IPC_SEND_REQUEST, "send request failed");
240
241 int32_t ret = AVSESSION_ERROR;
242 CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_UNMARSHALLING, "read int32 failed");
243 CHECK_AND_RETURN_RET_LOG(ret != ERR_NO_PERMISSION, ret, "no permission");
244 CHECK_AND_RETURN_RET_LOG(ret != ERR_PERMISSION_DENIED, ret, "permission denied");
245 if (ret != AVSESSION_SUCCESS) {
246 return ret;
247 }
248 int bufferLength = reply.ReadInt32();
249 if (bufferLength == 0) {
250 uint32_t size {};
251 CHECK_AND_RETURN_RET_LOG(reply.ReadUint32(size), ERR_UNMARSHALLING, "read vector size failed");
252 CHECK_AND_RETURN_RET_LOG(size, ret, "size=0");
253
254 std::vector<AVQueueInfo> result(size);
255 for (auto& avQueueInfo : result) {
256 CHECK_AND_RETURN_RET_LOG(avQueueInfo.Unmarshalling(reply), ERR_UNMARSHALLING, "read avqueueInfo failed");
257 }
258 avQueueInfos = result;
259 return ret;
260 }
261 UnMarshallingAVQueueInfos(reply, avQueueInfos);
262 const char *buffer = nullptr;
263 buffer = reinterpret_cast<const char *>(reply.ReadRawData(bufferLength));
264 if (buffer == nullptr) {
265 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed");
266 SLOGE("read raw data failed, length = %{public}d", bufferLength);
267 return AVSESSION_ERROR;
268 }
269 BufferToAVQueueInfoImg(buffer, avQueueInfos);
270 return AVSESSION_SUCCESS;
271 }
272
StartAVPlayback(const std::string & bundleName,const std::string & assetId)273 int32_t AVSessionServiceProxy::StartAVPlayback(const std::string& bundleName, const std::string& assetId)
274 {
275 MessageParcel data;
276 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
277 "write interface token failed");
278 CHECK_AND_RETURN_RET_LOG(data.WriteString(bundleName), ERR_MARSHALLING, "write bundleName failed");
279 CHECK_AND_RETURN_RET_LOG(data.WriteString(assetId), ERR_MARSHALLING, "write assetId failed");
280
281 auto remote = Remote();
282 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
283 MessageParcel reply;
284 MessageOption option;
285 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
286 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_START_AV_PLAYBACK),\
287 data, reply, option) == 0,
288 ERR_IPC_SEND_REQUEST, "send request failed");
289
290 int32_t ret = AVSESSION_ERROR;
291 CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_UNMARSHALLING, "read int32 failed");
292 return ret;
293 }
294
CreateController(const std::string & sessionId,std::shared_ptr<AVSessionController> & controller)295 int32_t AVSessionServiceProxy::CreateController(const std::string& sessionId,
296 std::shared_ptr<AVSessionController>& controller)
297 {
298 std::lock_guard lockGuard(createControllerMutex_);
299 SLOGI("create controller in");
300 sptr<IRemoteObject> object;
301 auto ret = AVSessionServiceProxy::CreateControllerInner(sessionId, object);
302 CHECK_AND_RETURN_RET_LOG((ret == AVSESSION_SUCCESS || ret == ERR_CONTROLLER_IS_EXIST),
303 ret, "CreateControllerInner failed");
304 CHECK_AND_RETURN_RET_LOG(ret != ERR_NO_PERMISSION, ret, "no permission");
305 CHECK_AND_RETURN_RET_LOG(ret != ERR_PERMISSION_DENIED, ret, "permission denied");
306 auto controllerObject = iface_cast<AVSessionControllerProxy>(object);
307 CHECK_AND_RETURN_RET_LOG(controllerObject, AVSESSION_ERROR, "controllerObject is nullptr");
308
309 controller = std::shared_ptr<AVSessionController>(controllerObject.GetRefPtr(),
310 [holder = controllerObject](const auto*) {});
311 return ret;
312 }
313
CreateControllerInner(const std::string & sessionId,sptr<IRemoteObject> & object)314 int32_t AVSessionServiceProxy::CreateControllerInner(const std::string& sessionId, sptr<IRemoteObject>& object)
315 {
316 MessageParcel data;
317 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_UNMARSHALLING,
318 "write interface token failed");
319 CHECK_AND_RETURN_RET_LOG(data.WriteString(sessionId), ERR_UNMARSHALLING, "write sessionId failed");
320
321 auto remote = Remote();
322 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
323 MessageParcel reply;
324 MessageOption option;
325 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
326 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_CREATE_CONTROLLER), data, reply, option) == 0,
327 ERR_IPC_SEND_REQUEST, "send request failed");
328 int32_t ret = AVSESSION_ERROR;
329 CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_UNMARSHALLING, "read int32 failed");
330 if (ret == AVSESSION_SUCCESS || ret == ERR_CONTROLLER_IS_EXIST) {
331 object = reply.ReadRemoteObject();
332 }
333 return ret;
334 }
335
336 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
GetAVCastController(const std::string & sessionId,std::shared_ptr<AVCastController> & castController)337 int32_t AVSessionServiceProxy::GetAVCastController(const std::string& sessionId,
338 std::shared_ptr<AVCastController>& castController)
339 {
340 sptr<IRemoteObject> object;
341 auto ret = AVSessionServiceProxy::GetAVCastControllerInner(sessionId, object);
342 CHECK_AND_RETURN_RET_LOG(ret != ERR_NO_PERMISSION, ret, "no permission");
343 CHECK_AND_RETURN_RET_LOG(ret != ERR_PERMISSION_DENIED, ret, "permission denied");
344 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "CreateControllerInner failed");
345
346 auto castControllerObject = iface_cast<AVCastControllerProxy>(object);
347 CHECK_AND_RETURN_RET_LOG(castControllerObject, AVSESSION_ERROR, "castControllerObject is nullptr");
348
349 castController = std::shared_ptr<AVCastController>(castControllerObject.GetRefPtr(),
350 [holder = castControllerObject](const auto*) {});
351 return ret;
352 }
353
GetAVCastControllerInner(const std::string & sessionId,sptr<IRemoteObject> & object)354 int32_t AVSessionServiceProxy::GetAVCastControllerInner(const std::string& sessionId, sptr<IRemoteObject>& object)
355 {
356 MessageParcel data;
357 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_UNMARSHALLING,
358 "write interface token failed");
359 CHECK_AND_RETURN_RET_LOG(data.WriteString(sessionId), ERR_UNMARSHALLING, "write sessionId failed");
360
361 auto remote = Remote();
362 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
363 MessageParcel reply;
364 MessageOption option;
365 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
366 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_GET_AV_CAST_CONTROLLER),\
367 data, reply, option) == 0,
368 ERR_IPC_SEND_REQUEST, "send request failed");
369 int32_t ret = AVSESSION_ERROR;
370 CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_UNMARSHALLING, "read int32 failed");
371 CHECK_AND_RETURN_RET_LOG(ret != ERR_NO_PERMISSION, ret, "no permission");
372 CHECK_AND_RETURN_RET_LOG(ret != ERR_PERMISSION_DENIED, ret, "permission denied");
373 if (ret == AVSESSION_SUCCESS) {
374 object = reply.ReadRemoteObject();
375 }
376 return ret;
377 }
378 #endif
379
RegisterSessionListener(const sptr<ISessionListener> & listener)380 int32_t AVSessionServiceProxy::RegisterSessionListener(const sptr<ISessionListener>& listener)
381 {
382 MessageParcel data;
383 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
384 "write interface token failed in RegisterSessionListener");
385 CHECK_AND_RETURN_RET_LOG(data.WriteRemoteObject(listener->AsObject()), ERR_MARSHALLING, "write tag failed");
386
387 auto remote = Remote();
388 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
389 MessageParcel reply;
390 MessageOption option;
391 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
392 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_REGISTER_SESSION_LISTENER),\
393 data, reply, option) == 0,
394 ERR_IPC_SEND_REQUEST, "send request failed");
395 int32_t res = AVSESSION_ERROR;
396 return reply.ReadInt32(res) ? res : AVSESSION_ERROR;
397 }
398
RegisterSessionListenerForAllUsers(const sptr<ISessionListener> & listener)399 int32_t AVSessionServiceProxy::RegisterSessionListenerForAllUsers(const sptr<ISessionListener>& listener)
400 {
401 MessageParcel data;
402 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
403 "write interface token failed in RegisterSessionListenerForAllUsers");
404 CHECK_AND_RETURN_RET_LOG(data.WriteRemoteObject(listener->AsObject()), ERR_MARSHALLING, "write tag failed");
405
406 auto remote = Remote();
407 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
408 MessageParcel reply;
409 MessageOption option;
410 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
411 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_REGISTER_SESSION_LISTENER_FOR_ALL_USERS),\
412 data, reply, option) == 0,
413 ERR_IPC_SEND_REQUEST, "send request failed");
414 int32_t res = AVSESSION_ERROR;
415 return reply.ReadInt32(res) ? res : AVSESSION_ERROR;
416 }
417
SendSystemAVKeyEvent(const MMI::KeyEvent & keyEvent)418 int32_t AVSessionServiceProxy::SendSystemAVKeyEvent(const MMI::KeyEvent& keyEvent)
419 {
420 MessageParcel data;
421 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
422 "write interface token failed");
423 SLOGI("try SendSystemAVKeyEvent with key=%{public}d", keyEvent.GetKeyCode());
424 CHECK_AND_RETURN_RET_LOG(keyEvent.WriteToParcel(data), ERR_MARSHALLING, "write keyEvent failed");
425
426 auto remote = Remote();
427 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
428 MessageParcel reply;
429 MessageOption option;
430 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
431 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_SEND_SYSTEM_AV_KEY_EVENT),\
432 data, reply, option) == 0,
433 ERR_IPC_SEND_REQUEST, "send request failed");
434 int32_t res = AVSESSION_ERROR;
435 return reply.ReadInt32(res) ? res : AVSESSION_ERROR;
436 }
437
SendSystemAVKeyEvent(const MMI::KeyEvent & keyEvent,const AAFwk::Want & wantParam)438 int32_t AVSessionServiceProxy::SendSystemAVKeyEvent(const MMI::KeyEvent& keyEvent, const AAFwk::Want &wantParam)
439 {
440 MessageParcel data;
441 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
442 "write interface token failed");
443 CHECK_AND_RETURN_RET_LOG(keyEvent.WriteToParcel(data), ERR_MARSHALLING, "write keyEvent failed");
444 CHECK_AND_RETURN_RET_LOG(data.WriteParcelable(&wantParam), ERR_MARSHALLING, "write wantParam failed");
445 SLOGI("try SendSystemAVKeyEvent with key=%{public}d", keyEvent.GetKeyCode());
446
447 auto remote = Remote();
448 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
449 MessageParcel reply;
450 MessageOption option;
451 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
452 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_SEND_SYSTEM_AV_KEY_EVENT),\
453 data, reply, option) == 0,
454 ERR_IPC_SEND_REQUEST, "send request failed");
455 int32_t res = AVSESSION_ERROR;
456 return reply.ReadInt32(res) ? res : AVSESSION_ERROR;
457 }
458
SendSystemControlCommand(const AVControlCommand & command)459 int32_t AVSessionServiceProxy::SendSystemControlCommand(const AVControlCommand& command)
460 {
461 MessageParcel data;
462 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
463 "write interface token failed");
464 SLOGI("try SendSystemControlCommand with cmd=%{public}d", command.GetCommand());
465 CHECK_AND_RETURN_RET_LOG(data.WriteParcelable(&command), ERR_MARSHALLING, "write keyEvent failed");
466
467 auto remote = Remote();
468 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
469 MessageParcel reply;
470 MessageOption option;
471 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
472 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_SEND_SYSTEM_CONTROL_COMMAND),\
473 data, reply, option) == 0,
474 ERR_IPC_SEND_REQUEST, "send request failed");
475 int32_t res = AVSESSION_ERROR;
476 return reply.ReadInt32(res) ? res : AVSESSION_ERROR;
477 }
478
RegisterClientDeathObserver(const sptr<IClientDeath> & observer)479 int32_t AVSessionServiceProxy::RegisterClientDeathObserver(const sptr<IClientDeath>& observer)
480 {
481 MessageParcel data;
482 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
483 "write interface token failed");
484 CHECK_AND_RETURN_RET_LOG(data.WriteRemoteObject(observer->AsObject()), ERR_MARSHALLING, "write observer failed");
485
486 auto remote = Remote();
487 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
488 MessageParcel reply;
489 MessageOption option;
490 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
491 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_REGISTER_CLIENT_DEATH),\
492 data, reply, option) == 0,
493 ERR_IPC_SEND_REQUEST, "send request failed");
494 int32_t res = AVSESSION_ERROR;
495 return reply.ReadInt32(res) ? res : AVSESSION_ERROR;
496 }
497
Close(void)498 int32_t AVSessionServiceProxy::Close(void)
499 {
500 MessageParcel data;
501 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
502 "write interface token failed");
503
504 auto remote = Remote();
505 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
506 MessageParcel reply;
507 MessageOption option;
508 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
509 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_CLOSE),\
510 data, reply, option) == 0,
511 ERR_IPC_SEND_REQUEST, "send request failed");
512 int32_t res = AVSESSION_ERROR;
513 return reply.ReadInt32(res) ? res : AVSESSION_ERROR;
514 }
515
CastAudio(const SessionToken & token,const std::vector<AudioStandard::AudioDeviceDescriptor> & descriptors)516 int32_t AVSessionServiceProxy::CastAudio(const SessionToken& token,
517 const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors)
518 {
519 MessageParcel data;
520 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
521 "write interface token failed");
522 CHECK_AND_RETURN_RET_LOG(data.WriteString(token.sessionId), ERR_MARSHALLING, "write sessionId failed");
523 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(token.pid), ERR_MARSHALLING, "write pid failed");
524 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(token.uid), ERR_MARSHALLING, "write uid failed");
525 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(static_cast<int32_t>(descriptors.size())), ERR_MARSHALLING,
526 "write descriptors size failed");
527 for (auto descriptor : descriptors) {
528 SLOGI("networkId_: %{public}.6s, role %{public}d", descriptor.networkId_.c_str(),
529 static_cast<int32_t>(descriptor.deviceRole_));
530 CHECK_AND_RETURN_RET_LOG(descriptor.Marshalling(data), ERR_MARSHALLING, "write descriptor failed");
531 }
532
533 auto remote = Remote();
534 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
535 MessageParcel reply;
536 MessageOption option;
537 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
538 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_CAST_AUDIO), data, reply, option) == 0,
539 ERR_IPC_SEND_REQUEST, "send request failed");
540 int32_t res = AVSESSION_ERROR;
541 return reply.ReadInt32(res) ? res : AVSESSION_ERROR;
542 }
543
CastAudioForAll(const std::vector<AudioStandard::AudioDeviceDescriptor> & descriptors)544 int32_t AVSessionServiceProxy::CastAudioForAll(const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors)
545 {
546 MessageParcel data;
547 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
548 "write interface token failed");
549 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(static_cast<int32_t>(descriptors.size())), ERR_MARSHALLING,
550 "write descriptors size failed");
551 for (auto descriptor : descriptors) {
552 SLOGI("networkId_: %{public}.6s, role %{public}d", descriptor.networkId_.c_str(),
553 static_cast<int32_t>(descriptor.deviceRole_));
554 CHECK_AND_RETURN_RET_LOG(descriptor.Marshalling(data), ERR_MARSHALLING, "write descriptor failed");
555 }
556
557 auto remote = Remote();
558 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
559 MessageParcel reply;
560 MessageOption option;
561 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
562 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_CAST_AUDIO_FOR_ALL), data, reply, option) == 0,
563 ERR_IPC_SEND_REQUEST, "send request failed");
564 int32_t res = AVSESSION_ERROR;
565 return reply.ReadInt32(res) ? res : AVSESSION_ERROR;
566 }
567
568 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
StartCastDiscovery(int32_t castDeviceCapability,std::vector<std::string> drmSchemes)569 int32_t AVSessionServiceProxy::StartCastDiscovery(int32_t castDeviceCapability, std::vector<std::string> drmSchemes)
570 {
571 MessageParcel data;
572 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
573 "write interface token failed");
574 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(castDeviceCapability),
575 ERR_MARSHALLING, "write castDeviceCapability failed");
576 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(drmSchemes.size()), ERR_MARSHALLING, "write drmSchemes size failed");
577 for (auto drmScheme : drmSchemes) {
578 CHECK_AND_RETURN_RET_LOG(data.WriteString(drmScheme), ERR_MARSHALLING, "write drmScheme failed");
579 }
580 auto remote = Remote();
581 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
582 MessageParcel reply;
583 MessageOption option;
584 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
585 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_START_CAST_DISCOVERY),\
586 data, reply, option) == 0,
587 ERR_IPC_SEND_REQUEST, "send request failed");
588 int32_t res = AVSESSION_ERROR;
589 return reply.ReadInt32(res) ? res : AVSESSION_ERROR;
590 }
591
StopCastDiscovery()592 int32_t AVSessionServiceProxy::StopCastDiscovery()
593 {
594 MessageParcel data;
595 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
596 "write interface token failed");
597
598 auto remote = Remote();
599 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
600 MessageParcel reply;
601 MessageOption option;
602 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
603 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_STOP_CAST_DISCOVERY), data, reply, option) == 0,
604 ERR_IPC_SEND_REQUEST, "send request failed");
605 int32_t res = AVSESSION_ERROR;
606 return reply.ReadInt32(res) ? res : AVSESSION_ERROR;
607 }
608
SetDiscoverable(const bool enable)609 int32_t AVSessionServiceProxy::SetDiscoverable(const bool enable)
610 {
611 MessageParcel data;
612 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
613 "write interface token failed");
614 CHECK_AND_RETURN_RET_LOG(data.WriteBool(enable), ERR_MARSHALLING, "write enable failed");
615
616 auto remote = Remote();
617 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
618 MessageParcel reply;
619 MessageOption option;
620 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
621 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_SET_DISCOVERYABLE), data, reply, option) == 0,
622 ERR_IPC_SEND_REQUEST, "send request failed");
623 int32_t res = AVSESSION_ERROR;
624 return reply.ReadInt32(res) ? res : AVSESSION_ERROR;
625 }
626
StartDeviceLogging(int32_t fd,uint32_t maxSize)627 int32_t AVSessionServiceProxy::StartDeviceLogging(int32_t fd, uint32_t maxSize)
628 {
629 MessageParcel data;
630 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
631 "write interface token failed");
632 CHECK_AND_RETURN_RET_LOG(data.WriteFileDescriptor(fd), ERR_MARSHALLING, "write fd failed");
633 CHECK_AND_RETURN_RET_LOG(data.WriteUint32(maxSize), ERR_MARSHALLING, "write maxSize failed");
634 auto remote = Remote();
635 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
636 MessageParcel reply;
637 MessageOption option;
638 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
639 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_START_DEVICE_LOGGING),\
640 data, reply, option) == 0,
641 ERR_IPC_SEND_REQUEST, "send request failed");
642 int32_t res = AVSESSION_ERROR;
643 return reply.ReadInt32(res) ? res : AVSESSION_ERROR;
644 }
645
StopDeviceLogging()646 int32_t AVSessionServiceProxy::StopDeviceLogging()
647 {
648 MessageParcel data;
649 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
650 "write interface token failed");
651
652 auto remote = Remote();
653 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
654 MessageParcel reply;
655 MessageOption option;
656 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
657 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_STOP_DEVICE_LOGGING), data, reply, option) == 0,
658 ERR_IPC_SEND_REQUEST, "send request failed");
659 int32_t res = AVSESSION_ERROR;
660 return reply.ReadInt32(res) ? res : AVSESSION_ERROR;
661 }
662
StartCast(const SessionToken & sessionToken,const OutputDeviceInfo & outputDeviceInfo)663 int32_t AVSessionServiceProxy::StartCast(const SessionToken& sessionToken, const OutputDeviceInfo& outputDeviceInfo)
664 {
665 MessageParcel data;
666 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
667 "write interface token failed");
668 CHECK_AND_RETURN_RET_LOG(data.WriteString(sessionToken.sessionId), ERR_MARSHALLING, "write sessionId failed");
669 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(sessionToken.pid), ERR_MARSHALLING, "write pid failed");
670 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(sessionToken.uid), ERR_MARSHALLING, "write uid failed");
671
672 int32_t deviceInfoSize = static_cast<int32_t>(outputDeviceInfo.deviceInfos_.size());
673 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(deviceInfoSize), ERR_MARSHALLING, "write deviceInfoSize failed");
674 for (const DeviceInfo& deviceInfo : outputDeviceInfo.deviceInfos_) {
675 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(deviceInfo.castCategory_),
676 ERR_MARSHALLING, "write castCategory failed");
677 CHECK_AND_RETURN_RET_LOG(data.WriteString(deviceInfo.deviceId_), ERR_MARSHALLING, "write deviceId failed");
678 CHECK_AND_RETURN_RET_LOG(data.WriteString(deviceInfo.deviceName_), ERR_MARSHALLING, "write deviceName failed");
679 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(deviceInfo.deviceType_), ERR_MARSHALLING, "write deviceType failed");
680 CHECK_AND_RETURN_RET_LOG(data.WriteString(deviceInfo.ipAddress_), ERR_MARSHALLING, "write ipAddress failed");
681 CHECK_AND_RETURN_RET_LOG(data.WriteString(deviceInfo.networkId_), ERR_MARSHALLING, "write networkId failed");
682 CHECK_AND_RETURN_RET_LOG(data.WriteString(deviceInfo.manufacturer_),
683 ERR_MARSHALLING, "write manufacturer failed");
684 CHECK_AND_RETURN_RET_LOG(data.WriteString(deviceInfo.modelName_), ERR_MARSHALLING, "write modelName failed");
685 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(deviceInfo.providerId_), ERR_MARSHALLING, "write providerId failed");
686 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(deviceInfo.supportedProtocols_), ERR_MARSHALLING,
687 "write supportedProtocols failed");
688 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(deviceInfo.authenticationStatus_), ERR_MARSHALLING,
689 "write authenticationStatus failed");
690 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(deviceInfo.supportedDrmCapabilities_.size()), ERR_MARSHALLING,
691 "write supportedDrmCapabilities size failed");
692 for (auto supportedDrmCapability : deviceInfo.supportedDrmCapabilities_) {
693 CHECK_AND_RETURN_RET_LOG(data.WriteString(supportedDrmCapability), ERR_MARSHALLING,
694 "write supportedDrmCapability failed");
695 }
696 CHECK_AND_RETURN_RET_LOG(data.WriteBool(deviceInfo.isLegacy_), ERR_MARSHALLING, "write isLegacy failed");
697 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(deviceInfo.mediumTypes_), ERR_MARSHALLING,
698 "write mediumTypes failed");
699 }
700
701 auto remote = Remote();
702 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
703 MessageParcel reply;
704 MessageOption option;
705 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
706 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_START_CAST), data, reply, option) == 0,
707 ERR_IPC_SEND_REQUEST, "send request failed");
708 int32_t res = AVSESSION_ERROR;
709 return reply.ReadInt32(res) ? res : AVSESSION_ERROR;
710 }
711
StopCast(const SessionToken & sessionToken)712 int32_t AVSessionServiceProxy::StopCast(const SessionToken& sessionToken)
713 {
714 MessageParcel data;
715 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_MARSHALLING,
716 "write interface token failed");
717 CHECK_AND_RETURN_RET_LOG(data.WriteString(sessionToken.sessionId), ERR_MARSHALLING, "write sessionId failed");
718 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(sessionToken.pid), ERR_MARSHALLING, "write pid failed");
719 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(sessionToken.uid), ERR_MARSHALLING, "write uid failed");
720
721 auto remote = Remote();
722 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
723 MessageParcel reply;
724 MessageOption option;
725 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(
726 static_cast<uint32_t>(AvsessionSeviceInterfaceCode::SERVICE_CMD_STOP_CAST), data, reply, option) == 0,
727 ERR_IPC_SEND_REQUEST, "send request failed");
728 int32_t res = AVSESSION_ERROR;
729 return reply.ReadInt32(res) ? res : AVSESSION_ERROR;
730 }
731 #endif
732
GetDistributedSessionControllers(const DistributedSessionType & sessionType,std::vector<std::shared_ptr<AVSessionController>> & sessionControllers)733 int32_t AVSessionServiceProxy::GetDistributedSessionControllers(const DistributedSessionType& sessionType,
734 std::vector<std::shared_ptr<AVSessionController>>& sessionControllers)
735 {
736 std::vector<sptr<IRemoteObject>> objects;
737 auto ret = AVSessionServiceProxy::GetDistributedSessionControllersInner(sessionType, objects);
738 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "GetDistributedSessionControllers failed");
739 CHECK_AND_RETURN_RET_LOG(ret != ERR_NO_PERMISSION, ret, "no permission");
740 CHECK_AND_RETURN_RET_LOG(ret != ERR_PERMISSION_DENIED, ret, "permission denied");
741 CHECK_AND_RETURN_RET_LOG(ret != ERR_REMOTE_CONNECTION_NOT_EXIST, ret, "connect not exist");
742 for (auto& object: objects) {
743 auto controllerObject = iface_cast<AVSessionControllerProxy>(object);
744 CHECK_AND_RETURN_RET_LOG(controllerObject, AVSESSION_ERROR, "controllerObject is nullptr");
745 sessionControllers.push_back(std::shared_ptr<AVSessionController>(controllerObject.GetRefPtr(),
746 [holder = controllerObject](const auto*) {}));
747 }
748 return ret;
749 }
750
GetDistributedSessionControllersInner(const DistributedSessionType & sessionType,std::vector<sptr<IRemoteObject>> & sessionControllers)751 int32_t AVSessionServiceProxy::GetDistributedSessionControllersInner(const DistributedSessionType& sessionType,
752 std::vector<sptr<IRemoteObject>>& sessionControllers)
753 {
754 MessageParcel data;
755 CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERR_UNMARSHALLING,
756 "write interface token failed");
757 CHECK_AND_RETURN_RET_LOG(data.WriteInt32(sessionType), ERR_UNMARSHALLING, "write sessionType failed");
758
759 auto remote = Remote();
760 CHECK_AND_RETURN_RET_LOG(remote != nullptr, ERR_SERVICE_NOT_EXIST, "get remote service failed");
761 MessageParcel reply;
762 MessageOption option;
763 CHECK_AND_RETURN_RET_LOG(remote->SendRequest(static_cast<uint32_t>(
764 AvsessionSeviceInterfaceCode::SERVICE_CMD_GET_DISTRIBUTED_SESSION_CONTROLLERS), data, reply, option) == 0,
765 ERR_IPC_SEND_REQUEST, "send request failed");
766 int32_t ret = AVSESSION_ERROR;
767 CHECK_AND_RETURN_RET_LOG(reply.ReadInt32(ret), ERR_UNMARSHALLING, "read int32 failed");
768 CHECK_AND_RETURN_RET_LOG(ret != ERR_NO_PERMISSION, ret, "no permission");
769 CHECK_AND_RETURN_RET_LOG(ret != ERR_PERMISSION_DENIED, ret, "permission denied");
770 CHECK_AND_RETURN_RET_LOG(ret != ERR_REMOTE_CONNECTION_NOT_EXIST, ret, "connect not exist");
771 if (ret == AVSESSION_SUCCESS) {
772 uint32_t size {};
773 CHECK_AND_RETURN_RET_LOG(reply.ReadUint32(size), ERR_UNMARSHALLING, "read vector size failed");
774 CHECK_AND_RETURN_RET_LOG(size, ret, "get distributed controller with true empty");
775
776 std::vector<sptr<IRemoteObject>> controllerResult(size);
777 for (auto& controller : controllerResult) {
778 controller = reply.ReadRemoteObject();
779 CHECK_AND_RETURN_RET_LOG(controller, ERR_UNMARSHALLING, "read controller failed");
780 }
781 sessionControllers = controllerResult;
782 }
783 return ret;
784 }
785 } // namespace OHOS::AVSession
786