blob: 7c96e5413f25d8b84890de35473064c92bdef933 [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;
Arthur Hung7c3ae9c2019-03-11 11:23:03 +080090 std::vector<InputDeviceInfo> inputDevices;
Michael Wrightd02c5b62014-02-10 15:10:22 -080091 { // acquire lock
92 AutoMutex _l(mLock);
93
94 oldGeneration = mGeneration;
95 timeoutMillis = -1;
96
97 uint32_t changes = mConfigurationChangesToRefresh;
98 if (changes) {
99 mConfigurationChangesToRefresh = 0;
100 timeoutMillis = 0;
101 refreshConfigurationLocked(changes);
102 } else if (mNextTimeout != LLONG_MAX) {
103 nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
104 timeoutMillis = toMillisecondTimeoutDelay(now, mNextTimeout);
105 }
106 } // release lock
107
108 size_t count = mEventHub->getEvents(timeoutMillis, mEventBuffer, EVENT_BUFFER_SIZE);
109
110 { // acquire lock
111 AutoMutex _l(mLock);
112 mReaderIsAliveCondition.broadcast();
113
114 if (count) {
115 processEventsLocked(mEventBuffer, count);
116 }
117
118 if (mNextTimeout != LLONG_MAX) {
119 nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
120 if (now >= mNextTimeout) {
121#if DEBUG_RAW_EVENTS
122 ALOGD("Timeout expired, latency=%0.3fms", (now - mNextTimeout) * 0.000001f);
123#endif
124 mNextTimeout = LLONG_MAX;
125 timeoutExpiredLocked(now);
126 }
127 }
128
129 if (oldGeneration != mGeneration) {
130 inputDevicesChanged = true;
131 getInputDevicesLocked(inputDevices);
132 }
133 } // release lock
134
135 // Send out a message that the describes the changed input devices.
136 if (inputDevicesChanged) {
137 mPolicy->notifyInputDevicesChanged(inputDevices);
138 }
139
140 // Flush queued events out to the listener.
141 // This must happen outside of the lock because the listener could potentially call
142 // back into the InputReader's methods, such as getScanCodeState, or become blocked
143 // on another thread similarly waiting to acquire the InputReader lock thereby
144 // resulting in a deadlock. This situation is actually quite plausible because the
145 // listener is actually the input dispatcher, which calls into the window manager,
146 // which occasionally calls into the input reader.
147 mQueuedListener->flush();
148}
149
150void InputReader::processEventsLocked(const RawEvent* rawEvents, size_t count) {
151 for (const RawEvent* rawEvent = rawEvents; count;) {
152 int32_t type = rawEvent->type;
153 size_t batchSize = 1;
154 if (type < EventHubInterface::FIRST_SYNTHETIC_EVENT) {
155 int32_t deviceId = rawEvent->deviceId;
156 while (batchSize < count) {
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700157 if (rawEvent[batchSize].type >= EventHubInterface::FIRST_SYNTHETIC_EVENT ||
158 rawEvent[batchSize].deviceId != deviceId) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800159 break;
160 }
161 batchSize += 1;
162 }
163#if DEBUG_RAW_EVENTS
Siarhei Vishniakou5d83f602017-09-12 12:40:29 -0700164 ALOGD("BatchSize: %zu Count: %zu", batchSize, count);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800165#endif
166 processEventsForDeviceLocked(deviceId, rawEvent, batchSize);
167 } else {
168 switch (rawEvent->type) {
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700169 case EventHubInterface::DEVICE_ADDED:
170 addDeviceLocked(rawEvent->when, rawEvent->deviceId);
171 break;
172 case EventHubInterface::DEVICE_REMOVED:
173 removeDeviceLocked(rawEvent->when, rawEvent->deviceId);
174 break;
175 case EventHubInterface::FINISHED_DEVICE_SCAN:
176 handleConfigurationChangedLocked(rawEvent->when);
177 break;
178 default:
179 ALOG_ASSERT(false); // can't happen
180 break;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800181 }
182 }
183 count -= batchSize;
184 rawEvent += batchSize;
185 }
186}
187
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800188void InputReader::addDeviceLocked(nsecs_t when, int32_t eventHubId) {
189 if (mDevices.find(eventHubId) != mDevices.end()) {
190 ALOGW("Ignoring spurious device added event for eventHubId %d.", eventHubId);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800191 return;
192 }
193
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800194 InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(eventHubId);
195 std::shared_ptr<InputDevice> device = createDeviceLocked(eventHubId, identifier);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800196 device->configure(when, &mConfig, 0);
197 device->reset(when);
198
199 if (device->isIgnored()) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800200 ALOGI("Device added: id=%d, eventHubId=%d, name='%s', descriptor='%s' "
201 "(ignored non-input device)",
202 device->getId(), eventHubId, identifier.name.c_str(), identifier.descriptor.c_str());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800203 } else {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800204 ALOGI("Device added: id=%d, eventHubId=%d, name='%s', descriptor='%s',sources=0x%08x",
205 device->getId(), eventHubId, identifier.name.c_str(), identifier.descriptor.c_str(),
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700206 device->getSources());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800207 }
208
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800209 mDevices.emplace(eventHubId, device);
Chris Yee7310032020-09-22 15:36:28 -0700210 // Add device to device to EventHub ids map.
211 const auto mapIt = mDeviceToEventHubIdsMap.find(device);
212 if (mapIt == mDeviceToEventHubIdsMap.end()) {
213 std::vector<int32_t> ids = {eventHubId};
214 mDeviceToEventHubIdsMap.emplace(device, ids);
215 } else {
216 mapIt->second.push_back(eventHubId);
217 }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800218 bumpGenerationLocked();
Michael Wright842500e2015-03-13 17:32:02 -0700219
Chris Ye1b0c7342020-07-28 21:57:03 -0700220 if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS)) {
Michael Wright842500e2015-03-13 17:32:02 -0700221 notifyExternalStylusPresenceChanged();
222 }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800223}
224
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800225void InputReader::removeDeviceLocked(nsecs_t when, int32_t eventHubId) {
226 auto deviceIt = mDevices.find(eventHubId);
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000227 if (deviceIt == mDevices.end()) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800228 ALOGW("Ignoring spurious device removed event for eventHubId %d.", eventHubId);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800229 return;
230 }
231
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000232 std::shared_ptr<InputDevice> device = std::move(deviceIt->second);
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000233 mDevices.erase(deviceIt);
Chris Yee7310032020-09-22 15:36:28 -0700234 // Erase device from device to EventHub ids map.
235 auto mapIt = mDeviceToEventHubIdsMap.find(device);
236 if (mapIt != mDeviceToEventHubIdsMap.end()) {
237 std::vector<int32_t>& eventHubIds = mapIt->second;
238 eventHubIds.erase(std::remove_if(eventHubIds.begin(), eventHubIds.end(),
239 [eventHubId](int32_t eId) { return eId == eventHubId; }),
240 eventHubIds.end());
241 if (eventHubIds.size() == 0) {
242 mDeviceToEventHubIdsMap.erase(mapIt);
243 }
244 }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800245 bumpGenerationLocked();
246
247 if (device->isIgnored()) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800248 ALOGI("Device removed: id=%d, eventHubId=%d, name='%s', descriptor='%s' "
249 "(ignored non-input device)",
250 device->getId(), eventHubId, device->getName().c_str(),
251 device->getDescriptor().c_str());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800252 } else {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800253 ALOGI("Device removed: id=%d, eventHubId=%d, name='%s', descriptor='%s', sources=0x%08x",
254 device->getId(), eventHubId, device->getName().c_str(),
255 device->getDescriptor().c_str(), device->getSources());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800256 }
257
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800258 device->removeEventHubDevice(eventHubId);
259
Chris Ye1b0c7342020-07-28 21:57:03 -0700260 if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS)) {
Michael Wright842500e2015-03-13 17:32:02 -0700261 notifyExternalStylusPresenceChanged();
262 }
263
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800264 if (device->hasEventHubDevices()) {
265 device->configure(when, &mConfig, 0);
266 }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800267 device->reset(when);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800268}
269
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000270std::shared_ptr<InputDevice> InputReader::createDeviceLocked(
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800271 int32_t eventHubId, const InputDeviceIdentifier& identifier) {
272 auto deviceIt = std::find_if(mDevices.begin(), mDevices.end(), [identifier](auto& devicePair) {
273 return devicePair.second->getDescriptor().size() && identifier.descriptor.size() &&
274 devicePair.second->getDescriptor() == identifier.descriptor;
275 });
276
277 std::shared_ptr<InputDevice> device;
278 if (deviceIt != mDevices.end()) {
279 device = deviceIt->second;
280 } else {
281 int32_t deviceId = (eventHubId < END_RESERVED_ID) ? eventHubId : nextInputDeviceIdLocked();
282 device = std::make_shared<InputDevice>(&mContext, deviceId, bumpGenerationLocked(),
283 identifier);
284 }
285 device->addEventHubDevice(eventHubId);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800286 return device;
287}
288
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800289void InputReader::processEventsForDeviceLocked(int32_t eventHubId, const RawEvent* rawEvents,
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700290 size_t count) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800291 auto deviceIt = mDevices.find(eventHubId);
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000292 if (deviceIt == mDevices.end()) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800293 ALOGW("Discarding event for unknown eventHubId %d.", eventHubId);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800294 return;
295 }
296
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000297 std::shared_ptr<InputDevice>& device = deviceIt->second;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800298 if (device->isIgnored()) {
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700299 // ALOGD("Discarding event for ignored deviceId %d.", deviceId);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800300 return;
301 }
302
303 device->process(rawEvents, count);
304}
305
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800306InputDevice* InputReader::findInputDevice(int32_t deviceId) {
307 auto deviceIt =
308 std::find_if(mDevices.begin(), mDevices.end(), [deviceId](const auto& devicePair) {
309 return devicePair.second->getId() == deviceId;
310 });
311 if (deviceIt != mDevices.end()) {
312 return deviceIt->second.get();
313 }
314 return nullptr;
315}
316
Michael Wrightd02c5b62014-02-10 15:10:22 -0800317void InputReader::timeoutExpiredLocked(nsecs_t when) {
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000318 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000319 std::shared_ptr<InputDevice>& device = devicePair.second;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800320 if (!device->isIgnored()) {
321 device->timeoutExpired(when);
322 }
323 }
324}
325
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800326int32_t InputReader::nextInputDeviceIdLocked() {
327 return ++mNextInputDeviceId;
328}
329
Michael Wrightd02c5b62014-02-10 15:10:22 -0800330void InputReader::handleConfigurationChangedLocked(nsecs_t when) {
331 // Reset global meta state because it depends on the list of all configured devices.
332 updateGlobalMetaStateLocked();
333
334 // Enqueue configuration changed.
Garfield Tan6a5a14e2020-01-28 13:24:04 -0800335 NotifyConfigurationChangedArgs args(mContext.getNextId(), when);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800336 mQueuedListener->notifyConfigurationChanged(&args);
337}
338
339void InputReader::refreshConfigurationLocked(uint32_t changes) {
340 mPolicy->getReaderConfiguration(&mConfig);
341 mEventHub->setExcludedDevices(mConfig.excludedDeviceNames);
342
343 if (changes) {
Siarhei Vishniakouc5ae0dc2019-07-10 15:51:18 -0700344 ALOGI("Reconfiguring input devices, changes=%s",
345 InputReaderConfiguration::changesToString(changes).c_str());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800346 nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
347
Prabir Pradhanc7ef27e2020-02-03 19:19:15 -0800348 if (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO) {
349 updatePointerDisplayLocked();
350 }
351
Michael Wrightd02c5b62014-02-10 15:10:22 -0800352 if (changes & InputReaderConfiguration::CHANGE_MUST_REOPEN) {
353 mEventHub->requestReopenDevices();
354 } else {
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000355 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000356 std::shared_ptr<InputDevice>& device = devicePair.second;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800357 device->configure(now, &mConfig, changes);
358 }
359 }
360 }
361}
362
363void InputReader::updateGlobalMetaStateLocked() {
364 mGlobalMetaState = 0;
365
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000366 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000367 std::shared_ptr<InputDevice>& device = devicePair.second;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800368 mGlobalMetaState |= device->getMetaState();
369 }
370}
371
372int32_t InputReader::getGlobalMetaStateLocked() {
373 return mGlobalMetaState;
374}
375
arthurhungc903df12020-08-11 15:08:42 +0800376void InputReader::updateLedMetaStateLocked(int32_t metaState) {
377 mLedMetaState = metaState;
378 for (auto& devicePair : mDevices) {
379 std::shared_ptr<InputDevice>& device = devicePair.second;
380 device->updateLedState(false);
381 }
382}
383
384int32_t InputReader::getLedMetaStateLocked() {
385 return mLedMetaState;
386}
387
Michael Wright842500e2015-03-13 17:32:02 -0700388void InputReader::notifyExternalStylusPresenceChanged() {
389 refreshConfigurationLocked(InputReaderConfiguration::CHANGE_EXTERNAL_STYLUS_PRESENCE);
390}
391
Arthur Hung7c3ae9c2019-03-11 11:23:03 +0800392void InputReader::getExternalStylusDevicesLocked(std::vector<InputDeviceInfo>& outDevices) {
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000393 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000394 std::shared_ptr<InputDevice>& device = devicePair.second;
Chris Ye1b0c7342020-07-28 21:57:03 -0700395 if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS) && !device->isIgnored()) {
Arthur Hung7c3ae9c2019-03-11 11:23:03 +0800396 InputDeviceInfo info;
397 device->getDeviceInfo(&info);
398 outDevices.push_back(info);
Michael Wright842500e2015-03-13 17:32:02 -0700399 }
400 }
401}
402
403void InputReader::dispatchExternalStylusState(const StylusState& state) {
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000404 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000405 std::shared_ptr<InputDevice>& device = devicePair.second;
Michael Wright842500e2015-03-13 17:32:02 -0700406 device->updateExternalStylusState(state);
407 }
408}
409
Michael Wrightd02c5b62014-02-10 15:10:22 -0800410void InputReader::disableVirtualKeysUntilLocked(nsecs_t time) {
411 mDisableVirtualKeysTimeout = time;
412}
413
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800414bool InputReader::shouldDropVirtualKeyLocked(nsecs_t now, int32_t keyCode, int32_t scanCode) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800415 if (now < mDisableVirtualKeysTimeout) {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800416 ALOGI("Dropping virtual key from device because virtual keys are "
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700417 "temporarily disabled for the next %0.3fms. keyCode=%d, scanCode=%d",
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800418 (mDisableVirtualKeysTimeout - now) * 0.000001, keyCode, scanCode);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800419 return true;
420 } else {
421 return false;
422 }
423}
424
Michael Wright17db18e2020-06-26 20:51:44 +0100425std::shared_ptr<PointerControllerInterface> InputReader::getPointerControllerLocked(
426 int32_t deviceId) {
427 std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock();
Prabir Pradhanc7ef27e2020-02-03 19:19:15 -0800428 if (controller == nullptr) {
429 controller = mPolicy->obtainPointerController(deviceId);
430 mPointerController = controller;
431 updatePointerDisplayLocked();
432 }
433 return controller;
434}
435
436void InputReader::updatePointerDisplayLocked() {
Michael Wright17db18e2020-06-26 20:51:44 +0100437 std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock();
Prabir Pradhanc7ef27e2020-02-03 19:19:15 -0800438 if (controller == nullptr) {
439 return;
440 }
441
442 std::optional<DisplayViewport> viewport =
443 mConfig.getDisplayViewportById(mConfig.defaultPointerDisplayId);
444 if (!viewport) {
445 ALOGW("Can't find the designated viewport with ID %" PRId32 " to update cursor input "
446 "mapper. Fall back to default display",
447 mConfig.defaultPointerDisplayId);
448 viewport = mConfig.getDisplayViewportById(ADISPLAY_ID_DEFAULT);
449 }
450 if (!viewport) {
451 ALOGE("Still can't find a viable viewport to update cursor input mapper. Skip setting it to"
452 " PointerController.");
453 return;
454 }
455
456 controller->setDisplayViewport(*viewport);
457}
458
Michael Wrightd02c5b62014-02-10 15:10:22 -0800459void InputReader::fadePointerLocked() {
Michael Wright17db18e2020-06-26 20:51:44 +0100460 std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock();
Prabir Pradhanc7ef27e2020-02-03 19:19:15 -0800461 if (controller != nullptr) {
Michael Wrightca5bede2020-07-02 00:00:29 +0100462 controller->fade(PointerControllerInterface::Transition::GRADUAL);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800463 }
464}
465
466void InputReader::requestTimeoutAtTimeLocked(nsecs_t when) {
467 if (when < mNextTimeout) {
468 mNextTimeout = when;
469 mEventHub->wake();
470 }
471}
472
473int32_t InputReader::bumpGenerationLocked() {
474 return ++mGeneration;
475}
476
Arthur Hung7c3ae9c2019-03-11 11:23:03 +0800477void InputReader::getInputDevices(std::vector<InputDeviceInfo>& outInputDevices) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800478 AutoMutex _l(mLock);
479 getInputDevicesLocked(outInputDevices);
480}
481
Arthur Hung7c3ae9c2019-03-11 11:23:03 +0800482void InputReader::getInputDevicesLocked(std::vector<InputDeviceInfo>& outInputDevices) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800483 outInputDevices.clear();
484
Chris Yee7310032020-09-22 15:36:28 -0700485 for (const auto& [device, eventHubIds] : mDeviceToEventHubIdsMap) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800486 if (!device->isIgnored()) {
Arthur Hung7c3ae9c2019-03-11 11:23:03 +0800487 InputDeviceInfo info;
488 device->getDeviceInfo(&info);
489 outInputDevices.push_back(info);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800490 }
491 }
492}
493
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700494int32_t InputReader::getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800495 AutoMutex _l(mLock);
496
497 return getStateLocked(deviceId, sourceMask, keyCode, &InputDevice::getKeyCodeState);
498}
499
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700500int32_t InputReader::getScanCodeState(int32_t deviceId, uint32_t sourceMask, int32_t scanCode) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800501 AutoMutex _l(mLock);
502
503 return getStateLocked(deviceId, sourceMask, scanCode, &InputDevice::getScanCodeState);
504}
505
506int32_t InputReader::getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t switchCode) {
507 AutoMutex _l(mLock);
508
509 return getStateLocked(deviceId, sourceMask, switchCode, &InputDevice::getSwitchState);
510}
511
512int32_t InputReader::getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code,
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700513 GetStateFunc getStateFunc) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800514 int32_t result = AKEY_STATE_UNKNOWN;
515 if (deviceId >= 0) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800516 InputDevice* device = findInputDevice(deviceId);
517 if (device && !device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
518 result = (device->*getStateFunc)(sourceMask, code);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800519 }
520 } else {
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000521 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000522 std::shared_ptr<InputDevice>& device = devicePair.second;
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700523 if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800524 // If any device reports AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL, return that
525 // value. Otherwise, return AKEY_STATE_UP as long as one device reports it.
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000526 int32_t currentResult = (device.get()->*getStateFunc)(sourceMask, code);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800527 if (currentResult >= AKEY_STATE_DOWN) {
528 return currentResult;
529 } else if (currentResult == AKEY_STATE_UP) {
530 result = currentResult;
531 }
532 }
533 }
534 }
535 return result;
536}
537
Andrii Kulian763a3a42016-03-08 10:46:16 -0800538void InputReader::toggleCapsLockState(int32_t deviceId) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800539 InputDevice* device = findInputDevice(deviceId);
540 if (!device) {
Andrii Kulian763a3a42016-03-08 10:46:16 -0800541 ALOGW("Ignoring toggleCapsLock for unknown deviceId %" PRId32 ".", deviceId);
542 return;
543 }
544
Andrii Kulian763a3a42016-03-08 10:46:16 -0800545 if (device->isIgnored()) {
546 return;
547 }
548
549 device->updateMetaState(AKEYCODE_CAPS_LOCK);
550}
551
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700552bool InputReader::hasKeys(int32_t deviceId, uint32_t sourceMask, size_t numCodes,
553 const int32_t* keyCodes, uint8_t* outFlags) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800554 AutoMutex _l(mLock);
555
556 memset(outFlags, 0, numCodes);
557 return markSupportedKeyCodesLocked(deviceId, sourceMask, numCodes, keyCodes, outFlags);
558}
559
560bool InputReader::markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask,
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700561 size_t numCodes, const int32_t* keyCodes,
562 uint8_t* outFlags) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800563 bool result = false;
564 if (deviceId >= 0) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800565 InputDevice* device = findInputDevice(deviceId);
566 if (device && !device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
567 result = device->markSupportedKeyCodes(sourceMask, numCodes, keyCodes, outFlags);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800568 }
569 } else {
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000570 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000571 std::shared_ptr<InputDevice>& device = devicePair.second;
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700572 if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
573 result |= device->markSupportedKeyCodes(sourceMask, numCodes, keyCodes, outFlags);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800574 }
575 }
576 }
577 return result;
578}
579
580void InputReader::requestRefreshConfiguration(uint32_t changes) {
581 AutoMutex _l(mLock);
582
583 if (changes) {
584 bool needWake = !mConfigurationChangesToRefresh;
585 mConfigurationChangesToRefresh |= changes;
586
587 if (needWake) {
588 mEventHub->wake();
589 }
590 }
591}
592
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +0000593void InputReader::vibrate(int32_t deviceId, const std::vector<VibrationElement>& pattern,
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700594 ssize_t repeat, int32_t token) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800595 AutoMutex _l(mLock);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800596 InputDevice* device = findInputDevice(deviceId);
597 if (device) {
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +0000598 device->vibrate(pattern, repeat, token);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800599 }
600}
601
602void InputReader::cancelVibrate(int32_t deviceId, int32_t token) {
603 AutoMutex _l(mLock);
604
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800605 InputDevice* device = findInputDevice(deviceId);
606 if (device) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800607 device->cancelVibrate(token);
608 }
609}
610
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700611bool InputReader::isInputDeviceEnabled(int32_t deviceId) {
612 AutoMutex _l(mLock);
613
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800614 InputDevice* device = findInputDevice(deviceId);
615 if (device) {
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700616 return device->isEnabled();
617 }
618 ALOGW("Ignoring invalid device id %" PRId32 ".", deviceId);
619 return false;
620}
621
Arthur Hungc23540e2018-11-29 20:42:11 +0800622bool InputReader::canDispatchToDisplay(int32_t deviceId, int32_t displayId) {
623 AutoMutex _l(mLock);
624
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800625 InputDevice* device = findInputDevice(deviceId);
626 if (!device) {
Arthur Hungc23540e2018-11-29 20:42:11 +0800627 ALOGW("Ignoring invalid device id %" PRId32 ".", deviceId);
628 return false;
629 }
630
Arthur Hung2c9a3342019-07-23 14:18:59 +0800631 if (!device->isEnabled()) {
632 ALOGW("Ignoring disabled device %s", device->getName().c_str());
633 return false;
634 }
635
636 std::optional<int32_t> associatedDisplayId = device->getAssociatedDisplayId();
Arthur Hungc23540e2018-11-29 20:42:11 +0800637 // No associated display. By default, can dispatch to all displays.
638 if (!associatedDisplayId) {
639 return true;
640 }
641
642 if (*associatedDisplayId == ADISPLAY_ID_NONE) {
Arthur Hung2c9a3342019-07-23 14:18:59 +0800643 ALOGW("Device %s is associated with display ADISPLAY_ID_NONE.", device->getName().c_str());
Arthur Hungc23540e2018-11-29 20:42:11 +0800644 return true;
645 }
646
647 return *associatedDisplayId == displayId;
648}
649
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800650void InputReader::dump(std::string& dump) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800651 AutoMutex _l(mLock);
652
653 mEventHub->dump(dump);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800654 dump += "\n";
Michael Wrightd02c5b62014-02-10 15:10:22 -0800655
Chris Yee7310032020-09-22 15:36:28 -0700656 dump += StringPrintf("Input Reader State (Nums of device: %zu):\n",
657 mDeviceToEventHubIdsMap.size());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800658
Chris Yee7310032020-09-22 15:36:28 -0700659 for (const auto& devicePair : mDeviceToEventHubIdsMap) {
660 const std::shared_ptr<InputDevice>& device = devicePair.first;
661 std::string eventHubDevStr = INDENT "EventHub Devices: [ ";
662 for (const auto& eId : devicePair.second) {
663 eventHubDevStr += StringPrintf("%d ", eId);
664 }
665 eventHubDevStr += "] \n";
666 device->dump(dump, eventHubDevStr);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800667 }
668
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800669 dump += INDENT "Configuration:\n";
670 dump += INDENT2 "ExcludedDeviceNames: [";
Michael Wrightd02c5b62014-02-10 15:10:22 -0800671 for (size_t i = 0; i < mConfig.excludedDeviceNames.size(); i++) {
672 if (i != 0) {
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800673 dump += ", ";
Michael Wrightd02c5b62014-02-10 15:10:22 -0800674 }
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100675 dump += mConfig.excludedDeviceNames[i];
Michael Wrightd02c5b62014-02-10 15:10:22 -0800676 }
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800677 dump += "]\n";
678 dump += StringPrintf(INDENT2 "VirtualKeyQuietTime: %0.1fms\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700679 mConfig.virtualKeyQuietTime * 0.000001f);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800680
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800681 dump += StringPrintf(INDENT2 "PointerVelocityControlParameters: "
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700682 "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, "
683 "acceleration=%0.3f\n",
684 mConfig.pointerVelocityControlParameters.scale,
685 mConfig.pointerVelocityControlParameters.lowThreshold,
686 mConfig.pointerVelocityControlParameters.highThreshold,
687 mConfig.pointerVelocityControlParameters.acceleration);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800688
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800689 dump += StringPrintf(INDENT2 "WheelVelocityControlParameters: "
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700690 "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, "
691 "acceleration=%0.3f\n",
692 mConfig.wheelVelocityControlParameters.scale,
693 mConfig.wheelVelocityControlParameters.lowThreshold,
694 mConfig.wheelVelocityControlParameters.highThreshold,
695 mConfig.wheelVelocityControlParameters.acceleration);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800696
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800697 dump += StringPrintf(INDENT2 "PointerGesture:\n");
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700698 dump += StringPrintf(INDENT3 "Enabled: %s\n", toString(mConfig.pointerGesturesEnabled));
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800699 dump += StringPrintf(INDENT3 "QuietInterval: %0.1fms\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700700 mConfig.pointerGestureQuietInterval * 0.000001f);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800701 dump += StringPrintf(INDENT3 "DragMinSwitchSpeed: %0.1fpx/s\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700702 mConfig.pointerGestureDragMinSwitchSpeed);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800703 dump += StringPrintf(INDENT3 "TapInterval: %0.1fms\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700704 mConfig.pointerGestureTapInterval * 0.000001f);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800705 dump += StringPrintf(INDENT3 "TapDragInterval: %0.1fms\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700706 mConfig.pointerGestureTapDragInterval * 0.000001f);
707 dump += StringPrintf(INDENT3 "TapSlop: %0.1fpx\n", mConfig.pointerGestureTapSlop);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800708 dump += StringPrintf(INDENT3 "MultitouchSettleInterval: %0.1fms\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700709 mConfig.pointerGestureMultitouchSettleInterval * 0.000001f);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800710 dump += StringPrintf(INDENT3 "MultitouchMinDistance: %0.1fpx\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700711 mConfig.pointerGestureMultitouchMinDistance);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800712 dump += StringPrintf(INDENT3 "SwipeTransitionAngleCosine: %0.1f\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700713 mConfig.pointerGestureSwipeTransitionAngleCosine);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800714 dump += StringPrintf(INDENT3 "SwipeMaxWidthRatio: %0.1f\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700715 mConfig.pointerGestureSwipeMaxWidthRatio);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800716 dump += StringPrintf(INDENT3 "MovementSpeedRatio: %0.1f\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700717 mConfig.pointerGestureMovementSpeedRatio);
718 dump += StringPrintf(INDENT3 "ZoomSpeedRatio: %0.1f\n", mConfig.pointerGestureZoomSpeedRatio);
Santos Cordonfa5cf462017-04-05 10:37:00 -0700719
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800720 dump += INDENT3 "Viewports:\n";
Santos Cordonfa5cf462017-04-05 10:37:00 -0700721 mConfig.dump(dump);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800722}
723
724void InputReader::monitor() {
725 // Acquire and release the lock to ensure that the reader has not deadlocked.
726 mLock.lock();
727 mEventHub->wake();
728 mReaderIsAliveCondition.wait(mLock);
729 mLock.unlock();
730
731 // Check the EventHub
732 mEventHub->monitor();
733}
734
Michael Wrightd02c5b62014-02-10 15:10:22 -0800735// --- InputReader::ContextImpl ---
736
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800737InputReader::ContextImpl::ContextImpl(InputReader* reader)
738 : mReader(reader), mIdGenerator(IdGenerator::Source::INPUT_READER) {}
Michael Wrightd02c5b62014-02-10 15:10:22 -0800739
740void InputReader::ContextImpl::updateGlobalMetaState() {
741 // lock is already held by the input loop
742 mReader->updateGlobalMetaStateLocked();
743}
744
745int32_t InputReader::ContextImpl::getGlobalMetaState() {
746 // lock is already held by the input loop
747 return mReader->getGlobalMetaStateLocked();
748}
749
arthurhungc903df12020-08-11 15:08:42 +0800750void InputReader::ContextImpl::updateLedMetaState(int32_t metaState) {
751 // lock is already held by the input loop
752 mReader->updateLedMetaStateLocked(metaState);
753}
754
755int32_t InputReader::ContextImpl::getLedMetaState() {
756 // lock is already held by the input loop
757 return mReader->getLedMetaStateLocked();
758}
759
Michael Wrightd02c5b62014-02-10 15:10:22 -0800760void InputReader::ContextImpl::disableVirtualKeysUntil(nsecs_t time) {
761 // lock is already held by the input loop
762 mReader->disableVirtualKeysUntilLocked(time);
763}
764
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800765bool InputReader::ContextImpl::shouldDropVirtualKey(nsecs_t now, int32_t keyCode,
766 int32_t scanCode) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800767 // lock is already held by the input loop
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800768 return mReader->shouldDropVirtualKeyLocked(now, keyCode, scanCode);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800769}
770
771void InputReader::ContextImpl::fadePointer() {
772 // lock is already held by the input loop
773 mReader->fadePointerLocked();
774}
775
Michael Wright17db18e2020-06-26 20:51:44 +0100776std::shared_ptr<PointerControllerInterface> InputReader::ContextImpl::getPointerController(
777 int32_t deviceId) {
Prabir Pradhanc7ef27e2020-02-03 19:19:15 -0800778 // lock is already held by the input loop
779 return mReader->getPointerControllerLocked(deviceId);
780}
781
Michael Wrightd02c5b62014-02-10 15:10:22 -0800782void InputReader::ContextImpl::requestTimeoutAtTime(nsecs_t when) {
783 // lock is already held by the input loop
784 mReader->requestTimeoutAtTimeLocked(when);
785}
786
787int32_t InputReader::ContextImpl::bumpGeneration() {
788 // lock is already held by the input loop
789 return mReader->bumpGenerationLocked();
790}
791
Arthur Hung7c3ae9c2019-03-11 11:23:03 +0800792void InputReader::ContextImpl::getExternalStylusDevices(std::vector<InputDeviceInfo>& outDevices) {
Michael Wright842500e2015-03-13 17:32:02 -0700793 // lock is already held by whatever called refreshConfigurationLocked
794 mReader->getExternalStylusDevicesLocked(outDevices);
795}
796
797void InputReader::ContextImpl::dispatchExternalStylusState(const StylusState& state) {
798 mReader->dispatchExternalStylusState(state);
799}
800
Michael Wrightd02c5b62014-02-10 15:10:22 -0800801InputReaderPolicyInterface* InputReader::ContextImpl::getPolicy() {
802 return mReader->mPolicy.get();
803}
804
805InputListenerInterface* InputReader::ContextImpl::getListener() {
806 return mReader->mQueuedListener.get();
807}
808
809EventHubInterface* InputReader::ContextImpl::getEventHub() {
810 return mReader->mEventHub.get();
811}
812
Garfield Tan6a5a14e2020-01-28 13:24:04 -0800813int32_t InputReader::ContextImpl::getNextId() {
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800814 return mIdGenerator.nextId();
Prabir Pradhan42611e02018-11-27 14:04:02 -0800815}
Michael Wrightd02c5b62014-02-10 15:10:22 -0800816
Michael Wrightd02c5b62014-02-10 15:10:22 -0800817} // namespace android