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