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