• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
AddSelectedPixelMapParam(std::shared_ptr<OHOS::Media::PixelMap> pixelMap)153 AddSelectedPixelMapParam::AddSelectedPixelMapParam(std::shared_ptr<OHOS::Media::PixelMap> pixelMap)
154     :pixelMap_(pixelMap)
155 {}
156 
Marshalling(MessageParcel & parcel) const157 bool AddSelectedPixelMapParam::Marshalling(MessageParcel &parcel) const
158 {
159     return ((pixelMap_ != nullptr) && pixelMap_->Marshalling(parcel));
160 }
161 
Unmarshalling(MessageParcel & parcel)162 bool AddSelectedPixelMapParam::Unmarshalling(MessageParcel &parcel)
163 {
164     pixelMap_ = std::shared_ptr<Media::PixelMap>(Media::PixelMap::Unmarshalling(parcel));
165     return ((pixelMap_ != nullptr));
166 }
167 
GetDragTargetPidReply(int32_t pid)168 GetDragTargetPidReply::GetDragTargetPidReply(int32_t pid)
169     : targetPid_(pid)
170 {}
171 
Marshalling(MessageParcel & parcel) const172 bool GetDragTargetPidReply::Marshalling(MessageParcel &parcel) const
173 {
174     return parcel.WriteInt32(targetPid_);
175 }
176 
Unmarshalling(MessageParcel & parcel)177 bool GetDragTargetPidReply::Unmarshalling(MessageParcel &parcel)
178 {
179     return parcel.ReadInt32(targetPid_);
180 }
181 
GetUdKeyReply(std::string && udKey)182 GetUdKeyReply::GetUdKeyReply(std::string &&udKey)
183     : udKey_(std::move(udKey))
184 {}
185 
Marshalling(MessageParcel & parcel) const186 bool GetUdKeyReply::Marshalling(MessageParcel &parcel) const
187 {
188     return parcel.WriteString(udKey_);
189 }
190 
Unmarshalling(MessageParcel & parcel)191 bool GetUdKeyReply::Unmarshalling(MessageParcel &parcel)
192 {
193     return parcel.ReadString(udKey_);
194 }
195 
GetShadowOffsetReply(const ShadowOffset & shadowOffset)196 GetShadowOffsetReply::GetShadowOffsetReply(const ShadowOffset &shadowOffset)
197     : shadowOffset_(shadowOffset)
198 {}
199 
Marshalling(MessageParcel & parcel) const200 bool GetShadowOffsetReply::Marshalling(MessageParcel &parcel) const
201 {
202     return (
203         parcel.WriteInt32(shadowOffset_.offsetX) &&
204         parcel.WriteInt32(shadowOffset_.offsetY) &&
205         parcel.WriteInt32(shadowOffset_.width) &&
206         parcel.WriteInt32(shadowOffset_.height)
207     );
208 }
209 
Unmarshalling(MessageParcel & parcel)210 bool GetShadowOffsetReply::Unmarshalling(MessageParcel &parcel)
211 {
212     return (
213         parcel.ReadInt32(shadowOffset_.offsetX) &&
214         parcel.ReadInt32(shadowOffset_.offsetY) &&
215         parcel.ReadInt32(shadowOffset_.width) &&
216         parcel.ReadInt32(shadowOffset_.height)
217     );
218 }
219 
UpdatePreviewStyleParam(const PreviewStyle & previewStyle)220 UpdatePreviewStyleParam::UpdatePreviewStyleParam(const PreviewStyle &previewStyle)
221     : previewStyle_(previewStyle)
222 {}
223 
Marshalling(MessageParcel & parcel) const224 bool UpdatePreviewStyleParam::Marshalling(MessageParcel &parcel) const
225 {
226     return (PreviewStylePacker::Marshalling(previewStyle_, parcel) == RET_OK);
227 }
228 
Unmarshalling(MessageParcel & parcel)229 bool UpdatePreviewStyleParam::Unmarshalling(MessageParcel &parcel)
230 {
231     return (PreviewStylePacker::UnMarshalling(parcel, previewStyle_) == RET_OK);
232 }
233 
UpdatePreviewAnimationParam(const PreviewStyle & previewStyle,const PreviewAnimation & animation)234 UpdatePreviewAnimationParam::UpdatePreviewAnimationParam(
235     const PreviewStyle &previewStyle, const PreviewAnimation &animation)
236     : previewStyle_(previewStyle), previewAnimation_(animation)
237 {}
238 
Marshalling(MessageParcel & parcel) const239 bool UpdatePreviewAnimationParam::Marshalling(MessageParcel &parcel) const
240 {
241     return (
242         (PreviewStylePacker::Marshalling(previewStyle_, parcel) == RET_OK) &&
243         (PreviewAnimationPacker::Marshalling(previewAnimation_, parcel) == RET_OK)
244     );
245 }
246 
Unmarshalling(MessageParcel & parcel)247 bool UpdatePreviewAnimationParam::Unmarshalling(MessageParcel &parcel)
248 {
249     return (
250         (PreviewStylePacker::UnMarshalling(parcel, previewStyle_) == RET_OK) &&
251         (PreviewAnimationPacker::UnMarshalling(parcel, previewAnimation_) == RET_OK)
252     );
253 }
254 
RotateDragWindowSyncParam(const std::shared_ptr<Rosen::RSTransaction> & rsTransaction)255 RotateDragWindowSyncParam::RotateDragWindowSyncParam(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction)
256     : rsTransaction_(rsTransaction)
257 {}
258 
Marshalling(MessageParcel & parcel) const259 bool RotateDragWindowSyncParam::Marshalling(MessageParcel &parcel) const
260 {
261     if (rsTransaction_ == nullptr) {
262         FI_HILOGE("rsTransaction_ is nullptr");
263         return false;
264     }
265     if (!parcel.WriteParcelable(rsTransaction_.get())) {
266         FI_HILOGE("Write transaction sync id failed");
267         return false;
268     }
269     return true;
270 }
271 
Unmarshalling(MessageParcel & parcel)272 bool RotateDragWindowSyncParam::Unmarshalling(MessageParcel &parcel)
273 {
274     std::shared_ptr<Rosen::RSTransaction> rsTransaction(parcel.ReadParcelable<Rosen::RSTransaction>());
275     if (rsTransaction == nullptr) {
276         FI_HILOGE("UnMarshalling rsTransaction failed");
277         return false;
278     }
279     rsTransaction_ = rsTransaction;
280     return true;
281 }
282 
SetDragWindowScreenIdParam(uint64_t displayId,uint64_t screenId)283 SetDragWindowScreenIdParam::SetDragWindowScreenIdParam(uint64_t displayId, uint64_t screenId)
284     : displayId_(displayId), screenId_(screenId)
285 {}
286 
Marshalling(MessageParcel & parcel) const287 bool SetDragWindowScreenIdParam::Marshalling(MessageParcel &parcel) const
288 {
289     return (parcel.WriteUint64(displayId_) && parcel.WriteUint64(screenId_));
290 }
291 
Unmarshalling(MessageParcel & parcel)292 bool SetDragWindowScreenIdParam::Unmarshalling(MessageParcel &parcel)
293 {
294     return (parcel.ReadUint64(displayId_) && parcel.ReadUint64(screenId_));
295 }
296 
AddDraglistenerParam(bool isJsCaller)297 AddDraglistenerParam::AddDraglistenerParam(bool isJsCaller)
298     : isJsCaller_(isJsCaller)
299 {}
300 
Marshalling(MessageParcel & parcel) const301 bool AddDraglistenerParam::Marshalling(MessageParcel &parcel) const
302 {
303     return parcel.WriteBool(isJsCaller_);
304 }
305 
Unmarshalling(MessageParcel & parcel)306 bool AddDraglistenerParam::Unmarshalling(MessageParcel &parcel)
307 {
308     return parcel.ReadBool(isJsCaller_);
309 }
310 
RemoveDraglistenerParam(bool isJsCaller)311 RemoveDraglistenerParam::RemoveDraglistenerParam(bool isJsCaller)
312     : isJsCaller_(isJsCaller)
313 {}
314 
Marshalling(MessageParcel & parcel) const315 bool RemoveDraglistenerParam::Marshalling(MessageParcel &parcel) const
316 {
317     return parcel.WriteBool(isJsCaller_);
318 }
319 
Unmarshalling(MessageParcel & parcel)320 bool RemoveDraglistenerParam::Unmarshalling(MessageParcel &parcel)
321 {
322     return parcel.ReadBool(isJsCaller_);
323 }
324 
GetDragSummaryParam(bool isJsCaller)325 GetDragSummaryParam::GetDragSummaryParam(bool isJsCaller)
326     : isJsCaller_(isJsCaller)
327 {}
328 
Marshalling(MessageParcel & parcel) const329 bool GetDragSummaryParam::Marshalling(MessageParcel &parcel) const
330 {
331     return parcel.WriteBool(isJsCaller_);
332 }
333 
Unmarshalling(MessageParcel & parcel)334 bool GetDragSummaryParam::Unmarshalling(MessageParcel &parcel)
335 {
336     return parcel.ReadBool(isJsCaller_);
337 }
338 
GetDragSummaryReply(std::map<std::string,int64_t> && summary)339 GetDragSummaryReply::GetDragSummaryReply(std::map<std::string, int64_t> &&summary)
340     : summary_(std::move(summary))
341 {}
342 
Marshalling(MessageParcel & parcel) const343 bool GetDragSummaryReply::Marshalling(MessageParcel &parcel) const
344 {
345     return (SummaryPacker::Marshalling(summary_, parcel) == RET_OK);
346 }
347 
Unmarshalling(MessageParcel & parcel)348 bool GetDragSummaryReply::Unmarshalling(MessageParcel &parcel)
349 {
350     return (SummaryPacker::UnMarshalling(parcel, summary_) == RET_OK);
351 }
352 
SetDragSwitchStateParam(bool enable,bool isJsCaller)353 SetDragSwitchStateParam::SetDragSwitchStateParam(bool enable, bool isJsCaller)
354     : enable_(enable), isJsCaller_(isJsCaller)
355 {}
356 
Marshalling(MessageParcel & parcel) const357 bool SetDragSwitchStateParam::Marshalling(MessageParcel &parcel) const
358 {
359     return parcel.WriteBool(enable_) && parcel.WriteBool(isJsCaller_);
360 }
361 
Unmarshalling(MessageParcel & parcel)362 bool SetDragSwitchStateParam::Unmarshalling(MessageParcel &parcel)
363 {
364     return parcel.ReadBool(enable_) && parcel.ReadBool(isJsCaller_);
365 }
366 
SetAppDragSwitchStateParam(bool enable,const std::string & pkgName,bool isJsCaller)367 SetAppDragSwitchStateParam::SetAppDragSwitchStateParam(bool enable, const std::string &pkgName, bool isJsCaller)
368     : enable_(enable), pkgName_(pkgName), isJsCaller_(isJsCaller)
369 {}
370 
Marshalling(MessageParcel & parcel) const371 bool SetAppDragSwitchStateParam::Marshalling(MessageParcel &parcel) const
372 {
373     return parcel.WriteBool(enable_) && parcel.WriteString(pkgName_) && parcel.WriteBool(isJsCaller_);
374 }
375 
Unmarshalling(MessageParcel & parcel)376 bool SetAppDragSwitchStateParam::Unmarshalling(MessageParcel &parcel)
377 {
378     return parcel.ReadBool(enable_) && parcel.ReadString(pkgName_) && parcel.ReadBool(isJsCaller_);
379 }
380 
GetDragStateReply(DragState dragState)381 GetDragStateReply::GetDragStateReply(DragState dragState)
382     : dragState_(dragState)
383 {}
384 
Marshalling(MessageParcel & parcel) const385 bool GetDragStateReply::Marshalling(MessageParcel &parcel) const
386 {
387     return parcel.WriteInt32(static_cast<int32_t>(dragState_));
388 }
389 
Unmarshalling(MessageParcel & parcel)390 bool GetDragStateReply::Unmarshalling(MessageParcel &parcel)
391 {
392     int32_t dragState { -1 };
393     if (!parcel.ReadInt32(dragState) ||
394         (dragState < static_cast<int32_t>(DragState::ERROR)) ||
395         (dragState > static_cast<int32_t>(DragState::MOTION_DRAGGING))) {
396         return false;
397     }
398     dragState_ = static_cast<DragState>(dragState);
399     return true;
400 }
401 
GetDragActionReply(DragAction dragAction)402 GetDragActionReply::GetDragActionReply(DragAction dragAction)
403     : dragAction_(dragAction)
404 {}
405 
Marshalling(MessageParcel & parcel) const406 bool GetDragActionReply::Marshalling(MessageParcel &parcel) const
407 {
408     return parcel.WriteInt32(static_cast<int32_t>(dragAction_));
409 }
410 
Unmarshalling(MessageParcel & parcel)411 bool GetDragActionReply::Unmarshalling(MessageParcel &parcel)
412 {
413     int32_t dragAction { -1 };
414     if (!parcel.ReadInt32(dragAction) ||
415         (dragAction < static_cast<int32_t>(DragAction::INVALID)) ||
416         (dragAction > static_cast<int32_t>(DragAction::COPY))) {
417         return false;
418     }
419     dragAction_ = static_cast<DragAction>(dragAction);
420     return true;
421 }
422 
GetExtraInfoReply(std::string && extraInfo)423 GetExtraInfoReply::GetExtraInfoReply(std::string &&extraInfo)
424     : extraInfo_(std::move(extraInfo))
425 {}
426 
Marshalling(MessageParcel & parcel) const427 bool GetExtraInfoReply::Marshalling(MessageParcel &parcel) const
428 {
429     return parcel.WriteString(extraInfo_);
430 }
431 
Unmarshalling(MessageParcel & parcel)432 bool GetExtraInfoReply::Unmarshalling(MessageParcel &parcel)
433 {
434     return parcel.ReadString(extraInfo_);
435 }
436 
SetDraggableStateParam(bool state)437 SetDraggableStateParam::SetDraggableStateParam(bool state)
438 {
439     state_ = state;
440 }
441 
Marshalling(MessageParcel & parcel) const442 bool SetDraggableStateParam::Marshalling(MessageParcel &parcel) const
443 {
444     return parcel.WriteBool(state_);
445 }
446 
Unmarshalling(MessageParcel & parcel)447 bool SetDraggableStateParam::Unmarshalling(MessageParcel &parcel)
448 {
449     return parcel.ReadBool(state_);
450 }
451 
GetUniversalDragAppStateReply(bool state)452 GetUniversalDragAppStateReply::GetUniversalDragAppStateReply(bool state)
453 {
454     state_ = state;
455 }
456 
Marshalling(MessageParcel & parcel) const457 bool GetUniversalDragAppStateReply::Marshalling(MessageParcel &parcel) const
458 {
459     return parcel.WriteBool(state_);
460 }
461 
Unmarshalling(MessageParcel & parcel)462 bool GetUniversalDragAppStateReply::Unmarshalling(MessageParcel &parcel)
463 {
464     return parcel.ReadBool(state_);
465 }
466 
SetDraggableStateAsyncParam(bool state,int64_t downTime)467 SetDraggableStateAsyncParam::SetDraggableStateAsyncParam(bool state, int64_t downTime)
468 {
469     state_ = state;
470     downTime_ = downTime;
471 }
472 
Marshalling(MessageParcel & parcel) const473 bool SetDraggableStateAsyncParam::Marshalling(MessageParcel &parcel) const
474 {
475     return (parcel.WriteBool(state_) && parcel.WriteInt64(downTime_));
476 }
477 
Unmarshalling(MessageParcel & parcel)478 bool SetDraggableStateAsyncParam::Unmarshalling(MessageParcel &parcel)
479 {
480     return (parcel.ReadBool(state_) && parcel.ReadInt64(downTime_));
481 }
482 } // namespace DeviceStatus
483 } // namespace Msdp
484 } // namespace OHOS