1 /* 2 * Copyright (c) 2021-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 #ifndef MULTIMODAL_INPUT_CONNECT_MANAGER_H 17 #define MULTIMODAL_INPUT_CONNECT_MANAGER_H 18 19 #include <system_ability_definition.h> 20 21 #include "i_input_service_watcher.h" 22 #include "imultimodal_input_connect.h" 23 24 namespace OHOS { 25 namespace MMI { 26 class MultimodalInputConnectManager final : public std::enable_shared_from_this<MultimodalInputConnectManager> { 27 public: 28 enum { 29 CONNECT_MODULE_TYPE_MMI_CLIENT = 0, 30 }; 31 static constexpr int32_t INVALID_SOCKET_FD = -1; 32 static constexpr int32_t MULTIMODAL_INPUT_CONNECT_SERVICE_ID = MULTIMODAL_INPUT_SERVICE_ID; 33 ~MultimodalInputConnectManager() = default; 34 static std::shared_ptr<MultimodalInputConnectManager> GetInstance(); 35 int32_t AllocSocketPair(const int32_t moduleType); 36 int32_t GetClientSocketFdOfAllocedSocketPair() const; GetTokenType()37 int32_t GetTokenType() const 38 { 39 return tokenType_; 40 } 41 int32_t AddInputEventFilter(sptr<IEventFilter> filter, int32_t filterId, int32_t priority, uint32_t deviceTags); 42 int32_t RemoveInputEventFilter(int32_t filterId); 43 int32_t NotifyNapOnline(); 44 int32_t RemoveInputEventObserver(); 45 int32_t SetNapStatus(int32_t pid, int32_t uid, const std::string &bundleName, int32_t napStatus); 46 int32_t GetDisplayBindInfo(DisplayBindInfos &infos); 47 int32_t GetAllMmiSubscribedEvents(std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> &datas); 48 int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg); 49 int32_t SetMouseScrollRows(int32_t rows); 50 int32_t GetMouseScrollRows(int32_t &rows); 51 int32_t SetPointerSize(int32_t size); 52 int32_t GetPointerSize(int32_t &size); 53 int32_t GetCursorSurfaceId(uint64_t &surfaceId); 54 int32_t SetCustomCursor(int32_t windowId, int32_t focusX, int32_t focusY, void* pixelMap); 55 int32_t SetCustomCursor(int32_t windowId, CustomCursor cursor, CursorOptions options); 56 int32_t SetMouseIcon(int32_t windowId, void* pixelMap); 57 int32_t SetMouseHotSpot(int32_t pid, int32_t windowId, int32_t hotSpotX, int32_t hotSpotY); 58 int32_t SetMousePrimaryButton(int32_t primaryButton); 59 int32_t GetMousePrimaryButton(int32_t &primaryButton); 60 int32_t SetHoverScrollState(bool state); 61 int32_t GetHoverScrollState(bool &state); 62 int32_t SetPointerVisible(bool visible, int32_t priority); 63 int32_t IsPointerVisible(bool &visible); 64 int32_t MarkProcessed(int32_t eventType, int32_t eventId); 65 int32_t SetPointerColor(int32_t color); 66 int32_t GetPointerColor(int32_t &color); 67 int32_t EnableCombineKey(bool enable); 68 int32_t SetPointerSpeed(int32_t speed); 69 int32_t GetPointerSpeed(int32_t &speed); 70 int32_t SetPointerStyle(int32_t windowId, PointerStyle pointerStyle, bool isUiExtension = false); 71 int32_t GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle, bool isUiExtension = false); 72 int32_t ClearWindowPointerStyle(int32_t pid, int32_t windowId); 73 int32_t SupportKeys(int32_t deviceId, std::vector<int32_t> &keys, std::vector<bool> &keystroke); 74 int32_t GetDeviceIds(std::vector<int32_t> &ids); 75 int32_t GetDevice(int32_t deviceId, std::shared_ptr<InputDevice> &inputDevice); 76 int32_t RegisterDevListener(); 77 int32_t UnregisterDevListener(); 78 int32_t GetKeyboardType(int32_t deviceId, int32_t &keyboardType); 79 int32_t SetKeyboardRepeatDelay(int32_t delay); 80 int32_t SetKeyboardRepeatRate(int32_t rate); 81 int32_t GetKeyboardRepeatDelay(int32_t &delay); 82 int32_t GetKeyboardRepeatRate(int32_t &rate); 83 int32_t AddInputHandler(InputHandlerType handlerType, HandleEventType eventType, int32_t priority, 84 uint32_t deviceTags, std::vector<int32_t> actionsType = std::vector<int32_t>()); 85 int32_t RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType, int32_t priority, 86 uint32_t deviceTags, std::vector<int32_t> actionsType = std::vector<int32_t>()); 87 int32_t AddPreInputHandler(int32_t handlerId, HandleEventType eventType, std::vector<int32_t> keys); 88 int32_t RemovePreInputHandler(int32_t handlerId); 89 int32_t AddGestureMonitor(InputHandlerType handlerType, 90 HandleEventType eventType, TouchGestureType gestureType, int32_t fingers); 91 int32_t RemoveGestureMonitor(InputHandlerType handlerType, 92 HandleEventType eventType, TouchGestureType gestureType, int32_t fingers); 93 int32_t MarkEventConsumed(int32_t eventId); 94 int32_t MoveMouseEvent(int32_t offsetX, int32_t offsetY); 95 int32_t InjectKeyEvent(const std::shared_ptr<KeyEvent> keyEvent, bool isNativeInject); 96 int32_t SubscribeKeyEvent(int32_t subscribeId, const std::shared_ptr<KeyOption> option); 97 int32_t UnsubscribeKeyEvent(int32_t subscribeId); 98 int32_t SubscribeHotkey(int32_t subscribeId, const std::shared_ptr<KeyOption> option); 99 int32_t UnsubscribeHotkey(int32_t subscribeId); 100 #ifdef OHOS_BUILD_ENABLE_KEY_PRESSED_HANDLER 101 int32_t SubscribeKeyMonitor(const KeyMonitorOption &keyOption); 102 int32_t UnsubscribeKeyMonitor(const KeyMonitorOption &keyOption); 103 #endif // OHOS_BUILD_ENABLE_KEY_PRESSED_HANDLER 104 int32_t SubscribeSwitchEvent(int32_t subscribeId, int32_t switchType); 105 int32_t UnsubscribeSwitchEvent(int32_t subscribeId); 106 int32_t QuerySwitchStatus(int32_t switchType, int32_t& state); 107 int32_t SubscribeTabletProximity(int32_t subscribeId); 108 int32_t UnsubscribetabletProximity(int32_t subscribeId); 109 int32_t SubscribeLongPressEvent(int32_t subscribeId, const LongPressRequest &longPressRequest); 110 int32_t UnsubscribeLongPressEvent(int32_t subscribeId); 111 int32_t InjectPointerEvent(const std::shared_ptr<PointerEvent> pointerEvent, bool isNativeInject, 112 int32_t useCoordinate); 113 int32_t InjectTouchPadEvent(std::shared_ptr<PointerEvent> pointerEvent, const TouchpadCDG &touchpadCDG, 114 bool isNativeInject); 115 int32_t SetAnrObserver(); 116 int32_t GetFunctionKeyState(int32_t funcKey, bool &state); 117 int32_t SetFunctionKeyState(int32_t funcKey, bool enable); 118 int32_t SetPointerLocation(int32_t x, int32_t y, int32_t displayId); 119 int32_t GetPointerLocation(int32_t &displayId, double &displayX, double &displayY); 120 int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode); 121 int32_t GetWindowPid(int32_t windowId); 122 int32_t AppendExtraData(const ExtraData& extraData); 123 int32_t EnableInputDevice(bool enable); 124 int32_t SetKeyDownDuration(const std::string &businessId, int32_t delay); 125 int32_t SetTouchpadScrollSwitch(bool switchFlag); 126 int32_t GetTouchpadScrollSwitch(bool &switchFlag); 127 int32_t SetTouchpadScrollDirection(bool state); 128 int32_t GetTouchpadScrollDirection(bool &state); 129 int32_t SetTouchpadTapSwitch(bool switchFlag); 130 int32_t GetTouchpadTapSwitch(bool &switchFlag); 131 int32_t SetTouchpadPointerSpeed(int32_t speed); 132 int32_t GetTouchpadPointerSpeed(int32_t &speed); 133 int32_t GetTouchpadCDG(TouchpadCDG &touchpadCDG); 134 int32_t SetTouchpadPinchSwitch(bool switchFlag); 135 int32_t GetTouchpadPinchSwitch(bool &switchFlag); 136 int32_t SetTouchpadSwipeSwitch(bool switchFlag); 137 int32_t GetTouchpadSwipeSwitch(bool &switchFlag); 138 int32_t SetTouchpadRightClickType(int32_t type); 139 int32_t GetTouchpadRightClickType(int32_t &type); 140 int32_t SetTouchpadRotateSwitch(bool rotateSwitch); 141 int32_t GetTouchpadRotateSwitch(bool &rotateSwitch); 142 int32_t SetTouchpadDoubleTapAndDragState(bool switchFlag); 143 int32_t GetTouchpadDoubleTapAndDragState(bool &switchFlag); 144 int32_t SetShieldStatus(int32_t shieldMode, bool isShield); 145 int32_t GetShieldStatus(int32_t shieldMode, bool &isShield); 146 int32_t GetKeyState(std::vector<int32_t> &pressedKeys, std::map<int32_t, int32_t> &specialKeysState); 147 int32_t Authorize(bool isAuthorize); 148 int32_t CancelInjection(); 149 int32_t RequestInjection(int32_t &status, int32_t &reqId); 150 int32_t QueryAuthorizedStatus(int32_t &status); 151 int32_t HasIrEmitter(bool &hasIrEmitter); 152 int32_t GetInfraredFrequencies(std::vector<InfraredFrequency>& requencys); 153 int32_t TransmitInfrared(int64_t number, std::vector<int64_t>& pattern); 154 #ifdef OHOS_BUILD_ENABLE_VKEYBOARD 155 int32_t CreateVKeyboardDevice(sptr<IRemoteObject> &vkeyboardDevice); 156 #endif // OHOS_BUILD_ENABLE_VKEYBOARD 157 int32_t SetMoveEventFilters(bool flag); 158 void AddServiceWatcher(std::shared_ptr<IInputServiceWatcher> watcher); 159 void RemoveServiceWatcher(std::shared_ptr<IInputServiceWatcher> watcher); 160 int32_t SetPixelMapData(int32_t infoId, void* pixelMap); 161 int32_t SetCurrentUser(int32_t userId); 162 int32_t SetTouchpadThreeFingersTapSwitch(bool switchFlag); 163 int32_t GetTouchpadThreeFingersTapSwitch(bool &switchFlag); 164 int32_t EnableHardwareCursorStats(bool enable); 165 int32_t GetHardwareCursorStats(uint32_t &frameCount, uint32_t &vsyncCount); 166 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR 167 int32_t GetPointerSnapshot(void *pixelMapPtr); 168 #endif // OHOS_BUILD_ENABLE_MAGICCURSOR 169 int32_t AddVirtualInputDevice(std::shared_ptr<InputDevice> device, int32_t &deviceId); 170 int32_t RemoveVirtualInputDevice(int32_t deviceId); 171 int32_t SetTouchpadScrollRows(int32_t rows); 172 int32_t GetTouchpadScrollRows(int32_t &rows); 173 int32_t SkipPointerLayer(bool isSkip); 174 int32_t SetClientInfo(int32_t pid, uint64_t readThreadId); 175 int32_t GetIntervalSinceLastInput(int64_t &timeInterval); 176 177 #ifdef OHOS_BUILD_ENABLE_ANCO 178 int32_t AncoAddChannel(sptr<IAncoChannel> channel); 179 int32_t AncoRemoveChannel(sptr<IAncoChannel> channel); 180 int32_t CheckKnuckleEvent(float pointX, float pointY, bool &isKnuckleType); 181 #endif // OHOS_BUILD_ENABLE_ANCO 182 183 int32_t GetAllSystemHotkeys(std::vector<std::unique_ptr<KeyOption>> &keyOptions); 184 int32_t SetInputDeviceEnabled(int32_t deviceId, bool enable, int32_t index); 185 int32_t ShiftAppPointerEvent(const ShiftWindowParam ¶m, bool autoGenDown); 186 int32_t SetMultiWindowScreenId(uint64_t screenId, uint64_t displayNodeScreenId); 187 int32_t SetKnuckleSwitch(bool knuckleSwitch); 188 int32_t LaunchAiScreenAbility(); 189 int32_t GetMaxMultiTouchPointNum(int32_t &pointNum); 190 int32_t SetInputDeviceConsumer(const std::vector<std::string>& deviceNames); 191 int32_t ClearInputDeviceConsumer(const std::vector<std::string>& deviceNames); 192 int32_t SubscribeInputActive(int32_t subscribeId, int64_t interval); 193 int32_t UnsubscribeInputActive(int32_t subscribeId); 194 int32_t SetMouseAccelerateMotionSwitch(int32_t deviceId, bool enable); 195 int32_t SwitchScreenCapturePermission(uint32_t permissionType, bool enable); 196 int32_t ClearMouseHideFlag(int32_t eventId); 197 int32_t QueryPointerRecord(int32_t count, std::vector<std::shared_ptr<PointerEvent>> &pointerList); 198 199 private: 200 MultimodalInputConnectManager() = default; 201 DISALLOW_COPY_AND_MOVE(MultimodalInputConnectManager); 202 203 bool ConnectMultimodalInputService(); 204 void OnDeath(const wptr<IRemoteObject> &remoteObj); 205 void Clean(const wptr<IRemoteObject> &remoteObj); 206 void NotifyServiceDeath(); 207 void NotifyDeath(); 208 sptr<IMultimodalInputConnect> multimodalInputConnectService_ { nullptr }; 209 sptr<IRemoteObject::DeathRecipient> multimodalInputConnectRecipient_ { nullptr }; 210 int32_t socketFd_ { MultimodalInputConnectManager::INVALID_SOCKET_FD }; 211 int32_t tokenType_ { -1 }; 212 std::mutex lock_; 213 std::set<std::shared_ptr<IInputServiceWatcher>> watchers_; 214 }; 215 } // namespace MMI 216 } // namespace OHOS 217 #define MULTIMODAL_INPUT_CONNECT_MGR MultimodalInputConnectManager::GetInstance() 218 #endif // MULTIMODAL_INPUT_CONNECT_MANAGER_H