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)107 UpdateDragStyleParam::UpdateDragStyleParam(DragCursorStyle style)
108 : cursorStyle_(style)
109 {}
110
Marshalling(MessageParcel & parcel) const111 bool UpdateDragStyleParam::Marshalling(MessageParcel &parcel) const
112 {
113 return parcel.WriteInt32(static_cast<int32_t>(cursorStyle_));
114 }
115
Unmarshalling(MessageParcel & parcel)116 bool UpdateDragStyleParam::Unmarshalling(MessageParcel &parcel)
117 {
118 int32_t style { -1 };
119 if (!parcel.ReadInt32(style) ||
120 (style < static_cast<int32_t>(DragCursorStyle::DEFAULT)) ||
121 (style > static_cast<int32_t>(DragCursorStyle::MOVE))) {
122 return false;
123 }
124 cursorStyle_ = static_cast<DragCursorStyle>(style);
125 return true;
126 }
127
UpdateShadowPicParam(const ShadowInfo & shadowInfo)128 UpdateShadowPicParam::UpdateShadowPicParam(const ShadowInfo &shadowInfo)
129 : shadowInfo_(shadowInfo)
130 {}
131
Marshalling(MessageParcel & parcel) const132 bool UpdateShadowPicParam::Marshalling(MessageParcel &parcel) const
133 {
134 return (
135 (shadowInfo_.pixelMap != nullptr) &&
136 shadowInfo_.pixelMap->Marshalling(parcel) &&
137 parcel.WriteInt32(shadowInfo_.x) &&
138 parcel.WriteInt32(shadowInfo_.y)
139 );
140 }
141
Unmarshalling(MessageParcel & parcel)142 bool UpdateShadowPicParam::Unmarshalling(MessageParcel &parcel)
143 {
144 shadowInfo_.pixelMap = std::shared_ptr<Media::PixelMap>(Media::PixelMap::Unmarshalling(parcel));
145 return (
146 (shadowInfo_.pixelMap != nullptr) &&
147 parcel.ReadInt32(shadowInfo_.x) &&
148 parcel.ReadInt32(shadowInfo_.y)
149 );
150 }
151
AddSelectedPixelMapParam(std::shared_ptr<OHOS::Media::PixelMap> pixelMap)152 AddSelectedPixelMapParam::AddSelectedPixelMapParam(std::shared_ptr<OHOS::Media::PixelMap> pixelMap)
153 :pixelMap_(pixelMap)
154 {}
155
Marshalling(MessageParcel & parcel) const156 bool AddSelectedPixelMapParam::Marshalling(MessageParcel &parcel) const
157 {
158 return ((pixelMap_ != nullptr) && pixelMap_->Marshalling(parcel));
159 }
160
Unmarshalling(MessageParcel & parcel)161 bool AddSelectedPixelMapParam::Unmarshalling(MessageParcel &parcel)
162 {
163 pixelMap_ = std::shared_ptr<Media::PixelMap>(Media::PixelMap::Unmarshalling(parcel));
164 return ((pixelMap_ != nullptr));
165 }
166
GetDragTargetPidReply(int32_t pid)167 GetDragTargetPidReply::GetDragTargetPidReply(int32_t pid)
168 : targetPid_(pid)
169 {}
170
Marshalling(MessageParcel & parcel) const171 bool GetDragTargetPidReply::Marshalling(MessageParcel &parcel) const
172 {
173 return parcel.WriteInt32(targetPid_);
174 }
175
Unmarshalling(MessageParcel & parcel)176 bool GetDragTargetPidReply::Unmarshalling(MessageParcel &parcel)
177 {
178 return parcel.ReadInt32(targetPid_);
179 }
180
GetUdKeyReply(std::string && udKey)181 GetUdKeyReply::GetUdKeyReply(std::string &&udKey)
182 : udKey_(std::move(udKey))
183 {}
184
Marshalling(MessageParcel & parcel) const185 bool GetUdKeyReply::Marshalling(MessageParcel &parcel) const
186 {
187 return parcel.WriteString(udKey_);
188 }
189
Unmarshalling(MessageParcel & parcel)190 bool GetUdKeyReply::Unmarshalling(MessageParcel &parcel)
191 {
192 return parcel.ReadString(udKey_);
193 }
194
GetShadowOffsetReply(const ShadowOffset & shadowOffset)195 GetShadowOffsetReply::GetShadowOffsetReply(const ShadowOffset &shadowOffset)
196 : shadowOffset_(shadowOffset)
197 {}
198
Marshalling(MessageParcel & parcel) const199 bool GetShadowOffsetReply::Marshalling(MessageParcel &parcel) const
200 {
201 return (
202 parcel.WriteInt32(shadowOffset_.offsetX) &&
203 parcel.WriteInt32(shadowOffset_.offsetY) &&
204 parcel.WriteInt32(shadowOffset_.width) &&
205 parcel.WriteInt32(shadowOffset_.height)
206 );
207 }
208
Unmarshalling(MessageParcel & parcel)209 bool GetShadowOffsetReply::Unmarshalling(MessageParcel &parcel)
210 {
211 return (
212 parcel.ReadInt32(shadowOffset_.offsetX) &&
213 parcel.ReadInt32(shadowOffset_.offsetY) &&
214 parcel.ReadInt32(shadowOffset_.width) &&
215 parcel.ReadInt32(shadowOffset_.height)
216 );
217 }
218
UpdatePreviewStyleParam(const PreviewStyle & previewStyle)219 UpdatePreviewStyleParam::UpdatePreviewStyleParam(const PreviewStyle &previewStyle)
220 : previewStyle_(previewStyle)
221 {}
222
Marshalling(MessageParcel & parcel) const223 bool UpdatePreviewStyleParam::Marshalling(MessageParcel &parcel) const
224 {
225 return (PreviewStylePacker::Marshalling(previewStyle_, parcel) == RET_OK);
226 }
227
Unmarshalling(MessageParcel & parcel)228 bool UpdatePreviewStyleParam::Unmarshalling(MessageParcel &parcel)
229 {
230 return (PreviewStylePacker::UnMarshalling(parcel, previewStyle_) == RET_OK);
231 }
232
UpdatePreviewAnimationParam(const PreviewStyle & previewStyle,const PreviewAnimation & animation)233 UpdatePreviewAnimationParam::UpdatePreviewAnimationParam(
234 const PreviewStyle &previewStyle, const PreviewAnimation &animation)
235 : previewStyle_(previewStyle), previewAnimation_(animation)
236 {}
237
Marshalling(MessageParcel & parcel) const238 bool UpdatePreviewAnimationParam::Marshalling(MessageParcel &parcel) const
239 {
240 return (
241 (PreviewStylePacker::Marshalling(previewStyle_, parcel) == RET_OK) &&
242 (PreviewAnimationPacker::Marshalling(previewAnimation_, parcel) == RET_OK)
243 );
244 }
245
Unmarshalling(MessageParcel & parcel)246 bool UpdatePreviewAnimationParam::Unmarshalling(MessageParcel &parcel)
247 {
248 return (
249 (PreviewStylePacker::UnMarshalling(parcel, previewStyle_) == RET_OK) &&
250 (PreviewAnimationPacker::UnMarshalling(parcel, previewAnimation_) == RET_OK)
251 );
252 }
253
RotateDragWindowSyncParam(const std::shared_ptr<Rosen::RSTransaction> & rsTransaction)254 RotateDragWindowSyncParam::RotateDragWindowSyncParam(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction)
255 : rsTransaction_(rsTransaction)
256 {}
257
Marshalling(MessageParcel & parcel) const258 bool RotateDragWindowSyncParam::Marshalling(MessageParcel &parcel) const
259 {
260 if (rsTransaction_ == nullptr) {
261 FI_HILOGE("rsTransaction_ is nullptr");
262 return false;
263 }
264 if (!parcel.WriteParcelable(rsTransaction_.get())) {
265 FI_HILOGE("Write transaction sync id failed");
266 return false;
267 }
268 return true;
269 }
270
Unmarshalling(MessageParcel & parcel)271 bool RotateDragWindowSyncParam::Unmarshalling(MessageParcel &parcel)
272 {
273 std::shared_ptr<Rosen::RSTransaction> rsTransaction(parcel.ReadParcelable<Rosen::RSTransaction>());
274 if (rsTransaction == nullptr) {
275 FI_HILOGE("UnMarshalling rsTransaction failed");
276 return false;
277 }
278 rsTransaction_ = rsTransaction;
279 return true;
280 }
281
SetDragWindowScreenIdParam(uint64_t displayId,uint64_t screenId)282 SetDragWindowScreenIdParam::SetDragWindowScreenIdParam(uint64_t displayId, uint64_t screenId)
283 : displayId_(displayId), screenId_(screenId)
284 {}
285
Marshalling(MessageParcel & parcel) const286 bool SetDragWindowScreenIdParam::Marshalling(MessageParcel &parcel) const
287 {
288 return (parcel.WriteUint64(displayId_) && parcel.WriteUint64(screenId_));
289 }
290
Unmarshalling(MessageParcel & parcel)291 bool SetDragWindowScreenIdParam::Unmarshalling(MessageParcel &parcel)
292 {
293 return (parcel.ReadUint64(displayId_) && parcel.ReadUint64(screenId_));
294 }
295
GetDragSummaryReply(std::map<std::string,int64_t> && summary)296 GetDragSummaryReply::GetDragSummaryReply(std::map<std::string, int64_t> &&summary)
297 : summary_(std::move(summary))
298 {}
299
Marshalling(MessageParcel & parcel) const300 bool GetDragSummaryReply::Marshalling(MessageParcel &parcel) const
301 {
302 return (SummaryPacker::Marshalling(summary_, parcel) == RET_OK);
303 }
304
Unmarshalling(MessageParcel & parcel)305 bool GetDragSummaryReply::Unmarshalling(MessageParcel &parcel)
306 {
307 return (SummaryPacker::UnMarshalling(parcel, summary_) == RET_OK);
308 }
309
GetDragStateReply(DragState dragState)310 GetDragStateReply::GetDragStateReply(DragState dragState)
311 : dragState_(dragState)
312 {}
313
Marshalling(MessageParcel & parcel) const314 bool GetDragStateReply::Marshalling(MessageParcel &parcel) const
315 {
316 return parcel.WriteInt32(static_cast<int32_t>(dragState_));
317 }
318
Unmarshalling(MessageParcel & parcel)319 bool GetDragStateReply::Unmarshalling(MessageParcel &parcel)
320 {
321 int32_t dragState { -1 };
322 if (!parcel.ReadInt32(dragState) ||
323 (dragState < static_cast<int32_t>(DragState::ERROR)) ||
324 (dragState > static_cast<int32_t>(DragState::MOTION_DRAGGING))) {
325 return false;
326 }
327 dragState_ = static_cast<DragState>(dragState);
328 return true;
329 }
330
GetDragActionReply(DragAction dragAction)331 GetDragActionReply::GetDragActionReply(DragAction dragAction)
332 : dragAction_(dragAction)
333 {}
334
Marshalling(MessageParcel & parcel) const335 bool GetDragActionReply::Marshalling(MessageParcel &parcel) const
336 {
337 return parcel.WriteInt32(static_cast<int32_t>(dragAction_));
338 }
339
Unmarshalling(MessageParcel & parcel)340 bool GetDragActionReply::Unmarshalling(MessageParcel &parcel)
341 {
342 int32_t dragAction { -1 };
343 if (!parcel.ReadInt32(dragAction) ||
344 (dragAction < static_cast<int32_t>(DragAction::INVALID)) ||
345 (dragAction > static_cast<int32_t>(DragAction::COPY))) {
346 return false;
347 }
348 dragAction_ = static_cast<DragAction>(dragAction);
349 return true;
350 }
351
GetExtraInfoReply(std::string && extraInfo)352 GetExtraInfoReply::GetExtraInfoReply(std::string &&extraInfo)
353 : extraInfo_(std::move(extraInfo))
354 {}
355
Marshalling(MessageParcel & parcel) const356 bool GetExtraInfoReply::Marshalling(MessageParcel &parcel) const
357 {
358 return parcel.WriteString(extraInfo_);
359 }
360
Unmarshalling(MessageParcel & parcel)361 bool GetExtraInfoReply::Unmarshalling(MessageParcel &parcel)
362 {
363 return parcel.ReadString(extraInfo_);
364 }
365 } // namespace DeviceStatus
366 } // namespace Msdp
367 } // namespace OHOS