Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 17 | #include "Macros.h" |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 18 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 19 | #include "InputReader.h" |
| 20 | |
Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 21 | #include <android-base/stringprintf.h> |
Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 22 | #include <errno.h> |
Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 23 | #include <input/Keyboard.h> |
| 24 | #include <input/VirtualKeyMap.h> |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 25 | #include <inttypes.h> |
Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 26 | #include <limits.h> |
Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 27 | #include <log/log.h> |
Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 28 | #include <math.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 29 | #include <stddef.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <unistd.h> |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 32 | #include <utils/Errors.h> |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 33 | #include <utils/Thread.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 34 | |
Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 35 | #include "InputDevice.h" |
| 36 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 37 | using android::base::StringPrintf; |
| 38 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 39 | namespace android { |
| 40 | |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 41 | // --- InputReader --- |
| 42 | |
Siarhei Vishniakou | 3bc7e09 | 2019-07-24 17:43:30 -0700 | [diff] [blame] | 43 | InputReader::InputReader(std::shared_ptr<EventHubInterface> eventHub, |
| 44 | const sp<InputReaderPolicyInterface>& policy, |
| 45 | const sp<InputListenerInterface>& listener) |
| 46 | : mContext(this), |
| 47 | mEventHub(eventHub), |
| 48 | mPolicy(policy), |
| 49 | mNextSequenceNum(1), |
| 50 | mGlobalMetaState(0), |
| 51 | mGeneration(1), |
| 52 | mDisableVirtualKeysTimeout(LLONG_MIN), |
| 53 | mNextTimeout(LLONG_MAX), |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 54 | mConfigurationChangesToRefresh(0) { |
| 55 | mQueuedListener = new QueuedInputListener(listener); |
| 56 | |
| 57 | { // acquire lock |
| 58 | AutoMutex _l(mLock); |
| 59 | |
| 60 | refreshConfigurationLocked(0); |
| 61 | updateGlobalMetaStateLocked(); |
| 62 | } // release lock |
| 63 | } |
| 64 | |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 65 | InputReader::~InputReader() {} |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 66 | |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 67 | status_t InputReader::start() { |
Prabir Pradhan | 5a57cff | 2019-10-31 18:40:33 -0700 | [diff] [blame] | 68 | if (mThread) { |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 69 | return ALREADY_EXISTS; |
| 70 | } |
Prabir Pradhan | 5a57cff | 2019-10-31 18:40:33 -0700 | [diff] [blame] | 71 | mThread = std::make_unique<InputThread>( |
| 72 | "InputReader", [this]() { loopOnce(); }, [this]() { mEventHub->wake(); }); |
| 73 | return OK; |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | status_t InputReader::stop() { |
Prabir Pradhan | 5a57cff | 2019-10-31 18:40:33 -0700 | [diff] [blame] | 77 | if (mThread && mThread->isCallingThread()) { |
| 78 | ALOGE("InputReader cannot be stopped from its own thread!"); |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 79 | return INVALID_OPERATION; |
| 80 | } |
Prabir Pradhan | 5a57cff | 2019-10-31 18:40:33 -0700 | [diff] [blame] | 81 | mThread.reset(); |
| 82 | return OK; |
Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 85 | void InputReader::loopOnce() { |
| 86 | int32_t oldGeneration; |
| 87 | int32_t timeoutMillis; |
| 88 | bool inputDevicesChanged = false; |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 89 | std::vector<InputDeviceInfo> inputDevices; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 90 | { // acquire lock |
| 91 | AutoMutex _l(mLock); |
| 92 | |
| 93 | oldGeneration = mGeneration; |
| 94 | timeoutMillis = -1; |
| 95 | |
| 96 | uint32_t changes = mConfigurationChangesToRefresh; |
| 97 | if (changes) { |
| 98 | mConfigurationChangesToRefresh = 0; |
| 99 | timeoutMillis = 0; |
| 100 | refreshConfigurationLocked(changes); |
| 101 | } else if (mNextTimeout != LLONG_MAX) { |
| 102 | nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); |
| 103 | timeoutMillis = toMillisecondTimeoutDelay(now, mNextTimeout); |
| 104 | } |
| 105 | } // release lock |
| 106 | |
| 107 | size_t count = mEventHub->getEvents(timeoutMillis, mEventBuffer, EVENT_BUFFER_SIZE); |
| 108 | |
| 109 | { // acquire lock |
| 110 | AutoMutex _l(mLock); |
| 111 | mReaderIsAliveCondition.broadcast(); |
| 112 | |
| 113 | if (count) { |
| 114 | processEventsLocked(mEventBuffer, count); |
| 115 | } |
| 116 | |
| 117 | if (mNextTimeout != LLONG_MAX) { |
| 118 | nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); |
| 119 | if (now >= mNextTimeout) { |
| 120 | #if DEBUG_RAW_EVENTS |
| 121 | ALOGD("Timeout expired, latency=%0.3fms", (now - mNextTimeout) * 0.000001f); |
| 122 | #endif |
| 123 | mNextTimeout = LLONG_MAX; |
| 124 | timeoutExpiredLocked(now); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | if (oldGeneration != mGeneration) { |
| 129 | inputDevicesChanged = true; |
| 130 | getInputDevicesLocked(inputDevices); |
| 131 | } |
| 132 | } // release lock |
| 133 | |
| 134 | // Send out a message that the describes the changed input devices. |
| 135 | if (inputDevicesChanged) { |
| 136 | mPolicy->notifyInputDevicesChanged(inputDevices); |
| 137 | } |
| 138 | |
| 139 | // Flush queued events out to the listener. |
| 140 | // This must happen outside of the lock because the listener could potentially call |
| 141 | // back into the InputReader's methods, such as getScanCodeState, or become blocked |
| 142 | // on another thread similarly waiting to acquire the InputReader lock thereby |
| 143 | // resulting in a deadlock. This situation is actually quite plausible because the |
| 144 | // listener is actually the input dispatcher, which calls into the window manager, |
| 145 | // which occasionally calls into the input reader. |
| 146 | mQueuedListener->flush(); |
| 147 | } |
| 148 | |
| 149 | void InputReader::processEventsLocked(const RawEvent* rawEvents, size_t count) { |
| 150 | for (const RawEvent* rawEvent = rawEvents; count;) { |
| 151 | int32_t type = rawEvent->type; |
| 152 | size_t batchSize = 1; |
| 153 | if (type < EventHubInterface::FIRST_SYNTHETIC_EVENT) { |
| 154 | int32_t deviceId = rawEvent->deviceId; |
| 155 | while (batchSize < count) { |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 156 | if (rawEvent[batchSize].type >= EventHubInterface::FIRST_SYNTHETIC_EVENT || |
| 157 | rawEvent[batchSize].deviceId != deviceId) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 158 | break; |
| 159 | } |
| 160 | batchSize += 1; |
| 161 | } |
| 162 | #if DEBUG_RAW_EVENTS |
Siarhei Vishniakou | 5d83f60 | 2017-09-12 12:40:29 -0700 | [diff] [blame] | 163 | ALOGD("BatchSize: %zu Count: %zu", batchSize, count); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 164 | #endif |
| 165 | processEventsForDeviceLocked(deviceId, rawEvent, batchSize); |
| 166 | } else { |
| 167 | switch (rawEvent->type) { |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 168 | case EventHubInterface::DEVICE_ADDED: |
| 169 | addDeviceLocked(rawEvent->when, rawEvent->deviceId); |
| 170 | break; |
| 171 | case EventHubInterface::DEVICE_REMOVED: |
| 172 | removeDeviceLocked(rawEvent->when, rawEvent->deviceId); |
| 173 | break; |
| 174 | case EventHubInterface::FINISHED_DEVICE_SCAN: |
| 175 | handleConfigurationChangedLocked(rawEvent->when); |
| 176 | break; |
| 177 | default: |
| 178 | ALOG_ASSERT(false); // can't happen |
| 179 | break; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | count -= batchSize; |
| 183 | rawEvent += batchSize; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | void InputReader::addDeviceLocked(nsecs_t when, int32_t deviceId) { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 188 | if (mDevices.find(deviceId) != mDevices.end()) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 189 | ALOGW("Ignoring spurious device added event for deviceId %d.", deviceId); |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(deviceId); |
| 194 | uint32_t classes = mEventHub->getDeviceClasses(deviceId); |
| 195 | int32_t controllerNumber = mEventHub->getDeviceControllerNumber(deviceId); |
| 196 | |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 197 | std::shared_ptr<InputDevice> device = |
| 198 | createDeviceLocked(deviceId, controllerNumber, identifier, classes); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 199 | device->configure(when, &mConfig, 0); |
| 200 | device->reset(when); |
| 201 | |
| 202 | if (device->isIgnored()) { |
| 203 | ALOGI("Device added: id=%d, name='%s' (ignored non-input device)", deviceId, |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 204 | identifier.name.c_str()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 205 | } else { |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 206 | ALOGI("Device added: id=%d, name='%s', sources=0x%08x", deviceId, identifier.name.c_str(), |
| 207 | device->getSources()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 208 | } |
| 209 | |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 210 | mDevices.emplace(deviceId, device); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 211 | bumpGenerationLocked(); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 212 | |
| 213 | if (device->getClasses() & INPUT_DEVICE_CLASS_EXTERNAL_STYLUS) { |
| 214 | notifyExternalStylusPresenceChanged(); |
| 215 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | void InputReader::removeDeviceLocked(nsecs_t when, int32_t deviceId) { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 219 | auto deviceIt = mDevices.find(deviceId); |
| 220 | if (deviceIt == mDevices.end()) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 221 | ALOGW("Ignoring spurious device removed event for deviceId %d.", deviceId); |
| 222 | return; |
| 223 | } |
| 224 | |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 225 | std::shared_ptr<InputDevice> device = std::move(deviceIt->second); |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 226 | mDevices.erase(deviceIt); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 227 | bumpGenerationLocked(); |
| 228 | |
| 229 | if (device->isIgnored()) { |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 230 | ALOGI("Device removed: id=%d, name='%s' (ignored non-input device)", device->getId(), |
| 231 | device->getName().c_str()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 232 | } else { |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 233 | ALOGI("Device removed: id=%d, name='%s', sources=0x%08x", device->getId(), |
| 234 | device->getName().c_str(), device->getSources()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 237 | if (device->getClasses() & INPUT_DEVICE_CLASS_EXTERNAL_STYLUS) { |
| 238 | notifyExternalStylusPresenceChanged(); |
| 239 | } |
| 240 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 241 | device->reset(when); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 244 | std::shared_ptr<InputDevice> InputReader::createDeviceLocked( |
| 245 | int32_t deviceId, int32_t controllerNumber, const InputDeviceIdentifier& identifier, |
| 246 | uint32_t classes) { |
| 247 | std::shared_ptr<InputDevice> device = |
| 248 | std::make_shared<InputDevice>(&mContext, deviceId, bumpGenerationLocked(), |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 249 | controllerNumber, identifier, classes); |
Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 250 | device->populateMappers(); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 251 | return device; |
| 252 | } |
| 253 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 254 | void InputReader::processEventsForDeviceLocked(int32_t deviceId, const RawEvent* rawEvents, |
| 255 | size_t count) { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 256 | auto deviceIt = mDevices.find(deviceId); |
| 257 | if (deviceIt == mDevices.end()) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 258 | ALOGW("Discarding event for unknown deviceId %d.", deviceId); |
| 259 | return; |
| 260 | } |
| 261 | |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 262 | std::shared_ptr<InputDevice>& device = deviceIt->second; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 263 | if (device->isIgnored()) { |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 264 | // ALOGD("Discarding event for ignored deviceId %d.", deviceId); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 265 | return; |
| 266 | } |
| 267 | |
| 268 | device->process(rawEvents, count); |
| 269 | } |
| 270 | |
| 271 | void InputReader::timeoutExpiredLocked(nsecs_t when) { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 272 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 273 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 274 | if (!device->isIgnored()) { |
| 275 | device->timeoutExpired(when); |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | void InputReader::handleConfigurationChangedLocked(nsecs_t when) { |
| 281 | // Reset global meta state because it depends on the list of all configured devices. |
| 282 | updateGlobalMetaStateLocked(); |
| 283 | |
| 284 | // Enqueue configuration changed. |
Prabir Pradhan | 42611e0 | 2018-11-27 14:04:02 -0800 | [diff] [blame] | 285 | NotifyConfigurationChangedArgs args(mContext.getNextSequenceNum(), when); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 286 | mQueuedListener->notifyConfigurationChanged(&args); |
| 287 | } |
| 288 | |
| 289 | void InputReader::refreshConfigurationLocked(uint32_t changes) { |
| 290 | mPolicy->getReaderConfiguration(&mConfig); |
| 291 | mEventHub->setExcludedDevices(mConfig.excludedDeviceNames); |
| 292 | |
| 293 | if (changes) { |
Siarhei Vishniakou | c5ae0dc | 2019-07-10 15:51:18 -0700 | [diff] [blame] | 294 | ALOGI("Reconfiguring input devices, changes=%s", |
| 295 | InputReaderConfiguration::changesToString(changes).c_str()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 296 | nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); |
| 297 | |
| 298 | if (changes & InputReaderConfiguration::CHANGE_MUST_REOPEN) { |
| 299 | mEventHub->requestReopenDevices(); |
| 300 | } else { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 301 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 302 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 303 | device->configure(now, &mConfig, changes); |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | void InputReader::updateGlobalMetaStateLocked() { |
| 310 | mGlobalMetaState = 0; |
| 311 | |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 312 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 313 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 314 | mGlobalMetaState |= device->getMetaState(); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | int32_t InputReader::getGlobalMetaStateLocked() { |
| 319 | return mGlobalMetaState; |
| 320 | } |
| 321 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 322 | void InputReader::notifyExternalStylusPresenceChanged() { |
| 323 | refreshConfigurationLocked(InputReaderConfiguration::CHANGE_EXTERNAL_STYLUS_PRESENCE); |
| 324 | } |
| 325 | |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 326 | void InputReader::getExternalStylusDevicesLocked(std::vector<InputDeviceInfo>& outDevices) { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 327 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 328 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 329 | if (device->getClasses() & INPUT_DEVICE_CLASS_EXTERNAL_STYLUS && !device->isIgnored()) { |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 330 | InputDeviceInfo info; |
| 331 | device->getDeviceInfo(&info); |
| 332 | outDevices.push_back(info); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | void InputReader::dispatchExternalStylusState(const StylusState& state) { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 338 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 339 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 340 | device->updateExternalStylusState(state); |
| 341 | } |
| 342 | } |
| 343 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 344 | void InputReader::disableVirtualKeysUntilLocked(nsecs_t time) { |
| 345 | mDisableVirtualKeysTimeout = time; |
| 346 | } |
| 347 | |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 348 | bool InputReader::shouldDropVirtualKeyLocked(nsecs_t now, int32_t keyCode, int32_t scanCode) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 349 | if (now < mDisableVirtualKeysTimeout) { |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 350 | ALOGI("Dropping virtual key from device because virtual keys are " |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 351 | "temporarily disabled for the next %0.3fms. keyCode=%d, scanCode=%d", |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 352 | (mDisableVirtualKeysTimeout - now) * 0.000001, keyCode, scanCode); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 353 | return true; |
| 354 | } else { |
| 355 | return false; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | void InputReader::fadePointerLocked() { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 360 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 361 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 362 | device->fadePointer(); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | void InputReader::requestTimeoutAtTimeLocked(nsecs_t when) { |
| 367 | if (when < mNextTimeout) { |
| 368 | mNextTimeout = when; |
| 369 | mEventHub->wake(); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | int32_t InputReader::bumpGenerationLocked() { |
| 374 | return ++mGeneration; |
| 375 | } |
| 376 | |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 377 | void InputReader::getInputDevices(std::vector<InputDeviceInfo>& outInputDevices) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 378 | AutoMutex _l(mLock); |
| 379 | getInputDevicesLocked(outInputDevices); |
| 380 | } |
| 381 | |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 382 | void InputReader::getInputDevicesLocked(std::vector<InputDeviceInfo>& outInputDevices) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 383 | outInputDevices.clear(); |
| 384 | |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 385 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 386 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 387 | if (!device->isIgnored()) { |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 388 | InputDeviceInfo info; |
| 389 | device->getDeviceInfo(&info); |
| 390 | outInputDevices.push_back(info); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | } |
| 394 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 395 | int32_t InputReader::getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 396 | AutoMutex _l(mLock); |
| 397 | |
| 398 | return getStateLocked(deviceId, sourceMask, keyCode, &InputDevice::getKeyCodeState); |
| 399 | } |
| 400 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 401 | int32_t InputReader::getScanCodeState(int32_t deviceId, uint32_t sourceMask, int32_t scanCode) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 402 | AutoMutex _l(mLock); |
| 403 | |
| 404 | return getStateLocked(deviceId, sourceMask, scanCode, &InputDevice::getScanCodeState); |
| 405 | } |
| 406 | |
| 407 | int32_t InputReader::getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t switchCode) { |
| 408 | AutoMutex _l(mLock); |
| 409 | |
| 410 | return getStateLocked(deviceId, sourceMask, switchCode, &InputDevice::getSwitchState); |
| 411 | } |
| 412 | |
| 413 | 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] | 414 | GetStateFunc getStateFunc) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 415 | int32_t result = AKEY_STATE_UNKNOWN; |
| 416 | if (deviceId >= 0) { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 417 | auto deviceIt = mDevices.find(deviceId); |
| 418 | if (deviceIt != mDevices.end()) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 419 | std::shared_ptr<InputDevice>& device = deviceIt->second; |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 420 | if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 421 | result = (device.get()->*getStateFunc)(sourceMask, code); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | } else { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 425 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 426 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 427 | if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 428 | // If any device reports AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL, return that |
| 429 | // 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^] | 430 | int32_t currentResult = (device.get()->*getStateFunc)(sourceMask, code); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 431 | if (currentResult >= AKEY_STATE_DOWN) { |
| 432 | return currentResult; |
| 433 | } else if (currentResult == AKEY_STATE_UP) { |
| 434 | result = currentResult; |
| 435 | } |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | return result; |
| 440 | } |
| 441 | |
Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 442 | void InputReader::toggleCapsLockState(int32_t deviceId) { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 443 | auto deviceIt = mDevices.find(deviceId); |
| 444 | if (deviceIt == mDevices.end()) { |
Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 445 | ALOGW("Ignoring toggleCapsLock for unknown deviceId %" PRId32 ".", deviceId); |
| 446 | return; |
| 447 | } |
| 448 | |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 449 | std::shared_ptr<InputDevice>& device = deviceIt->second; |
Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 450 | if (device->isIgnored()) { |
| 451 | return; |
| 452 | } |
| 453 | |
| 454 | device->updateMetaState(AKEYCODE_CAPS_LOCK); |
| 455 | } |
| 456 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 457 | bool InputReader::hasKeys(int32_t deviceId, uint32_t sourceMask, size_t numCodes, |
| 458 | const int32_t* keyCodes, uint8_t* outFlags) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 459 | AutoMutex _l(mLock); |
| 460 | |
| 461 | memset(outFlags, 0, numCodes); |
| 462 | return markSupportedKeyCodesLocked(deviceId, sourceMask, numCodes, keyCodes, outFlags); |
| 463 | } |
| 464 | |
| 465 | bool InputReader::markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask, |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 466 | size_t numCodes, const int32_t* keyCodes, |
| 467 | uint8_t* outFlags) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 468 | bool result = false; |
| 469 | if (deviceId >= 0) { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 470 | auto deviceIt = mDevices.find(deviceId); |
| 471 | if (deviceIt != mDevices.end()) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 472 | std::shared_ptr<InputDevice>& device = deviceIt->second; |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 473 | if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
| 474 | result = device->markSupportedKeyCodes(sourceMask, numCodes, keyCodes, outFlags); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | } else { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 478 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 479 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 480 | if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
| 481 | result |= device->markSupportedKeyCodes(sourceMask, numCodes, keyCodes, outFlags); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 482 | } |
| 483 | } |
| 484 | } |
| 485 | return result; |
| 486 | } |
| 487 | |
| 488 | void InputReader::requestRefreshConfiguration(uint32_t changes) { |
| 489 | AutoMutex _l(mLock); |
| 490 | |
| 491 | if (changes) { |
| 492 | bool needWake = !mConfigurationChangesToRefresh; |
| 493 | mConfigurationChangesToRefresh |= changes; |
| 494 | |
| 495 | if (needWake) { |
| 496 | mEventHub->wake(); |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | void InputReader::vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize, |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 502 | ssize_t repeat, int32_t token) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 503 | AutoMutex _l(mLock); |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 504 | auto deviceIt = mDevices.find(deviceId); |
| 505 | if (deviceIt != mDevices.end()) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 506 | std::shared_ptr<InputDevice>& device = deviceIt->second; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 507 | device->vibrate(pattern, patternSize, repeat, token); |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | void InputReader::cancelVibrate(int32_t deviceId, int32_t token) { |
| 512 | AutoMutex _l(mLock); |
| 513 | |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 514 | auto deviceIt = mDevices.find(deviceId); |
| 515 | if (deviceIt != mDevices.end()) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 516 | std::shared_ptr<InputDevice>& device = deviceIt->second; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 517 | device->cancelVibrate(token); |
| 518 | } |
| 519 | } |
| 520 | |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 521 | bool InputReader::isInputDeviceEnabled(int32_t deviceId) { |
| 522 | AutoMutex _l(mLock); |
| 523 | |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 524 | auto deviceIt = mDevices.find(deviceId); |
| 525 | if (deviceIt != mDevices.end()) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 526 | std::shared_ptr<InputDevice>& device = deviceIt->second; |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 527 | return device->isEnabled(); |
| 528 | } |
| 529 | ALOGW("Ignoring invalid device id %" PRId32 ".", deviceId); |
| 530 | return false; |
| 531 | } |
| 532 | |
Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 533 | bool InputReader::canDispatchToDisplay(int32_t deviceId, int32_t displayId) { |
| 534 | AutoMutex _l(mLock); |
| 535 | |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 536 | auto deviceIt = mDevices.find(deviceId); |
| 537 | if (deviceIt == mDevices.end()) { |
Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 538 | ALOGW("Ignoring invalid device id %" PRId32 ".", deviceId); |
| 539 | return false; |
| 540 | } |
| 541 | |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 542 | std::shared_ptr<InputDevice>& device = deviceIt->second; |
Arthur Hung | 2c9a334 | 2019-07-23 14:18:59 +0800 | [diff] [blame] | 543 | if (!device->isEnabled()) { |
| 544 | ALOGW("Ignoring disabled device %s", device->getName().c_str()); |
| 545 | return false; |
| 546 | } |
| 547 | |
| 548 | std::optional<int32_t> associatedDisplayId = device->getAssociatedDisplayId(); |
Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 549 | // No associated display. By default, can dispatch to all displays. |
| 550 | if (!associatedDisplayId) { |
| 551 | return true; |
| 552 | } |
| 553 | |
| 554 | if (*associatedDisplayId == ADISPLAY_ID_NONE) { |
Arthur Hung | 2c9a334 | 2019-07-23 14:18:59 +0800 | [diff] [blame] | 555 | 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] | 556 | return true; |
| 557 | } |
| 558 | |
| 559 | return *associatedDisplayId == displayId; |
| 560 | } |
| 561 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 562 | void InputReader::dump(std::string& dump) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 563 | AutoMutex _l(mLock); |
| 564 | |
| 565 | mEventHub->dump(dump); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 566 | dump += "\n"; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 567 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 568 | dump += "Input Reader State:\n"; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 569 | |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 570 | for (const auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame^] | 571 | const std::shared_ptr<InputDevice>& device = devicePair.second; |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 572 | device->dump(dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 573 | } |
| 574 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 575 | dump += INDENT "Configuration:\n"; |
| 576 | dump += INDENT2 "ExcludedDeviceNames: ["; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 577 | for (size_t i = 0; i < mConfig.excludedDeviceNames.size(); i++) { |
| 578 | if (i != 0) { |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 579 | dump += ", "; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 580 | } |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 581 | dump += mConfig.excludedDeviceNames[i]; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 582 | } |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 583 | dump += "]\n"; |
| 584 | dump += StringPrintf(INDENT2 "VirtualKeyQuietTime: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 585 | mConfig.virtualKeyQuietTime * 0.000001f); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 586 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 587 | dump += StringPrintf(INDENT2 "PointerVelocityControlParameters: " |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 588 | "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, " |
| 589 | "acceleration=%0.3f\n", |
| 590 | mConfig.pointerVelocityControlParameters.scale, |
| 591 | mConfig.pointerVelocityControlParameters.lowThreshold, |
| 592 | mConfig.pointerVelocityControlParameters.highThreshold, |
| 593 | mConfig.pointerVelocityControlParameters.acceleration); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 594 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 595 | dump += StringPrintf(INDENT2 "WheelVelocityControlParameters: " |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 596 | "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, " |
| 597 | "acceleration=%0.3f\n", |
| 598 | mConfig.wheelVelocityControlParameters.scale, |
| 599 | mConfig.wheelVelocityControlParameters.lowThreshold, |
| 600 | mConfig.wheelVelocityControlParameters.highThreshold, |
| 601 | mConfig.wheelVelocityControlParameters.acceleration); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 602 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 603 | dump += StringPrintf(INDENT2 "PointerGesture:\n"); |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 604 | dump += StringPrintf(INDENT3 "Enabled: %s\n", toString(mConfig.pointerGesturesEnabled)); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 605 | dump += StringPrintf(INDENT3 "QuietInterval: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 606 | mConfig.pointerGestureQuietInterval * 0.000001f); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 607 | dump += StringPrintf(INDENT3 "DragMinSwitchSpeed: %0.1fpx/s\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 608 | mConfig.pointerGestureDragMinSwitchSpeed); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 609 | dump += StringPrintf(INDENT3 "TapInterval: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 610 | mConfig.pointerGestureTapInterval * 0.000001f); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 611 | dump += StringPrintf(INDENT3 "TapDragInterval: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 612 | mConfig.pointerGestureTapDragInterval * 0.000001f); |
| 613 | dump += StringPrintf(INDENT3 "TapSlop: %0.1fpx\n", mConfig.pointerGestureTapSlop); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 614 | dump += StringPrintf(INDENT3 "MultitouchSettleInterval: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 615 | mConfig.pointerGestureMultitouchSettleInterval * 0.000001f); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 616 | dump += StringPrintf(INDENT3 "MultitouchMinDistance: %0.1fpx\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 617 | mConfig.pointerGestureMultitouchMinDistance); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 618 | dump += StringPrintf(INDENT3 "SwipeTransitionAngleCosine: %0.1f\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 619 | mConfig.pointerGestureSwipeTransitionAngleCosine); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 620 | dump += StringPrintf(INDENT3 "SwipeMaxWidthRatio: %0.1f\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 621 | mConfig.pointerGestureSwipeMaxWidthRatio); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 622 | dump += StringPrintf(INDENT3 "MovementSpeedRatio: %0.1f\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 623 | mConfig.pointerGestureMovementSpeedRatio); |
| 624 | dump += StringPrintf(INDENT3 "ZoomSpeedRatio: %0.1f\n", mConfig.pointerGestureZoomSpeedRatio); |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 625 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 626 | dump += INDENT3 "Viewports:\n"; |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 627 | mConfig.dump(dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | void InputReader::monitor() { |
| 631 | // Acquire and release the lock to ensure that the reader has not deadlocked. |
| 632 | mLock.lock(); |
| 633 | mEventHub->wake(); |
| 634 | mReaderIsAliveCondition.wait(mLock); |
| 635 | mLock.unlock(); |
| 636 | |
| 637 | // Check the EventHub |
| 638 | mEventHub->monitor(); |
| 639 | } |
| 640 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 641 | // --- InputReader::ContextImpl --- |
| 642 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 643 | InputReader::ContextImpl::ContextImpl(InputReader* reader) : mReader(reader) {} |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 644 | |
| 645 | void InputReader::ContextImpl::updateGlobalMetaState() { |
| 646 | // lock is already held by the input loop |
| 647 | mReader->updateGlobalMetaStateLocked(); |
| 648 | } |
| 649 | |
| 650 | int32_t InputReader::ContextImpl::getGlobalMetaState() { |
| 651 | // lock is already held by the input loop |
| 652 | return mReader->getGlobalMetaStateLocked(); |
| 653 | } |
| 654 | |
| 655 | void InputReader::ContextImpl::disableVirtualKeysUntil(nsecs_t time) { |
| 656 | // lock is already held by the input loop |
| 657 | mReader->disableVirtualKeysUntilLocked(time); |
| 658 | } |
| 659 | |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 660 | bool InputReader::ContextImpl::shouldDropVirtualKey(nsecs_t now, int32_t keyCode, |
| 661 | int32_t scanCode) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 662 | // lock is already held by the input loop |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 663 | return mReader->shouldDropVirtualKeyLocked(now, keyCode, scanCode); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | void InputReader::ContextImpl::fadePointer() { |
| 667 | // lock is already held by the input loop |
| 668 | mReader->fadePointerLocked(); |
| 669 | } |
| 670 | |
| 671 | void InputReader::ContextImpl::requestTimeoutAtTime(nsecs_t when) { |
| 672 | // lock is already held by the input loop |
| 673 | mReader->requestTimeoutAtTimeLocked(when); |
| 674 | } |
| 675 | |
| 676 | int32_t InputReader::ContextImpl::bumpGeneration() { |
| 677 | // lock is already held by the input loop |
| 678 | return mReader->bumpGenerationLocked(); |
| 679 | } |
| 680 | |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 681 | void InputReader::ContextImpl::getExternalStylusDevices(std::vector<InputDeviceInfo>& outDevices) { |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 682 | // lock is already held by whatever called refreshConfigurationLocked |
| 683 | mReader->getExternalStylusDevicesLocked(outDevices); |
| 684 | } |
| 685 | |
| 686 | void InputReader::ContextImpl::dispatchExternalStylusState(const StylusState& state) { |
| 687 | mReader->dispatchExternalStylusState(state); |
| 688 | } |
| 689 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 690 | InputReaderPolicyInterface* InputReader::ContextImpl::getPolicy() { |
| 691 | return mReader->mPolicy.get(); |
| 692 | } |
| 693 | |
| 694 | InputListenerInterface* InputReader::ContextImpl::getListener() { |
| 695 | return mReader->mQueuedListener.get(); |
| 696 | } |
| 697 | |
| 698 | EventHubInterface* InputReader::ContextImpl::getEventHub() { |
| 699 | return mReader->mEventHub.get(); |
| 700 | } |
| 701 | |
Prabir Pradhan | 42611e0 | 2018-11-27 14:04:02 -0800 | [diff] [blame] | 702 | uint32_t InputReader::ContextImpl::getNextSequenceNum() { |
| 703 | return (mReader->mNextSequenceNum)++; |
| 704 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 705 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 706 | } // namespace android |