blob: a379d6c306423a954f125ac9d1bb507d8787aa90 [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 Kilbourn3186e7b2015-04-16 15:32:08 -070025#include "InputHost.h"
Tim Kilbourn73475a42015-02-13 10:35:20 -080026#include "InputHub.h"
Tim Kilbourn4f3145d2015-05-04 17:26:30 -070027#include "InputMapper.h"
Tim Kilbourn73475a42015-02-13 10:35:20 -080028
29namespace android {
30
31/**
32 * InputDeviceInterface represents an input device in the HAL. It processes
33 * input events before passing them to the input host.
34 */
35class InputDeviceInterface {
36public:
37 virtual void processInput(InputEvent& event, nsecs_t currentTime) = 0;
38
Tim Kilbourn3186e7b2015-04-16 15:32:08 -070039 virtual uint32_t getInputClasses() = 0;
Tim Kilbourn73475a42015-02-13 10:35:20 -080040protected:
41 InputDeviceInterface() = default;
42 virtual ~InputDeviceInterface() = default;
43};
44
45/**
46 * EvdevDevice is an input device backed by a Linux evdev node.
47 */
48class EvdevDevice : public InputDeviceInterface {
49public:
Tim Kilbourn4f3145d2015-05-04 17:26:30 -070050 EvdevDevice(InputHostInterface* host, const std::shared_ptr<InputDeviceNode>& node);
Tim Kilbourn73475a42015-02-13 10:35:20 -080051 virtual ~EvdevDevice() override = default;
52
53 virtual void processInput(InputEvent& event, nsecs_t currentTime) override;
54
Tim Kilbourn3186e7b2015-04-16 15:32:08 -070055 virtual uint32_t getInputClasses() override { return mClasses; }
Tim Kilbourn73475a42015-02-13 10:35:20 -080056private:
Tim Kilbourn4f3145d2015-05-04 17:26:30 -070057 void createMappers();
58 void configureDevice();
59
60 InputHostInterface* mHost = nullptr;
Tim Kilbourn73475a42015-02-13 10:35:20 -080061 std::shared_ptr<InputDeviceNode> mDeviceNode;
Tim Kilbourn4f3145d2015-05-04 17:26:30 -070062 InputDeviceIdentifier* mInputId = nullptr;
63 InputDeviceDefinition* mDeviceDefinition = nullptr;
64 InputDeviceHandle* mDeviceHandle = nullptr;
65 std::vector<std::unique_ptr<InputMapper>> mMappers;
Tim Kilbourn3186e7b2015-04-16 15:32:08 -070066 uint32_t mClasses = 0;
Tim Kilbourn73475a42015-02-13 10:35:20 -080067
68 int32_t mOverrideSec = 0;
69 int32_t mOverrideUsec = 0;
70};
71
Tim Kilbourn3186e7b2015-04-16 15:32:08 -070072/* Input device classes. */
73enum {
74 /* The input device is a keyboard or has buttons. */
75 INPUT_DEVICE_CLASS_KEYBOARD = 0x00000001,
76
77 /* The input device is an alpha-numeric keyboard (not just a dial pad). */
78 INPUT_DEVICE_CLASS_ALPHAKEY = 0x00000002,
79
80 /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */
81 INPUT_DEVICE_CLASS_TOUCH = 0x00000004,
82
83 /* The input device is a cursor device such as a trackball or mouse. */
84 INPUT_DEVICE_CLASS_CURSOR = 0x00000008,
85
86 /* The input device is a multi-touch touchscreen. */
87 INPUT_DEVICE_CLASS_TOUCH_MT = 0x00000010,
88
89 /* The input device is a directional pad (implies keyboard, has DPAD keys). */
90 INPUT_DEVICE_CLASS_DPAD = 0x00000020,
91
92 /* The input device is a gamepad (implies keyboard, has BUTTON keys). */
93 INPUT_DEVICE_CLASS_GAMEPAD = 0x00000040,
94
95 /* The input device has switches. */
96 INPUT_DEVICE_CLASS_SWITCH = 0x00000080,
97
98 /* The input device is a joystick (implies gamepad, has joystick absolute axes). */
99 INPUT_DEVICE_CLASS_JOYSTICK = 0x00000100,
100
101 /* The input device has a vibrator (supports FF_RUMBLE). */
102 INPUT_DEVICE_CLASS_VIBRATOR = 0x00000200,
103
104 /* The input device has a microphone. */
105 // TODO: remove this and let the host take care of it
106 INPUT_DEVICE_CLASS_MIC = 0x00000400,
107
108 /* The input device is an external stylus (has data we want to fuse with touch data). */
109 INPUT_DEVICE_CLASS_EXTERNAL_STYLUS = 0x00000800,
110
111 /* The input device is virtual (not a real device, not part of UI configuration). */
112 /* not used - INPUT_DEVICE_CLASS_VIRTUAL = 0x40000000, */
113
114 /* The input device is external (not built-in). */
115 // TODO: remove this and let the host take care of it?
116 INPUT_DEVICE_CLASS_EXTERNAL = 0x80000000,
117};
118
Tim Kilbourn73475a42015-02-13 10:35:20 -0800119} // namespace android
120
121#endif // ANDROID_INPUT_DEVICE_H_