blob: 439123bf1dd753ba8de69feb0049b7ace718e718 [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 }
Dominik Laskowski2f01d772022-03-23 16:01:29 -070057 inline ftl::Flags<InputDeviceClass> getClasses() const { return mClasses; }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070058 inline uint32_t getSources() const { return mSources; }
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080059 inline bool hasEventHubDevices() const { return !mDevices.empty(); }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070060
61 inline bool isExternal() { return mIsExternal; }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070062 inline std::optional<uint8_t> getAssociatedDisplayPort() const {
63 return mAssociatedDisplayPort;
64 }
Christine Franks2a2293c2022-01-18 11:51:16 -080065 inline std::optional<std::string> getAssociatedDisplayUniqueId() const {
66 return mAssociatedDisplayUniqueId;
67 }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070068 inline std::optional<DisplayViewport> getAssociatedViewport() const {
69 return mAssociatedViewport;
70 }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070071 inline bool hasMic() const { return mHasMic; }
72
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080073 inline bool isIgnored() { return !getMapperCount(); }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070074
75 bool isEnabled();
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070076 [[nodiscard]] std::list<NotifyArgs> setEnabled(bool enabled, nsecs_t when);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070077
Chris Yee7310032020-09-22 15:36:28 -070078 void dump(std::string& dump, const std::string& eventHubDevStr);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080079 void addEventHubDevice(int32_t eventHubId, bool populateMappers = true);
80 void removeEventHubDevice(int32_t eventHubId);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070081 [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when,
82 const InputReaderConfiguration* config,
83 uint32_t changes);
84 [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when);
85 [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvents, size_t count);
86 [[nodiscard]] std::list<NotifyArgs> timeoutExpired(nsecs_t when);
87 [[nodiscard]] std::list<NotifyArgs> updateExternalStylusState(const StylusState& state);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070088
Siarhei Vishniakou1983a712021-06-04 19:27:09 +000089 InputDeviceInfo getDeviceInfo();
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070090 int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
91 int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
92 int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
Philip Junker4af3b3d2021-12-14 10:36:55 +010093 int32_t getKeyCodeForKeyLocation(int32_t locationKeyCode) const;
Siarhei Vishniakou74007942022-06-13 13:57:47 -070094 bool markSupportedKeyCodes(uint32_t sourceMask, const std::vector<int32_t>& keyCodes,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070095 uint8_t* outFlags);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -070096 [[nodiscard]] std::list<NotifyArgs> vibrate(const VibrationSequence& sequence, ssize_t repeat,
97 int32_t token);
98 [[nodiscard]] std::list<NotifyArgs> cancelVibrate(int32_t token);
Chris Ye87143712020-11-10 05:05:58 +000099 bool isVibrating();
100 std::vector<int32_t> getVibratorIds();
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700101 [[nodiscard]] std::list<NotifyArgs> cancelTouch(nsecs_t when, nsecs_t readTime);
Chris Yef59a2f42020-10-16 12:55:26 -0700102 bool enableSensor(InputDeviceSensorType sensorType, std::chrono::microseconds samplingPeriod,
103 std::chrono::microseconds maxBatchReportLatency);
104 void disableSensor(InputDeviceSensorType sensorType);
105 void flushSensor(InputDeviceSensorType sensorType);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700106
Andy Chenf9f1a022022-08-29 20:07:10 -0400107 std::optional<int32_t> getBatteryEventHubId() const;
Kim Low03ea0352020-11-06 12:45:07 -0800108
Chris Ye3fdbfef2021-01-06 18:45:18 -0800109 bool setLightColor(int32_t lightId, int32_t color);
110 bool setLightPlayerId(int32_t lightId, int32_t playerId);
111 std::optional<int32_t> getLightColor(int32_t lightId);
112 std::optional<int32_t> getLightPlayerId(int32_t lightId);
113
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700114 int32_t getMetaState();
115 void updateMetaState(int32_t keyCode);
116
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700117 void bumpGeneration();
118
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700119 [[nodiscard]] NotifyDeviceResetArgs notifyReset(nsecs_t when);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700120
121 inline const PropertyMap& getConfiguration() { return mConfiguration; }
122 inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
123
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700124 std::optional<int32_t> getAssociatedDisplayId();
125
arthurhungc903df12020-08-11 15:08:42 +0800126 void updateLedState(bool reset);
127
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800128 size_t getMapperCount();
129
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800130 // construct and add a mapper to the input device
131 template <class T, typename... Args>
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800132 T& addMapper(int32_t eventHubId, Args... args) {
133 // ensure a device entry exists for this eventHubId
134 addEventHubDevice(eventHubId, false);
135
136 // create mapper
137 auto& devicePair = mDevices[eventHubId];
138 auto& deviceContext = devicePair.first;
139 auto& mappers = devicePair.second;
140 T* mapper = new T(*deviceContext, args...);
141 mappers.emplace_back(mapper);
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800142 return *mapper;
143 }
144
Chris Yee2b1e5c2021-03-10 22:45:12 -0800145 // construct and add a controller to the input device
146 template <class T>
147 T& addController(int32_t eventHubId) {
148 // ensure a device entry exists for this eventHubId
149 addEventHubDevice(eventHubId, false);
150
151 // create controller
152 auto& devicePair = mDevices[eventHubId];
153 auto& deviceContext = devicePair.first;
154
155 mController = std::make_unique<T>(*deviceContext);
156 return *(reinterpret_cast<T*>(mController.get()));
157 }
158
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700159private:
160 InputReaderContext* mContext;
161 int32_t mId;
162 int32_t mGeneration;
163 int32_t mControllerNumber;
Vaibhav Devmuraridd82b8e2022-08-16 15:34:01 +0000164 hardware::input::InputDeviceCountryCode mCountryCode;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700165 InputDeviceIdentifier mIdentifier;
166 std::string mAlias;
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700167 ftl::Flags<InputDeviceClass> mClasses;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700168
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800169 // map from eventHubId to device context and mappers
170 using MapperVector = std::vector<std::unique_ptr<InputMapper>>;
171 using DevicePair = std::pair<std::unique_ptr<InputDeviceContext>, MapperVector>;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800172 // Map from EventHub ID to pair of device context and vector of mapper.
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800173 std::unordered_map<int32_t, DevicePair> mDevices;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800174 // Misc devices controller for lights, battery, etc.
Chris Ye1dd2e5c2021-04-04 23:12:41 -0700175 std::unique_ptr<PeripheralControllerInterface> mController;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700176
177 uint32_t mSources;
178 bool mIsExternal;
179 std::optional<uint8_t> mAssociatedDisplayPort;
Christine Franks1ba71cc2021-04-07 14:37:42 -0700180 std::optional<std::string> mAssociatedDisplayUniqueId;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700181 std::optional<DisplayViewport> mAssociatedViewport;
182 bool mHasMic;
183 bool mDropUntilNextSync;
184
185 typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);
186 int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
187
188 PropertyMap mConfiguration;
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800189
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800190 // helpers to interate over the devices collection
191 // run a function against every mapper on every subdevice
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800192 inline void for_each_mapper(std::function<void(InputMapper&)> f) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800193 for (auto& deviceEntry : mDevices) {
194 auto& devicePair = deviceEntry.second;
195 auto& mappers = devicePair.second;
196 for (auto& mapperPtr : mappers) {
197 f(*mapperPtr);
198 }
199 }
200 }
201
202 // run a function against every mapper on a specific subdevice
203 inline void for_each_mapper_in_subdevice(int32_t eventHubDevice,
204 std::function<void(InputMapper&)> f) {
205 auto deviceIt = mDevices.find(eventHubDevice);
206 if (deviceIt != mDevices.end()) {
207 auto& devicePair = deviceIt->second;
208 auto& mappers = devicePair.second;
209 for (auto& mapperPtr : mappers) {
210 f(*mapperPtr);
211 }
212 }
213 }
214
215 // run a function against every subdevice
216 inline void for_each_subdevice(std::function<void(InputDeviceContext&)> f) {
217 for (auto& deviceEntry : mDevices) {
218 auto& devicePair = deviceEntry.second;
219 auto& contextPtr = devicePair.first;
220 f(*contextPtr);
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800221 }
222 }
223
224 // return the first value returned by a function over every mapper.
225 // if all mappers return nullopt, return nullopt.
226 template <typename T>
Philip Junker4af3b3d2021-12-14 10:36:55 +0100227 inline std::optional<T> first_in_mappers(
228 std::function<std::optional<T>(InputMapper&)> f) const {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800229 for (auto& deviceEntry : mDevices) {
230 auto& devicePair = deviceEntry.second;
231 auto& mappers = devicePair.second;
232 for (auto& mapperPtr : mappers) {
233 std::optional<T> ret = f(*mapperPtr);
234 if (ret) {
235 return ret;
236 }
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800237 }
238 }
239 return std::nullopt;
240 }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700241};
242
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800243/* Provides access to EventHub methods, but limits access to the current InputDevice.
244 * Essentially an implementation of EventHubInterface, but for a specific device id.
245 * Helps hide implementation details of InputDevice and EventHub. Used by mappers to
246 * check the status of the associated hardware device
247 */
248class InputDeviceContext {
249public:
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800250 InputDeviceContext(InputDevice& device, int32_t eventHubId);
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800251 ~InputDeviceContext();
252
253 inline InputReaderContext* getContext() { return mContext; }
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800254 inline int32_t getId() { return mDeviceId; }
255 inline int32_t getEventHubId() { return mId; }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800256
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700257 inline ftl::Flags<InputDeviceClass> getDeviceClasses() const {
Chris Ye1b0c7342020-07-28 21:57:03 -0700258 return mEventHub->getDeviceClasses(mId);
259 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800260 inline InputDeviceIdentifier getDeviceIdentifier() const {
261 return mEventHub->getDeviceIdentifier(mId);
262 }
263 inline int32_t getDeviceControllerNumber() const {
264 return mEventHub->getDeviceControllerNumber(mId);
265 }
266 inline void getConfiguration(PropertyMap* outConfiguration) const {
267 return mEventHub->getConfiguration(mId, outConfiguration);
268 }
269 inline status_t getAbsoluteAxisInfo(int32_t code, RawAbsoluteAxisInfo* axisInfo) const {
270 return mEventHub->getAbsoluteAxisInfo(mId, code, axisInfo);
271 }
272 inline bool hasRelativeAxis(int32_t code) const {
273 return mEventHub->hasRelativeAxis(mId, code);
274 }
Chris Yef59a2f42020-10-16 12:55:26 -0700275 inline bool hasInputProperty(int32_t property) const {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800276 return mEventHub->hasInputProperty(mId, property);
277 }
Chris Yef59a2f42020-10-16 12:55:26 -0700278
279 inline bool hasMscEvent(int mscEvent) const { return mEventHub->hasMscEvent(mId, mscEvent); }
280
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800281 inline status_t mapKey(int32_t scanCode, int32_t usageCode, int32_t metaState,
282 int32_t* outKeycode, int32_t* outMetaState, uint32_t* outFlags) const {
283 return mEventHub->mapKey(mId, scanCode, usageCode, metaState, outKeycode, outMetaState,
284 outFlags);
285 }
286 inline status_t mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const {
287 return mEventHub->mapAxis(mId, scanCode, outAxisInfo);
288 }
Chris Yef59a2f42020-10-16 12:55:26 -0700289 inline base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor(int32_t absCode) {
290 return mEventHub->mapSensor(mId, absCode);
291 }
292
Chris Ye3fdbfef2021-01-06 18:45:18 -0800293 inline const std::vector<int32_t> getRawLightIds() { return mEventHub->getRawLightIds(mId); }
294
295 inline std::optional<RawLightInfo> getRawLightInfo(int32_t lightId) {
296 return mEventHub->getRawLightInfo(mId, lightId);
297 }
298
299 inline std::optional<int32_t> getLightBrightness(int32_t lightId) {
300 return mEventHub->getLightBrightness(mId, lightId);
301 }
302
303 inline void setLightBrightness(int32_t lightId, int32_t brightness) {
304 return mEventHub->setLightBrightness(mId, lightId, brightness);
305 }
306
307 inline std::optional<std::unordered_map<LightColor, int32_t>> getLightIntensities(
308 int32_t lightId) {
309 return mEventHub->getLightIntensities(mId, lightId);
310 }
311
312 inline void setLightIntensities(int32_t lightId,
313 std::unordered_map<LightColor, int32_t> intensities) {
314 return mEventHub->setLightIntensities(mId, lightId, intensities);
315 }
316
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800317 inline std::vector<TouchVideoFrame> getVideoFrames() { return mEventHub->getVideoFrames(mId); }
Vaibhav Devmuraridd82b8e2022-08-16 15:34:01 +0000318 inline hardware::input::InputDeviceCountryCode getCountryCode() const {
319 return mEventHub->getCountryCode(mId);
320 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800321 inline int32_t getScanCodeState(int32_t scanCode) const {
322 return mEventHub->getScanCodeState(mId, scanCode);
323 }
324 inline int32_t getKeyCodeState(int32_t keyCode) const {
325 return mEventHub->getKeyCodeState(mId, keyCode);
326 }
Philip Junker4af3b3d2021-12-14 10:36:55 +0100327 inline int32_t getKeyCodeForKeyLocation(int32_t locationKeyCode) const {
328 return mEventHub->getKeyCodeForKeyLocation(mId, locationKeyCode);
329 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800330 inline int32_t getSwitchState(int32_t sw) const { return mEventHub->getSwitchState(mId, sw); }
331 inline status_t getAbsoluteAxisValue(int32_t code, int32_t* outValue) const {
332 return mEventHub->getAbsoluteAxisValue(mId, code, outValue);
333 }
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700334 inline bool markSupportedKeyCodes(const std::vector<int32_t>& keyCodes,
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800335 uint8_t* outFlags) const {
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700336 return mEventHub->markSupportedKeyCodes(mId, keyCodes, outFlags);
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800337 }
338 inline bool hasScanCode(int32_t scanCode) const {
339 return mEventHub->hasScanCode(mId, scanCode);
340 }
Arthur Hungcb40a002021-08-03 14:31:01 +0000341 inline bool hasKeyCode(int32_t keyCode) const { return mEventHub->hasKeyCode(mId, keyCode); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800342 inline bool hasLed(int32_t led) const { return mEventHub->hasLed(mId, led); }
343 inline void setLedState(int32_t led, bool on) { return mEventHub->setLedState(mId, led, on); }
344 inline void getVirtualKeyDefinitions(std::vector<VirtualKeyDefinition>& outVirtualKeys) const {
345 return mEventHub->getVirtualKeyDefinitions(mId, outVirtualKeys);
346 }
Chris Ye3a1e4462020-08-12 10:13:15 -0700347 inline const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap() const {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800348 return mEventHub->getKeyCharacterMap(mId);
349 }
Chris Ye3a1e4462020-08-12 10:13:15 -0700350 inline bool setKeyboardLayoutOverlay(std::shared_ptr<KeyCharacterMap> map) {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800351 return mEventHub->setKeyboardLayoutOverlay(mId, map);
352 }
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +0000353 inline void vibrate(const VibrationElement& element) {
354 return mEventHub->vibrate(mId, element);
355 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800356 inline void cancelVibrate() { return mEventHub->cancelVibrate(mId); }
357
Chris Ye87143712020-11-10 05:05:58 +0000358 inline std::vector<int32_t> getVibratorIds() { return mEventHub->getVibratorIds(mId); }
359
Chris Yee2b1e5c2021-03-10 22:45:12 -0800360 inline const std::vector<int32_t> getRawBatteryIds() {
361 return mEventHub->getRawBatteryIds(mId);
Kim Low03ea0352020-11-06 12:45:07 -0800362 }
363
Chris Yee2b1e5c2021-03-10 22:45:12 -0800364 inline std::optional<RawBatteryInfo> getRawBatteryInfo(int32_t batteryId) {
365 return mEventHub->getRawBatteryInfo(mId, batteryId);
366 }
367
368 inline std::optional<int32_t> getBatteryCapacity(int32_t batteryId) {
369 return mEventHub->getBatteryCapacity(mId, batteryId);
370 }
371
372 inline std::optional<int32_t> getBatteryStatus(int32_t batteryId) {
373 return mEventHub->getBatteryStatus(mId, batteryId);
374 }
Kim Low03ea0352020-11-06 12:45:07 -0800375
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800376 inline bool hasAbsoluteAxis(int32_t code) const {
377 RawAbsoluteAxisInfo info;
378 mEventHub->getAbsoluteAxisInfo(mId, code, &info);
379 return info.valid;
380 }
Prabir Pradhan4f05b5f2022-10-11 21:24:07 +0000381 inline bool isKeyPressed(int32_t scanCode) const {
382 return mEventHub->getScanCodeState(mId, scanCode) == AKEY_STATE_DOWN;
383 }
384 inline bool isKeyCodePressed(int32_t keyCode) const {
385 return mEventHub->getKeyCodeState(mId, keyCode) == AKEY_STATE_DOWN;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800386 }
387 inline int32_t getAbsoluteAxisValue(int32_t code) const {
388 int32_t value;
389 mEventHub->getAbsoluteAxisValue(mId, code, &value);
390 return value;
391 }
392 inline bool isDeviceEnabled() { return mEventHub->isDeviceEnabled(mId); }
393 inline status_t enableDevice() { return mEventHub->enableDevice(mId); }
394 inline status_t disableDevice() { return mEventHub->disableDevice(mId); }
395
396 inline const std::string getName() { return mDevice.getName(); }
397 inline const std::string getDescriptor() { return mDevice.getDescriptor(); }
398 inline bool isExternal() { return mDevice.isExternal(); }
399 inline std::optional<uint8_t> getAssociatedDisplayPort() const {
400 return mDevice.getAssociatedDisplayPort();
401 }
Christine Franks2a2293c2022-01-18 11:51:16 -0800402 inline std::optional<std::string> getAssociatedDisplayUniqueId() const {
403 return mDevice.getAssociatedDisplayUniqueId();
404 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800405 inline std::optional<DisplayViewport> getAssociatedViewport() const {
406 return mDevice.getAssociatedViewport();
407 }
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700408 [[nodiscard]] inline std::list<NotifyArgs> cancelTouch(nsecs_t when, nsecs_t readTime) {
409 return mDevice.cancelTouch(when, readTime);
410 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800411 inline void bumpGeneration() { mDevice.bumpGeneration(); }
412 inline const PropertyMap& getConfiguration() { return mDevice.getConfiguration(); }
413
414private:
415 InputDevice& mDevice;
416 InputReaderContext* mContext;
417 EventHubInterface* mEventHub;
418 int32_t mId;
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800419 int32_t mDeviceId;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800420};
421
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700422} // namespace android