blob: 9608210ca0620c621d00fd0853b063c4f04ada7a [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
Josh Bartel938632f2022-07-19 15:34:22 -050041/**
42 * Determines if the identifiers passed are a sub-devices. Sub-devices are physical devices
43 * that expose multiple input device paths such a keyboard that also has a touchpad input.
44 * These are separate devices with unique descriptors in EventHub, but InputReader should
45 * create a single InputDevice for them.
46 * Sub-devices are detected by the following criteria:
47 * 1. The vendor, product, bus, version, and unique id match
48 * 2. The location matches. The location is used to distinguish a single device with multiple
49 * inputs versus the same device plugged into multiple ports.
50 */
51
52static bool isSubDevice(const InputDeviceIdentifier& identifier1,
53 const InputDeviceIdentifier& identifier2) {
54 return (identifier1.vendor == identifier2.vendor &&
55 identifier1.product == identifier2.product && identifier1.bus == identifier2.bus &&
56 identifier1.version == identifier2.version &&
57 identifier1.uniqueId == identifier2.uniqueId &&
58 identifier1.location == identifier2.location);
59}
60
Prabir Pradhanda20b172022-09-26 17:01:18 +000061static bool isStylusPointerGestureStart(const NotifyMotionArgs& motionArgs) {
62 const auto actionMasked = MotionEvent::getActionMasked(motionArgs.action);
63 if (actionMasked != AMOTION_EVENT_ACTION_HOVER_ENTER &&
64 actionMasked != AMOTION_EVENT_ACTION_DOWN &&
65 actionMasked != AMOTION_EVENT_ACTION_POINTER_DOWN) {
66 return false;
67 }
68 const auto actionIndex = MotionEvent::getActionIndex(motionArgs.action);
Prabir Pradhane5626962022-10-27 20:30:53 +000069 return isStylusToolType(motionArgs.pointerProperties[actionIndex].toolType);
Prabir Pradhanda20b172022-09-26 17:01:18 +000070}
71
Prabir Pradhan28efc192019-11-05 01:10:04 +000072// --- InputReader ---
73
Siarhei Vishniakou3bc7e092019-07-24 17:43:30 -070074InputReader::InputReader(std::shared_ptr<EventHubInterface> eventHub,
75 const sp<InputReaderPolicyInterface>& policy,
Siarhei Vishniakou18050092021-09-01 13:32:49 -070076 InputListenerInterface& listener)
Siarhei Vishniakou3bc7e092019-07-24 17:43:30 -070077 : mContext(this),
78 mEventHub(eventHub),
79 mPolicy(policy),
Siarhei Vishniakou23a98bf2023-08-15 17:28:49 -070080 mNextListener(listener),
Arthur Hung95f68612022-04-07 14:08:22 +080081 mGlobalMetaState(AMETA_NONE),
82 mLedMetaState(AMETA_NONE),
Siarhei Vishniakou3bc7e092019-07-24 17:43:30 -070083 mGeneration(1),
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -080084 mNextInputDeviceId(END_RESERVED_ID),
Siarhei Vishniakou3bc7e092019-07-24 17:43:30 -070085 mDisableVirtualKeysTimeout(LLONG_MIN),
86 mNextTimeout(LLONG_MAX),
Michael Wrightd02c5b62014-02-10 15:10:22 -080087 mConfigurationChangesToRefresh(0) {
Prabir Pradhan4bf6d452023-04-18 21:26:56 +000088 refreshConfigurationLocked(/*changes=*/{});
Siarhei Vishniakou18050092021-09-01 13:32:49 -070089 updateGlobalMetaStateLocked();
Michael Wrightd02c5b62014-02-10 15:10:22 -080090}
91
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +000092InputReader::~InputReader() {}
Michael Wrightd02c5b62014-02-10 15:10:22 -080093
Prabir Pradhan28efc192019-11-05 01:10:04 +000094status_t InputReader::start() {
Prabir Pradhan5a57cff2019-10-31 18:40:33 -070095 if (mThread) {
Prabir Pradhan28efc192019-11-05 01:10:04 +000096 return ALREADY_EXISTS;
97 }
Prabir Pradhan5a57cff2019-10-31 18:40:33 -070098 mThread = std::make_unique<InputThread>(
99 "InputReader", [this]() { loopOnce(); }, [this]() { mEventHub->wake(); });
100 return OK;
Prabir Pradhan28efc192019-11-05 01:10:04 +0000101}
102
103status_t InputReader::stop() {
Prabir Pradhan5a57cff2019-10-31 18:40:33 -0700104 if (mThread && mThread->isCallingThread()) {
105 ALOGE("InputReader cannot be stopped from its own thread!");
Prabir Pradhan28efc192019-11-05 01:10:04 +0000106 return INVALID_OPERATION;
107 }
Prabir Pradhan5a57cff2019-10-31 18:40:33 -0700108 mThread.reset();
109 return OK;
Prabir Pradhan28efc192019-11-05 01:10:04 +0000110}
111
Michael Wrightd02c5b62014-02-10 15:10:22 -0800112void InputReader::loopOnce() {
113 int32_t oldGeneration;
114 int32_t timeoutMillis;
Prabir Pradhanda20b172022-09-26 17:01:18 +0000115 // Copy some state so that we can access it outside the lock later.
Michael Wrightd02c5b62014-02-10 15:10:22 -0800116 bool inputDevicesChanged = false;
Chris Ye1c2e0892020-11-30 21:41:44 -0800117 std::vector<InputDeviceInfo> inputDevices;
Prabir Pradhanda20b172022-09-26 17:01:18 +0000118 std::list<NotifyArgs> notifyArgs;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800119 { // acquire lock
Chris Ye87143712020-11-10 05:05:58 +0000120 std::scoped_lock _l(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800121
122 oldGeneration = mGeneration;
123 timeoutMillis = -1;
124
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000125 auto changes = mConfigurationChangesToRefresh;
126 if (changes.any()) {
127 mConfigurationChangesToRefresh.clear();
Michael Wrightd02c5b62014-02-10 15:10:22 -0800128 timeoutMillis = 0;
129 refreshConfigurationLocked(changes);
130 } else if (mNextTimeout != LLONG_MAX) {
131 nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
132 timeoutMillis = toMillisecondTimeoutDelay(now, mNextTimeout);
133 }
134 } // release lock
135
Siarhei Vishniakou7b3ea0b2022-09-16 14:23:20 -0700136 std::vector<RawEvent> events = mEventHub->getEvents(timeoutMillis);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800137
138 { // acquire lock
Chris Ye87143712020-11-10 05:05:58 +0000139 std::scoped_lock _l(mLock);
Chris Ye1c2e0892020-11-30 21:41:44 -0800140 mReaderIsAliveCondition.notify_all();
Michael Wrightd02c5b62014-02-10 15:10:22 -0800141
Siarhei Vishniakou7b3ea0b2022-09-16 14:23:20 -0700142 if (!events.empty()) {
Siarhei Vishniakou23a98bf2023-08-15 17:28:49 -0700143 mPendingArgs += processEventsLocked(events.data(), events.size());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800144 }
145
146 if (mNextTimeout != LLONG_MAX) {
147 nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
148 if (now >= mNextTimeout) {
Prabir Pradhan011ca3d2023-02-22 21:31:39 +0000149 if (debugRawEvents()) {
Siarhei Vishniakou465e1c02021-12-09 10:47:29 -0800150 ALOGD("Timeout expired, latency=%0.3fms", (now - mNextTimeout) * 0.000001f);
151 }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800152 mNextTimeout = LLONG_MAX;
Siarhei Vishniakou23a98bf2023-08-15 17:28:49 -0700153 mPendingArgs += timeoutExpiredLocked(now);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800154 }
155 }
156
157 if (oldGeneration != mGeneration) {
158 inputDevicesChanged = true;
Chris Ye1c2e0892020-11-30 21:41:44 -0800159 inputDevices = getInputDevicesLocked();
Siarhei Vishniakou23a98bf2023-08-15 17:28:49 -0700160 mPendingArgs.emplace_back(
Prabir Pradhane3da4bb2023-04-05 23:51:23 +0000161 NotifyInputDevicesChangedArgs{mContext.getNextId(), inputDevices});
Michael Wrightd02c5b62014-02-10 15:10:22 -0800162 }
Siarhei Vishniakou23a98bf2023-08-15 17:28:49 -0700163
164 std::swap(notifyArgs, mPendingArgs);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800165 } // release lock
166
Michael Wrightd02c5b62014-02-10 15:10:22 -0800167 // Flush queued events out to the listener.
168 // This must happen outside of the lock because the listener could potentially call
169 // back into the InputReader's methods, such as getScanCodeState, or become blocked
170 // on another thread similarly waiting to acquire the InputReader lock thereby
171 // resulting in a deadlock. This situation is actually quite plausible because the
172 // listener is actually the input dispatcher, which calls into the window manager,
173 // which occasionally calls into the input reader.
Siarhei Vishniakou23a98bf2023-08-15 17:28:49 -0700174 for (const NotifyArgs& args : notifyArgs) {
175 mNextListener.notify(args);
176 }
Prabir Pradhanc3a92472024-02-06 20:08:05 +0000177
178 // Notify the policy that input devices have changed.
179 // This must be done after flushing events down the listener chain to ensure that the rest of
180 // the listeners are synchronized with the changes before the policy reacts to them.
181 if (inputDevicesChanged) {
182 mPolicy->notifyInputDevicesChanged(inputDevices);
183 }
184
185 // Notify the policy of the start of every new stylus gesture.
186 for (const auto& args : notifyArgs) {
187 const auto* motionArgs = std::get_if<NotifyMotionArgs>(&args);
188 if (motionArgs != nullptr && isStylusPointerGestureStart(*motionArgs)) {
189 mPolicy->notifyStylusGestureStarted(motionArgs->deviceId, motionArgs->eventTime);
190 }
191 }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800192}
193
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700194std::list<NotifyArgs> InputReader::processEventsLocked(const RawEvent* rawEvents, size_t count) {
195 std::list<NotifyArgs> out;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800196 for (const RawEvent* rawEvent = rawEvents; count;) {
197 int32_t type = rawEvent->type;
198 size_t batchSize = 1;
199 if (type < EventHubInterface::FIRST_SYNTHETIC_EVENT) {
200 int32_t deviceId = rawEvent->deviceId;
201 while (batchSize < count) {
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700202 if (rawEvent[batchSize].type >= EventHubInterface::FIRST_SYNTHETIC_EVENT ||
203 rawEvent[batchSize].deviceId != deviceId) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800204 break;
205 }
206 batchSize += 1;
207 }
Prabir Pradhan011ca3d2023-02-22 21:31:39 +0000208 if (debugRawEvents()) {
Siarhei Vishniakou465e1c02021-12-09 10:47:29 -0800209 ALOGD("BatchSize: %zu Count: %zu", batchSize, count);
210 }
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700211 out += processEventsForDeviceLocked(deviceId, rawEvent, batchSize);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800212 } else {
213 switch (rawEvent->type) {
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700214 case EventHubInterface::DEVICE_ADDED:
215 addDeviceLocked(rawEvent->when, rawEvent->deviceId);
216 break;
217 case EventHubInterface::DEVICE_REMOVED:
218 removeDeviceLocked(rawEvent->when, rawEvent->deviceId);
219 break;
220 case EventHubInterface::FINISHED_DEVICE_SCAN:
221 handleConfigurationChangedLocked(rawEvent->when);
222 break;
223 default:
224 ALOG_ASSERT(false); // can't happen
225 break;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800226 }
227 }
228 count -= batchSize;
229 rawEvent += batchSize;
230 }
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700231 return out;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800232}
233
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800234void InputReader::addDeviceLocked(nsecs_t when, int32_t eventHubId) {
235 if (mDevices.find(eventHubId) != mDevices.end()) {
236 ALOGW("Ignoring spurious device added event for eventHubId %d.", eventHubId);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800237 return;
238 }
239
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800240 InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(eventHubId);
Arpit Singh82f29a12023-06-13 15:05:53 +0000241 std::shared_ptr<InputDevice> device = createDeviceLocked(when, eventHubId, identifier);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700242
Siarhei Vishniakou23a98bf2023-08-15 17:28:49 -0700243 mPendingArgs += device->configure(when, mConfig, /*changes=*/{});
244 mPendingArgs += device->reset(when);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800245
246 if (device->isIgnored()) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800247 ALOGI("Device added: id=%d, eventHubId=%d, name='%s', descriptor='%s' "
248 "(ignored non-input device)",
249 device->getId(), eventHubId, identifier.name.c_str(), identifier.descriptor.c_str());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800250 } else {
Siarhei Vishniakou88151b82022-08-11 00:53:38 +0000251 ALOGI("Device added: id=%d, eventHubId=%d, name='%s', descriptor='%s',sources=%s",
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800252 device->getId(), eventHubId, identifier.name.c_str(), identifier.descriptor.c_str(),
Siarhei Vishniakou88151b82022-08-11 00:53:38 +0000253 inputEventSourceToString(device->getSources()).c_str());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800254 }
255
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800256 mDevices.emplace(eventHubId, device);
Chris Yee7310032020-09-22 15:36:28 -0700257 // Add device to device to EventHub ids map.
258 const auto mapIt = mDeviceToEventHubIdsMap.find(device);
259 if (mapIt == mDeviceToEventHubIdsMap.end()) {
260 std::vector<int32_t> ids = {eventHubId};
261 mDeviceToEventHubIdsMap.emplace(device, ids);
262 } else {
263 mapIt->second.push_back(eventHubId);
264 }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800265 bumpGenerationLocked();
Michael Wright842500e2015-03-13 17:32:02 -0700266
Chris Ye1b0c7342020-07-28 21:57:03 -0700267 if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS)) {
Chris Ye1c2e0892020-11-30 21:41:44 -0800268 notifyExternalStylusPresenceChangedLocked();
Michael Wright842500e2015-03-13 17:32:02 -0700269 }
Chris Yef59a2f42020-10-16 12:55:26 -0700270
271 // Sensor input device is noisy, to save power disable it by default.
Chris Yee14523a2020-12-19 13:46:00 -0800272 // Input device is classified as SENSOR when any sub device is a SENSOR device, check Eventhub
273 // device class to disable SENSOR sub device only.
274 if (mEventHub->getDeviceClasses(eventHubId).test(InputDeviceClass::SENSOR)) {
Chris Yef59a2f42020-10-16 12:55:26 -0700275 mEventHub->disableDevice(eventHubId);
276 }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800277}
278
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800279void InputReader::removeDeviceLocked(nsecs_t when, int32_t eventHubId) {
280 auto deviceIt = mDevices.find(eventHubId);
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000281 if (deviceIt == mDevices.end()) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800282 ALOGW("Ignoring spurious device removed event for eventHubId %d.", eventHubId);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800283 return;
284 }
285
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000286 std::shared_ptr<InputDevice> device = std::move(deviceIt->second);
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000287 mDevices.erase(deviceIt);
Chris Yee7310032020-09-22 15:36:28 -0700288 // Erase device from device to EventHub ids map.
289 auto mapIt = mDeviceToEventHubIdsMap.find(device);
290 if (mapIt != mDeviceToEventHubIdsMap.end()) {
291 std::vector<int32_t>& eventHubIds = mapIt->second;
Siarhei Vishniakouf47c339e2021-12-30 11:22:26 -0800292 std::erase_if(eventHubIds, [eventHubId](int32_t eId) { return eId == eventHubId; });
Chris Yee7310032020-09-22 15:36:28 -0700293 if (eventHubIds.size() == 0) {
294 mDeviceToEventHubIdsMap.erase(mapIt);
295 }
296 }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800297 bumpGenerationLocked();
298
299 if (device->isIgnored()) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800300 ALOGI("Device removed: id=%d, eventHubId=%d, name='%s', descriptor='%s' "
301 "(ignored non-input device)",
302 device->getId(), eventHubId, device->getName().c_str(),
303 device->getDescriptor().c_str());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800304 } else {
Siarhei Vishniakou88151b82022-08-11 00:53:38 +0000305 ALOGI("Device removed: id=%d, eventHubId=%d, name='%s', descriptor='%s', sources=%s",
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800306 device->getId(), eventHubId, device->getName().c_str(),
Siarhei Vishniakou88151b82022-08-11 00:53:38 +0000307 device->getDescriptor().c_str(),
308 inputEventSourceToString(device->getSources()).c_str());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800309 }
310
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800311 device->removeEventHubDevice(eventHubId);
312
Chris Ye1b0c7342020-07-28 21:57:03 -0700313 if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS)) {
Chris Ye1c2e0892020-11-30 21:41:44 -0800314 notifyExternalStylusPresenceChangedLocked();
Michael Wright842500e2015-03-13 17:32:02 -0700315 }
316
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800317 if (device->hasEventHubDevices()) {
Siarhei Vishniakou23a98bf2023-08-15 17:28:49 -0700318 mPendingArgs += device->configure(when, mConfig, /*changes=*/{});
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800319 }
Siarhei Vishniakou23a98bf2023-08-15 17:28:49 -0700320 mPendingArgs += device->reset(when);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800321}
322
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000323std::shared_ptr<InputDevice> InputReader::createDeviceLocked(
Arpit Singh82f29a12023-06-13 15:05:53 +0000324 nsecs_t when, int32_t eventHubId, const InputDeviceIdentifier& identifier) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800325 auto deviceIt = std::find_if(mDevices.begin(), mDevices.end(), [identifier](auto& devicePair) {
Josh Bartel938632f2022-07-19 15:34:22 -0500326 const InputDeviceIdentifier identifier2 =
327 devicePair.second->getDeviceInfo().getIdentifier();
328 return isSubDevice(identifier, identifier2);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800329 });
330
331 std::shared_ptr<InputDevice> device;
332 if (deviceIt != mDevices.end()) {
333 device = deviceIt->second;
334 } else {
335 int32_t deviceId = (eventHubId < END_RESERVED_ID) ? eventHubId : nextInputDeviceIdLocked();
336 device = std::make_shared<InputDevice>(&mContext, deviceId, bumpGenerationLocked(),
337 identifier);
338 }
Arpit Singh82f29a12023-06-13 15:05:53 +0000339 mPendingArgs += device->addEventHubDevice(when, eventHubId, mConfig);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800340 return device;
341}
342
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700343std::list<NotifyArgs> InputReader::processEventsForDeviceLocked(int32_t eventHubId,
344 const RawEvent* rawEvents,
345 size_t count) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800346 auto deviceIt = mDevices.find(eventHubId);
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000347 if (deviceIt == mDevices.end()) {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800348 ALOGW("Discarding event for unknown eventHubId %d.", eventHubId);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700349 return {};
Michael Wrightd02c5b62014-02-10 15:10:22 -0800350 }
351
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000352 std::shared_ptr<InputDevice>& device = deviceIt->second;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800353 if (device->isIgnored()) {
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700354 // ALOGD("Discarding event for ignored deviceId %d.", deviceId);
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700355 return {};
Michael Wrightd02c5b62014-02-10 15:10:22 -0800356 }
357
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700358 return device->process(rawEvents, count);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800359}
360
Philip Junker4af3b3d2021-12-14 10:36:55 +0100361InputDevice* InputReader::findInputDeviceLocked(int32_t deviceId) const {
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800362 auto deviceIt =
363 std::find_if(mDevices.begin(), mDevices.end(), [deviceId](const auto& devicePair) {
364 return devicePair.second->getId() == deviceId;
365 });
366 if (deviceIt != mDevices.end()) {
367 return deviceIt->second.get();
368 }
369 return nullptr;
370}
371
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700372std::list<NotifyArgs> InputReader::timeoutExpiredLocked(nsecs_t when) {
373 std::list<NotifyArgs> out;
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000374 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000375 std::shared_ptr<InputDevice>& device = devicePair.second;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800376 if (!device->isIgnored()) {
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700377 out += device->timeoutExpired(when);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800378 }
379 }
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700380 return out;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800381}
382
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800383int32_t InputReader::nextInputDeviceIdLocked() {
384 return ++mNextInputDeviceId;
385}
386
Michael Wrightd02c5b62014-02-10 15:10:22 -0800387void InputReader::handleConfigurationChangedLocked(nsecs_t when) {
388 // Reset global meta state because it depends on the list of all configured devices.
389 updateGlobalMetaStateLocked();
390
391 // Enqueue configuration changed.
Siarhei Vishniakou23a98bf2023-08-15 17:28:49 -0700392 mPendingArgs.emplace_back(NotifyConfigurationChangedArgs{mContext.getNextId(), when});
Michael Wrightd02c5b62014-02-10 15:10:22 -0800393}
394
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000395void InputReader::refreshConfigurationLocked(ConfigurationChanges changes) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800396 mPolicy->getReaderConfiguration(&mConfig);
397 mEventHub->setExcludedDevices(mConfig.excludedDeviceNames);
398
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000399 using Change = InputReaderConfiguration::Change;
400 if (!changes.any()) return;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800401
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000402 ALOGI("Reconfiguring input devices, changes=%s", changes.string().c_str());
Prabir Pradhan7e186182020-11-10 13:56:45 -0800403 nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
Prabir Pradhanc7ef27e2020-02-03 19:19:15 -0800404
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000405 if (changes.test(Change::DISPLAY_INFO)) {
Prabir Pradhan7e186182020-11-10 13:56:45 -0800406 updatePointerDisplayLocked();
407 }
408
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000409 if (changes.test(Change::MUST_REOPEN)) {
Prabir Pradhan7e186182020-11-10 13:56:45 -0800410 mEventHub->requestReopenDevices();
411 } else {
412 for (auto& devicePair : mDevices) {
413 std::shared_ptr<InputDevice>& device = devicePair.second;
Siarhei Vishniakou23a98bf2023-08-15 17:28:49 -0700414 mPendingArgs += device->configure(now, mConfig, changes);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800415 }
416 }
Prabir Pradhan7e186182020-11-10 13:56:45 -0800417
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000418 if (changes.test(Change::POINTER_CAPTURE)) {
Prabir Pradhan5cc1a692021-08-06 14:01:18 +0000419 if (mCurrentPointerCaptureRequest == mConfig.pointerCaptureRequest) {
420 ALOGV("Skipping notifying pointer capture changes: "
421 "There was no change in the pointer capture state.");
422 } else {
423 mCurrentPointerCaptureRequest = mConfig.pointerCaptureRequest;
Siarhei Vishniakou23a98bf2023-08-15 17:28:49 -0700424 mPendingArgs.emplace_back(
425 NotifyPointerCaptureChangedArgs{mContext.getNextId(), now,
426 mCurrentPointerCaptureRequest});
Prabir Pradhan5cc1a692021-08-06 14:01:18 +0000427 }
Prabir Pradhan7e186182020-11-10 13:56:45 -0800428 }
Michael Wrightd02c5b62014-02-10 15:10:22 -0800429}
430
431void InputReader::updateGlobalMetaStateLocked() {
432 mGlobalMetaState = 0;
433
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000434 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000435 std::shared_ptr<InputDevice>& device = devicePair.second;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800436 mGlobalMetaState |= device->getMetaState();
437 }
438}
439
440int32_t InputReader::getGlobalMetaStateLocked() {
441 return mGlobalMetaState;
442}
443
arthurhungc903df12020-08-11 15:08:42 +0800444void InputReader::updateLedMetaStateLocked(int32_t metaState) {
445 mLedMetaState = metaState;
446 for (auto& devicePair : mDevices) {
447 std::shared_ptr<InputDevice>& device = devicePair.second;
448 device->updateLedState(false);
449 }
450}
451
452int32_t InputReader::getLedMetaStateLocked() {
453 return mLedMetaState;
454}
455
Chris Ye1c2e0892020-11-30 21:41:44 -0800456void InputReader::notifyExternalStylusPresenceChangedLocked() {
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000457 refreshConfigurationLocked(InputReaderConfiguration::Change::EXTERNAL_STYLUS_PRESENCE);
Michael Wright842500e2015-03-13 17:32:02 -0700458}
459
Arthur Hung7c3ae9c2019-03-11 11:23:03 +0800460void InputReader::getExternalStylusDevicesLocked(std::vector<InputDeviceInfo>& outDevices) {
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000461 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000462 std::shared_ptr<InputDevice>& device = devicePair.second;
Chris Ye1b0c7342020-07-28 21:57:03 -0700463 if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS) && !device->isIgnored()) {
Siarhei Vishniakou1983a712021-06-04 19:27:09 +0000464 outDevices.push_back(device->getDeviceInfo());
Michael Wright842500e2015-03-13 17:32:02 -0700465 }
466 }
467}
468
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700469std::list<NotifyArgs> InputReader::dispatchExternalStylusStateLocked(const StylusState& state) {
470 std::list<NotifyArgs> out;
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000471 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000472 std::shared_ptr<InputDevice>& device = devicePair.second;
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700473 out += device->updateExternalStylusState(state);
Michael Wright842500e2015-03-13 17:32:02 -0700474 }
Siarhei Vishniakou2935db72022-09-22 13:35:22 -0700475 return out;
Michael Wright842500e2015-03-13 17:32:02 -0700476}
477
Michael Wrightd02c5b62014-02-10 15:10:22 -0800478void InputReader::disableVirtualKeysUntilLocked(nsecs_t time) {
479 mDisableVirtualKeysTimeout = time;
480}
481
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800482bool InputReader::shouldDropVirtualKeyLocked(nsecs_t now, int32_t keyCode, int32_t scanCode) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800483 if (now < mDisableVirtualKeysTimeout) {
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800484 ALOGI("Dropping virtual key from device because virtual keys are "
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700485 "temporarily disabled for the next %0.3fms. keyCode=%d, scanCode=%d",
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -0800486 (mDisableVirtualKeysTimeout - now) * 0.000001, keyCode, scanCode);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800487 return true;
488 } else {
489 return false;
490 }
491}
492
Michael Wright17db18e2020-06-26 20:51:44 +0100493std::shared_ptr<PointerControllerInterface> InputReader::getPointerControllerLocked(
494 int32_t deviceId) {
495 std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock();
Prabir Pradhanc7ef27e2020-02-03 19:19:15 -0800496 if (controller == nullptr) {
497 controller = mPolicy->obtainPointerController(deviceId);
498 mPointerController = controller;
499 updatePointerDisplayLocked();
500 }
501 return controller;
502}
503
504void InputReader::updatePointerDisplayLocked() {
Michael Wright17db18e2020-06-26 20:51:44 +0100505 std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock();
Prabir Pradhanc7ef27e2020-02-03 19:19:15 -0800506 if (controller == nullptr) {
507 return;
508 }
509
510 std::optional<DisplayViewport> viewport =
511 mConfig.getDisplayViewportById(mConfig.defaultPointerDisplayId);
512 if (!viewport) {
513 ALOGW("Can't find the designated viewport with ID %" PRId32 " to update cursor input "
514 "mapper. Fall back to default display",
515 mConfig.defaultPointerDisplayId);
516 viewport = mConfig.getDisplayViewportById(ADISPLAY_ID_DEFAULT);
517 }
518 if (!viewport) {
519 ALOGE("Still can't find a viable viewport to update cursor input mapper. Skip setting it to"
520 " PointerController.");
521 return;
522 }
523
524 controller->setDisplayViewport(*viewport);
525}
526
Michael Wrightd02c5b62014-02-10 15:10:22 -0800527void InputReader::fadePointerLocked() {
Michael Wright17db18e2020-06-26 20:51:44 +0100528 std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock();
Prabir Pradhanc7ef27e2020-02-03 19:19:15 -0800529 if (controller != nullptr) {
Michael Wrightca5bede2020-07-02 00:00:29 +0100530 controller->fade(PointerControllerInterface::Transition::GRADUAL);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800531 }
532}
533
534void InputReader::requestTimeoutAtTimeLocked(nsecs_t when) {
535 if (when < mNextTimeout) {
536 mNextTimeout = when;
537 mEventHub->wake();
538 }
539}
540
541int32_t InputReader::bumpGenerationLocked() {
542 return ++mGeneration;
543}
544
Chris Ye98d3f532020-10-01 21:48:59 -0700545std::vector<InputDeviceInfo> InputReader::getInputDevices() const {
Chris Ye87143712020-11-10 05:05:58 +0000546 std::scoped_lock _l(mLock);
Chris Ye98d3f532020-10-01 21:48:59 -0700547 return getInputDevicesLocked();
Michael Wrightd02c5b62014-02-10 15:10:22 -0800548}
549
Chris Ye98d3f532020-10-01 21:48:59 -0700550std::vector<InputDeviceInfo> InputReader::getInputDevicesLocked() const {
551 std::vector<InputDeviceInfo> outInputDevices;
552 outInputDevices.reserve(mDeviceToEventHubIdsMap.size());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800553
Chris Yee7310032020-09-22 15:36:28 -0700554 for (const auto& [device, eventHubIds] : mDeviceToEventHubIdsMap) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800555 if (!device->isIgnored()) {
Siarhei Vishniakou1983a712021-06-04 19:27:09 +0000556 outInputDevices.push_back(device->getDeviceInfo());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800557 }
558 }
Chris Ye98d3f532020-10-01 21:48:59 -0700559 return outInputDevices;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800560}
561
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700562int32_t InputReader::getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) {
Chris Ye87143712020-11-10 05:05:58 +0000563 std::scoped_lock _l(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800564
565 return getStateLocked(deviceId, sourceMask, keyCode, &InputDevice::getKeyCodeState);
566}
567
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700568int32_t InputReader::getScanCodeState(int32_t deviceId, uint32_t sourceMask, int32_t scanCode) {
Chris Ye87143712020-11-10 05:05:58 +0000569 std::scoped_lock _l(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800570
571 return getStateLocked(deviceId, sourceMask, scanCode, &InputDevice::getScanCodeState);
572}
573
574int32_t InputReader::getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t switchCode) {
Chris Ye87143712020-11-10 05:05:58 +0000575 std::scoped_lock _l(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800576
577 return getStateLocked(deviceId, sourceMask, switchCode, &InputDevice::getSwitchState);
578}
579
580int32_t InputReader::getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code,
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700581 GetStateFunc getStateFunc) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800582 int32_t result = AKEY_STATE_UNKNOWN;
583 if (deviceId >= 0) {
Chris Ye1c2e0892020-11-30 21:41:44 -0800584 InputDevice* device = findInputDeviceLocked(deviceId);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800585 if (device && !device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
586 result = (device->*getStateFunc)(sourceMask, code);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800587 }
588 } else {
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000589 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000590 std::shared_ptr<InputDevice>& device = devicePair.second;
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700591 if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800592 // If any device reports AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL, return that
593 // value. Otherwise, return AKEY_STATE_UP as long as one device reports it.
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000594 int32_t currentResult = (device.get()->*getStateFunc)(sourceMask, code);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800595 if (currentResult >= AKEY_STATE_DOWN) {
596 return currentResult;
597 } else if (currentResult == AKEY_STATE_UP) {
598 result = currentResult;
599 }
600 }
601 }
602 }
603 return result;
604}
605
Andrii Kulian763a3a42016-03-08 10:46:16 -0800606void InputReader::toggleCapsLockState(int32_t deviceId) {
Chris Ye87143712020-11-10 05:05:58 +0000607 std::scoped_lock _l(mLock);
Chris Ye1c2e0892020-11-30 21:41:44 -0800608 InputDevice* device = findInputDeviceLocked(deviceId);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800609 if (!device) {
Andrii Kulian763a3a42016-03-08 10:46:16 -0800610 ALOGW("Ignoring toggleCapsLock for unknown deviceId %" PRId32 ".", deviceId);
611 return;
612 }
613
Andrii Kulian763a3a42016-03-08 10:46:16 -0800614 if (device->isIgnored()) {
Arthur Hungcb40a002021-08-03 14:31:01 +0000615 ALOGW("Ignoring toggleCapsLock for ignored deviceId %" PRId32 ".", deviceId);
Andrii Kulian763a3a42016-03-08 10:46:16 -0800616 return;
617 }
618
619 device->updateMetaState(AKEYCODE_CAPS_LOCK);
620}
621
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700622bool InputReader::hasKeys(int32_t deviceId, uint32_t sourceMask,
623 const std::vector<int32_t>& keyCodes, uint8_t* outFlags) {
Chris Ye87143712020-11-10 05:05:58 +0000624 std::scoped_lock _l(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800625
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700626 memset(outFlags, 0, keyCodes.size());
627 return markSupportedKeyCodesLocked(deviceId, sourceMask, keyCodes, outFlags);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800628}
629
630bool InputReader::markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask,
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700631 const std::vector<int32_t>& keyCodes,
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700632 uint8_t* outFlags) {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800633 bool result = false;
634 if (deviceId >= 0) {
Chris Ye1c2e0892020-11-30 21:41:44 -0800635 InputDevice* device = findInputDeviceLocked(deviceId);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800636 if (device && !device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700637 result = device->markSupportedKeyCodes(sourceMask, keyCodes, outFlags);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800638 }
639 } else {
Nathaniel R. Lewis10793a62019-11-05 02:17:02 +0000640 for (auto& devicePair : mDevices) {
Nathaniel R. Lewis0cab12d2019-11-05 02:17:02 +0000641 std::shared_ptr<InputDevice>& device = devicePair.second;
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700642 if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700643 result |= device->markSupportedKeyCodes(sourceMask, keyCodes, outFlags);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800644 }
645 }
646 }
647 return result;
648}
649
Vaibhav Devmuraricbba14c2022-10-10 16:54:49 +0000650void InputReader::addKeyRemapping(int32_t deviceId, int32_t fromKeyCode, int32_t toKeyCode) const {
651 std::scoped_lock _l(mLock);
652
653 InputDevice* device = findInputDeviceLocked(deviceId);
654 if (device != nullptr) {
655 device->addKeyRemapping(fromKeyCode, toKeyCode);
656 }
657}
658
Philip Junker4af3b3d2021-12-14 10:36:55 +0100659int32_t InputReader::getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const {
660 std::scoped_lock _l(mLock);
661
662 InputDevice* device = findInputDeviceLocked(deviceId);
663 if (device == nullptr) {
664 ALOGW("Failed to get key code for key location: Input device with id %d not found",
665 deviceId);
666 return AKEYCODE_UNKNOWN;
667 }
668 return device->getKeyCodeForKeyLocation(locationKeyCode);
669}
670
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000671void InputReader::requestRefreshConfiguration(ConfigurationChanges changes) {
Chris Ye87143712020-11-10 05:05:58 +0000672 std::scoped_lock _l(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800673
Prabir Pradhan4bf6d452023-04-18 21:26:56 +0000674 if (changes.any()) {
675 bool needWake = !mConfigurationChangesToRefresh.any();
Michael Wrightd02c5b62014-02-10 15:10:22 -0800676 mConfigurationChangesToRefresh |= changes;
677
678 if (needWake) {
679 mEventHub->wake();
680 }
681 }
682}
683
Chris Ye87143712020-11-10 05:05:58 +0000684void InputReader::vibrate(int32_t deviceId, const VibrationSequence& sequence, ssize_t repeat,
685 int32_t token) {
686 std::scoped_lock _l(mLock);
687
Chris Ye1c2e0892020-11-30 21:41:44 -0800688 InputDevice* device = findInputDeviceLocked(deviceId);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800689 if (device) {
Siarhei Vishniakou23a98bf2023-08-15 17:28:49 -0700690 mPendingArgs += device->vibrate(sequence, repeat, token);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800691 }
692}
693
694void InputReader::cancelVibrate(int32_t deviceId, int32_t token) {
Chris Ye87143712020-11-10 05:05:58 +0000695 std::scoped_lock _l(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800696
Chris Ye1c2e0892020-11-30 21:41:44 -0800697 InputDevice* device = findInputDeviceLocked(deviceId);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800698 if (device) {
Siarhei Vishniakou23a98bf2023-08-15 17:28:49 -0700699 mPendingArgs += device->cancelVibrate(token);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800700 }
701}
702
Chris Ye87143712020-11-10 05:05:58 +0000703bool InputReader::isVibrating(int32_t deviceId) {
704 std::scoped_lock _l(mLock);
705
706 InputDevice* device = findInputDeviceLocked(deviceId);
707 if (device) {
708 return device->isVibrating();
709 }
710 return false;
711}
712
713std::vector<int32_t> InputReader::getVibratorIds(int32_t deviceId) {
714 std::scoped_lock _l(mLock);
715
716 InputDevice* device = findInputDeviceLocked(deviceId);
717 if (device) {
718 return device->getVibratorIds();
719 }
720 return {};
721}
722
Chris Yef59a2f42020-10-16 12:55:26 -0700723void InputReader::disableSensor(int32_t deviceId, InputDeviceSensorType sensorType) {
724 std::scoped_lock _l(mLock);
725
726 InputDevice* device = findInputDeviceLocked(deviceId);
727 if (device) {
728 device->disableSensor(sensorType);
729 }
730}
731
732bool InputReader::enableSensor(int32_t deviceId, InputDeviceSensorType sensorType,
733 std::chrono::microseconds samplingPeriod,
734 std::chrono::microseconds maxBatchReportLatency) {
735 std::scoped_lock _l(mLock);
736
737 InputDevice* device = findInputDeviceLocked(deviceId);
738 if (device) {
739 return device->enableSensor(sensorType, samplingPeriod, maxBatchReportLatency);
740 }
741 return false;
742}
743
744void InputReader::flushSensor(int32_t deviceId, InputDeviceSensorType sensorType) {
745 std::scoped_lock _l(mLock);
746
747 InputDevice* device = findInputDeviceLocked(deviceId);
748 if (device) {
749 device->flushSensor(sensorType);
750 }
751}
752
Kim Low03ea0352020-11-06 12:45:07 -0800753std::optional<int32_t> InputReader::getBatteryCapacity(int32_t deviceId) {
Andy Chenf9f1a022022-08-29 20:07:10 -0400754 std::optional<int32_t> eventHubId;
755 {
756 // Do not query the battery state while holding the lock. For some peripheral devices,
757 // reading battery state can be broken and take 5+ seconds. Holding the lock in this case
758 // would block all other event processing during this time. For now, we assume this
759 // call never happens on the InputReader thread and get the battery state outside the
760 // lock to prevent event processing from being blocked by this call.
761 std::scoped_lock _l(mLock);
762 InputDevice* device = findInputDeviceLocked(deviceId);
763 if (!device) return {};
764 eventHubId = device->getBatteryEventHubId();
765 } // release lock
Kim Low03ea0352020-11-06 12:45:07 -0800766
Andy Chenf9f1a022022-08-29 20:07:10 -0400767 if (!eventHubId) return {};
768 const auto batteryIds = mEventHub->getRawBatteryIds(*eventHubId);
Prabir Pradhane287ecd2022-09-07 21:18:05 +0000769 if (batteryIds.empty()) {
770 ALOGW("%s: There are no battery ids for EventHub device %d", __func__, *eventHubId);
771 return {};
772 }
Andy Chenf9f1a022022-08-29 20:07:10 -0400773 return mEventHub->getBatteryCapacity(*eventHubId, batteryIds.front());
Kim Low03ea0352020-11-06 12:45:07 -0800774}
775
776std::optional<int32_t> InputReader::getBatteryStatus(int32_t deviceId) {
Andy Chenf9f1a022022-08-29 20:07:10 -0400777 std::optional<int32_t> eventHubId;
778 {
779 // Do not query the battery state while holding the lock. For some peripheral devices,
780 // reading battery state can be broken and take 5+ seconds. Holding the lock in this case
781 // would block all other event processing during this time. For now, we assume this
782 // call never happens on the InputReader thread and get the battery state outside the
783 // lock to prevent event processing from being blocked by this call.
784 std::scoped_lock _l(mLock);
785 InputDevice* device = findInputDeviceLocked(deviceId);
786 if (!device) return {};
787 eventHubId = device->getBatteryEventHubId();
788 } // release lock
Kim Low03ea0352020-11-06 12:45:07 -0800789
Andy Chenf9f1a022022-08-29 20:07:10 -0400790 if (!eventHubId) return {};
791 const auto batteryIds = mEventHub->getRawBatteryIds(*eventHubId);
Prabir Pradhane287ecd2022-09-07 21:18:05 +0000792 if (batteryIds.empty()) {
793 ALOGW("%s: There are no battery ids for EventHub device %d", __func__, *eventHubId);
794 return {};
795 }
Andy Chenf9f1a022022-08-29 20:07:10 -0400796 return mEventHub->getBatteryStatus(*eventHubId, batteryIds.front());
Kim Low03ea0352020-11-06 12:45:07 -0800797}
798
Prabir Pradhane287ecd2022-09-07 21:18:05 +0000799std::optional<std::string> InputReader::getBatteryDevicePath(int32_t deviceId) {
800 std::scoped_lock _l(mLock);
801
802 InputDevice* device = findInputDeviceLocked(deviceId);
803 if (!device) return {};
804
805 std::optional<int32_t> eventHubId = device->getBatteryEventHubId();
806 if (!eventHubId) return {};
807 const auto batteryIds = mEventHub->getRawBatteryIds(*eventHubId);
808 if (batteryIds.empty()) {
809 ALOGW("%s: There are no battery ids for EventHub device %d", __func__, *eventHubId);
810 return {};
811 }
812 const auto batteryInfo = mEventHub->getRawBatteryInfo(*eventHubId, batteryIds.front());
813 if (!batteryInfo) {
814 ALOGW("%s: Failed to get RawBatteryInfo for battery %d of EventHub device %d", __func__,
815 batteryIds.front(), *eventHubId);
816 return {};
817 }
818 return batteryInfo->path;
819}
820
Siarhei Vishniakou1983a712021-06-04 19:27:09 +0000821std::vector<InputDeviceLightInfo> InputReader::getLights(int32_t deviceId) {
Chris Ye3fdbfef2021-01-06 18:45:18 -0800822 std::scoped_lock _l(mLock);
823
824 InputDevice* device = findInputDeviceLocked(deviceId);
Siarhei Vishniakou1983a712021-06-04 19:27:09 +0000825 if (device == nullptr) {
826 return {};
Chris Ye3fdbfef2021-01-06 18:45:18 -0800827 }
Siarhei Vishniakou1983a712021-06-04 19:27:09 +0000828
829 return device->getDeviceInfo().getLights();
Chris Ye3fdbfef2021-01-06 18:45:18 -0800830}
831
Siarhei Vishniakou1983a712021-06-04 19:27:09 +0000832std::vector<InputDeviceSensorInfo> InputReader::getSensors(int32_t deviceId) {
Chris Ye3fdbfef2021-01-06 18:45:18 -0800833 std::scoped_lock _l(mLock);
834
835 InputDevice* device = findInputDeviceLocked(deviceId);
Siarhei Vishniakou1983a712021-06-04 19:27:09 +0000836 if (device == nullptr) {
837 return {};
Chris Ye3fdbfef2021-01-06 18:45:18 -0800838 }
Siarhei Vishniakou1983a712021-06-04 19:27:09 +0000839
840 return device->getDeviceInfo().getSensors();
Chris Ye3fdbfef2021-01-06 18:45:18 -0800841}
842
843bool InputReader::setLightColor(int32_t deviceId, int32_t lightId, int32_t color) {
844 std::scoped_lock _l(mLock);
845
846 InputDevice* device = findInputDeviceLocked(deviceId);
847 if (device) {
848 return device->setLightColor(lightId, color);
849 }
850 return false;
851}
852
853bool InputReader::setLightPlayerId(int32_t deviceId, int32_t lightId, int32_t playerId) {
854 std::scoped_lock _l(mLock);
855
856 InputDevice* device = findInputDeviceLocked(deviceId);
857 if (device) {
858 return device->setLightPlayerId(lightId, playerId);
859 }
860 return false;
861}
862
863std::optional<int32_t> InputReader::getLightColor(int32_t deviceId, int32_t lightId) {
864 std::scoped_lock _l(mLock);
865
866 InputDevice* device = findInputDeviceLocked(deviceId);
867 if (device) {
868 return device->getLightColor(lightId);
869 }
870 return std::nullopt;
871}
872
873std::optional<int32_t> InputReader::getLightPlayerId(int32_t deviceId, int32_t lightId) {
874 std::scoped_lock _l(mLock);
875
876 InputDevice* device = findInputDeviceLocked(deviceId);
877 if (device) {
878 return device->getLightPlayerId(lightId);
879 }
880 return std::nullopt;
881}
882
Prabir Pradhanb54ffb22022-10-27 18:03:34 +0000883std::optional<std::string> InputReader::getBluetoothAddress(int32_t deviceId) const {
884 std::scoped_lock _l(mLock);
885
886 InputDevice* device = findInputDeviceLocked(deviceId);
887 if (device) {
888 return device->getBluetoothAddress();
889 }
890 return std::nullopt;
891}
892
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700893bool InputReader::isInputDeviceEnabled(int32_t deviceId) {
Chris Ye87143712020-11-10 05:05:58 +0000894 std::scoped_lock _l(mLock);
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700895
Chris Ye1c2e0892020-11-30 21:41:44 -0800896 InputDevice* device = findInputDeviceLocked(deviceId);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800897 if (device) {
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700898 return device->isEnabled();
899 }
900 ALOGW("Ignoring invalid device id %" PRId32 ".", deviceId);
901 return false;
902}
903
Arthur Hungc23540e2018-11-29 20:42:11 +0800904bool InputReader::canDispatchToDisplay(int32_t deviceId, int32_t displayId) {
Chris Ye87143712020-11-10 05:05:58 +0000905 std::scoped_lock _l(mLock);
Arthur Hungc23540e2018-11-29 20:42:11 +0800906
Chris Ye1c2e0892020-11-30 21:41:44 -0800907 InputDevice* device = findInputDeviceLocked(deviceId);
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800908 if (!device) {
Arthur Hungc23540e2018-11-29 20:42:11 +0800909 ALOGW("Ignoring invalid device id %" PRId32 ".", deviceId);
910 return false;
911 }
912
Arthur Hung2c9a3342019-07-23 14:18:59 +0800913 if (!device->isEnabled()) {
914 ALOGW("Ignoring disabled device %s", device->getName().c_str());
915 return false;
916 }
917
918 std::optional<int32_t> associatedDisplayId = device->getAssociatedDisplayId();
Arthur Hungc23540e2018-11-29 20:42:11 +0800919 // No associated display. By default, can dispatch to all displays.
Weilun Dud00847d2021-12-08 10:55:58 -0800920 if (!associatedDisplayId ||
921 *associatedDisplayId == ADISPLAY_ID_NONE) {
Arthur Hungc23540e2018-11-29 20:42:11 +0800922 return true;
923 }
924
925 return *associatedDisplayId == displayId;
926}
927
Vaibhav Devmurari5fc7d852023-03-17 18:43:33 +0000928void InputReader::sysfsNodeChanged(const std::string& sysfsNodePath) {
929 mEventHub->sysfsNodeChanged(sysfsNodePath);
930}
931
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800932void InputReader::dump(std::string& dump) {
Chris Ye87143712020-11-10 05:05:58 +0000933 std::scoped_lock _l(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800934
935 mEventHub->dump(dump);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800936 dump += "\n";
Michael Wrightd02c5b62014-02-10 15:10:22 -0800937
Chris Yee7310032020-09-22 15:36:28 -0700938 dump += StringPrintf("Input Reader State (Nums of device: %zu):\n",
939 mDeviceToEventHubIdsMap.size());
Michael Wrightd02c5b62014-02-10 15:10:22 -0800940
Chris Yee7310032020-09-22 15:36:28 -0700941 for (const auto& devicePair : mDeviceToEventHubIdsMap) {
942 const std::shared_ptr<InputDevice>& device = devicePair.first;
943 std::string eventHubDevStr = INDENT "EventHub Devices: [ ";
944 for (const auto& eId : devicePair.second) {
945 eventHubDevStr += StringPrintf("%d ", eId);
946 }
947 eventHubDevStr += "] \n";
948 device->dump(dump, eventHubDevStr);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800949 }
950
Harry Cutts8c7cb592023-08-23 17:20:13 +0000951 dump += StringPrintf(INDENT "NextTimeout: %" PRId64 "\n", mNextTimeout);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800952 dump += INDENT "Configuration:\n";
953 dump += INDENT2 "ExcludedDeviceNames: [";
Michael Wrightd02c5b62014-02-10 15:10:22 -0800954 for (size_t i = 0; i < mConfig.excludedDeviceNames.size(); i++) {
955 if (i != 0) {
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800956 dump += ", ";
Michael Wrightd02c5b62014-02-10 15:10:22 -0800957 }
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100958 dump += mConfig.excludedDeviceNames[i];
Michael Wrightd02c5b62014-02-10 15:10:22 -0800959 }
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800960 dump += "]\n";
961 dump += StringPrintf(INDENT2 "VirtualKeyQuietTime: %0.1fms\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700962 mConfig.virtualKeyQuietTime * 0.000001f);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800963
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800964 dump += StringPrintf(INDENT2 "PointerVelocityControlParameters: "
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700965 "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, "
966 "acceleration=%0.3f\n",
967 mConfig.pointerVelocityControlParameters.scale,
968 mConfig.pointerVelocityControlParameters.lowThreshold,
969 mConfig.pointerVelocityControlParameters.highThreshold,
970 mConfig.pointerVelocityControlParameters.acceleration);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800971
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800972 dump += StringPrintf(INDENT2 "WheelVelocityControlParameters: "
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700973 "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, "
974 "acceleration=%0.3f\n",
975 mConfig.wheelVelocityControlParameters.scale,
976 mConfig.wheelVelocityControlParameters.lowThreshold,
977 mConfig.wheelVelocityControlParameters.highThreshold,
978 mConfig.wheelVelocityControlParameters.acceleration);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800979
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800980 dump += StringPrintf(INDENT2 "PointerGesture:\n");
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700981 dump += StringPrintf(INDENT3 "Enabled: %s\n", toString(mConfig.pointerGesturesEnabled));
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800982 dump += StringPrintf(INDENT3 "QuietInterval: %0.1fms\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700983 mConfig.pointerGestureQuietInterval * 0.000001f);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800984 dump += StringPrintf(INDENT3 "DragMinSwitchSpeed: %0.1fpx/s\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700985 mConfig.pointerGestureDragMinSwitchSpeed);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800986 dump += StringPrintf(INDENT3 "TapInterval: %0.1fms\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700987 mConfig.pointerGestureTapInterval * 0.000001f);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800988 dump += StringPrintf(INDENT3 "TapDragInterval: %0.1fms\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700989 mConfig.pointerGestureTapDragInterval * 0.000001f);
990 dump += StringPrintf(INDENT3 "TapSlop: %0.1fpx\n", mConfig.pointerGestureTapSlop);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800991 dump += StringPrintf(INDENT3 "MultitouchSettleInterval: %0.1fms\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700992 mConfig.pointerGestureMultitouchSettleInterval * 0.000001f);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800993 dump += StringPrintf(INDENT3 "MultitouchMinDistance: %0.1fpx\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700994 mConfig.pointerGestureMultitouchMinDistance);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800995 dump += StringPrintf(INDENT3 "SwipeTransitionAngleCosine: %0.1f\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700996 mConfig.pointerGestureSwipeTransitionAngleCosine);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800997 dump += StringPrintf(INDENT3 "SwipeMaxWidthRatio: %0.1f\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700998 mConfig.pointerGestureSwipeMaxWidthRatio);
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800999 dump += StringPrintf(INDENT3 "MovementSpeedRatio: %0.1f\n",
Prabir Pradhanda7c00c2019-08-29 14:12:42 -07001000 mConfig.pointerGestureMovementSpeedRatio);
1001 dump += StringPrintf(INDENT3 "ZoomSpeedRatio: %0.1f\n", mConfig.pointerGestureZoomSpeedRatio);
Santos Cordonfa5cf462017-04-05 10:37:00 -07001002
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -08001003 dump += INDENT3 "Viewports:\n";
Santos Cordonfa5cf462017-04-05 10:37:00 -07001004 mConfig.dump(dump);
Michael Wrightd02c5b62014-02-10 15:10:22 -08001005}
1006
1007void InputReader::monitor() {
1008 // Acquire and release the lock to ensure that the reader has not deadlocked.
Chris Ye1c2e0892020-11-30 21:41:44 -08001009 std::unique_lock<std::mutex> lock(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -08001010 mEventHub->wake();
Chris Ye1c2e0892020-11-30 21:41:44 -08001011 mReaderIsAliveCondition.wait(lock);
Michael Wrightd02c5b62014-02-10 15:10:22 -08001012 // Check the EventHub
1013 mEventHub->monitor();
1014}
1015
Michael Wrightd02c5b62014-02-10 15:10:22 -08001016// --- InputReader::ContextImpl ---
1017
Garfield Tanff1f1bb2020-01-28 13:24:04 -08001018InputReader::ContextImpl::ContextImpl(InputReader* reader)
1019 : mReader(reader), mIdGenerator(IdGenerator::Source::INPUT_READER) {}
Michael Wrightd02c5b62014-02-10 15:10:22 -08001020
1021void InputReader::ContextImpl::updateGlobalMetaState() {
1022 // lock is already held by the input loop
1023 mReader->updateGlobalMetaStateLocked();
1024}
1025
1026int32_t InputReader::ContextImpl::getGlobalMetaState() {
1027 // lock is already held by the input loop
1028 return mReader->getGlobalMetaStateLocked();
1029}
1030
arthurhungc903df12020-08-11 15:08:42 +08001031void InputReader::ContextImpl::updateLedMetaState(int32_t metaState) {
1032 // lock is already held by the input loop
1033 mReader->updateLedMetaStateLocked(metaState);
1034}
1035
1036int32_t InputReader::ContextImpl::getLedMetaState() {
1037 // lock is already held by the input loop
1038 return mReader->getLedMetaStateLocked();
1039}
1040
Arpit Singha5ea7c12023-07-05 15:39:25 +00001041void InputReader::ContextImpl::setPreventingTouchpadTaps(bool prevent) {
1042 // lock is already held by the input loop
1043 mReader->mPreventingTouchpadTaps = prevent;
1044}
1045
1046bool InputReader::ContextImpl::isPreventingTouchpadTaps() {
1047 // lock is already held by the input loop
1048 return mReader->mPreventingTouchpadTaps;
1049}
1050
Arpit Singh82e413e2023-10-10 19:30:58 +00001051void InputReader::ContextImpl::setLastKeyDownTimestamp(nsecs_t when) {
1052 mReader->mLastKeyDownTimestamp = when;
1053}
1054
1055nsecs_t InputReader::ContextImpl::getLastKeyDownTimestamp() {
1056 return mReader->mLastKeyDownTimestamp;
1057}
1058
Michael Wrightd02c5b62014-02-10 15:10:22 -08001059void InputReader::ContextImpl::disableVirtualKeysUntil(nsecs_t time) {
1060 // lock is already held by the input loop
1061 mReader->disableVirtualKeysUntilLocked(time);
1062}
1063
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -08001064bool InputReader::ContextImpl::shouldDropVirtualKey(nsecs_t now, int32_t keyCode,
1065 int32_t scanCode) {
Michael Wrightd02c5b62014-02-10 15:10:22 -08001066 // lock is already held by the input loop
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -08001067 return mReader->shouldDropVirtualKeyLocked(now, keyCode, scanCode);
Michael Wrightd02c5b62014-02-10 15:10:22 -08001068}
1069
1070void InputReader::ContextImpl::fadePointer() {
1071 // lock is already held by the input loop
1072 mReader->fadePointerLocked();
1073}
1074
Michael Wright17db18e2020-06-26 20:51:44 +01001075std::shared_ptr<PointerControllerInterface> InputReader::ContextImpl::getPointerController(
1076 int32_t deviceId) {
Prabir Pradhanc7ef27e2020-02-03 19:19:15 -08001077 // lock is already held by the input loop
1078 return mReader->getPointerControllerLocked(deviceId);
1079}
1080
Michael Wrightd02c5b62014-02-10 15:10:22 -08001081void InputReader::ContextImpl::requestTimeoutAtTime(nsecs_t when) {
1082 // lock is already held by the input loop
1083 mReader->requestTimeoutAtTimeLocked(when);
1084}
1085
1086int32_t InputReader::ContextImpl::bumpGeneration() {
1087 // lock is already held by the input loop
1088 return mReader->bumpGenerationLocked();
1089}
1090
Arthur Hung7c3ae9c2019-03-11 11:23:03 +08001091void InputReader::ContextImpl::getExternalStylusDevices(std::vector<InputDeviceInfo>& outDevices) {
Michael Wright842500e2015-03-13 17:32:02 -07001092 // lock is already held by whatever called refreshConfigurationLocked
1093 mReader->getExternalStylusDevicesLocked(outDevices);
1094}
1095
Siarhei Vishniakou2935db72022-09-22 13:35:22 -07001096std::list<NotifyArgs> InputReader::ContextImpl::dispatchExternalStylusState(
1097 const StylusState& state) {
1098 return mReader->dispatchExternalStylusStateLocked(state);
Michael Wright842500e2015-03-13 17:32:02 -07001099}
1100
Michael Wrightd02c5b62014-02-10 15:10:22 -08001101InputReaderPolicyInterface* InputReader::ContextImpl::getPolicy() {
1102 return mReader->mPolicy.get();
1103}
1104
Michael Wrightd02c5b62014-02-10 15:10:22 -08001105EventHubInterface* InputReader::ContextImpl::getEventHub() {
1106 return mReader->mEventHub.get();
1107}
1108
Siarhei Vishniakouf2f073b2021-02-09 21:59:56 +00001109int32_t InputReader::ContextImpl::getNextId() {
1110 return mIdGenerator.nextId();
Prabir Pradhan42611e02018-11-27 14:04:02 -08001111}
Michael Wrightd02c5b62014-02-10 15:10:22 -08001112
Michael Wrightd02c5b62014-02-10 15:10:22 -08001113} // namespace android