Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 17 | #include "Macros.h" |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 18 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 19 | #include "InputReader.h" |
| 20 | |
Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 21 | #include <android-base/stringprintf.h> |
Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 22 | #include <errno.h> |
Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 23 | #include <input/Keyboard.h> |
| 24 | #include <input/VirtualKeyMap.h> |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 25 | #include <inttypes.h> |
Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 26 | #include <limits.h> |
Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 27 | #include <log/log.h> |
Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 28 | #include <math.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 29 | #include <stddef.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <unistd.h> |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 32 | #include <utils/Errors.h> |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 33 | #include <utils/Thread.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 34 | |
Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 35 | #include "InputDevice.h" |
Omar Abdelmonem | 5e70e96 | 2024-08-06 09:38:42 +0000 | [diff] [blame] | 36 | #include "include/gestures.h" |
Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 37 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 38 | using android::base::StringPrintf; |
| 39 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 40 | namespace android { |
| 41 | |
Prabir Pradhan | 018faea | 2024-05-08 21:52:54 +0000 | [diff] [blame] | 42 | namespace { |
| 43 | |
Josh Bartel | 938632f | 2022-07-19 15:34:22 -0500 | [diff] [blame] | 44 | /** |
| 45 | * Determines if the identifiers passed are a sub-devices. Sub-devices are physical devices |
| 46 | * that expose multiple input device paths such a keyboard that also has a touchpad input. |
| 47 | * These are separate devices with unique descriptors in EventHub, but InputReader should |
| 48 | * create a single InputDevice for them. |
| 49 | * Sub-devices are detected by the following criteria: |
| 50 | * 1. The vendor, product, bus, version, and unique id match |
| 51 | * 2. The location matches. The location is used to distinguish a single device with multiple |
| 52 | * inputs versus the same device plugged into multiple ports. |
| 53 | */ |
| 54 | |
Prabir Pradhan | 018faea | 2024-05-08 21:52:54 +0000 | [diff] [blame] | 55 | bool isSubDevice(const InputDeviceIdentifier& identifier1, |
| 56 | const InputDeviceIdentifier& identifier2) { |
Josh Bartel | 938632f | 2022-07-19 15:34:22 -0500 | [diff] [blame] | 57 | return (identifier1.vendor == identifier2.vendor && |
| 58 | identifier1.product == identifier2.product && identifier1.bus == identifier2.bus && |
| 59 | identifier1.version == identifier2.version && |
| 60 | identifier1.uniqueId == identifier2.uniqueId && |
| 61 | identifier1.location == identifier2.location); |
| 62 | } |
| 63 | |
Prabir Pradhan | 018faea | 2024-05-08 21:52:54 +0000 | [diff] [blame] | 64 | bool isStylusPointerGestureStart(const NotifyMotionArgs& motionArgs) { |
Prabir Pradhan | da20b17 | 2022-09-26 17:01:18 +0000 | [diff] [blame] | 65 | const auto actionMasked = MotionEvent::getActionMasked(motionArgs.action); |
| 66 | if (actionMasked != AMOTION_EVENT_ACTION_HOVER_ENTER && |
| 67 | actionMasked != AMOTION_EVENT_ACTION_DOWN && |
| 68 | actionMasked != AMOTION_EVENT_ACTION_POINTER_DOWN) { |
| 69 | return false; |
| 70 | } |
| 71 | const auto actionIndex = MotionEvent::getActionIndex(motionArgs.action); |
Prabir Pradhan | e562696 | 2022-10-27 20:30:53 +0000 | [diff] [blame] | 72 | return isStylusToolType(motionArgs.pointerProperties[actionIndex].toolType); |
Prabir Pradhan | da20b17 | 2022-09-26 17:01:18 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Prabir Pradhan | 018faea | 2024-05-08 21:52:54 +0000 | [diff] [blame] | 75 | bool isNewGestureStart(const NotifyMotionArgs& motion) { |
| 76 | return motion.action == AMOTION_EVENT_ACTION_DOWN || |
| 77 | motion.action == AMOTION_EVENT_ACTION_HOVER_ENTER; |
| 78 | } |
| 79 | |
| 80 | bool isNewGestureStart(const NotifyKeyArgs& key) { |
| 81 | return key.action == AKEY_EVENT_ACTION_DOWN; |
| 82 | } |
| 83 | |
| 84 | // Return the event's device ID if it marks the start of a new gesture. |
| 85 | std::optional<DeviceId> getDeviceIdOfNewGesture(const NotifyArgs& args) { |
| 86 | if (const auto* motion = std::get_if<NotifyMotionArgs>(&args); motion != nullptr) { |
| 87 | return isNewGestureStart(*motion) ? std::make_optional(motion->deviceId) : std::nullopt; |
| 88 | } |
| 89 | if (const auto* key = std::get_if<NotifyKeyArgs>(&args); key != nullptr) { |
| 90 | return isNewGestureStart(*key) ? std::make_optional(key->deviceId) : std::nullopt; |
| 91 | } |
| 92 | return std::nullopt; |
| 93 | } |
| 94 | |
| 95 | } // namespace |
| 96 | |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 97 | // --- InputReader --- |
| 98 | |
Siarhei Vishniakou | 3bc7e09 | 2019-07-24 17:43:30 -0700 | [diff] [blame] | 99 | InputReader::InputReader(std::shared_ptr<EventHubInterface> eventHub, |
| 100 | const sp<InputReaderPolicyInterface>& policy, |
Siarhei Vishniakou | 1805009 | 2021-09-01 13:32:49 -0700 | [diff] [blame] | 101 | InputListenerInterface& listener) |
Siarhei Vishniakou | 3bc7e09 | 2019-07-24 17:43:30 -0700 | [diff] [blame] | 102 | : mContext(this), |
| 103 | mEventHub(eventHub), |
| 104 | mPolicy(policy), |
Siarhei Vishniakou | 23a98bf | 2023-08-15 17:28:49 -0700 | [diff] [blame] | 105 | mNextListener(listener), |
Vaibhav Devmurari | e58ffb9 | 2024-05-22 17:38:25 +0000 | [diff] [blame] | 106 | mKeyboardClassifier(std::make_unique<KeyboardClassifier>()), |
Arthur Hung | 95f6861 | 2022-04-07 14:08:22 +0800 | [diff] [blame] | 107 | mGlobalMetaState(AMETA_NONE), |
| 108 | mLedMetaState(AMETA_NONE), |
Siarhei Vishniakou | 3bc7e09 | 2019-07-24 17:43:30 -0700 | [diff] [blame] | 109 | mGeneration(1), |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 110 | mNextInputDeviceId(END_RESERVED_ID), |
Siarhei Vishniakou | 3bc7e09 | 2019-07-24 17:43:30 -0700 | [diff] [blame] | 111 | mDisableVirtualKeysTimeout(LLONG_MIN), |
| 112 | mNextTimeout(LLONG_MAX), |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 113 | mConfigurationChangesToRefresh(0) { |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 114 | refreshConfigurationLocked(/*changes=*/{}); |
Siarhei Vishniakou | 1805009 | 2021-09-01 13:32:49 -0700 | [diff] [blame] | 115 | updateGlobalMetaStateLocked(); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 118 | InputReader::~InputReader() {} |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 119 | |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 120 | status_t InputReader::start() { |
Prabir Pradhan | 5a57cff | 2019-10-31 18:40:33 -0700 | [diff] [blame] | 121 | if (mThread) { |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 122 | return ALREADY_EXISTS; |
| 123 | } |
Prabir Pradhan | 5a57cff | 2019-10-31 18:40:33 -0700 | [diff] [blame] | 124 | mThread = std::make_unique<InputThread>( |
| 125 | "InputReader", [this]() { loopOnce(); }, [this]() { mEventHub->wake(); }); |
| 126 | return OK; |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | status_t InputReader::stop() { |
Prabir Pradhan | 5a57cff | 2019-10-31 18:40:33 -0700 | [diff] [blame] | 130 | if (mThread && mThread->isCallingThread()) { |
| 131 | ALOGE("InputReader cannot be stopped from its own thread!"); |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 132 | return INVALID_OPERATION; |
| 133 | } |
Prabir Pradhan | 5a57cff | 2019-10-31 18:40:33 -0700 | [diff] [blame] | 134 | mThread.reset(); |
| 135 | return OK; |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 138 | void InputReader::loopOnce() { |
| 139 | int32_t oldGeneration; |
| 140 | int32_t timeoutMillis; |
Prabir Pradhan | da20b17 | 2022-09-26 17:01:18 +0000 | [diff] [blame] | 141 | // Copy some state so that we can access it outside the lock later. |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 142 | bool inputDevicesChanged = false; |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 143 | std::vector<InputDeviceInfo> inputDevices; |
Prabir Pradhan | da20b17 | 2022-09-26 17:01:18 +0000 | [diff] [blame] | 144 | std::list<NotifyArgs> notifyArgs; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 145 | { // acquire lock |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 146 | std::scoped_lock _l(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 147 | |
| 148 | oldGeneration = mGeneration; |
| 149 | timeoutMillis = -1; |
| 150 | |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 151 | auto changes = mConfigurationChangesToRefresh; |
| 152 | if (changes.any()) { |
| 153 | mConfigurationChangesToRefresh.clear(); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 154 | timeoutMillis = 0; |
| 155 | refreshConfigurationLocked(changes); |
| 156 | } else if (mNextTimeout != LLONG_MAX) { |
| 157 | nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); |
| 158 | timeoutMillis = toMillisecondTimeoutDelay(now, mNextTimeout); |
| 159 | } |
| 160 | } // release lock |
| 161 | |
Siarhei Vishniakou | 7b3ea0b | 2022-09-16 14:23:20 -0700 | [diff] [blame] | 162 | std::vector<RawEvent> events = mEventHub->getEvents(timeoutMillis); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 163 | |
| 164 | { // acquire lock |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 165 | std::scoped_lock _l(mLock); |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 166 | mReaderIsAliveCondition.notify_all(); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 167 | |
Siarhei Vishniakou | 7b3ea0b | 2022-09-16 14:23:20 -0700 | [diff] [blame] | 168 | if (!events.empty()) { |
Siarhei Vishniakou | 23a98bf | 2023-08-15 17:28:49 -0700 | [diff] [blame] | 169 | mPendingArgs += processEventsLocked(events.data(), events.size()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | if (mNextTimeout != LLONG_MAX) { |
| 173 | nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); |
| 174 | if (now >= mNextTimeout) { |
Prabir Pradhan | 011ca3d | 2023-02-22 21:31:39 +0000 | [diff] [blame] | 175 | if (debugRawEvents()) { |
Siarhei Vishniakou | 465e1c0 | 2021-12-09 10:47:29 -0800 | [diff] [blame] | 176 | ALOGD("Timeout expired, latency=%0.3fms", (now - mNextTimeout) * 0.000001f); |
| 177 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 178 | mNextTimeout = LLONG_MAX; |
Siarhei Vishniakou | 23a98bf | 2023-08-15 17:28:49 -0700 | [diff] [blame] | 179 | mPendingArgs += timeoutExpiredLocked(now); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | |
| 183 | if (oldGeneration != mGeneration) { |
Liana Kazanova | 5b8217b | 2024-07-18 17:44:51 +0000 | [diff] [blame] | 184 | // Reset global meta state because it depends on connected input devices. |
| 185 | updateGlobalMetaStateLocked(); |
| 186 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 187 | inputDevicesChanged = true; |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 188 | inputDevices = getInputDevicesLocked(); |
Siarhei Vishniakou | 23a98bf | 2023-08-15 17:28:49 -0700 | [diff] [blame] | 189 | mPendingArgs.emplace_back( |
Prabir Pradhan | e3da4bb | 2023-04-05 23:51:23 +0000 | [diff] [blame] | 190 | NotifyInputDevicesChangedArgs{mContext.getNextId(), inputDevices}); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 191 | } |
Siarhei Vishniakou | 23a98bf | 2023-08-15 17:28:49 -0700 | [diff] [blame] | 192 | |
| 193 | std::swap(notifyArgs, mPendingArgs); |
Prabir Pradhan | 018faea | 2024-05-08 21:52:54 +0000 | [diff] [blame] | 194 | |
| 195 | // Keep track of the last used device |
| 196 | for (const NotifyArgs& args : notifyArgs) { |
| 197 | mLastUsedDeviceId = getDeviceIdOfNewGesture(args).value_or(mLastUsedDeviceId); |
| 198 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 199 | } // release lock |
| 200 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 201 | // Flush queued events out to the listener. |
| 202 | // This must happen outside of the lock because the listener could potentially call |
| 203 | // back into the InputReader's methods, such as getScanCodeState, or become blocked |
| 204 | // on another thread similarly waiting to acquire the InputReader lock thereby |
| 205 | // resulting in a deadlock. This situation is actually quite plausible because the |
| 206 | // listener is actually the input dispatcher, which calls into the window manager, |
| 207 | // which occasionally calls into the input reader. |
Siarhei Vishniakou | 23a98bf | 2023-08-15 17:28:49 -0700 | [diff] [blame] | 208 | for (const NotifyArgs& args : notifyArgs) { |
| 209 | mNextListener.notify(args); |
| 210 | } |
Prabir Pradhan | c3a9247 | 2024-02-06 20:08:05 +0000 | [diff] [blame] | 211 | |
| 212 | // Notify the policy that input devices have changed. |
| 213 | // This must be done after flushing events down the listener chain to ensure that the rest of |
| 214 | // the listeners are synchronized with the changes before the policy reacts to them. |
| 215 | if (inputDevicesChanged) { |
| 216 | mPolicy->notifyInputDevicesChanged(inputDevices); |
| 217 | } |
| 218 | |
| 219 | // Notify the policy of the start of every new stylus gesture. |
| 220 | for (const auto& args : notifyArgs) { |
| 221 | const auto* motionArgs = std::get_if<NotifyMotionArgs>(&args); |
| 222 | if (motionArgs != nullptr && isStylusPointerGestureStart(*motionArgs)) { |
| 223 | mPolicy->notifyStylusGestureStarted(motionArgs->deviceId, motionArgs->eventTime); |
| 224 | } |
| 225 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 228 | std::list<NotifyArgs> InputReader::processEventsLocked(const RawEvent* rawEvents, size_t count) { |
| 229 | std::list<NotifyArgs> out; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 230 | for (const RawEvent* rawEvent = rawEvents; count;) { |
| 231 | int32_t type = rawEvent->type; |
| 232 | size_t batchSize = 1; |
| 233 | if (type < EventHubInterface::FIRST_SYNTHETIC_EVENT) { |
| 234 | int32_t deviceId = rawEvent->deviceId; |
| 235 | while (batchSize < count) { |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 236 | if (rawEvent[batchSize].type >= EventHubInterface::FIRST_SYNTHETIC_EVENT || |
| 237 | rawEvent[batchSize].deviceId != deviceId) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 238 | break; |
| 239 | } |
| 240 | batchSize += 1; |
| 241 | } |
Prabir Pradhan | 011ca3d | 2023-02-22 21:31:39 +0000 | [diff] [blame] | 242 | if (debugRawEvents()) { |
Siarhei Vishniakou | 465e1c0 | 2021-12-09 10:47:29 -0800 | [diff] [blame] | 243 | ALOGD("BatchSize: %zu Count: %zu", batchSize, count); |
| 244 | } |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 245 | out += processEventsForDeviceLocked(deviceId, rawEvent, batchSize); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 246 | } else { |
| 247 | switch (rawEvent->type) { |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 248 | case EventHubInterface::DEVICE_ADDED: |
| 249 | addDeviceLocked(rawEvent->when, rawEvent->deviceId); |
| 250 | break; |
| 251 | case EventHubInterface::DEVICE_REMOVED: |
| 252 | removeDeviceLocked(rawEvent->when, rawEvent->deviceId); |
| 253 | break; |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 254 | default: |
| 255 | ALOG_ASSERT(false); // can't happen |
| 256 | break; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | count -= batchSize; |
| 260 | rawEvent += batchSize; |
| 261 | } |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 262 | return out; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 263 | } |
| 264 | |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 265 | void InputReader::addDeviceLocked(nsecs_t when, int32_t eventHubId) { |
| 266 | if (mDevices.find(eventHubId) != mDevices.end()) { |
| 267 | ALOGW("Ignoring spurious device added event for eventHubId %d.", eventHubId); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 268 | return; |
| 269 | } |
| 270 | |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 271 | InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(eventHubId); |
Arpit Singh | 82f29a1 | 2023-06-13 15:05:53 +0000 | [diff] [blame] | 272 | std::shared_ptr<InputDevice> device = createDeviceLocked(when, eventHubId, identifier); |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 273 | |
Siarhei Vishniakou | 23a98bf | 2023-08-15 17:28:49 -0700 | [diff] [blame] | 274 | mPendingArgs += device->configure(when, mConfig, /*changes=*/{}); |
| 275 | mPendingArgs += device->reset(when); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 276 | |
| 277 | if (device->isIgnored()) { |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 278 | ALOGI("Device added: id=%d, eventHubId=%d, name='%s', descriptor='%s' " |
| 279 | "(ignored non-input device)", |
| 280 | device->getId(), eventHubId, identifier.name.c_str(), identifier.descriptor.c_str()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 281 | } else { |
Siarhei Vishniakou | 88151b8 | 2022-08-11 00:53:38 +0000 | [diff] [blame] | 282 | ALOGI("Device added: id=%d, eventHubId=%d, name='%s', descriptor='%s',sources=%s", |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 283 | device->getId(), eventHubId, identifier.name.c_str(), identifier.descriptor.c_str(), |
Siarhei Vishniakou | 88151b8 | 2022-08-11 00:53:38 +0000 | [diff] [blame] | 284 | inputEventSourceToString(device->getSources()).c_str()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 285 | } |
| 286 | |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 287 | mDevices.emplace(eventHubId, device); |
Chris Ye | e731003 | 2020-09-22 15:36:28 -0700 | [diff] [blame] | 288 | // Add device to device to EventHub ids map. |
| 289 | const auto mapIt = mDeviceToEventHubIdsMap.find(device); |
| 290 | if (mapIt == mDeviceToEventHubIdsMap.end()) { |
| 291 | std::vector<int32_t> ids = {eventHubId}; |
| 292 | mDeviceToEventHubIdsMap.emplace(device, ids); |
| 293 | } else { |
| 294 | mapIt->second.push_back(eventHubId); |
| 295 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 296 | bumpGenerationLocked(); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 297 | |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 298 | if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS)) { |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 299 | notifyExternalStylusPresenceChangedLocked(); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 300 | } |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 301 | |
| 302 | // Sensor input device is noisy, to save power disable it by default. |
Chris Ye | e14523a | 2020-12-19 13:46:00 -0800 | [diff] [blame] | 303 | // Input device is classified as SENSOR when any sub device is a SENSOR device, check Eventhub |
| 304 | // device class to disable SENSOR sub device only. |
| 305 | if (mEventHub->getDeviceClasses(eventHubId).test(InputDeviceClass::SENSOR)) { |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 306 | mEventHub->disableDevice(eventHubId); |
| 307 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 308 | } |
| 309 | |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 310 | void InputReader::removeDeviceLocked(nsecs_t when, int32_t eventHubId) { |
| 311 | auto deviceIt = mDevices.find(eventHubId); |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 312 | if (deviceIt == mDevices.end()) { |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 313 | ALOGW("Ignoring spurious device removed event for eventHubId %d.", eventHubId); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 314 | return; |
| 315 | } |
| 316 | |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 317 | std::shared_ptr<InputDevice> device = std::move(deviceIt->second); |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 318 | mDevices.erase(deviceIt); |
Chris Ye | e731003 | 2020-09-22 15:36:28 -0700 | [diff] [blame] | 319 | // Erase device from device to EventHub ids map. |
| 320 | auto mapIt = mDeviceToEventHubIdsMap.find(device); |
| 321 | if (mapIt != mDeviceToEventHubIdsMap.end()) { |
| 322 | std::vector<int32_t>& eventHubIds = mapIt->second; |
Siarhei Vishniakou | f47c339e | 2021-12-30 11:22:26 -0800 | [diff] [blame] | 323 | std::erase_if(eventHubIds, [eventHubId](int32_t eId) { return eId == eventHubId; }); |
Chris Ye | e731003 | 2020-09-22 15:36:28 -0700 | [diff] [blame] | 324 | if (eventHubIds.size() == 0) { |
| 325 | mDeviceToEventHubIdsMap.erase(mapIt); |
| 326 | } |
| 327 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 328 | bumpGenerationLocked(); |
| 329 | |
| 330 | if (device->isIgnored()) { |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 331 | ALOGI("Device removed: id=%d, eventHubId=%d, name='%s', descriptor='%s' " |
| 332 | "(ignored non-input device)", |
| 333 | device->getId(), eventHubId, device->getName().c_str(), |
| 334 | device->getDescriptor().c_str()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 335 | } else { |
Siarhei Vishniakou | 88151b8 | 2022-08-11 00:53:38 +0000 | [diff] [blame] | 336 | ALOGI("Device removed: id=%d, eventHubId=%d, name='%s', descriptor='%s', sources=%s", |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 337 | device->getId(), eventHubId, device->getName().c_str(), |
Siarhei Vishniakou | 88151b8 | 2022-08-11 00:53:38 +0000 | [diff] [blame] | 338 | device->getDescriptor().c_str(), |
| 339 | inputEventSourceToString(device->getSources()).c_str()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 342 | device->removeEventHubDevice(eventHubId); |
| 343 | |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 344 | if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS)) { |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 345 | notifyExternalStylusPresenceChangedLocked(); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 348 | if (device->hasEventHubDevices()) { |
Siarhei Vishniakou | 23a98bf | 2023-08-15 17:28:49 -0700 | [diff] [blame] | 349 | mPendingArgs += device->configure(when, mConfig, /*changes=*/{}); |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 350 | } |
Siarhei Vishniakou | 23a98bf | 2023-08-15 17:28:49 -0700 | [diff] [blame] | 351 | mPendingArgs += device->reset(when); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 352 | } |
| 353 | |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 354 | std::shared_ptr<InputDevice> InputReader::createDeviceLocked( |
Arpit Singh | 82f29a1 | 2023-06-13 15:05:53 +0000 | [diff] [blame] | 355 | nsecs_t when, int32_t eventHubId, const InputDeviceIdentifier& identifier) { |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 356 | auto deviceIt = std::find_if(mDevices.begin(), mDevices.end(), [identifier](auto& devicePair) { |
Josh Bartel | 938632f | 2022-07-19 15:34:22 -0500 | [diff] [blame] | 357 | const InputDeviceIdentifier identifier2 = |
| 358 | devicePair.second->getDeviceInfo().getIdentifier(); |
| 359 | return isSubDevice(identifier, identifier2); |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 360 | }); |
| 361 | |
| 362 | std::shared_ptr<InputDevice> device; |
| 363 | if (deviceIt != mDevices.end()) { |
| 364 | device = deviceIt->second; |
| 365 | } else { |
| 366 | int32_t deviceId = (eventHubId < END_RESERVED_ID) ? eventHubId : nextInputDeviceIdLocked(); |
| 367 | device = std::make_shared<InputDevice>(&mContext, deviceId, bumpGenerationLocked(), |
| 368 | identifier); |
| 369 | } |
Arpit Singh | 82f29a1 | 2023-06-13 15:05:53 +0000 | [diff] [blame] | 370 | mPendingArgs += device->addEventHubDevice(when, eventHubId, mConfig); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 371 | return device; |
| 372 | } |
| 373 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 374 | std::list<NotifyArgs> InputReader::processEventsForDeviceLocked(int32_t eventHubId, |
| 375 | const RawEvent* rawEvents, |
| 376 | size_t count) { |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 377 | auto deviceIt = mDevices.find(eventHubId); |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 378 | if (deviceIt == mDevices.end()) { |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 379 | ALOGW("Discarding event for unknown eventHubId %d.", eventHubId); |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 380 | return {}; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 381 | } |
| 382 | |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 383 | std::shared_ptr<InputDevice>& device = deviceIt->second; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 384 | if (device->isIgnored()) { |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 385 | // ALOGD("Discarding event for ignored deviceId %d.", deviceId); |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 386 | return {}; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 387 | } |
| 388 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 389 | return device->process(rawEvents, count); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 390 | } |
| 391 | |
Philip Junker | 4af3b3d | 2021-12-14 10:36:55 +0100 | [diff] [blame] | 392 | InputDevice* InputReader::findInputDeviceLocked(int32_t deviceId) const { |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 393 | auto deviceIt = |
| 394 | std::find_if(mDevices.begin(), mDevices.end(), [deviceId](const auto& devicePair) { |
| 395 | return devicePair.second->getId() == deviceId; |
| 396 | }); |
| 397 | if (deviceIt != mDevices.end()) { |
| 398 | return deviceIt->second.get(); |
| 399 | } |
| 400 | return nullptr; |
| 401 | } |
| 402 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 403 | std::list<NotifyArgs> InputReader::timeoutExpiredLocked(nsecs_t when) { |
| 404 | std::list<NotifyArgs> out; |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 405 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 406 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 407 | if (!device->isIgnored()) { |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 408 | out += device->timeoutExpired(when); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 409 | } |
| 410 | } |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 411 | return out; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 412 | } |
| 413 | |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 414 | int32_t InputReader::nextInputDeviceIdLocked() { |
| 415 | return ++mNextInputDeviceId; |
| 416 | } |
| 417 | |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 418 | void InputReader::refreshConfigurationLocked(ConfigurationChanges changes) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 419 | mPolicy->getReaderConfiguration(&mConfig); |
| 420 | mEventHub->setExcludedDevices(mConfig.excludedDeviceNames); |
| 421 | |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 422 | using Change = InputReaderConfiguration::Change; |
| 423 | if (!changes.any()) return; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 424 | |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 425 | ALOGI("Reconfiguring input devices, changes=%s", changes.string().c_str()); |
Prabir Pradhan | 7e18618 | 2020-11-10 13:56:45 -0800 | [diff] [blame] | 426 | nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); |
Prabir Pradhan | c7ef27e | 2020-02-03 19:19:15 -0800 | [diff] [blame] | 427 | |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 428 | if (changes.test(Change::MUST_REOPEN)) { |
Prabir Pradhan | 7e18618 | 2020-11-10 13:56:45 -0800 | [diff] [blame] | 429 | mEventHub->requestReopenDevices(); |
| 430 | } else { |
| 431 | for (auto& devicePair : mDevices) { |
| 432 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Siarhei Vishniakou | 23a98bf | 2023-08-15 17:28:49 -0700 | [diff] [blame] | 433 | mPendingArgs += device->configure(now, mConfig, changes); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 434 | } |
| 435 | } |
Prabir Pradhan | 7e18618 | 2020-11-10 13:56:45 -0800 | [diff] [blame] | 436 | |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 437 | if (changes.test(Change::POINTER_CAPTURE)) { |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 438 | if (mCurrentPointerCaptureRequest == mConfig.pointerCaptureRequest) { |
| 439 | ALOGV("Skipping notifying pointer capture changes: " |
| 440 | "There was no change in the pointer capture state."); |
| 441 | } else { |
| 442 | mCurrentPointerCaptureRequest = mConfig.pointerCaptureRequest; |
Siarhei Vishniakou | 23a98bf | 2023-08-15 17:28:49 -0700 | [diff] [blame] | 443 | mPendingArgs.emplace_back( |
| 444 | NotifyPointerCaptureChangedArgs{mContext.getNextId(), now, |
| 445 | mCurrentPointerCaptureRequest}); |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 446 | } |
Prabir Pradhan | 7e18618 | 2020-11-10 13:56:45 -0800 | [diff] [blame] | 447 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | void InputReader::updateGlobalMetaStateLocked() { |
| 451 | mGlobalMetaState = 0; |
| 452 | |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 453 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 454 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 455 | mGlobalMetaState |= device->getMetaState(); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | int32_t InputReader::getGlobalMetaStateLocked() { |
| 460 | return mGlobalMetaState; |
| 461 | } |
| 462 | |
arthurhung | c903df1 | 2020-08-11 15:08:42 +0800 | [diff] [blame] | 463 | void InputReader::updateLedMetaStateLocked(int32_t metaState) { |
| 464 | mLedMetaState = metaState; |
| 465 | for (auto& devicePair : mDevices) { |
| 466 | std::shared_ptr<InputDevice>& device = devicePair.second; |
| 467 | device->updateLedState(false); |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | int32_t InputReader::getLedMetaStateLocked() { |
| 472 | return mLedMetaState; |
| 473 | } |
| 474 | |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 475 | void InputReader::notifyExternalStylusPresenceChangedLocked() { |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 476 | refreshConfigurationLocked(InputReaderConfiguration::Change::EXTERNAL_STYLUS_PRESENCE); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 479 | void InputReader::getExternalStylusDevicesLocked(std::vector<InputDeviceInfo>& outDevices) { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 480 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 481 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 482 | if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS) && !device->isIgnored()) { |
Siarhei Vishniakou | 1983a71 | 2021-06-04 19:27:09 +0000 | [diff] [blame] | 483 | outDevices.push_back(device->getDeviceInfo()); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | } |
| 487 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 488 | std::list<NotifyArgs> InputReader::dispatchExternalStylusStateLocked(const StylusState& state) { |
| 489 | std::list<NotifyArgs> out; |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 490 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 491 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 492 | out += device->updateExternalStylusState(state); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 493 | } |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 494 | return out; |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 497 | void InputReader::disableVirtualKeysUntilLocked(nsecs_t time) { |
| 498 | mDisableVirtualKeysTimeout = time; |
| 499 | } |
| 500 | |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 501 | bool InputReader::shouldDropVirtualKeyLocked(nsecs_t now, int32_t keyCode, int32_t scanCode) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 502 | if (now < mDisableVirtualKeysTimeout) { |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 503 | ALOGI("Dropping virtual key from device because virtual keys are " |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 504 | "temporarily disabled for the next %0.3fms. keyCode=%d, scanCode=%d", |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 505 | (mDisableVirtualKeysTimeout - now) * 0.000001, keyCode, scanCode); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 506 | return true; |
| 507 | } else { |
| 508 | return false; |
| 509 | } |
| 510 | } |
| 511 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 512 | void InputReader::requestTimeoutAtTimeLocked(nsecs_t when) { |
| 513 | if (when < mNextTimeout) { |
| 514 | mNextTimeout = when; |
| 515 | mEventHub->wake(); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | int32_t InputReader::bumpGenerationLocked() { |
| 520 | return ++mGeneration; |
| 521 | } |
| 522 | |
Chris Ye | 98d3f53 | 2020-10-01 21:48:59 -0700 | [diff] [blame] | 523 | std::vector<InputDeviceInfo> InputReader::getInputDevices() const { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 524 | std::scoped_lock _l(mLock); |
Chris Ye | 98d3f53 | 2020-10-01 21:48:59 -0700 | [diff] [blame] | 525 | return getInputDevicesLocked(); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 526 | } |
| 527 | |
Chris Ye | 98d3f53 | 2020-10-01 21:48:59 -0700 | [diff] [blame] | 528 | std::vector<InputDeviceInfo> InputReader::getInputDevicesLocked() const { |
| 529 | std::vector<InputDeviceInfo> outInputDevices; |
| 530 | outInputDevices.reserve(mDeviceToEventHubIdsMap.size()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 531 | |
Chris Ye | e731003 | 2020-09-22 15:36:28 -0700 | [diff] [blame] | 532 | for (const auto& [device, eventHubIds] : mDeviceToEventHubIdsMap) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 533 | if (!device->isIgnored()) { |
Siarhei Vishniakou | 1983a71 | 2021-06-04 19:27:09 +0000 | [diff] [blame] | 534 | outInputDevices.push_back(device->getDeviceInfo()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 535 | } |
| 536 | } |
Chris Ye | 98d3f53 | 2020-10-01 21:48:59 -0700 | [diff] [blame] | 537 | return outInputDevices; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 538 | } |
| 539 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 540 | int32_t InputReader::getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 541 | std::scoped_lock _l(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 542 | |
| 543 | return getStateLocked(deviceId, sourceMask, keyCode, &InputDevice::getKeyCodeState); |
| 544 | } |
| 545 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 546 | int32_t InputReader::getScanCodeState(int32_t deviceId, uint32_t sourceMask, int32_t scanCode) { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 547 | std::scoped_lock _l(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 548 | |
| 549 | return getStateLocked(deviceId, sourceMask, scanCode, &InputDevice::getScanCodeState); |
| 550 | } |
| 551 | |
| 552 | int32_t InputReader::getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t switchCode) { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 553 | std::scoped_lock _l(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 554 | |
| 555 | return getStateLocked(deviceId, sourceMask, switchCode, &InputDevice::getSwitchState); |
| 556 | } |
| 557 | |
| 558 | int32_t InputReader::getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code, |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 559 | GetStateFunc getStateFunc) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 560 | int32_t result = AKEY_STATE_UNKNOWN; |
| 561 | if (deviceId >= 0) { |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 562 | InputDevice* device = findInputDeviceLocked(deviceId); |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 563 | if (device && !device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
| 564 | result = (device->*getStateFunc)(sourceMask, code); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 565 | } |
| 566 | } else { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 567 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 568 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 569 | if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 570 | // If any device reports AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL, return that |
| 571 | // value. Otherwise, return AKEY_STATE_UP as long as one device reports it. |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 572 | int32_t currentResult = (device.get()->*getStateFunc)(sourceMask, code); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 573 | if (currentResult >= AKEY_STATE_DOWN) { |
| 574 | return currentResult; |
| 575 | } else if (currentResult == AKEY_STATE_UP) { |
| 576 | result = currentResult; |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | } |
| 581 | return result; |
| 582 | } |
| 583 | |
Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 584 | void InputReader::toggleCapsLockState(int32_t deviceId) { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 585 | std::scoped_lock _l(mLock); |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 586 | InputDevice* device = findInputDeviceLocked(deviceId); |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 587 | if (!device) { |
Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 588 | ALOGW("Ignoring toggleCapsLock for unknown deviceId %" PRId32 ".", deviceId); |
| 589 | return; |
| 590 | } |
| 591 | |
Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 592 | if (device->isIgnored()) { |
Arthur Hung | cb40a00 | 2021-08-03 14:31:01 +0000 | [diff] [blame] | 593 | ALOGW("Ignoring toggleCapsLock for ignored deviceId %" PRId32 ".", deviceId); |
Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 594 | return; |
| 595 | } |
| 596 | |
| 597 | device->updateMetaState(AKEYCODE_CAPS_LOCK); |
| 598 | } |
| 599 | |
Siarhei Vishniakou | 7400794 | 2022-06-13 13:57:47 -0700 | [diff] [blame] | 600 | bool InputReader::hasKeys(int32_t deviceId, uint32_t sourceMask, |
| 601 | const std::vector<int32_t>& keyCodes, uint8_t* outFlags) { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 602 | std::scoped_lock _l(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 603 | |
Siarhei Vishniakou | 7400794 | 2022-06-13 13:57:47 -0700 | [diff] [blame] | 604 | memset(outFlags, 0, keyCodes.size()); |
| 605 | return markSupportedKeyCodesLocked(deviceId, sourceMask, keyCodes, outFlags); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | bool InputReader::markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask, |
Siarhei Vishniakou | 7400794 | 2022-06-13 13:57:47 -0700 | [diff] [blame] | 609 | const std::vector<int32_t>& keyCodes, |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 610 | uint8_t* outFlags) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 611 | bool result = false; |
| 612 | if (deviceId >= 0) { |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 613 | InputDevice* device = findInputDeviceLocked(deviceId); |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 614 | if (device && !device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
Siarhei Vishniakou | 7400794 | 2022-06-13 13:57:47 -0700 | [diff] [blame] | 615 | result = device->markSupportedKeyCodes(sourceMask, keyCodes, outFlags); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 616 | } |
| 617 | } else { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 618 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 619 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 620 | if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
Siarhei Vishniakou | 7400794 | 2022-06-13 13:57:47 -0700 | [diff] [blame] | 621 | result |= device->markSupportedKeyCodes(sourceMask, keyCodes, outFlags); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | } |
| 625 | return result; |
| 626 | } |
| 627 | |
Philip Junker | 4af3b3d | 2021-12-14 10:36:55 +0100 | [diff] [blame] | 628 | int32_t InputReader::getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const { |
| 629 | std::scoped_lock _l(mLock); |
| 630 | |
| 631 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 632 | if (device == nullptr) { |
| 633 | ALOGW("Failed to get key code for key location: Input device with id %d not found", |
| 634 | deviceId); |
| 635 | return AKEYCODE_UNKNOWN; |
| 636 | } |
| 637 | return device->getKeyCodeForKeyLocation(locationKeyCode); |
| 638 | } |
| 639 | |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 640 | void InputReader::requestRefreshConfiguration(ConfigurationChanges changes) { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 641 | std::scoped_lock _l(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 642 | |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame] | 643 | if (changes.any()) { |
| 644 | bool needWake = !mConfigurationChangesToRefresh.any(); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 645 | mConfigurationChangesToRefresh |= changes; |
| 646 | |
| 647 | if (needWake) { |
| 648 | mEventHub->wake(); |
| 649 | } |
| 650 | } |
| 651 | } |
| 652 | |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 653 | void InputReader::vibrate(int32_t deviceId, const VibrationSequence& sequence, ssize_t repeat, |
| 654 | int32_t token) { |
| 655 | std::scoped_lock _l(mLock); |
| 656 | |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 657 | InputDevice* device = findInputDeviceLocked(deviceId); |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 658 | if (device) { |
Siarhei Vishniakou | 23a98bf | 2023-08-15 17:28:49 -0700 | [diff] [blame] | 659 | mPendingArgs += device->vibrate(sequence, repeat, token); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 660 | } |
| 661 | } |
| 662 | |
| 663 | void InputReader::cancelVibrate(int32_t deviceId, int32_t token) { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 664 | std::scoped_lock _l(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 665 | |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 666 | InputDevice* device = findInputDeviceLocked(deviceId); |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 667 | if (device) { |
Siarhei Vishniakou | 23a98bf | 2023-08-15 17:28:49 -0700 | [diff] [blame] | 668 | mPendingArgs += device->cancelVibrate(token); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 669 | } |
| 670 | } |
| 671 | |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 672 | bool InputReader::isVibrating(int32_t deviceId) { |
| 673 | std::scoped_lock _l(mLock); |
| 674 | |
| 675 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 676 | if (device) { |
| 677 | return device->isVibrating(); |
| 678 | } |
| 679 | return false; |
| 680 | } |
| 681 | |
| 682 | std::vector<int32_t> InputReader::getVibratorIds(int32_t deviceId) { |
| 683 | std::scoped_lock _l(mLock); |
| 684 | |
| 685 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 686 | if (device) { |
| 687 | return device->getVibratorIds(); |
| 688 | } |
| 689 | return {}; |
| 690 | } |
| 691 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 692 | void InputReader::disableSensor(int32_t deviceId, InputDeviceSensorType sensorType) { |
| 693 | std::scoped_lock _l(mLock); |
| 694 | |
| 695 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 696 | if (device) { |
| 697 | device->disableSensor(sensorType); |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | bool InputReader::enableSensor(int32_t deviceId, InputDeviceSensorType sensorType, |
| 702 | std::chrono::microseconds samplingPeriod, |
| 703 | std::chrono::microseconds maxBatchReportLatency) { |
| 704 | std::scoped_lock _l(mLock); |
| 705 | |
| 706 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 707 | if (device) { |
| 708 | return device->enableSensor(sensorType, samplingPeriod, maxBatchReportLatency); |
| 709 | } |
| 710 | return false; |
| 711 | } |
| 712 | |
| 713 | void InputReader::flushSensor(int32_t deviceId, InputDeviceSensorType sensorType) { |
| 714 | std::scoped_lock _l(mLock); |
| 715 | |
| 716 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 717 | if (device) { |
| 718 | device->flushSensor(sensorType); |
| 719 | } |
| 720 | } |
| 721 | |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 722 | std::optional<int32_t> InputReader::getBatteryCapacity(int32_t deviceId) { |
Andy Chen | f9f1a02 | 2022-08-29 20:07:10 -0400 | [diff] [blame] | 723 | std::optional<int32_t> eventHubId; |
| 724 | { |
| 725 | // Do not query the battery state while holding the lock. For some peripheral devices, |
| 726 | // reading battery state can be broken and take 5+ seconds. Holding the lock in this case |
| 727 | // would block all other event processing during this time. For now, we assume this |
| 728 | // call never happens on the InputReader thread and get the battery state outside the |
| 729 | // lock to prevent event processing from being blocked by this call. |
| 730 | std::scoped_lock _l(mLock); |
| 731 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 732 | if (!device) return {}; |
| 733 | eventHubId = device->getBatteryEventHubId(); |
| 734 | } // release lock |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 735 | |
Andy Chen | f9f1a02 | 2022-08-29 20:07:10 -0400 | [diff] [blame] | 736 | if (!eventHubId) return {}; |
| 737 | const auto batteryIds = mEventHub->getRawBatteryIds(*eventHubId); |
Prabir Pradhan | e287ecd | 2022-09-07 21:18:05 +0000 | [diff] [blame] | 738 | if (batteryIds.empty()) { |
| 739 | ALOGW("%s: There are no battery ids for EventHub device %d", __func__, *eventHubId); |
| 740 | return {}; |
| 741 | } |
Andy Chen | f9f1a02 | 2022-08-29 20:07:10 -0400 | [diff] [blame] | 742 | return mEventHub->getBatteryCapacity(*eventHubId, batteryIds.front()); |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | std::optional<int32_t> InputReader::getBatteryStatus(int32_t deviceId) { |
Andy Chen | f9f1a02 | 2022-08-29 20:07:10 -0400 | [diff] [blame] | 746 | std::optional<int32_t> eventHubId; |
| 747 | { |
| 748 | // Do not query the battery state while holding the lock. For some peripheral devices, |
| 749 | // reading battery state can be broken and take 5+ seconds. Holding the lock in this case |
| 750 | // would block all other event processing during this time. For now, we assume this |
| 751 | // call never happens on the InputReader thread and get the battery state outside the |
| 752 | // lock to prevent event processing from being blocked by this call. |
| 753 | std::scoped_lock _l(mLock); |
| 754 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 755 | if (!device) return {}; |
| 756 | eventHubId = device->getBatteryEventHubId(); |
| 757 | } // release lock |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 758 | |
Andy Chen | f9f1a02 | 2022-08-29 20:07:10 -0400 | [diff] [blame] | 759 | if (!eventHubId) return {}; |
| 760 | const auto batteryIds = mEventHub->getRawBatteryIds(*eventHubId); |
Prabir Pradhan | e287ecd | 2022-09-07 21:18:05 +0000 | [diff] [blame] | 761 | if (batteryIds.empty()) { |
| 762 | ALOGW("%s: There are no battery ids for EventHub device %d", __func__, *eventHubId); |
| 763 | return {}; |
| 764 | } |
Andy Chen | f9f1a02 | 2022-08-29 20:07:10 -0400 | [diff] [blame] | 765 | return mEventHub->getBatteryStatus(*eventHubId, batteryIds.front()); |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 766 | } |
| 767 | |
Prabir Pradhan | e287ecd | 2022-09-07 21:18:05 +0000 | [diff] [blame] | 768 | std::optional<std::string> InputReader::getBatteryDevicePath(int32_t deviceId) { |
| 769 | std::scoped_lock _l(mLock); |
| 770 | |
| 771 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 772 | if (!device) return {}; |
| 773 | |
| 774 | std::optional<int32_t> eventHubId = device->getBatteryEventHubId(); |
| 775 | if (!eventHubId) return {}; |
| 776 | const auto batteryIds = mEventHub->getRawBatteryIds(*eventHubId); |
| 777 | if (batteryIds.empty()) { |
| 778 | ALOGW("%s: There are no battery ids for EventHub device %d", __func__, *eventHubId); |
| 779 | return {}; |
| 780 | } |
| 781 | const auto batteryInfo = mEventHub->getRawBatteryInfo(*eventHubId, batteryIds.front()); |
| 782 | if (!batteryInfo) { |
| 783 | ALOGW("%s: Failed to get RawBatteryInfo for battery %d of EventHub device %d", __func__, |
| 784 | batteryIds.front(), *eventHubId); |
| 785 | return {}; |
| 786 | } |
| 787 | return batteryInfo->path; |
| 788 | } |
| 789 | |
Siarhei Vishniakou | 1983a71 | 2021-06-04 19:27:09 +0000 | [diff] [blame] | 790 | std::vector<InputDeviceLightInfo> InputReader::getLights(int32_t deviceId) { |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 791 | std::scoped_lock _l(mLock); |
| 792 | |
| 793 | InputDevice* device = findInputDeviceLocked(deviceId); |
Siarhei Vishniakou | 1983a71 | 2021-06-04 19:27:09 +0000 | [diff] [blame] | 794 | if (device == nullptr) { |
| 795 | return {}; |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 796 | } |
Siarhei Vishniakou | 1983a71 | 2021-06-04 19:27:09 +0000 | [diff] [blame] | 797 | |
| 798 | return device->getDeviceInfo().getLights(); |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 799 | } |
| 800 | |
Siarhei Vishniakou | 1983a71 | 2021-06-04 19:27:09 +0000 | [diff] [blame] | 801 | std::vector<InputDeviceSensorInfo> InputReader::getSensors(int32_t deviceId) { |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 802 | std::scoped_lock _l(mLock); |
| 803 | |
| 804 | InputDevice* device = findInputDeviceLocked(deviceId); |
Siarhei Vishniakou | 1983a71 | 2021-06-04 19:27:09 +0000 | [diff] [blame] | 805 | if (device == nullptr) { |
| 806 | return {}; |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 807 | } |
Siarhei Vishniakou | 1983a71 | 2021-06-04 19:27:09 +0000 | [diff] [blame] | 808 | |
| 809 | return device->getDeviceInfo().getSensors(); |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 810 | } |
| 811 | |
Omar Abdelmonem | 5e70e96 | 2024-08-06 09:38:42 +0000 | [diff] [blame] | 812 | std::optional<HardwareProperties> InputReader::getTouchpadHardwareProperties(int32_t deviceId) { |
| 813 | std::scoped_lock _l(mLock); |
| 814 | |
| 815 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 816 | |
| 817 | if (device == nullptr) { |
| 818 | return {}; |
| 819 | } |
| 820 | |
| 821 | return device->getTouchpadHardwareProperties(); |
| 822 | } |
| 823 | |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 824 | bool InputReader::setLightColor(int32_t deviceId, int32_t lightId, int32_t color) { |
| 825 | std::scoped_lock _l(mLock); |
| 826 | |
| 827 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 828 | if (device) { |
| 829 | return device->setLightColor(lightId, color); |
| 830 | } |
| 831 | return false; |
| 832 | } |
| 833 | |
| 834 | bool InputReader::setLightPlayerId(int32_t deviceId, int32_t lightId, int32_t playerId) { |
| 835 | std::scoped_lock _l(mLock); |
| 836 | |
| 837 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 838 | if (device) { |
| 839 | return device->setLightPlayerId(lightId, playerId); |
| 840 | } |
| 841 | return false; |
| 842 | } |
| 843 | |
| 844 | std::optional<int32_t> InputReader::getLightColor(int32_t deviceId, int32_t lightId) { |
| 845 | std::scoped_lock _l(mLock); |
| 846 | |
| 847 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 848 | if (device) { |
| 849 | return device->getLightColor(lightId); |
| 850 | } |
| 851 | return std::nullopt; |
| 852 | } |
| 853 | |
| 854 | std::optional<int32_t> InputReader::getLightPlayerId(int32_t deviceId, int32_t lightId) { |
| 855 | std::scoped_lock _l(mLock); |
| 856 | |
| 857 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 858 | if (device) { |
| 859 | return device->getLightPlayerId(lightId); |
| 860 | } |
| 861 | return std::nullopt; |
| 862 | } |
| 863 | |
Prabir Pradhan | b54ffb2 | 2022-10-27 18:03:34 +0000 | [diff] [blame] | 864 | std::optional<std::string> InputReader::getBluetoothAddress(int32_t deviceId) const { |
| 865 | std::scoped_lock _l(mLock); |
| 866 | |
| 867 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 868 | if (device) { |
| 869 | return device->getBluetoothAddress(); |
| 870 | } |
| 871 | return std::nullopt; |
| 872 | } |
| 873 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 874 | bool InputReader::canDispatchToDisplay(int32_t deviceId, ui::LogicalDisplayId displayId) { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 875 | std::scoped_lock _l(mLock); |
Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 876 | |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 877 | InputDevice* device = findInputDeviceLocked(deviceId); |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 878 | if (!device) { |
Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 879 | ALOGW("Ignoring invalid device id %" PRId32 ".", deviceId); |
| 880 | return false; |
| 881 | } |
| 882 | |
Arthur Hung | 2c9a334 | 2019-07-23 14:18:59 +0800 | [diff] [blame] | 883 | if (!device->isEnabled()) { |
| 884 | ALOGW("Ignoring disabled device %s", device->getName().c_str()); |
| 885 | return false; |
| 886 | } |
| 887 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 888 | std::optional<ui::LogicalDisplayId> associatedDisplayId = device->getAssociatedDisplayId(); |
Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 889 | // No associated display. By default, can dispatch to all displays. |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 890 | if (!associatedDisplayId || !associatedDisplayId->isValid()) { |
Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 891 | return true; |
| 892 | } |
| 893 | |
| 894 | return *associatedDisplayId == displayId; |
| 895 | } |
| 896 | |
Vaibhav Devmurari | 5fc7d85 | 2023-03-17 18:43:33 +0000 | [diff] [blame] | 897 | void InputReader::sysfsNodeChanged(const std::string& sysfsNodePath) { |
| 898 | mEventHub->sysfsNodeChanged(sysfsNodePath); |
| 899 | } |
| 900 | |
Prabir Pradhan | 018faea | 2024-05-08 21:52:54 +0000 | [diff] [blame] | 901 | DeviceId InputReader::getLastUsedInputDeviceId() { |
| 902 | std::scoped_lock _l(mLock); |
| 903 | return mLastUsedDeviceId; |
| 904 | } |
| 905 | |
Arpit Singh | 849beb4 | 2024-06-06 07:14:17 +0000 | [diff] [blame] | 906 | void InputReader::notifyMouseCursorFadedOnTyping() { |
| 907 | std::scoped_lock _l(mLock); |
| 908 | // disable touchpad taps when cursor has faded due to typing |
| 909 | mPreventingTouchpadTaps = true; |
| 910 | } |
| 911 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 912 | void InputReader::dump(std::string& dump) { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 913 | std::scoped_lock _l(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 914 | |
| 915 | mEventHub->dump(dump); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 916 | dump += "\n"; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 917 | |
Chris Ye | e731003 | 2020-09-22 15:36:28 -0700 | [diff] [blame] | 918 | dump += StringPrintf("Input Reader State (Nums of device: %zu):\n", |
| 919 | mDeviceToEventHubIdsMap.size()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 920 | |
Chris Ye | e731003 | 2020-09-22 15:36:28 -0700 | [diff] [blame] | 921 | for (const auto& devicePair : mDeviceToEventHubIdsMap) { |
| 922 | const std::shared_ptr<InputDevice>& device = devicePair.first; |
| 923 | std::string eventHubDevStr = INDENT "EventHub Devices: [ "; |
| 924 | for (const auto& eId : devicePair.second) { |
| 925 | eventHubDevStr += StringPrintf("%d ", eId); |
| 926 | } |
| 927 | eventHubDevStr += "] \n"; |
| 928 | device->dump(dump, eventHubDevStr); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 929 | } |
| 930 | |
Harry Cutts | 8c7cb59 | 2023-08-23 17:20:13 +0000 | [diff] [blame] | 931 | dump += StringPrintf(INDENT "NextTimeout: %" PRId64 "\n", mNextTimeout); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 932 | dump += INDENT "Configuration:\n"; |
| 933 | dump += INDENT2 "ExcludedDeviceNames: ["; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 934 | for (size_t i = 0; i < mConfig.excludedDeviceNames.size(); i++) { |
| 935 | if (i != 0) { |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 936 | dump += ", "; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 937 | } |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 938 | dump += mConfig.excludedDeviceNames[i]; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 939 | } |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 940 | dump += "]\n"; |
| 941 | dump += StringPrintf(INDENT2 "VirtualKeyQuietTime: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 942 | mConfig.virtualKeyQuietTime * 0.000001f); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 943 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 944 | dump += StringPrintf(INDENT2 "PointerVelocityControlParameters: " |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 945 | "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, " |
| 946 | "acceleration=%0.3f\n", |
| 947 | mConfig.pointerVelocityControlParameters.scale, |
| 948 | mConfig.pointerVelocityControlParameters.lowThreshold, |
| 949 | mConfig.pointerVelocityControlParameters.highThreshold, |
| 950 | mConfig.pointerVelocityControlParameters.acceleration); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 951 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 952 | dump += StringPrintf(INDENT2 "WheelVelocityControlParameters: " |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 953 | "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, " |
| 954 | "acceleration=%0.3f\n", |
| 955 | mConfig.wheelVelocityControlParameters.scale, |
| 956 | mConfig.wheelVelocityControlParameters.lowThreshold, |
| 957 | mConfig.wheelVelocityControlParameters.highThreshold, |
| 958 | mConfig.wheelVelocityControlParameters.acceleration); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 959 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 960 | dump += StringPrintf(INDENT2 "PointerGesture:\n"); |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 961 | dump += StringPrintf(INDENT3 "Enabled: %s\n", toString(mConfig.pointerGesturesEnabled)); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 962 | dump += StringPrintf(INDENT3 "QuietInterval: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 963 | mConfig.pointerGestureQuietInterval * 0.000001f); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 964 | dump += StringPrintf(INDENT3 "DragMinSwitchSpeed: %0.1fpx/s\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 965 | mConfig.pointerGestureDragMinSwitchSpeed); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 966 | dump += StringPrintf(INDENT3 "TapInterval: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 967 | mConfig.pointerGestureTapInterval * 0.000001f); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 968 | dump += StringPrintf(INDENT3 "TapDragInterval: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 969 | mConfig.pointerGestureTapDragInterval * 0.000001f); |
| 970 | dump += StringPrintf(INDENT3 "TapSlop: %0.1fpx\n", mConfig.pointerGestureTapSlop); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 971 | dump += StringPrintf(INDENT3 "MultitouchSettleInterval: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 972 | mConfig.pointerGestureMultitouchSettleInterval * 0.000001f); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 973 | dump += StringPrintf(INDENT3 "MultitouchMinDistance: %0.1fpx\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 974 | mConfig.pointerGestureMultitouchMinDistance); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 975 | dump += StringPrintf(INDENT3 "SwipeTransitionAngleCosine: %0.1f\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 976 | mConfig.pointerGestureSwipeTransitionAngleCosine); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 977 | dump += StringPrintf(INDENT3 "SwipeMaxWidthRatio: %0.1f\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 978 | mConfig.pointerGestureSwipeMaxWidthRatio); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 979 | dump += StringPrintf(INDENT3 "MovementSpeedRatio: %0.1f\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 980 | mConfig.pointerGestureMovementSpeedRatio); |
| 981 | dump += StringPrintf(INDENT3 "ZoomSpeedRatio: %0.1f\n", mConfig.pointerGestureZoomSpeedRatio); |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 982 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 983 | dump += INDENT3 "Viewports:\n"; |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 984 | mConfig.dump(dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | void InputReader::monitor() { |
| 988 | // Acquire and release the lock to ensure that the reader has not deadlocked. |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 989 | std::unique_lock<std::mutex> lock(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 990 | mEventHub->wake(); |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 991 | mReaderIsAliveCondition.wait(lock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 992 | // Check the EventHub |
| 993 | mEventHub->monitor(); |
| 994 | } |
| 995 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 996 | // --- InputReader::ContextImpl --- |
| 997 | |
Garfield Tan | ff1f1bb | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 998 | InputReader::ContextImpl::ContextImpl(InputReader* reader) |
| 999 | : mReader(reader), mIdGenerator(IdGenerator::Source::INPUT_READER) {} |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1000 | |
| 1001 | void InputReader::ContextImpl::updateGlobalMetaState() { |
| 1002 | // lock is already held by the input loop |
| 1003 | mReader->updateGlobalMetaStateLocked(); |
| 1004 | } |
| 1005 | |
| 1006 | int32_t InputReader::ContextImpl::getGlobalMetaState() { |
| 1007 | // lock is already held by the input loop |
| 1008 | return mReader->getGlobalMetaStateLocked(); |
| 1009 | } |
| 1010 | |
arthurhung | c903df1 | 2020-08-11 15:08:42 +0800 | [diff] [blame] | 1011 | void InputReader::ContextImpl::updateLedMetaState(int32_t metaState) { |
| 1012 | // lock is already held by the input loop |
| 1013 | mReader->updateLedMetaStateLocked(metaState); |
| 1014 | } |
| 1015 | |
| 1016 | int32_t InputReader::ContextImpl::getLedMetaState() { |
| 1017 | // lock is already held by the input loop |
| 1018 | return mReader->getLedMetaStateLocked(); |
| 1019 | } |
| 1020 | |
Arpit Singh | a5ea7c1 | 2023-07-05 15:39:25 +0000 | [diff] [blame] | 1021 | void InputReader::ContextImpl::setPreventingTouchpadTaps(bool prevent) { |
| 1022 | // lock is already held by the input loop |
| 1023 | mReader->mPreventingTouchpadTaps = prevent; |
| 1024 | } |
| 1025 | |
| 1026 | bool InputReader::ContextImpl::isPreventingTouchpadTaps() { |
| 1027 | // lock is already held by the input loop |
| 1028 | return mReader->mPreventingTouchpadTaps; |
| 1029 | } |
| 1030 | |
Arpit Singh | 82e413e | 2023-10-10 19:30:58 +0000 | [diff] [blame] | 1031 | void InputReader::ContextImpl::setLastKeyDownTimestamp(nsecs_t when) { |
| 1032 | mReader->mLastKeyDownTimestamp = when; |
| 1033 | } |
| 1034 | |
| 1035 | nsecs_t InputReader::ContextImpl::getLastKeyDownTimestamp() { |
| 1036 | return mReader->mLastKeyDownTimestamp; |
| 1037 | } |
| 1038 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1039 | void InputReader::ContextImpl::disableVirtualKeysUntil(nsecs_t time) { |
| 1040 | // lock is already held by the input loop |
| 1041 | mReader->disableVirtualKeysUntilLocked(time); |
| 1042 | } |
| 1043 | |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 1044 | bool InputReader::ContextImpl::shouldDropVirtualKey(nsecs_t now, int32_t keyCode, |
| 1045 | int32_t scanCode) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1046 | // lock is already held by the input loop |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 1047 | return mReader->shouldDropVirtualKeyLocked(now, keyCode, scanCode); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1048 | } |
| 1049 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1050 | void InputReader::ContextImpl::requestTimeoutAtTime(nsecs_t when) { |
| 1051 | // lock is already held by the input loop |
| 1052 | mReader->requestTimeoutAtTimeLocked(when); |
| 1053 | } |
| 1054 | |
| 1055 | int32_t InputReader::ContextImpl::bumpGeneration() { |
| 1056 | // lock is already held by the input loop |
| 1057 | return mReader->bumpGenerationLocked(); |
| 1058 | } |
| 1059 | |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 1060 | void InputReader::ContextImpl::getExternalStylusDevices(std::vector<InputDeviceInfo>& outDevices) { |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1061 | // lock is already held by whatever called refreshConfigurationLocked |
| 1062 | mReader->getExternalStylusDevicesLocked(outDevices); |
| 1063 | } |
| 1064 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 1065 | std::list<NotifyArgs> InputReader::ContextImpl::dispatchExternalStylusState( |
| 1066 | const StylusState& state) { |
| 1067 | return mReader->dispatchExternalStylusStateLocked(state); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1070 | InputReaderPolicyInterface* InputReader::ContextImpl::getPolicy() { |
| 1071 | return mReader->mPolicy.get(); |
| 1072 | } |
| 1073 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1074 | EventHubInterface* InputReader::ContextImpl::getEventHub() { |
| 1075 | return mReader->mEventHub.get(); |
| 1076 | } |
| 1077 | |
Siarhei Vishniakou | f2f073b | 2021-02-09 21:59:56 +0000 | [diff] [blame] | 1078 | int32_t InputReader::ContextImpl::getNextId() { |
| 1079 | return mIdGenerator.nextId(); |
Prabir Pradhan | 42611e0 | 2018-11-27 14:04:02 -0800 | [diff] [blame] | 1080 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1081 | |
Vaibhav Devmurari | e58ffb9 | 2024-05-22 17:38:25 +0000 | [diff] [blame] | 1082 | KeyboardClassifier& InputReader::ContextImpl::getKeyboardClassifier() { |
| 1083 | return *mReader->mKeyboardClassifier; |
| 1084 | } |
| 1085 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1086 | } // namespace android |