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 int32_t mOverrideSec = 0; 77 int32_t mOverrideUsec = 0; 78 }; 79 80 /* Input device classes. */ 81 enum { 82 /* The input device is a keyboard or has buttons. */ 83 INPUT_DEVICE_CLASS_KEYBOARD = 0x00000001, 84 85 /* The input device is an alpha-numeric keyboard (not just a dial pad). */ 86 INPUT_DEVICE_CLASS_ALPHAKEY = 0x00000002, 87 88 /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */ 89 INPUT_DEVICE_CLASS_TOUCH = 0x00000004, 90 91 /* The input device is a cursor device such as a trackball or mouse. */ 92 INPUT_DEVICE_CLASS_CURSOR = 0x00000008, 93 94 /* The input device is a multi-touch touchscreen. */ 95 INPUT_DEVICE_CLASS_TOUCH_MT = 0x00000010, 96 97 /* The input device is a directional pad (implies keyboard, has DPAD keys). */ 98 INPUT_DEVICE_CLASS_DPAD = 0x00000020, 99 100 /* The input device is a gamepad (implies keyboard, has BUTTON keys). */ 101 INPUT_DEVICE_CLASS_GAMEPAD = 0x00000040, 102 103 /* The input device has switches. */ 104 INPUT_DEVICE_CLASS_SWITCH = 0x00000080, 105 106 /* The input device is a joystick (implies gamepad, has joystick absolute axes). */ 107 INPUT_DEVICE_CLASS_JOYSTICK = 0x00000100, 108 109 /* The input device has a vibrator (supports FF_RUMBLE). */ 110 INPUT_DEVICE_CLASS_VIBRATOR = 0x00000200, 111 112 /* The input device has a microphone. */ 113 // TODO: remove this and let the host take care of it 114 INPUT_DEVICE_CLASS_MIC = 0x00000400, 115 116 /* The input device is an external stylus (has data we want to fuse with touch data). */ 117 INPUT_DEVICE_CLASS_EXTERNAL_STYLUS = 0x00000800, 118 119 /* The input device is virtual (not a real device, not part of UI configuration). */ 120 /* not used - INPUT_DEVICE_CLASS_VIRTUAL = 0x40000000, */ 121 122 /* The input device is external (not built-in). */ 123 // TODO: remove this and let the host take care of it? 124 INPUT_DEVICE_CLASS_EXTERNAL = 0x80000000, 125 }; 126 127 } // namespace android 128 129 #endif // ANDROID_INPUT_DEVICE_H_ 130