1 /* 2 * Copyright (c) 2022-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 DEVICESTATUS_CLIENT_H 17 #define DEVICESTATUS_CLIENT_H 18 19 #include <functional> 20 #include <map> 21 22 #include <singleton.h> 23 24 #include "devicestatus_common.h" 25 #include "drag_data.h" 26 #include "i_coordination_listener.h" 27 #include "i_devicestatus.h" 28 #include "stationary_callback.h" 29 #include "stationary_data.h" 30 31 namespace OHOS { 32 namespace Msdp { 33 namespace DeviceStatus { 34 class DeviceStatusClient final : public DelayedRefSingleton<DeviceStatusClient> { DECLARE_DELAYED_REF_SINGLETON(DeviceStatusClient)35 DECLARE_DELAYED_REF_SINGLETON(DeviceStatusClient) 36 37 public: 38 std::map<Type, int32_t> GetTypeMap() 39 { 40 return typeMap_; 41 } 42 DISALLOW_COPY_AND_MOVE(DeviceStatusClient); 43 44 int32_t SubscribeCallback(Type type, ActivityEvent event, ReportLatencyNs latency, 45 sptr<IRemoteDevStaCallback> callback); 46 int32_t UnsubscribeCallback(Type type, ActivityEvent event, sptr<IRemoteDevStaCallback> callback); 47 Data GetDeviceStatusData(const Type type); 48 void RegisterDeathListener(std::function<void()> deathListener); 49 int32_t RegisterCoordinationListener(bool isCompatible = false); 50 int32_t UnregisterCoordinationListener(bool isCompatible = false); 51 int32_t PrepareCoordination(int32_t userData, bool isCompatible = false); 52 int32_t UnprepareCoordination(int32_t userData, bool isCompatible = false); 53 int32_t ActivateCoordination(int32_t userData, 54 const std::string &remoteNetworkId, int32_t startDeviceId, bool isCompatible = false); 55 int32_t DeactivateCoordination(int32_t userData, bool isUnchained, bool isCompatible = false); 56 int32_t GetCoordinationState(int32_t userData, const std::string &networkId, bool isCompatible = false); 57 int32_t GetCoordinationState(const std::string &udId, bool &state); 58 int32_t StartDrag(const DragData &dragData); 59 int32_t StopDrag(const DragDropResult &dropResult); 60 int32_t UpdateDragStyle(DragCursorStyle style); 61 int32_t GetDragTargetPid(); 62 int32_t GetUdKey(std::string &udKey); 63 int32_t AddDraglistener(); 64 int32_t RemoveDraglistener(); 65 int32_t AddSubscriptListener(); 66 int32_t RemoveSubscriptListener(); 67 int32_t SetDragWindowVisible(bool visible, bool isForce = false); 68 int32_t GetShadowOffset(ShadowOffset &shadowOffset); 69 int32_t UpdateShadowPic(const ShadowInfo &shadowInfo); 70 int32_t GetDragData(DragData &dragData); 71 int32_t GetDragState(DragState &dragState); 72 int32_t GetDragAction(DragAction &dragAction); 73 int32_t GetExtraInfo(std::string &extraInfo); 74 int32_t AllocSocketPair(int32_t moduleType); 75 int32_t GetClientSocketFdOfAllocedSocketPair() const; 76 int32_t AddHotAreaListener(); 77 int32_t RemoveHotAreaListener(); 78 int32_t UpdatePreviewStyle(const PreviewStyle &previewStyle); 79 int32_t UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle, const PreviewAnimation &animation); 80 int32_t GetDragSummary(std::map<std::string, int64_t> &summarys); 81 int32_t EnterTextEditorArea(bool enable); 82 int32_t AddPrivilege(); 83 int32_t EraseMouseIcon(); 84 85 private: 86 class DeviceStatusDeathRecipient : public IRemoteObject::DeathRecipient { 87 public: 88 DeviceStatusDeathRecipient() = default; 89 ~DeviceStatusDeathRecipient() = default; 90 void OnRemoteDied(const wptr<IRemoteObject> &remote); 91 92 private: 93 DISALLOW_COPY_AND_MOVE(DeviceStatusDeathRecipient); 94 }; 95 96 ErrCode Connect(); 97 void ResetProxy(const wptr<IRemoteObject> &remote); 98 99 sptr<Idevicestatus> devicestatusProxy_ { nullptr }; 100 sptr<IRemoteObject::DeathRecipient> deathRecipient_ { nullptr }; 101 std::mutex mutex_; 102 int32_t tokenType_ { -1 }; 103 int32_t socketFd_ { -1 }; 104 std::map<Type, int32_t> typeMap_; 105 std::function<void()> deathListener_ { nullptr }; 106 }; 107 } // namespace DeviceStatus 108 } // namespace Msdp 109 } // namespace OHOS 110 #endif // DEVICESTATUS_CLIENT_H 111