• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 OHOS_DISTRIBUTED_INPUT_CONSTANTS_H
17 #define OHOS_DISTRIBUTED_INPUT_CONSTANTS_H
18 
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 #include <linux/uinput.h>
24 
25 namespace OHOS {
26 namespace DistributedHardware {
27 namespace DistributedInput {
28 #define INPUT_KEY_WHEN  "when"
29 #define INPUT_KEY_TYPE  "type"
30 #define INPUT_KEY_CODE  "code"
31 #define INPUT_KEY_VALUE "value"
32 #define INPUT_KEY_DESCRIPTOR  "descriptor"
33 #define INPUT_KEY_PATH "path"
34 
35 #define VIRTUAL_DEVICE_NAME "DistributedInput "
36 #define LONG_BITS (sizeof(long) * 8)
37 #define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS)
38 
39     const char INPUT_STRING_SPLIT_POINT = '.';
40     const uint32_t KEY_DOWN_STATE = 1;
41     const uint32_t KEY_UP_STATE = 0;
42     const uint32_t READ_SLEEP_TIME_MS = 50;
43     const uint32_t READ_RETRY_MAX = 5;
44     const uint32_t DH_ID_LENGTH_MAX = 256;
45     const uint32_t DEV_ID_LENGTH_MAX = 256;
46     const uint32_t STRING_MAX_SIZE = 40 * 1024 * 1024;
47     const uint32_t SCREEN_MSG_MAX = 40 * 1024 * 1024;
48     const uint32_t AUTH_SESSION_SIDE_SERVER = 0;
49     const uint32_t IPC_VECTOR_MAX_SIZE = 32;
50 
51     /*
52      * Device Type definitions
53      */
54     enum class DInputDeviceType : uint32_t {
55         NONE = 0x0000,
56         MOUSE = 0x0001,
57         KEYBOARD = 0x0002,
58         TOUCHSCREEN = 0x0004,
59         TOUCHPAD = MOUSE,
60         ALL = MOUSE | KEYBOARD | TOUCHSCREEN,
61     };
62 
63     const char * const DEVICE_PATH = "/dev/input";
64 
65     /*
66      * Maximum number of signalled FDs to handle at a time.
67      */
68     constexpr uint32_t EPOLL_MAX_EVENTS = 16;
69 
70     /*
71      * Maximum number of event buffer size.
72      */
73     constexpr uint32_t INPUT_EVENT_BUFFER_SIZE = 256;
74 
75     constexpr int32_t INPUT_LOAD_SA_TIMEOUT_MS = 10000;
76 
77     constexpr int32_t INPUT_LATENCY_DELAYTIME_US = 50 * 1000;
78 
79     constexpr uint32_t INPUT_LATENCY_DELAY_TIMES = 60;
80 
81     constexpr int32_t SESSION_WAIT_TIMEOUT_SECOND = 5;
82 
83     constexpr int32_t EPOLL_WAITTIME = -1;
84 
85     /* The input device is a keyboard or has buttons. */
86     constexpr uint32_t INPUT_DEVICE_CLASS_KEYBOARD      = 0x00000001;
87 
88     /* The input device is an alpha-numeric keyboard (not just a dial pad). */
89     constexpr uint32_t INPUT_DEVICE_CLASS_ALPHAKEY      = 0x00000002;
90 
91     /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */
92     constexpr uint32_t INPUT_DEVICE_CLASS_TOUCH         = 0x00000004;
93 
94     /* The input device is a cursor device such as a trackball or mouse. */
95     constexpr uint32_t INPUT_DEVICE_CLASS_CURSOR        = 0x00000008;
96 
97     /* The input device is a multi-touch touchscreen. */
98     constexpr uint32_t INPUT_DEVICE_CLASS_TOUCH_MT      = 0x00000010;
99 
100     /* The input device is a directional pad (implies keyboard, has DPAD keys). */
101     constexpr uint32_t INPUT_DEVICE_CLASS_DPAD          = 0x00000020;
102 
103     /* The input device is a gamepad (implies keyboard, has BUTTON keys). */
104     constexpr uint32_t INPUT_DEVICE_CLASS_GAMEPAD       = 0x00000040;
105 
106     /* The input device has switches. */
107     constexpr uint32_t INPUT_DEVICE_CLASS_SWITCH        = 0x00000080;
108 
109     /* The input device is a joystick (implies gamepad, has joystick absolute axes). */
110     constexpr uint32_t INPUT_DEVICE_CLASS_JOYSTICK      = 0x00000100;
111 
112     /* The input device has a vibrator (supports FF_RUMBLE). */
113     constexpr uint32_t INPUT_DEVICE_CLASS_VIBRATOR      = 0x00000200;
114 
115     /* The input device has a microphone. */
116     constexpr uint32_t INPUT_DEVICE_CLASS_MIC           = 0x00000400;
117 
118     /* The input device is an external stylus (has data we want to fuse with touch data). */
119     constexpr uint32_t INPUT_DEVICE_CLASS_EXTERNAL_STYLUS = 0x00000800;
120 
121     /* The input device has a rotary encoder. */
122     constexpr uint32_t INPUT_DEVICE_CLASS_ROTARY_ENCODER = 0x00001000;
123 
124     /* The input device is virtual (not a real device, not part of UI configuration). */
125     constexpr uint32_t INPUT_DEVICE_CLASS_VIRTUAL       = 0x40000000;
126 
127     /* The input device is external (not built-in). */
128     constexpr uint32_t INPUT_DEVICE_CLASS_EXTERNAL      = 0x80000000;
129 
130     constexpr uint32_t MAX_SIZE_OF_DEVICE_NAME = UINPUT_MAX_NAME_SIZE - 1;
131 
132     const std::string DH_ID_PREFIX = "Input_";
133 
134     const std::string DINPUT_SPLIT_COMMA = ", ";
135 
136     const std::string SOURCE_DEVICE_ID = "sourceDevId";
137 
138     const std::string SINK_DEVICE_ID = "sinkDevId";
139 
140     const std::string SOURCE_WINDOW_ID = "sourceWinId";
141 
142     const std::string SINK_SHOW_WINDOW_ID = "sinkShowWinId";
143 
144     const std::string SOURCE_WINDOW_WIDTH = "sourceWinWidth";
145 
146     const std::string SOURCE_WINDOW_HEIGHT = "sourceWinHeight";
147 
148     const std::string SINK_PROJECT_SHOW_WIDTH = "sinkProjShowWidth";
149 
150     const std::string SINK_PROJECT_SHOW_HEIGHT = "sinkProjShowHeight";
151 
152     const std::string SINK_WINDOW_SHOW_X = "sinkWinShowX";
153 
154     const std::string SINK_WINDOW_SHOW_Y = "sinkWinShowY";
155 
156     const std::string DEVICE_NAME = "name";
157 
158     const std::string PHYSICAL_PATH = "physicalPath";
159 
160     const std::string UNIQUE_ID = "uniqueId";
161 
162     const std::string BUS = "bus";
163 
164     const std::string VENDOR = "vendor";
165 
166     const std::string PRODUCT = "product";
167 
168     const std::string VERSION = "version";
169 
170     const std::string DESCRIPTOR = "descriptor";
171 
172     const std::string CLASSES = "classes";
173 
174     const std::string EVENT_TYPES = "eventTypes";
175 
176     const std::string EVENT_KEYS = "eventKeys";
177 
178     const std::string ABS_TYPES = "absTypes";
179 
180     const std::string ABS_INFOS = "absInfos";
181 
182     const std::string REL_TYPES = "relTypes";
183 
184     const std::string PROPERTIES = "properties";
185 
186     const std::string DH_TOUCH_PAD = "touchpad";
187 
188     const std::string DINPUT_LOG_TITLE_TAG = "DINPUT";
189 
190     constexpr const char* LATENCY_COUNT_THREAD_NAME = "latencyCount";
191 
192     constexpr const char* EVENT_INJECT_THREAD_NAME = "eventInject";
193 
194     constexpr const char* COLLECT_EVENT_THREAD_NAME = "collectEvents";
195 
196     constexpr const char* CHECK_KEY_STATUS_THREAD_NAME = "checkKeyStatus";
197 
198     constexpr int32_t LOG_MAX_LEN = 4096;
199 
200     constexpr uint32_t SCREEN_ID_DEFAULT = 0;
201 
202     constexpr uint32_t DEFAULT_VALUE = 0;
203 
204     constexpr int32_t UN_INIT_FD_VALUE = -1;
205 
206     constexpr int32_t SINK_SCREEN_INFO_SIZE = 4;
207 
208     enum class EHandlerMsgType {
209         DINPUT_SINK_EVENT_HANDLER_MSG = 1,
210         DINPUT_SOURCE_EVENT_HANDLER_MSG = 2
211     };
212 
213     struct BusinessEvent {
214         std::vector<int32_t> pressedKeys;
215         int32_t keyCode;
216         int32_t keyAction;
217     };
218 
219     struct TouchScreenEvent {
220         uint32_t absX;
221         uint32_t absY;
222     };
223 
224     /*
225      * A raw event as retrieved from the input_event.
226      */
227     struct RawEvent {
228         int64_t when;
229         uint32_t type;
230         uint32_t code;
231         int32_t value;
232         std::string descriptor;
233         std::string path;
234     };
235 
236     /*
237      * Input device Info retrieved from the kernel.
238      */
239     struct InputDevice {
InputDeviceInputDevice240         inline InputDevice() : name(""), physicalPath(""), uniqueId(""), bus(0), vendor(0), product(0),
241             version(0), descriptor(""), classes(0) {}
242         std::string name;
243         std::string physicalPath;
244         std::string uniqueId;
245         uint16_t bus;
246         uint16_t vendor;
247         uint16_t product;
248         uint16_t version;
249         std::string descriptor;
250         uint32_t classes;
251         std::vector<uint32_t> eventTypes;
252         std::vector<uint32_t> eventKeys;
253         std::vector<uint32_t> absTypes;
254         std::map<uint32_t, std::vector<int32_t>> absInfos;
255         std::vector<uint32_t> relTypes;
256         std::vector<uint32_t> properties;
257     };
258 
259     /*
260      * Distributed Hardware Handle
261      */
262     struct HardwareHandle {
263         // equipment ID
264         std::string eqId;
265 
266         // Hardware ID
267         std::string hhId;
268 
269         // Hardware detailed information
270         std::string hdInfo;
271     };
272 
273     // Synthetic raw event type codes produced when devices are added or removed.
274     enum class DeviceType {
275         // Sent when a device is added.
276         DEVICE_ADDED = 0x10000000,
277 
278         // Sent when a device is removed.
279         DEVICE_REMOVED = 0x20000000,
280 
281         // Sent when all added/removed devices from the most recent scan have been reported.
282         // This event is always sent at least once.
283         FINISHED_DEVICE_SCAN = 0x30000000,
284 
285         FIRST_SYNTHETIC_EVENT = DEVICE_ADDED,
286     };
287 
288     /*
289      * Input device connection status
290      */
291     struct InputDeviceEvent {
292         DeviceType type;
293         InputDevice deviceInfo;
294     };
295 
296     /*
297      * Device Type definitions
298      */
299     enum class DInputServerType {
300         /*
301          * null server
302          */
303         NULL_SERVER_TYPE = 0,
304 
305         /*
306          * source server
307          */
308         SOURCE_SERVER_TYPE = 1,
309 
310         /*
311          * sink server.
312          */
313         SINK_SERVER_TYPE = 2,
314     };
315 
316     // Current Input Session Status
317     enum class SessionStatus : uint32_t {
318         CLOSED = 0x00,
319         OPENING = 0x01,
320         OPENED = 0x02,
321         CLOSING = 0x03,
322     };
323 } // namespace DistributedInput
324 } // namespace DistributedHardware
325 } // namespace OHOS
326 
327 #endif // OHOS_DISTRIBUTED_INPUT_CONSTANTS_H
328