1 /*
2 * Copyright (c) 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 "drag_params.h"
17
18 #include "devicestatus_define.h"
19 #include "drag_data_packer.h"
20 #include "preview_style_packer.h"
21
22 #undef LOG_TAG
23 #define LOG_TAG "DragParams"
24
25 namespace OHOS {
26 namespace Msdp {
27 namespace DeviceStatus {
28
StartDragParam(DragData & dragData)29 StartDragParam::StartDragParam(DragData &dragData)
30 {
31 dragDataPtr_ = &dragData;
32 }
33
StartDragParam(const DragData & dragData)34 StartDragParam::StartDragParam(const DragData &dragData)
35 {
36 cDragDataPtr_ = &dragData;
37 }
38
Marshalling(MessageParcel & parcel) const39 bool StartDragParam::Marshalling(MessageParcel &parcel) const
40 {
41 return (
42 (cDragDataPtr_ != nullptr) &&
43 (DragDataPacker::Marshalling(*cDragDataPtr_, parcel) == RET_OK)
44 );
45 }
46
Unmarshalling(MessageParcel & parcel)47 bool StartDragParam::Unmarshalling(MessageParcel &parcel)
48 {
49 return (
50 (dragDataPtr_ != nullptr) &&
51 (DragDataPacker::UnMarshalling(parcel, *dragDataPtr_) == RET_OK)
52 );
53 }
54
StopDragParam(const DragDropResult & dropResult)55 StopDragParam::StopDragParam(const DragDropResult &dropResult)
56 : dropResult_(dropResult)
57 {}
58
Marshalling(MessageParcel & parcel) const59 bool StopDragParam::Marshalling(MessageParcel &parcel) const
60 {
61 return (
62 parcel.WriteInt32(static_cast<int32_t>(dropResult_.result)) &&
63 parcel.WriteInt32(dropResult_.mainWindow) &&
64 parcel.WriteBool(dropResult_.hasCustomAnimation) &&
65 parcel.WriteInt32(static_cast<int32_t>(dropResult_.dragBehavior))
66 );
67 }
68
Unmarshalling(MessageParcel & parcel)69 bool StopDragParam::Unmarshalling(MessageParcel &parcel)
70 {
71 int32_t result { -1 };
72 if (!parcel.ReadInt32(result) ||
73 (result < static_cast<int32_t>(DragResult::DRAG_SUCCESS)) ||
74 (result > static_cast<int32_t>(DragResult::DRAG_EXCEPTION))) {
75 return false;
76 }
77 dropResult_.result = static_cast<DragResult>(result);
78 if (!parcel.ReadInt32(dropResult_.mainWindow) || !parcel.ReadBool(dropResult_.hasCustomAnimation)) {
79 return false;
80 }
81 int32_t dragBehavior { -1 };
82 if (!parcel.ReadInt32(dragBehavior) ||
83 (dragBehavior < static_cast<int32_t>(DragBehavior::UNKNOWN)) ||
84 (dragBehavior > static_cast<int32_t>(DragBehavior::MOVE))) {
85 return false;
86 }
87 dropResult_.dragBehavior = static_cast<DragBehavior>(dragBehavior);
88 return true;
89 }
90
SetDragWindowVisibleParam(bool visible,bool isForce)91 SetDragWindowVisibleParam::SetDragWindowVisibleParam(bool visible, bool isForce)
92 : visible_(visible), isForce_(isForce)
93 {}
94
Marshalling(MessageParcel & parcel) const95 bool SetDragWindowVisibleParam::Marshalling(MessageParcel &parcel) const
96 {
97 return (parcel.WriteBool(visible_) &&
98 parcel.WriteBool(isForce_));
99 }
100
Unmarshalling(MessageParcel & parcel)101 bool SetDragWindowVisibleParam::Unmarshalling(MessageParcel &parcel)
102 {
103 return (parcel.ReadBool(visible_) &&
104 parcel.ReadBool(isForce_));
105 }
106
UpdateDragStyleParam(DragCursorStyle style,int32_t eventId)107 UpdateDragStyleParam::UpdateDragStyleParam(DragCursorStyle style, int32_t eventId)
108 : cursorStyle_(style), eventId_(eventId)
109 {}
110
Marshalling(MessageParcel & parcel) const111 bool UpdateDragStyleParam::Marshalling(MessageParcel &parcel) const
112 {
113 return (parcel.WriteInt32(static_cast<int32_t>(cursorStyle_)) &&
114 parcel.WriteInt32(eventId_));
115 }
116
Unmarshalling(MessageParcel & parcel)117 bool UpdateDragStyleParam::Unmarshalling(MessageParcel &parcel)
118 {
119 int32_t style { -1 };
120 if (!parcel.ReadInt32(style) ||
121 (style < static_cast<int32_t>(DragCursorStyle::DEFAULT)) ||
122 (style > static_cast<int32_t>(DragCursorStyle::MOVE))) {
123 return false;
124 }
125 cursorStyle_ = static_cast<DragCursorStyle>(style);
126 return parcel.ReadInt32(eventId_);
127 }
128
UpdateShadowPicParam(const ShadowInfo & shadowInfo)129 UpdateShadowPicParam::UpdateShadowPicParam(const ShadowInfo &shadowInfo)
130 : shadowInfo_(shadowInfo)
131 {}
132
Marshalling(MessageParcel & parcel) const133 bool UpdateShadowPicParam::Marshalling(MessageParcel &parcel) const
134 {
135 return (
136 (shadowInfo_.pixelMap != nullptr) &&
137 shadowInfo_.pixelMap->Marshalling(parcel) &&
138 parcel.WriteInt32(shadowInfo_.x) &&
139 parcel.WriteInt32(shadowInfo_.y)
140 );
141 }
142
Unmarshalling(MessageParcel & parcel)143 bool UpdateShadowPicParam::Unmarshalling(MessageParcel &parcel)
144 {
145 shadowInfo_.pixelMap = std::shared_ptr<Media::PixelMap>(Media::PixelMap::Unmarshalling(parcel));
146 return (
147 (shadowInfo_.pixelMap != nullptr) &&
148 parcel.ReadInt32(shadowInfo_.x) &&
149 parcel.ReadInt32(shadowInfo_.y)
150 );
151 }
152
GetDragTargetPidReply(int32_t pid)153 GetDragTargetPidReply::GetDragTargetPidReply(int32_t pid)
154 : targetPid_(pid)
155 {}
156
Marshalling(MessageParcel & parcel) const157 bool GetDragTargetPidReply::Marshalling(MessageParcel &parcel) const
158 {
159 return parcel.WriteInt32(targetPid_);
160 }
161
Unmarshalling(MessageParcel & parcel)162 bool GetDragTargetPidReply::Unmarshalling(MessageParcel &parcel)
163 {
164 return parcel.ReadInt32(targetPid_);
165 }
166
GetUdKeyReply(std::string && udKey)167 GetUdKeyReply::GetUdKeyReply(std::string &&udKey)
168 : udKey_(std::move(udKey))
169 {}
170
Marshalling(MessageParcel & parcel) const171 bool GetUdKeyReply::Marshalling(MessageParcel &parcel) const
172 {
173 return parcel.WriteString(udKey_);
174 }
175
Unmarshalling(MessageParcel & parcel)176 bool GetUdKeyReply::Unmarshalling(MessageParcel &parcel)
177 {
178 return parcel.ReadString(udKey_);
179 }
180
GetShadowOffsetReply(const ShadowOffset & shadowOffset)181 GetShadowOffsetReply::GetShadowOffsetReply(const ShadowOffset &shadowOffset)
182 : shadowOffset_(shadowOffset)
183 {}
184
Marshalling(MessageParcel & parcel) const185 bool GetShadowOffsetReply::Marshalling(MessageParcel &parcel) const
186 {
187 return (
188 parcel.WriteInt32(shadowOffset_.offsetX) &&
189 parcel.WriteInt32(shadowOffset_.offsetY) &&
190 parcel.WriteInt32(shadowOffset_.width) &&
191 parcel.WriteInt32(shadowOffset_.height)
192 );
193 }
194
Unmarshalling(MessageParcel & parcel)195 bool GetShadowOffsetReply::Unmarshalling(MessageParcel &parcel)
196 {
197 return (
198 parcel.ReadInt32(shadowOffset_.offsetX) &&
199 parcel.ReadInt32(shadowOffset_.offsetY) &&
200 parcel.ReadInt32(shadowOffset_.width) &&
201 parcel.ReadInt32(shadowOffset_.height)
202 );
203 }
204
UpdatePreviewStyleParam(const PreviewStyle & previewStyle)205 UpdatePreviewStyleParam::UpdatePreviewStyleParam(const PreviewStyle &previewStyle)
206 : previewStyle_(previewStyle)
207 {}
208
Marshalling(MessageParcel & parcel) const209 bool UpdatePreviewStyleParam::Marshalling(MessageParcel &parcel) const
210 {
211 return (PreviewStylePacker::Marshalling(previewStyle_, parcel) == RET_OK);
212 }
213
Unmarshalling(MessageParcel & parcel)214 bool UpdatePreviewStyleParam::Unmarshalling(MessageParcel &parcel)
215 {
216 return (PreviewStylePacker::UnMarshalling(parcel, previewStyle_) == RET_OK);
217 }
218
UpdatePreviewAnimationParam(const PreviewStyle & previewStyle,const PreviewAnimation & animation)219 UpdatePreviewAnimationParam::UpdatePreviewAnimationParam(
220 const PreviewStyle &previewStyle, const PreviewAnimation &animation)
221 : previewStyle_(previewStyle), previewAnimation_(animation)
222 {}
223
Marshalling(MessageParcel & parcel) const224 bool UpdatePreviewAnimationParam::Marshalling(MessageParcel &parcel) const
225 {
226 return (
227 (PreviewStylePacker::Marshalling(previewStyle_, parcel) == RET_OK) &&
228 (PreviewAnimationPacker::Marshalling(previewAnimation_, parcel) == RET_OK)
229 );
230 }
231
Unmarshalling(MessageParcel & parcel)232 bool UpdatePreviewAnimationParam::Unmarshalling(MessageParcel &parcel)
233 {
234 return (
235 (PreviewStylePacker::UnMarshalling(parcel, previewStyle_) == RET_OK) &&
236 (PreviewAnimationPacker::UnMarshalling(parcel, previewAnimation_) == RET_OK)
237 );
238 }
239
RotateDragWindowSyncParam(const std::shared_ptr<Rosen::RSTransaction> & rsTransaction)240 RotateDragWindowSyncParam::RotateDragWindowSyncParam(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction)
241 : rsTransaction_(rsTransaction)
242 {}
243
Marshalling(MessageParcel & parcel) const244 bool RotateDragWindowSyncParam::Marshalling(MessageParcel &parcel) const
245 {
246 if (rsTransaction_ == nullptr) {
247 FI_HILOGE("rsTransaction_ is nullptr");
248 return false;
249 }
250 if (!parcel.WriteParcelable(rsTransaction_.get())) {
251 FI_HILOGE("Write transaction sync id failed");
252 return false;
253 }
254 return true;
255 }
256
Unmarshalling(MessageParcel & parcel)257 bool RotateDragWindowSyncParam::Unmarshalling(MessageParcel &parcel)
258 {
259 std::shared_ptr<Rosen::RSTransaction> rsTransaction(parcel.ReadParcelable<Rosen::RSTransaction>());
260 if (rsTransaction == nullptr) {
261 FI_HILOGE("UnMarshalling rsTransaction failed");
262 return false;
263 }
264 rsTransaction_ = rsTransaction;
265 return true;
266 }
267
SetDragWindowScreenIdParam(uint64_t displayId,uint64_t screenId)268 SetDragWindowScreenIdParam::SetDragWindowScreenIdParam(uint64_t displayId, uint64_t screenId)
269 : displayId_(displayId), screenId_(screenId)
270 {}
271
Marshalling(MessageParcel & parcel) const272 bool SetDragWindowScreenIdParam::Marshalling(MessageParcel &parcel) const
273 {
274 return (parcel.WriteUint64(displayId_) && parcel.WriteUint64(screenId_));
275 }
276
Unmarshalling(MessageParcel & parcel)277 bool SetDragWindowScreenIdParam::Unmarshalling(MessageParcel &parcel)
278 {
279 return (parcel.ReadUint64(displayId_) && parcel.ReadUint64(screenId_));
280 }
281
AddDraglistenerParam(bool isJsCaller)282 AddDraglistenerParam::AddDraglistenerParam(bool isJsCaller)
283 : isJsCaller_(isJsCaller)
284 {}
285
Marshalling(MessageParcel & parcel) const286 bool AddDraglistenerParam::Marshalling(MessageParcel &parcel) const
287 {
288 return parcel.WriteBool(isJsCaller_);
289 }
290
Unmarshalling(MessageParcel & parcel)291 bool AddDraglistenerParam::Unmarshalling(MessageParcel &parcel)
292 {
293 return parcel.ReadBool(isJsCaller_);
294 }
295
RemoveDraglistenerParam(bool isJsCaller)296 RemoveDraglistenerParam::RemoveDraglistenerParam(bool isJsCaller)
297 : isJsCaller_(isJsCaller)
298 {}
299
Marshalling(MessageParcel & parcel) const300 bool RemoveDraglistenerParam::Marshalling(MessageParcel &parcel) const
301 {
302 return parcel.WriteBool(isJsCaller_);
303 }
304
Unmarshalling(MessageParcel & parcel)305 bool RemoveDraglistenerParam::Unmarshalling(MessageParcel &parcel)
306 {
307 return parcel.ReadBool(isJsCaller_);
308 }
309
GetDragSummaryParam(bool isJsCaller)310 GetDragSummaryParam::GetDragSummaryParam(bool isJsCaller)
311 : isJsCaller_(isJsCaller)
312 {}
313
Marshalling(MessageParcel & parcel) const314 bool GetDragSummaryParam::Marshalling(MessageParcel &parcel) const
315 {
316 return parcel.WriteBool(isJsCaller_);
317 }
318
Unmarshalling(MessageParcel & parcel)319 bool GetDragSummaryParam::Unmarshalling(MessageParcel &parcel)
320 {
321 return parcel.ReadBool(isJsCaller_);
322 }
323
GetDragSummaryReply(std::map<std::string,int64_t> && summary)324 GetDragSummaryReply::GetDragSummaryReply(std::map<std::string, int64_t> &&summary)
325 : summary_(std::move(summary))
326 {}
327
Marshalling(MessageParcel & parcel) const328 bool GetDragSummaryReply::Marshalling(MessageParcel &parcel) const
329 {
330 return (SummaryPacker::Marshalling(summary_, parcel) == RET_OK);
331 }
332
Unmarshalling(MessageParcel & parcel)333 bool GetDragSummaryReply::Unmarshalling(MessageParcel &parcel)
334 {
335 return (SummaryPacker::UnMarshalling(parcel, summary_) == RET_OK);
336 }
337
GetDragStateReply(DragState dragState)338 GetDragStateReply::GetDragStateReply(DragState dragState)
339 : dragState_(dragState)
340 {}
341
Marshalling(MessageParcel & parcel) const342 bool GetDragStateReply::Marshalling(MessageParcel &parcel) const
343 {
344 return parcel.WriteInt32(static_cast<int32_t>(dragState_));
345 }
346
Unmarshalling(MessageParcel & parcel)347 bool GetDragStateReply::Unmarshalling(MessageParcel &parcel)
348 {
349 int32_t dragState { -1 };
350 if (!parcel.ReadInt32(dragState) ||
351 (dragState < static_cast<int32_t>(DragState::ERROR)) ||
352 (dragState > static_cast<int32_t>(DragState::MOTION_DRAGGING))) {
353 return false;
354 }
355 dragState_ = static_cast<DragState>(dragState);
356 return true;
357 }
358
GetDragActionReply(DragAction dragAction)359 GetDragActionReply::GetDragActionReply(DragAction dragAction)
360 : dragAction_(dragAction)
361 {}
362
Marshalling(MessageParcel & parcel) const363 bool GetDragActionReply::Marshalling(MessageParcel &parcel) const
364 {
365 return parcel.WriteInt32(static_cast<int32_t>(dragAction_));
366 }
367
Unmarshalling(MessageParcel & parcel)368 bool GetDragActionReply::Unmarshalling(MessageParcel &parcel)
369 {
370 int32_t dragAction { -1 };
371 if (!parcel.ReadInt32(dragAction) ||
372 (dragAction < static_cast<int32_t>(DragAction::INVALID)) ||
373 (dragAction > static_cast<int32_t>(DragAction::COPY))) {
374 return false;
375 }
376 dragAction_ = static_cast<DragAction>(dragAction);
377 return true;
378 }
379
GetExtraInfoReply(std::string && extraInfo)380 GetExtraInfoReply::GetExtraInfoReply(std::string &&extraInfo)
381 : extraInfo_(std::move(extraInfo))
382 {}
383
Marshalling(MessageParcel & parcel) const384 bool GetExtraInfoReply::Marshalling(MessageParcel &parcel) const
385 {
386 return parcel.WriteString(extraInfo_);
387 }
388
Unmarshalling(MessageParcel & parcel)389 bool GetExtraInfoReply::Unmarshalling(MessageParcel &parcel)
390 {
391 return parcel.ReadString(extraInfo_);
392 }
393 } // namespace DeviceStatus
394 } // namespace Msdp
395 } // namespace OHOS