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_SERVICE_H 17 #define DEVICESTATUS_SERVICE_H 18 19 #include <memory> 20 21 #include <iremote_object.h> 22 #include <system_ability.h> 23 24 #include "delegate_tasks.h" 25 #include "device_manager.h" 26 #include "devicestatus_delayed_sp_singleton.h" 27 #include "devicestatus_dumper.h" 28 #include "devicestatus_manager.h" 29 #include "devicestatus_srv_stub.h" 30 #include "drag_data.h" 31 #include "drag_manager.h" 32 #include "i_context.h" 33 #ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK 34 #include "dinput_adapter.h" 35 #include "plugin_manager.h" 36 #include "input_adapter.h" 37 #include "intention_service.h" 38 #include "socket_session_manager.h" 39 #endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK 40 #include "stationary_callback.h" 41 #include "stationary_data.h" 42 #include "stream_server.h" 43 #include "timer_manager.h" 44 45 namespace OHOS { 46 namespace Msdp { 47 class MotionDrag; 48 namespace DeviceStatus { 49 enum class ServiceRunningState {STATE_NOT_START, STATE_RUNNING, STATE_EXIT}; 50 class DeviceStatusService final : public IContext, 51 public StreamServer, 52 public SystemAbility, 53 public DeviceStatusSrvStub { 54 DECLARE_SYSTEM_ABILITY(DeviceStatusService) 55 DECLARE_DELAYED_SP_SINGLETON(DeviceStatusService); 56 public: 57 virtual void OnDump() override; 58 virtual void OnStart() override; 59 virtual void OnStop() override; 60 61 IDelegateTasks& GetDelegateTasks() override; 62 IDeviceManager& GetDeviceManager() override; 63 ITimerManager& GetTimerManager() override; 64 IDragManager& GetDragManager() override; 65 66 #ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK 67 IPluginManager& GetPluginManager() override; 68 ISocketSessionManager& GetSocketSessionManager() override; 69 IInputAdapter& GetInput() override; 70 IDInputAdapter& GetDInput() override; 71 #endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK 72 73 void Subscribe(Type type, ActivityEvent event, ReportLatencyNs latency, 74 sptr<IRemoteDevStaCallback> callback) override; 75 void Unsubscribe(Type type, ActivityEvent event, sptr<IRemoteDevStaCallback> callback) override; 76 Data GetCache(const Type &type) override; 77 bool IsServiceReady() const; 78 std::shared_ptr<DeviceStatusManager> GetDeviceStatusManager() const; 79 int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override; 80 void ReportSensorSysEvent(int32_t type, bool enable); 81 int32_t RegisterCoordinationListener(bool isCompatible = false) override; 82 int32_t UnregisterCoordinationListener(bool isCompatible = false) override; 83 int32_t PrepareCoordination(int32_t userData, bool isCompatible = false) override; 84 int32_t UnprepareCoordination(int32_t userData, bool isCompatible = false) override; 85 int32_t ActivateCoordination(int32_t userData, const std::string &remoteNetworkId, int32_t startDeviceId, 86 bool isCompatible = false) override; 87 int32_t DeactivateCoordination(int32_t userData, bool isUnchained, bool isCompatible = false) override; 88 int32_t GetCoordinationState(int32_t userData, const std::string &networkId, 89 bool isCompatible = false) override; 90 int32_t StartDrag(const DragData &dragData) override; 91 int32_t StopDrag(const DragDropResult &dropResult) override; 92 int32_t UpdateDragStyle(DragCursorStyle style) override; 93 int32_t GetDragTargetPid() override; 94 int32_t GetUdKey(std::string &udKey) override; 95 int32_t AddDraglistener() override; 96 int32_t RemoveDraglistener() override; 97 int32_t AddSubscriptListener() override; 98 int32_t RemoveSubscriptListener() override; 99 int32_t SetDragWindowVisible(bool visible, bool isForce = false) override; 100 int32_t EnterTextEditorArea(bool enable) override; 101 int32_t GetShadowOffset(int32_t &offsetX, int32_t &offsetY, int32_t &width, int32_t &height) override; 102 int32_t UpdateShadowPic(const ShadowInfo &shadowInfo) override; 103 int32_t GetDragData(DragData &dragData) override; 104 int32_t GetDragState(DragState &dragState) override; 105 int32_t GetDragAction(DragAction &dragAction) override; 106 int32_t GetExtraInfo(std::string &extraInfo) override; 107 int32_t AllocSocketFd(const std::string &programName, int32_t moduleType, 108 int32_t &toReturnClientFd, int32_t &tokenType) override; 109 void OnConnected(SessionPtr s) override; 110 void OnDisconnected(SessionPtr s) override; 111 int32_t AddEpoll(EpollEventType type, int32_t fd) override; 112 int32_t DelEpoll(EpollEventType type, int32_t fd); 113 bool IsRunning() const override; 114 int32_t AddHotAreaListener() override; 115 int32_t RemoveHotAreaListener() override; 116 int32_t UpdatePreviewStyle(const PreviewStyle &previewStyle) override; 117 int32_t UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle, 118 const PreviewAnimation &animation) override; 119 int32_t GetDragSummary(std::map<std::string, int64_t> &summarys) override; 120 int32_t AddPrivilege() override; 121 122 private: 123 bool Init(); 124 int32_t InitDelegateTasks(); 125 int32_t InitTimerMgr(); 126 int32_t InitMotionDrag(); 127 void OnThread(); 128 void OnDelegateTask(const epoll_event &ev); 129 void OnTimeout(const epoll_event &ev); 130 void OnDeviceMgr(const epoll_event &ev); 131 int32_t EnableDevMgr(int32_t nRetries); 132 void DisableDevMgr(); 133 int32_t OnAddHotAreaListener(int32_t pid); 134 int32_t OnRemoveHotAreaListener(int32_t pid); 135 136 #ifdef OHOS_BUILD_ENABLE_COORDINATION 137 int32_t OnRegisterCoordinationListener(int32_t pid); 138 int32_t OnUnregisterCoordinationListener(int32_t pid); 139 int32_t OnPrepareCoordination(int32_t pid, int32_t userData); 140 int32_t OnUnprepareCoordination(int32_t pid, int32_t userData); 141 int32_t OnActivateCoordination(int32_t pid, int32_t userData, const std::string &remoteNetworkId, 142 int32_t startDeviceId); 143 int32_t OnDeactivateCoordination(int32_t pid, int32_t userData, bool isUnchained); 144 int32_t OnGetCoordinationState(int32_t pid, int32_t userData, const std::string &networkId); 145 #endif // OHOS_BUILD_ENABLE_COORDINATION 146 147 private: 148 std::atomic<ServiceRunningState> state_ { ServiceRunningState::STATE_NOT_START }; 149 std::thread worker_; 150 DelegateTasks delegateTasks_; 151 DeviceManager devMgr_; 152 TimerManager timerMgr_; 153 std::atomic<bool> ready_ { false }; 154 std::shared_ptr<DeviceStatusManager> devicestatusManager_ { nullptr }; 155 DragManager dragMgr_; 156 #ifdef OHOS_BUILD_ENABLE_MOTION_DRAG 157 std::unique_ptr<MotionDrag> motionDrag_ { nullptr }; 158 #endif // OHOS_BUILD_ENABLE_MOTION_DRAG 159 #ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK 160 SocketSessionManager socketSessionMgr_; 161 PluginManager pluginMgr_; 162 InputAdapter input_; 163 std::shared_ptr<DInputAdapter> dinput_; 164 sptr<IntentionService> intention_; 165 #endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK 166 }; 167 } // namespace DeviceStatus 168 } // namespace Msdp 169 } // namespace OHOS 170 #endif // DEVICESTATUS_SERVICE_H 171