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 | ba266f2 | 2019-09-03 17:11:27 -0700 | [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 | ba266f2 | 2019-09-03 17:11:27 -0700 | [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 | ba266f2 | 2019-09-03 17:11:27 -0700 | [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 | ba266f2 | 2019-09-03 17:11:27 -0700 | [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() { |
| 97 | for (size_t i = 0; i < mDevices.size(); i++) { |
| 98 | delete mDevices.valueAt(i); |
| 99 | } |
| 100 | } |
| 101 | |
Prabir Pradhan | ba266f2 | 2019-09-03 17:11:27 -0700 | [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) { |
| 227 | ssize_t deviceIndex = mDevices.indexOfKey(deviceId); |
| 228 | if (deviceIndex >= 0) { |
| 229 | ALOGW("Ignoring spurious device added event for deviceId %d.", deviceId); |
| 230 | return; |
| 231 | } |
| 232 | |
| 233 | InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(deviceId); |
| 234 | uint32_t classes = mEventHub->getDeviceClasses(deviceId); |
| 235 | int32_t controllerNumber = mEventHub->getDeviceControllerNumber(deviceId); |
| 236 | |
| 237 | InputDevice* device = createDeviceLocked(deviceId, controllerNumber, identifier, classes); |
| 238 | device->configure(when, &mConfig, 0); |
| 239 | device->reset(when); |
| 240 | |
| 241 | if (device->isIgnored()) { |
| 242 | ALOGI("Device added: id=%d, name='%s' (ignored non-input device)", deviceId, |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 243 | identifier.name.c_str()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 244 | } else { |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 245 | ALOGI("Device added: id=%d, name='%s', sources=0x%08x", deviceId, identifier.name.c_str(), |
| 246 | device->getSources()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | mDevices.add(deviceId, device); |
| 250 | bumpGenerationLocked(); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 251 | |
| 252 | if (device->getClasses() & INPUT_DEVICE_CLASS_EXTERNAL_STYLUS) { |
| 253 | notifyExternalStylusPresenceChanged(); |
| 254 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | void InputReader::removeDeviceLocked(nsecs_t when, int32_t deviceId) { |
Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 258 | InputDevice* device = nullptr; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 259 | ssize_t deviceIndex = mDevices.indexOfKey(deviceId); |
| 260 | if (deviceIndex < 0) { |
| 261 | ALOGW("Ignoring spurious device removed event for deviceId %d.", deviceId); |
| 262 | return; |
| 263 | } |
| 264 | |
| 265 | device = mDevices.valueAt(deviceIndex); |
| 266 | mDevices.removeItemsAt(deviceIndex, 1); |
| 267 | bumpGenerationLocked(); |
| 268 | |
| 269 | if (device->isIgnored()) { |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 270 | ALOGI("Device removed: id=%d, name='%s' (ignored non-input device)", device->getId(), |
| 271 | device->getName().c_str()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 272 | } else { |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 273 | ALOGI("Device removed: id=%d, name='%s', sources=0x%08x", device->getId(), |
| 274 | device->getName().c_str(), device->getSources()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 275 | } |
| 276 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 277 | if (device->getClasses() & INPUT_DEVICE_CLASS_EXTERNAL_STYLUS) { |
| 278 | notifyExternalStylusPresenceChanged(); |
| 279 | } |
| 280 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 281 | device->reset(when); |
| 282 | delete device; |
| 283 | } |
| 284 | |
| 285 | InputDevice* InputReader::createDeviceLocked(int32_t deviceId, int32_t controllerNumber, |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 286 | const InputDeviceIdentifier& identifier, |
| 287 | uint32_t classes) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 288 | InputDevice* device = new InputDevice(&mContext, deviceId, bumpGenerationLocked(), |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 289 | controllerNumber, identifier, classes); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 290 | |
| 291 | // External devices. |
| 292 | if (classes & INPUT_DEVICE_CLASS_EXTERNAL) { |
| 293 | device->setExternal(true); |
| 294 | } |
| 295 | |
Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 296 | // Devices with mics. |
| 297 | if (classes & INPUT_DEVICE_CLASS_MIC) { |
| 298 | device->setMic(true); |
| 299 | } |
| 300 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 301 | // Switch-like devices. |
| 302 | if (classes & INPUT_DEVICE_CLASS_SWITCH) { |
| 303 | device->addMapper(new SwitchInputMapper(device)); |
| 304 | } |
| 305 | |
Prashant Malani | 1941ff5 | 2015-08-11 18:29:28 -0700 | [diff] [blame] | 306 | // Scroll wheel-like devices. |
| 307 | if (classes & INPUT_DEVICE_CLASS_ROTARY_ENCODER) { |
| 308 | device->addMapper(new RotaryEncoderInputMapper(device)); |
| 309 | } |
| 310 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 311 | // Vibrator-like devices. |
| 312 | if (classes & INPUT_DEVICE_CLASS_VIBRATOR) { |
| 313 | device->addMapper(new VibratorInputMapper(device)); |
| 314 | } |
| 315 | |
| 316 | // Keyboard-like devices. |
| 317 | uint32_t keyboardSource = 0; |
| 318 | int32_t keyboardType = AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC; |
| 319 | if (classes & INPUT_DEVICE_CLASS_KEYBOARD) { |
| 320 | keyboardSource |= AINPUT_SOURCE_KEYBOARD; |
| 321 | } |
| 322 | if (classes & INPUT_DEVICE_CLASS_ALPHAKEY) { |
| 323 | keyboardType = AINPUT_KEYBOARD_TYPE_ALPHABETIC; |
| 324 | } |
| 325 | if (classes & INPUT_DEVICE_CLASS_DPAD) { |
| 326 | keyboardSource |= AINPUT_SOURCE_DPAD; |
| 327 | } |
| 328 | if (classes & INPUT_DEVICE_CLASS_GAMEPAD) { |
| 329 | keyboardSource |= AINPUT_SOURCE_GAMEPAD; |
| 330 | } |
| 331 | |
| 332 | if (keyboardSource != 0) { |
| 333 | device->addMapper(new KeyboardInputMapper(device, keyboardSource, keyboardType)); |
| 334 | } |
| 335 | |
| 336 | // Cursor-like devices. |
| 337 | if (classes & INPUT_DEVICE_CLASS_CURSOR) { |
| 338 | device->addMapper(new CursorInputMapper(device)); |
| 339 | } |
| 340 | |
| 341 | // Touchscreens and touchpad devices. |
| 342 | if (classes & INPUT_DEVICE_CLASS_TOUCH_MT) { |
| 343 | device->addMapper(new MultiTouchInputMapper(device)); |
| 344 | } else if (classes & INPUT_DEVICE_CLASS_TOUCH) { |
| 345 | device->addMapper(new SingleTouchInputMapper(device)); |
| 346 | } |
| 347 | |
| 348 | // Joystick-like devices. |
| 349 | if (classes & INPUT_DEVICE_CLASS_JOYSTICK) { |
| 350 | device->addMapper(new JoystickInputMapper(device)); |
| 351 | } |
| 352 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 353 | // External stylus-like devices. |
| 354 | if (classes & INPUT_DEVICE_CLASS_EXTERNAL_STYLUS) { |
| 355 | device->addMapper(new ExternalStylusInputMapper(device)); |
| 356 | } |
| 357 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 358 | return device; |
| 359 | } |
| 360 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 361 | void InputReader::processEventsForDeviceLocked(int32_t deviceId, const RawEvent* rawEvents, |
| 362 | size_t count) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 363 | ssize_t deviceIndex = mDevices.indexOfKey(deviceId); |
| 364 | if (deviceIndex < 0) { |
| 365 | ALOGW("Discarding event for unknown deviceId %d.", deviceId); |
| 366 | return; |
| 367 | } |
| 368 | |
| 369 | InputDevice* device = mDevices.valueAt(deviceIndex); |
| 370 | if (device->isIgnored()) { |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 371 | // ALOGD("Discarding event for ignored deviceId %d.", deviceId); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 372 | return; |
| 373 | } |
| 374 | |
| 375 | device->process(rawEvents, count); |
| 376 | } |
| 377 | |
| 378 | void InputReader::timeoutExpiredLocked(nsecs_t when) { |
| 379 | for (size_t i = 0; i < mDevices.size(); i++) { |
| 380 | InputDevice* device = mDevices.valueAt(i); |
| 381 | if (!device->isIgnored()) { |
| 382 | device->timeoutExpired(when); |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | void InputReader::handleConfigurationChangedLocked(nsecs_t when) { |
| 388 | // Reset global meta state because it depends on the list of all configured devices. |
| 389 | updateGlobalMetaStateLocked(); |
| 390 | |
| 391 | // Enqueue configuration changed. |
Prabir Pradhan | 42611e0 | 2018-11-27 14:04:02 -0800 | [diff] [blame] | 392 | NotifyConfigurationChangedArgs args(mContext.getNextSequenceNum(), when); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 393 | mQueuedListener->notifyConfigurationChanged(&args); |
| 394 | } |
| 395 | |
| 396 | void InputReader::refreshConfigurationLocked(uint32_t changes) { |
| 397 | mPolicy->getReaderConfiguration(&mConfig); |
| 398 | mEventHub->setExcludedDevices(mConfig.excludedDeviceNames); |
| 399 | |
| 400 | if (changes) { |
Siarhei Vishniakou | c5ae0dc | 2019-07-10 15:51:18 -0700 | [diff] [blame] | 401 | ALOGI("Reconfiguring input devices, changes=%s", |
| 402 | InputReaderConfiguration::changesToString(changes).c_str()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 403 | nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); |
| 404 | |
| 405 | if (changes & InputReaderConfiguration::CHANGE_MUST_REOPEN) { |
| 406 | mEventHub->requestReopenDevices(); |
| 407 | } else { |
| 408 | for (size_t i = 0; i < mDevices.size(); i++) { |
| 409 | InputDevice* device = mDevices.valueAt(i); |
| 410 | device->configure(now, &mConfig, changes); |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | void InputReader::updateGlobalMetaStateLocked() { |
| 417 | mGlobalMetaState = 0; |
| 418 | |
| 419 | for (size_t i = 0; i < mDevices.size(); i++) { |
| 420 | InputDevice* device = mDevices.valueAt(i); |
| 421 | mGlobalMetaState |= device->getMetaState(); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | int32_t InputReader::getGlobalMetaStateLocked() { |
| 426 | return mGlobalMetaState; |
| 427 | } |
| 428 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 429 | void InputReader::notifyExternalStylusPresenceChanged() { |
| 430 | refreshConfigurationLocked(InputReaderConfiguration::CHANGE_EXTERNAL_STYLUS_PRESENCE); |
| 431 | } |
| 432 | |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 433 | void InputReader::getExternalStylusDevicesLocked(std::vector<InputDeviceInfo>& outDevices) { |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 434 | for (size_t i = 0; i < mDevices.size(); i++) { |
| 435 | InputDevice* device = mDevices.valueAt(i); |
| 436 | if (device->getClasses() & INPUT_DEVICE_CLASS_EXTERNAL_STYLUS && !device->isIgnored()) { |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 437 | InputDeviceInfo info; |
| 438 | device->getDeviceInfo(&info); |
| 439 | outDevices.push_back(info); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | void InputReader::dispatchExternalStylusState(const StylusState& state) { |
| 445 | for (size_t i = 0; i < mDevices.size(); i++) { |
| 446 | InputDevice* device = mDevices.valueAt(i); |
| 447 | device->updateExternalStylusState(state); |
| 448 | } |
| 449 | } |
| 450 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 451 | void InputReader::disableVirtualKeysUntilLocked(nsecs_t time) { |
| 452 | mDisableVirtualKeysTimeout = time; |
| 453 | } |
| 454 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 455 | bool InputReader::shouldDropVirtualKeyLocked(nsecs_t now, InputDevice* device, int32_t keyCode, |
| 456 | int32_t scanCode) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 457 | if (now < mDisableVirtualKeysTimeout) { |
| 458 | ALOGI("Dropping virtual key from device %s because virtual keys are " |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 459 | "temporarily disabled for the next %0.3fms. keyCode=%d, scanCode=%d", |
| 460 | device->getName().c_str(), (mDisableVirtualKeysTimeout - now) * 0.000001, keyCode, |
| 461 | scanCode); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 462 | return true; |
| 463 | } else { |
| 464 | return false; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | void InputReader::fadePointerLocked() { |
| 469 | for (size_t i = 0; i < mDevices.size(); i++) { |
| 470 | InputDevice* device = mDevices.valueAt(i); |
| 471 | device->fadePointer(); |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | void InputReader::requestTimeoutAtTimeLocked(nsecs_t when) { |
| 476 | if (when < mNextTimeout) { |
| 477 | mNextTimeout = when; |
| 478 | mEventHub->wake(); |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | int32_t InputReader::bumpGenerationLocked() { |
| 483 | return ++mGeneration; |
| 484 | } |
| 485 | |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 486 | void InputReader::getInputDevices(std::vector<InputDeviceInfo>& outInputDevices) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 487 | AutoMutex _l(mLock); |
| 488 | getInputDevicesLocked(outInputDevices); |
| 489 | } |
| 490 | |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 491 | void InputReader::getInputDevicesLocked(std::vector<InputDeviceInfo>& outInputDevices) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 492 | outInputDevices.clear(); |
| 493 | |
| 494 | size_t numDevices = mDevices.size(); |
| 495 | for (size_t i = 0; i < numDevices; i++) { |
| 496 | InputDevice* device = mDevices.valueAt(i); |
| 497 | if (!device->isIgnored()) { |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 498 | InputDeviceInfo info; |
| 499 | device->getDeviceInfo(&info); |
| 500 | outInputDevices.push_back(info); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | } |
| 504 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 505 | 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] | 506 | AutoMutex _l(mLock); |
| 507 | |
| 508 | return getStateLocked(deviceId, sourceMask, keyCode, &InputDevice::getKeyCodeState); |
| 509 | } |
| 510 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 511 | 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] | 512 | AutoMutex _l(mLock); |
| 513 | |
| 514 | return getStateLocked(deviceId, sourceMask, scanCode, &InputDevice::getScanCodeState); |
| 515 | } |
| 516 | |
| 517 | int32_t InputReader::getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t switchCode) { |
| 518 | AutoMutex _l(mLock); |
| 519 | |
| 520 | return getStateLocked(deviceId, sourceMask, switchCode, &InputDevice::getSwitchState); |
| 521 | } |
| 522 | |
| 523 | 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] | 524 | GetStateFunc getStateFunc) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 525 | int32_t result = AKEY_STATE_UNKNOWN; |
| 526 | if (deviceId >= 0) { |
| 527 | ssize_t deviceIndex = mDevices.indexOfKey(deviceId); |
| 528 | if (deviceIndex >= 0) { |
| 529 | InputDevice* device = mDevices.valueAt(deviceIndex); |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 530 | if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 531 | result = (device->*getStateFunc)(sourceMask, code); |
| 532 | } |
| 533 | } |
| 534 | } else { |
| 535 | size_t numDevices = mDevices.size(); |
| 536 | for (size_t i = 0; i < numDevices; i++) { |
| 537 | InputDevice* device = mDevices.valueAt(i); |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 538 | if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 539 | // If any device reports AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL, return that |
| 540 | // value. Otherwise, return AKEY_STATE_UP as long as one device reports it. |
| 541 | int32_t currentResult = (device->*getStateFunc)(sourceMask, code); |
| 542 | if (currentResult >= AKEY_STATE_DOWN) { |
| 543 | return currentResult; |
| 544 | } else if (currentResult == AKEY_STATE_UP) { |
| 545 | result = currentResult; |
| 546 | } |
| 547 | } |
| 548 | } |
| 549 | } |
| 550 | return result; |
| 551 | } |
| 552 | |
Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 553 | void InputReader::toggleCapsLockState(int32_t deviceId) { |
| 554 | ssize_t deviceIndex = mDevices.indexOfKey(deviceId); |
| 555 | if (deviceIndex < 0) { |
| 556 | ALOGW("Ignoring toggleCapsLock for unknown deviceId %" PRId32 ".", deviceId); |
| 557 | return; |
| 558 | } |
| 559 | |
| 560 | InputDevice* device = mDevices.valueAt(deviceIndex); |
| 561 | if (device->isIgnored()) { |
| 562 | return; |
| 563 | } |
| 564 | |
| 565 | device->updateMetaState(AKEYCODE_CAPS_LOCK); |
| 566 | } |
| 567 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 568 | bool InputReader::hasKeys(int32_t deviceId, uint32_t sourceMask, size_t numCodes, |
| 569 | const int32_t* keyCodes, uint8_t* outFlags) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 570 | AutoMutex _l(mLock); |
| 571 | |
| 572 | memset(outFlags, 0, numCodes); |
| 573 | return markSupportedKeyCodesLocked(deviceId, sourceMask, numCodes, keyCodes, outFlags); |
| 574 | } |
| 575 | |
| 576 | bool InputReader::markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask, |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 577 | size_t numCodes, const int32_t* keyCodes, |
| 578 | uint8_t* outFlags) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 579 | bool result = false; |
| 580 | if (deviceId >= 0) { |
| 581 | ssize_t deviceIndex = mDevices.indexOfKey(deviceId); |
| 582 | if (deviceIndex >= 0) { |
| 583 | InputDevice* device = mDevices.valueAt(deviceIndex); |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 584 | if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
| 585 | result = device->markSupportedKeyCodes(sourceMask, numCodes, keyCodes, outFlags); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | } else { |
| 589 | size_t numDevices = mDevices.size(); |
| 590 | for (size_t i = 0; i < numDevices; i++) { |
| 591 | InputDevice* device = mDevices.valueAt(i); |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 592 | if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
| 593 | result |= device->markSupportedKeyCodes(sourceMask, numCodes, keyCodes, outFlags); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | } |
| 597 | return result; |
| 598 | } |
| 599 | |
| 600 | void InputReader::requestRefreshConfiguration(uint32_t changes) { |
| 601 | AutoMutex _l(mLock); |
| 602 | |
| 603 | if (changes) { |
| 604 | bool needWake = !mConfigurationChangesToRefresh; |
| 605 | mConfigurationChangesToRefresh |= changes; |
| 606 | |
| 607 | if (needWake) { |
| 608 | mEventHub->wake(); |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | 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] | 614 | ssize_t repeat, int32_t token) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 615 | AutoMutex _l(mLock); |
| 616 | |
| 617 | ssize_t deviceIndex = mDevices.indexOfKey(deviceId); |
| 618 | if (deviceIndex >= 0) { |
| 619 | InputDevice* device = mDevices.valueAt(deviceIndex); |
| 620 | device->vibrate(pattern, patternSize, repeat, token); |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | void InputReader::cancelVibrate(int32_t deviceId, int32_t token) { |
| 625 | AutoMutex _l(mLock); |
| 626 | |
| 627 | ssize_t deviceIndex = mDevices.indexOfKey(deviceId); |
| 628 | if (deviceIndex >= 0) { |
| 629 | InputDevice* device = mDevices.valueAt(deviceIndex); |
| 630 | device->cancelVibrate(token); |
| 631 | } |
| 632 | } |
| 633 | |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 634 | bool InputReader::isInputDeviceEnabled(int32_t deviceId) { |
| 635 | AutoMutex _l(mLock); |
| 636 | |
| 637 | ssize_t deviceIndex = mDevices.indexOfKey(deviceId); |
| 638 | if (deviceIndex >= 0) { |
| 639 | InputDevice* device = mDevices.valueAt(deviceIndex); |
| 640 | return device->isEnabled(); |
| 641 | } |
| 642 | ALOGW("Ignoring invalid device id %" PRId32 ".", deviceId); |
| 643 | return false; |
| 644 | } |
| 645 | |
Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 646 | bool InputReader::canDispatchToDisplay(int32_t deviceId, int32_t displayId) { |
| 647 | AutoMutex _l(mLock); |
| 648 | |
| 649 | ssize_t deviceIndex = mDevices.indexOfKey(deviceId); |
| 650 | if (deviceIndex < 0) { |
| 651 | ALOGW("Ignoring invalid device id %" PRId32 ".", deviceId); |
| 652 | return false; |
| 653 | } |
| 654 | |
| 655 | InputDevice* device = mDevices.valueAt(deviceIndex); |
Arthur Hung | 2c9a334 | 2019-07-23 14:18:59 +0800 | [diff] [blame] | 656 | if (!device->isEnabled()) { |
| 657 | ALOGW("Ignoring disabled device %s", device->getName().c_str()); |
| 658 | return false; |
| 659 | } |
| 660 | |
| 661 | std::optional<int32_t> associatedDisplayId = device->getAssociatedDisplayId(); |
Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 662 | // No associated display. By default, can dispatch to all displays. |
| 663 | if (!associatedDisplayId) { |
| 664 | return true; |
| 665 | } |
| 666 | |
| 667 | if (*associatedDisplayId == ADISPLAY_ID_NONE) { |
Arthur Hung | 2c9a334 | 2019-07-23 14:18:59 +0800 | [diff] [blame] | 668 | 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] | 669 | return true; |
| 670 | } |
| 671 | |
| 672 | return *associatedDisplayId == displayId; |
| 673 | } |
| 674 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 675 | void InputReader::dump(std::string& dump) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 676 | AutoMutex _l(mLock); |
| 677 | |
| 678 | mEventHub->dump(dump); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 679 | dump += "\n"; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 680 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 681 | dump += "Input Reader State:\n"; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 682 | |
| 683 | for (size_t i = 0; i < mDevices.size(); i++) { |
| 684 | mDevices.valueAt(i)->dump(dump); |
| 685 | } |
| 686 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 687 | dump += INDENT "Configuration:\n"; |
| 688 | dump += INDENT2 "ExcludedDeviceNames: ["; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 689 | for (size_t i = 0; i < mConfig.excludedDeviceNames.size(); i++) { |
| 690 | if (i != 0) { |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 691 | dump += ", "; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 692 | } |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 693 | dump += mConfig.excludedDeviceNames[i]; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 694 | } |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 695 | dump += "]\n"; |
| 696 | dump += StringPrintf(INDENT2 "VirtualKeyQuietTime: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 697 | mConfig.virtualKeyQuietTime * 0.000001f); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 698 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 699 | dump += StringPrintf(INDENT2 "PointerVelocityControlParameters: " |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 700 | "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, " |
| 701 | "acceleration=%0.3f\n", |
| 702 | mConfig.pointerVelocityControlParameters.scale, |
| 703 | mConfig.pointerVelocityControlParameters.lowThreshold, |
| 704 | mConfig.pointerVelocityControlParameters.highThreshold, |
| 705 | mConfig.pointerVelocityControlParameters.acceleration); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 706 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 707 | dump += StringPrintf(INDENT2 "WheelVelocityControlParameters: " |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 708 | "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, " |
| 709 | "acceleration=%0.3f\n", |
| 710 | mConfig.wheelVelocityControlParameters.scale, |
| 711 | mConfig.wheelVelocityControlParameters.lowThreshold, |
| 712 | mConfig.wheelVelocityControlParameters.highThreshold, |
| 713 | mConfig.wheelVelocityControlParameters.acceleration); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 714 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 715 | dump += StringPrintf(INDENT2 "PointerGesture:\n"); |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 716 | dump += StringPrintf(INDENT3 "Enabled: %s\n", toString(mConfig.pointerGesturesEnabled)); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 717 | dump += StringPrintf(INDENT3 "QuietInterval: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 718 | mConfig.pointerGestureQuietInterval * 0.000001f); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 719 | dump += StringPrintf(INDENT3 "DragMinSwitchSpeed: %0.1fpx/s\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 720 | mConfig.pointerGestureDragMinSwitchSpeed); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 721 | dump += StringPrintf(INDENT3 "TapInterval: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 722 | mConfig.pointerGestureTapInterval * 0.000001f); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 723 | dump += StringPrintf(INDENT3 "TapDragInterval: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 724 | mConfig.pointerGestureTapDragInterval * 0.000001f); |
| 725 | dump += StringPrintf(INDENT3 "TapSlop: %0.1fpx\n", mConfig.pointerGestureTapSlop); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 726 | dump += StringPrintf(INDENT3 "MultitouchSettleInterval: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 727 | mConfig.pointerGestureMultitouchSettleInterval * 0.000001f); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 728 | dump += StringPrintf(INDENT3 "MultitouchMinDistance: %0.1fpx\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 729 | mConfig.pointerGestureMultitouchMinDistance); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 730 | dump += StringPrintf(INDENT3 "SwipeTransitionAngleCosine: %0.1f\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 731 | mConfig.pointerGestureSwipeTransitionAngleCosine); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 732 | dump += StringPrintf(INDENT3 "SwipeMaxWidthRatio: %0.1f\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 733 | mConfig.pointerGestureSwipeMaxWidthRatio); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 734 | dump += StringPrintf(INDENT3 "MovementSpeedRatio: %0.1f\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 735 | mConfig.pointerGestureMovementSpeedRatio); |
| 736 | dump += StringPrintf(INDENT3 "ZoomSpeedRatio: %0.1f\n", mConfig.pointerGestureZoomSpeedRatio); |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 737 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 738 | dump += INDENT3 "Viewports:\n"; |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 739 | mConfig.dump(dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | void InputReader::monitor() { |
| 743 | // Acquire and release the lock to ensure that the reader has not deadlocked. |
| 744 | mLock.lock(); |
| 745 | mEventHub->wake(); |
| 746 | mReaderIsAliveCondition.wait(mLock); |
| 747 | mLock.unlock(); |
| 748 | |
| 749 | // Check the EventHub |
| 750 | mEventHub->monitor(); |
| 751 | } |
| 752 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 753 | // --- InputReader::ContextImpl --- |
| 754 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 755 | InputReader::ContextImpl::ContextImpl(InputReader* reader) : mReader(reader) {} |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 756 | |
| 757 | void InputReader::ContextImpl::updateGlobalMetaState() { |
| 758 | // lock is already held by the input loop |
| 759 | mReader->updateGlobalMetaStateLocked(); |
| 760 | } |
| 761 | |
| 762 | int32_t InputReader::ContextImpl::getGlobalMetaState() { |
| 763 | // lock is already held by the input loop |
| 764 | return mReader->getGlobalMetaStateLocked(); |
| 765 | } |
| 766 | |
| 767 | void InputReader::ContextImpl::disableVirtualKeysUntil(nsecs_t time) { |
| 768 | // lock is already held by the input loop |
| 769 | mReader->disableVirtualKeysUntilLocked(time); |
| 770 | } |
| 771 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 772 | bool InputReader::ContextImpl::shouldDropVirtualKey(nsecs_t now, InputDevice* device, |
| 773 | int32_t keyCode, int32_t scanCode) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 774 | // lock is already held by the input loop |
| 775 | return mReader->shouldDropVirtualKeyLocked(now, device, keyCode, scanCode); |
| 776 | } |
| 777 | |
| 778 | void InputReader::ContextImpl::fadePointer() { |
| 779 | // lock is already held by the input loop |
| 780 | mReader->fadePointerLocked(); |
| 781 | } |
| 782 | |
| 783 | void InputReader::ContextImpl::requestTimeoutAtTime(nsecs_t when) { |
| 784 | // lock is already held by the input loop |
| 785 | mReader->requestTimeoutAtTimeLocked(when); |
| 786 | } |
| 787 | |
| 788 | int32_t InputReader::ContextImpl::bumpGeneration() { |
| 789 | // lock is already held by the input loop |
| 790 | return mReader->bumpGenerationLocked(); |
| 791 | } |
| 792 | |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 793 | void InputReader::ContextImpl::getExternalStylusDevices(std::vector<InputDeviceInfo>& outDevices) { |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 794 | // lock is already held by whatever called refreshConfigurationLocked |
| 795 | mReader->getExternalStylusDevicesLocked(outDevices); |
| 796 | } |
| 797 | |
| 798 | void InputReader::ContextImpl::dispatchExternalStylusState(const StylusState& state) { |
| 799 | mReader->dispatchExternalStylusState(state); |
| 800 | } |
| 801 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 802 | InputReaderPolicyInterface* InputReader::ContextImpl::getPolicy() { |
| 803 | return mReader->mPolicy.get(); |
| 804 | } |
| 805 | |
| 806 | InputListenerInterface* InputReader::ContextImpl::getListener() { |
| 807 | return mReader->mQueuedListener.get(); |
| 808 | } |
| 809 | |
| 810 | EventHubInterface* InputReader::ContextImpl::getEventHub() { |
| 811 | return mReader->mEventHub.get(); |
| 812 | } |
| 813 | |
Prabir Pradhan | 42611e0 | 2018-11-27 14:04:02 -0800 | [diff] [blame] | 814 | uint32_t InputReader::ContextImpl::getNextSequenceNum() { |
| 815 | return (mReader->mNextSequenceNum)++; |
| 816 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 817 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 818 | } // namespace android |