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