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