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