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
GetDragStateReply(DragState dragState)353 GetDragStateReply::GetDragStateReply(DragState dragState)
354 : dragState_(dragState)
355 {}
356
Marshalling(MessageParcel &parcel) const357 bool GetDragStateReply::Marshalling(MessageParcel &parcel) const
358 {
359 return parcel.WriteInt32(static_cast<int32_t>(dragState_));
360 }
361
Unmarshalling(MessageParcel &parcel)362 bool GetDragStateReply::Unmarshalling(MessageParcel &parcel)
363 {
364 int32_t dragState { -1 };
365 if (!parcel.ReadInt32(dragState) ||
366 (dragState < static_cast<int32_t>(DragState::ERROR)) ||
367 (dragState > static_cast<int32_t>(DragState::MOTION_DRAGGING))) {
368 return false;
369 }
370 dragState_ = static_cast<DragState>(dragState);
371 return true;
372 }
373
GetDragActionReply(DragAction dragAction)374 GetDragActionReply::GetDragActionReply(DragAction dragAction)
375 : dragAction_(dragAction)
376 {}
377
Marshalling(MessageParcel &parcel) const378 bool GetDragActionReply::Marshalling(MessageParcel &parcel) const
379 {
380 return parcel.WriteInt32(static_cast<int32_t>(dragAction_));
381 }
382
Unmarshalling(MessageParcel &parcel)383 bool GetDragActionReply::Unmarshalling(MessageParcel &parcel)
384 {
385 int32_t dragAction { -1 };
386 if (!parcel.ReadInt32(dragAction) ||
387 (dragAction < static_cast<int32_t>(DragAction::INVALID)) ||
388 (dragAction > static_cast<int32_t>(DragAction::COPY))) {
389 return false;
390 }
391 dragAction_ = static_cast<DragAction>(dragAction);
392 return true;
393 }
394
GetExtraInfoReply(std::string &&extraInfo)395 GetExtraInfoReply::GetExtraInfoReply(std::string &&extraInfo)
396 : extraInfo_(std::move(extraInfo))
397 {}
398
Marshalling(MessageParcel &parcel) const399 bool GetExtraInfoReply::Marshalling(MessageParcel &parcel) const
400 {
401 return parcel.WriteString(extraInfo_);
402 }
403
Unmarshalling(MessageParcel &parcel)404 bool GetExtraInfoReply::Unmarshalling(MessageParcel &parcel)
405 {
406 return parcel.ReadString(extraInfo_);
407 }
408 } // namespace DeviceStatus
409 } // namespace Msdp
410 } // namespace OHOS