1 /* 2 * Copyright (c) 2021-2022 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 INPUT_DEVICE_MANAGER_H 17 #define INPUT_DEVICE_MANAGER_H 18 19 #include <list> 20 #include <string> 21 22 #include "device_observer.h" 23 #include "event_dispatch_handler.h" 24 #include "key_event_normalize.h" 25 #include "input_device.h" 26 #include "key_auto_repeat.h" 27 #include "key_map_manager.h" 28 #include "msg_handler.h" 29 #include "nocopyable.h" 30 #include "pointer_drawing_manager.h" 31 #include "singleton.h" 32 #include "util.h" 33 34 namespace OHOS { 35 namespace MMI { 36 class InputDeviceManager final : public IDeviceObject { 37 DECLARE_DELAYED_SINGLETON(InputDeviceManager); 38 39 struct InputDeviceInfo { 40 struct libinput_device *inputDeviceOrigin { nullptr }; 41 std::string networkIdOrigin; 42 bool isRemote { false }; 43 bool isPointerDevice { false }; 44 bool isTouchableDevice { false }; 45 std::string dhid; 46 }; 47 public: 48 DISALLOW_COPY_AND_MOVE(InputDeviceManager); 49 void OnInputDeviceAdded(struct libinput_device *inputDevice); 50 void OnInputDeviceRemoved(struct libinput_device *inputDevice); 51 std::vector<int32_t> GetInputDeviceIds() const; 52 std::shared_ptr<InputDevice> GetInputDevice(int32_t id) const; 53 int32_t SupportKeys(int32_t deviceId, std::vector<int32_t> &keyCodes, std::vector<bool> &keystroke); 54 int32_t FindInputDeviceId(struct libinput_device* inputDevice); 55 int32_t GetKeyboardBusMode(int32_t deviceId); 56 bool GetDeviceConfig(int32_t deviceId, int32_t &KeyboardType); 57 int32_t GetDeviceSupportKey(int32_t deviceId, int32_t &keyboardType); 58 int32_t GetKeyboardType(int32_t deviceId, int32_t &keyboardType); 59 void Attach(std::shared_ptr<IDeviceObserver> observer); 60 void Detach(std::shared_ptr<IDeviceObserver> observer); 61 void NotifyPointerDevice(bool hasPointerDevice, bool isVisible); 62 void AddDevListener(SessionPtr sess, std::function<void(int32_t, const std::string&)> callback); 63 void RemoveDevListener(SessionPtr sess); 64 void Dump(int32_t fd, const std::vector<std::string> &args); 65 void DumpDeviceList(int32_t fd, const std::vector<std::string> &args); 66 bool IsRemote(struct libinput_device *inputDevice) const; 67 bool IsRemote(int32_t id) const; 68 #ifdef OHOS_BUILD_ENABLE_COOPERATE 69 std::string GetOriginNetworkId(int32_t id); 70 std::string GetOriginNetworkId(const std::string &dhid); 71 std::string GetDhid(int32_t deviceId) const; 72 std::vector<std::string> GetCooperateDhids(int32_t deviceId); 73 std::vector<std::string> GetCooperateDhids(const std::string &dhid); 74 bool HasLocalPointerDevice() const; 75 void NotifyVirtualKeyBoardStatus(int32_t deviceId, bool isAvailable) const; 76 #endif // OHOS_BUILD_ENABLE_COOPERATE 77 bool IsKeyboardDevice(struct libinput_device* device) const; 78 bool IsPointerDevice(struct libinput_device* device) const; 79 bool IsTouchDevice(struct libinput_device* device) const; 80 struct libinput_device* GetKeyboardDevice() const; 81 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING 82 bool HasPointerDevice(); 83 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING 84 bool HasTouchDevice(); 85 int32_t SetInputDevice(const std::string& dhid, const std::string& screenId); 86 const std::string& GetScreenId(int32_t deviceId) const; 87 88 private: 89 int32_t ParseDeviceId(const std::string &sysName); 90 void MakeDeviceInfo(struct libinput_device *inputDevice, struct InputDeviceInfo& info); 91 bool IsMatchKeys(struct libinput_device* device, const std::vector<int32_t> &keyCodes) const; 92 void ScanPointerDevice(); 93 #ifdef OHOS_BUILD_ENABLE_COOPERATE 94 std::string MakeNetworkId(const char *phys) const; 95 std::string Sha256(const std::string &in) const; 96 std::string GenerateDescriptor(struct libinput_device *inputDevice, bool isRemote) const; 97 #endif // OHOS_BUILD_ENABLE_COOPERATE 98 std::map<int32_t, struct InputDeviceInfo> inputDevice_; 99 std::map<std::string, std::string> inputDeviceScreens_; 100 std::list<std::shared_ptr<IDeviceObserver>> observers_; 101 std::map<SessionPtr, std::function<void(int32_t, const std::string&)>> devListener_; 102 }; 103 104 #define InputDevMgr ::OHOS::DelayedSingleton<InputDeviceManager>::GetInstance() 105 } // namespace MMI 106 } // namespace OHOS 107 #endif // INPUT_DEVICE_MANAGER_H 108