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