1 /*
2 * Copyright (c) 2022-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
16 #include "avsession_stub.h"
17 #include "avsession_callback_proxy.h"
18 #include "avsession_trace.h"
19 #include "session_xcollie.h"
20
21 namespace OHOS::AVSession {
CheckInterfaceToken(MessageParcel & data)22 bool AVSessionStub::CheckInterfaceToken(MessageParcel& data)
23 {
24 auto localDescriptor = IAVSession::GetDescriptor();
25 auto remoteDescriptor = data.ReadInterfaceToken();
26 if (remoteDescriptor != localDescriptor) {
27 SLOGI("interface token is not equal");
28 return false;
29 }
30 return true;
31 }
32
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)33 int32_t AVSessionStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
34 {
35 if (code >= static_cast<uint32_t>(IAVSession::SESSION_CMD_GET_SESSION_ID)
36 && code < static_cast<uint32_t>(IAVSession::SESSION_CMD_MAX)) {
37 SessionXCollie sessionXCollie(mapCodeToFuncNameXCollie[code]);
38 }
39 if (!CheckInterfaceToken(data)) {
40 return AVSESSION_ERROR;
41 }
42 SLOGI("cmd code is %{public}d", code);
43 if (code >= static_cast<uint32_t>(IAVSession::SESSION_CMD_GET_SESSION_ID)
44 && code < static_cast<uint32_t>(IAVSession::SESSION_CMD_MAX)) {
45 return handlers[code](data, reply);
46 }
47 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
48 }
49
HandleGetSessionId(MessageParcel & data,MessageParcel & reply)50 int32_t AVSessionStub::HandleGetSessionId(MessageParcel& data, MessageParcel& reply)
51 {
52 CHECK_AND_PRINT_LOG(reply.WriteString(GetSessionId()), "write int32_t failed");
53 return ERR_NONE;
54 }
55
HandleGetSessionType(MessageParcel & data,MessageParcel & reply)56 int32_t AVSessionStub::HandleGetSessionType(MessageParcel& data, MessageParcel& reply)
57 {
58 CHECK_AND_PRINT_LOG(reply.WriteString(GetSessionType()), "write int32_t failed");
59 return ERR_NONE;
60 }
61
HandleRegisterCallbackInner(MessageParcel & data,MessageParcel & reply)62 int32_t AVSessionStub::HandleRegisterCallbackInner(MessageParcel& data, MessageParcel& reply)
63 {
64 auto remoteObject = data.ReadRemoteObject();
65 if (remoteObject == nullptr) {
66 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "write int32_t failed");
67 return ERR_NONE;
68 }
69 auto callback = iface_cast<AVSessionCallbackProxy>(remoteObject);
70 CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERR_NONE, "callback is nullptr");
71 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(RegisterCallbackInner(callback)),
72 ERR_NONE, "write int32_t failed");
73 return ERR_NONE;
74 }
75
HandleDestroy(MessageParcel & data,MessageParcel & reply)76 int32_t AVSessionStub::HandleDestroy(MessageParcel& data, MessageParcel& reply)
77 {
78 int32_t ret = Destroy();
79 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(AVSESSION_SUCCESS), ERR_NONE, "write int32_t failed");
80 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "Destroy failed");
81 return ERR_NONE;
82 }
83
HandleSetAVCallMetaData(MessageParcel & data,MessageParcel & reply)84 int32_t AVSessionStub::HandleSetAVCallMetaData(MessageParcel& data, MessageParcel& reply)
85 {
86 AVSESSION_TRACE_SYNC_START("AVSessionStub::SetAVCallMetaData");
87 sptr avCallMetaData = data.ReadParcelable<AVCallMetaData>();
88 if (avCallMetaData == nullptr) {
89 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed");
90 return ERR_NONE;
91 }
92 int32_t ret = SetAVCallMetaData(*avCallMetaData);
93 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed");
94 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "GetAVCallMetaData failed");
95 return ERR_NONE;
96 }
97
HandleSetAVCallState(MessageParcel & data,MessageParcel & reply)98 int32_t AVSessionStub::HandleSetAVCallState(MessageParcel& data, MessageParcel& reply)
99 {
100 AVSESSION_TRACE_SYNC_START("AVSessionStub::SetAVCallState");
101 sptr avCallState = data.ReadParcelable<AVCallState>();
102 if (avCallState == nullptr) {
103 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed");
104 return ERR_NONE;
105 }
106 int32_t ret = SetAVCallState(*avCallState);
107 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed");
108 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "GetAVCallState failed");
109 return ERR_NONE;
110 }
111
HandleGetAVPlaybackState(MessageParcel & data,MessageParcel & reply)112 int32_t AVSessionStub::HandleGetAVPlaybackState(MessageParcel& data, MessageParcel& reply)
113 {
114 AVPlaybackState avPlaybackState;
115 int32_t ret = GetAVPlaybackState(avPlaybackState);
116 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "write int32 failed");
117 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "GetAVPlaybackState failed");
118 CHECK_AND_RETURN_RET_LOG(reply.WriteParcelable(&avPlaybackState), ERR_NONE, "write avPlaybackState failed");
119 return ERR_NONE;
120 }
121
HandleSetAVPlaybackState(MessageParcel & data,MessageParcel & reply)122 int32_t AVSessionStub::HandleSetAVPlaybackState(MessageParcel& data, MessageParcel& reply)
123 {
124 AVSESSION_TRACE_SYNC_START("AVSessionStub::SetAVPlaybackState");
125 sptr avPlaybackState = data.ReadParcelable<AVPlaybackState>();
126 if (avPlaybackState == nullptr) {
127 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed");
128 return ERR_NONE;
129 }
130 int32_t ret = SetAVPlaybackState(*avPlaybackState);
131 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed");
132 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "GetAVPlaybackState failed");
133 return ERR_NONE;
134 }
135
SetImageData(AVMetaData & meta,const char * buffer,int twoImageLength)136 int32_t AVSessionStub::SetImageData(AVMetaData& meta, const char *buffer, int twoImageLength)
137 {
138 int mediaImageLength = meta.GetMediaLength();
139 CHECK_AND_RETURN_RET_LOG(mediaImageLength >= 0, ERR_NONE, "mediaImageLength is negative number");
140 CHECK_AND_RETURN_RET_LOG(mediaImageLength <= twoImageLength, ERR_NONE, "Maybe cuase Out-of-bunds read");
141
142 auto mediaPixelMap = new (std::nothrow) AVSessionPixelMap();
143 CHECK_AND_RETURN_RET_LOG(mediaPixelMap != nullptr, ERR_NONE, "mediaPixelMap malloc fail");
144 SLOGI("change for-loop to vector init");
145 std::vector<uint8_t> mediaImageBuffer(buffer, buffer + mediaImageLength);
146 mediaPixelMap->SetInnerImgBuffer(mediaImageBuffer);
147 meta.SetMediaImage(std::shared_ptr<AVSessionPixelMap>(mediaPixelMap));
148 mediaPixelMap = nullptr;
149 delete mediaPixelMap;
150
151 auto avQueuePixelMap = new (std::nothrow) AVSessionPixelMap();
152 CHECK_AND_RETURN_RET_LOG(avQueuePixelMap != nullptr, ERR_NONE, "avQueuePixelMap malloc fail");
153 std::vector<uint8_t> avQueueImageBuffer(buffer + mediaImageLength, buffer + twoImageLength);
154 avQueuePixelMap->SetInnerImgBuffer(avQueueImageBuffer);
155 meta.SetAVQueueImage(std::shared_ptr<AVSessionPixelMap>(avQueuePixelMap));
156 avQueuePixelMap = nullptr;
157 delete avQueuePixelMap;
158
159 return AVSESSION_SUCCESS;
160 }
161
HandleSetAVMetaData(MessageParcel & data,MessageParcel & reply)162 int32_t AVSessionStub::HandleSetAVMetaData(MessageParcel& data, MessageParcel& reply)
163 {
164 AVSESSION_TRACE_SYNC_START("AVSessionStub::SetAVMetaData");
165 int twoImageLength = data.ReadInt32();
166 SLOGD("read length from twoImage %{public}d", twoImageLength);
167 if (twoImageLength <= 0 || twoImageLength > MAX_IMAGE_SIZE) {
168 sptr avMetaData = data.ReadParcelable<AVMetaData>();
169 if (avMetaData == nullptr) {
170 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed");
171 return ERR_NONE;
172 }
173 int32_t ret = SetAVMetaData(*avMetaData);
174 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed");
175 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "SetAVMetaData failed");
176 return ERR_NONE;
177 }
178
179 AVMetaData meta;
180 AVMetaData::UnmarshallingExceptImg(data, meta);
181 const char *buffer = nullptr;
182 buffer = reinterpret_cast<const char *>(data.ReadRawData(twoImageLength));
183 if (buffer == nullptr) {
184 SLOGI("read raw data with null, try set without length = %{public}d", twoImageLength);
185 int32_t ret = SetAVMetaData(meta);
186 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed");
187 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "SetAVMetaData failed");
188 return ERR_NONE;
189 }
190
191 CHECK_AND_RETURN_RET_LOG(!SetImageData(meta, buffer, twoImageLength), ERR_NONE, "SetImageData fail");
192
193 int32_t ret = SetAVMetaData(meta);
194 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed");
195 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "SetAVMetaData failed");
196 return ERR_NONE;
197 }
198
HandleSetLaunchAbility(MessageParcel & data,MessageParcel & reply)199 int32_t AVSessionStub::HandleSetLaunchAbility(MessageParcel& data, MessageParcel& reply)
200 {
201 sptr want = data.ReadParcelable<AbilityRuntime::WantAgent::WantAgent>();
202 if (want == nullptr) {
203 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed");
204 return ERR_NONE;
205 }
206 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(SetLaunchAbility(*want)), ERR_NONE, "WriteInt32 result failed");
207 return ERR_NONE;
208 }
209
HandleGetAVMetaData(MessageParcel & data,MessageParcel & reply)210 int32_t AVSessionStub::HandleGetAVMetaData(MessageParcel& data, MessageParcel& reply)
211 {
212 AVMetaData avMetaData;
213 reply.SetMaxCapacity(defaultIpcCapacity);
214 int32_t ret = GetAVMetaData(avMetaData);
215 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "write int32 failed");
216 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "GetAVMetaData failed");
217 CHECK_AND_RETURN_RET_LOG(reply.WriteParcelable(&avMetaData), ERR_NONE, "write avMetaData failed");
218 SLOGI("clear media img after handle get metadata");
219 std::shared_ptr<AVSessionPixelMap> innerQueuePixelMap = avMetaData.GetAVQueueImage();
220 if (innerQueuePixelMap != nullptr) {
221 innerQueuePixelMap->Clear();
222 }
223 std::shared_ptr<AVSessionPixelMap> innerMediaPixelMap = avMetaData.GetMediaImage();
224 if (innerMediaPixelMap != nullptr) {
225 innerMediaPixelMap->Clear();
226 }
227 return ERR_NONE;
228 }
229
HandleGetAVQueueItems(MessageParcel & data,MessageParcel & reply)230 int32_t AVSessionStub::HandleGetAVQueueItems(MessageParcel& data, MessageParcel& reply)
231 {
232 std::vector<AVQueueItem> avQueueItems;
233 int32_t ret = GetAVQueueItems(avQueueItems);
234 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "write int32 failed");
235 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "GetAVQueueItems failed");
236 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(avQueueItems.size()), ERR_NONE, "write items num int32 failed");
237 for (auto &parcelable : avQueueItems) {
238 CHECK_AND_RETURN_RET_LOG(reply.WriteParcelable(&parcelable), ERR_NONE, "Write items failed");
239 }
240 return ERR_NONE;
241 }
242
HandleSetAVQueueItems(MessageParcel & data,MessageParcel & reply)243 int32_t AVSessionStub::HandleSetAVQueueItems(MessageParcel& data, MessageParcel& reply)
244 {
245 AVSESSION_TRACE_SYNC_START("AVSessionStub::SetAVQueueItems");
246 int32_t maxQueueItemLength = 1000; // The maximum allowed playlist size is 1000
247 std::vector<AVQueueItem> items_;
248 int32_t itemNum = data.ReadInt32();
249 CHECK_AND_RETURN_RET_LOG((itemNum >= 0) && (itemNum < maxQueueItemLength),
250 ERR_UNMARSHALLING, "read int32 itemNum failed");
251 for (int32_t i = 0; i < itemNum; i++) {
252 AVQueueItem *item = data.ReadParcelable<AVQueueItem>();
253 CHECK_AND_RETURN_RET_LOG(item != nullptr, ERR_UNMARSHALLING, "read parcelable AVQueueItem failed");
254 if (item == nullptr) {
255 SLOGE("HandleSetAVQueueItems: read parcelable AVQueueItem failed");
256 delete item;
257 return ERR_UNMARSHALLING;
258 }
259 items_.emplace_back(*item);
260 delete item;
261 }
262 int32_t ret = SetAVQueueItems(items_);
263 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed");
264 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "SetAVQueueItems failed");
265 return ERR_NONE;
266 }
267
HandleGetAVQueueTitle(MessageParcel & data,MessageParcel & reply)268 int32_t AVSessionStub::HandleGetAVQueueTitle(MessageParcel& data, MessageParcel& reply)
269 {
270 std::string title;
271 int32_t ret = GetAVQueueTitle(title);
272 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "write int32 failed");
273 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "GetAVQueueTitle failed");
274 CHECK_AND_RETURN_RET_LOG(reply.WriteString(title), ERR_NONE, "write title string failed");
275 return ERR_NONE;
276 }
277
HandleSetAVQueueTitle(MessageParcel & data,MessageParcel & reply)278 int32_t AVSessionStub::HandleSetAVQueueTitle(MessageParcel& data, MessageParcel& reply)
279 {
280 AVSESSION_TRACE_SYNC_START("AVSessionStub::SetAVQueueTitle");
281 std::string title;
282 CHECK_AND_RETURN_RET_LOG(data.ReadString(title), ERR_NONE, "read title string failed");
283 int32_t ret = SetAVQueueTitle(title);
284 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed");
285 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "SetAVQueueTitle failed");
286 return ERR_NONE;
287 }
288
HandleGetExtras(MessageParcel & data,MessageParcel & reply)289 int32_t AVSessionStub::HandleGetExtras(MessageParcel& data, MessageParcel& reply)
290 {
291 AVSESSION_TRACE_SYNC_START("AVSessionStub::HandleGetExtras");
292 AAFwk::WantParams extras;
293 int32_t ret = GetExtras(extras);
294 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "write int32 failed");
295 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "GetExtras failed");
296 CHECK_AND_RETURN_RET_LOG(reply.WriteParcelable(&extras), ERR_NONE, "write extras failed");
297 return ERR_NONE;
298 }
299
HandleSetExtras(MessageParcel & data,MessageParcel & reply)300 int32_t AVSessionStub::HandleSetExtras(MessageParcel& data, MessageParcel& reply)
301 {
302 AVSESSION_TRACE_SYNC_START("AVSessionStub::HandleSetExtras");
303 sptr extrasWant = data.ReadParcelable<AAFwk::WantParams>();
304 if (extrasWant == nullptr) {
305 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed");
306 return ERR_NONE;
307 }
308 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(SetExtras(*extrasWant)), ERR_NONE, "WriteInt32 result failed");
309 return ERR_NONE;
310 }
311
HandleGetController(MessageParcel & data,MessageParcel & reply)312 int32_t AVSessionStub::HandleGetController(MessageParcel& data, MessageParcel& reply)
313 {
314 sptr<IRemoteObject> controller = GetControllerInner();
315 if (controller == nullptr) {
316 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(AVSESSION_ERROR), ERR_NONE, "write int32 failed");
317 return ERR_NONE;
318 }
319 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(AVSESSION_SUCCESS), ERR_NONE, "write int32 failed");
320 CHECK_AND_RETURN_RET_LOG(reply.WriteRemoteObject(controller), ERR_NONE, "write object failed");
321 return ERR_NONE;
322 }
323
324 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
HandleGetAVCastController(MessageParcel & data,MessageParcel & reply)325 int32_t AVSessionStub::HandleGetAVCastController(MessageParcel& data, MessageParcel& reply)
326 {
327 sptr<IRemoteObject> castController = GetAVCastControllerInner();
328 if (castController == nullptr) {
329 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(AVSESSION_ERROR), ERR_NONE, "write int32 failed");
330 return ERR_NONE;
331 }
332 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(AVSESSION_SUCCESS), ERR_NONE, "write int32 failed");
333 CHECK_AND_RETURN_RET_LOG(reply.WriteRemoteObject(castController), ERR_NONE, "write object failed");
334 return ERR_NONE;
335 }
336 #endif
337
HandleActivate(MessageParcel & data,MessageParcel & reply)338 int32_t AVSessionStub::HandleActivate(MessageParcel& data, MessageParcel& reply)
339 {
340 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(Activate()), ERR_NONE, "WriteInt32 failed");
341 return ERR_NONE;
342 }
343
HandleDeactivate(MessageParcel & data,MessageParcel & reply)344 int32_t AVSessionStub::HandleDeactivate(MessageParcel& data, MessageParcel& reply)
345 {
346 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(Deactivate()), ERR_NONE, "WriteInt32 failed");
347 return ERR_NONE;
348 }
349
HandleIsActive(MessageParcel & data,MessageParcel & reply)350 int32_t AVSessionStub::HandleIsActive(MessageParcel& data, MessageParcel& reply)
351 {
352 CHECK_AND_RETURN_RET_LOG(reply.WriteBool(IsActive()), ERR_NONE, "WriteBool failed");
353 return ERR_NONE;
354 }
355
HandleAddSupportCommand(MessageParcel & data,MessageParcel & reply)356 int32_t AVSessionStub::HandleAddSupportCommand(MessageParcel& data, MessageParcel& reply)
357 {
358 int32_t ret = AddSupportCommand(data.ReadInt32());
359 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 failed");
360 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "AddSupportCommand failed");
361 return ERR_NONE;
362 }
363
HandleDeleteSupportCommand(MessageParcel & data,MessageParcel & reply)364 int32_t AVSessionStub::HandleDeleteSupportCommand(MessageParcel& data, MessageParcel& reply)
365 {
366 int32_t ret = DeleteSupportCommand(data.ReadInt32());
367 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 failed");
368 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "DeleteSupportCommand failed");
369 return ERR_NONE;
370 }
371
HandleSetSessionEvent(MessageParcel & data,MessageParcel & reply)372 int32_t AVSessionStub::HandleSetSessionEvent(MessageParcel& data, MessageParcel& reply)
373 {
374 auto event = data.ReadString();
375 sptr want = data.ReadParcelable<AAFwk::WantParams>();
376 if (want == nullptr) {
377 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed");
378 return ERR_NONE;
379 }
380 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(SetSessionEvent(event, *want)), ERR_NONE, "WriteInt32 result failed");
381 return ERR_NONE;
382 }
383
384 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
HandleReleaseCast(MessageParcel & data,MessageParcel & reply)385 int32_t AVSessionStub::HandleReleaseCast(MessageParcel& data, MessageParcel& reply)
386 {
387 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ReleaseCast()), ERR_NONE, "WriteInt32 failed");
388 return ERR_NONE;
389 }
390
HandleStartCastDisplayListener(MessageParcel & data,MessageParcel & reply)391 int32_t AVSessionStub::HandleStartCastDisplayListener(MessageParcel& data, MessageParcel& reply)
392 {
393 int32_t ret = StartCastDisplayListener();
394 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 failed");
395 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "StartCastDisplayListener failed");
396 return ERR_NONE;
397 }
398
HandleStopCastDisplayListener(MessageParcel & data,MessageParcel & reply)399 int32_t AVSessionStub::HandleStopCastDisplayListener(MessageParcel& data, MessageParcel& reply)
400 {
401 int32_t ret = StopCastDisplayListener();
402 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 failed");
403 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "StopCastDisplayListener failed");
404 return ERR_NONE;
405 }
406
HandleGetAllCastDisplays(MessageParcel & data,MessageParcel & reply)407 int32_t AVSessionStub::HandleGetAllCastDisplays(MessageParcel& data, MessageParcel& reply)
408 {
409 std::vector<CastDisplayInfo> castDisplays;
410 int32_t ret = GetAllCastDisplays(castDisplays);
411 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 failed");
412 CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "GetAllCastDisplays failed");
413 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(castDisplays.size()), ERR_NONE, "WriteInt32 failed");
414 for (auto &castDisplay : castDisplays) {
415 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(static_cast<int32_t>(castDisplay.displayState)),
416 ERR_NONE, "Write displayState failed");
417 CHECK_AND_RETURN_RET_LOG(reply.WriteUint64(castDisplay.displayId), ERR_NONE, "Write displayId failed");
418 CHECK_AND_RETURN_RET_LOG(reply.WriteString(castDisplay.name), ERR_NONE, "Write name failed");
419 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(castDisplay.width), ERR_NONE, "Write width failed");
420 CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(castDisplay.height), ERR_NONE, "Write height failed");
421 }
422 return ERR_NONE;
423 }
424 #endif
425 } // namespace OHOS::AVSession
426