/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "drag_params.h" #include "devicestatus_define.h" #include "drag_data_packer.h" #include "preview_style_packer.h" #undef LOG_TAG #define LOG_TAG "DragParams" namespace OHOS { namespace Msdp { namespace DeviceStatus { StartDragParam::StartDragParam(DragData &dragData) { dragDataPtr_ = &dragData; } StartDragParam::StartDragParam(const DragData &dragData) { cDragDataPtr_ = &dragData; } bool StartDragParam::Marshalling(MessageParcel &parcel) const { return ( (cDragDataPtr_ != nullptr) && (DragDataPacker::Marshalling(*cDragDataPtr_, parcel) == RET_OK) ); } bool StartDragParam::Unmarshalling(MessageParcel &parcel) { return ( (dragDataPtr_ != nullptr) && (DragDataPacker::UnMarshalling(parcel, *dragDataPtr_) == RET_OK) ); } StopDragParam::StopDragParam(const DragDropResult &dropResult) : dropResult_(dropResult) {} bool StopDragParam::Marshalling(MessageParcel &parcel) const { return ( parcel.WriteInt32(static_cast(dropResult_.result)) && parcel.WriteInt32(dropResult_.mainWindow) && parcel.WriteBool(dropResult_.hasCustomAnimation) && parcel.WriteInt32(static_cast(dropResult_.dragBehavior)) ); } bool StopDragParam::Unmarshalling(MessageParcel &parcel) { int32_t result { -1 }; if (!parcel.ReadInt32(result) || (result < static_cast(DragResult::DRAG_SUCCESS)) || (result > static_cast(DragResult::DRAG_EXCEPTION))) { return false; } dropResult_.result = static_cast(result); if (!parcel.ReadInt32(dropResult_.mainWindow) || !parcel.ReadBool(dropResult_.hasCustomAnimation)) { return false; } int32_t dragBehavior { -1 }; if (!parcel.ReadInt32(dragBehavior) || (dragBehavior < static_cast(DragBehavior::UNKNOWN)) || (dragBehavior > static_cast(DragBehavior::MOVE))) { return false; } dropResult_.dragBehavior = static_cast(dragBehavior); return true; } SetDragWindowVisibleParam::SetDragWindowVisibleParam(bool visible, bool isForce) : visible_(visible), isForce_(isForce) {} bool SetDragWindowVisibleParam::Marshalling(MessageParcel &parcel) const { return (parcel.WriteBool(visible_) && parcel.WriteBool(isForce_)); } bool SetDragWindowVisibleParam::Unmarshalling(MessageParcel &parcel) { return (parcel.ReadBool(visible_) && parcel.ReadBool(isForce_)); } UpdateDragStyleParam::UpdateDragStyleParam(DragCursorStyle style, int32_t eventId) : cursorStyle_(style), eventId_(eventId) {} bool UpdateDragStyleParam::Marshalling(MessageParcel &parcel) const { return (parcel.WriteInt32(static_cast(cursorStyle_)) && parcel.WriteInt32(eventId_)); } bool UpdateDragStyleParam::Unmarshalling(MessageParcel &parcel) { int32_t style { -1 }; if (!parcel.ReadInt32(style) || (style < static_cast(DragCursorStyle::DEFAULT)) || (style > static_cast(DragCursorStyle::MOVE))) { return false; } cursorStyle_ = static_cast(style); return parcel.ReadInt32(eventId_); } UpdateShadowPicParam::UpdateShadowPicParam(const ShadowInfo &shadowInfo) : shadowInfo_(shadowInfo) {} bool UpdateShadowPicParam::Marshalling(MessageParcel &parcel) const { return ( (shadowInfo_.pixelMap != nullptr) && shadowInfo_.pixelMap->Marshalling(parcel) && parcel.WriteInt32(shadowInfo_.x) && parcel.WriteInt32(shadowInfo_.y) ); } bool UpdateShadowPicParam::Unmarshalling(MessageParcel &parcel) { shadowInfo_.pixelMap = std::shared_ptr(Media::PixelMap::Unmarshalling(parcel)); return ( (shadowInfo_.pixelMap != nullptr) && parcel.ReadInt32(shadowInfo_.x) && parcel.ReadInt32(shadowInfo_.y) ); } GetDragTargetPidReply::GetDragTargetPidReply(int32_t pid) : targetPid_(pid) {} bool GetDragTargetPidReply::Marshalling(MessageParcel &parcel) const { return parcel.WriteInt32(targetPid_); } bool GetDragTargetPidReply::Unmarshalling(MessageParcel &parcel) { return parcel.ReadInt32(targetPid_); } GetUdKeyReply::GetUdKeyReply(std::string &&udKey) : udKey_(std::move(udKey)) {} bool GetUdKeyReply::Marshalling(MessageParcel &parcel) const { return parcel.WriteString(udKey_); } bool GetUdKeyReply::Unmarshalling(MessageParcel &parcel) { return parcel.ReadString(udKey_); } GetShadowOffsetReply::GetShadowOffsetReply(const ShadowOffset &shadowOffset) : shadowOffset_(shadowOffset) {} bool GetShadowOffsetReply::Marshalling(MessageParcel &parcel) const { return ( parcel.WriteInt32(shadowOffset_.offsetX) && parcel.WriteInt32(shadowOffset_.offsetY) && parcel.WriteInt32(shadowOffset_.width) && parcel.WriteInt32(shadowOffset_.height) ); } bool GetShadowOffsetReply::Unmarshalling(MessageParcel &parcel) { return ( parcel.ReadInt32(shadowOffset_.offsetX) && parcel.ReadInt32(shadowOffset_.offsetY) && parcel.ReadInt32(shadowOffset_.width) && parcel.ReadInt32(shadowOffset_.height) ); } UpdatePreviewStyleParam::UpdatePreviewStyleParam(const PreviewStyle &previewStyle) : previewStyle_(previewStyle) {} bool UpdatePreviewStyleParam::Marshalling(MessageParcel &parcel) const { return (PreviewStylePacker::Marshalling(previewStyle_, parcel) == RET_OK); } bool UpdatePreviewStyleParam::Unmarshalling(MessageParcel &parcel) { return (PreviewStylePacker::UnMarshalling(parcel, previewStyle_) == RET_OK); } UpdatePreviewAnimationParam::UpdatePreviewAnimationParam( const PreviewStyle &previewStyle, const PreviewAnimation &animation) : previewStyle_(previewStyle), previewAnimation_(animation) {} bool UpdatePreviewAnimationParam::Marshalling(MessageParcel &parcel) const { return ( (PreviewStylePacker::Marshalling(previewStyle_, parcel) == RET_OK) && (PreviewAnimationPacker::Marshalling(previewAnimation_, parcel) == RET_OK) ); } bool UpdatePreviewAnimationParam::Unmarshalling(MessageParcel &parcel) { return ( (PreviewStylePacker::UnMarshalling(parcel, previewStyle_) == RET_OK) && (PreviewAnimationPacker::UnMarshalling(parcel, previewAnimation_) == RET_OK) ); } RotateDragWindowSyncParam::RotateDragWindowSyncParam(const std::shared_ptr& rsTransaction) : rsTransaction_(rsTransaction) {} bool RotateDragWindowSyncParam::Marshalling(MessageParcel &parcel) const { if (rsTransaction_ == nullptr) { FI_HILOGE("rsTransaction_ is nullptr"); return false; } if (!parcel.WriteParcelable(rsTransaction_.get())) { FI_HILOGE("Write transaction sync id failed"); return false; } return true; } bool RotateDragWindowSyncParam::Unmarshalling(MessageParcel &parcel) { std::shared_ptr rsTransaction(parcel.ReadParcelable()); if (rsTransaction == nullptr) { FI_HILOGE("UnMarshalling rsTransaction failed"); return false; } rsTransaction_ = rsTransaction; return true; } SetDragWindowScreenIdParam::SetDragWindowScreenIdParam(uint64_t displayId, uint64_t screenId) : displayId_(displayId), screenId_(screenId) {} bool SetDragWindowScreenIdParam::Marshalling(MessageParcel &parcel) const { return (parcel.WriteUint64(displayId_) && parcel.WriteUint64(screenId_)); } bool SetDragWindowScreenIdParam::Unmarshalling(MessageParcel &parcel) { return (parcel.ReadUint64(displayId_) && parcel.ReadUint64(screenId_)); } AddDraglistenerParam::AddDraglistenerParam(bool isJsCaller) : isJsCaller_(isJsCaller) {} bool AddDraglistenerParam::Marshalling(MessageParcel &parcel) const { return parcel.WriteBool(isJsCaller_); } bool AddDraglistenerParam::Unmarshalling(MessageParcel &parcel) { return parcel.ReadBool(isJsCaller_); } RemoveDraglistenerParam::RemoveDraglistenerParam(bool isJsCaller) : isJsCaller_(isJsCaller) {} bool RemoveDraglistenerParam::Marshalling(MessageParcel &parcel) const { return parcel.WriteBool(isJsCaller_); } bool RemoveDraglistenerParam::Unmarshalling(MessageParcel &parcel) { return parcel.ReadBool(isJsCaller_); } GetDragSummaryParam::GetDragSummaryParam(bool isJsCaller) : isJsCaller_(isJsCaller) {} bool GetDragSummaryParam::Marshalling(MessageParcel &parcel) const { return parcel.WriteBool(isJsCaller_); } bool GetDragSummaryParam::Unmarshalling(MessageParcel &parcel) { return parcel.ReadBool(isJsCaller_); } GetDragSummaryReply::GetDragSummaryReply(std::map &&summary) : summary_(std::move(summary)) {} bool GetDragSummaryReply::Marshalling(MessageParcel &parcel) const { return (SummaryPacker::Marshalling(summary_, parcel) == RET_OK); } bool GetDragSummaryReply::Unmarshalling(MessageParcel &parcel) { return (SummaryPacker::UnMarshalling(parcel, summary_) == RET_OK); } GetDragStateReply::GetDragStateReply(DragState dragState) : dragState_(dragState) {} bool GetDragStateReply::Marshalling(MessageParcel &parcel) const { return parcel.WriteInt32(static_cast(dragState_)); } bool GetDragStateReply::Unmarshalling(MessageParcel &parcel) { int32_t dragState { -1 }; if (!parcel.ReadInt32(dragState) || (dragState < static_cast(DragState::ERROR)) || (dragState > static_cast(DragState::MOTION_DRAGGING))) { return false; } dragState_ = static_cast(dragState); return true; } GetDragActionReply::GetDragActionReply(DragAction dragAction) : dragAction_(dragAction) {} bool GetDragActionReply::Marshalling(MessageParcel &parcel) const { return parcel.WriteInt32(static_cast(dragAction_)); } bool GetDragActionReply::Unmarshalling(MessageParcel &parcel) { int32_t dragAction { -1 }; if (!parcel.ReadInt32(dragAction) || (dragAction < static_cast(DragAction::INVALID)) || (dragAction > static_cast(DragAction::COPY))) { return false; } dragAction_ = static_cast(dragAction); return true; } GetExtraInfoReply::GetExtraInfoReply(std::string &&extraInfo) : extraInfo_(std::move(extraInfo)) {} bool GetExtraInfoReply::Marshalling(MessageParcel &parcel) const { return parcel.WriteString(extraInfo_); } bool GetExtraInfoReply::Unmarshalling(MessageParcel &parcel) { return parcel.ReadString(extraInfo_); } } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS