blob: e263f010c3b2d9c718c49df8634c7732058d3f8e [file] [log] [blame]
Michael Wrightd02c5b62014-02-10 15:10:22 -08001/*
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 Pradhanbaa5c822019-08-30 15:27:05 -070017#include "Macros.h"
Michael Wright842500e2015-03-13 17:32:02 -070018
Michael Wrightd02c5b62014-02-10 15:10:22 -080019#include "InputReader.h"
20
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -080021#include <android-base/stringprintf.h>
Mark Salyzyna5e161b2016-09-29 08:08:05 -070022#include <errno.h>
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -080023#include <input/Keyboard.h>
24#include <input/VirtualKeyMap.h>
Michael Wright842500e2015-03-13 17:32:02 -070025#include <inttypes.h>
Mark Salyzyna5e161b2016-09-29 08:08:05 -070026#include <limits.h>
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -080027#include <log/log.h>
Mark Salyzyna5e161b2016-09-29 08:08:05 -070028#include <math.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080029#include <stddef.h>
30#include <stdlib.h>
31#include <unistd.h>
Prabir Pradhan28efc192019-11-05 01:10:04 +000032#include <utils/Errors.h>
Prabir Pradhan28efc192019-11-05 01:10:04 +000033#include <utils/Thread.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080034
Nathaniel R. Lewisf4916ef2020-01-14 11:57:18 -080035#include "InputDevice.h"
36
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -080037using android::base::StringPrintf;
38
Michael Wrightd02c5b62014-02-10 15:10:22 -080039namespace android {
40
Prabir Pradhan28efc192019-11-05 01:10:04 +000041// --- InputReader ---
42
Siarhei Vishniakou3bc7e092019-07-24 17:43:30 -070043InputReader::InputReader(std::shared_ptr<EventHubInterface> eventHub,
44 const sp<InputReaderPolicyInterface>& policy,
45 const sp<InputListenerInterface>& listener)
46 : mContext(this),
47 mEventHub(eventHub),
48 mPolicy(policy),
Siarhei Vishniakou3bc7e092019-07-24 17:43:30 -070049 mGlobalMetaState(0),
arthurhungc903df12020-08-11 15:08:42 +080050 mLedMetaState(AMETA_NUM_LOCK_ON),
Siarhei Vishniakou3bc7e092019-07-24 17:43:30 -070051 mGeneration(1),
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080052 mNextInputDeviceId(END_RESERVED_ID),
Siarhei Vishniakou3bc7e092019-07-24 17:43:30 -070053 mDisableVirtualKeysTimeout(LLONG_MIN),
54 mNextTimeout(LLONG_MAX),
Michael Wrightd02c5b62014-02-10 15:10:22 -080055 mConfigurationChangesToRefresh(0) {
56 mQueuedListener = new QueuedInputListener(listener);
57
58 { // acquire lock
59 AutoMutex _l(mLock);
60
61 refreshConfigurationLocked(0);
62 updateGlobalMetaStateLocked();
63 } // release lock
64}
65
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +000066InputReader::~InputReader() {}
Michael Wrightd02c5b62014-02-10 15:10:22 -080067
Prabir Pradhan28efc192019-11-05 01:10:04 +000068status_t InputReader::start() {
Prabir Pradhan5a57cff2019-10-31 18:40:33 -070069 if (mThread) {
Prabir Pradhan28efc192019-11-05 01:10:04 +000070 return ALREADY_EXISTS;
71 }
Prabir Pradhan5a57cff2019-10-31 18:40:33 -070072 mThread = std::make_unique<InputThread>(
73 "InputReader", [this]() { loopOnce(); }, [this]() { mEventHub->wake(); });
74 return OK;
Prabir Pradhan28efc192019-11-05 01:10:04 +000075}
76
77status_t InputReader::stop() {
Prabir Pradhan5a57cff2019-10-31 18:40:33 -070078 if (mThread && mThread->isCallingThread()) {
79 ALOGE("InputReader cannot be stopped from its own thread!");
Prabir Pradhan28efc192019-11-05 01:10:04 +000080 return INVALID_OPERATION;
81 }
Prabir Pradhan5a57cff2019-10-31 18:40:33 -070082 mThread.reset();
83 return OK;
Prabir Pradhan28efc192019-11-05 01:10:04 +000084}
85
Michael Wrightd02c5b62014-02-10 15:10:22 -080086void InputReader::loopOnce() {
87 int32_t oldGeneration;
88 int32_t timeoutMillis;
89 bool inputDevicesChanged = false;
Michael Wrightd02c5b62014-02-10 15:10:22 -080090 { // acquire lock
91 AutoMutex _l(mLock);
92
93 oldGeneration = mGeneration;
94 timeoutMillis = -1;
95
96 uint32_t changes = mConfigurationChangesToRefresh;
97 if (changes) {
98 mConfigurationChangesToRefresh = 0;
99 timeoutMillis = 0;
100 refreshConfigurationLocked(changes);
101 } else if (mNextTimeout != LLONG_MAX) {
102 nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
103 timeoutMillis = toMillisecondTimeoutDelay(now, mNextTimeout);
104 }
105 } // release lock
106
107 size_t count = mEventHub->getEvents(timeoutMillis, mEventBuffer, EVENT_BUFFER_SIZE);
108
109 { // acquire lock
110 AutoMutex _l(mLock);
111 mReaderIsAliveCondition.broadcast();
112
113 if (count) {
114 processEventsLocked(mEventBuffer, count);
115 }
116
117 if (mNextTimeout != LLONG_MAX) {
118 nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
119 if (now >= mNextTimeout) {
120#if DEBUG_RAW_EVENTS
121 ALOGD("Timeout expired, latency=%0.3fms", (now - mNextTimeout) * 0.000001f);
122#endif
123 mNextTimeout = LLONG_MAX;
124 timeoutExpiredLocked(now);
125 }
126 }
127
128 if (oldGeneration != mGeneration) {
129 inputDevicesChanged = true;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800130 }
131 } // release lock
132
133 // Send out a message that the describes the changed input devices.
134 if (inputDevicesChanged) {
Chris Ye98d3f532020-10-01 21:48:59 -0700135 mPolicy->notifyInputDevicesChanged(getInputDevicesLocked());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800136 }
137
138 // Flush queued events out to the listener.
139 // This must happen outside of the lock because the listener could potentially call
140 // back into the InputReader's methods, such as getScanCodeState, or become blocked
141 // on another thread similarly waiting to acquire the InputReader lock thereby
142 // resulting in a deadlock. This situation is actually quite plausible because the
143 // listener is actually the input dispatcher, which calls into the window manager,
144 // which occasionally calls into the input reader.
145 mQueuedListener->flush();
146}
147
148void InputReader::processEventsLocked(const RawEvent* rawEvents, size_t count) {
149 for (const RawEvent* rawEvent = rawEvents; count;) {
150 int32_t type = rawEvent->type;
151 size_t batchSize = 1;
152 if (type < EventHubInterface::FIRST_SYNTHETIC_EVENT) {
153 int32_t deviceId = rawEvent->deviceId;
154 while (batchSize < count) {
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700155 if (rawEvent[batchSize].type >= EventHubInterface::FIRST_SYNTHETIC_EVENT ||
156 rawEvent[batchSize].deviceId != deviceId) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800157 break;
158 }
159 batchSize += 1;
160 }
161#if DEBUG_RAW_EVENTS
Siarhei Vishniakou5d83f602017-09-12 12:40:29 -0700162 ALOGD("BatchSize: %zu Count: %zu", batchSize, count);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800163#endif
164 processEventsForDeviceLocked(deviceId, rawEvent, batchSize);
165 } else {
166 switch (rawEvent->type) {
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700167 case EventHubInterface::DEVICE_ADDED:
168 addDeviceLocked(rawEvent->when, rawEvent->deviceId);
169 break;
170 case EventHubInterface::DEVICE_REMOVED:
171 removeDeviceLocked(rawEvent->when, rawEvent->deviceId);
172 break;
173 case EventHubInterface::FINISHED_DEVICE_SCAN:
174 handleConfigurationChangedLocked(rawEvent->when);
175 break;
176 default:
177 ALOG_ASSERT(false); // can't happen
178 break;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800179 }
180 }
181 count -= batchSize;
182 rawEvent += batchSize;
183 }
184}
185
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800186void InputReader::addDeviceLocked(nsecs_t when, int32_t eventHubId) {
187 if (mDevices.find(eventHubId) != mDevices.end()) {
188 ALOGW("Ignoring spurious device added event for eventHubId %d.", eventHubId);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800189 return;
190 }
191
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800192 InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(eventHubId);
193 std::shared_ptr<InputDevice> device = createDeviceLocked(eventHubId, identifier);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800194 device->configure(when, &mConfig, 0);
195 device->reset(when);
196
197 if (device->isIgnored()) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800198 ALOGI("Device added: id=%d, eventHubId=%d, name='%s', descriptor='%s' "
199 "(ignored non-input device)",
200 device->getId(), eventHubId, identifier.name.c_str(), identifier.descriptor.c_str());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800201 } else {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800202 ALOGI("Device added: id=%d, eventHubId=%d, name='%s', descriptor='%s',sources=0x%08x",
203 device->getId(), eventHubId, identifier.name.c_str(), identifier.descriptor.c_str(),
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700204 device->getSources());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800205 }
206
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800207 mDevices.emplace(eventHubId, device);
Chris Yee7310032020-09-22 15:36:28 -0700208 // Add device to device to EventHub ids map.
209 const auto mapIt = mDeviceToEventHubIdsMap.find(device);
210 if (mapIt == mDeviceToEventHubIdsMap.end()) {
211 std::vector<int32_t> ids = {eventHubId};
212 mDeviceToEventHubIdsMap.emplace(device, ids);
213 } else {
214 mapIt->second.push_back(eventHubId);
215 }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800216 bumpGenerationLocked();
Michael Wright842500e2015-03-13 17:32:02 -0700217
Chris Ye1b0c7342020-07-28 21:57:03 -0700218 if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS)) {
Michael Wright842500e2015-03-13 17:32:02 -0700219 notifyExternalStylusPresenceChanged();
220 }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800221}
222
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800223void InputReader::removeDeviceLocked(nsecs_t when, int32_t eventHubId) {
224 auto deviceIt = mDevices.find(eventHubId);
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000225 if (deviceIt == mDevices.end()) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800226 ALOGW("Ignoring spurious device removed event for eventHubId %d.", eventHubId);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800227 return;
228 }
229
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000230 std::shared_ptr<InputDevice> device = std::move(deviceIt->second);
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000231 mDevices.erase(deviceIt);
Chris Yee7310032020-09-22 15:36:28 -0700232 // Erase device from device to EventHub ids map.
233 auto mapIt = mDeviceToEventHubIdsMap.find(device);
234 if (mapIt != mDeviceToEventHubIdsMap.end()) {
235 std::vector<int32_t>& eventHubIds = mapIt->second;
236 eventHubIds.erase(std::remove_if(eventHubIds.begin(), eventHubIds.end(),
237 [eventHubId](int32_t eId) { return eId == eventHubId; }),
238 eventHubIds.end());
239 if (eventHubIds.size() == 0) {
240 mDeviceToEventHubIdsMap.erase(mapIt);
241 }
242 }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800243 bumpGenerationLocked();
244
245 if (device->isIgnored()) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800246 ALOGI("Device removed: id=%d, eventHubId=%d, name='%s', descriptor='%s' "
247 "(ignored non-input device)",
248 device->getId(), eventHubId, device->getName().c_str(),
249 device->getDescriptor().c_str());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800250 } else {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800251 ALOGI("Device removed: id=%d, eventHubId=%d, name='%s', descriptor='%s', sources=0x%08x",
252 device->getId(), eventHubId, device->getName().c_str(),
253 device->getDescriptor().c_str(), device->getSources());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800254 }
255
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800256 device->removeEventHubDevice(eventHubId);
257
Chris Ye1b0c7342020-07-28 21:57:03 -0700258 if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS)) {
Michael Wright842500e2015-03-13 17:32:02 -0700259 notifyExternalStylusPresenceChanged();
260 }
261
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800262 if (device->hasEventHubDevices()) {
263 device->configure(when, &mConfig, 0);
264 }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800265 device->reset(when);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800266}
267
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000268std::shared_ptr<InputDevice> InputReader::createDeviceLocked(
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800269 int32_t eventHubId, const InputDeviceIdentifier& identifier) {
270 auto deviceIt = std::find_if(mDevices.begin(), mDevices.end(), [identifier](auto& devicePair) {
271 return devicePair.second->getDescriptor().size() && identifier.descriptor.size() &&
272 devicePair.second->getDescriptor() == identifier.descriptor;
273 });
274
275 std::shared_ptr<InputDevice> device;
276 if (deviceIt != mDevices.end()) {
277 device = deviceIt->second;
278 } else {
279 int32_t deviceId = (eventHubId < END_RESERVED_ID) ? eventHubId : nextInputDeviceIdLocked();
280 device = std::make_shared<InputDevice>(&mContext, deviceId, bumpGenerationLocked(),
281 identifier);
282 }
283 device->addEventHubDevice(eventHubId);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800284 return device;
285}
286
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800287void InputReader::processEventsForDeviceLocked(int32_t eventHubId, const RawEvent* rawEvents,
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700288 size_t count) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800289 auto deviceIt = mDevices.find(eventHubId);
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000290 if (deviceIt == mDevices.end()) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800291 ALOGW("Discarding event for unknown eventHubId %d.", eventHubId);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800292 return;
293 }
294
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000295 std::shared_ptr<InputDevice>& device = deviceIt->second;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800296 if (device->isIgnored()) {
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700297 // ALOGD("Discarding event for ignored deviceId %d.", deviceId);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800298 return;
299 }
300
301 device->process(rawEvents, count);
302}
303
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800304InputDevice* InputReader::findInputDevice(int32_t deviceId) {
305 auto deviceIt =
306 std::find_if(mDevices.begin(), mDevices.end(), [deviceId](const auto& devicePair) {
307 return devicePair.second->getId() == deviceId;
308 });
309 if (deviceIt != mDevices.end()) {
310 return deviceIt->second.get();
311 }
312 return nullptr;
313}
314
Michael Wrightd02c5b62014-02-10 15:10:22 -0800315void InputReader::timeoutExpiredLocked(nsecs_t when) {
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000316 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000317 std::shared_ptr<InputDevice>& device = devicePair.second;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800318 if (!device->isIgnored()) {
319 device->timeoutExpired(when);
320 }
321 }
322}
323
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800324int32_t InputReader::nextInputDeviceIdLocked() {
325 return ++mNextInputDeviceId;
326}
327
Michael Wrightd02c5b62014-02-10 15:10:22 -0800328void InputReader::handleConfigurationChangedLocked(nsecs_t when) {
329 // Reset global meta state because it depends on the list of all configured devices.
330 updateGlobalMetaStateLocked();
331
332 // Enqueue configuration changed.
Garfield Tan6a5a14e2020-01-28 13:24:04 -0800333 NotifyConfigurationChangedArgs args(mContext.getNextId(), when);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800334 mQueuedListener->notifyConfigurationChanged(&args);
335}
336
337void InputReader::refreshConfigurationLocked(uint32_t changes) {
338 mPolicy->getReaderConfiguration(&mConfig);
339 mEventHub->setExcludedDevices(mConfig.excludedDeviceNames);
340
Prabir Pradhan7e186182020-11-10 13:56:45 -0800341 if (!changes) return;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800342
Prabir Pradhan7e186182020-11-10 13:56:45 -0800343 ALOGI("Reconfiguring input devices, changes=%s",
344 InputReaderConfiguration::changesToString(changes).c_str());
345 nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
Prabir Pradhanc7ef27e2020-02-03 19:19:15 -0800346
Prabir Pradhan7e186182020-11-10 13:56:45 -0800347 if (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO) {
348 updatePointerDisplayLocked();
349 }
350
351 if (changes & InputReaderConfiguration::CHANGE_MUST_REOPEN) {
352 mEventHub->requestReopenDevices();
353 } else {
354 for (auto& devicePair : mDevices) {
355 std::shared_ptr<InputDevice>& device = devicePair.second;
356 device->configure(now, &mConfig, changes);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800357 }
358 }
Prabir Pradhan7e186182020-11-10 13:56:45 -0800359
360 if (changes & InputReaderConfiguration::CHANGE_POINTER_CAPTURE) {
361 const NotifyPointerCaptureChangedArgs args(mContext.getNextId(), now,
362 mConfig.pointerCapture);
363 mQueuedListener->notifyPointerCaptureChanged(&args);
364 }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800365}
366
367void InputReader::updateGlobalMetaStateLocked() {
368 mGlobalMetaState = 0;
369
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000370 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000371 std::shared_ptr<InputDevice>& device = devicePair.second;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800372 mGlobalMetaState |= device->getMetaState();
373 }
374}
375
376int32_t InputReader::getGlobalMetaStateLocked() {
377 return mGlobalMetaState;
378}
379
arthurhungc903df12020-08-11 15:08:42 +0800380void InputReader::updateLedMetaStateLocked(int32_t metaState) {
381 mLedMetaState = metaState;
382 for (auto& devicePair : mDevices) {
383 std::shared_ptr<InputDevice>& device = devicePair.second;
384 device->updateLedState(false);
385 }
386}
387
388int32_t InputReader::getLedMetaStateLocked() {
389 return mLedMetaState;
390}
391
Michael Wright842500e2015-03-13 17:32:02 -0700392void InputReader::notifyExternalStylusPresenceChanged() {
393 refreshConfigurationLocked(InputReaderConfiguration::CHANGE_EXTERNAL_STYLUS_PRESENCE);
394}
395
Arthur Hung7c3ae9c2019-03-11 11:23:03 +0800396void InputReader::getExternalStylusDevicesLocked(std::vector<InputDeviceInfo>& outDevices) {
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000397 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000398 std::shared_ptr<InputDevice>& device = devicePair.second;
Chris Ye1b0c7342020-07-28 21:57:03 -0700399 if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS) && !device->isIgnored()) {
Arthur Hung7c3ae9c2019-03-11 11:23:03 +0800400 InputDeviceInfo info;
401 device->getDeviceInfo(&info);
402 outDevices.push_back(info);
Michael Wright842500e2015-03-13 17:32:02 -0700403 }
404 }
405}
406
407void InputReader::dispatchExternalStylusState(const StylusState& state) {
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000408 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000409 std::shared_ptr<InputDevice>& device = devicePair.second;
Michael Wright842500e2015-03-13 17:32:02 -0700410 device->updateExternalStylusState(state);
411 }
412}
413
Michael Wrightd02c5b62014-02-10 15:10:22 -0800414void InputReader::disableVirtualKeysUntilLocked(nsecs_t time) {
415 mDisableVirtualKeysTimeout = time;
416}
417
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800418bool InputReader::shouldDropVirtualKeyLocked(nsecs_t now, int32_t keyCode, int32_t scanCode) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800419 if (now < mDisableVirtualKeysTimeout) {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800420 ALOGI("Dropping virtual key from device because virtual keys are "
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700421 "temporarily disabled for the next %0.3fms. keyCode=%d, scanCode=%d",
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800422 (mDisableVirtualKeysTimeout - now) * 0.000001, keyCode, scanCode);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800423 return true;
424 } else {
425 return false;
426 }
427}
428
Michael Wright17db18e2020-06-26 20:51:44 +0100429std::shared_ptr<PointerControllerInterface> InputReader::getPointerControllerLocked(
430 int32_t deviceId) {
431 std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock();
Prabir Pradhanc7ef27e2020-02-03 19:19:15 -0800432 if (controller == nullptr) {
433 controller = mPolicy->obtainPointerController(deviceId);
434 mPointerController = controller;
435 updatePointerDisplayLocked();
436 }
437 return controller;
438}
439
440void InputReader::updatePointerDisplayLocked() {
Michael Wright17db18e2020-06-26 20:51:44 +0100441 std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock();
Prabir Pradhanc7ef27e2020-02-03 19:19:15 -0800442 if (controller == nullptr) {
443 return;
444 }
445
446 std::optional<DisplayViewport> viewport =
447 mConfig.getDisplayViewportById(mConfig.defaultPointerDisplayId);
448 if (!viewport) {
449 ALOGW("Can't find the designated viewport with ID %" PRId32 " to update cursor input "
450 "mapper. Fall back to default display",
451 mConfig.defaultPointerDisplayId);
452 viewport = mConfig.getDisplayViewportById(ADISPLAY_ID_DEFAULT);
453 }
454 if (!viewport) {
455 ALOGE("Still can't find a viable viewport to update cursor input mapper. Skip setting it to"
456 " PointerController.");
457 return;
458 }
459
460 controller->setDisplayViewport(*viewport);
461}
462
Michael Wrightd02c5b62014-02-10 15:10:22 -0800463void InputReader::fadePointerLocked() {
Michael Wright17db18e2020-06-26 20:51:44 +0100464 std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock();
Prabir Pradhanc7ef27e2020-02-03 19:19:15 -0800465 if (controller != nullptr) {
Michael Wrightca5bede2020-07-02 00:00:29 +0100466 controller->fade(PointerControllerInterface::Transition::GRADUAL);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800467 }
468}
469
470void InputReader::requestTimeoutAtTimeLocked(nsecs_t when) {
471 if (when < mNextTimeout) {
472 mNextTimeout = when;
473 mEventHub->wake();
474 }
475}
476
477int32_t InputReader::bumpGenerationLocked() {
478 return ++mGeneration;
479}
480
Chris Ye98d3f532020-10-01 21:48:59 -0700481std::vector<InputDeviceInfo> InputReader::getInputDevices() const {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800482 AutoMutex _l(mLock);
Chris Ye98d3f532020-10-01 21:48:59 -0700483 return getInputDevicesLocked();
Michael Wrightd02c5b62014-02-10 15:10:22 -0800484}
485
Chris Ye98d3f532020-10-01 21:48:59 -0700486std::vector<InputDeviceInfo> InputReader::getInputDevicesLocked() const {
487 std::vector<InputDeviceInfo> outInputDevices;
488 outInputDevices.reserve(mDeviceToEventHubIdsMap.size());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800489
Chris Yee7310032020-09-22 15:36:28 -0700490 for (const auto& [device, eventHubIds] : mDeviceToEventHubIdsMap) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800491 if (!device->isIgnored()) {
Arthur Hung7c3ae9c2019-03-11 11:23:03 +0800492 InputDeviceInfo info;
493 device->getDeviceInfo(&info);
494 outInputDevices.push_back(info);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800495 }
496 }
Chris Ye98d3f532020-10-01 21:48:59 -0700497 return outInputDevices;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800498}
499
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700500int32_t InputReader::getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800501 AutoMutex _l(mLock);
502
503 return getStateLocked(deviceId, sourceMask, keyCode, &InputDevice::getKeyCodeState);
504}
505
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700506int32_t InputReader::getScanCodeState(int32_t deviceId, uint32_t sourceMask, int32_t scanCode) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800507 AutoMutex _l(mLock);
508
509 return getStateLocked(deviceId, sourceMask, scanCode, &InputDevice::getScanCodeState);
510}
511
512int32_t InputReader::getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t switchCode) {
513 AutoMutex _l(mLock);
514
515 return getStateLocked(deviceId, sourceMask, switchCode, &InputDevice::getSwitchState);
516}
517
518int32_t InputReader::getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code,
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700519 GetStateFunc getStateFunc) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800520 int32_t result = AKEY_STATE_UNKNOWN;
521 if (deviceId >= 0) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800522 InputDevice* device = findInputDevice(deviceId);
523 if (device && !device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
524 result = (device->*getStateFunc)(sourceMask, code);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800525 }
526 } else {
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000527 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000528 std::shared_ptr<InputDevice>& device = devicePair.second;
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700529 if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800530 // If any device reports AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL, return that
531 // value. Otherwise, return AKEY_STATE_UP as long as one device reports it.
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000532 int32_t currentResult = (device.get()->*getStateFunc)(sourceMask, code);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800533 if (currentResult >= AKEY_STATE_DOWN) {
534 return currentResult;
535 } else if (currentResult == AKEY_STATE_UP) {
536 result = currentResult;
537 }
538 }
539 }
540 }
541 return result;
542}
543
Andrii Kulian763a3a42016-03-08 10:46:16 -0800544void InputReader::toggleCapsLockState(int32_t deviceId) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800545 InputDevice* device = findInputDevice(deviceId);
546 if (!device) {
Andrii Kulian763a3a42016-03-08 10:46:16 -0800547 ALOGW("Ignoring toggleCapsLock for unknown deviceId %" PRId32 ".", deviceId);
548 return;
549 }
550
Andrii Kulian763a3a42016-03-08 10:46:16 -0800551 if (device->isIgnored()) {
552 return;
553 }
554
555 device->updateMetaState(AKEYCODE_CAPS_LOCK);
556}
557
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700558bool InputReader::hasKeys(int32_t deviceId, uint32_t sourceMask, size_t numCodes,
559 const int32_t* keyCodes, uint8_t* outFlags) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800560 AutoMutex _l(mLock);
561
562 memset(outFlags, 0, numCodes);
563 return markSupportedKeyCodesLocked(deviceId, sourceMask, numCodes, keyCodes, outFlags);
564}
565
566bool InputReader::markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask,
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700567 size_t numCodes, const int32_t* keyCodes,
568 uint8_t* outFlags) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800569 bool result = false;
570 if (deviceId >= 0) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800571 InputDevice* device = findInputDevice(deviceId);
572 if (device && !device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
573 result = device->markSupportedKeyCodes(sourceMask, numCodes, keyCodes, outFlags);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800574 }
575 } else {
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000576 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000577 std::shared_ptr<InputDevice>& device = devicePair.second;
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700578 if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
579 result |= device->markSupportedKeyCodes(sourceMask, numCodes, keyCodes, outFlags);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800580 }
581 }
582 }
583 return result;
584}
585
586void InputReader::requestRefreshConfiguration(uint32_t changes) {
587 AutoMutex _l(mLock);
588
589 if (changes) {
590 bool needWake = !mConfigurationChangesToRefresh;
591 mConfigurationChangesToRefresh |= changes;
592
593 if (needWake) {
594 mEventHub->wake();
595 }
596 }
597}
598
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +0000599void InputReader::vibrate(int32_t deviceId, const std::vector<VibrationElement>& pattern,
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700600 ssize_t repeat, int32_t token) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800601 AutoMutex _l(mLock);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800602 InputDevice* device = findInputDevice(deviceId);
603 if (device) {
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +0000604 device->vibrate(pattern, repeat, token);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800605 }
606}
607
608void InputReader::cancelVibrate(int32_t deviceId, int32_t token) {
609 AutoMutex _l(mLock);
610
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800611 InputDevice* device = findInputDevice(deviceId);
612 if (device) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800613 device->cancelVibrate(token);
614 }
615}
616
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700617bool InputReader::isInputDeviceEnabled(int32_t deviceId) {
618 AutoMutex _l(mLock);
619
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800620 InputDevice* device = findInputDevice(deviceId);
621 if (device) {
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700622 return device->isEnabled();
623 }
624 ALOGW("Ignoring invalid device id %" PRId32 ".", deviceId);
625 return false;
626}
627
Arthur Hungc23540e2018-11-29 20:42:11 +0800628bool InputReader::canDispatchToDisplay(int32_t deviceId, int32_t displayId) {
629 AutoMutex _l(mLock);
630
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800631 InputDevice* device = findInputDevice(deviceId);
632 if (!device) {
Arthur Hungc23540e2018-11-29 20:42:11 +0800633 ALOGW("Ignoring invalid device id %" PRId32 ".", deviceId);
634 return false;
635 }
636
Arthur Hung2c9a3342019-07-23 14:18:59 +0800637 if (!device->isEnabled()) {
638 ALOGW("Ignoring disabled device %s", device->getName().c_str());
639 return false;
640 }
641
642 std::optional<int32_t> associatedDisplayId = device->getAssociatedDisplayId();
Arthur Hungc23540e2018-11-29 20:42:11 +0800643 // No associated display. By default, can dispatch to all displays.
644 if (!associatedDisplayId) {
645 return true;
646 }
647
648 if (*associatedDisplayId == ADISPLAY_ID_NONE) {
Arthur Hung2c9a3342019-07-23 14:18:59 +0800649 ALOGW("Device %s is associated with display ADISPLAY_ID_NONE.", device->getName().c_str());
Arthur Hungc23540e2018-11-29 20:42:11 +0800650 return true;
651 }
652
653 return *associatedDisplayId == displayId;
654}
655
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800656void InputReader::dump(std::string& dump) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800657 AutoMutex _l(mLock);
658
659 mEventHub->dump(dump);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800660 dump += "\n";
Michael Wrightd02c5b62014-02-10 15:10:22 -0800661
Chris Yee7310032020-09-22 15:36:28 -0700662 dump += StringPrintf("Input Reader State (Nums of device: %zu):\n",
663 mDeviceToEventHubIdsMap.size());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800664
Chris Yee7310032020-09-22 15:36:28 -0700665 for (const auto& devicePair : mDeviceToEventHubIdsMap) {
666 const std::shared_ptr<InputDevice>& device = devicePair.first;
667 std::string eventHubDevStr = INDENT "EventHub Devices: [ ";
668 for (const auto& eId : devicePair.second) {
669 eventHubDevStr += StringPrintf("%d ", eId);
670 }
671 eventHubDevStr += "] \n";
672 device->dump(dump, eventHubDevStr);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800673 }
674
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800675 dump += INDENT "Configuration:\n";
676 dump += INDENT2 "ExcludedDeviceNames: [";
Michael Wrightd02c5b62014-02-10 15:10:22 -0800677 for (size_t i = 0; i < mConfig.excludedDeviceNames.size(); i++) {
678 if (i != 0) {
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800679 dump += ", ";
Michael Wrightd02c5b62014-02-10 15:10:22 -0800680 }
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100681 dump += mConfig.excludedDeviceNames[i];
Michael Wrightd02c5b62014-02-10 15:10:22 -0800682 }
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800683 dump += "]\n";
684 dump += StringPrintf(INDENT2 "VirtualKeyQuietTime: %0.1fms\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700685 mConfig.virtualKeyQuietTime * 0.000001f);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800686
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800687 dump += StringPrintf(INDENT2 "PointerVelocityControlParameters: "
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700688 "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, "
689 "acceleration=%0.3f\n",
690 mConfig.pointerVelocityControlParameters.scale,
691 mConfig.pointerVelocityControlParameters.lowThreshold,
692 mConfig.pointerVelocityControlParameters.highThreshold,
693 mConfig.pointerVelocityControlParameters.acceleration);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800694
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800695 dump += StringPrintf(INDENT2 "WheelVelocityControlParameters: "
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700696 "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, "
697 "acceleration=%0.3f\n",
698 mConfig.wheelVelocityControlParameters.scale,
699 mConfig.wheelVelocityControlParameters.lowThreshold,
700 mConfig.wheelVelocityControlParameters.highThreshold,
701 mConfig.wheelVelocityControlParameters.acceleration);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800702
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800703 dump += StringPrintf(INDENT2 "PointerGesture:\n");
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700704 dump += StringPrintf(INDENT3 "Enabled: %s\n", toString(mConfig.pointerGesturesEnabled));
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800705 dump += StringPrintf(INDENT3 "QuietInterval: %0.1fms\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700706 mConfig.pointerGestureQuietInterval * 0.000001f);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800707 dump += StringPrintf(INDENT3 "DragMinSwitchSpeed: %0.1fpx/s\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700708 mConfig.pointerGestureDragMinSwitchSpeed);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800709 dump += StringPrintf(INDENT3 "TapInterval: %0.1fms\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700710 mConfig.pointerGestureTapInterval * 0.000001f);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800711 dump += StringPrintf(INDENT3 "TapDragInterval: %0.1fms\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700712 mConfig.pointerGestureTapDragInterval * 0.000001f);
713 dump += StringPrintf(INDENT3 "TapSlop: %0.1fpx\n", mConfig.pointerGestureTapSlop);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800714 dump += StringPrintf(INDENT3 "MultitouchSettleInterval: %0.1fms\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700715 mConfig.pointerGestureMultitouchSettleInterval * 0.000001f);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800716 dump += StringPrintf(INDENT3 "MultitouchMinDistance: %0.1fpx\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700717 mConfig.pointerGestureMultitouchMinDistance);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800718 dump += StringPrintf(INDENT3 "SwipeTransitionAngleCosine: %0.1f\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700719 mConfig.pointerGestureSwipeTransitionAngleCosine);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800720 dump += StringPrintf(INDENT3 "SwipeMaxWidthRatio: %0.1f\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700721 mConfig.pointerGestureSwipeMaxWidthRatio);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800722 dump += StringPrintf(INDENT3 "MovementSpeedRatio: %0.1f\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700723 mConfig.pointerGestureMovementSpeedRatio);
724 dump += StringPrintf(INDENT3 "ZoomSpeedRatio: %0.1f\n", mConfig.pointerGestureZoomSpeedRatio);
Santos Cordonfa5cf462017-04-05 10:37:00 -0700725
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800726 dump += INDENT3 "Viewports:\n";
Santos Cordonfa5cf462017-04-05 10:37:00 -0700727 mConfig.dump(dump);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800728}
729
730void InputReader::monitor() {
731 // Acquire and release the lock to ensure that the reader has not deadlocked.
732 mLock.lock();
733 mEventHub->wake();
734 mReaderIsAliveCondition.wait(mLock);
735 mLock.unlock();
736
737 // Check the EventHub
738 mEventHub->monitor();
739}
740
Michael Wrightd02c5b62014-02-10 15:10:22 -0800741// --- InputReader::ContextImpl ---
742
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800743InputReader::ContextImpl::ContextImpl(InputReader* reader)
744 : mReader(reader), mIdGenerator(IdGenerator::Source::INPUT_READER) {}
Michael Wrightd02c5b62014-02-10 15:10:22 -0800745
746void InputReader::ContextImpl::updateGlobalMetaState() {
747 // lock is already held by the input loop
748 mReader->updateGlobalMetaStateLocked();
749}
750
751int32_t InputReader::ContextImpl::getGlobalMetaState() {
752 // lock is already held by the input loop
753 return mReader->getGlobalMetaStateLocked();
754}
755
arthurhungc903df12020-08-11 15:08:42 +0800756void InputReader::ContextImpl::updateLedMetaState(int32_t metaState) {
757 // lock is already held by the input loop
758 mReader->updateLedMetaStateLocked(metaState);
759}
760
761int32_t InputReader::ContextImpl::getLedMetaState() {
762 // lock is already held by the input loop
763 return mReader->getLedMetaStateLocked();
764}
765
Michael Wrightd02c5b62014-02-10 15:10:22 -0800766void InputReader::ContextImpl::disableVirtualKeysUntil(nsecs_t time) {
767 // lock is already held by the input loop
768 mReader->disableVirtualKeysUntilLocked(time);
769}
770
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800771bool InputReader::ContextImpl::shouldDropVirtualKey(nsecs_t now, int32_t keyCode,
772 int32_t scanCode) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800773 // lock is already held by the input loop
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800774 return mReader->shouldDropVirtualKeyLocked(now, keyCode, scanCode);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800775}
776
777void InputReader::ContextImpl::fadePointer() {
778 // lock is already held by the input loop
779 mReader->fadePointerLocked();
780}
781
Michael Wright17db18e2020-06-26 20:51:44 +0100782std::shared_ptr<PointerControllerInterface> InputReader::ContextImpl::getPointerController(
783 int32_t deviceId) {
Prabir Pradhanc7ef27e2020-02-03 19:19:15 -0800784 // lock is already held by the input loop
785 return mReader->getPointerControllerLocked(deviceId);
786}
787
Michael Wrightd02c5b62014-02-10 15:10:22 -0800788void InputReader::ContextImpl::requestTimeoutAtTime(nsecs_t when) {
789 // lock is already held by the input loop
790 mReader->requestTimeoutAtTimeLocked(when);
791}
792
793int32_t InputReader::ContextImpl::bumpGeneration() {
794 // lock is already held by the input loop
795 return mReader->bumpGenerationLocked();
796}
797
Arthur Hung7c3ae9c2019-03-11 11:23:03 +0800798void InputReader::ContextImpl::getExternalStylusDevices(std::vector<InputDeviceInfo>& outDevices) {
Michael Wright842500e2015-03-13 17:32:02 -0700799 // lock is already held by whatever called refreshConfigurationLocked
800 mReader->getExternalStylusDevicesLocked(outDevices);
801}
802
803void InputReader::ContextImpl::dispatchExternalStylusState(const StylusState& state) {
804 mReader->dispatchExternalStylusState(state);
805}
806
Michael Wrightd02c5b62014-02-10 15:10:22 -0800807InputReaderPolicyInterface* InputReader::ContextImpl::getPolicy() {
808 return mReader->mPolicy.get();
809}
810
811InputListenerInterface* InputReader::ContextImpl::getListener() {
812 return mReader->mQueuedListener.get();
813}
814
815EventHubInterface* InputReader::ContextImpl::getEventHub() {
816 return mReader->mEventHub.get();
817}
818
Garfield Tan6a5a14e2020-01-28 13:24:04 -0800819int32_t InputReader::ContextImpl::getNextId() {
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800820 return mIdGenerator.nextId();
Prabir Pradhan42611e02018-11-27 14:04:02 -0800821}
Michael Wrightd02c5b62014-02-10 15:10:22 -0800822
Michael Wrightd02c5b62014-02-10 15:10:22 -0800823} // namespace android