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
17 #include "Macros.h"
18
19 #include "InputReader.h"
20
21 #include <android-base/stringprintf.h>
22 #include <com_android_input_flags.h>
23 #include <errno.h>
24 #include <input/Keyboard.h>
25 #include <input/VirtualKeyMap.h>
26 #include <inttypes.h>
27 #include <limits.h>
28 #include <log/log.h>
29 #include <math.h>
30 #include <stddef.h>
31 #include <stdlib.h>
32 #include <unistd.h>
33 #include <utils/Errors.h>
34 #include <utils/Thread.h>
35 #include <string>
36
37 #include "InputDevice.h"
38 #include "include/gestures.h"
39
40 using android::base::StringPrintf;
41
42 namespace android {
43
44 namespace {
45
46 /**
47 * Determines if the identifiers passed are a sub-devices. Sub-devices are physical devices
48 * that expose multiple input device paths such a keyboard that also has a touchpad input.
49 * These are separate devices with unique descriptors in EventHub, but InputReader should
50 * create a single InputDevice for them.
51 * Sub-devices are detected by the following criteria:
52 * 1. The vendor, product, bus, version, and unique id match
53 * 2. The location matches. The location is used to distinguish a single device with multiple
54 * inputs versus the same device plugged into multiple ports.
55 */
56
isSubDevice(const InputDeviceIdentifier & identifier1,const InputDeviceIdentifier & identifier2)57 bool isSubDevice(const InputDeviceIdentifier& identifier1,
58 const InputDeviceIdentifier& identifier2) {
59 return (identifier1.vendor == identifier2.vendor &&
60 identifier1.product == identifier2.product && identifier1.bus == identifier2.bus &&
61 identifier1.version == identifier2.version &&
62 identifier1.uniqueId == identifier2.uniqueId &&
63 identifier1.location == identifier2.location);
64 }
65
66 /**
67 * Determines if the device classes passed for two devices represent incompatible combinations
68 * that should not be merged into into a single InputDevice.
69 */
70
isCompatibleSubDevice(ftl::Flags<InputDeviceClass> classes1,ftl::Flags<InputDeviceClass> classes2)71 bool isCompatibleSubDevice(ftl::Flags<InputDeviceClass> classes1,
72 ftl::Flags<InputDeviceClass> classes2) {
73 if (!com::android::input::flags::prevent_merging_input_pointer_devices()) {
74 return true;
75 }
76
77 const ftl::Flags<InputDeviceClass> pointerFlags =
78 ftl::Flags<InputDeviceClass>{InputDeviceClass::TOUCH, InputDeviceClass::TOUCH_MT,
79 InputDeviceClass::CURSOR, InputDeviceClass::TOUCHPAD};
80
81 // Do not merge devices that both have any type of pointer event.
82 if (classes1.any(pointerFlags) && classes2.any(pointerFlags)) return false;
83
84 // Safe to merge
85 return true;
86 }
87
isStylusPointerGestureStart(const NotifyMotionArgs & motionArgs)88 bool isStylusPointerGestureStart(const NotifyMotionArgs& motionArgs) {
89 const auto actionMasked = MotionEvent::getActionMasked(motionArgs.action);
90 if (actionMasked != AMOTION_EVENT_ACTION_HOVER_ENTER &&
91 actionMasked != AMOTION_EVENT_ACTION_DOWN &&
92 actionMasked != AMOTION_EVENT_ACTION_POINTER_DOWN) {
93 return false;
94 }
95 const auto actionIndex = MotionEvent::getActionIndex(motionArgs.action);
96 return isStylusToolType(motionArgs.pointerProperties[actionIndex].toolType);
97 }
98
isNewGestureStart(const NotifyMotionArgs & motion)99 bool isNewGestureStart(const NotifyMotionArgs& motion) {
100 return motion.action == AMOTION_EVENT_ACTION_DOWN ||
101 motion.action == AMOTION_EVENT_ACTION_HOVER_ENTER;
102 }
103
isNewGestureStart(const NotifyKeyArgs & key)104 bool isNewGestureStart(const NotifyKeyArgs& key) {
105 return key.action == AKEY_EVENT_ACTION_DOWN;
106 }
107
108 // Return the event's device ID if it marks the start of a new gesture.
getDeviceIdOfNewGesture(const NotifyArgs & args)109 std::optional<DeviceId> getDeviceIdOfNewGesture(const NotifyArgs& args) {
110 if (const auto* motion = std::get_if<NotifyMotionArgs>(&args); motion != nullptr) {
111 return isNewGestureStart(*motion) ? std::make_optional(motion->deviceId) : std::nullopt;
112 }
113 if (const auto* key = std::get_if<NotifyKeyArgs>(&args); key != nullptr) {
114 return isNewGestureStart(*key) ? std::make_optional(key->deviceId) : std::nullopt;
115 }
116 return std::nullopt;
117 }
118
119 } // namespace
120
121 // --- InputReader ---
122
InputReader(std::shared_ptr<EventHubInterface> eventHub,const sp<InputReaderPolicyInterface> & policy,InputListenerInterface & listener)123 InputReader::InputReader(std::shared_ptr<EventHubInterface> eventHub,
124 const sp<InputReaderPolicyInterface>& policy,
125 InputListenerInterface& listener)
126 : mContext(this),
127 mEventHub(eventHub),
128 mPolicy(policy),
129 mNextListener(listener),
130 mKeyboardClassifier(std::make_unique<KeyboardClassifier>()),
131 mGlobalMetaState(AMETA_NONE),
132 mLedMetaState(AMETA_NONE),
133 mGeneration(1),
134 mNextInputDeviceId(END_RESERVED_ID),
135 mDisableVirtualKeysTimeout(LLONG_MIN),
136 mNextTimeout(LLONG_MAX),
137 mConfigurationChangesToRefresh(0) {
138 refreshConfigurationLocked(/*changes=*/{});
139 updateGlobalMetaStateLocked();
140 }
141
~InputReader()142 InputReader::~InputReader() {}
143
start()144 status_t InputReader::start() {
145 if (mThread) {
146 return ALREADY_EXISTS;
147 }
148 mThread = std::make_unique<InputThread>(
149 "InputReader", [this]() { loopOnce(); }, [this]() { mEventHub->wake(); },
150 /*isInCriticalPath=*/true);
151 return OK;
152 }
153
stop()154 status_t InputReader::stop() {
155 if (mThread && mThread->isCallingThread()) {
156 ALOGE("InputReader cannot be stopped from its own thread!");
157 return INVALID_OPERATION;
158 }
159 mThread.reset();
160 return OK;
161 }
162
loopOnce()163 void InputReader::loopOnce() {
164 int32_t oldGeneration;
165 int32_t timeoutMillis;
166 // Copy some state so that we can access it outside the lock later.
167 bool inputDevicesChanged = false;
168 std::vector<InputDeviceInfo> inputDevices;
169 std::list<NotifyArgs> notifyArgs;
170 { // acquire lock
171 std::scoped_lock _l(mLock);
172
173 oldGeneration = mGeneration;
174 timeoutMillis = -1;
175
176 auto changes = mConfigurationChangesToRefresh;
177 if (changes.any()) {
178 mConfigurationChangesToRefresh.clear();
179 timeoutMillis = 0;
180 refreshConfigurationLocked(changes);
181 } else if (mNextTimeout != LLONG_MAX) {
182 nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
183 timeoutMillis = toMillisecondTimeoutDelay(now, mNextTimeout);
184 }
185 } // release lock
186
187 std::vector<RawEvent> events = mEventHub->getEvents(timeoutMillis);
188
189 { // acquire lock
190 std::scoped_lock _l(mLock);
191 mReaderIsAliveCondition.notify_all();
192
193 if (!events.empty()) {
194 mPendingArgs += processEventsLocked(events.data(), events.size());
195 }
196
197 if (mNextTimeout != LLONG_MAX) {
198 nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
199 if (now >= mNextTimeout) {
200 ALOGD_IF(debugRawEvents(), "Timeout expired, latency=%0.3fms",
201 (now - mNextTimeout) * 0.000001f);
202 mNextTimeout = LLONG_MAX;
203 mPendingArgs += timeoutExpiredLocked(now);
204 }
205 }
206
207 if (oldGeneration != mGeneration) {
208 // Reset global meta state because it depends on connected input devices.
209 updateGlobalMetaStateLocked();
210
211 inputDevicesChanged = true;
212 inputDevices = getInputDevicesLocked();
213 mPendingArgs.emplace_back(
214 NotifyInputDevicesChangedArgs{mContext.getNextId(), inputDevices});
215 }
216
217 std::swap(notifyArgs, mPendingArgs);
218
219 // Keep track of the last used device
220 for (const NotifyArgs& args : notifyArgs) {
221 mLastUsedDeviceId = getDeviceIdOfNewGesture(args).value_or(mLastUsedDeviceId);
222 }
223 } // release lock
224
225 // Flush queued events out to the listener.
226 // This must happen outside of the lock because the listener could potentially call
227 // back into the InputReader's methods, such as getScanCodeState, or become blocked
228 // on another thread similarly waiting to acquire the InputReader lock thereby
229 // resulting in a deadlock. This situation is actually quite plausible because the
230 // listener is actually the input dispatcher, which calls into the window manager,
231 // which occasionally calls into the input reader.
232 for (const NotifyArgs& args : notifyArgs) {
233 mNextListener.notify(args);
234 }
235
236 // Notify the policy that input devices have changed.
237 // This must be done after flushing events down the listener chain to ensure that the rest of
238 // the listeners are synchronized with the changes before the policy reacts to them.
239 if (inputDevicesChanged) {
240 mPolicy->notifyInputDevicesChanged(inputDevices);
241 }
242
243 // Notify the policy of the start of every new stylus gesture.
244 for (const auto& args : notifyArgs) {
245 const auto* motionArgs = std::get_if<NotifyMotionArgs>(&args);
246 if (motionArgs != nullptr && isStylusPointerGestureStart(*motionArgs)) {
247 mPolicy->notifyStylusGestureStarted(motionArgs->deviceId, motionArgs->eventTime);
248 }
249 }
250 }
251
processEventsLocked(const RawEvent * rawEvents,size_t count)252 std::list<NotifyArgs> InputReader::processEventsLocked(const RawEvent* rawEvents, size_t count) {
253 std::list<NotifyArgs> out;
254 for (const RawEvent* rawEvent = rawEvents; count;) {
255 int32_t type = rawEvent->type;
256 size_t batchSize = 1;
257 if (type < EventHubInterface::FIRST_SYNTHETIC_EVENT) {
258 int32_t deviceId = rawEvent->deviceId;
259 while (batchSize < count) {
260 if (rawEvent[batchSize].type >= EventHubInterface::FIRST_SYNTHETIC_EVENT ||
261 rawEvent[batchSize].deviceId != deviceId) {
262 break;
263 }
264 batchSize += 1;
265 }
266 ALOGD_IF(debugRawEvents(), "BatchSize: %zu Count: %zu", batchSize, count);
267 out += processEventsForDeviceLocked(deviceId, rawEvent, batchSize);
268 } else {
269 switch (rawEvent->type) {
270 case EventHubInterface::DEVICE_ADDED:
271 addDeviceLocked(rawEvent->when, rawEvent->deviceId);
272 break;
273 case EventHubInterface::DEVICE_REMOVED:
274 removeDeviceLocked(rawEvent->when, rawEvent->deviceId);
275 break;
276 default:
277 ALOG_ASSERT(false); // can't happen
278 break;
279 }
280 }
281 count -= batchSize;
282 rawEvent += batchSize;
283 }
284 return out;
285 }
286
addDeviceLocked(nsecs_t when,int32_t eventHubId)287 void InputReader::addDeviceLocked(nsecs_t when, int32_t eventHubId) {
288 if (mDevices.find(eventHubId) != mDevices.end()) {
289 ALOGW("Ignoring spurious device added event for eventHubId %d.", eventHubId);
290 return;
291 }
292
293 InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(eventHubId);
294 ftl::Flags<InputDeviceClass> classes = mEventHub->getDeviceClasses(eventHubId);
295 std::shared_ptr<InputDevice> device = createDeviceLocked(when, eventHubId, identifier, classes);
296
297 mPendingArgs += device->configure(when, mConfig, /*changes=*/{});
298 mPendingArgs += device->reset(when);
299
300 if (device->isIgnored()) {
301 ALOGI("Device added: id=%d, eventHubId=%d, name='%s', descriptor='%s' "
302 "(ignored non-input device)",
303 device->getId(), eventHubId, identifier.name.c_str(), identifier.descriptor.c_str());
304 } else {
305 ALOGI("Device added: id=%d, eventHubId=%d, name='%s', descriptor='%s',sources=%s",
306 device->getId(), eventHubId, identifier.name.c_str(), identifier.descriptor.c_str(),
307 inputEventSourceToString(device->getSources()).c_str());
308 }
309
310 mDevices.emplace(eventHubId, device);
311 // Add device to device to EventHub ids map.
312 const auto mapIt = mDeviceToEventHubIdsMap.find(device);
313 if (mapIt == mDeviceToEventHubIdsMap.end()) {
314 std::vector<int32_t> ids = {eventHubId};
315 mDeviceToEventHubIdsMap.emplace(device, ids);
316 } else {
317 mapIt->second.push_back(eventHubId);
318 }
319 bumpGenerationLocked();
320
321 if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS)) {
322 notifyExternalStylusPresenceChangedLocked();
323 }
324
325 // Sensor input device is noisy, to save power disable it by default.
326 // Input device is classified as SENSOR when any sub device is a SENSOR device, check Eventhub
327 // device class to disable SENSOR sub device only.
328 if (mEventHub->getDeviceClasses(eventHubId).test(InputDeviceClass::SENSOR)) {
329 mEventHub->disableDevice(eventHubId);
330 }
331 }
332
removeDeviceLocked(nsecs_t when,int32_t eventHubId)333 void InputReader::removeDeviceLocked(nsecs_t when, int32_t eventHubId) {
334 auto deviceIt = mDevices.find(eventHubId);
335 if (deviceIt == mDevices.end()) {
336 ALOGW("Ignoring spurious device removed event for eventHubId %d.", eventHubId);
337 return;
338 }
339
340 std::shared_ptr<InputDevice> device = std::move(deviceIt->second);
341 mDevices.erase(deviceIt);
342 // Erase device from device to EventHub ids map.
343 auto mapIt = mDeviceToEventHubIdsMap.find(device);
344 if (mapIt != mDeviceToEventHubIdsMap.end()) {
345 std::vector<int32_t>& eventHubIds = mapIt->second;
346 std::erase_if(eventHubIds, [eventHubId](int32_t eId) { return eId == eventHubId; });
347 if (eventHubIds.size() == 0) {
348 mDeviceToEventHubIdsMap.erase(mapIt);
349 }
350 }
351 bumpGenerationLocked();
352
353 if (device->isIgnored()) {
354 ALOGI("Device removed: id=%d, eventHubId=%d, name='%s', descriptor='%s' "
355 "(ignored non-input device)",
356 device->getId(), eventHubId, device->getName().c_str(),
357 device->getDescriptor().c_str());
358 } else {
359 ALOGI("Device removed: id=%d, eventHubId=%d, name='%s', descriptor='%s', sources=%s",
360 device->getId(), eventHubId, device->getName().c_str(),
361 device->getDescriptor().c_str(),
362 inputEventSourceToString(device->getSources()).c_str());
363 }
364
365 device->removeEventHubDevice(eventHubId);
366
367 if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS)) {
368 notifyExternalStylusPresenceChangedLocked();
369 }
370
371 if (device->hasEventHubDevices()) {
372 mPendingArgs += device->configure(when, mConfig, /*changes=*/{});
373 }
374 mPendingArgs += device->reset(when);
375 }
376
createDeviceLocked(nsecs_t when,int32_t eventHubId,const InputDeviceIdentifier & identifier,ftl::Flags<InputDeviceClass> classes)377 std::shared_ptr<InputDevice> InputReader::createDeviceLocked(
378 nsecs_t when, int32_t eventHubId, const InputDeviceIdentifier& identifier,
379 ftl::Flags<InputDeviceClass> classes) {
380 auto deviceIt =
381 std::find_if(mDevices.begin(), mDevices.end(), [identifier, classes](auto& devicePair) {
382 const InputDeviceIdentifier identifier2 =
383 devicePair.second->getDeviceInfo().getIdentifier();
384 const ftl::Flags<InputDeviceClass> classes2 = devicePair.second->getClasses();
385 return isSubDevice(identifier, identifier2) &&
386 isCompatibleSubDevice(classes, classes2);
387 });
388
389 std::shared_ptr<InputDevice> device;
390 if (deviceIt != mDevices.end()) {
391 device = deviceIt->second;
392 } else {
393 int32_t deviceId = (eventHubId < END_RESERVED_ID) ? eventHubId : nextInputDeviceIdLocked();
394 device = std::make_shared<InputDevice>(&mContext, deviceId, bumpGenerationLocked(),
395 identifier);
396 }
397 mPendingArgs += device->addEventHubDevice(when, eventHubId, mConfig);
398 return device;
399 }
400
processEventsForDeviceLocked(int32_t eventHubId,const RawEvent * rawEvents,size_t count)401 std::list<NotifyArgs> InputReader::processEventsForDeviceLocked(int32_t eventHubId,
402 const RawEvent* rawEvents,
403 size_t count) {
404 auto deviceIt = mDevices.find(eventHubId);
405 if (deviceIt == mDevices.end()) {
406 ALOGW("Discarding event for unknown eventHubId %d.", eventHubId);
407 return {};
408 }
409
410 std::shared_ptr<InputDevice>& device = deviceIt->second;
411 if (device->isIgnored()) {
412 // ALOGD("Discarding event for ignored deviceId %d.", deviceId);
413 return {};
414 }
415
416 return device->process(rawEvents, count);
417 }
418
findInputDeviceLocked(int32_t deviceId) const419 InputDevice* InputReader::findInputDeviceLocked(int32_t deviceId) const {
420 auto deviceIt =
421 std::find_if(mDevices.begin(), mDevices.end(), [deviceId](const auto& devicePair) {
422 return devicePair.second->getId() == deviceId;
423 });
424 if (deviceIt != mDevices.end()) {
425 return deviceIt->second.get();
426 }
427 return nullptr;
428 }
429
timeoutExpiredLocked(nsecs_t when)430 std::list<NotifyArgs> InputReader::timeoutExpiredLocked(nsecs_t when) {
431 std::list<NotifyArgs> out;
432 for (auto& devicePair : mDevices) {
433 std::shared_ptr<InputDevice>& device = devicePair.second;
434 if (!device->isIgnored()) {
435 out += device->timeoutExpired(when);
436 }
437 }
438 return out;
439 }
440
nextInputDeviceIdLocked()441 int32_t InputReader::nextInputDeviceIdLocked() {
442 return ++mNextInputDeviceId;
443 }
444
refreshConfigurationLocked(ConfigurationChanges changes)445 void InputReader::refreshConfigurationLocked(ConfigurationChanges changes) {
446 mPolicy->getReaderConfiguration(&mConfig);
447 mEventHub->setExcludedDevices(mConfig.excludedDeviceNames);
448
449 using Change = InputReaderConfiguration::Change;
450 if (!changes.any()) return;
451
452 ALOGI("Reconfiguring input devices, changes=%s", changes.string().c_str());
453 nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
454
455 if (changes.test(Change::MUST_REOPEN)) {
456 mEventHub->requestReopenDevices();
457 } else {
458 for (auto& devicePair : mDevices) {
459 std::shared_ptr<InputDevice>& device = devicePair.second;
460 mPendingArgs += device->configure(now, mConfig, changes);
461 }
462 }
463
464 if (changes.test(Change::POINTER_CAPTURE)) {
465 if (mCurrentPointerCaptureRequest == mConfig.pointerCaptureRequest) {
466 ALOGV("Skipping notifying pointer capture changes: "
467 "There was no change in the pointer capture state.");
468 } else {
469 mCurrentPointerCaptureRequest = mConfig.pointerCaptureRequest;
470 mPendingArgs.emplace_back(
471 NotifyPointerCaptureChangedArgs{mContext.getNextId(), now,
472 mCurrentPointerCaptureRequest});
473 }
474 }
475 }
476
updateGlobalMetaStateLocked()477 void InputReader::updateGlobalMetaStateLocked() {
478 mGlobalMetaState = 0;
479
480 for (auto& devicePair : mDevices) {
481 std::shared_ptr<InputDevice>& device = devicePair.second;
482 mGlobalMetaState |= device->getMetaState();
483 }
484 }
485
getGlobalMetaStateLocked()486 int32_t InputReader::getGlobalMetaStateLocked() {
487 return mGlobalMetaState;
488 }
489
updateLedMetaStateLocked(int32_t metaState)490 void InputReader::updateLedMetaStateLocked(int32_t metaState) {
491 mLedMetaState = metaState;
492 for (auto& devicePair : mDevices) {
493 std::shared_ptr<InputDevice>& device = devicePair.second;
494 device->updateLedState(false);
495 }
496 }
497
getLedMetaStateLocked()498 int32_t InputReader::getLedMetaStateLocked() {
499 return mLedMetaState;
500 }
501
notifyExternalStylusPresenceChangedLocked()502 void InputReader::notifyExternalStylusPresenceChangedLocked() {
503 refreshConfigurationLocked(InputReaderConfiguration::Change::EXTERNAL_STYLUS_PRESENCE);
504 }
505
getExternalStylusDevicesLocked(std::vector<InputDeviceInfo> & outDevices)506 void InputReader::getExternalStylusDevicesLocked(std::vector<InputDeviceInfo>& outDevices) {
507 for (auto& devicePair : mDevices) {
508 std::shared_ptr<InputDevice>& device = devicePair.second;
509 if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS) && !device->isIgnored()) {
510 outDevices.push_back(device->getDeviceInfo());
511 }
512 }
513 }
514
dispatchExternalStylusStateLocked(const StylusState & state)515 std::list<NotifyArgs> InputReader::dispatchExternalStylusStateLocked(const StylusState& state) {
516 std::list<NotifyArgs> out;
517 for (auto& devicePair : mDevices) {
518 std::shared_ptr<InputDevice>& device = devicePair.second;
519 out += device->updateExternalStylusState(state);
520 }
521 return out;
522 }
523
disableVirtualKeysUntilLocked(nsecs_t time)524 void InputReader::disableVirtualKeysUntilLocked(nsecs_t time) {
525 mDisableVirtualKeysTimeout = time;
526 }
527
shouldDropVirtualKeyLocked(nsecs_t now,int32_t keyCode,int32_t scanCode)528 bool InputReader::shouldDropVirtualKeyLocked(nsecs_t now, int32_t keyCode, int32_t scanCode) {
529 if (now < mDisableVirtualKeysTimeout) {
530 ALOGI("Dropping virtual key from device because virtual keys are "
531 "temporarily disabled for the next %0.3fms. keyCode=%d, scanCode=%d",
532 (mDisableVirtualKeysTimeout - now) * 0.000001, keyCode, scanCode);
533 return true;
534 } else {
535 return false;
536 }
537 }
538
requestTimeoutAtTimeLocked(nsecs_t when)539 void InputReader::requestTimeoutAtTimeLocked(nsecs_t when) {
540 if (when < mNextTimeout) {
541 mNextTimeout = when;
542 mEventHub->wake();
543 }
544 }
545
bumpGenerationLocked()546 int32_t InputReader::bumpGenerationLocked() {
547 return ++mGeneration;
548 }
549
getInputDevices() const550 std::vector<InputDeviceInfo> InputReader::getInputDevices() const {
551 std::scoped_lock _l(mLock);
552 return getInputDevicesLocked();
553 }
554
getInputDevicesLocked() const555 std::vector<InputDeviceInfo> InputReader::getInputDevicesLocked() const {
556 std::vector<InputDeviceInfo> outInputDevices;
557 outInputDevices.reserve(mDeviceToEventHubIdsMap.size());
558
559 for (const auto& [device, eventHubIds] : mDeviceToEventHubIdsMap) {
560 if (!device->isIgnored()) {
561 outInputDevices.push_back(device->getDeviceInfo());
562 }
563 }
564 return outInputDevices;
565 }
566
getKeyCodeState(int32_t deviceId,uint32_t sourceMask,int32_t keyCode)567 int32_t InputReader::getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) {
568 std::scoped_lock _l(mLock);
569
570 return getStateLocked(deviceId, sourceMask, keyCode, &InputDevice::getKeyCodeState);
571 }
572
getScanCodeState(int32_t deviceId,uint32_t sourceMask,int32_t scanCode)573 int32_t InputReader::getScanCodeState(int32_t deviceId, uint32_t sourceMask, int32_t scanCode) {
574 std::scoped_lock _l(mLock);
575
576 return getStateLocked(deviceId, sourceMask, scanCode, &InputDevice::getScanCodeState);
577 }
578
getSwitchState(int32_t deviceId,uint32_t sourceMask,int32_t switchCode)579 int32_t InputReader::getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t switchCode) {
580 std::scoped_lock _l(mLock);
581
582 return getStateLocked(deviceId, sourceMask, switchCode, &InputDevice::getSwitchState);
583 }
584
getStateLocked(int32_t deviceId,uint32_t sourceMask,int32_t code,GetStateFunc getStateFunc)585 int32_t InputReader::getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code,
586 GetStateFunc getStateFunc) {
587 int32_t result = AKEY_STATE_UNKNOWN;
588 if (deviceId >= 0) {
589 InputDevice* device = findInputDeviceLocked(deviceId);
590 if (device && !device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
591 result = (device->*getStateFunc)(sourceMask, code);
592 }
593 } else {
594 for (auto& devicePair : mDevices) {
595 std::shared_ptr<InputDevice>& device = devicePair.second;
596 if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
597 // If any device reports AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL, return that
598 // value. Otherwise, return AKEY_STATE_UP as long as one device reports it.
599 int32_t currentResult = (device.get()->*getStateFunc)(sourceMask, code);
600 if (currentResult >= AKEY_STATE_DOWN) {
601 return currentResult;
602 } else if (currentResult == AKEY_STATE_UP) {
603 result = currentResult;
604 }
605 }
606 }
607 }
608 return result;
609 }
610
toggleCapsLockState(int32_t deviceId)611 void InputReader::toggleCapsLockState(int32_t deviceId) {
612 std::scoped_lock _l(mLock);
613 if (mKeyboardClassifier->getKeyboardType(deviceId) == KeyboardType::ALPHABETIC) {
614 updateLedMetaStateLocked(mLedMetaState ^ AMETA_CAPS_LOCK_ON);
615 }
616 }
617
resetLockedModifierState()618 void InputReader::resetLockedModifierState() {
619 std::scoped_lock _l(mLock);
620 updateLedMetaStateLocked(0);
621 }
622
hasKeys(int32_t deviceId,uint32_t sourceMask,const std::vector<int32_t> & keyCodes,uint8_t * outFlags)623 bool InputReader::hasKeys(int32_t deviceId, uint32_t sourceMask,
624 const std::vector<int32_t>& keyCodes, uint8_t* outFlags) {
625 std::scoped_lock _l(mLock);
626
627 memset(outFlags, 0, keyCodes.size());
628 return markSupportedKeyCodesLocked(deviceId, sourceMask, keyCodes, outFlags);
629 }
630
markSupportedKeyCodesLocked(int32_t deviceId,uint32_t sourceMask,const std::vector<int32_t> & keyCodes,uint8_t * outFlags)631 bool InputReader::markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask,
632 const std::vector<int32_t>& keyCodes,
633 uint8_t* outFlags) {
634 bool result = false;
635 if (deviceId >= 0) {
636 InputDevice* device = findInputDeviceLocked(deviceId);
637 if (device && !device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
638 result = device->markSupportedKeyCodes(sourceMask, keyCodes, outFlags);
639 }
640 } else {
641 for (auto& devicePair : mDevices) {
642 std::shared_ptr<InputDevice>& device = devicePair.second;
643 if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
644 result |= device->markSupportedKeyCodes(sourceMask, keyCodes, outFlags);
645 }
646 }
647 }
648 return result;
649 }
650
getKeyCodeForKeyLocation(int32_t deviceId,int32_t locationKeyCode) const651 int32_t InputReader::getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const {
652 std::scoped_lock _l(mLock);
653
654 InputDevice* device = findInputDeviceLocked(deviceId);
655 if (device == nullptr) {
656 ALOGW("Failed to get key code for key location: Input device with id %d not found",
657 deviceId);
658 return AKEYCODE_UNKNOWN;
659 }
660 return device->getKeyCodeForKeyLocation(locationKeyCode);
661 }
662
requestRefreshConfiguration(ConfigurationChanges changes)663 void InputReader::requestRefreshConfiguration(ConfigurationChanges changes) {
664 std::scoped_lock _l(mLock);
665
666 if (changes.any()) {
667 bool needWake = !mConfigurationChangesToRefresh.any();
668 mConfigurationChangesToRefresh |= changes;
669
670 if (needWake) {
671 mEventHub->wake();
672 }
673 }
674 }
675
vibrate(int32_t deviceId,const VibrationSequence & sequence,ssize_t repeat,int32_t token)676 void InputReader::vibrate(int32_t deviceId, const VibrationSequence& sequence, ssize_t repeat,
677 int32_t token) {
678 std::scoped_lock _l(mLock);
679
680 InputDevice* device = findInputDeviceLocked(deviceId);
681 if (device) {
682 mPendingArgs += device->vibrate(sequence, repeat, token);
683 }
684 }
685
cancelVibrate(int32_t deviceId,int32_t token)686 void InputReader::cancelVibrate(int32_t deviceId, int32_t token) {
687 std::scoped_lock _l(mLock);
688
689 InputDevice* device = findInputDeviceLocked(deviceId);
690 if (device) {
691 mPendingArgs += device->cancelVibrate(token);
692 }
693 }
694
isVibrating(int32_t deviceId)695 bool InputReader::isVibrating(int32_t deviceId) {
696 std::scoped_lock _l(mLock);
697
698 InputDevice* device = findInputDeviceLocked(deviceId);
699 if (device) {
700 return device->isVibrating();
701 }
702 return false;
703 }
704
getVibratorIds(int32_t deviceId)705 std::vector<int32_t> InputReader::getVibratorIds(int32_t deviceId) {
706 std::scoped_lock _l(mLock);
707
708 InputDevice* device = findInputDeviceLocked(deviceId);
709 if (device) {
710 return device->getVibratorIds();
711 }
712 return {};
713 }
714
disableSensor(int32_t deviceId,InputDeviceSensorType sensorType)715 void InputReader::disableSensor(int32_t deviceId, InputDeviceSensorType sensorType) {
716 std::scoped_lock _l(mLock);
717
718 InputDevice* device = findInputDeviceLocked(deviceId);
719 if (device) {
720 device->disableSensor(sensorType);
721 }
722 }
723
enableSensor(int32_t deviceId,InputDeviceSensorType sensorType,std::chrono::microseconds samplingPeriod,std::chrono::microseconds maxBatchReportLatency)724 bool InputReader::enableSensor(int32_t deviceId, InputDeviceSensorType sensorType,
725 std::chrono::microseconds samplingPeriod,
726 std::chrono::microseconds maxBatchReportLatency) {
727 std::scoped_lock _l(mLock);
728
729 InputDevice* device = findInputDeviceLocked(deviceId);
730 if (device) {
731 return device->enableSensor(sensorType, samplingPeriod, maxBatchReportLatency);
732 }
733 return false;
734 }
735
flushSensor(int32_t deviceId,InputDeviceSensorType sensorType)736 void InputReader::flushSensor(int32_t deviceId, InputDeviceSensorType sensorType) {
737 std::scoped_lock _l(mLock);
738
739 InputDevice* device = findInputDeviceLocked(deviceId);
740 if (device) {
741 device->flushSensor(sensorType);
742 }
743 }
744
getBatteryCapacity(int32_t deviceId)745 std::optional<int32_t> InputReader::getBatteryCapacity(int32_t deviceId) {
746 std::optional<int32_t> eventHubId;
747 {
748 // Do not query the battery state while holding the lock. For some peripheral devices,
749 // reading battery state can be broken and take 5+ seconds. Holding the lock in this case
750 // would block all other event processing during this time. For now, we assume this
751 // call never happens on the InputReader thread and get the battery state outside the
752 // lock to prevent event processing from being blocked by this call.
753 std::scoped_lock _l(mLock);
754 InputDevice* device = findInputDeviceLocked(deviceId);
755 if (!device) return {};
756 eventHubId = device->getBatteryEventHubId();
757 } // release lock
758
759 if (!eventHubId) return {};
760 const auto batteryIds = mEventHub->getRawBatteryIds(*eventHubId);
761 if (batteryIds.empty()) {
762 ALOGW("%s: There are no battery ids for EventHub device %d", __func__, *eventHubId);
763 return {};
764 }
765 return mEventHub->getBatteryCapacity(*eventHubId, batteryIds.front());
766 }
767
getBatteryStatus(int32_t deviceId)768 std::optional<int32_t> InputReader::getBatteryStatus(int32_t deviceId) {
769 std::optional<int32_t> eventHubId;
770 {
771 // Do not query the battery state while holding the lock. For some peripheral devices,
772 // reading battery state can be broken and take 5+ seconds. Holding the lock in this case
773 // would block all other event processing during this time. For now, we assume this
774 // call never happens on the InputReader thread and get the battery state outside the
775 // lock to prevent event processing from being blocked by this call.
776 std::scoped_lock _l(mLock);
777 InputDevice* device = findInputDeviceLocked(deviceId);
778 if (!device) return {};
779 eventHubId = device->getBatteryEventHubId();
780 } // release lock
781
782 if (!eventHubId) return {};
783 const auto batteryIds = mEventHub->getRawBatteryIds(*eventHubId);
784 if (batteryIds.empty()) {
785 ALOGW("%s: There are no battery ids for EventHub device %d", __func__, *eventHubId);
786 return {};
787 }
788 return mEventHub->getBatteryStatus(*eventHubId, batteryIds.front());
789 }
790
getBatteryDevicePath(int32_t deviceId)791 std::optional<std::string> InputReader::getBatteryDevicePath(int32_t deviceId) {
792 std::scoped_lock _l(mLock);
793
794 InputDevice* device = findInputDeviceLocked(deviceId);
795 if (!device) return {};
796
797 std::optional<int32_t> eventHubId = device->getBatteryEventHubId();
798 if (!eventHubId) return {};
799 const auto batteryIds = mEventHub->getRawBatteryIds(*eventHubId);
800 if (batteryIds.empty()) {
801 ALOGW("%s: There are no battery ids for EventHub device %d", __func__, *eventHubId);
802 return {};
803 }
804 const auto batteryInfo = mEventHub->getRawBatteryInfo(*eventHubId, batteryIds.front());
805 if (!batteryInfo) {
806 ALOGW("%s: Failed to get RawBatteryInfo for battery %d of EventHub device %d", __func__,
807 batteryIds.front(), *eventHubId);
808 return {};
809 }
810 return batteryInfo->path;
811 }
812
getLights(int32_t deviceId)813 std::vector<InputDeviceLightInfo> InputReader::getLights(int32_t deviceId) {
814 std::scoped_lock _l(mLock);
815
816 InputDevice* device = findInputDeviceLocked(deviceId);
817 if (device == nullptr) {
818 return {};
819 }
820
821 return device->getDeviceInfo().getLights();
822 }
823
getSensors(int32_t deviceId)824 std::vector<InputDeviceSensorInfo> InputReader::getSensors(int32_t deviceId) {
825 std::scoped_lock _l(mLock);
826
827 InputDevice* device = findInputDeviceLocked(deviceId);
828 if (device == nullptr) {
829 return {};
830 }
831
832 return device->getDeviceInfo().getSensors();
833 }
834
getTouchpadHardwareProperties(int32_t deviceId)835 std::optional<HardwareProperties> InputReader::getTouchpadHardwareProperties(int32_t deviceId) {
836 std::scoped_lock _l(mLock);
837
838 InputDevice* device = findInputDeviceLocked(deviceId);
839
840 if (device == nullptr) {
841 return {};
842 }
843
844 return device->getTouchpadHardwareProperties();
845 }
846
setLightColor(int32_t deviceId,int32_t lightId,int32_t color)847 bool InputReader::setLightColor(int32_t deviceId, int32_t lightId, int32_t color) {
848 std::scoped_lock _l(mLock);
849
850 InputDevice* device = findInputDeviceLocked(deviceId);
851 if (device) {
852 return device->setLightColor(lightId, color);
853 }
854 return false;
855 }
856
setLightPlayerId(int32_t deviceId,int32_t lightId,int32_t playerId)857 bool InputReader::setLightPlayerId(int32_t deviceId, int32_t lightId, int32_t playerId) {
858 std::scoped_lock _l(mLock);
859
860 InputDevice* device = findInputDeviceLocked(deviceId);
861 if (device) {
862 return device->setLightPlayerId(lightId, playerId);
863 }
864 return false;
865 }
866
getLightColor(int32_t deviceId,int32_t lightId)867 std::optional<int32_t> InputReader::getLightColor(int32_t deviceId, int32_t lightId) {
868 std::scoped_lock _l(mLock);
869
870 InputDevice* device = findInputDeviceLocked(deviceId);
871 if (device) {
872 return device->getLightColor(lightId);
873 }
874 return std::nullopt;
875 }
876
getLightPlayerId(int32_t deviceId,int32_t lightId)877 std::optional<int32_t> InputReader::getLightPlayerId(int32_t deviceId, int32_t lightId) {
878 std::scoped_lock _l(mLock);
879
880 InputDevice* device = findInputDeviceLocked(deviceId);
881 if (device) {
882 return device->getLightPlayerId(lightId);
883 }
884 return std::nullopt;
885 }
886
getBluetoothAddress(int32_t deviceId) const887 std::optional<std::string> InputReader::getBluetoothAddress(int32_t deviceId) const {
888 std::scoped_lock _l(mLock);
889
890 InputDevice* device = findInputDeviceLocked(deviceId);
891 if (device) {
892 return device->getBluetoothAddress();
893 }
894 return std::nullopt;
895 }
896
canDispatchToDisplay(int32_t deviceId,ui::LogicalDisplayId displayId)897 bool InputReader::canDispatchToDisplay(int32_t deviceId, ui::LogicalDisplayId displayId) {
898 std::scoped_lock _l(mLock);
899
900 InputDevice* device = findInputDeviceLocked(deviceId);
901 if (!device) {
902 ALOGW("Ignoring invalid device id %" PRId32 ".", deviceId);
903 return false;
904 }
905
906 if (!device->isEnabled()) {
907 ALOGW("Ignoring disabled device %s", device->getName().c_str());
908 return false;
909 }
910
911 std::optional<ui::LogicalDisplayId> associatedDisplayId = device->getAssociatedDisplayId();
912 // No associated display. By default, can dispatch to all displays.
913 if (!associatedDisplayId || !associatedDisplayId->isValid()) {
914 return true;
915 }
916
917 return *associatedDisplayId == displayId;
918 }
919
getSysfsRootPath(int32_t deviceId) const920 std::filesystem::path InputReader::getSysfsRootPath(int32_t deviceId) const {
921 std::scoped_lock _l(mLock);
922
923 const InputDevice* device = findInputDeviceLocked(deviceId);
924 if (!device) {
925 return {};
926 }
927 return device->getSysfsRootPath();
928 }
929
sysfsNodeChanged(const std::string & sysfsNodePath)930 void InputReader::sysfsNodeChanged(const std::string& sysfsNodePath) {
931 mEventHub->sysfsNodeChanged(sysfsNodePath);
932 mEventHub->wake();
933 }
934
getLastUsedInputDeviceId()935 DeviceId InputReader::getLastUsedInputDeviceId() {
936 std::scoped_lock _l(mLock);
937 return mLastUsedDeviceId;
938 }
939
notifyMouseCursorFadedOnTyping()940 void InputReader::notifyMouseCursorFadedOnTyping() {
941 std::scoped_lock _l(mLock);
942 // disable touchpad taps when cursor has faded due to typing
943 mPreventingTouchpadTaps = true;
944 }
945
setKernelWakeEnabled(int32_t deviceId,bool enabled)946 bool InputReader::setKernelWakeEnabled(int32_t deviceId, bool enabled) {
947 std::scoped_lock _l(mLock);
948 if (!com::android::input::flags::set_input_device_kernel_wake()){
949 return false;
950 }
951 InputDevice* device = findInputDeviceLocked(deviceId);
952 if (device) {
953 return device->setKernelWakeEnabled(enabled);
954 }
955 return false;
956 }
957
dump(std::string & dump)958 void InputReader::dump(std::string& dump) {
959 std::scoped_lock _l(mLock);
960 dumpLocked(dump);
961 }
962
dumpLocked(std::string & dump)963 void InputReader::dumpLocked(std::string& dump) {
964 mEventHub->dump(dump);
965 dump += "\n";
966
967 dump += StringPrintf("Input Reader State (Nums of device: %zu):\n",
968 mDeviceToEventHubIdsMap.size());
969
970 for (const auto& devicePair : mDeviceToEventHubIdsMap) {
971 const std::shared_ptr<InputDevice>& device = devicePair.first;
972 std::string eventHubDevStr = INDENT "EventHub Devices: [ ";
973 for (const auto& eId : devicePair.second) {
974 eventHubDevStr += StringPrintf("%d ", eId);
975 }
976 eventHubDevStr += "] \n";
977 device->dump(dump, eventHubDevStr);
978 }
979
980 dump += StringPrintf(INDENT "NextTimeout: %" PRId64 "\n", mNextTimeout);
981 dump += INDENT "Configuration:\n";
982 dump += INDENT2 "ExcludedDeviceNames: [";
983 for (size_t i = 0; i < mConfig.excludedDeviceNames.size(); i++) {
984 if (i != 0) {
985 dump += ", ";
986 }
987 dump += mConfig.excludedDeviceNames[i];
988 }
989 dump += "]\n";
990 dump += StringPrintf(INDENT2 "VirtualKeyQuietTime: %0.1fms\n",
991 mConfig.virtualKeyQuietTime * 0.000001f);
992
993 dump += StringPrintf(INDENT2 "PointerVelocityControlParameters: "
994 "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, "
995 "acceleration=%0.3f\n",
996 mConfig.pointerVelocityControlParameters.scale,
997 mConfig.pointerVelocityControlParameters.lowThreshold,
998 mConfig.pointerVelocityControlParameters.highThreshold,
999 mConfig.pointerVelocityControlParameters.acceleration);
1000
1001 dump += StringPrintf(INDENT2 "WheelVelocityControlParameters: "
1002 "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, "
1003 "acceleration=%0.3f\n",
1004 mConfig.wheelVelocityControlParameters.scale,
1005 mConfig.wheelVelocityControlParameters.lowThreshold,
1006 mConfig.wheelVelocityControlParameters.highThreshold,
1007 mConfig.wheelVelocityControlParameters.acceleration);
1008
1009 dump += StringPrintf(INDENT2 "PointerGesture:\n");
1010 dump += StringPrintf(INDENT3 "Enabled: %s\n", toString(mConfig.pointerGesturesEnabled));
1011 dump += StringPrintf(INDENT3 "QuietInterval: %0.1fms\n",
1012 mConfig.pointerGestureQuietInterval * 0.000001f);
1013 dump += StringPrintf(INDENT3 "DragMinSwitchSpeed: %0.1fpx/s\n",
1014 mConfig.pointerGestureDragMinSwitchSpeed);
1015 dump += StringPrintf(INDENT3 "TapInterval: %0.1fms\n",
1016 mConfig.pointerGestureTapInterval * 0.000001f);
1017 dump += StringPrintf(INDENT3 "TapDragInterval: %0.1fms\n",
1018 mConfig.pointerGestureTapDragInterval * 0.000001f);
1019 dump += StringPrintf(INDENT3 "TapSlop: %0.1fpx\n", mConfig.pointerGestureTapSlop);
1020 dump += StringPrintf(INDENT3 "MultitouchSettleInterval: %0.1fms\n",
1021 mConfig.pointerGestureMultitouchSettleInterval * 0.000001f);
1022 dump += StringPrintf(INDENT3 "MultitouchMinDistance: %0.1fpx\n",
1023 mConfig.pointerGestureMultitouchMinDistance);
1024 dump += StringPrintf(INDENT3 "SwipeTransitionAngleCosine: %0.1f\n",
1025 mConfig.pointerGestureSwipeTransitionAngleCosine);
1026 dump += StringPrintf(INDENT3 "SwipeMaxWidthRatio: %0.1f\n",
1027 mConfig.pointerGestureSwipeMaxWidthRatio);
1028 dump += StringPrintf(INDENT3 "MovementSpeedRatio: %0.1f\n",
1029 mConfig.pointerGestureMovementSpeedRatio);
1030 dump += StringPrintf(INDENT3 "ZoomSpeedRatio: %0.1f\n", mConfig.pointerGestureZoomSpeedRatio);
1031
1032 dump += INDENT3 "Viewports:\n";
1033 mConfig.dump(dump);
1034 }
1035
monitor()1036 void InputReader::monitor() {
1037 // Acquire and release the lock to ensure that the reader has not deadlocked.
1038 std::unique_lock<std::mutex> lock(mLock);
1039 mEventHub->wake();
1040 mReaderIsAliveCondition.wait(lock);
1041 // Check the EventHub
1042 mEventHub->monitor();
1043 }
1044
1045 // --- InputReader::ContextImpl ---
1046
ContextImpl(InputReader * reader)1047 InputReader::ContextImpl::ContextImpl(InputReader* reader)
1048 : mReader(reader), mIdGenerator(IdGenerator::Source::INPUT_READER) {}
1049
dump()1050 std::string InputReader::ContextImpl::dump() {
1051 std::string dump;
1052 mReader->dumpLocked(dump);
1053 return dump;
1054 }
1055
updateGlobalMetaState()1056 void InputReader::ContextImpl::updateGlobalMetaState() {
1057 // lock is already held by the input loop
1058 mReader->updateGlobalMetaStateLocked();
1059 }
1060
getGlobalMetaState()1061 int32_t InputReader::ContextImpl::getGlobalMetaState() {
1062 // lock is already held by the input loop
1063 return mReader->getGlobalMetaStateLocked();
1064 }
1065
updateLedMetaState(int32_t metaState)1066 void InputReader::ContextImpl::updateLedMetaState(int32_t metaState) {
1067 // lock is already held by the input loop
1068 mReader->updateLedMetaStateLocked(metaState);
1069 }
1070
getLedMetaState()1071 int32_t InputReader::ContextImpl::getLedMetaState() {
1072 // lock is already held by the input loop
1073 return mReader->getLedMetaStateLocked();
1074 }
1075
setPreventingTouchpadTaps(bool prevent)1076 void InputReader::ContextImpl::setPreventingTouchpadTaps(bool prevent) {
1077 // lock is already held by the input loop
1078 mReader->mPreventingTouchpadTaps = prevent;
1079 }
1080
isPreventingTouchpadTaps()1081 bool InputReader::ContextImpl::isPreventingTouchpadTaps() {
1082 // lock is already held by the input loop
1083 return mReader->mPreventingTouchpadTaps;
1084 }
1085
setLastKeyDownTimestamp(nsecs_t when)1086 void InputReader::ContextImpl::setLastKeyDownTimestamp(nsecs_t when) {
1087 mReader->mLastKeyDownTimestamp = when;
1088 }
1089
getLastKeyDownTimestamp()1090 nsecs_t InputReader::ContextImpl::getLastKeyDownTimestamp() {
1091 return mReader->mLastKeyDownTimestamp;
1092 }
1093
disableVirtualKeysUntil(nsecs_t time)1094 void InputReader::ContextImpl::disableVirtualKeysUntil(nsecs_t time) {
1095 // lock is already held by the input loop
1096 mReader->disableVirtualKeysUntilLocked(time);
1097 }
1098
shouldDropVirtualKey(nsecs_t now,int32_t keyCode,int32_t scanCode)1099 bool InputReader::ContextImpl::shouldDropVirtualKey(nsecs_t now, int32_t keyCode,
1100 int32_t scanCode) {
1101 // lock is already held by the input loop
1102 return mReader->shouldDropVirtualKeyLocked(now, keyCode, scanCode);
1103 }
1104
requestTimeoutAtTime(nsecs_t when)1105 void InputReader::ContextImpl::requestTimeoutAtTime(nsecs_t when) {
1106 // lock is already held by the input loop
1107 mReader->requestTimeoutAtTimeLocked(when);
1108 }
1109
bumpGeneration()1110 int32_t InputReader::ContextImpl::bumpGeneration() {
1111 // lock is already held by the input loop
1112 return mReader->bumpGenerationLocked();
1113 }
1114
getExternalStylusDevices(std::vector<InputDeviceInfo> & outDevices)1115 void InputReader::ContextImpl::getExternalStylusDevices(std::vector<InputDeviceInfo>& outDevices) {
1116 // lock is already held by whatever called refreshConfigurationLocked
1117 mReader->getExternalStylusDevicesLocked(outDevices);
1118 }
1119
dispatchExternalStylusState(const StylusState & state)1120 std::list<NotifyArgs> InputReader::ContextImpl::dispatchExternalStylusState(
1121 const StylusState& state) {
1122 return mReader->dispatchExternalStylusStateLocked(state);
1123 }
1124
getPolicy()1125 InputReaderPolicyInterface* InputReader::ContextImpl::getPolicy() {
1126 return mReader->mPolicy.get();
1127 }
1128
getEventHub()1129 EventHubInterface* InputReader::ContextImpl::getEventHub() {
1130 return mReader->mEventHub.get();
1131 }
1132
getNextId() const1133 int32_t InputReader::ContextImpl::getNextId() const {
1134 return mIdGenerator.nextId();
1135 }
1136
getKeyboardClassifier()1137 KeyboardClassifier& InputReader::ContextImpl::getKeyboardClassifier() {
1138 return *mReader->mKeyboardClassifier;
1139 }
1140
1141 } // namespace android
1142