• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_config_file_parser.h"
23 #include "device_observer.h"
24 #include "input_device.h"
25 #include "msg_handler.h"
26 #include "nocopyable.h"
27 #include "singleton.h"
28 #include "uds_session.h"
29 #include "util.h"
30 
31 namespace OHOS {
32 namespace MMI {
33 class InputDeviceManager final : public IDeviceObject {
34     DECLARE_DELAYED_SINGLETON(InputDeviceManager);
35 
36     struct InputDeviceInfo {
37         struct libinput_device *inputDeviceOrigin { nullptr };
38         std::string networkIdOrigin;
39         bool isRemote { false };
40         bool isPointerDevice { false };
41         bool isTouchableDevice { false };
42         bool enable { false };
43         std::string dhid;
44         std::string sysUid;
45         VendorConfig vendorConfig;
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, bool checked = true) 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     bool IsKeyboardDevice(struct libinput_device* device) const;
69     bool IsPointerDevice(struct libinput_device* device) const;
70     bool IsTouchDevice(struct libinput_device* device) const;
71     struct libinput_device* GetKeyboardDevice() const;
72 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
73     bool HasPointerDevice();
74 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
75     bool HasTouchDevice();
76     const std::string& GetScreenId(int32_t deviceId) const;
77     using inputDeviceCallback = std::function<void(int32_t deviceId, std::string devName, std::string devStatus)>;
78     void SetInputStatusChangeCallback(inputDeviceCallback callback);
79     VendorConfig GetVendorConfig(int32_t deviceId) const;
80     int32_t OnEnableInputDevice(bool enable);
81 
82 private:
83     int32_t ParseDeviceId(const std::string &sysName);
84     void MakeDeviceInfo(struct libinput_device *inputDevice, struct InputDeviceInfo& info);
85     bool IsMatchKeys(struct libinput_device* device, const std::vector<int32_t> &keyCodes) const;
86     void ScanPointerDevice();
87     void FillInputDevice(std::shared_ptr<InputDevice> inputDevice, libinput_device *deviceOrigin) const;
88     std::string GetInputIdentification(struct libinput_device* inputDevice);
89     void NotifyDevCallback(int32_t deviceId,  struct InputDeviceInfo inDevice);
90 private:
91     std::map<int32_t, struct InputDeviceInfo> inputDevice_;
92     std::map<std::string, std::string> inputDeviceScreens_;
93     std::list<std::shared_ptr<IDeviceObserver>> observers_;
94     std::map<SessionPtr, std::function<void(int32_t, const std::string&)>> devListener_;
95     inputDeviceCallback devCallbacks_ = { nullptr };
96     std::map<int32_t, std::string> displayInputBindInfos_;
97     DeviceConfigManagement configManagement_;
98 };
99 
100 #define InputDevMgr ::OHOS::DelayedSingleton<InputDeviceManager>::GetInstance()
101 } // namespace MMI
102 } // namespace OHOS
103 #endif // INPUT_DEVICE_MANAGER_H
104