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