blob: 837c3c4902c94212a35db86b42b955c4a22af490 [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);
83 void addEventHubDevice(int32_t eventHubId, const InputReaderConfiguration& readerConfig);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080084 void removeEventHubDevice(int32_t eventHubId);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070085 [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when,
Arpit Singhed6c3de2023-04-05 19:24:37 +000086 const InputReaderConfiguration& readerConfig,
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000087 ConfigurationChanges changes);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070088 [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when);
89 [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvents, size_t count);
90 [[nodiscard]] std::list<NotifyArgs> timeoutExpired(nsecs_t when);
91 [[nodiscard]] std::list<NotifyArgs> updateExternalStylusState(const StylusState& state);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070092
Siarhei Vishniakou1983a712021-06-04 19:27:09 +000093 InputDeviceInfo getDeviceInfo();
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070094 int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
95 int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
96 int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
Philip Junker4af3b3d2021-12-14 10:36:55 +010097 int32_t getKeyCodeForKeyLocation(int32_t locationKeyCode) const;
Siarhei Vishniakou74007942022-06-13 13:57:47 -070098 bool markSupportedKeyCodes(uint32_t sourceMask, const std::vector<int32_t>& keyCodes,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070099 uint8_t* outFlags);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700100 [[nodiscard]] std::list<NotifyArgs> vibrate(const VibrationSequence& sequence, ssize_t repeat,
101 int32_t token);
102 [[nodiscard]] std::list<NotifyArgs> cancelVibrate(int32_t token);
Chris Ye87143712020-11-10 05:05:58 +0000103 bool isVibrating();
104 std::vector<int32_t> getVibratorIds();
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700105 [[nodiscard]] std::list<NotifyArgs> cancelTouch(nsecs_t when, nsecs_t readTime);
Chris Yef59a2f42020-10-16 12:55:26 -0700106 bool enableSensor(InputDeviceSensorType sensorType, std::chrono::microseconds samplingPeriod,
107 std::chrono::microseconds maxBatchReportLatency);
108 void disableSensor(InputDeviceSensorType sensorType);
109 void flushSensor(InputDeviceSensorType sensorType);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700110
Andy Chenf9f1a022022-08-29 20:07:10 -0400111 std::optional<int32_t> getBatteryEventHubId() const;
Kim Low03ea0352020-11-06 12:45:07 -0800112
Chris Ye3fdbfef2021-01-06 18:45:18 -0800113 bool setLightColor(int32_t lightId, int32_t color);
114 bool setLightPlayerId(int32_t lightId, int32_t playerId);
115 std::optional<int32_t> getLightColor(int32_t lightId);
116 std::optional<int32_t> getLightPlayerId(int32_t lightId);
117
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700118 int32_t getMetaState();
119 void updateMetaState(int32_t keyCode);
120
Vaibhav Devmuraricbba14c2022-10-10 16:54:49 +0000121 void addKeyRemapping(int32_t fromKeyCode, int32_t toKeyCode);
122
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700123 void bumpGeneration();
124
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700125 [[nodiscard]] NotifyDeviceResetArgs notifyReset(nsecs_t when);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700126
127 inline const PropertyMap& getConfiguration() { return mConfiguration; }
128 inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
129
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700130 std::optional<int32_t> getAssociatedDisplayId();
131
arthurhungc903df12020-08-11 15:08:42 +0800132 void updateLedState(bool reset);
133
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800134 size_t getMapperCount();
135
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800136 // construct and add a mapper to the input device
137 template <class T, typename... Args>
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800138 T& addMapper(int32_t eventHubId, Args... args) {
139 // ensure a device entry exists for this eventHubId
Arpit Singh8e6fb252023-04-06 11:49:17 +0000140 addEmptyEventHubDevice(eventHubId);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800141
142 // create mapper
143 auto& devicePair = mDevices[eventHubId];
144 auto& deviceContext = devicePair.first;
145 auto& mappers = devicePair.second;
146 T* mapper = new T(*deviceContext, args...);
147 mappers.emplace_back(mapper);
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800148 return *mapper;
149 }
150
Arpit Singh56adebc2023-04-25 13:56:05 +0000151 template <class T, typename... Args>
152 T& constructAndAddMapper(int32_t eventHubId, Args... args) {
153 // create mapper
154 auto& devicePair = mDevices[eventHubId];
155 auto& deviceContext = devicePair.first;
156 auto& mappers = devicePair.second;
157 mappers.push_back(createInputMapper<T>(*deviceContext, args...));
158 return static_cast<T&>(*mappers.back());
159 }
160
Chris Yee2b1e5c2021-03-10 22:45:12 -0800161 // construct and add a controller to the input device
162 template <class T>
163 T& addController(int32_t eventHubId) {
164 // ensure a device entry exists for this eventHubId
Arpit Singh8e6fb252023-04-06 11:49:17 +0000165 addEmptyEventHubDevice(eventHubId);
Chris Yee2b1e5c2021-03-10 22:45:12 -0800166
167 // create controller
168 auto& devicePair = mDevices[eventHubId];
169 auto& deviceContext = devicePair.first;
170
171 mController = std::make_unique<T>(*deviceContext);
172 return *(reinterpret_cast<T*>(mController.get()));
173 }
174
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700175private:
176 InputReaderContext* mContext;
177 int32_t mId;
178 int32_t mGeneration;
179 int32_t mControllerNumber;
180 InputDeviceIdentifier mIdentifier;
181 std::string mAlias;
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700182 ftl::Flags<InputDeviceClass> mClasses;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700183
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800184 // map from eventHubId to device context and mappers
185 using MapperVector = std::vector<std::unique_ptr<InputMapper>>;
186 using DevicePair = std::pair<std::unique_ptr<InputDeviceContext>, MapperVector>;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800187 // Map from EventHub ID to pair of device context and vector of mapper.
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800188 std::unordered_map<int32_t, DevicePair> mDevices;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800189 // Misc devices controller for lights, battery, etc.
Chris Ye1dd2e5c2021-04-04 23:12:41 -0700190 std::unique_ptr<PeripheralControllerInterface> mController;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700191
192 uint32_t mSources;
193 bool mIsExternal;
194 std::optional<uint8_t> mAssociatedDisplayPort;
Christine Franks1ba71cc2021-04-07 14:37:42 -0700195 std::optional<std::string> mAssociatedDisplayUniqueId;
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +0000196 std::optional<std::string> mAssociatedDeviceType;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700197 std::optional<DisplayViewport> mAssociatedViewport;
198 bool mHasMic;
199 bool mDropUntilNextSync;
200
201 typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);
202 int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
203
Arpit Singh8e6fb252023-04-06 11:49:17 +0000204 std::vector<std::unique_ptr<InputMapper>> createMappers(
205 InputDeviceContext& contextPtr, const InputReaderConfiguration& readerConfig);
206
Arpit Singhf4cdbef2023-05-30 14:12:49 +0000207 [[nodiscard]] std::list<NotifyArgs> updateEnableState(
208 nsecs_t when, const InputReaderConfiguration& readerConfig, bool forceEnable = false);
209
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700210 PropertyMap mConfiguration;
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800211
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800212 // helpers to interate over the devices collection
213 // run a function against every mapper on every subdevice
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800214 inline void for_each_mapper(std::function<void(InputMapper&)> f) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800215 for (auto& deviceEntry : mDevices) {
216 auto& devicePair = deviceEntry.second;
217 auto& mappers = devicePair.second;
218 for (auto& mapperPtr : mappers) {
219 f(*mapperPtr);
220 }
221 }
222 }
223
224 // run a function against every mapper on a specific subdevice
225 inline void for_each_mapper_in_subdevice(int32_t eventHubDevice,
226 std::function<void(InputMapper&)> f) {
227 auto deviceIt = mDevices.find(eventHubDevice);
228 if (deviceIt != mDevices.end()) {
229 auto& devicePair = deviceIt->second;
230 auto& mappers = devicePair.second;
231 for (auto& mapperPtr : mappers) {
232 f(*mapperPtr);
233 }
234 }
235 }
236
237 // run a function against every subdevice
238 inline void for_each_subdevice(std::function<void(InputDeviceContext&)> f) {
239 for (auto& deviceEntry : mDevices) {
240 auto& devicePair = deviceEntry.second;
241 auto& contextPtr = devicePair.first;
242 f(*contextPtr);
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800243 }
244 }
245
246 // return the first value returned by a function over every mapper.
247 // if all mappers return nullopt, return nullopt.
248 template <typename T>
Philip Junker4af3b3d2021-12-14 10:36:55 +0100249 inline std::optional<T> first_in_mappers(
250 std::function<std::optional<T>(InputMapper&)> f) const {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800251 for (auto& deviceEntry : mDevices) {
252 auto& devicePair = deviceEntry.second;
253 auto& mappers = devicePair.second;
254 for (auto& mapperPtr : mappers) {
255 std::optional<T> ret = f(*mapperPtr);
256 if (ret) {
257 return ret;
258 }
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800259 }
260 }
261 return std::nullopt;
262 }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700263};
264
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800265/* Provides access to EventHub methods, but limits access to the current InputDevice.
266 * Essentially an implementation of EventHubInterface, but for a specific device id.
267 * Helps hide implementation details of InputDevice and EventHub. Used by mappers to
268 * check the status of the associated hardware device
269 */
270class InputDeviceContext {
271public:
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800272 InputDeviceContext(InputDevice& device, int32_t eventHubId);
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800273 ~InputDeviceContext();
274
275 inline InputReaderContext* getContext() { return mContext; }
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800276 inline int32_t getId() { return mDeviceId; }
277 inline int32_t getEventHubId() { return mId; }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800278
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700279 inline ftl::Flags<InputDeviceClass> getDeviceClasses() const {
Chris Ye1b0c7342020-07-28 21:57:03 -0700280 return mEventHub->getDeviceClasses(mId);
281 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800282 inline InputDeviceIdentifier getDeviceIdentifier() const {
283 return mEventHub->getDeviceIdentifier(mId);
284 }
285 inline int32_t getDeviceControllerNumber() const {
286 return mEventHub->getDeviceControllerNumber(mId);
287 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800288 inline status_t getAbsoluteAxisInfo(int32_t code, RawAbsoluteAxisInfo* axisInfo) const {
289 return mEventHub->getAbsoluteAxisInfo(mId, code, axisInfo);
290 }
291 inline bool hasRelativeAxis(int32_t code) const {
292 return mEventHub->hasRelativeAxis(mId, code);
293 }
Chris Yef59a2f42020-10-16 12:55:26 -0700294 inline bool hasInputProperty(int32_t property) const {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800295 return mEventHub->hasInputProperty(mId, property);
296 }
Chris Yef59a2f42020-10-16 12:55:26 -0700297
298 inline bool hasMscEvent(int mscEvent) const { return mEventHub->hasMscEvent(mId, mscEvent); }
299
Vaibhav Devmuraricbba14c2022-10-10 16:54:49 +0000300 inline void addKeyRemapping(int32_t fromKeyCode, int32_t toKeyCode) const {
301 mEventHub->addKeyRemapping(mId, fromKeyCode, toKeyCode);
302 }
303
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800304 inline status_t mapKey(int32_t scanCode, int32_t usageCode, int32_t metaState,
305 int32_t* outKeycode, int32_t* outMetaState, uint32_t* outFlags) const {
306 return mEventHub->mapKey(mId, scanCode, usageCode, metaState, outKeycode, outMetaState,
307 outFlags);
308 }
309 inline status_t mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const {
310 return mEventHub->mapAxis(mId, scanCode, outAxisInfo);
311 }
Chris Yef59a2f42020-10-16 12:55:26 -0700312 inline base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor(int32_t absCode) {
313 return mEventHub->mapSensor(mId, absCode);
314 }
315
Chris Ye3fdbfef2021-01-06 18:45:18 -0800316 inline const std::vector<int32_t> getRawLightIds() { return mEventHub->getRawLightIds(mId); }
317
318 inline std::optional<RawLightInfo> getRawLightInfo(int32_t lightId) {
319 return mEventHub->getRawLightInfo(mId, lightId);
320 }
321
322 inline std::optional<int32_t> getLightBrightness(int32_t lightId) {
323 return mEventHub->getLightBrightness(mId, lightId);
324 }
325
326 inline void setLightBrightness(int32_t lightId, int32_t brightness) {
327 return mEventHub->setLightBrightness(mId, lightId, brightness);
328 }
329
330 inline std::optional<std::unordered_map<LightColor, int32_t>> getLightIntensities(
331 int32_t lightId) {
332 return mEventHub->getLightIntensities(mId, lightId);
333 }
334
335 inline void setLightIntensities(int32_t lightId,
336 std::unordered_map<LightColor, int32_t> intensities) {
337 return mEventHub->setLightIntensities(mId, lightId, intensities);
338 }
339
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800340 inline std::vector<TouchVideoFrame> getVideoFrames() { return mEventHub->getVideoFrames(mId); }
341 inline int32_t getScanCodeState(int32_t scanCode) const {
342 return mEventHub->getScanCodeState(mId, scanCode);
343 }
344 inline int32_t getKeyCodeState(int32_t keyCode) const {
345 return mEventHub->getKeyCodeState(mId, keyCode);
346 }
Philip Junker4af3b3d2021-12-14 10:36:55 +0100347 inline int32_t getKeyCodeForKeyLocation(int32_t locationKeyCode) const {
348 return mEventHub->getKeyCodeForKeyLocation(mId, locationKeyCode);
349 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800350 inline int32_t getSwitchState(int32_t sw) const { return mEventHub->getSwitchState(mId, sw); }
351 inline status_t getAbsoluteAxisValue(int32_t code, int32_t* outValue) const {
352 return mEventHub->getAbsoluteAxisValue(mId, code, outValue);
353 }
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700354 inline bool markSupportedKeyCodes(const std::vector<int32_t>& keyCodes,
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800355 uint8_t* outFlags) const {
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700356 return mEventHub->markSupportedKeyCodes(mId, keyCodes, outFlags);
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800357 }
358 inline bool hasScanCode(int32_t scanCode) const {
359 return mEventHub->hasScanCode(mId, scanCode);
360 }
Arthur Hungcb40a002021-08-03 14:31:01 +0000361 inline bool hasKeyCode(int32_t keyCode) const { return mEventHub->hasKeyCode(mId, keyCode); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800362 inline bool hasLed(int32_t led) const { return mEventHub->hasLed(mId, led); }
363 inline void setLedState(int32_t led, bool on) { return mEventHub->setLedState(mId, led, on); }
364 inline void getVirtualKeyDefinitions(std::vector<VirtualKeyDefinition>& outVirtualKeys) const {
365 return mEventHub->getVirtualKeyDefinitions(mId, outVirtualKeys);
366 }
Chris Ye3a1e4462020-08-12 10:13:15 -0700367 inline const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap() const {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800368 return mEventHub->getKeyCharacterMap(mId);
369 }
Chris Ye3a1e4462020-08-12 10:13:15 -0700370 inline bool setKeyboardLayoutOverlay(std::shared_ptr<KeyCharacterMap> map) {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800371 return mEventHub->setKeyboardLayoutOverlay(mId, map);
372 }
Vaibhav Devmurari7fb41132023-01-02 13:30:26 +0000373 inline const std::optional<RawLayoutInfo> getRawLayoutInfo() {
374 return mEventHub->getRawLayoutInfo(mId);
375 }
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +0000376 inline void vibrate(const VibrationElement& element) {
377 return mEventHub->vibrate(mId, element);
378 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800379 inline void cancelVibrate() { return mEventHub->cancelVibrate(mId); }
380
Chris Ye87143712020-11-10 05:05:58 +0000381 inline std::vector<int32_t> getVibratorIds() { return mEventHub->getVibratorIds(mId); }
382
Chris Yee2b1e5c2021-03-10 22:45:12 -0800383 inline const std::vector<int32_t> getRawBatteryIds() {
384 return mEventHub->getRawBatteryIds(mId);
Kim Low03ea0352020-11-06 12:45:07 -0800385 }
386
Chris Yee2b1e5c2021-03-10 22:45:12 -0800387 inline std::optional<RawBatteryInfo> getRawBatteryInfo(int32_t batteryId) {
388 return mEventHub->getRawBatteryInfo(mId, batteryId);
389 }
390
391 inline std::optional<int32_t> getBatteryCapacity(int32_t batteryId) {
392 return mEventHub->getBatteryCapacity(mId, batteryId);
393 }
394
395 inline std::optional<int32_t> getBatteryStatus(int32_t batteryId) {
396 return mEventHub->getBatteryStatus(mId, batteryId);
397 }
Kim Low03ea0352020-11-06 12:45:07 -0800398
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800399 inline bool hasAbsoluteAxis(int32_t code) const {
400 RawAbsoluteAxisInfo info;
401 mEventHub->getAbsoluteAxisInfo(mId, code, &info);
402 return info.valid;
403 }
Prabir Pradhan4f05b5f2022-10-11 21:24:07 +0000404 inline bool isKeyPressed(int32_t scanCode) const {
405 return mEventHub->getScanCodeState(mId, scanCode) == AKEY_STATE_DOWN;
406 }
407 inline bool isKeyCodePressed(int32_t keyCode) const {
408 return mEventHub->getKeyCodeState(mId, keyCode) == AKEY_STATE_DOWN;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800409 }
410 inline int32_t getAbsoluteAxisValue(int32_t code) const {
411 int32_t value;
412 mEventHub->getAbsoluteAxisValue(mId, code, &value);
413 return value;
414 }
415 inline bool isDeviceEnabled() { return mEventHub->isDeviceEnabled(mId); }
416 inline status_t enableDevice() { return mEventHub->enableDevice(mId); }
417 inline status_t disableDevice() { return mEventHub->disableDevice(mId); }
418
Harry Cuttsba9364a2022-12-15 12:39:04 +0000419 inline const std::string getName() const { return mDevice.getName(); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800420 inline const std::string getDescriptor() { return mDevice.getDescriptor(); }
Zixuan Qufecb6062022-11-12 04:44:31 +0000421 inline const std::string getLocation() { return mDevice.getLocation(); }
Arpit Singh403e53c2023-04-18 11:46:56 +0000422 inline bool isExternal() const { return mDevice.isExternal(); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800423 inline std::optional<uint8_t> getAssociatedDisplayPort() const {
424 return mDevice.getAssociatedDisplayPort();
425 }
Christine Franks2a2293c2022-01-18 11:51:16 -0800426 inline std::optional<std::string> getAssociatedDisplayUniqueId() const {
427 return mDevice.getAssociatedDisplayUniqueId();
428 }
Ambrus Weisz7bc23bf2022-10-04 13:13:07 +0000429 inline std::optional<std::string> getDeviceTypeAssociation() const {
430 return mDevice.getDeviceTypeAssociation();
431 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800432 inline std::optional<DisplayViewport> getAssociatedViewport() const {
433 return mDevice.getAssociatedViewport();
434 }
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700435 [[nodiscard]] inline std::list<NotifyArgs> cancelTouch(nsecs_t when, nsecs_t readTime) {
436 return mDevice.cancelTouch(when, readTime);
437 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800438 inline void bumpGeneration() { mDevice.bumpGeneration(); }
Arpit Singh403e53c2023-04-18 11:46:56 +0000439 inline const PropertyMap& getConfiguration() const { return mDevice.getConfiguration(); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800440
441private:
442 InputDevice& mDevice;
443 InputReaderContext* mContext;
444 EventHubInterface* mEventHub;
445 int32_t mId;
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800446 int32_t mDeviceId;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800447};
448
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700449} // namespace android