Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 20 | #include <input/DisplayViewport.h> |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 21 | #include <input/Flags.h> |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 22 | #include <input/InputDevice.h> |
Siarhei Vishniakou | 32f36ae | 2020-09-02 20:17:10 -0700 | [diff] [blame] | 23 | #include <input/PropertyMap.h> |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 24 | #include <stdint.h> |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 25 | |
| 26 | #include <optional> |
| 27 | #include <unordered_map> |
| 28 | #include <vector> |
| 29 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 30 | #include "EventHub.h" |
| 31 | #include "InputReaderBase.h" |
| 32 | #include "InputReaderContext.h" |
| 33 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 34 | namespace android { |
| 35 | |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 36 | class InputController; |
| 37 | class InputControllerInterface; |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 38 | class InputDeviceContext; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 39 | class InputMapper; |
| 40 | |
| 41 | /* Represents the state of a single input device. */ |
| 42 | class InputDevice { |
| 43 | public: |
| 44 | InputDevice(InputReaderContext* context, int32_t id, int32_t generation, |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 45 | const InputDeviceIdentifier& identifier); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 46 | ~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; } |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 54 | inline Flags<InputDeviceClass> getClasses() const { return mClasses; } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 55 | inline uint32_t getSources() const { return mSources; } |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 56 | inline bool hasEventHubDevices() const { return !mDevices.empty(); } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 57 | |
| 58 | inline bool isExternal() { return mIsExternal; } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 59 | inline std::optional<uint8_t> getAssociatedDisplayPort() const { |
| 60 | return mAssociatedDisplayPort; |
| 61 | } |
| 62 | inline std::optional<DisplayViewport> getAssociatedViewport() const { |
| 63 | return mAssociatedViewport; |
| 64 | } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 65 | inline bool hasMic() const { return mHasMic; } |
| 66 | |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 67 | inline bool isIgnored() { return !getMapperCount(); } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 68 | |
| 69 | bool isEnabled(); |
| 70 | void setEnabled(bool enabled, nsecs_t when); |
| 71 | |
Chris Ye | e731003 | 2020-09-22 15:36:28 -0700 | [diff] [blame] | 72 | void dump(std::string& dump, const std::string& eventHubDevStr); |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 73 | void addEventHubDevice(int32_t eventHubId, bool populateMappers = true); |
| 74 | void removeEventHubDevice(int32_t eventHubId); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 75 | void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 76 | void reset(nsecs_t when); |
| 77 | void process(const RawEvent* rawEvents, size_t count); |
| 78 | void timeoutExpired(nsecs_t when); |
| 79 | void updateExternalStylusState(const StylusState& state); |
| 80 | |
| 81 | void getDeviceInfo(InputDeviceInfo* outDeviceInfo); |
| 82 | int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 83 | int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 84 | int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode); |
| 85 | bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, const int32_t* keyCodes, |
| 86 | uint8_t* outFlags); |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 87 | void vibrate(const VibrationSequence& sequence, ssize_t repeat, int32_t token); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 88 | void cancelVibrate(int32_t token); |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 89 | bool isVibrating(); |
| 90 | std::vector<int32_t> getVibratorIds(); |
Siarhei Vishniakou | 58ba3d1 | 2021-02-11 01:31:07 +0000 | [diff] [blame] | 91 | void cancelTouch(nsecs_t when, nsecs_t readTime); |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 92 | bool enableSensor(InputDeviceSensorType sensorType, std::chrono::microseconds samplingPeriod, |
| 93 | std::chrono::microseconds maxBatchReportLatency); |
| 94 | void disableSensor(InputDeviceSensorType sensorType); |
| 95 | void flushSensor(InputDeviceSensorType sensorType); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 96 | |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 97 | std::optional<int32_t> getBatteryCapacity(); |
| 98 | std::optional<int32_t> getBatteryStatus(); |
| 99 | |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 100 | bool setLightColor(int32_t lightId, int32_t color); |
| 101 | bool setLightPlayerId(int32_t lightId, int32_t playerId); |
| 102 | std::optional<int32_t> getLightColor(int32_t lightId); |
| 103 | std::optional<int32_t> getLightPlayerId(int32_t lightId); |
| 104 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 105 | int32_t getMetaState(); |
| 106 | void updateMetaState(int32_t keyCode); |
| 107 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 108 | void bumpGeneration(); |
| 109 | |
| 110 | void notifyReset(nsecs_t when); |
| 111 | |
| 112 | inline const PropertyMap& getConfiguration() { return mConfiguration; } |
| 113 | inline EventHubInterface* getEventHub() { return mContext->getEventHub(); } |
| 114 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 115 | std::optional<int32_t> getAssociatedDisplayId(); |
| 116 | |
arthurhung | c903df1 | 2020-08-11 15:08:42 +0800 | [diff] [blame] | 117 | void updateLedState(bool reset); |
| 118 | |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 119 | size_t getMapperCount(); |
| 120 | |
Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 121 | // construct and add a mapper to the input device |
| 122 | template <class T, typename... Args> |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 123 | T& addMapper(int32_t eventHubId, Args... args) { |
| 124 | // ensure a device entry exists for this eventHubId |
| 125 | addEventHubDevice(eventHubId, false); |
| 126 | |
| 127 | // create mapper |
| 128 | auto& devicePair = mDevices[eventHubId]; |
| 129 | auto& deviceContext = devicePair.first; |
| 130 | auto& mappers = devicePair.second; |
| 131 | T* mapper = new T(*deviceContext, args...); |
| 132 | mappers.emplace_back(mapper); |
Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 133 | return *mapper; |
| 134 | } |
| 135 | |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 136 | // construct and add a controller to the input device |
| 137 | template <class T> |
| 138 | T& addController(int32_t eventHubId) { |
| 139 | // ensure a device entry exists for this eventHubId |
| 140 | addEventHubDevice(eventHubId, false); |
| 141 | |
| 142 | // create controller |
| 143 | auto& devicePair = mDevices[eventHubId]; |
| 144 | auto& deviceContext = devicePair.first; |
| 145 | |
| 146 | mController = std::make_unique<T>(*deviceContext); |
| 147 | return *(reinterpret_cast<T*>(mController.get())); |
| 148 | } |
| 149 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 150 | private: |
| 151 | InputReaderContext* mContext; |
| 152 | int32_t mId; |
| 153 | int32_t mGeneration; |
| 154 | int32_t mControllerNumber; |
| 155 | InputDeviceIdentifier mIdentifier; |
| 156 | std::string mAlias; |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 157 | Flags<InputDeviceClass> mClasses; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 158 | |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 159 | // map from eventHubId to device context and mappers |
| 160 | using MapperVector = std::vector<std::unique_ptr<InputMapper>>; |
| 161 | using DevicePair = std::pair<std::unique_ptr<InputDeviceContext>, MapperVector>; |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 162 | // Map from EventHub ID to pair of device context and vector of mapper. |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 163 | std::unordered_map<int32_t, DevicePair> mDevices; |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 164 | // Misc devices controller for lights, battery, etc. |
| 165 | std::unique_ptr<InputControllerInterface> mController; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 166 | |
| 167 | uint32_t mSources; |
| 168 | bool mIsExternal; |
| 169 | std::optional<uint8_t> mAssociatedDisplayPort; |
| 170 | std::optional<DisplayViewport> mAssociatedViewport; |
| 171 | bool mHasMic; |
| 172 | bool mDropUntilNextSync; |
| 173 | |
| 174 | typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code); |
| 175 | int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc); |
| 176 | |
| 177 | PropertyMap mConfiguration; |
Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 178 | |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 179 | // helpers to interate over the devices collection |
| 180 | // run a function against every mapper on every subdevice |
Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 181 | inline void for_each_mapper(std::function<void(InputMapper&)> f) { |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 182 | for (auto& deviceEntry : mDevices) { |
| 183 | auto& devicePair = deviceEntry.second; |
| 184 | auto& mappers = devicePair.second; |
| 185 | for (auto& mapperPtr : mappers) { |
| 186 | f(*mapperPtr); |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | // run a function against every mapper on a specific subdevice |
| 192 | inline void for_each_mapper_in_subdevice(int32_t eventHubDevice, |
| 193 | std::function<void(InputMapper&)> f) { |
| 194 | auto deviceIt = mDevices.find(eventHubDevice); |
| 195 | if (deviceIt != mDevices.end()) { |
| 196 | auto& devicePair = deviceIt->second; |
| 197 | auto& mappers = devicePair.second; |
| 198 | for (auto& mapperPtr : mappers) { |
| 199 | f(*mapperPtr); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | // run a function against every subdevice |
| 205 | inline void for_each_subdevice(std::function<void(InputDeviceContext&)> f) { |
| 206 | for (auto& deviceEntry : mDevices) { |
| 207 | auto& devicePair = deviceEntry.second; |
| 208 | auto& contextPtr = devicePair.first; |
| 209 | f(*contextPtr); |
Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | |
| 213 | // return the first value returned by a function over every mapper. |
| 214 | // if all mappers return nullopt, return nullopt. |
| 215 | template <typename T> |
| 216 | inline std::optional<T> first_in_mappers(std::function<std::optional<T>(InputMapper&)> f) { |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 217 | for (auto& deviceEntry : mDevices) { |
| 218 | auto& devicePair = deviceEntry.second; |
| 219 | auto& mappers = devicePair.second; |
| 220 | for (auto& mapperPtr : mappers) { |
| 221 | std::optional<T> ret = f(*mapperPtr); |
| 222 | if (ret) { |
| 223 | return ret; |
| 224 | } |
Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | return std::nullopt; |
| 228 | } |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 229 | }; |
| 230 | |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 231 | /* Provides access to EventHub methods, but limits access to the current InputDevice. |
| 232 | * Essentially an implementation of EventHubInterface, but for a specific device id. |
| 233 | * Helps hide implementation details of InputDevice and EventHub. Used by mappers to |
| 234 | * check the status of the associated hardware device |
| 235 | */ |
| 236 | class InputDeviceContext { |
| 237 | public: |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 238 | InputDeviceContext(InputDevice& device, int32_t eventHubId); |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 239 | ~InputDeviceContext(); |
| 240 | |
| 241 | inline InputReaderContext* getContext() { return mContext; } |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 242 | inline int32_t getId() { return mDeviceId; } |
| 243 | inline int32_t getEventHubId() { return mId; } |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 244 | |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 245 | inline Flags<InputDeviceClass> getDeviceClasses() const { |
| 246 | return mEventHub->getDeviceClasses(mId); |
| 247 | } |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 248 | inline InputDeviceIdentifier getDeviceIdentifier() const { |
| 249 | return mEventHub->getDeviceIdentifier(mId); |
| 250 | } |
| 251 | inline int32_t getDeviceControllerNumber() const { |
| 252 | return mEventHub->getDeviceControllerNumber(mId); |
| 253 | } |
| 254 | inline void getConfiguration(PropertyMap* outConfiguration) const { |
| 255 | return mEventHub->getConfiguration(mId, outConfiguration); |
| 256 | } |
| 257 | inline status_t getAbsoluteAxisInfo(int32_t code, RawAbsoluteAxisInfo* axisInfo) const { |
| 258 | return mEventHub->getAbsoluteAxisInfo(mId, code, axisInfo); |
| 259 | } |
| 260 | inline bool hasRelativeAxis(int32_t code) const { |
| 261 | return mEventHub->hasRelativeAxis(mId, code); |
| 262 | } |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 263 | inline bool hasInputProperty(int32_t property) const { |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 264 | return mEventHub->hasInputProperty(mId, property); |
| 265 | } |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 266 | |
| 267 | inline bool hasMscEvent(int mscEvent) const { return mEventHub->hasMscEvent(mId, mscEvent); } |
| 268 | |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 269 | inline status_t mapKey(int32_t scanCode, int32_t usageCode, int32_t metaState, |
| 270 | int32_t* outKeycode, int32_t* outMetaState, uint32_t* outFlags) const { |
| 271 | return mEventHub->mapKey(mId, scanCode, usageCode, metaState, outKeycode, outMetaState, |
| 272 | outFlags); |
| 273 | } |
| 274 | inline status_t mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const { |
| 275 | return mEventHub->mapAxis(mId, scanCode, outAxisInfo); |
| 276 | } |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 277 | inline base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor(int32_t absCode) { |
| 278 | return mEventHub->mapSensor(mId, absCode); |
| 279 | } |
| 280 | |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 281 | inline const std::vector<int32_t> getRawLightIds() { return mEventHub->getRawLightIds(mId); } |
| 282 | |
| 283 | inline std::optional<RawLightInfo> getRawLightInfo(int32_t lightId) { |
| 284 | return mEventHub->getRawLightInfo(mId, lightId); |
| 285 | } |
| 286 | |
| 287 | inline std::optional<int32_t> getLightBrightness(int32_t lightId) { |
| 288 | return mEventHub->getLightBrightness(mId, lightId); |
| 289 | } |
| 290 | |
| 291 | inline void setLightBrightness(int32_t lightId, int32_t brightness) { |
| 292 | return mEventHub->setLightBrightness(mId, lightId, brightness); |
| 293 | } |
| 294 | |
| 295 | inline std::optional<std::unordered_map<LightColor, int32_t>> getLightIntensities( |
| 296 | int32_t lightId) { |
| 297 | return mEventHub->getLightIntensities(mId, lightId); |
| 298 | } |
| 299 | |
| 300 | inline void setLightIntensities(int32_t lightId, |
| 301 | std::unordered_map<LightColor, int32_t> intensities) { |
| 302 | return mEventHub->setLightIntensities(mId, lightId, intensities); |
| 303 | } |
| 304 | |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 305 | inline std::vector<TouchVideoFrame> getVideoFrames() { return mEventHub->getVideoFrames(mId); } |
| 306 | inline int32_t getScanCodeState(int32_t scanCode) const { |
| 307 | return mEventHub->getScanCodeState(mId, scanCode); |
| 308 | } |
| 309 | inline int32_t getKeyCodeState(int32_t keyCode) const { |
| 310 | return mEventHub->getKeyCodeState(mId, keyCode); |
| 311 | } |
| 312 | inline int32_t getSwitchState(int32_t sw) const { return mEventHub->getSwitchState(mId, sw); } |
| 313 | inline status_t getAbsoluteAxisValue(int32_t code, int32_t* outValue) const { |
| 314 | return mEventHub->getAbsoluteAxisValue(mId, code, outValue); |
| 315 | } |
| 316 | inline bool markSupportedKeyCodes(size_t numCodes, const int32_t* keyCodes, |
| 317 | uint8_t* outFlags) const { |
| 318 | return mEventHub->markSupportedKeyCodes(mId, numCodes, keyCodes, outFlags); |
| 319 | } |
| 320 | inline bool hasScanCode(int32_t scanCode) const { |
| 321 | return mEventHub->hasScanCode(mId, scanCode); |
| 322 | } |
| 323 | inline bool hasLed(int32_t led) const { return mEventHub->hasLed(mId, led); } |
| 324 | inline void setLedState(int32_t led, bool on) { return mEventHub->setLedState(mId, led, on); } |
| 325 | inline void getVirtualKeyDefinitions(std::vector<VirtualKeyDefinition>& outVirtualKeys) const { |
| 326 | return mEventHub->getVirtualKeyDefinitions(mId, outVirtualKeys); |
| 327 | } |
Chris Ye | 3a1e446 | 2020-08-12 10:13:15 -0700 | [diff] [blame] | 328 | inline const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap() const { |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 329 | return mEventHub->getKeyCharacterMap(mId); |
| 330 | } |
Chris Ye | 3a1e446 | 2020-08-12 10:13:15 -0700 | [diff] [blame] | 331 | inline bool setKeyboardLayoutOverlay(std::shared_ptr<KeyCharacterMap> map) { |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 332 | return mEventHub->setKeyboardLayoutOverlay(mId, map); |
| 333 | } |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 334 | inline void vibrate(const VibrationElement& element) { |
| 335 | return mEventHub->vibrate(mId, element); |
| 336 | } |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 337 | inline void cancelVibrate() { return mEventHub->cancelVibrate(mId); } |
| 338 | |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 339 | inline std::vector<int32_t> getVibratorIds() { return mEventHub->getVibratorIds(mId); } |
| 340 | |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 341 | inline const std::vector<int32_t> getRawBatteryIds() { |
| 342 | return mEventHub->getRawBatteryIds(mId); |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 343 | } |
| 344 | |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 345 | inline std::optional<RawBatteryInfo> getRawBatteryInfo(int32_t batteryId) { |
| 346 | return mEventHub->getRawBatteryInfo(mId, batteryId); |
| 347 | } |
| 348 | |
| 349 | inline std::optional<int32_t> getBatteryCapacity(int32_t batteryId) { |
| 350 | return mEventHub->getBatteryCapacity(mId, batteryId); |
| 351 | } |
| 352 | |
| 353 | inline std::optional<int32_t> getBatteryStatus(int32_t batteryId) { |
| 354 | return mEventHub->getBatteryStatus(mId, batteryId); |
| 355 | } |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 356 | |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 357 | inline bool hasAbsoluteAxis(int32_t code) const { |
| 358 | RawAbsoluteAxisInfo info; |
| 359 | mEventHub->getAbsoluteAxisInfo(mId, code, &info); |
| 360 | return info.valid; |
| 361 | } |
| 362 | inline bool isKeyPressed(int32_t code) const { |
| 363 | return mEventHub->getScanCodeState(mId, code) == AKEY_STATE_DOWN; |
| 364 | } |
| 365 | inline int32_t getAbsoluteAxisValue(int32_t code) const { |
| 366 | int32_t value; |
| 367 | mEventHub->getAbsoluteAxisValue(mId, code, &value); |
| 368 | return value; |
| 369 | } |
| 370 | inline bool isDeviceEnabled() { return mEventHub->isDeviceEnabled(mId); } |
| 371 | inline status_t enableDevice() { return mEventHub->enableDevice(mId); } |
| 372 | inline status_t disableDevice() { return mEventHub->disableDevice(mId); } |
| 373 | |
| 374 | inline const std::string getName() { return mDevice.getName(); } |
| 375 | inline const std::string getDescriptor() { return mDevice.getDescriptor(); } |
| 376 | inline bool isExternal() { return mDevice.isExternal(); } |
| 377 | inline std::optional<uint8_t> getAssociatedDisplayPort() const { |
| 378 | return mDevice.getAssociatedDisplayPort(); |
| 379 | } |
| 380 | inline std::optional<DisplayViewport> getAssociatedViewport() const { |
| 381 | return mDevice.getAssociatedViewport(); |
| 382 | } |
Siarhei Vishniakou | 58ba3d1 | 2021-02-11 01:31:07 +0000 | [diff] [blame] | 383 | inline void cancelTouch(nsecs_t when, nsecs_t readTime) { mDevice.cancelTouch(when, readTime); } |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 384 | inline void bumpGeneration() { mDevice.bumpGeneration(); } |
| 385 | inline const PropertyMap& getConfiguration() { return mDevice.getConfiguration(); } |
| 386 | |
| 387 | private: |
| 388 | InputDevice& mDevice; |
| 389 | InputReaderContext* mContext; |
| 390 | EventHubInterface* mEventHub; |
| 391 | int32_t mId; |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 392 | int32_t mDeviceId; |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 393 | }; |
| 394 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 395 | } // namespace android |
| 396 | |
| 397 | #endif //_UI_INPUTREADER_INPUT_DEVICE_H |