blob: a1e9e98ced3b5c9b481dd1c2b2281aea91276437 [file] [log] [blame]
Tim Kilbourn73475a42015-02-13 10:35:20 -08001/*
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>
Tim Kilbourn4f3145d2015-05-04 17:26:30 -070021#include <vector>
Tim Kilbourn73475a42015-02-13 10:35:20 -080022
23#include <utils/Timers.h>
24
Tim Kilbourn4f3145d2015-05-04 17:26:30 -070025#include "InputMapper.h"
Tim Kilbourn73475a42015-02-13 10:35:20 -080026
Tim Kilbourndbc8c162015-05-19 15:04:30 -070027struct input_device_handle;
28struct input_device_identifier;
29
Tim Kilbourn73475a42015-02-13 10:35:20 -080030namespace android {
31
Tim Kilbourndbc8c162015-05-19 15:04:30 -070032class InputDeviceDefinition;
33class InputDeviceNode;
34class InputHostInterface;
35struct InputEvent;
36using InputDeviceHandle = struct input_device_handle;
37using InputDeviceIdentifier = struct input_device_identifier;
38
Tim Kilbourn73475a42015-02-13 10:35:20 -080039/**
40 * InputDeviceInterface represents an input device in the HAL. It processes
41 * input events before passing them to the input host.
42 */
43class InputDeviceInterface {
44public:
45 virtual void processInput(InputEvent& event, nsecs_t currentTime) = 0;
46
Tim Kilbourn3186e7b2015-04-16 15:32:08 -070047 virtual uint32_t getInputClasses() = 0;
Tim Kilbourn73475a42015-02-13 10:35:20 -080048protected:
49 InputDeviceInterface() = default;
50 virtual ~InputDeviceInterface() = default;
51};
52
53/**
54 * EvdevDevice is an input device backed by a Linux evdev node.
55 */
56class EvdevDevice : public InputDeviceInterface {
57public:
Tim Kilbourn4f3145d2015-05-04 17:26:30 -070058 EvdevDevice(InputHostInterface* host, const std::shared_ptr<InputDeviceNode>& node);
Tim Kilbourn73475a42015-02-13 10:35:20 -080059 virtual ~EvdevDevice() override = default;
60
61 virtual void processInput(InputEvent& event, nsecs_t currentTime) override;
62
Tim Kilbourn3186e7b2015-04-16 15:32:08 -070063 virtual uint32_t getInputClasses() override { return mClasses; }
Tim Kilbourn73475a42015-02-13 10:35:20 -080064private:
Tim Kilbourn4f3145d2015-05-04 17:26:30 -070065 void createMappers();
66 void configureDevice();
67
68 InputHostInterface* mHost = nullptr;
Tim Kilbourn73475a42015-02-13 10:35:20 -080069 std::shared_ptr<InputDeviceNode> mDeviceNode;
Tim Kilbourn4f3145d2015-05-04 17:26:30 -070070 InputDeviceIdentifier* mInputId = nullptr;
71 InputDeviceDefinition* mDeviceDefinition = nullptr;
72 InputDeviceHandle* mDeviceHandle = nullptr;
73 std::vector<std::unique_ptr<InputMapper>> mMappers;
Tim Kilbourn3186e7b2015-04-16 15:32:08 -070074 uint32_t mClasses = 0;
Tim Kilbourn73475a42015-02-13 10:35:20 -080075};
76
Tim Kilbourn3186e7b2015-04-16 15:32:08 -070077/* Input device classes. */
78enum {
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
Tim Kilbourn73475a42015-02-13 10:35:20 -0800124} // namespace android
125
126#endif // ANDROID_INPUT_DEVICE_H_