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