blob: 141464f6e4b091d7855dcf7407a4a90ec9451824 [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
17#ifndef _UI_INPUTREADER_INPUT_DEVICE_H
18#define _UI_INPUTREADER_INPUT_DEVICE_H
19
Dominik Laskowski2f01d772022-03-23 16:01:29 -070020#include <ftl/flags.h>
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080021#include <input/DisplayViewport.h>
22#include <input/InputDevice.h>
Siarhei Vishniakou32f36ae2020-09-02 20:17:10 -070023#include <input/PropertyMap.h>
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080024
Dominik Laskowski2f01d772022-03-23 16:01:29 -070025#include <cstdint>
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080026#include <optional>
27#include <unordered_map>
28#include <vector>
29
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070030#include "EventHub.h"
31#include "InputReaderBase.h"
32#include "InputReaderContext.h"
33
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070034namespace android {
Chris Ye1dd2e5c2021-04-04 23:12:41 -070035// TODO b/180733860 support multiple battery in API and remove this.
36constexpr int32_t DEFAULT_BATTERY_ID = 1;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070037
Chris Ye1dd2e5c2021-04-04 23:12:41 -070038class PeripheralController;
39class PeripheralControllerInterface;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -080040class InputDeviceContext;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070041class InputMapper;
42
43/* Represents the state of a single input device. */
44class InputDevice {
45public:
46 InputDevice(InputReaderContext* context, int32_t id, int32_t generation,
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080047 const InputDeviceIdentifier& identifier);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070048 ~InputDevice();
49
50 inline InputReaderContext* getContext() { return mContext; }
51 inline int32_t getId() const { return mId; }
52 inline int32_t getControllerNumber() const { return mControllerNumber; }
53 inline int32_t getGeneration() const { return mGeneration; }
54 inline const std::string getName() const { return mIdentifier.name; }
55 inline const std::string getDescriptor() { return mIdentifier.descriptor; }
Dominik Laskowski2f01d772022-03-23 16:01:29 -070056 inline ftl::Flags<InputDeviceClass> getClasses() const { return mClasses; }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070057 inline uint32_t getSources() const { return mSources; }
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080058 inline bool hasEventHubDevices() const { return !mDevices.empty(); }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070059
60 inline bool isExternal() { return mIsExternal; }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070061 inline std::optional<uint8_t> getAssociatedDisplayPort() const {
62 return mAssociatedDisplayPort;
63 }
Christine Franks2a2293c2022-01-18 11:51:16 -080064 inline std::optional<std::string> getAssociatedDisplayUniqueId() const {
65 return mAssociatedDisplayUniqueId;
66 }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070067 inline std::optional<DisplayViewport> getAssociatedViewport() const {
68 return mAssociatedViewport;
69 }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070070 inline bool hasMic() const { return mHasMic; }
71
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080072 inline bool isIgnored() { return !getMapperCount(); }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070073
74 bool isEnabled();
75 void setEnabled(bool enabled, nsecs_t when);
76
Chris Yee7310032020-09-22 15:36:28 -070077 void dump(std::string& dump, const std::string& eventHubDevStr);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080078 void addEventHubDevice(int32_t eventHubId, bool populateMappers = true);
79 void removeEventHubDevice(int32_t eventHubId);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070080 void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
81 void reset(nsecs_t when);
82 void process(const RawEvent* rawEvents, size_t count);
83 void timeoutExpired(nsecs_t when);
84 void updateExternalStylusState(const StylusState& state);
85
Siarhei Vishniakou1983a712021-06-04 19:27:09 +000086 InputDeviceInfo getDeviceInfo();
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070087 int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
88 int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
89 int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
Philip Junker4af3b3d2021-12-14 10:36:55 +010090 int32_t getKeyCodeForKeyLocation(int32_t locationKeyCode) const;
Siarhei Vishniakou74007942022-06-13 13:57:47 -070091 bool markSupportedKeyCodes(uint32_t sourceMask, const std::vector<int32_t>& keyCodes,
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070092 uint8_t* outFlags);
Chris Ye87143712020-11-10 05:05:58 +000093 void vibrate(const VibrationSequence& sequence, ssize_t repeat, int32_t token);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070094 void cancelVibrate(int32_t token);
Chris Ye87143712020-11-10 05:05:58 +000095 bool isVibrating();
96 std::vector<int32_t> getVibratorIds();
Siarhei Vishniakou58ba3d12021-02-11 01:31:07 +000097 void cancelTouch(nsecs_t when, nsecs_t readTime);
Chris Yef59a2f42020-10-16 12:55:26 -070098 bool enableSensor(InputDeviceSensorType sensorType, std::chrono::microseconds samplingPeriod,
99 std::chrono::microseconds maxBatchReportLatency);
100 void disableSensor(InputDeviceSensorType sensorType);
101 void flushSensor(InputDeviceSensorType sensorType);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700102
Kim Low03ea0352020-11-06 12:45:07 -0800103 std::optional<int32_t> getBatteryCapacity();
104 std::optional<int32_t> getBatteryStatus();
105
Chris Ye3fdbfef2021-01-06 18:45:18 -0800106 bool setLightColor(int32_t lightId, int32_t color);
107 bool setLightPlayerId(int32_t lightId, int32_t playerId);
108 std::optional<int32_t> getLightColor(int32_t lightId);
109 std::optional<int32_t> getLightPlayerId(int32_t lightId);
110
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700111 int32_t getMetaState();
112 void updateMetaState(int32_t keyCode);
113
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700114 void bumpGeneration();
115
116 void notifyReset(nsecs_t when);
117
118 inline const PropertyMap& getConfiguration() { return mConfiguration; }
119 inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
120
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700121 std::optional<int32_t> getAssociatedDisplayId();
122
arthurhungc903df12020-08-11 15:08:42 +0800123 void updateLedState(bool reset);
124
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800125 size_t getMapperCount();
126
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800127 // construct and add a mapper to the input device
128 template <class T, typename... Args>
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800129 T& addMapper(int32_t eventHubId, Args... args) {
130 // ensure a device entry exists for this eventHubId
131 addEventHubDevice(eventHubId, false);
132
133 // create mapper
134 auto& devicePair = mDevices[eventHubId];
135 auto& deviceContext = devicePair.first;
136 auto& mappers = devicePair.second;
137 T* mapper = new T(*deviceContext, args...);
138 mappers.emplace_back(mapper);
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800139 return *mapper;
140 }
141
Chris Yee2b1e5c2021-03-10 22:45:12 -0800142 // construct and add a controller to the input device
143 template <class T>
144 T& addController(int32_t eventHubId) {
145 // ensure a device entry exists for this eventHubId
146 addEventHubDevice(eventHubId, false);
147
148 // create controller
149 auto& devicePair = mDevices[eventHubId];
150 auto& deviceContext = devicePair.first;
151
152 mController = std::make_unique<T>(*deviceContext);
153 return *(reinterpret_cast<T*>(mController.get()));
154 }
155
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700156private:
157 InputReaderContext* mContext;
158 int32_t mId;
159 int32_t mGeneration;
160 int32_t mControllerNumber;
Vaibhav Devmuraridd82b8e2022-08-16 15:34:01 +0000161 hardware::input::InputDeviceCountryCode mCountryCode;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700162 InputDeviceIdentifier mIdentifier;
163 std::string mAlias;
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700164 ftl::Flags<InputDeviceClass> mClasses;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700165
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800166 // map from eventHubId to device context and mappers
167 using MapperVector = std::vector<std::unique_ptr<InputMapper>>;
168 using DevicePair = std::pair<std::unique_ptr<InputDeviceContext>, MapperVector>;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800169 // Map from EventHub ID to pair of device context and vector of mapper.
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800170 std::unordered_map<int32_t, DevicePair> mDevices;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800171 // Misc devices controller for lights, battery, etc.
Chris Ye1dd2e5c2021-04-04 23:12:41 -0700172 std::unique_ptr<PeripheralControllerInterface> mController;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700173
174 uint32_t mSources;
175 bool mIsExternal;
176 std::optional<uint8_t> mAssociatedDisplayPort;
Christine Franks1ba71cc2021-04-07 14:37:42 -0700177 std::optional<std::string> mAssociatedDisplayUniqueId;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700178 std::optional<DisplayViewport> mAssociatedViewport;
179 bool mHasMic;
180 bool mDropUntilNextSync;
181
182 typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);
183 int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
184
185 PropertyMap mConfiguration;
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800186
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800187 // helpers to interate over the devices collection
188 // run a function against every mapper on every subdevice
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800189 inline void for_each_mapper(std::function<void(InputMapper&)> f) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800190 for (auto& deviceEntry : mDevices) {
191 auto& devicePair = deviceEntry.second;
192 auto& mappers = devicePair.second;
193 for (auto& mapperPtr : mappers) {
194 f(*mapperPtr);
195 }
196 }
197 }
198
199 // run a function against every mapper on a specific subdevice
200 inline void for_each_mapper_in_subdevice(int32_t eventHubDevice,
201 std::function<void(InputMapper&)> f) {
202 auto deviceIt = mDevices.find(eventHubDevice);
203 if (deviceIt != mDevices.end()) {
204 auto& devicePair = deviceIt->second;
205 auto& mappers = devicePair.second;
206 for (auto& mapperPtr : mappers) {
207 f(*mapperPtr);
208 }
209 }
210 }
211
212 // run a function against every subdevice
213 inline void for_each_subdevice(std::function<void(InputDeviceContext&)> f) {
214 for (auto& deviceEntry : mDevices) {
215 auto& devicePair = deviceEntry.second;
216 auto& contextPtr = devicePair.first;
217 f(*contextPtr);
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800218 }
219 }
220
221 // return the first value returned by a function over every mapper.
222 // if all mappers return nullopt, return nullopt.
223 template <typename T>
Philip Junker4af3b3d2021-12-14 10:36:55 +0100224 inline std::optional<T> first_in_mappers(
225 std::function<std::optional<T>(InputMapper&)> f) const {
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 std::optional<T> ret = f(*mapperPtr);
231 if (ret) {
232 return ret;
233 }
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -0800234 }
235 }
236 return std::nullopt;
237 }
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700238};
239
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800240/* Provides access to EventHub methods, but limits access to the current InputDevice.
241 * Essentially an implementation of EventHubInterface, but for a specific device id.
242 * Helps hide implementation details of InputDevice and EventHub. Used by mappers to
243 * check the status of the associated hardware device
244 */
245class InputDeviceContext {
246public:
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800247 InputDeviceContext(InputDevice& device, int32_t eventHubId);
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800248 ~InputDeviceContext();
249
250 inline InputReaderContext* getContext() { return mContext; }
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800251 inline int32_t getId() { return mDeviceId; }
252 inline int32_t getEventHubId() { return mId; }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800253
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700254 inline ftl::Flags<InputDeviceClass> getDeviceClasses() const {
Chris Ye1b0c7342020-07-28 21:57:03 -0700255 return mEventHub->getDeviceClasses(mId);
256 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800257 inline InputDeviceIdentifier getDeviceIdentifier() const {
258 return mEventHub->getDeviceIdentifier(mId);
259 }
260 inline int32_t getDeviceControllerNumber() const {
261 return mEventHub->getDeviceControllerNumber(mId);
262 }
263 inline void getConfiguration(PropertyMap* outConfiguration) const {
264 return mEventHub->getConfiguration(mId, outConfiguration);
265 }
266 inline status_t getAbsoluteAxisInfo(int32_t code, RawAbsoluteAxisInfo* axisInfo) const {
267 return mEventHub->getAbsoluteAxisInfo(mId, code, axisInfo);
268 }
269 inline bool hasRelativeAxis(int32_t code) const {
270 return mEventHub->hasRelativeAxis(mId, code);
271 }
Chris Yef59a2f42020-10-16 12:55:26 -0700272 inline bool hasInputProperty(int32_t property) const {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800273 return mEventHub->hasInputProperty(mId, property);
274 }
Chris Yef59a2f42020-10-16 12:55:26 -0700275
276 inline bool hasMscEvent(int mscEvent) const { return mEventHub->hasMscEvent(mId, mscEvent); }
277
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800278 inline status_t mapKey(int32_t scanCode, int32_t usageCode, int32_t metaState,
279 int32_t* outKeycode, int32_t* outMetaState, uint32_t* outFlags) const {
280 return mEventHub->mapKey(mId, scanCode, usageCode, metaState, outKeycode, outMetaState,
281 outFlags);
282 }
283 inline status_t mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const {
284 return mEventHub->mapAxis(mId, scanCode, outAxisInfo);
285 }
Chris Yef59a2f42020-10-16 12:55:26 -0700286 inline base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor(int32_t absCode) {
287 return mEventHub->mapSensor(mId, absCode);
288 }
289
Chris Ye3fdbfef2021-01-06 18:45:18 -0800290 inline const std::vector<int32_t> getRawLightIds() { return mEventHub->getRawLightIds(mId); }
291
292 inline std::optional<RawLightInfo> getRawLightInfo(int32_t lightId) {
293 return mEventHub->getRawLightInfo(mId, lightId);
294 }
295
296 inline std::optional<int32_t> getLightBrightness(int32_t lightId) {
297 return mEventHub->getLightBrightness(mId, lightId);
298 }
299
300 inline void setLightBrightness(int32_t lightId, int32_t brightness) {
301 return mEventHub->setLightBrightness(mId, lightId, brightness);
302 }
303
304 inline std::optional<std::unordered_map<LightColor, int32_t>> getLightIntensities(
305 int32_t lightId) {
306 return mEventHub->getLightIntensities(mId, lightId);
307 }
308
309 inline void setLightIntensities(int32_t lightId,
310 std::unordered_map<LightColor, int32_t> intensities) {
311 return mEventHub->setLightIntensities(mId, lightId, intensities);
312 }
313
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800314 inline std::vector<TouchVideoFrame> getVideoFrames() { return mEventHub->getVideoFrames(mId); }
Vaibhav Devmuraridd82b8e2022-08-16 15:34:01 +0000315 inline hardware::input::InputDeviceCountryCode getCountryCode() const {
316 return mEventHub->getCountryCode(mId);
317 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800318 inline int32_t getScanCodeState(int32_t scanCode) const {
319 return mEventHub->getScanCodeState(mId, scanCode);
320 }
321 inline int32_t getKeyCodeState(int32_t keyCode) const {
322 return mEventHub->getKeyCodeState(mId, keyCode);
323 }
Philip Junker4af3b3d2021-12-14 10:36:55 +0100324 inline int32_t getKeyCodeForKeyLocation(int32_t locationKeyCode) const {
325 return mEventHub->getKeyCodeForKeyLocation(mId, locationKeyCode);
326 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800327 inline int32_t getSwitchState(int32_t sw) const { return mEventHub->getSwitchState(mId, sw); }
328 inline status_t getAbsoluteAxisValue(int32_t code, int32_t* outValue) const {
329 return mEventHub->getAbsoluteAxisValue(mId, code, outValue);
330 }
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700331 inline bool markSupportedKeyCodes(const std::vector<int32_t>& keyCodes,
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800332 uint8_t* outFlags) const {
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700333 return mEventHub->markSupportedKeyCodes(mId, keyCodes, outFlags);
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800334 }
335 inline bool hasScanCode(int32_t scanCode) const {
336 return mEventHub->hasScanCode(mId, scanCode);
337 }
Arthur Hungcb40a002021-08-03 14:31:01 +0000338 inline bool hasKeyCode(int32_t keyCode) const { return mEventHub->hasKeyCode(mId, keyCode); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800339 inline bool hasLed(int32_t led) const { return mEventHub->hasLed(mId, led); }
340 inline void setLedState(int32_t led, bool on) { return mEventHub->setLedState(mId, led, on); }
341 inline void getVirtualKeyDefinitions(std::vector<VirtualKeyDefinition>& outVirtualKeys) const {
342 return mEventHub->getVirtualKeyDefinitions(mId, outVirtualKeys);
343 }
Chris Ye3a1e4462020-08-12 10:13:15 -0700344 inline const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap() const {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800345 return mEventHub->getKeyCharacterMap(mId);
346 }
Chris Ye3a1e4462020-08-12 10:13:15 -0700347 inline bool setKeyboardLayoutOverlay(std::shared_ptr<KeyCharacterMap> map) {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800348 return mEventHub->setKeyboardLayoutOverlay(mId, map);
349 }
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +0000350 inline void vibrate(const VibrationElement& element) {
351 return mEventHub->vibrate(mId, element);
352 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800353 inline void cancelVibrate() { return mEventHub->cancelVibrate(mId); }
354
Chris Ye87143712020-11-10 05:05:58 +0000355 inline std::vector<int32_t> getVibratorIds() { return mEventHub->getVibratorIds(mId); }
356
Chris Yee2b1e5c2021-03-10 22:45:12 -0800357 inline const std::vector<int32_t> getRawBatteryIds() {
358 return mEventHub->getRawBatteryIds(mId);
Kim Low03ea0352020-11-06 12:45:07 -0800359 }
360
Chris Yee2b1e5c2021-03-10 22:45:12 -0800361 inline std::optional<RawBatteryInfo> getRawBatteryInfo(int32_t batteryId) {
362 return mEventHub->getRawBatteryInfo(mId, batteryId);
363 }
364
365 inline std::optional<int32_t> getBatteryCapacity(int32_t batteryId) {
366 return mEventHub->getBatteryCapacity(mId, batteryId);
367 }
368
369 inline std::optional<int32_t> getBatteryStatus(int32_t batteryId) {
370 return mEventHub->getBatteryStatus(mId, batteryId);
371 }
Kim Low03ea0352020-11-06 12:45:07 -0800372
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800373 inline bool hasAbsoluteAxis(int32_t code) const {
374 RawAbsoluteAxisInfo info;
375 mEventHub->getAbsoluteAxisInfo(mId, code, &info);
376 return info.valid;
377 }
378 inline bool isKeyPressed(int32_t code) const {
379 return mEventHub->getScanCodeState(mId, code) == AKEY_STATE_DOWN;
380 }
381 inline int32_t getAbsoluteAxisValue(int32_t code) const {
382 int32_t value;
383 mEventHub->getAbsoluteAxisValue(mId, code, &value);
384 return value;
385 }
386 inline bool isDeviceEnabled() { return mEventHub->isDeviceEnabled(mId); }
387 inline status_t enableDevice() { return mEventHub->enableDevice(mId); }
388 inline status_t disableDevice() { return mEventHub->disableDevice(mId); }
389
390 inline const std::string getName() { return mDevice.getName(); }
391 inline const std::string getDescriptor() { return mDevice.getDescriptor(); }
392 inline bool isExternal() { return mDevice.isExternal(); }
393 inline std::optional<uint8_t> getAssociatedDisplayPort() const {
394 return mDevice.getAssociatedDisplayPort();
395 }
Christine Franks2a2293c2022-01-18 11:51:16 -0800396 inline std::optional<std::string> getAssociatedDisplayUniqueId() const {
397 return mDevice.getAssociatedDisplayUniqueId();
398 }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800399 inline std::optional<DisplayViewport> getAssociatedViewport() const {
400 return mDevice.getAssociatedViewport();
401 }
Siarhei Vishniakou58ba3d12021-02-11 01:31:07 +0000402 inline void cancelTouch(nsecs_t when, nsecs_t readTime) { mDevice.cancelTouch(when, readTime); }
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800403 inline void bumpGeneration() { mDevice.bumpGeneration(); }
404 inline const PropertyMap& getConfiguration() { return mDevice.getConfiguration(); }
405
406private:
407 InputDevice& mDevice;
408 InputReaderContext* mContext;
409 EventHubInterface* mEventHub;
410 int32_t mId;
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800411 int32_t mDeviceId;
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800412};
413
Prabir Pradhanbaa5c822019-08-30 15:27:05 -0700414} // namespace android
415
416#endif //_UI_INPUTREADER_INPUT_DEVICE_H