Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 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 | |
| 22 | #include <utils/Timers.h> |
| 23 | |
Tim Kilbourn | 3186e7b | 2015-04-16 15:32:08 -0700 | [diff] [blame] | 24 | #include "InputHost.h" |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 25 | #include "InputHub.h" |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | /** |
| 30 | * InputDeviceInterface represents an input device in the HAL. It processes |
| 31 | * input events before passing them to the input host. |
| 32 | */ |
| 33 | class InputDeviceInterface { |
| 34 | public: |
| 35 | virtual void processInput(InputEvent& event, nsecs_t currentTime) = 0; |
| 36 | |
Tim Kilbourn | 3186e7b | 2015-04-16 15:32:08 -0700 | [diff] [blame] | 37 | virtual uint32_t getInputClasses() = 0; |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 38 | protected: |
| 39 | InputDeviceInterface() = default; |
| 40 | virtual ~InputDeviceInterface() = default; |
| 41 | }; |
| 42 | |
| 43 | /** |
| 44 | * EvdevDevice is an input device backed by a Linux evdev node. |
| 45 | */ |
| 46 | class EvdevDevice : public InputDeviceInterface { |
| 47 | public: |
Tim Kilbourn | 3186e7b | 2015-04-16 15:32:08 -0700 | [diff] [blame] | 48 | EvdevDevice(InputHost host, const std::shared_ptr<InputDeviceNode>& node); |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 49 | virtual ~EvdevDevice() override = default; |
| 50 | |
| 51 | virtual void processInput(InputEvent& event, nsecs_t currentTime) override; |
| 52 | |
Tim Kilbourn | 3186e7b | 2015-04-16 15:32:08 -0700 | [diff] [blame] | 53 | virtual uint32_t getInputClasses() override { return mClasses; } |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 54 | private: |
Tim Kilbourn | 3186e7b | 2015-04-16 15:32:08 -0700 | [diff] [blame] | 55 | InputHost mHost; |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 56 | std::shared_ptr<InputDeviceNode> mDeviceNode; |
Tim Kilbourn | 3186e7b | 2015-04-16 15:32:08 -0700 | [diff] [blame] | 57 | InputDeviceIdentifier mInputId; |
| 58 | uint32_t mClasses = 0; |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 59 | |
| 60 | int32_t mOverrideSec = 0; |
| 61 | int32_t mOverrideUsec = 0; |
| 62 | }; |
| 63 | |
Tim Kilbourn | 3186e7b | 2015-04-16 15:32:08 -0700 | [diff] [blame] | 64 | /* Input device classes. */ |
| 65 | enum { |
| 66 | /* The input device is a keyboard or has buttons. */ |
| 67 | INPUT_DEVICE_CLASS_KEYBOARD = 0x00000001, |
| 68 | |
| 69 | /* The input device is an alpha-numeric keyboard (not just a dial pad). */ |
| 70 | INPUT_DEVICE_CLASS_ALPHAKEY = 0x00000002, |
| 71 | |
| 72 | /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */ |
| 73 | INPUT_DEVICE_CLASS_TOUCH = 0x00000004, |
| 74 | |
| 75 | /* The input device is a cursor device such as a trackball or mouse. */ |
| 76 | INPUT_DEVICE_CLASS_CURSOR = 0x00000008, |
| 77 | |
| 78 | /* The input device is a multi-touch touchscreen. */ |
| 79 | INPUT_DEVICE_CLASS_TOUCH_MT = 0x00000010, |
| 80 | |
| 81 | /* The input device is a directional pad (implies keyboard, has DPAD keys). */ |
| 82 | INPUT_DEVICE_CLASS_DPAD = 0x00000020, |
| 83 | |
| 84 | /* The input device is a gamepad (implies keyboard, has BUTTON keys). */ |
| 85 | INPUT_DEVICE_CLASS_GAMEPAD = 0x00000040, |
| 86 | |
| 87 | /* The input device has switches. */ |
| 88 | INPUT_DEVICE_CLASS_SWITCH = 0x00000080, |
| 89 | |
| 90 | /* The input device is a joystick (implies gamepad, has joystick absolute axes). */ |
| 91 | INPUT_DEVICE_CLASS_JOYSTICK = 0x00000100, |
| 92 | |
| 93 | /* The input device has a vibrator (supports FF_RUMBLE). */ |
| 94 | INPUT_DEVICE_CLASS_VIBRATOR = 0x00000200, |
| 95 | |
| 96 | /* The input device has a microphone. */ |
| 97 | // TODO: remove this and let the host take care of it |
| 98 | INPUT_DEVICE_CLASS_MIC = 0x00000400, |
| 99 | |
| 100 | /* The input device is an external stylus (has data we want to fuse with touch data). */ |
| 101 | INPUT_DEVICE_CLASS_EXTERNAL_STYLUS = 0x00000800, |
| 102 | |
| 103 | /* The input device is virtual (not a real device, not part of UI configuration). */ |
| 104 | /* not used - INPUT_DEVICE_CLASS_VIRTUAL = 0x40000000, */ |
| 105 | |
| 106 | /* The input device is external (not built-in). */ |
| 107 | // TODO: remove this and let the host take care of it? |
| 108 | INPUT_DEVICE_CLASS_EXTERNAL = 0x80000000, |
| 109 | }; |
| 110 | |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 111 | } // namespace android |
| 112 | |
| 113 | #endif // ANDROID_INPUT_DEVICE_H_ |