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