blob: 021978dee7a605ccb128842f781c923d2edddd7e [file] [log] [blame]
Prabir Pradhanbaa5c822019-08-30 15:27:05 -07001/*
2 * Copyright (C) 2019 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
Prabir Pradhan48108662022-09-09 21:22:04 +000017#pragma once
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070018
Dominik Laskowski2f01d772022-03-23 16:01:29 -070019#include <ftl/flags.h>
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080020#include <input/DisplayViewport.h>
21#include <input/InputDevice.h>
Siarhei Vishniakou32f36ae2020-09-02 20:17:10 -070022#include <input/PropertyMap.h>
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080023
Dominik Laskowski2f01d772022-03-23 16:01:29 -070024#include <cstdint>
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080025#include <optional>
26#include <unordered_map>
27#include <vector>
28
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070029#include "EventHub.h"
30#include "InputReaderBase.h"
31#include "InputReaderContext.h"
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070032#include "NotifyArgs.h"
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070033
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070034namespace android {
35
Chris Ye1dd2e5c2021-04-04 23:12:41 -070036class PeripheralController;
37class PeripheralControllerInterface;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -080038class InputDeviceContext;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070039class InputMapper;
40
41/* Represents the state of a single input device. */
42class InputDevice {
43public:
44 InputDevice(InputReaderContext* context, int32_t id, int32_t generation,
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080045 const InputDeviceIdentifier& identifier);
Prabir Pradhan31d05c42024-07-24 21:19:08 +000046 virtual ~InputDevice();
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070047
48 inline InputReaderContext* getContext() { return mContext; }
49 inline int32_t getId() const { return mId; }
50 inline int32_t getControllerNumber() const { return mControllerNumber; }
51 inline int32_t getGeneration() const { return mGeneration; }
52 inline const std::string getName() const { return mIdentifier.name; }
53 inline const std::string getDescriptor() { return mIdentifier.descriptor; }
Prabir Pradhanb54ffb22022-10-27 18:03:34 +000054 inline std::optional<std::string> getBluetoothAddress() const {
55 return mIdentifier.bluetoothAddress;
56 }
Zixuan Qufecb6062022-11-12 04:44:31 +000057 inline const std::string getLocation() const { return mIdentifier.location; }
Dominik Laskowski2f01d772022-03-23 16:01:29 -070058 inline ftl::Flags<InputDeviceClass> getClasses() const { return mClasses; }
Prabir Pradhan31d05c42024-07-24 21:19:08 +000059 inline virtual uint32_t getSources() const { return mSources; }
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080060 inline bool hasEventHubDevices() const { return !mDevices.empty(); }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070061
62 inline bool isExternal() { return mIsExternal; }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070063 inline std::optional<uint8_t> getAssociatedDisplayPort() const {
64 return mAssociatedDisplayPort;
65 }
Antonio Kantek0ac5e092024-04-22 17:10:27 +000066 inline std::optional<std::string> getAssociatedDisplayUniqueIdByPort() const {
67 return mAssociatedDisplayUniqueIdByPort;
68 }
69 inline std::optional<std::string> getAssociatedDisplayUniqueIdByDescriptor() const {
70 return mAssociatedDisplayUniqueIdByDescriptor;
Christine Franks2a2293c2022-01-18 11:51:16 -080071 }
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +000072 inline std::optional<std::string> getDeviceTypeAssociation() const {
73 return mAssociatedDeviceType;
74 }
Harry Cutts511ce6a2024-07-24 11:38:25 +000075 inline virtual std::optional<DisplayViewport> getAssociatedViewport() const {
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070076 return mAssociatedViewport;
77 }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070078 inline bool hasMic() const { return mHasMic; }
79
Vaibhav Devmurari16c24192023-05-04 15:20:12 +000080 inline bool isIgnored() { return !getMapperCount() && !mController; }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070081
Vaibhav Devmurarie58ffb92024-05-22 17:38:25 +000082 inline KeyboardType getKeyboardType() const { return mKeyboardType; }
83
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070084 bool isEnabled();
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070085
Chris Yee7310032020-09-22 15:36:28 -070086 void dump(std::string& dump, const std::string& eventHubDevStr);
Arpit Singh8e6fb252023-04-06 11:49:17 +000087 void addEmptyEventHubDevice(int32_t eventHubId);
Arpit Singh82f29a12023-06-13 15:05:53 +000088 [[nodiscard]] std::list<NotifyArgs> addEventHubDevice(
89 nsecs_t when, int32_t eventHubId, const InputReaderConfiguration& readerConfig);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080090 void removeEventHubDevice(int32_t eventHubId);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070091 [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when,
Arpit Singhed6c3de2023-04-05 19:24:37 +000092 const InputReaderConfiguration& readerConfig,
Arpit Singh7f1765e2023-07-07 13:12:37 +000093 ConfigurationChanges changes);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070094 [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when);
95 [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvents, size_t count);
96 [[nodiscard]] std::list<NotifyArgs> timeoutExpired(nsecs_t when);
97 [[nodiscard]] std::list<NotifyArgs> updateExternalStylusState(const StylusState& state);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070098
Siarhei Vishniakou1983a712021-06-04 19:27:09 +000099 InputDeviceInfo getDeviceInfo();
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700100 int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
101 int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
102 int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
Philip Junker4af3b3d2021-12-14 10:36:55 +0100103 int32_t getKeyCodeForKeyLocation(int32_t locationKeyCode) const;
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700104 bool markSupportedKeyCodes(uint32_t sourceMask, const std::vector<int32_t>& keyCodes,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700105 uint8_t* outFlags);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700106 [[nodiscard]] std::list<NotifyArgs> vibrate(const VibrationSequence& sequence, ssize_t repeat,
107 int32_t token);
108 [[nodiscard]] std::list<NotifyArgs> cancelVibrate(int32_t token);
Chris Ye87143712020-11-10 05:05:58 +0000109 bool isVibrating();
110 std::vector<int32_t> getVibratorIds();
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700111 [[nodiscard]] std::list<NotifyArgs> cancelTouch(nsecs_t when, nsecs_t readTime);
Chris Yef59a2f42020-10-16 12:55:26 -0700112 bool enableSensor(InputDeviceSensorType sensorType, std::chrono::microseconds samplingPeriod,
113 std::chrono::microseconds maxBatchReportLatency);
114 void disableSensor(InputDeviceSensorType sensorType);
115 void flushSensor(InputDeviceSensorType sensorType);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700116
Andy Chenf9f1a022022-08-29 20:07:10 -0400117 std::optional<int32_t> getBatteryEventHubId() const;
Kim Low03ea0352020-11-06 12:45:07 -0800118
Chris Ye3fdbfef2021-01-06 18:45:18 -0800119 bool setLightColor(int32_t lightId, int32_t color);
120 bool setLightPlayerId(int32_t lightId, int32_t playerId);
121 std::optional<int32_t> getLightColor(int32_t lightId);
122 std::optional<int32_t> getLightPlayerId(int32_t lightId);
123
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700124 int32_t getMetaState();
125 void updateMetaState(int32_t keyCode);
126
Vaibhav Devmuraricbba14c2022-10-10 16:54:49 +0000127 void addKeyRemapping(int32_t fromKeyCode, int32_t toKeyCode);
128
Vaibhav Devmurarie58ffb92024-05-22 17:38:25 +0000129 void setKeyboardType(KeyboardType keyboardType);
130
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700131 void bumpGeneration();
132
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700133 [[nodiscard]] NotifyDeviceResetArgs notifyReset(nsecs_t when);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700134
Prabir Pradhan31d05c42024-07-24 21:19:08 +0000135 inline virtual const PropertyMap& getConfiguration() const { return mConfiguration; }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700136 inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
137
Linnan Li13bf76a2024-05-05 19:18:02 +0800138 std::optional<ui::LogicalDisplayId> getAssociatedDisplayId();
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700139
arthurhungc903df12020-08-11 15:08:42 +0800140 void updateLedState(bool reset);
141
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800142 size_t getMapperCount();
143
Omar Abdelmonem5e70e962024-08-06 09:38:42 +0000144 std::optional<HardwareProperties> getTouchpadHardwareProperties();
145
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800146 // construct and add a mapper to the input device
147 template <class T, typename... Args>
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800148 T& addMapper(int32_t eventHubId, Args... args) {
149 // ensure a device entry exists for this eventHubId
Arpit Singh8e6fb252023-04-06 11:49:17 +0000150 addEmptyEventHubDevice(eventHubId);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800151
152 // create mapper
153 auto& devicePair = mDevices[eventHubId];
154 auto& deviceContext = devicePair.first;
155 auto& mappers = devicePair.second;
156 T* mapper = new T(*deviceContext, args...);
157 mappers.emplace_back(mapper);
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800158 return *mapper;
159 }
160
Arpit Singh56adebc2023-04-25 13:56:05 +0000161 template <class T, typename... Args>
162 T& constructAndAddMapper(int32_t eventHubId, Args... args) {
163 // create mapper
164 auto& devicePair = mDevices[eventHubId];
165 auto& deviceContext = devicePair.first;
166 auto& mappers = devicePair.second;
167 mappers.push_back(createInputMapper<T>(*deviceContext, args...));
168 return static_cast<T&>(*mappers.back());
169 }
170
Chris Yee2b1e5c2021-03-10 22:45:12 -0800171 // construct and add a controller to the input device
172 template <class T>
173 T& addController(int32_t eventHubId) {
174 // ensure a device entry exists for this eventHubId
Arpit Singh8e6fb252023-04-06 11:49:17 +0000175 addEmptyEventHubDevice(eventHubId);
Chris Yee2b1e5c2021-03-10 22:45:12 -0800176
177 // create controller
178 auto& devicePair = mDevices[eventHubId];
179 auto& deviceContext = devicePair.first;
180
181 mController = std::make_unique<T>(*deviceContext);
182 return *(reinterpret_cast<T*>(mController.get()));
183 }
184
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700185private:
186 InputReaderContext* mContext;
187 int32_t mId;
188 int32_t mGeneration;
189 int32_t mControllerNumber;
190 InputDeviceIdentifier mIdentifier;
191 std::string mAlias;
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700192 ftl::Flags<InputDeviceClass> mClasses;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700193
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800194 // map from eventHubId to device context and mappers
195 using MapperVector = std::vector<std::unique_ptr<InputMapper>>;
196 using DevicePair = std::pair<std::unique_ptr<InputDeviceContext>, MapperVector>;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800197 // Map from EventHub ID to pair of device context and vector of mapper.
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800198 std::unordered_map<int32_t, DevicePair> mDevices;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800199 // Misc devices controller for lights, battery, etc.
Chris Ye1dd2e5c2021-04-04 23:12:41 -0700200 std::unique_ptr<PeripheralControllerInterface> mController;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700201
202 uint32_t mSources;
Yeabkal Wubshite03e8b12023-06-27 16:23:12 -0700203 bool mIsWaking;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700204 bool mIsExternal;
Vaibhav Devmurarie58ffb92024-05-22 17:38:25 +0000205 KeyboardType mKeyboardType = KeyboardType::NONE;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700206 std::optional<uint8_t> mAssociatedDisplayPort;
Antonio Kantek0ac5e092024-04-22 17:10:27 +0000207 std::optional<std::string> mAssociatedDisplayUniqueIdByPort;
208 std::optional<std::string> mAssociatedDisplayUniqueIdByDescriptor;
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +0000209 std::optional<std::string> mAssociatedDeviceType;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700210 std::optional<DisplayViewport> mAssociatedViewport;
211 bool mHasMic;
212 bool mDropUntilNextSync;
Yeabkal Wubshitb1b96db2024-01-24 12:47:00 -0800213 std::optional<bool> mShouldSmoothScroll;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700214
215 typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);
216 int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
217
Arpit Singh8e6fb252023-04-06 11:49:17 +0000218 std::vector<std::unique_ptr<InputMapper>> createMappers(
219 InputDeviceContext& contextPtr, const InputReaderConfiguration& readerConfig);
220
Arpit Singh82f29a12023-06-13 15:05:53 +0000221 [[nodiscard]] std::list<NotifyArgs> configureInternal(
222 nsecs_t when, const InputReaderConfiguration& readerConfig,
223 ConfigurationChanges changes, bool forceEnable = false);
224
Arpit Singh48189772023-05-30 14:12:49 +0000225 [[nodiscard]] std::list<NotifyArgs> updateEnableState(
Arpit Singh82f29a12023-06-13 15:05:53 +0000226 nsecs_t when, const InputReaderConfiguration& readerConfig, bool forceEnable = false);
Arpit Singh48189772023-05-30 14:12:49 +0000227
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700228 PropertyMap mConfiguration;
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800229
Yeabkal Wubshite03e8b12023-06-27 16:23:12 -0700230 // Runs logic post a `process` call. This can be used to update the generated `NotifyArgs` as
231 // per the properties of the InputDevice.
232 void postProcess(std::list<NotifyArgs>& args) const;
233
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800234 // helpers to interate over the devices collection
235 // run a function against every mapper on every subdevice
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800236 inline void for_each_mapper(std::function<void(InputMapper&)> f) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800237 for (auto& deviceEntry : mDevices) {
238 auto& devicePair = deviceEntry.second;
239 auto& mappers = devicePair.second;
240 for (auto& mapperPtr : mappers) {
241 f(*mapperPtr);
242 }
243 }
244 }
245
246 // run a function against every mapper on a specific subdevice
247 inline void for_each_mapper_in_subdevice(int32_t eventHubDevice,
248 std::function<void(InputMapper&)> f) {
249 auto deviceIt = mDevices.find(eventHubDevice);
250 if (deviceIt != mDevices.end()) {
251 auto& devicePair = deviceIt->second;
252 auto& mappers = devicePair.second;
253 for (auto& mapperPtr : mappers) {
254 f(*mapperPtr);
255 }
256 }
257 }
258
259 // run a function against every subdevice
260 inline void for_each_subdevice(std::function<void(InputDeviceContext&)> f) {
261 for (auto& deviceEntry : mDevices) {
262 auto& devicePair = deviceEntry.second;
263 auto& contextPtr = devicePair.first;
264 f(*contextPtr);
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800265 }
266 }
267
268 // return the first value returned by a function over every mapper.
269 // if all mappers return nullopt, return nullopt.
270 template <typename T>
Philip Junker4af3b3d2021-12-14 10:36:55 +0100271 inline std::optional<T> first_in_mappers(
272 std::function<std::optional<T>(InputMapper&)> f) const {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800273 for (auto& deviceEntry : mDevices) {
274 auto& devicePair = deviceEntry.second;
275 auto& mappers = devicePair.second;
276 for (auto& mapperPtr : mappers) {
277 std::optional<T> ret = f(*mapperPtr);
278 if (ret) {
279 return ret;
280 }
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800281 }
282 }
283 return std::nullopt;
284 }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700285};
286
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800287/* Provides access to EventHub methods, but limits access to the current InputDevice.
288 * Essentially an implementation of EventHubInterface, but for a specific device id.
289 * Helps hide implementation details of InputDevice and EventHub. Used by mappers to
290 * check the status of the associated hardware device
291 */
292class InputDeviceContext {
293public:
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800294 InputDeviceContext(InputDevice& device, int32_t eventHubId);
Harry Cutts92559ef2024-01-05 12:45:36 +0000295 virtual ~InputDeviceContext();
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800296
297 inline InputReaderContext* getContext() { return mContext; }
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800298 inline int32_t getId() { return mDeviceId; }
299 inline int32_t getEventHubId() { return mId; }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800300
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700301 inline ftl::Flags<InputDeviceClass> getDeviceClasses() const {
Chris Ye1b0c7342020-07-28 21:57:03 -0700302 return mEventHub->getDeviceClasses(mId);
303 }
Prabir Pradhan38636652024-07-23 21:59:36 +0000304 inline uint32_t getDeviceSources() const { return mDevice.getSources(); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800305 inline InputDeviceIdentifier getDeviceIdentifier() const {
306 return mEventHub->getDeviceIdentifier(mId);
307 }
308 inline int32_t getDeviceControllerNumber() const {
309 return mEventHub->getDeviceControllerNumber(mId);
310 }
Prabir Pradhan132f21c2024-07-25 16:48:30 +0000311 inline std::optional<RawAbsoluteAxisInfo> getAbsoluteAxisInfo(int32_t code) const {
Harry Cutts207674d2024-06-06 18:53:41 +0000312 std::optional<RawAbsoluteAxisInfo> info = mEventHub->getAbsoluteAxisInfo(mId, code);
Prabir Pradhan10301422023-07-26 21:48:30 +0000313
314 // Validate axis info for InputDevice.
Prabir Pradhan132f21c2024-07-25 16:48:30 +0000315 if (info && info->minValue == info->maxValue) {
Prabir Pradhan10301422023-07-26 21:48:30 +0000316 // Historically, we deem axes with the same min and max values as invalid to avoid
317 // dividing by zero when scaling by max - min.
318 // TODO(b/291772515): Perform axis info validation on a per-axis basis when it is used.
Prabir Pradhan132f21c2024-07-25 16:48:30 +0000319 return std::nullopt;
Prabir Pradhan10301422023-07-26 21:48:30 +0000320 }
Prabir Pradhan132f21c2024-07-25 16:48:30 +0000321 return info;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800322 }
323 inline bool hasRelativeAxis(int32_t code) const {
324 return mEventHub->hasRelativeAxis(mId, code);
325 }
Chris Yef59a2f42020-10-16 12:55:26 -0700326 inline bool hasInputProperty(int32_t property) const {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800327 return mEventHub->hasInputProperty(mId, property);
328 }
Chris Yef59a2f42020-10-16 12:55:26 -0700329
330 inline bool hasMscEvent(int mscEvent) const { return mEventHub->hasMscEvent(mId, mscEvent); }
331
Vaibhav Devmuraricbba14c2022-10-10 16:54:49 +0000332 inline void addKeyRemapping(int32_t fromKeyCode, int32_t toKeyCode) const {
333 mEventHub->addKeyRemapping(mId, fromKeyCode, toKeyCode);
334 }
335
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800336 inline status_t mapKey(int32_t scanCode, int32_t usageCode, int32_t metaState,
337 int32_t* outKeycode, int32_t* outMetaState, uint32_t* outFlags) const {
338 return mEventHub->mapKey(mId, scanCode, usageCode, metaState, outKeycode, outMetaState,
339 outFlags);
340 }
341 inline status_t mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const {
342 return mEventHub->mapAxis(mId, scanCode, outAxisInfo);
343 }
Chris Yef59a2f42020-10-16 12:55:26 -0700344 inline base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor(int32_t absCode) {
345 return mEventHub->mapSensor(mId, absCode);
346 }
347
Chris Ye3fdbfef2021-01-06 18:45:18 -0800348 inline const std::vector<int32_t> getRawLightIds() { return mEventHub->getRawLightIds(mId); }
349
350 inline std::optional<RawLightInfo> getRawLightInfo(int32_t lightId) {
351 return mEventHub->getRawLightInfo(mId, lightId);
352 }
353
354 inline std::optional<int32_t> getLightBrightness(int32_t lightId) {
355 return mEventHub->getLightBrightness(mId, lightId);
356 }
357
358 inline void setLightBrightness(int32_t lightId, int32_t brightness) {
359 return mEventHub->setLightBrightness(mId, lightId, brightness);
360 }
361
362 inline std::optional<std::unordered_map<LightColor, int32_t>> getLightIntensities(
363 int32_t lightId) {
364 return mEventHub->getLightIntensities(mId, lightId);
365 }
366
367 inline void setLightIntensities(int32_t lightId,
368 std::unordered_map<LightColor, int32_t> intensities) {
369 return mEventHub->setLightIntensities(mId, lightId, intensities);
370 }
371
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800372 inline std::vector<TouchVideoFrame> getVideoFrames() { return mEventHub->getVideoFrames(mId); }
373 inline int32_t getScanCodeState(int32_t scanCode) const {
374 return mEventHub->getScanCodeState(mId, scanCode);
375 }
376 inline int32_t getKeyCodeState(int32_t keyCode) const {
377 return mEventHub->getKeyCodeState(mId, keyCode);
378 }
Philip Junker4af3b3d2021-12-14 10:36:55 +0100379 inline int32_t getKeyCodeForKeyLocation(int32_t locationKeyCode) const {
380 return mEventHub->getKeyCodeForKeyLocation(mId, locationKeyCode);
381 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800382 inline int32_t getSwitchState(int32_t sw) const { return mEventHub->getSwitchState(mId, sw); }
Harry Cuttse2c5e202024-06-21 17:08:48 +0000383 inline std::optional<int32_t> getAbsoluteAxisValue(int32_t code) const {
384 return mEventHub->getAbsoluteAxisValue(mId, code);
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800385 }
Arpit Singh4b4a4572023-11-24 18:19:56 +0000386 inline base::Result<std::vector<int32_t>> getMtSlotValues(int32_t axis,
387 size_t slotCount) const {
388 return mEventHub->getMtSlotValues(mId, axis, slotCount);
389 }
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700390 inline bool markSupportedKeyCodes(const std::vector<int32_t>& keyCodes,
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800391 uint8_t* outFlags) const {
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700392 return mEventHub->markSupportedKeyCodes(mId, keyCodes, outFlags);
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800393 }
394 inline bool hasScanCode(int32_t scanCode) const {
395 return mEventHub->hasScanCode(mId, scanCode);
396 }
Arthur Hungcb40a002021-08-03 14:31:01 +0000397 inline bool hasKeyCode(int32_t keyCode) const { return mEventHub->hasKeyCode(mId, keyCode); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800398 inline bool hasLed(int32_t led) const { return mEventHub->hasLed(mId, led); }
399 inline void setLedState(int32_t led, bool on) { return mEventHub->setLedState(mId, led, on); }
400 inline void getVirtualKeyDefinitions(std::vector<VirtualKeyDefinition>& outVirtualKeys) const {
401 return mEventHub->getVirtualKeyDefinitions(mId, outVirtualKeys);
402 }
Chris Ye3a1e4462020-08-12 10:13:15 -0700403 inline const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap() const {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800404 return mEventHub->getKeyCharacterMap(mId);
405 }
Chris Ye3a1e4462020-08-12 10:13:15 -0700406 inline bool setKeyboardLayoutOverlay(std::shared_ptr<KeyCharacterMap> map) {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800407 return mEventHub->setKeyboardLayoutOverlay(mId, map);
408 }
Vaibhav Devmurari7fb41132023-01-02 13:30:26 +0000409 inline const std::optional<RawLayoutInfo> getRawLayoutInfo() {
410 return mEventHub->getRawLayoutInfo(mId);
411 }
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +0000412 inline void vibrate(const VibrationElement& element) {
413 return mEventHub->vibrate(mId, element);
414 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800415 inline void cancelVibrate() { return mEventHub->cancelVibrate(mId); }
416
Chris Ye87143712020-11-10 05:05:58 +0000417 inline std::vector<int32_t> getVibratorIds() { return mEventHub->getVibratorIds(mId); }
418
Chris Yee2b1e5c2021-03-10 22:45:12 -0800419 inline const std::vector<int32_t> getRawBatteryIds() {
420 return mEventHub->getRawBatteryIds(mId);
Kim Low03ea0352020-11-06 12:45:07 -0800421 }
422
Chris Yee2b1e5c2021-03-10 22:45:12 -0800423 inline std::optional<RawBatteryInfo> getRawBatteryInfo(int32_t batteryId) {
424 return mEventHub->getRawBatteryInfo(mId, batteryId);
425 }
426
427 inline std::optional<int32_t> getBatteryCapacity(int32_t batteryId) {
428 return mEventHub->getBatteryCapacity(mId, batteryId);
429 }
430
431 inline std::optional<int32_t> getBatteryStatus(int32_t batteryId) {
432 return mEventHub->getBatteryStatus(mId, batteryId);
433 }
Kim Low03ea0352020-11-06 12:45:07 -0800434
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800435 inline bool hasAbsoluteAxis(int32_t code) const {
Prabir Pradhan132f21c2024-07-25 16:48:30 +0000436 return mEventHub->getAbsoluteAxisInfo(mId, code).has_value();
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800437 }
Prabir Pradhan4f05b5f2022-10-11 21:24:07 +0000438 inline bool isKeyPressed(int32_t scanCode) const {
439 return mEventHub->getScanCodeState(mId, scanCode) == AKEY_STATE_DOWN;
440 }
441 inline bool isKeyCodePressed(int32_t keyCode) const {
442 return mEventHub->getKeyCodeState(mId, keyCode) == AKEY_STATE_DOWN;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800443 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800444 inline bool isDeviceEnabled() { return mEventHub->isDeviceEnabled(mId); }
445 inline status_t enableDevice() { return mEventHub->enableDevice(mId); }
446 inline status_t disableDevice() { return mEventHub->disableDevice(mId); }
447
Harry Cuttsba9364a2022-12-15 12:39:04 +0000448 inline const std::string getName() const { return mDevice.getName(); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800449 inline const std::string getDescriptor() { return mDevice.getDescriptor(); }
Zixuan Qufecb6062022-11-12 04:44:31 +0000450 inline const std::string getLocation() { return mDevice.getLocation(); }
Arpit Singh403e53c2023-04-18 11:46:56 +0000451 inline bool isExternal() const { return mDevice.isExternal(); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800452 inline std::optional<uint8_t> getAssociatedDisplayPort() const {
453 return mDevice.getAssociatedDisplayPort();
454 }
Antonio Kantek0ac5e092024-04-22 17:10:27 +0000455 inline std::optional<std::string> getAssociatedDisplayUniqueIdByPort() const {
456 return mDevice.getAssociatedDisplayUniqueIdByPort();
457 }
458 inline std::optional<std::string> getAssociatedDisplayUniqueIdByDescriptor() const {
459 return mDevice.getAssociatedDisplayUniqueIdByDescriptor();
Christine Franks2a2293c2022-01-18 11:51:16 -0800460 }
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +0000461 inline std::optional<std::string> getDeviceTypeAssociation() const {
462 return mDevice.getDeviceTypeAssociation();
463 }
Harry Cutts92559ef2024-01-05 12:45:36 +0000464 virtual std::optional<DisplayViewport> getAssociatedViewport() const {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800465 return mDevice.getAssociatedViewport();
466 }
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700467 [[nodiscard]] inline std::list<NotifyArgs> cancelTouch(nsecs_t when, nsecs_t readTime) {
468 return mDevice.cancelTouch(when, readTime);
469 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800470 inline void bumpGeneration() { mDevice.bumpGeneration(); }
Arpit Singh403e53c2023-04-18 11:46:56 +0000471 inline const PropertyMap& getConfiguration() const { return mDevice.getConfiguration(); }
Vaibhav Devmurarie58ffb92024-05-22 17:38:25 +0000472 inline KeyboardType getKeyboardType() const { return mDevice.getKeyboardType(); }
473 inline void setKeyboardType(KeyboardType keyboardType) {
474 return mDevice.setKeyboardType(keyboardType);
475 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800476
477private:
478 InputDevice& mDevice;
479 InputReaderContext* mContext;
480 EventHubInterface* mEventHub;
481 int32_t mId;
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800482 int32_t mDeviceId;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800483};
484
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700485} // namespace android