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