1 /* 2 * Copyright (c) 2025 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 // Implementation of client side of IPC. 17 18 #ifndef INTENTION_CLIENT_H 19 #define INTENTION_CLIENT_H 20 21 #include <memory> 22 23 #include "iintention.h" 24 25 namespace OHOS { 26 namespace Msdp { 27 namespace DeviceStatus { 28 class IntentionClient final : public std::enable_shared_from_this<IntentionClient> { 29 public: 30 IntentionClient() = default; 31 ~IntentionClient(); 32 DISALLOW_COPY_AND_MOVE(IntentionClient); 33 static IntentionClient *GetInstance(); 34 // Socket 35 ErrCode Socket(const std::string& programName, int32_t moduleType, int& socketFd, int32_t& tokenType); 36 37 // Cooperate 38 int32_t EnableCooperate(int32_t userData); 39 int32_t DisableCooperate(int32_t userData); 40 int32_t StartCooperate(const std::string& remoteNetworkId, int32_t userData, int32_t startDeviceId, 41 bool checkPermission); 42 int32_t StartCooperateWithOptions(const std::string &remoteNetworkId, 43 int32_t userData, int32_t startDeviceId, bool checkPermission, const CooperateOptions &options); 44 int32_t StopCooperate(int32_t userData, bool isUnchained, bool checkPermission); 45 int32_t RegisterCooperateListener(); 46 int32_t UnregisterCooperateListener(); 47 int32_t RegisterHotAreaListener(int32_t userData, bool checkPermission); 48 int32_t UnregisterHotAreaListener(int32_t userData, bool checkPermission); 49 int32_t RegisterMouseEventListener(const std::string& networkId); 50 int32_t UnregisterMouseEventListener(const std::string& networkId); 51 int32_t GetCooperateStateSync(const std::string& udid, bool& state); 52 int32_t GetCooperateStateAsync(const std::string& networkId, int32_t userData, bool isCheckPermission); 53 int32_t SetDamplingCoefficient(uint32_t direction, double coefficient); 54 55 // Drag 56 int32_t StartDrag(const DragData &dragData); 57 int32_t StopDrag(const DragDropResult &dropResult); 58 int32_t EnableInternalDropAnimation(const std::string &animationInfo); 59 int32_t AddDraglistener(bool isJsCaller); 60 int32_t RemoveDraglistener(bool isJsCaller); 61 int32_t AddSubscriptListener(); 62 int32_t RemoveSubscriptListener(); 63 int32_t SetDragWindowVisible(bool visible, bool isForce, 64 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction); 65 int32_t UpdateDragStyle(DragCursorStyle style, int32_t eventId); 66 int32_t UpdateShadowPic(const ShadowInfo &shadowInfo); 67 int32_t GetDragTargetPid(int32_t &targetPid); 68 int32_t GetUdKey(std::string &udKey); 69 int32_t GetShadowOffset(ShadowOffset &shadowOffset); 70 int32_t GetDragData(DragData &dragData); 71 int32_t UpdatePreviewStyle(const PreviewStyle &previewStyle); 72 int32_t UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle, const PreviewAnimation &animation); 73 int32_t RotateDragWindowSync(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction); 74 int32_t SetDragWindowScreenId(uint64_t displayId, uint64_t screenId); 75 int32_t GetDragSummary(std::map<std::string, int64_t> &summarys, bool isJsCaller); 76 int32_t SetDragSwitchState(bool enable, bool isJsCaller); 77 int32_t SetAppDragSwitchState(bool enable, const std::string &pkgName, bool isJsCaller); 78 int32_t GetDragState(DragState &dragState); 79 int32_t EnableUpperCenterMode(bool enable); 80 int32_t GetDragAction(DragAction &dragAction); 81 int32_t GetExtraInfo(std::string &extraInfo); 82 int32_t AddPrivilege(); 83 int32_t EraseMouseIcon(); 84 int32_t SetMouseDragMonitorState(bool state); 85 int32_t SetDraggableState(bool state); 86 int32_t GetAppDragSwitchState(bool &state); 87 int32_t SetDraggableStateAsync(bool state, int64_t downTime); 88 int32_t GetDragBundleInfo(DragBundleInfo &dragBundleInfo); 89 int32_t IsDragStart(bool &isStart); 90 int32_t GetDragSummaryInfo(DragSummaryInfo &dragSummaryInfo); 91 92 // Boomerang 93 int32_t SubscribeCallback(int32_t type, const std::string& bundleName, 94 const sptr<IRemoteBoomerangCallback>& subCallback); 95 int32_t UnsubscribeCallback(int32_t type, const std::string& bundleName, 96 const sptr<IRemoteBoomerangCallback>& unsubCallback); 97 int32_t NotifyMetadataBindingEvent(const std::string& bundleName, 98 const sptr<IRemoteBoomerangCallback>& notifyCallback); 99 int32_t SubmitMetadata(const std::string& metadata); 100 int32_t BoomerangEncodeImage(const std::shared_ptr<PixelMap>& pixelMap, const std::string& metadata, 101 const sptr<IRemoteBoomerangCallback>& encodeCallback); 102 int32_t BoomerangDecodeImage(const std::shared_ptr<PixelMap>& pixelMap, 103 const sptr<IRemoteBoomerangCallback>& decodeCallback); 104 105 // Stationary 106 int32_t SubscribeStationaryCallback(int32_t type, int32_t event, 107 int32_t latency, const sptr<IRemoteDevStaCallback> &subCallback); 108 int32_t UnsubscribeStationaryCallback(int32_t type, int32_t event, 109 const sptr<IRemoteDevStaCallback> &unsubCallback); 110 int32_t GetDeviceStatusData(int32_t type, int32_t &replyType, int32_t &replyValue); 111 int32_t GetDevicePostureDataSync(DevicePostureData &postureData); 112 113 // OnScreen 114 int32_t GetPageContent(const OnScreen::ContentOption& option, OnScreen::PageContent& pageContent); 115 int32_t SendControlEvent(const OnScreen::ControlEvent& event); 116 117 private: 118 class DeathRecipient : public IRemoteObject::DeathRecipient { 119 public: 120 DeathRecipient(std::shared_ptr<IntentionClient> parent); 121 ~DeathRecipient() = default; 122 void OnRemoteDied(const wptr<IRemoteObject> &remote); 123 124 private: 125 std::weak_ptr<IntentionClient> parent_; 126 }; 127 128 ErrCode Connect(); 129 void ResetProxy(const wptr<IRemoteObject> &remote); 130 131 private: 132 std::mutex mutex_; 133 sptr<IIntention> devicestatusProxy_ { nullptr }; 134 sptr<IRemoteObject::DeathRecipient> deathRecipient_ { nullptr }; 135 static std::shared_ptr<IntentionClient> instance_; 136 }; 137 138 #define INTENTION_CLIENT OHOS::Msdp::DeviceStatus::IntentionClient::GetInstance() 139 } // namespace DeviceStatus 140 } // namespace Msdp 141 } // namespace OHOS 142 #endif // INTENTION_CLIENT_H