blob: 0719b0ce3c4329e8284df15a91f9df7538ad77aa [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 Pradhanbaa5c822019-08-30 15:27:05 -070046 ~InputDevice();
47
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 Pradhanbaa5c822019-08-30 15:27:05 -070059 inline 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 }
Christine Franks2a2293c2022-01-18 11:51:16 -080066 inline std::optional<std::string> getAssociatedDisplayUniqueId() const {
67 return mAssociatedDisplayUniqueId;
68 }
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +000069 inline std::optional<std::string> getDeviceTypeAssociation() const {
70 return mAssociatedDeviceType;
71 }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070072 inline std::optional<DisplayViewport> getAssociatedViewport() const {
73 return mAssociatedViewport;
74 }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070075 inline bool hasMic() const { return mHasMic; }
76
Vaibhav Devmurari16c24192023-05-04 15:20:12 +000077 inline bool isIgnored() { return !getMapperCount() && !mController; }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070078
79 bool isEnabled();
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070080
Chris Yee7310032020-09-22 15:36:28 -070081 void dump(std::string& dump, const std::string& eventHubDevStr);
Arpit Singh8e6fb252023-04-06 11:49:17 +000082 void addEmptyEventHubDevice(int32_t eventHubId);
Arpit Singh82f29a12023-06-13 15:05:53 +000083 [[nodiscard]] std::list<NotifyArgs> addEventHubDevice(
84 nsecs_t when, int32_t eventHubId, const InputReaderConfiguration& readerConfig);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080085 void removeEventHubDevice(int32_t eventHubId);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070086 [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when,
Arpit Singhed6c3de2023-04-05 19:24:37 +000087 const InputReaderConfiguration& readerConfig,
Arpit Singh7f1765e2023-07-07 13:12:37 +000088 ConfigurationChanges changes);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070089 [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when);
90 [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvents, size_t count);
91 [[nodiscard]] std::list<NotifyArgs> timeoutExpired(nsecs_t when);
92 [[nodiscard]] std::list<NotifyArgs> updateExternalStylusState(const StylusState& state);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070093
Siarhei Vishniakou1983a712021-06-04 19:27:09 +000094 InputDeviceInfo getDeviceInfo();
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070095 int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
96 int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
97 int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
Philip Junker4af3b3d2021-12-14 10:36:55 +010098 int32_t getKeyCodeForKeyLocation(int32_t locationKeyCode) const;
Siarhei Vishniakou74007942022-06-13 13:57:47 -070099 bool markSupportedKeyCodes(uint32_t sourceMask, const std::vector<int32_t>& keyCodes,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700100 uint8_t* outFlags);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700101 [[nodiscard]] std::list<NotifyArgs> vibrate(const VibrationSequence& sequence, ssize_t repeat,
102 int32_t token);
103 [[nodiscard]] std::list<NotifyArgs> cancelVibrate(int32_t token);
Chris Ye87143712020-11-10 05:05:58 +0000104 bool isVibrating();
105 std::vector<int32_t> getVibratorIds();
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700106 [[nodiscard]] std::list<NotifyArgs> cancelTouch(nsecs_t when, nsecs_t readTime);
Chris Yef59a2f42020-10-16 12:55:26 -0700107 bool enableSensor(InputDeviceSensorType sensorType, std::chrono::microseconds samplingPeriod,
108 std::chrono::microseconds maxBatchReportLatency);
109 void disableSensor(InputDeviceSensorType sensorType);
110 void flushSensor(InputDeviceSensorType sensorType);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700111
Andy Chenf9f1a022022-08-29 20:07:10 -0400112 std::optional<int32_t> getBatteryEventHubId() const;
Kim Low03ea0352020-11-06 12:45:07 -0800113
Chris Ye3fdbfef2021-01-06 18:45:18 -0800114 bool setLightColor(int32_t lightId, int32_t color);
115 bool setLightPlayerId(int32_t lightId, int32_t playerId);
116 std::optional<int32_t> getLightColor(int32_t lightId);
117 std::optional<int32_t> getLightPlayerId(int32_t lightId);
118
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700119 int32_t getMetaState();
120 void updateMetaState(int32_t keyCode);
121
Vaibhav Devmuraricbba14c2022-10-10 16:54:49 +0000122 void addKeyRemapping(int32_t fromKeyCode, int32_t toKeyCode);
123
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700124 void bumpGeneration();
125
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700126 [[nodiscard]] NotifyDeviceResetArgs notifyReset(nsecs_t when);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700127
128 inline const PropertyMap& getConfiguration() { return mConfiguration; }
129 inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
130
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700131 std::optional<int32_t> getAssociatedDisplayId();
132
arthurhungc903df12020-08-11 15:08:42 +0800133 void updateLedState(bool reset);
134
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800135 size_t getMapperCount();
136
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800137 // construct and add a mapper to the input device
138 template <class T, typename... Args>
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800139 T& addMapper(int32_t eventHubId, Args... args) {
140 // ensure a device entry exists for this eventHubId
Arpit Singh8e6fb252023-04-06 11:49:17 +0000141 addEmptyEventHubDevice(eventHubId);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800142
143 // create mapper
144 auto& devicePair = mDevices[eventHubId];
145 auto& deviceContext = devicePair.first;
146 auto& mappers = devicePair.second;
147 T* mapper = new T(*deviceContext, args...);
148 mappers.emplace_back(mapper);
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800149 return *mapper;
150 }
151
Arpit Singh56adebc2023-04-25 13:56:05 +0000152 template <class T, typename... Args>
153 T& constructAndAddMapper(int32_t eventHubId, Args... args) {
154 // create mapper
155 auto& devicePair = mDevices[eventHubId];
156 auto& deviceContext = devicePair.first;
157 auto& mappers = devicePair.second;
158 mappers.push_back(createInputMapper<T>(*deviceContext, args...));
159 return static_cast<T&>(*mappers.back());
160 }
161
Chris Yee2b1e5c2021-03-10 22:45:12 -0800162 // construct and add a controller to the input device
163 template <class T>
164 T& addController(int32_t eventHubId) {
165 // ensure a device entry exists for this eventHubId
Arpit Singh8e6fb252023-04-06 11:49:17 +0000166 addEmptyEventHubDevice(eventHubId);
Chris Yee2b1e5c2021-03-10 22:45:12 -0800167
168 // create controller
169 auto& devicePair = mDevices[eventHubId];
170 auto& deviceContext = devicePair.first;
171
172 mController = std::make_unique<T>(*deviceContext);
173 return *(reinterpret_cast<T*>(mController.get()));
174 }
175
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700176private:
177 InputReaderContext* mContext;
178 int32_t mId;
179 int32_t mGeneration;
180 int32_t mControllerNumber;
181 InputDeviceIdentifier mIdentifier;
182 std::string mAlias;
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700183 ftl::Flags<InputDeviceClass> mClasses;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700184
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800185 // map from eventHubId to device context and mappers
186 using MapperVector = std::vector<std::unique_ptr<InputMapper>>;
187 using DevicePair = std::pair<std::unique_ptr<InputDeviceContext>, MapperVector>;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800188 // Map from EventHub ID to pair of device context and vector of mapper.
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800189 std::unordered_map<int32_t, DevicePair> mDevices;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800190 // Misc devices controller for lights, battery, etc.
Chris Ye1dd2e5c2021-04-04 23:12:41 -0700191 std::unique_ptr<PeripheralControllerInterface> mController;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700192
193 uint32_t mSources;
Yeabkal Wubshite03e8b12023-06-27 16:23:12 -0700194 bool mIsWaking;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700195 bool mIsExternal;
196 std::optional<uint8_t> mAssociatedDisplayPort;
Christine Franks1ba71cc2021-04-07 14:37:42 -0700197 std::optional<std::string> mAssociatedDisplayUniqueId;
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +0000198 std::optional<std::string> mAssociatedDeviceType;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700199 std::optional<DisplayViewport> mAssociatedViewport;
200 bool mHasMic;
201 bool mDropUntilNextSync;
Yeabkal Wubshitb1b96db2024-01-24 12:47:00 -0800202 std::optional<bool> mShouldSmoothScroll;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700203
204 typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);
205 int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
206
Arpit Singh8e6fb252023-04-06 11:49:17 +0000207 std::vector<std::unique_ptr<InputMapper>> createMappers(
208 InputDeviceContext& contextPtr, const InputReaderConfiguration& readerConfig);
209
Arpit Singh82f29a12023-06-13 15:05:53 +0000210 [[nodiscard]] std::list<NotifyArgs> configureInternal(
211 nsecs_t when, const InputReaderConfiguration& readerConfig,
212 ConfigurationChanges changes, bool forceEnable = false);
213
Arpit Singh48189772023-05-30 14:12:49 +0000214 [[nodiscard]] std::list<NotifyArgs> updateEnableState(
Arpit Singh82f29a12023-06-13 15:05:53 +0000215 nsecs_t when, const InputReaderConfiguration& readerConfig, bool forceEnable = false);
Arpit Singh48189772023-05-30 14:12:49 +0000216
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700217 PropertyMap mConfiguration;
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800218
Yeabkal Wubshite03e8b12023-06-27 16:23:12 -0700219 // Runs logic post a `process` call. This can be used to update the generated `NotifyArgs` as
220 // per the properties of the InputDevice.
221 void postProcess(std::list<NotifyArgs>& args) const;
222
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800223 // helpers to interate over the devices collection
224 // run a function against every mapper on every subdevice
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800225 inline void for_each_mapper(std::function<void(InputMapper&)> f) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800226 for (auto& deviceEntry : mDevices) {
227 auto& devicePair = deviceEntry.second;
228 auto& mappers = devicePair.second;
229 for (auto& mapperPtr : mappers) {
230 f(*mapperPtr);
231 }
232 }
233 }
234
235 // run a function against every mapper on a specific subdevice
236 inline void for_each_mapper_in_subdevice(int32_t eventHubDevice,
237 std::function<void(InputMapper&)> f) {
238 auto deviceIt = mDevices.find(eventHubDevice);
239 if (deviceIt != mDevices.end()) {
240 auto& devicePair = deviceIt->second;
241 auto& mappers = devicePair.second;
242 for (auto& mapperPtr : mappers) {
243 f(*mapperPtr);
244 }
245 }
246 }
247
248 // run a function against every subdevice
249 inline void for_each_subdevice(std::function<void(InputDeviceContext&)> f) {
250 for (auto& deviceEntry : mDevices) {
251 auto& devicePair = deviceEntry.second;
252 auto& contextPtr = devicePair.first;
253 f(*contextPtr);
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800254 }
255 }
256
257 // return the first value returned by a function over every mapper.
258 // if all mappers return nullopt, return nullopt.
259 template <typename T>
Philip Junker4af3b3d2021-12-14 10:36:55 +0100260 inline std::optional<T> first_in_mappers(
261 std::function<std::optional<T>(InputMapper&)> f) const {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800262 for (auto& deviceEntry : mDevices) {
263 auto& devicePair = deviceEntry.second;
264 auto& mappers = devicePair.second;
265 for (auto& mapperPtr : mappers) {
266 std::optional<T> ret = f(*mapperPtr);
267 if (ret) {
268 return ret;
269 }
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800270 }
271 }
272 return std::nullopt;
273 }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700274};
275
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800276/* Provides access to EventHub methods, but limits access to the current InputDevice.
277 * Essentially an implementation of EventHubInterface, but for a specific device id.
278 * Helps hide implementation details of InputDevice and EventHub. Used by mappers to
279 * check the status of the associated hardware device
280 */
281class InputDeviceContext {
282public:
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800283 InputDeviceContext(InputDevice& device, int32_t eventHubId);
Harry Cutts92559ef2024-01-05 12:45:36 +0000284 virtual ~InputDeviceContext();
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800285
286 inline InputReaderContext* getContext() { return mContext; }
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800287 inline int32_t getId() { return mDeviceId; }
288 inline int32_t getEventHubId() { return mId; }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800289
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700290 inline ftl::Flags<InputDeviceClass> getDeviceClasses() const {
Chris Ye1b0c7342020-07-28 21:57:03 -0700291 return mEventHub->getDeviceClasses(mId);
292 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800293 inline InputDeviceIdentifier getDeviceIdentifier() const {
294 return mEventHub->getDeviceIdentifier(mId);
295 }
296 inline int32_t getDeviceControllerNumber() const {
297 return mEventHub->getDeviceControllerNumber(mId);
298 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800299 inline status_t getAbsoluteAxisInfo(int32_t code, RawAbsoluteAxisInfo* axisInfo) const {
Prabir Pradhan10301422023-07-26 21:48:30 +0000300 if (const auto status = mEventHub->getAbsoluteAxisInfo(mId, code, axisInfo); status != OK) {
301 return status;
302 }
303
304 // Validate axis info for InputDevice.
305 if (axisInfo->valid && axisInfo->minValue == axisInfo->maxValue) {
306 // Historically, we deem axes with the same min and max values as invalid to avoid
307 // dividing by zero when scaling by max - min.
308 // TODO(b/291772515): Perform axis info validation on a per-axis basis when it is used.
309 axisInfo->valid = false;
310 }
311 return OK;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800312 }
313 inline bool hasRelativeAxis(int32_t code) const {
314 return mEventHub->hasRelativeAxis(mId, code);
315 }
Chris Yef59a2f42020-10-16 12:55:26 -0700316 inline bool hasInputProperty(int32_t property) const {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800317 return mEventHub->hasInputProperty(mId, property);
318 }
Chris Yef59a2f42020-10-16 12:55:26 -0700319
320 inline bool hasMscEvent(int mscEvent) const { return mEventHub->hasMscEvent(mId, mscEvent); }
321
Vaibhav Devmuraricbba14c2022-10-10 16:54:49 +0000322 inline void addKeyRemapping(int32_t fromKeyCode, int32_t toKeyCode) const {
323 mEventHub->addKeyRemapping(mId, fromKeyCode, toKeyCode);
324 }
325
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800326 inline status_t mapKey(int32_t scanCode, int32_t usageCode, int32_t metaState,
327 int32_t* outKeycode, int32_t* outMetaState, uint32_t* outFlags) const {
328 return mEventHub->mapKey(mId, scanCode, usageCode, metaState, outKeycode, outMetaState,
329 outFlags);
330 }
331 inline status_t mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const {
332 return mEventHub->mapAxis(mId, scanCode, outAxisInfo);
333 }
Chris Yef59a2f42020-10-16 12:55:26 -0700334 inline base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor(int32_t absCode) {
335 return mEventHub->mapSensor(mId, absCode);
336 }
337
Chris Ye3fdbfef2021-01-06 18:45:18 -0800338 inline const std::vector<int32_t> getRawLightIds() { return mEventHub->getRawLightIds(mId); }
339
340 inline std::optional<RawLightInfo> getRawLightInfo(int32_t lightId) {
341 return mEventHub->getRawLightInfo(mId, lightId);
342 }
343
344 inline std::optional<int32_t> getLightBrightness(int32_t lightId) {
345 return mEventHub->getLightBrightness(mId, lightId);
346 }
347
348 inline void setLightBrightness(int32_t lightId, int32_t brightness) {
349 return mEventHub->setLightBrightness(mId, lightId, brightness);
350 }
351
352 inline std::optional<std::unordered_map<LightColor, int32_t>> getLightIntensities(
353 int32_t lightId) {
354 return mEventHub->getLightIntensities(mId, lightId);
355 }
356
357 inline void setLightIntensities(int32_t lightId,
358 std::unordered_map<LightColor, int32_t> intensities) {
359 return mEventHub->setLightIntensities(mId, lightId, intensities);
360 }
361
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800362 inline std::vector<TouchVideoFrame> getVideoFrames() { return mEventHub->getVideoFrames(mId); }
363 inline int32_t getScanCodeState(int32_t scanCode) const {
364 return mEventHub->getScanCodeState(mId, scanCode);
365 }
366 inline int32_t getKeyCodeState(int32_t keyCode) const {
367 return mEventHub->getKeyCodeState(mId, keyCode);
368 }
Philip Junker4af3b3d2021-12-14 10:36:55 +0100369 inline int32_t getKeyCodeForKeyLocation(int32_t locationKeyCode) const {
370 return mEventHub->getKeyCodeForKeyLocation(mId, locationKeyCode);
371 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800372 inline int32_t getSwitchState(int32_t sw) const { return mEventHub->getSwitchState(mId, sw); }
373 inline status_t getAbsoluteAxisValue(int32_t code, int32_t* outValue) const {
374 return mEventHub->getAbsoluteAxisValue(mId, code, outValue);
375 }
Arpit Singh4b4a4572023-11-24 18:19:56 +0000376 inline base::Result<std::vector<int32_t>> getMtSlotValues(int32_t axis,
377 size_t slotCount) const {
378 return mEventHub->getMtSlotValues(mId, axis, slotCount);
379 }
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700380 inline bool markSupportedKeyCodes(const std::vector<int32_t>& keyCodes,
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800381 uint8_t* outFlags) const {
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700382 return mEventHub->markSupportedKeyCodes(mId, keyCodes, outFlags);
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800383 }
384 inline bool hasScanCode(int32_t scanCode) const {
385 return mEventHub->hasScanCode(mId, scanCode);
386 }
Arthur Hungcb40a002021-08-03 14:31:01 +0000387 inline bool hasKeyCode(int32_t keyCode) const { return mEventHub->hasKeyCode(mId, keyCode); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800388 inline bool hasLed(int32_t led) const { return mEventHub->hasLed(mId, led); }
389 inline void setLedState(int32_t led, bool on) { return mEventHub->setLedState(mId, led, on); }
390 inline void getVirtualKeyDefinitions(std::vector<VirtualKeyDefinition>& outVirtualKeys) const {
391 return mEventHub->getVirtualKeyDefinitions(mId, outVirtualKeys);
392 }
Chris Ye3a1e4462020-08-12 10:13:15 -0700393 inline const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap() const {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800394 return mEventHub->getKeyCharacterMap(mId);
395 }
Chris Ye3a1e4462020-08-12 10:13:15 -0700396 inline bool setKeyboardLayoutOverlay(std::shared_ptr<KeyCharacterMap> map) {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800397 return mEventHub->setKeyboardLayoutOverlay(mId, map);
398 }
Vaibhav Devmurari7fb41132023-01-02 13:30:26 +0000399 inline const std::optional<RawLayoutInfo> getRawLayoutInfo() {
400 return mEventHub->getRawLayoutInfo(mId);
401 }
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +0000402 inline void vibrate(const VibrationElement& element) {
403 return mEventHub->vibrate(mId, element);
404 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800405 inline void cancelVibrate() { return mEventHub->cancelVibrate(mId); }
406
Chris Ye87143712020-11-10 05:05:58 +0000407 inline std::vector<int32_t> getVibratorIds() { return mEventHub->getVibratorIds(mId); }
408
Chris Yee2b1e5c2021-03-10 22:45:12 -0800409 inline const std::vector<int32_t> getRawBatteryIds() {
410 return mEventHub->getRawBatteryIds(mId);
Kim Low03ea0352020-11-06 12:45:07 -0800411 }
412
Chris Yee2b1e5c2021-03-10 22:45:12 -0800413 inline std::optional<RawBatteryInfo> getRawBatteryInfo(int32_t batteryId) {
414 return mEventHub->getRawBatteryInfo(mId, batteryId);
415 }
416
417 inline std::optional<int32_t> getBatteryCapacity(int32_t batteryId) {
418 return mEventHub->getBatteryCapacity(mId, batteryId);
419 }
420
421 inline std::optional<int32_t> getBatteryStatus(int32_t batteryId) {
422 return mEventHub->getBatteryStatus(mId, batteryId);
423 }
Kim Low03ea0352020-11-06 12:45:07 -0800424
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800425 inline bool hasAbsoluteAxis(int32_t code) const {
426 RawAbsoluteAxisInfo info;
427 mEventHub->getAbsoluteAxisInfo(mId, code, &info);
428 return info.valid;
429 }
Prabir Pradhan4f05b5f2022-10-11 21:24:07 +0000430 inline bool isKeyPressed(int32_t scanCode) const {
431 return mEventHub->getScanCodeState(mId, scanCode) == AKEY_STATE_DOWN;
432 }
433 inline bool isKeyCodePressed(int32_t keyCode) const {
434 return mEventHub->getKeyCodeState(mId, keyCode) == AKEY_STATE_DOWN;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800435 }
436 inline int32_t getAbsoluteAxisValue(int32_t code) const {
437 int32_t value;
438 mEventHub->getAbsoluteAxisValue(mId, code, &value);
439 return value;
440 }
441 inline bool isDeviceEnabled() { return mEventHub->isDeviceEnabled(mId); }
442 inline status_t enableDevice() { return mEventHub->enableDevice(mId); }
443 inline status_t disableDevice() { return mEventHub->disableDevice(mId); }
444
Harry Cuttsba9364a2022-12-15 12:39:04 +0000445 inline const std::string getName() const { return mDevice.getName(); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800446 inline const std::string getDescriptor() { return mDevice.getDescriptor(); }
Zixuan Qufecb6062022-11-12 04:44:31 +0000447 inline const std::string getLocation() { return mDevice.getLocation(); }
Arpit Singh403e53c2023-04-18 11:46:56 +0000448 inline bool isExternal() const { return mDevice.isExternal(); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800449 inline std::optional<uint8_t> getAssociatedDisplayPort() const {
450 return mDevice.getAssociatedDisplayPort();
451 }
Christine Franks2a2293c2022-01-18 11:51:16 -0800452 inline std::optional<std::string> getAssociatedDisplayUniqueId() const {
453 return mDevice.getAssociatedDisplayUniqueId();
454 }
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +0000455 inline std::optional<std::string> getDeviceTypeAssociation() const {
456 return mDevice.getDeviceTypeAssociation();
457 }
Harry Cutts92559ef2024-01-05 12:45:36 +0000458 virtual std::optional<DisplayViewport> getAssociatedViewport() const {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800459 return mDevice.getAssociatedViewport();
460 }
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700461 [[nodiscard]] inline std::list<NotifyArgs> cancelTouch(nsecs_t when, nsecs_t readTime) {
462 return mDevice.cancelTouch(when, readTime);
463 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800464 inline void bumpGeneration() { mDevice.bumpGeneration(); }
Arpit Singh403e53c2023-04-18 11:46:56 +0000465 inline const PropertyMap& getConfiguration() const { return mDevice.getConfiguration(); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800466
467private:
468 InputDevice& mDevice;
469 InputReaderContext* mContext;
470 EventHubInterface* mEventHub;
471 int32_t mId;
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800472 int32_t mDeviceId;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800473};
474
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700475} // namespace android