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