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