• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_INPUT_DEVICE_H_
18 #define ANDROID_INPUT_DEVICE_H_
19 
20 #include <memory>
21 #include <vector>
22 
23 #include <utils/Timers.h>
24 
25 #include "InputMapper.h"
26 
27 struct input_device_handle;
28 struct input_device_identifier;
29 
30 namespace android {
31 
32 class InputDeviceDefinition;
33 class InputDeviceNode;
34 class InputHostInterface;
35 struct InputEvent;
36 using InputDeviceHandle = struct input_device_handle;
37 using InputDeviceIdentifier = struct input_device_identifier;
38 
39 /**
40  * InputDeviceInterface represents an input device in the HAL. It processes
41  * input events before passing them to the input host.
42  */
43 class InputDeviceInterface {
44 public:
45     virtual void processInput(InputEvent& event, nsecs_t currentTime) = 0;
46 
47     virtual uint32_t getInputClasses() = 0;
48 protected:
49     InputDeviceInterface() = default;
50     virtual ~InputDeviceInterface() = default;
51 };
52 
53 /**
54  * EvdevDevice is an input device backed by a Linux evdev node.
55  */
56 class EvdevDevice : public InputDeviceInterface {
57 public:
58     EvdevDevice(InputHostInterface* host, const std::shared_ptr<InputDeviceNode>& node);
59     virtual ~EvdevDevice() override = default;
60 
61     virtual void processInput(InputEvent& event, nsecs_t currentTime) override;
62 
getInputClasses()63     virtual uint32_t getInputClasses() override { return mClasses; }
64 private:
65     void createMappers();
66     void configureDevice();
67 
68     InputHostInterface* mHost = nullptr;
69     std::shared_ptr<InputDeviceNode> mDeviceNode;
70     InputDeviceIdentifier* mInputId = nullptr;
71     InputDeviceDefinition* mDeviceDefinition = nullptr;
72     InputDeviceHandle* mDeviceHandle = nullptr;
73     std::vector<std::unique_ptr<InputMapper>> mMappers;
74     uint32_t mClasses = 0;
75 };
76 
77 /* Input device classes. */
78 enum {
79     /* The input device is a keyboard or has buttons. */
80     INPUT_DEVICE_CLASS_KEYBOARD      = 0x00000001,
81 
82     /* The input device is an alpha-numeric keyboard (not just a dial pad). */
83     INPUT_DEVICE_CLASS_ALPHAKEY      = 0x00000002,
84 
85     /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */
86     INPUT_DEVICE_CLASS_TOUCH         = 0x00000004,
87 
88     /* The input device is a cursor device such as a trackball or mouse. */
89     INPUT_DEVICE_CLASS_CURSOR        = 0x00000008,
90 
91     /* The input device is a multi-touch touchscreen. */
92     INPUT_DEVICE_CLASS_TOUCH_MT      = 0x00000010,
93 
94     /* The input device is a directional pad (implies keyboard, has DPAD keys). */
95     INPUT_DEVICE_CLASS_DPAD          = 0x00000020,
96 
97     /* The input device is a gamepad (implies keyboard, has BUTTON keys). */
98     INPUT_DEVICE_CLASS_GAMEPAD       = 0x00000040,
99 
100     /* The input device has switches. */
101     INPUT_DEVICE_CLASS_SWITCH        = 0x00000080,
102 
103     /* The input device is a joystick (implies gamepad, has joystick absolute axes). */
104     INPUT_DEVICE_CLASS_JOYSTICK      = 0x00000100,
105 
106     /* The input device has a vibrator (supports FF_RUMBLE). */
107     INPUT_DEVICE_CLASS_VIBRATOR      = 0x00000200,
108 
109     /* The input device has a microphone. */
110     // TODO: remove this and let the host take care of it
111     INPUT_DEVICE_CLASS_MIC           = 0x00000400,
112 
113     /* The input device is an external stylus (has data we want to fuse with touch data). */
114     INPUT_DEVICE_CLASS_EXTERNAL_STYLUS = 0x00000800,
115 
116     /* The input device is virtual (not a real device, not part of UI configuration). */
117     /* not used - INPUT_DEVICE_CLASS_VIRTUAL       = 0x40000000, */
118 
119     /* The input device is external (not built-in). */
120     // TODO: remove this and let the host take care of it?
121     INPUT_DEVICE_CLASS_EXTERNAL      = 0x80000000,
122 };
123 
124 }  // namespace android
125 
126 #endif  // ANDROID_INPUT_DEVICE_H_
127