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