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 #ifndef INTENTION_DRAG_CLIENT_H 17 #define INTENTION_DRAG_CLIENT_H 18 19 #include "nocopyable.h" 20 21 #include <set> 22 23 #include "i_drag_listener.h" 24 #include "i_subscript_listener.h" 25 #include "i_tunnel_client.h" 26 #include "i_start_drag_listener.h" 27 #include "socket_client.h" 28 #include "transaction/rs_transaction.h" 29 30 namespace OHOS { 31 namespace Msdp { 32 namespace DeviceStatus { 33 class DragClient final { 34 public: 35 DragClient() = default; 36 ~DragClient() = default; 37 DISALLOW_COPY_AND_MOVE(DragClient); 38 39 int32_t StartDrag(ITunnelClient &tunnel, const DragData &dragData, std::shared_ptr<IStartDragListener> listener); 40 int32_t StopDrag(ITunnelClient &tunnel, const DragDropResult &dropResult); 41 int32_t AddDraglistener(ITunnelClient &tunnel, DragListenerPtr listener, bool isJsCaller = false); 42 int32_t RemoveDraglistener(ITunnelClient &tunnel, DragListenerPtr listener, bool isJsCaller = false); 43 int32_t AddSubscriptListener(ITunnelClient &tunnel, SubscriptListenerPtr listener); 44 int32_t RemoveSubscriptListener(ITunnelClient &tunnel, SubscriptListenerPtr listener); 45 int32_t SetDragWindowVisible(ITunnelClient &tunnel, bool visible, bool isForce); 46 int32_t UpdateDragStyle(ITunnelClient &tunnel, DragCursorStyle style, int32_t eventId = -1); 47 int32_t UpdateShadowPic(ITunnelClient &tunnel, const ShadowInfo &shadowInfo); 48 int32_t GetDragTargetPid(ITunnelClient &tunnel); 49 int32_t GetUdKey(ITunnelClient &tunnel, std::string &udKey); 50 int32_t GetShadowOffset(ITunnelClient &tunnel, ShadowOffset &shadowOffset); 51 int32_t GetDragData(ITunnelClient &tunnel, DragData &dragData); 52 int32_t UpdatePreviewStyle(ITunnelClient &tunnel, const PreviewStyle &previewStyle); 53 int32_t UpdatePreviewStyleWithAnimation(ITunnelClient &tunnel, 54 const PreviewStyle &previewStyle, const PreviewAnimation &animation); 55 int32_t RotateDragWindowSync(ITunnelClient &tunnel, 56 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr); 57 int32_t SetDragWindowScreenId(ITunnelClient &tunnel, uint64_t displayId, uint64_t screenId); 58 int32_t GetDragSummary(ITunnelClient &tunnel, std::map<std::string, int64_t> &summary, 59 bool isJsCaller = false); 60 int32_t SetDragSwitchState(ITunnelClient &tunnel, bool enable, bool isJsCaller = false); 61 int32_t SetAppDragSwitchState(ITunnelClient &tunnel, bool enable, const std::string &pkgName, 62 bool isJsCaller = false); 63 int32_t GetDragState(ITunnelClient &tunnel, DragState &dragState); 64 int32_t EnableUpperCenterMode(ITunnelClient &tunnel, bool enable); 65 int32_t GetDragAction(ITunnelClient &tunnel, DragAction &dragAction); 66 int32_t GetExtraInfo(ITunnelClient &tunnel, std::string &extraInfo); 67 int32_t AddPrivilege(ITunnelClient &tunnel); 68 int32_t EraseMouseIcon(ITunnelClient &tunnel); 69 int32_t AddSelectedPixelMap(ITunnelClient &tunnel, std::shared_ptr<OHOS::Media::PixelMap> pixelMap, 70 std::function<void(bool)> callback); 71 int32_t SetMouseDragMonitorState(ITunnelClient &tunnel, bool state); 72 73 int32_t OnNotifyResult(const StreamClient &client, NetPacket &pkt); 74 int32_t OnNotifyHideIcon(const StreamClient& client, NetPacket& pkt); 75 int32_t OnStateChangedMessage(const StreamClient &client, NetPacket &pkt); 76 int32_t OnDragStyleChangedMessage(const StreamClient &client, NetPacket &pkt); 77 int32_t OnAddSelectedPixelMapResult(const StreamClient &client, NetPacket &pkt); 78 void OnConnected(ITunnelClient &tunnel); 79 void OnDisconnected(ITunnelClient &tunnel); 80 int32_t SetDraggableState(ITunnelClient &tunnel, bool state); 81 int32_t GetAppDragSwitchState(ITunnelClient &tunnel, bool &state); 82 void SetDraggableStateAsync(ITunnelClient &tunnel, bool state, int64_t downTime); 83 84 private: 85 mutable std::mutex mtx_; 86 std::shared_ptr<IStartDragListener> startDragListener_ { nullptr }; 87 bool hasRegistered_ { false }; 88 bool hasSubscriptRegistered_ { false }; 89 std::set<DragListenerPtr> dragListeners_; 90 std::set<DragListenerPtr> connectedDragListeners_; 91 std::set<SubscriptListenerPtr> subscriptListeners_; 92 std::function<void(bool)> addSelectedPixelMapCallback_; 93 }; 94 } // namespace DeviceStatus 95 } // namespace Msdp 96 } // namespace OHOS 97 #endif // INTENTION_DRAG_CLIENT_H 98