blob: 4c9af2e30e82ed98aef8b2312104b18d53f602de [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 }
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 }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070075 inline std::optional<DisplayViewport> getAssociatedViewport() const {
76 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
82 bool isEnabled();
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070083
Chris Yee7310032020-09-22 15:36:28 -070084 void dump(std::string& dump, const std::string& eventHubDevStr);
Arpit Singh8e6fb252023-04-06 11:49:17 +000085 void addEmptyEventHubDevice(int32_t eventHubId);
Arpit Singh82f29a12023-06-13 15:05:53 +000086 [[nodiscard]] std::list<NotifyArgs> addEventHubDevice(
87 nsecs_t when, int32_t eventHubId, const InputReaderConfiguration& readerConfig);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080088 void removeEventHubDevice(int32_t eventHubId);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070089 [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when,
Arpit Singhed6c3de2023-04-05 19:24:37 +000090 const InputReaderConfiguration& readerConfig,
Arpit Singh7f1765e2023-07-07 13:12:37 +000091 ConfigurationChanges changes);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070092 [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when);
93 [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvents, size_t count);
94 [[nodiscard]] std::list<NotifyArgs> timeoutExpired(nsecs_t when);
95 [[nodiscard]] std::list<NotifyArgs> updateExternalStylusState(const StylusState& state);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070096
Siarhei Vishniakou1983a712021-06-04 19:27:09 +000097 InputDeviceInfo getDeviceInfo();
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070098 int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
99 int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
100 int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
Philip Junker4af3b3d2021-12-14 10:36:55 +0100101 int32_t getKeyCodeForKeyLocation(int32_t locationKeyCode) const;
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700102 bool markSupportedKeyCodes(uint32_t sourceMask, const std::vector<int32_t>& keyCodes,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700103 uint8_t* outFlags);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700104 [[nodiscard]] std::list<NotifyArgs> vibrate(const VibrationSequence& sequence, ssize_t repeat,
105 int32_t token);
106 [[nodiscard]] std::list<NotifyArgs> cancelVibrate(int32_t token);
Chris Ye87143712020-11-10 05:05:58 +0000107 bool isVibrating();
108 std::vector<int32_t> getVibratorIds();
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700109 [[nodiscard]] std::list<NotifyArgs> cancelTouch(nsecs_t when, nsecs_t readTime);
Chris Yef59a2f42020-10-16 12:55:26 -0700110 bool enableSensor(InputDeviceSensorType sensorType, std::chrono::microseconds samplingPeriod,
111 std::chrono::microseconds maxBatchReportLatency);
112 void disableSensor(InputDeviceSensorType sensorType);
113 void flushSensor(InputDeviceSensorType sensorType);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700114
Andy Chenf9f1a022022-08-29 20:07:10 -0400115 std::optional<int32_t> getBatteryEventHubId() const;
Kim Low03ea0352020-11-06 12:45:07 -0800116
Chris Ye3fdbfef2021-01-06 18:45:18 -0800117 bool setLightColor(int32_t lightId, int32_t color);
118 bool setLightPlayerId(int32_t lightId, int32_t playerId);
119 std::optional<int32_t> getLightColor(int32_t lightId);
120 std::optional<int32_t> getLightPlayerId(int32_t lightId);
121
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700122 int32_t getMetaState();
123 void updateMetaState(int32_t keyCode);
124
Vaibhav Devmuraricbba14c2022-10-10 16:54:49 +0000125 void addKeyRemapping(int32_t fromKeyCode, int32_t toKeyCode);
126
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700127 void bumpGeneration();
128
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700129 [[nodiscard]] NotifyDeviceResetArgs notifyReset(nsecs_t when);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700130
131 inline const PropertyMap& getConfiguration() { return mConfiguration; }
132 inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
133
Linnan Li13bf76a2024-05-05 19:18:02 +0800134 std::optional<ui::LogicalDisplayId> getAssociatedDisplayId();
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700135
arthurhungc903df12020-08-11 15:08:42 +0800136 void updateLedState(bool reset);
137
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800138 size_t getMapperCount();
139
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800140 // construct and add a mapper to the input device
141 template <class T, typename... Args>
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800142 T& addMapper(int32_t eventHubId, Args... args) {
143 // ensure a device entry exists for this eventHubId
Arpit Singh8e6fb252023-04-06 11:49:17 +0000144 addEmptyEventHubDevice(eventHubId);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800145
146 // create mapper
147 auto& devicePair = mDevices[eventHubId];
148 auto& deviceContext = devicePair.first;
149 auto& mappers = devicePair.second;
150 T* mapper = new T(*deviceContext, args...);
151 mappers.emplace_back(mapper);
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800152 return *mapper;
153 }
154
Arpit Singh56adebc2023-04-25 13:56:05 +0000155 template <class T, typename... Args>
156 T& constructAndAddMapper(int32_t eventHubId, Args... args) {
157 // create mapper
158 auto& devicePair = mDevices[eventHubId];
159 auto& deviceContext = devicePair.first;
160 auto& mappers = devicePair.second;
161 mappers.push_back(createInputMapper<T>(*deviceContext, args...));
162 return static_cast<T&>(*mappers.back());
163 }
164
Chris Yee2b1e5c2021-03-10 22:45:12 -0800165 // construct and add a controller to the input device
166 template <class T>
167 T& addController(int32_t eventHubId) {
168 // ensure a device entry exists for this eventHubId
Arpit Singh8e6fb252023-04-06 11:49:17 +0000169 addEmptyEventHubDevice(eventHubId);
Chris Yee2b1e5c2021-03-10 22:45:12 -0800170
171 // create controller
172 auto& devicePair = mDevices[eventHubId];
173 auto& deviceContext = devicePair.first;
174
175 mController = std::make_unique<T>(*deviceContext);
176 return *(reinterpret_cast<T*>(mController.get()));
177 }
178
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700179private:
180 InputReaderContext* mContext;
181 int32_t mId;
182 int32_t mGeneration;
183 int32_t mControllerNumber;
184 InputDeviceIdentifier mIdentifier;
185 std::string mAlias;
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700186 ftl::Flags<InputDeviceClass> mClasses;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700187
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800188 // map from eventHubId to device context and mappers
189 using MapperVector = std::vector<std::unique_ptr<InputMapper>>;
190 using DevicePair = std::pair<std::unique_ptr<InputDeviceContext>, MapperVector>;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800191 // Map from EventHub ID to pair of device context and vector of mapper.
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800192 std::unordered_map<int32_t, DevicePair> mDevices;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800193 // Misc devices controller for lights, battery, etc.
Chris Ye1dd2e5c2021-04-04 23:12:41 -0700194 std::unique_ptr<PeripheralControllerInterface> mController;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700195
196 uint32_t mSources;
Yeabkal Wubshite03e8b12023-06-27 16:23:12 -0700197 bool mIsWaking;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700198 bool mIsExternal;
199 std::optional<uint8_t> mAssociatedDisplayPort;
Antonio Kantek0ac5e092024-04-22 17:10:27 +0000200 std::optional<std::string> mAssociatedDisplayUniqueIdByPort;
201 std::optional<std::string> mAssociatedDisplayUniqueIdByDescriptor;
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +0000202 std::optional<std::string> mAssociatedDeviceType;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700203 std::optional<DisplayViewport> mAssociatedViewport;
204 bool mHasMic;
205 bool mDropUntilNextSync;
Yeabkal Wubshitb1b96db2024-01-24 12:47:00 -0800206 std::optional<bool> mShouldSmoothScroll;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700207
208 typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);
209 int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
210
Arpit Singh8e6fb252023-04-06 11:49:17 +0000211 std::vector<std::unique_ptr<InputMapper>> createMappers(
212 InputDeviceContext& contextPtr, const InputReaderConfiguration& readerConfig);
213
Arpit Singh82f29a12023-06-13 15:05:53 +0000214 [[nodiscard]] std::list<NotifyArgs> configureInternal(
215 nsecs_t when, const InputReaderConfiguration& readerConfig,
216 ConfigurationChanges changes, bool forceEnable = false);
217
Arpit Singh48189772023-05-30 14:12:49 +0000218 [[nodiscard]] std::list<NotifyArgs> updateEnableState(
Arpit Singh82f29a12023-06-13 15:05:53 +0000219 nsecs_t when, const InputReaderConfiguration& readerConfig, bool forceEnable = false);
Arpit Singh48189772023-05-30 14:12:49 +0000220
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700221 PropertyMap mConfiguration;
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800222
Yeabkal Wubshite03e8b12023-06-27 16:23:12 -0700223 // Runs logic post a `process` call. This can be used to update the generated `NotifyArgs` as
224 // per the properties of the InputDevice.
225 void postProcess(std::list<NotifyArgs>& args) const;
226
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800227 // helpers to interate over the devices collection
228 // run a function against every mapper on every subdevice
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800229 inline void for_each_mapper(std::function<void(InputMapper&)> f) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800230 for (auto& deviceEntry : mDevices) {
231 auto& devicePair = deviceEntry.second;
232 auto& mappers = devicePair.second;
233 for (auto& mapperPtr : mappers) {
234 f(*mapperPtr);
235 }
236 }
237 }
238
239 // run a function against every mapper on a specific subdevice
240 inline void for_each_mapper_in_subdevice(int32_t eventHubDevice,
241 std::function<void(InputMapper&)> f) {
242 auto deviceIt = mDevices.find(eventHubDevice);
243 if (deviceIt != mDevices.end()) {
244 auto& devicePair = deviceIt->second;
245 auto& mappers = devicePair.second;
246 for (auto& mapperPtr : mappers) {
247 f(*mapperPtr);
248 }
249 }
250 }
251
252 // run a function against every subdevice
253 inline void for_each_subdevice(std::function<void(InputDeviceContext&)> f) {
254 for (auto& deviceEntry : mDevices) {
255 auto& devicePair = deviceEntry.second;
256 auto& contextPtr = devicePair.first;
257 f(*contextPtr);
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800258 }
259 }
260
261 // return the first value returned by a function over every mapper.
262 // if all mappers return nullopt, return nullopt.
263 template <typename T>
Philip Junker4af3b3d2021-12-14 10:36:55 +0100264 inline std::optional<T> first_in_mappers(
265 std::function<std::optional<T>(InputMapper&)> f) const {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800266 for (auto& deviceEntry : mDevices) {
267 auto& devicePair = deviceEntry.second;
268 auto& mappers = devicePair.second;
269 for (auto& mapperPtr : mappers) {
270 std::optional<T> ret = f(*mapperPtr);
271 if (ret) {
272 return ret;
273 }
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800274 }
275 }
276 return std::nullopt;
277 }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700278};
279
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800280/* Provides access to EventHub methods, but limits access to the current InputDevice.
281 * Essentially an implementation of EventHubInterface, but for a specific device id.
282 * Helps hide implementation details of InputDevice and EventHub. Used by mappers to
283 * check the status of the associated hardware device
284 */
285class InputDeviceContext {
286public:
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800287 InputDeviceContext(InputDevice& device, int32_t eventHubId);
Harry Cutts92559ef2024-01-05 12:45:36 +0000288 virtual ~InputDeviceContext();
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800289
290 inline InputReaderContext* getContext() { return mContext; }
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800291 inline int32_t getId() { return mDeviceId; }
292 inline int32_t getEventHubId() { return mId; }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800293
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700294 inline ftl::Flags<InputDeviceClass> getDeviceClasses() const {
Chris Ye1b0c7342020-07-28 21:57:03 -0700295 return mEventHub->getDeviceClasses(mId);
296 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800297 inline InputDeviceIdentifier getDeviceIdentifier() const {
298 return mEventHub->getDeviceIdentifier(mId);
299 }
300 inline int32_t getDeviceControllerNumber() const {
301 return mEventHub->getDeviceControllerNumber(mId);
302 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800303 inline status_t getAbsoluteAxisInfo(int32_t code, RawAbsoluteAxisInfo* axisInfo) const {
Prabir Pradhan10301422023-07-26 21:48:30 +0000304 if (const auto status = mEventHub->getAbsoluteAxisInfo(mId, code, axisInfo); status != OK) {
305 return status;
306 }
307
308 // Validate axis info for InputDevice.
309 if (axisInfo->valid && axisInfo->minValue == axisInfo->maxValue) {
310 // Historically, we deem axes with the same min and max values as invalid to avoid
311 // dividing by zero when scaling by max - min.
312 // TODO(b/291772515): Perform axis info validation on a per-axis basis when it is used.
313 axisInfo->valid = false;
314 }
315 return OK;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800316 }
317 inline bool hasRelativeAxis(int32_t code) const {
318 return mEventHub->hasRelativeAxis(mId, code);
319 }
Chris Yef59a2f42020-10-16 12:55:26 -0700320 inline bool hasInputProperty(int32_t property) const {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800321 return mEventHub->hasInputProperty(mId, property);
322 }
Chris Yef59a2f42020-10-16 12:55:26 -0700323
324 inline bool hasMscEvent(int mscEvent) const { return mEventHub->hasMscEvent(mId, mscEvent); }
325
Vaibhav Devmuraricbba14c2022-10-10 16:54:49 +0000326 inline void addKeyRemapping(int32_t fromKeyCode, int32_t toKeyCode) const {
327 mEventHub->addKeyRemapping(mId, fromKeyCode, toKeyCode);
328 }
329
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800330 inline status_t mapKey(int32_t scanCode, int32_t usageCode, int32_t metaState,
331 int32_t* outKeycode, int32_t* outMetaState, uint32_t* outFlags) const {
332 return mEventHub->mapKey(mId, scanCode, usageCode, metaState, outKeycode, outMetaState,
333 outFlags);
334 }
335 inline status_t mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const {
336 return mEventHub->mapAxis(mId, scanCode, outAxisInfo);
337 }
Chris Yef59a2f42020-10-16 12:55:26 -0700338 inline base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor(int32_t absCode) {
339 return mEventHub->mapSensor(mId, absCode);
340 }
341
Chris Ye3fdbfef2021-01-06 18:45:18 -0800342 inline const std::vector<int32_t> getRawLightIds() { return mEventHub->getRawLightIds(mId); }
343
344 inline std::optional<RawLightInfo> getRawLightInfo(int32_t lightId) {
345 return mEventHub->getRawLightInfo(mId, lightId);
346 }
347
348 inline std::optional<int32_t> getLightBrightness(int32_t lightId) {
349 return mEventHub->getLightBrightness(mId, lightId);
350 }
351
352 inline void setLightBrightness(int32_t lightId, int32_t brightness) {
353 return mEventHub->setLightBrightness(mId, lightId, brightness);
354 }
355
356 inline std::optional<std::unordered_map<LightColor, int32_t>> getLightIntensities(
357 int32_t lightId) {
358 return mEventHub->getLightIntensities(mId, lightId);
359 }
360
361 inline void setLightIntensities(int32_t lightId,
362 std::unordered_map<LightColor, int32_t> intensities) {
363 return mEventHub->setLightIntensities(mId, lightId, intensities);
364 }
365
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800366 inline std::vector<TouchVideoFrame> getVideoFrames() { return mEventHub->getVideoFrames(mId); }
367 inline int32_t getScanCodeState(int32_t scanCode) const {
368 return mEventHub->getScanCodeState(mId, scanCode);
369 }
370 inline int32_t getKeyCodeState(int32_t keyCode) const {
371 return mEventHub->getKeyCodeState(mId, keyCode);
372 }
Philip Junker4af3b3d2021-12-14 10:36:55 +0100373 inline int32_t getKeyCodeForKeyLocation(int32_t locationKeyCode) const {
374 return mEventHub->getKeyCodeForKeyLocation(mId, locationKeyCode);
375 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800376 inline int32_t getSwitchState(int32_t sw) const { return mEventHub->getSwitchState(mId, sw); }
377 inline status_t getAbsoluteAxisValue(int32_t code, int32_t* outValue) const {
378 return mEventHub->getAbsoluteAxisValue(mId, code, outValue);
379 }
Arpit Singh4b4a4572023-11-24 18:19:56 +0000380 inline base::Result<std::vector<int32_t>> getMtSlotValues(int32_t axis,
381 size_t slotCount) const {
382 return mEventHub->getMtSlotValues(mId, axis, slotCount);
383 }
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700384 inline bool markSupportedKeyCodes(const std::vector<int32_t>& keyCodes,
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800385 uint8_t* outFlags) const {
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700386 return mEventHub->markSupportedKeyCodes(mId, keyCodes, outFlags);
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800387 }
388 inline bool hasScanCode(int32_t scanCode) const {
389 return mEventHub->hasScanCode(mId, scanCode);
390 }
Arthur Hungcb40a002021-08-03 14:31:01 +0000391 inline bool hasKeyCode(int32_t keyCode) const { return mEventHub->hasKeyCode(mId, keyCode); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800392 inline bool hasLed(int32_t led) const { return mEventHub->hasLed(mId, led); }
393 inline void setLedState(int32_t led, bool on) { return mEventHub->setLedState(mId, led, on); }
394 inline void getVirtualKeyDefinitions(std::vector<VirtualKeyDefinition>& outVirtualKeys) const {
395 return mEventHub->getVirtualKeyDefinitions(mId, outVirtualKeys);
396 }
Chris Ye3a1e4462020-08-12 10:13:15 -0700397 inline const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap() const {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800398 return mEventHub->getKeyCharacterMap(mId);
399 }
Chris Ye3a1e4462020-08-12 10:13:15 -0700400 inline bool setKeyboardLayoutOverlay(std::shared_ptr<KeyCharacterMap> map) {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800401 return mEventHub->setKeyboardLayoutOverlay(mId, map);
402 }
Vaibhav Devmurari7fb41132023-01-02 13:30:26 +0000403 inline const std::optional<RawLayoutInfo> getRawLayoutInfo() {
404 return mEventHub->getRawLayoutInfo(mId);
405 }
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +0000406 inline void vibrate(const VibrationElement& element) {
407 return mEventHub->vibrate(mId, element);
408 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800409 inline void cancelVibrate() { return mEventHub->cancelVibrate(mId); }
410
Chris Ye87143712020-11-10 05:05:58 +0000411 inline std::vector<int32_t> getVibratorIds() { return mEventHub->getVibratorIds(mId); }
412
Chris Yee2b1e5c2021-03-10 22:45:12 -0800413 inline const std::vector<int32_t> getRawBatteryIds() {
414 return mEventHub->getRawBatteryIds(mId);
Kim Low03ea0352020-11-06 12:45:07 -0800415 }
416
Chris Yee2b1e5c2021-03-10 22:45:12 -0800417 inline std::optional<RawBatteryInfo> getRawBatteryInfo(int32_t batteryId) {
418 return mEventHub->getRawBatteryInfo(mId, batteryId);
419 }
420
421 inline std::optional<int32_t> getBatteryCapacity(int32_t batteryId) {
422 return mEventHub->getBatteryCapacity(mId, batteryId);
423 }
424
425 inline std::optional<int32_t> getBatteryStatus(int32_t batteryId) {
426 return mEventHub->getBatteryStatus(mId, batteryId);
427 }
Kim Low03ea0352020-11-06 12:45:07 -0800428
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800429 inline bool hasAbsoluteAxis(int32_t code) const {
430 RawAbsoluteAxisInfo info;
431 mEventHub->getAbsoluteAxisInfo(mId, code, &info);
432 return info.valid;
433 }
Prabir Pradhan4f05b5f2022-10-11 21:24:07 +0000434 inline bool isKeyPressed(int32_t scanCode) const {
435 return mEventHub->getScanCodeState(mId, scanCode) == AKEY_STATE_DOWN;
436 }
437 inline bool isKeyCodePressed(int32_t keyCode) const {
438 return mEventHub->getKeyCodeState(mId, keyCode) == AKEY_STATE_DOWN;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800439 }
440 inline int32_t getAbsoluteAxisValue(int32_t code) const {
441 int32_t value;
442 mEventHub->getAbsoluteAxisValue(mId, code, &value);
443 return value;
444 }
445 inline bool isDeviceEnabled() { return mEventHub->isDeviceEnabled(mId); }
446 inline status_t enableDevice() { return mEventHub->enableDevice(mId); }
447 inline status_t disableDevice() { return mEventHub->disableDevice(mId); }
448
Harry Cuttsba9364a2022-12-15 12:39:04 +0000449 inline const std::string getName() const { return mDevice.getName(); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800450 inline const std::string getDescriptor() { return mDevice.getDescriptor(); }
Zixuan Qufecb6062022-11-12 04:44:31 +0000451 inline const std::string getLocation() { return mDevice.getLocation(); }
Arpit Singh403e53c2023-04-18 11:46:56 +0000452 inline bool isExternal() const { return mDevice.isExternal(); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800453 inline std::optional<uint8_t> getAssociatedDisplayPort() const {
454 return mDevice.getAssociatedDisplayPort();
455 }
Antonio Kantek0ac5e092024-04-22 17:10:27 +0000456 inline std::optional<std::string> getAssociatedDisplayUniqueIdByPort() const {
457 return mDevice.getAssociatedDisplayUniqueIdByPort();
458 }
459 inline std::optional<std::string> getAssociatedDisplayUniqueIdByDescriptor() const {
460 return mDevice.getAssociatedDisplayUniqueIdByDescriptor();
Christine Franks2a2293c2022-01-18 11:51:16 -0800461 }
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +0000462 inline std::optional<std::string> getDeviceTypeAssociation() const {
463 return mDevice.getDeviceTypeAssociation();
464 }
Harry Cutts92559ef2024-01-05 12:45:36 +0000465 virtual std::optional<DisplayViewport> getAssociatedViewport() const {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800466 return mDevice.getAssociatedViewport();
467 }
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700468 [[nodiscard]] inline std::list<NotifyArgs> cancelTouch(nsecs_t when, nsecs_t readTime) {
469 return mDevice.cancelTouch(when, readTime);
470 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800471 inline void bumpGeneration() { mDevice.bumpGeneration(); }
Arpit Singh403e53c2023-04-18 11:46:56 +0000472 inline const PropertyMap& getConfiguration() const { return mDevice.getConfiguration(); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800473
474private:
475 InputDevice& mDevice;
476 InputReaderContext* mContext;
477 EventHubInterface* mEventHub;
478 int32_t mId;
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800479 int32_t mDeviceId;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800480};
481
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700482} // namespace android