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     std::shared_ptr<AVSessionPixelMap> mediaPixelMap = std::make_shared<AVSessionPixelMap>();
143     SLOGI("change for-loop to vector init");
144     std::vector<uint8_t> mediaImageBuffer(buffer, buffer + mediaImageLength);
145     mediaPixelMap->SetInnerImgBuffer(mediaImageBuffer);
146     meta.SetMediaImage(mediaPixelMap);
147 
148     std::shared_ptr<AVSessionPixelMap> avQueuePixelMap = std::make_shared<AVSessionPixelMap>();
149     std::vector<uint8_t> avQueueImageBuffer(buffer + mediaImageLength, buffer + twoImageLength);
150     avQueuePixelMap->SetInnerImgBuffer(avQueueImageBuffer);
151     meta.SetAVQueueImage(avQueuePixelMap);
152 
153     return AVSESSION_SUCCESS;
154 }
155 
HandleSetAVMetaData(MessageParcel& data, MessageParcel& reply)156 int32_t AVSessionStub::HandleSetAVMetaData(MessageParcel& data, MessageParcel& reply)
157 {
158     AVSESSION_TRACE_SYNC_START("AVSessionStub::SetAVMetaData");
159     int twoImageLength = data.ReadInt32();
160     SLOGD("read length from twoImage %{public}d", twoImageLength);
161     if (twoImageLength <= 0 || twoImageLength > MAX_IMAGE_SIZE) {
162         sptr avMetaData = data.ReadParcelable<AVMetaData>();
163         if (avMetaData == nullptr) {
164             CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed");
165             return ERR_NONE;
166         }
167         int32_t ret = SetAVMetaData(*avMetaData);
168         CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed");
169         CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "SetAVMetaData failed");
170         return ERR_NONE;
171     }
172 
173     AVMetaData meta;
174     AVMetaData::UnmarshallingExceptImg(data, meta);
175     const char *buffer = nullptr;
176     buffer = reinterpret_cast<const char *>(data.ReadRawData(twoImageLength));
177     if (buffer == nullptr) {
178         SLOGI("read raw data with null, try set without length = %{public}d", twoImageLength);
179         int32_t ret = SetAVMetaData(meta);
180         CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed");
181         CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "SetAVMetaData failed");
182         return ERR_NONE;
183     }
184 
185     CHECK_AND_RETURN_RET_LOG(!SetImageData(meta, buffer, twoImageLength), ERR_NONE, "SetImageData fail");
186 
187     int32_t ret = SetAVMetaData(meta);
188     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed");
189     CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "SetAVMetaData failed");
190     return ERR_NONE;
191 }
192 
HandleSetLaunchAbility(MessageParcel& data, MessageParcel& reply)193 int32_t AVSessionStub::HandleSetLaunchAbility(MessageParcel& data, MessageParcel& reply)
194 {
195     sptr want = data.ReadParcelable<AbilityRuntime::WantAgent::WantAgent>();
196     if (want == nullptr) {
197         CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed");
198         return ERR_NONE;
199     }
200     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(SetLaunchAbility(*want)), ERR_NONE, "WriteInt32 result failed");
201     return ERR_NONE;
202 }
203 
HandleGetAVMetaData(MessageParcel& data, MessageParcel& reply)204 int32_t AVSessionStub::HandleGetAVMetaData(MessageParcel& data, MessageParcel& reply)
205 {
206     AVMetaData avMetaData;
207     reply.SetMaxCapacity(defaultIpcCapacity);
208     int32_t ret = GetAVMetaData(avMetaData);
209     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "write int32 failed");
210     CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "GetAVMetaData failed");
211     CHECK_AND_RETURN_RET_LOG(reply.WriteParcelable(&avMetaData), ERR_NONE, "write avMetaData failed");
212     SLOGI("clear media img after handle get metadata");
213     std::shared_ptr<AVSessionPixelMap> innerQueuePixelMap = avMetaData.GetAVQueueImage();
214     if (innerQueuePixelMap != nullptr) {
215         innerQueuePixelMap->Clear();
216     }
217     std::shared_ptr<AVSessionPixelMap> innerMediaPixelMap = avMetaData.GetMediaImage();
218     if (innerMediaPixelMap != nullptr) {
219         innerMediaPixelMap->Clear();
220     }
221     return ERR_NONE;
222 }
223 
HandleGetAVQueueItems(MessageParcel& data, MessageParcel& reply)224 int32_t AVSessionStub::HandleGetAVQueueItems(MessageParcel& data, MessageParcel& reply)
225 {
226     std::vector<AVQueueItem> avQueueItems;
227     int32_t ret = GetAVQueueItems(avQueueItems);
228     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "write int32 failed");
229     CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "GetAVQueueItems failed");
230     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(avQueueItems.size()), ERR_NONE, "write items num int32 failed");
231     for (auto &parcelable : avQueueItems) {
232         CHECK_AND_RETURN_RET_LOG(reply.WriteParcelable(&parcelable), ERR_NONE, "Write items failed");
233     }
234     return ERR_NONE;
235 }
236 
HandleSetAVQueueItems(MessageParcel& data, MessageParcel& reply)237 int32_t AVSessionStub::HandleSetAVQueueItems(MessageParcel& data, MessageParcel& reply)
238 {
239     AVSESSION_TRACE_SYNC_START("AVSessionStub::SetAVQueueItems");
240     int32_t maxQueueItemLength = 1000; // The maximum allowed playlist size is 1000
241     std::vector<AVQueueItem> items_;
242     int32_t itemNum = data.ReadInt32();
243     CHECK_AND_RETURN_RET_LOG((itemNum >= 0) && (itemNum < maxQueueItemLength),
244         ERR_UNMARSHALLING, "read int32 itemNum failed");
245     for (int32_t i = 0; i < itemNum; i++) {
246         AVQueueItem *item = data.ReadParcelable<AVQueueItem>();
247         CHECK_AND_RETURN_RET_LOG(item != nullptr, ERR_UNMARSHALLING, "read parcelable AVQueueItem failed");
248         if (item == nullptr) {
249             SLOGE("HandleSetAVQueueItems: read parcelable AVQueueItem failed");
250             delete item;
251             item = nullptr;
252             return ERR_UNMARSHALLING;
253         }
254         items_.emplace_back(*item);
255         delete item;
256         item = nullptr;
257     }
258     int32_t ret = SetAVQueueItems(items_);
259     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed");
260     CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "SetAVQueueItems failed");
261     return ERR_NONE;
262 }
263 
HandleGetAVQueueTitle(MessageParcel& data, MessageParcel& reply)264 int32_t AVSessionStub::HandleGetAVQueueTitle(MessageParcel& data, MessageParcel& reply)
265 {
266     std::string title;
267     int32_t ret = GetAVQueueTitle(title);
268     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "write int32 failed");
269     CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "GetAVQueueTitle failed");
270     CHECK_AND_RETURN_RET_LOG(reply.WriteString(title), ERR_NONE, "write title string failed");
271     return ERR_NONE;
272 }
273 
HandleSetAVQueueTitle(MessageParcel& data, MessageParcel& reply)274 int32_t AVSessionStub::HandleSetAVQueueTitle(MessageParcel& data, MessageParcel& reply)
275 {
276     AVSESSION_TRACE_SYNC_START("AVSessionStub::SetAVQueueTitle");
277     std::string title;
278     CHECK_AND_RETURN_RET_LOG(data.ReadString(title), ERR_NONE, "read title string failed");
279     int32_t ret = SetAVQueueTitle(title);
280     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed");
281     CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "SetAVQueueTitle failed");
282     return ERR_NONE;
283 }
284 
HandleGetExtras(MessageParcel& data, MessageParcel& reply)285 int32_t AVSessionStub::HandleGetExtras(MessageParcel& data, MessageParcel& reply)
286 {
287     AVSESSION_TRACE_SYNC_START("AVSessionStub::HandleGetExtras");
288     AAFwk::WantParams extras;
289     int32_t ret = GetExtras(extras);
290     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "write int32 failed");
291     CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "GetExtras failed");
292     CHECK_AND_RETURN_RET_LOG(reply.WriteParcelable(&extras), ERR_NONE, "write extras failed");
293     return ERR_NONE;
294 }
295 
HandleSetExtras(MessageParcel& data, MessageParcel& reply)296 int32_t AVSessionStub::HandleSetExtras(MessageParcel& data, MessageParcel& reply)
297 {
298     AVSESSION_TRACE_SYNC_START("AVSessionStub::HandleSetExtras");
299     sptr extrasWant = data.ReadParcelable<AAFwk::WantParams>();
300     if (extrasWant == nullptr) {
301         CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed");
302         return ERR_NONE;
303     }
304     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(SetExtras(*extrasWant)), ERR_NONE, "WriteInt32 result failed");
305     return ERR_NONE;
306 }
307 
HandleGetController(MessageParcel& data, MessageParcel& reply)308 int32_t AVSessionStub::HandleGetController(MessageParcel& data, MessageParcel& reply)
309 {
310     sptr<IRemoteObject> controller = GetControllerInner();
311     if (controller == nullptr) {
312         CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(AVSESSION_ERROR), ERR_NONE, "write int32 failed");
313         return ERR_NONE;
314     }
315     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(AVSESSION_SUCCESS), ERR_NONE, "write int32 failed");
316     CHECK_AND_RETURN_RET_LOG(reply.WriteRemoteObject(controller), ERR_NONE, "write object failed");
317     return ERR_NONE;
318 }
319 
320 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
HandleGetAVCastController(MessageParcel& data, MessageParcel& reply)321 int32_t AVSessionStub::HandleGetAVCastController(MessageParcel& data, MessageParcel& reply)
322 {
323     sptr<IRemoteObject> castController = GetAVCastControllerInner();
324     if (castController == nullptr) {
325         CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(AVSESSION_ERROR), ERR_NONE, "write int32 failed");
326         return ERR_NONE;
327     }
328     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(AVSESSION_SUCCESS), ERR_NONE, "write int32 failed");
329     CHECK_AND_RETURN_RET_LOG(reply.WriteRemoteObject(castController), ERR_NONE, "write object failed");
330     return ERR_NONE;
331 }
332 #endif
333 
HandleActivate(MessageParcel& data, MessageParcel& reply)334 int32_t AVSessionStub::HandleActivate(MessageParcel& data, MessageParcel& reply)
335 {
336     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(Activate()), ERR_NONE, "WriteInt32 failed");
337     return ERR_NONE;
338 }
339 
HandleDeactivate(MessageParcel& data, MessageParcel& reply)340 int32_t AVSessionStub::HandleDeactivate(MessageParcel& data, MessageParcel& reply)
341 {
342     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(Deactivate()), ERR_NONE, "WriteInt32 failed");
343     return ERR_NONE;
344 }
345 
HandleIsActive(MessageParcel& data, MessageParcel& reply)346 int32_t AVSessionStub::HandleIsActive(MessageParcel& data, MessageParcel& reply)
347 {
348     CHECK_AND_RETURN_RET_LOG(reply.WriteBool(IsActive()), ERR_NONE, "WriteBool failed");
349     return ERR_NONE;
350 }
351 
HandleAddSupportCommand(MessageParcel& data, MessageParcel& reply)352 int32_t AVSessionStub::HandleAddSupportCommand(MessageParcel& data, MessageParcel& reply)
353 {
354     int32_t ret = AddSupportCommand(data.ReadInt32());
355     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 failed");
356     CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "AddSupportCommand failed");
357     return ERR_NONE;
358 }
359 
HandleDeleteSupportCommand(MessageParcel& data, MessageParcel& reply)360 int32_t AVSessionStub::HandleDeleteSupportCommand(MessageParcel& data, MessageParcel& reply)
361 {
362     int32_t ret = DeleteSupportCommand(data.ReadInt32());
363     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 failed");
364     CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "DeleteSupportCommand failed");
365     return ERR_NONE;
366 }
367 
HandleSetSessionEvent(MessageParcel& data, MessageParcel& reply)368 int32_t AVSessionStub::HandleSetSessionEvent(MessageParcel& data, MessageParcel& reply)
369 {
370     auto event = data.ReadString();
371     sptr want = data.ReadParcelable<AAFwk::WantParams>();
372     if (want == nullptr) {
373         CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed");
374         return ERR_NONE;
375     }
376     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(SetSessionEvent(event, *want)), ERR_NONE, "WriteInt32 result failed");
377     return ERR_NONE;
378 }
379 
380 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
HandleReleaseCast(MessageParcel& data, MessageParcel& reply)381 int32_t AVSessionStub::HandleReleaseCast(MessageParcel& data, MessageParcel& reply)
382 {
383     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ReleaseCast()), ERR_NONE, "WriteInt32 failed");
384     return ERR_NONE;
385 }
386 
HandleStartCastDisplayListener(MessageParcel& data, MessageParcel& reply)387 int32_t AVSessionStub::HandleStartCastDisplayListener(MessageParcel& data, MessageParcel& reply)
388 {
389     int32_t ret = StartCastDisplayListener();
390     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 failed");
391     CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "StartCastDisplayListener failed");
392     return ERR_NONE;
393 }
394 
HandleStopCastDisplayListener(MessageParcel& data, MessageParcel& reply)395 int32_t AVSessionStub::HandleStopCastDisplayListener(MessageParcel& data, MessageParcel& reply)
396 {
397     int32_t ret = StopCastDisplayListener();
398     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 failed");
399     CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "StopCastDisplayListener failed");
400     return ERR_NONE;
401 }
402 
HandleGetAllCastDisplays(MessageParcel& data, MessageParcel& reply)403 int32_t AVSessionStub::HandleGetAllCastDisplays(MessageParcel& data, MessageParcel& reply)
404 {
405     std::vector<CastDisplayInfo> castDisplays;
406     int32_t ret = GetAllCastDisplays(castDisplays);
407     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 failed");
408     CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "GetAllCastDisplays failed");
409     CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(castDisplays.size()), ERR_NONE, "WriteInt32 failed");
410     for (auto &castDisplay : castDisplays) {
411         CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(static_cast<int32_t>(castDisplay.displayState)),
412             ERR_NONE, "Write displayState failed");
413         CHECK_AND_RETURN_RET_LOG(reply.WriteUint64(castDisplay.displayId), ERR_NONE, "Write displayId failed");
414         CHECK_AND_RETURN_RET_LOG(reply.WriteString(castDisplay.name), ERR_NONE, "Write name failed");
415         CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(castDisplay.width), ERR_NONE, "Write width failed");
416         CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(castDisplay.height), ERR_NONE, "Write height failed");
417     }
418     return ERR_NONE;
419 }
420 #endif
421 } // namespace OHOS::AVSession
422