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