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