| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2010 The Android Open Source Project | 
 | 3 |  * | 
 | 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 5 |  * you may not use this file except in compliance with the License. | 
 | 6 |  * You may obtain a copy of the License at | 
 | 7 |  * | 
 | 8 |  *      http://www.apache.org/licenses/LICENSE-2.0 | 
 | 9 |  * | 
 | 10 |  * Unless required by applicable law or agreed to in writing, software | 
 | 11 |  * distributed under the License is distributed on an "AS IS" BASIS, | 
 | 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 13 |  * See the License for the specific language governing permissions and | 
 | 14 |  * limitations under the License. | 
 | 15 |  */ | 
 | 16 |  | 
| Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 17 | #include "Macros.h" | 
| Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 18 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 19 | #include "InputReader.h" | 
 | 20 |  | 
| Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 21 | #include <android-base/stringprintf.h> | 
| Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 22 | #include <errno.h> | 
| Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 23 | #include <input/Keyboard.h> | 
 | 24 | #include <input/VirtualKeyMap.h> | 
| Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 25 | #include <inttypes.h> | 
| Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 26 | #include <limits.h> | 
| Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 27 | #include <log/log.h> | 
| Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 28 | #include <math.h> | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 29 | #include <stddef.h> | 
 | 30 | #include <stdlib.h> | 
 | 31 | #include <unistd.h> | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 32 | #include <utils/Errors.h> | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 33 | #include <utils/Thread.h> | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 34 |  | 
| Nathaniel R. Lewis | f4916ef | 2020-01-14 11:57:18 -0800 | [diff] [blame] | 35 | #include "InputDevice.h" | 
 | 36 |  | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 37 | using android::base::StringPrintf; | 
 | 38 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 39 | namespace android { | 
 | 40 |  | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 41 | // --- InputReader --- | 
 | 42 |  | 
| Siarhei Vishniakou | 3bc7e09 | 2019-07-24 17:43:30 -0700 | [diff] [blame] | 43 | InputReader::InputReader(std::shared_ptr<EventHubInterface> eventHub, | 
 | 44 |                          const sp<InputReaderPolicyInterface>& policy, | 
 | 45 |                          const sp<InputListenerInterface>& listener) | 
 | 46 |       : mContext(this), | 
 | 47 |         mEventHub(eventHub), | 
 | 48 |         mPolicy(policy), | 
| Siarhei Vishniakou | 3bc7e09 | 2019-07-24 17:43:30 -0700 | [diff] [blame] | 49 |         mGlobalMetaState(0), | 
| arthurhung | c903df1 | 2020-08-11 15:08:42 +0800 | [diff] [blame] | 50 |         mLedMetaState(AMETA_NUM_LOCK_ON), | 
| Siarhei Vishniakou | 3bc7e09 | 2019-07-24 17:43:30 -0700 | [diff] [blame] | 51 |         mGeneration(1), | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 52 |         mNextInputDeviceId(END_RESERVED_ID), | 
| Siarhei Vishniakou | 3bc7e09 | 2019-07-24 17:43:30 -0700 | [diff] [blame] | 53 |         mDisableVirtualKeysTimeout(LLONG_MIN), | 
 | 54 |         mNextTimeout(LLONG_MAX), | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 55 |         mConfigurationChangesToRefresh(0) { | 
 | 56 |     mQueuedListener = new QueuedInputListener(listener); | 
 | 57 |  | 
 | 58 |     { // acquire lock | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 59 |         std::scoped_lock _l(mLock); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 60 |  | 
 | 61 |         refreshConfigurationLocked(0); | 
 | 62 |         updateGlobalMetaStateLocked(); | 
 | 63 |     } // release lock | 
 | 64 | } | 
 | 65 |  | 
| Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 66 | InputReader::~InputReader() {} | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 67 |  | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 68 | status_t InputReader::start() { | 
| Prabir Pradhan | 5a57cff | 2019-10-31 18:40:33 -0700 | [diff] [blame] | 69 |     if (mThread) { | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 70 |         return ALREADY_EXISTS; | 
 | 71 |     } | 
| Prabir Pradhan | 5a57cff | 2019-10-31 18:40:33 -0700 | [diff] [blame] | 72 |     mThread = std::make_unique<InputThread>( | 
 | 73 |             "InputReader", [this]() { loopOnce(); }, [this]() { mEventHub->wake(); }); | 
 | 74 |     return OK; | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 75 | } | 
 | 76 |  | 
 | 77 | status_t InputReader::stop() { | 
| Prabir Pradhan | 5a57cff | 2019-10-31 18:40:33 -0700 | [diff] [blame] | 78 |     if (mThread && mThread->isCallingThread()) { | 
 | 79 |         ALOGE("InputReader cannot be stopped from its own thread!"); | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 80 |         return INVALID_OPERATION; | 
 | 81 |     } | 
| Prabir Pradhan | 5a57cff | 2019-10-31 18:40:33 -0700 | [diff] [blame] | 82 |     mThread.reset(); | 
 | 83 |     return OK; | 
| Prabir Pradhan | 28efc19 | 2019-11-05 01:10:04 +0000 | [diff] [blame] | 84 | } | 
 | 85 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 86 | void InputReader::loopOnce() { | 
 | 87 |     int32_t oldGeneration; | 
 | 88 |     int32_t timeoutMillis; | 
 | 89 |     bool inputDevicesChanged = false; | 
| Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 90 |     std::vector<InputDeviceInfo> inputDevices; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 91 |     { // acquire lock | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 92 |         std::scoped_lock _l(mLock); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 93 |  | 
 | 94 |         oldGeneration = mGeneration; | 
 | 95 |         timeoutMillis = -1; | 
 | 96 |  | 
 | 97 |         uint32_t changes = mConfigurationChangesToRefresh; | 
 | 98 |         if (changes) { | 
 | 99 |             mConfigurationChangesToRefresh = 0; | 
 | 100 |             timeoutMillis = 0; | 
 | 101 |             refreshConfigurationLocked(changes); | 
 | 102 |         } else if (mNextTimeout != LLONG_MAX) { | 
 | 103 |             nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); | 
 | 104 |             timeoutMillis = toMillisecondTimeoutDelay(now, mNextTimeout); | 
 | 105 |         } | 
 | 106 |     } // release lock | 
 | 107 |  | 
 | 108 |     size_t count = mEventHub->getEvents(timeoutMillis, mEventBuffer, EVENT_BUFFER_SIZE); | 
 | 109 |  | 
 | 110 |     { // acquire lock | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 111 |         std::scoped_lock _l(mLock); | 
| Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 112 |         mReaderIsAliveCondition.notify_all(); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 113 |  | 
 | 114 |         if (count) { | 
 | 115 |             processEventsLocked(mEventBuffer, count); | 
 | 116 |         } | 
 | 117 |  | 
 | 118 |         if (mNextTimeout != LLONG_MAX) { | 
 | 119 |             nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); | 
 | 120 |             if (now >= mNextTimeout) { | 
 | 121 | #if DEBUG_RAW_EVENTS | 
 | 122 |                 ALOGD("Timeout expired, latency=%0.3fms", (now - mNextTimeout) * 0.000001f); | 
 | 123 | #endif | 
 | 124 |                 mNextTimeout = LLONG_MAX; | 
 | 125 |                 timeoutExpiredLocked(now); | 
 | 126 |             } | 
 | 127 |         } | 
 | 128 |  | 
 | 129 |         if (oldGeneration != mGeneration) { | 
 | 130 |             inputDevicesChanged = true; | 
| Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 131 |             inputDevices = getInputDevicesLocked(); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 132 |         } | 
 | 133 |     } // release lock | 
 | 134 |  | 
 | 135 |     // Send out a message that the describes the changed input devices. | 
 | 136 |     if (inputDevicesChanged) { | 
| Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 137 |         mPolicy->notifyInputDevicesChanged(inputDevices); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 138 |     } | 
 | 139 |  | 
 | 140 |     // Flush queued events out to the listener. | 
 | 141 |     // This must happen outside of the lock because the listener could potentially call | 
 | 142 |     // back into the InputReader's methods, such as getScanCodeState, or become blocked | 
 | 143 |     // on another thread similarly waiting to acquire the InputReader lock thereby | 
 | 144 |     // resulting in a deadlock.  This situation is actually quite plausible because the | 
 | 145 |     // listener is actually the input dispatcher, which calls into the window manager, | 
 | 146 |     // which occasionally calls into the input reader. | 
 | 147 |     mQueuedListener->flush(); | 
 | 148 | } | 
 | 149 |  | 
 | 150 | void InputReader::processEventsLocked(const RawEvent* rawEvents, size_t count) { | 
 | 151 |     for (const RawEvent* rawEvent = rawEvents; count;) { | 
 | 152 |         int32_t type = rawEvent->type; | 
 | 153 |         size_t batchSize = 1; | 
 | 154 |         if (type < EventHubInterface::FIRST_SYNTHETIC_EVENT) { | 
 | 155 |             int32_t deviceId = rawEvent->deviceId; | 
 | 156 |             while (batchSize < count) { | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 157 |                 if (rawEvent[batchSize].type >= EventHubInterface::FIRST_SYNTHETIC_EVENT || | 
 | 158 |                     rawEvent[batchSize].deviceId != deviceId) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 159 |                     break; | 
 | 160 |                 } | 
 | 161 |                 batchSize += 1; | 
 | 162 |             } | 
 | 163 | #if DEBUG_RAW_EVENTS | 
| Siarhei Vishniakou | 5d83f60 | 2017-09-12 12:40:29 -0700 | [diff] [blame] | 164 |             ALOGD("BatchSize: %zu Count: %zu", batchSize, count); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 165 | #endif | 
 | 166 |             processEventsForDeviceLocked(deviceId, rawEvent, batchSize); | 
 | 167 |         } else { | 
 | 168 |             switch (rawEvent->type) { | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 169 |                 case EventHubInterface::DEVICE_ADDED: | 
 | 170 |                     addDeviceLocked(rawEvent->when, rawEvent->deviceId); | 
 | 171 |                     break; | 
 | 172 |                 case EventHubInterface::DEVICE_REMOVED: | 
 | 173 |                     removeDeviceLocked(rawEvent->when, rawEvent->deviceId); | 
 | 174 |                     break; | 
 | 175 |                 case EventHubInterface::FINISHED_DEVICE_SCAN: | 
 | 176 |                     handleConfigurationChangedLocked(rawEvent->when); | 
 | 177 |                     break; | 
 | 178 |                 default: | 
 | 179 |                     ALOG_ASSERT(false); // can't happen | 
 | 180 |                     break; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 181 |             } | 
 | 182 |         } | 
 | 183 |         count -= batchSize; | 
 | 184 |         rawEvent += batchSize; | 
 | 185 |     } | 
 | 186 | } | 
 | 187 |  | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 188 | void InputReader::addDeviceLocked(nsecs_t when, int32_t eventHubId) { | 
 | 189 |     if (mDevices.find(eventHubId) != mDevices.end()) { | 
 | 190 |         ALOGW("Ignoring spurious device added event for eventHubId %d.", eventHubId); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 191 |         return; | 
 | 192 |     } | 
 | 193 |  | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 194 |     InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(eventHubId); | 
 | 195 |     std::shared_ptr<InputDevice> device = createDeviceLocked(eventHubId, identifier); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 196 |     device->configure(when, &mConfig, 0); | 
 | 197 |     device->reset(when); | 
 | 198 |  | 
 | 199 |     if (device->isIgnored()) { | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 200 |         ALOGI("Device added: id=%d, eventHubId=%d, name='%s', descriptor='%s' " | 
 | 201 |               "(ignored non-input device)", | 
 | 202 |               device->getId(), eventHubId, identifier.name.c_str(), identifier.descriptor.c_str()); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 203 |     } else { | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 204 |         ALOGI("Device added: id=%d, eventHubId=%d, name='%s', descriptor='%s',sources=0x%08x", | 
 | 205 |               device->getId(), eventHubId, identifier.name.c_str(), identifier.descriptor.c_str(), | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 206 |               device->getSources()); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 207 |     } | 
 | 208 |  | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 209 |     mDevices.emplace(eventHubId, device); | 
| Chris Ye | e731003 | 2020-09-22 15:36:28 -0700 | [diff] [blame] | 210 |     // Add device to device to EventHub ids map. | 
 | 211 |     const auto mapIt = mDeviceToEventHubIdsMap.find(device); | 
 | 212 |     if (mapIt == mDeviceToEventHubIdsMap.end()) { | 
 | 213 |         std::vector<int32_t> ids = {eventHubId}; | 
 | 214 |         mDeviceToEventHubIdsMap.emplace(device, ids); | 
 | 215 |     } else { | 
 | 216 |         mapIt->second.push_back(eventHubId); | 
 | 217 |     } | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 218 |     bumpGenerationLocked(); | 
| Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 219 |  | 
| Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 220 |     if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS)) { | 
| Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 221 |         notifyExternalStylusPresenceChangedLocked(); | 
| Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 222 |     } | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 223 | } | 
 | 224 |  | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 225 | void InputReader::removeDeviceLocked(nsecs_t when, int32_t eventHubId) { | 
 | 226 |     auto deviceIt = mDevices.find(eventHubId); | 
| Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 227 |     if (deviceIt == mDevices.end()) { | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 228 |         ALOGW("Ignoring spurious device removed event for eventHubId %d.", eventHubId); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 229 |         return; | 
 | 230 |     } | 
 | 231 |  | 
| Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 232 |     std::shared_ptr<InputDevice> device = std::move(deviceIt->second); | 
| Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 233 |     mDevices.erase(deviceIt); | 
| Chris Ye | e731003 | 2020-09-22 15:36:28 -0700 | [diff] [blame] | 234 |     // Erase device from device to EventHub ids map. | 
 | 235 |     auto mapIt = mDeviceToEventHubIdsMap.find(device); | 
 | 236 |     if (mapIt != mDeviceToEventHubIdsMap.end()) { | 
 | 237 |         std::vector<int32_t>& eventHubIds = mapIt->second; | 
 | 238 |         eventHubIds.erase(std::remove_if(eventHubIds.begin(), eventHubIds.end(), | 
 | 239 |                                          [eventHubId](int32_t eId) { return eId == eventHubId; }), | 
 | 240 |                           eventHubIds.end()); | 
 | 241 |         if (eventHubIds.size() == 0) { | 
 | 242 |             mDeviceToEventHubIdsMap.erase(mapIt); | 
 | 243 |         } | 
 | 244 |     } | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 245 |     bumpGenerationLocked(); | 
 | 246 |  | 
 | 247 |     if (device->isIgnored()) { | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 248 |         ALOGI("Device removed: id=%d, eventHubId=%d, name='%s', descriptor='%s' " | 
 | 249 |               "(ignored non-input device)", | 
 | 250 |               device->getId(), eventHubId, device->getName().c_str(), | 
 | 251 |               device->getDescriptor().c_str()); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 252 |     } else { | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 253 |         ALOGI("Device removed: id=%d, eventHubId=%d, name='%s', descriptor='%s', sources=0x%08x", | 
 | 254 |               device->getId(), eventHubId, device->getName().c_str(), | 
 | 255 |               device->getDescriptor().c_str(), device->getSources()); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 256 |     } | 
 | 257 |  | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 258 |     device->removeEventHubDevice(eventHubId); | 
 | 259 |  | 
| Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 260 |     if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS)) { | 
| Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 261 |         notifyExternalStylusPresenceChangedLocked(); | 
| Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 262 |     } | 
 | 263 |  | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 264 |     if (device->hasEventHubDevices()) { | 
 | 265 |         device->configure(when, &mConfig, 0); | 
 | 266 |     } | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 267 |     device->reset(when); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 268 | } | 
 | 269 |  | 
| Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 270 | std::shared_ptr<InputDevice> InputReader::createDeviceLocked( | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 271 |         int32_t eventHubId, const InputDeviceIdentifier& identifier) { | 
 | 272 |     auto deviceIt = std::find_if(mDevices.begin(), mDevices.end(), [identifier](auto& devicePair) { | 
 | 273 |         return devicePair.second->getDescriptor().size() && identifier.descriptor.size() && | 
 | 274 |                 devicePair.second->getDescriptor() == identifier.descriptor; | 
 | 275 |     }); | 
 | 276 |  | 
 | 277 |     std::shared_ptr<InputDevice> device; | 
 | 278 |     if (deviceIt != mDevices.end()) { | 
 | 279 |         device = deviceIt->second; | 
 | 280 |     } else { | 
 | 281 |         int32_t deviceId = (eventHubId < END_RESERVED_ID) ? eventHubId : nextInputDeviceIdLocked(); | 
 | 282 |         device = std::make_shared<InputDevice>(&mContext, deviceId, bumpGenerationLocked(), | 
 | 283 |                                                identifier); | 
 | 284 |     } | 
 | 285 |     device->addEventHubDevice(eventHubId); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 286 |     return device; | 
 | 287 | } | 
 | 288 |  | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 289 | void InputReader::processEventsForDeviceLocked(int32_t eventHubId, const RawEvent* rawEvents, | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 290 |                                                size_t count) { | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 291 |     auto deviceIt = mDevices.find(eventHubId); | 
| Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 292 |     if (deviceIt == mDevices.end()) { | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 293 |         ALOGW("Discarding event for unknown eventHubId %d.", eventHubId); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 294 |         return; | 
 | 295 |     } | 
 | 296 |  | 
| Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 297 |     std::shared_ptr<InputDevice>& device = deviceIt->second; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 298 |     if (device->isIgnored()) { | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 299 |         // ALOGD("Discarding event for ignored deviceId %d.", deviceId); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 300 |         return; | 
 | 301 |     } | 
 | 302 |  | 
 | 303 |     device->process(rawEvents, count); | 
 | 304 | } | 
 | 305 |  | 
| Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 306 | InputDevice* InputReader::findInputDeviceLocked(int32_t deviceId) { | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 307 |     auto deviceIt = | 
 | 308 |             std::find_if(mDevices.begin(), mDevices.end(), [deviceId](const auto& devicePair) { | 
 | 309 |                 return devicePair.second->getId() == deviceId; | 
 | 310 |             }); | 
 | 311 |     if (deviceIt != mDevices.end()) { | 
 | 312 |         return deviceIt->second.get(); | 
 | 313 |     } | 
 | 314 |     return nullptr; | 
 | 315 | } | 
 | 316 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 317 | void InputReader::timeoutExpiredLocked(nsecs_t when) { | 
| Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 318 |     for (auto& devicePair : mDevices) { | 
| Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 319 |         std::shared_ptr<InputDevice>& device = devicePair.second; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 320 |         if (!device->isIgnored()) { | 
 | 321 |             device->timeoutExpired(when); | 
 | 322 |         } | 
 | 323 |     } | 
 | 324 | } | 
 | 325 |  | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 326 | int32_t InputReader::nextInputDeviceIdLocked() { | 
 | 327 |     return ++mNextInputDeviceId; | 
 | 328 | } | 
 | 329 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 330 | void InputReader::handleConfigurationChangedLocked(nsecs_t when) { | 
 | 331 |     // Reset global meta state because it depends on the list of all configured devices. | 
 | 332 |     updateGlobalMetaStateLocked(); | 
 | 333 |  | 
 | 334 |     // Enqueue configuration changed. | 
| Garfield Tan | 6a5a14e | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 335 |     NotifyConfigurationChangedArgs args(mContext.getNextId(), when); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 336 |     mQueuedListener->notifyConfigurationChanged(&args); | 
 | 337 | } | 
 | 338 |  | 
 | 339 | void InputReader::refreshConfigurationLocked(uint32_t changes) { | 
 | 340 |     mPolicy->getReaderConfiguration(&mConfig); | 
 | 341 |     mEventHub->setExcludedDevices(mConfig.excludedDeviceNames); | 
 | 342 |  | 
| Prabir Pradhan | 7e18618 | 2020-11-10 13:56:45 -0800 | [diff] [blame] | 343 |     if (!changes) return; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 344 |  | 
| Prabir Pradhan | 7e18618 | 2020-11-10 13:56:45 -0800 | [diff] [blame] | 345 |     ALOGI("Reconfiguring input devices, changes=%s", | 
 | 346 |           InputReaderConfiguration::changesToString(changes).c_str()); | 
 | 347 |     nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); | 
| Prabir Pradhan | c7ef27e | 2020-02-03 19:19:15 -0800 | [diff] [blame] | 348 |  | 
| Prabir Pradhan | 7e18618 | 2020-11-10 13:56:45 -0800 | [diff] [blame] | 349 |     if (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO) { | 
 | 350 |         updatePointerDisplayLocked(); | 
 | 351 |     } | 
 | 352 |  | 
 | 353 |     if (changes & InputReaderConfiguration::CHANGE_MUST_REOPEN) { | 
 | 354 |         mEventHub->requestReopenDevices(); | 
 | 355 |     } else { | 
 | 356 |         for (auto& devicePair : mDevices) { | 
 | 357 |             std::shared_ptr<InputDevice>& device = devicePair.second; | 
 | 358 |             device->configure(now, &mConfig, changes); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 359 |         } | 
 | 360 |     } | 
| Prabir Pradhan | 7e18618 | 2020-11-10 13:56:45 -0800 | [diff] [blame] | 361 |  | 
 | 362 |     if (changes & InputReaderConfiguration::CHANGE_POINTER_CAPTURE) { | 
 | 363 |         const NotifyPointerCaptureChangedArgs args(mContext.getNextId(), now, | 
 | 364 |                                                    mConfig.pointerCapture); | 
 | 365 |         mQueuedListener->notifyPointerCaptureChanged(&args); | 
 | 366 |     } | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 367 | } | 
 | 368 |  | 
 | 369 | void InputReader::updateGlobalMetaStateLocked() { | 
 | 370 |     mGlobalMetaState = 0; | 
 | 371 |  | 
| Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 372 |     for (auto& devicePair : mDevices) { | 
| Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 373 |         std::shared_ptr<InputDevice>& device = devicePair.second; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 374 |         mGlobalMetaState |= device->getMetaState(); | 
 | 375 |     } | 
 | 376 | } | 
 | 377 |  | 
 | 378 | int32_t InputReader::getGlobalMetaStateLocked() { | 
 | 379 |     return mGlobalMetaState; | 
 | 380 | } | 
 | 381 |  | 
| arthurhung | c903df1 | 2020-08-11 15:08:42 +0800 | [diff] [blame] | 382 | void InputReader::updateLedMetaStateLocked(int32_t metaState) { | 
 | 383 |     mLedMetaState = metaState; | 
 | 384 |     for (auto& devicePair : mDevices) { | 
 | 385 |         std::shared_ptr<InputDevice>& device = devicePair.second; | 
 | 386 |         device->updateLedState(false); | 
 | 387 |     } | 
 | 388 | } | 
 | 389 |  | 
 | 390 | int32_t InputReader::getLedMetaStateLocked() { | 
 | 391 |     return mLedMetaState; | 
 | 392 | } | 
 | 393 |  | 
| Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 394 | void InputReader::notifyExternalStylusPresenceChangedLocked() { | 
| Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 395 |     refreshConfigurationLocked(InputReaderConfiguration::CHANGE_EXTERNAL_STYLUS_PRESENCE); | 
 | 396 | } | 
 | 397 |  | 
| Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 398 | void InputReader::getExternalStylusDevicesLocked(std::vector<InputDeviceInfo>& outDevices) { | 
| Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 399 |     for (auto& devicePair : mDevices) { | 
| Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 400 |         std::shared_ptr<InputDevice>& device = devicePair.second; | 
| Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 401 |         if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS) && !device->isIgnored()) { | 
| Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 402 |             InputDeviceInfo info; | 
 | 403 |             device->getDeviceInfo(&info); | 
 | 404 |             outDevices.push_back(info); | 
| Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 405 |         } | 
 | 406 |     } | 
 | 407 | } | 
 | 408 |  | 
 | 409 | void InputReader::dispatchExternalStylusState(const StylusState& state) { | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 410 |     std::scoped_lock _l(mLock); | 
| Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 411 |     for (auto& devicePair : mDevices) { | 
| Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 412 |         std::shared_ptr<InputDevice>& device = devicePair.second; | 
| Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 413 |         device->updateExternalStylusState(state); | 
 | 414 |     } | 
 | 415 | } | 
 | 416 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 417 | void InputReader::disableVirtualKeysUntilLocked(nsecs_t time) { | 
 | 418 |     mDisableVirtualKeysTimeout = time; | 
 | 419 | } | 
 | 420 |  | 
| Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 421 | bool InputReader::shouldDropVirtualKeyLocked(nsecs_t now, int32_t keyCode, int32_t scanCode) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 422 |     if (now < mDisableVirtualKeysTimeout) { | 
| Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 423 |         ALOGI("Dropping virtual key from device because virtual keys are " | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 424 |               "temporarily disabled for the next %0.3fms.  keyCode=%d, scanCode=%d", | 
| Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 425 |               (mDisableVirtualKeysTimeout - now) * 0.000001, keyCode, scanCode); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 426 |         return true; | 
 | 427 |     } else { | 
 | 428 |         return false; | 
 | 429 |     } | 
 | 430 | } | 
 | 431 |  | 
| Michael Wright | 17db18e | 2020-06-26 20:51:44 +0100 | [diff] [blame] | 432 | std::shared_ptr<PointerControllerInterface> InputReader::getPointerControllerLocked( | 
 | 433 |         int32_t deviceId) { | 
 | 434 |     std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock(); | 
| Prabir Pradhan | c7ef27e | 2020-02-03 19:19:15 -0800 | [diff] [blame] | 435 |     if (controller == nullptr) { | 
 | 436 |         controller = mPolicy->obtainPointerController(deviceId); | 
 | 437 |         mPointerController = controller; | 
 | 438 |         updatePointerDisplayLocked(); | 
 | 439 |     } | 
 | 440 |     return controller; | 
 | 441 | } | 
 | 442 |  | 
 | 443 | void InputReader::updatePointerDisplayLocked() { | 
| Michael Wright | 17db18e | 2020-06-26 20:51:44 +0100 | [diff] [blame] | 444 |     std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock(); | 
| Prabir Pradhan | c7ef27e | 2020-02-03 19:19:15 -0800 | [diff] [blame] | 445 |     if (controller == nullptr) { | 
 | 446 |         return; | 
 | 447 |     } | 
 | 448 |  | 
 | 449 |     std::optional<DisplayViewport> viewport = | 
 | 450 |             mConfig.getDisplayViewportById(mConfig.defaultPointerDisplayId); | 
 | 451 |     if (!viewport) { | 
 | 452 |         ALOGW("Can't find the designated viewport with ID %" PRId32 " to update cursor input " | 
 | 453 |               "mapper. Fall back to default display", | 
 | 454 |               mConfig.defaultPointerDisplayId); | 
 | 455 |         viewport = mConfig.getDisplayViewportById(ADISPLAY_ID_DEFAULT); | 
 | 456 |     } | 
 | 457 |     if (!viewport) { | 
 | 458 |         ALOGE("Still can't find a viable viewport to update cursor input mapper. Skip setting it to" | 
 | 459 |               " PointerController."); | 
 | 460 |         return; | 
 | 461 |     } | 
 | 462 |  | 
 | 463 |     controller->setDisplayViewport(*viewport); | 
 | 464 | } | 
 | 465 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 466 | void InputReader::fadePointerLocked() { | 
| Michael Wright | 17db18e | 2020-06-26 20:51:44 +0100 | [diff] [blame] | 467 |     std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock(); | 
| Prabir Pradhan | c7ef27e | 2020-02-03 19:19:15 -0800 | [diff] [blame] | 468 |     if (controller != nullptr) { | 
| Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 469 |         controller->fade(PointerControllerInterface::Transition::GRADUAL); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 470 |     } | 
 | 471 | } | 
 | 472 |  | 
 | 473 | void InputReader::requestTimeoutAtTimeLocked(nsecs_t when) { | 
 | 474 |     if (when < mNextTimeout) { | 
 | 475 |         mNextTimeout = when; | 
 | 476 |         mEventHub->wake(); | 
 | 477 |     } | 
 | 478 | } | 
 | 479 |  | 
 | 480 | int32_t InputReader::bumpGenerationLocked() { | 
 | 481 |     return ++mGeneration; | 
 | 482 | } | 
 | 483 |  | 
| Chris Ye | 98d3f53 | 2020-10-01 21:48:59 -0700 | [diff] [blame] | 484 | std::vector<InputDeviceInfo> InputReader::getInputDevices() const { | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 485 |     std::scoped_lock _l(mLock); | 
| Chris Ye | 98d3f53 | 2020-10-01 21:48:59 -0700 | [diff] [blame] | 486 |     return getInputDevicesLocked(); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 487 | } | 
 | 488 |  | 
| Chris Ye | 98d3f53 | 2020-10-01 21:48:59 -0700 | [diff] [blame] | 489 | std::vector<InputDeviceInfo> InputReader::getInputDevicesLocked() const { | 
 | 490 |     std::vector<InputDeviceInfo> outInputDevices; | 
 | 491 |     outInputDevices.reserve(mDeviceToEventHubIdsMap.size()); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 492 |  | 
| Chris Ye | e731003 | 2020-09-22 15:36:28 -0700 | [diff] [blame] | 493 |     for (const auto& [device, eventHubIds] : mDeviceToEventHubIdsMap) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 494 |         if (!device->isIgnored()) { | 
| Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 495 |             InputDeviceInfo info; | 
 | 496 |             device->getDeviceInfo(&info); | 
 | 497 |             outInputDevices.push_back(info); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 498 |         } | 
 | 499 |     } | 
| Chris Ye | 98d3f53 | 2020-10-01 21:48:59 -0700 | [diff] [blame] | 500 |     return outInputDevices; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 501 | } | 
 | 502 |  | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 503 | int32_t InputReader::getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) { | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 504 |     std::scoped_lock _l(mLock); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 505 |  | 
 | 506 |     return getStateLocked(deviceId, sourceMask, keyCode, &InputDevice::getKeyCodeState); | 
 | 507 | } | 
 | 508 |  | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 509 | int32_t InputReader::getScanCodeState(int32_t deviceId, uint32_t sourceMask, int32_t scanCode) { | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 510 |     std::scoped_lock _l(mLock); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 511 |  | 
 | 512 |     return getStateLocked(deviceId, sourceMask, scanCode, &InputDevice::getScanCodeState); | 
 | 513 | } | 
 | 514 |  | 
 | 515 | int32_t InputReader::getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t switchCode) { | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 516 |     std::scoped_lock _l(mLock); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 517 |  | 
 | 518 |     return getStateLocked(deviceId, sourceMask, switchCode, &InputDevice::getSwitchState); | 
 | 519 | } | 
 | 520 |  | 
 | 521 | int32_t InputReader::getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code, | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 522 |                                     GetStateFunc getStateFunc) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 523 |     int32_t result = AKEY_STATE_UNKNOWN; | 
 | 524 |     if (deviceId >= 0) { | 
| Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 525 |         InputDevice* device = findInputDeviceLocked(deviceId); | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 526 |         if (device && !device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { | 
 | 527 |             result = (device->*getStateFunc)(sourceMask, code); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 528 |         } | 
 | 529 |     } else { | 
| Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 530 |         for (auto& devicePair : mDevices) { | 
| Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 531 |             std::shared_ptr<InputDevice>& device = devicePair.second; | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 532 |             if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 533 |                 // If any device reports AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL, return that | 
 | 534 |                 // value.  Otherwise, return AKEY_STATE_UP as long as one device reports it. | 
| Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 535 |                 int32_t currentResult = (device.get()->*getStateFunc)(sourceMask, code); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 536 |                 if (currentResult >= AKEY_STATE_DOWN) { | 
 | 537 |                     return currentResult; | 
 | 538 |                 } else if (currentResult == AKEY_STATE_UP) { | 
 | 539 |                     result = currentResult; | 
 | 540 |                 } | 
 | 541 |             } | 
 | 542 |         } | 
 | 543 |     } | 
 | 544 |     return result; | 
 | 545 | } | 
 | 546 |  | 
| Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 547 | void InputReader::toggleCapsLockState(int32_t deviceId) { | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 548 |     std::scoped_lock _l(mLock); | 
| Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 549 |     InputDevice* device = findInputDeviceLocked(deviceId); | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 550 |     if (!device) { | 
| Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 551 |         ALOGW("Ignoring toggleCapsLock for unknown deviceId %" PRId32 ".", deviceId); | 
 | 552 |         return; | 
 | 553 |     } | 
 | 554 |  | 
| Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 555 |     if (device->isIgnored()) { | 
 | 556 |         return; | 
 | 557 |     } | 
 | 558 |  | 
 | 559 |     device->updateMetaState(AKEYCODE_CAPS_LOCK); | 
 | 560 | } | 
 | 561 |  | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 562 | bool InputReader::hasKeys(int32_t deviceId, uint32_t sourceMask, size_t numCodes, | 
 | 563 |                           const int32_t* keyCodes, uint8_t* outFlags) { | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 564 |     std::scoped_lock _l(mLock); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 565 |  | 
 | 566 |     memset(outFlags, 0, numCodes); | 
 | 567 |     return markSupportedKeyCodesLocked(deviceId, sourceMask, numCodes, keyCodes, outFlags); | 
 | 568 | } | 
 | 569 |  | 
 | 570 | bool InputReader::markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask, | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 571 |                                               size_t numCodes, const int32_t* keyCodes, | 
 | 572 |                                               uint8_t* outFlags) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 573 |     bool result = false; | 
 | 574 |     if (deviceId >= 0) { | 
| Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 575 |         InputDevice* device = findInputDeviceLocked(deviceId); | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 576 |         if (device && !device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { | 
 | 577 |             result = device->markSupportedKeyCodes(sourceMask, numCodes, keyCodes, outFlags); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 578 |         } | 
 | 579 |     } else { | 
| Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 580 |         for (auto& devicePair : mDevices) { | 
| Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 581 |             std::shared_ptr<InputDevice>& device = devicePair.second; | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 582 |             if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { | 
 | 583 |                 result |= device->markSupportedKeyCodes(sourceMask, numCodes, keyCodes, outFlags); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 584 |             } | 
 | 585 |         } | 
 | 586 |     } | 
 | 587 |     return result; | 
 | 588 | } | 
 | 589 |  | 
 | 590 | void InputReader::requestRefreshConfiguration(uint32_t changes) { | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 591 |     std::scoped_lock _l(mLock); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 592 |  | 
 | 593 |     if (changes) { | 
 | 594 |         bool needWake = !mConfigurationChangesToRefresh; | 
 | 595 |         mConfigurationChangesToRefresh |= changes; | 
 | 596 |  | 
 | 597 |         if (needWake) { | 
 | 598 |             mEventHub->wake(); | 
 | 599 |         } | 
 | 600 |     } | 
 | 601 | } | 
 | 602 |  | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 603 | void InputReader::vibrate(int32_t deviceId, const VibrationSequence& sequence, ssize_t repeat, | 
 | 604 |                           int32_t token) { | 
 | 605 |     std::scoped_lock _l(mLock); | 
 | 606 |  | 
| Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 607 |     InputDevice* device = findInputDeviceLocked(deviceId); | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 608 |     if (device) { | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 609 |         device->vibrate(sequence, repeat, token); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 610 |     } | 
 | 611 | } | 
 | 612 |  | 
 | 613 | void InputReader::cancelVibrate(int32_t deviceId, int32_t token) { | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 614 |     std::scoped_lock _l(mLock); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 615 |  | 
| Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 616 |     InputDevice* device = findInputDeviceLocked(deviceId); | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 617 |     if (device) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 618 |         device->cancelVibrate(token); | 
 | 619 |     } | 
 | 620 | } | 
 | 621 |  | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 622 | bool InputReader::isVibrating(int32_t deviceId) { | 
 | 623 |     std::scoped_lock _l(mLock); | 
 | 624 |  | 
 | 625 |     InputDevice* device = findInputDeviceLocked(deviceId); | 
 | 626 |     if (device) { | 
 | 627 |         return device->isVibrating(); | 
 | 628 |     } | 
 | 629 |     return false; | 
 | 630 | } | 
 | 631 |  | 
 | 632 | std::vector<int32_t> InputReader::getVibratorIds(int32_t deviceId) { | 
 | 633 |     std::scoped_lock _l(mLock); | 
 | 634 |  | 
 | 635 |     InputDevice* device = findInputDeviceLocked(deviceId); | 
 | 636 |     if (device) { | 
 | 637 |         return device->getVibratorIds(); | 
 | 638 |     } | 
 | 639 |     return {}; | 
 | 640 | } | 
 | 641 |  | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 642 | bool InputReader::isInputDeviceEnabled(int32_t deviceId) { | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 643 |     std::scoped_lock _l(mLock); | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 644 |  | 
| Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 645 |     InputDevice* device = findInputDeviceLocked(deviceId); | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 646 |     if (device) { | 
| Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 647 |         return device->isEnabled(); | 
 | 648 |     } | 
 | 649 |     ALOGW("Ignoring invalid device id %" PRId32 ".", deviceId); | 
 | 650 |     return false; | 
 | 651 | } | 
 | 652 |  | 
| Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 653 | bool InputReader::canDispatchToDisplay(int32_t deviceId, int32_t displayId) { | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 654 |     std::scoped_lock _l(mLock); | 
| Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 655 |  | 
| Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 656 |     InputDevice* device = findInputDeviceLocked(deviceId); | 
| Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 657 |     if (!device) { | 
| Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 658 |         ALOGW("Ignoring invalid device id %" PRId32 ".", deviceId); | 
 | 659 |         return false; | 
 | 660 |     } | 
 | 661 |  | 
| Arthur Hung | 2c9a334 | 2019-07-23 14:18:59 +0800 | [diff] [blame] | 662 |     if (!device->isEnabled()) { | 
 | 663 |         ALOGW("Ignoring disabled device %s", device->getName().c_str()); | 
 | 664 |         return false; | 
 | 665 |     } | 
 | 666 |  | 
 | 667 |     std::optional<int32_t> associatedDisplayId = device->getAssociatedDisplayId(); | 
| Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 668 |     // No associated display. By default, can dispatch to all displays. | 
 | 669 |     if (!associatedDisplayId) { | 
 | 670 |         return true; | 
 | 671 |     } | 
 | 672 |  | 
 | 673 |     if (*associatedDisplayId == ADISPLAY_ID_NONE) { | 
| Arthur Hung | 2c9a334 | 2019-07-23 14:18:59 +0800 | [diff] [blame] | 674 |         ALOGW("Device %s is associated with display ADISPLAY_ID_NONE.", device->getName().c_str()); | 
| Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 675 |         return true; | 
 | 676 |     } | 
 | 677 |  | 
 | 678 |     return *associatedDisplayId == displayId; | 
 | 679 | } | 
 | 680 |  | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 681 | void InputReader::dump(std::string& dump) { | 
| Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 682 |     std::scoped_lock _l(mLock); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 683 |  | 
 | 684 |     mEventHub->dump(dump); | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 685 |     dump += "\n"; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 686 |  | 
| Chris Ye | e731003 | 2020-09-22 15:36:28 -0700 | [diff] [blame] | 687 |     dump += StringPrintf("Input Reader State (Nums of device: %zu):\n", | 
 | 688 |                          mDeviceToEventHubIdsMap.size()); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 689 |  | 
| Chris Ye | e731003 | 2020-09-22 15:36:28 -0700 | [diff] [blame] | 690 |     for (const auto& devicePair : mDeviceToEventHubIdsMap) { | 
 | 691 |         const std::shared_ptr<InputDevice>& device = devicePair.first; | 
 | 692 |         std::string eventHubDevStr = INDENT "EventHub Devices: [ "; | 
 | 693 |         for (const auto& eId : devicePair.second) { | 
 | 694 |             eventHubDevStr += StringPrintf("%d ", eId); | 
 | 695 |         } | 
 | 696 |         eventHubDevStr += "] \n"; | 
 | 697 |         device->dump(dump, eventHubDevStr); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 698 |     } | 
 | 699 |  | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 700 |     dump += INDENT "Configuration:\n"; | 
 | 701 |     dump += INDENT2 "ExcludedDeviceNames: ["; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 702 |     for (size_t i = 0; i < mConfig.excludedDeviceNames.size(); i++) { | 
 | 703 |         if (i != 0) { | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 704 |             dump += ", "; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 705 |         } | 
| Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 706 |         dump += mConfig.excludedDeviceNames[i]; | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 707 |     } | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 708 |     dump += "]\n"; | 
 | 709 |     dump += StringPrintf(INDENT2 "VirtualKeyQuietTime: %0.1fms\n", | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 710 |                          mConfig.virtualKeyQuietTime * 0.000001f); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 711 |  | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 712 |     dump += StringPrintf(INDENT2 "PointerVelocityControlParameters: " | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 713 |                                  "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, " | 
 | 714 |                                  "acceleration=%0.3f\n", | 
 | 715 |                          mConfig.pointerVelocityControlParameters.scale, | 
 | 716 |                          mConfig.pointerVelocityControlParameters.lowThreshold, | 
 | 717 |                          mConfig.pointerVelocityControlParameters.highThreshold, | 
 | 718 |                          mConfig.pointerVelocityControlParameters.acceleration); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 719 |  | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 720 |     dump += StringPrintf(INDENT2 "WheelVelocityControlParameters: " | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 721 |                                  "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, " | 
 | 722 |                                  "acceleration=%0.3f\n", | 
 | 723 |                          mConfig.wheelVelocityControlParameters.scale, | 
 | 724 |                          mConfig.wheelVelocityControlParameters.lowThreshold, | 
 | 725 |                          mConfig.wheelVelocityControlParameters.highThreshold, | 
 | 726 |                          mConfig.wheelVelocityControlParameters.acceleration); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 727 |  | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 728 |     dump += StringPrintf(INDENT2 "PointerGesture:\n"); | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 729 |     dump += StringPrintf(INDENT3 "Enabled: %s\n", toString(mConfig.pointerGesturesEnabled)); | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 730 |     dump += StringPrintf(INDENT3 "QuietInterval: %0.1fms\n", | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 731 |                          mConfig.pointerGestureQuietInterval * 0.000001f); | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 732 |     dump += StringPrintf(INDENT3 "DragMinSwitchSpeed: %0.1fpx/s\n", | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 733 |                          mConfig.pointerGestureDragMinSwitchSpeed); | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 734 |     dump += StringPrintf(INDENT3 "TapInterval: %0.1fms\n", | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 735 |                          mConfig.pointerGestureTapInterval * 0.000001f); | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 736 |     dump += StringPrintf(INDENT3 "TapDragInterval: %0.1fms\n", | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 737 |                          mConfig.pointerGestureTapDragInterval * 0.000001f); | 
 | 738 |     dump += StringPrintf(INDENT3 "TapSlop: %0.1fpx\n", mConfig.pointerGestureTapSlop); | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 739 |     dump += StringPrintf(INDENT3 "MultitouchSettleInterval: %0.1fms\n", | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 740 |                          mConfig.pointerGestureMultitouchSettleInterval * 0.000001f); | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 741 |     dump += StringPrintf(INDENT3 "MultitouchMinDistance: %0.1fpx\n", | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 742 |                          mConfig.pointerGestureMultitouchMinDistance); | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 743 |     dump += StringPrintf(INDENT3 "SwipeTransitionAngleCosine: %0.1f\n", | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 744 |                          mConfig.pointerGestureSwipeTransitionAngleCosine); | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 745 |     dump += StringPrintf(INDENT3 "SwipeMaxWidthRatio: %0.1f\n", | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 746 |                          mConfig.pointerGestureSwipeMaxWidthRatio); | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 747 |     dump += StringPrintf(INDENT3 "MovementSpeedRatio: %0.1f\n", | 
| Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 748 |                          mConfig.pointerGestureMovementSpeedRatio); | 
 | 749 |     dump += StringPrintf(INDENT3 "ZoomSpeedRatio: %0.1f\n", mConfig.pointerGestureZoomSpeedRatio); | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 750 |  | 
| Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 751 |     dump += INDENT3 "Viewports:\n"; | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 752 |     mConfig.dump(dump); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 753 | } | 
 | 754 |  | 
 | 755 | void InputReader::monitor() { | 
 | 756 |     // Acquire and release the lock to ensure that the reader has not deadlocked. | 
| Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 757 |     std::unique_lock<std::mutex> lock(mLock); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 758 |     mEventHub->wake(); | 
| Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 759 |     mReaderIsAliveCondition.wait(lock); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 760 |     // Check the EventHub | 
 | 761 |     mEventHub->monitor(); | 
 | 762 | } | 
 | 763 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 764 | // --- InputReader::ContextImpl --- | 
 | 765 |  | 
| Garfield Tan | ff1f1bb | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 766 | InputReader::ContextImpl::ContextImpl(InputReader* reader) | 
 | 767 |       : mReader(reader), mIdGenerator(IdGenerator::Source::INPUT_READER) {} | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 768 |  | 
 | 769 | void InputReader::ContextImpl::updateGlobalMetaState() { | 
 | 770 |     // lock is already held by the input loop | 
 | 771 |     mReader->updateGlobalMetaStateLocked(); | 
 | 772 | } | 
 | 773 |  | 
 | 774 | int32_t InputReader::ContextImpl::getGlobalMetaState() { | 
 | 775 |     // lock is already held by the input loop | 
 | 776 |     return mReader->getGlobalMetaStateLocked(); | 
 | 777 | } | 
 | 778 |  | 
| arthurhung | c903df1 | 2020-08-11 15:08:42 +0800 | [diff] [blame] | 779 | void InputReader::ContextImpl::updateLedMetaState(int32_t metaState) { | 
 | 780 |     // lock is already held by the input loop | 
 | 781 |     mReader->updateLedMetaStateLocked(metaState); | 
 | 782 | } | 
 | 783 |  | 
 | 784 | int32_t InputReader::ContextImpl::getLedMetaState() { | 
 | 785 |     // lock is already held by the input loop | 
 | 786 |     return mReader->getLedMetaStateLocked(); | 
 | 787 | } | 
 | 788 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 789 | void InputReader::ContextImpl::disableVirtualKeysUntil(nsecs_t time) { | 
 | 790 |     // lock is already held by the input loop | 
 | 791 |     mReader->disableVirtualKeysUntilLocked(time); | 
 | 792 | } | 
 | 793 |  | 
| Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 794 | bool InputReader::ContextImpl::shouldDropVirtualKey(nsecs_t now, int32_t keyCode, | 
 | 795 |                                                     int32_t scanCode) { | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 796 |     // lock is already held by the input loop | 
| Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 797 |     return mReader->shouldDropVirtualKeyLocked(now, keyCode, scanCode); | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 798 | } | 
 | 799 |  | 
 | 800 | void InputReader::ContextImpl::fadePointer() { | 
 | 801 |     // lock is already held by the input loop | 
 | 802 |     mReader->fadePointerLocked(); | 
 | 803 | } | 
 | 804 |  | 
| Michael Wright | 17db18e | 2020-06-26 20:51:44 +0100 | [diff] [blame] | 805 | std::shared_ptr<PointerControllerInterface> InputReader::ContextImpl::getPointerController( | 
 | 806 |         int32_t deviceId) { | 
| Prabir Pradhan | c7ef27e | 2020-02-03 19:19:15 -0800 | [diff] [blame] | 807 |     // lock is already held by the input loop | 
 | 808 |     return mReader->getPointerControllerLocked(deviceId); | 
 | 809 | } | 
 | 810 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 811 | void InputReader::ContextImpl::requestTimeoutAtTime(nsecs_t when) { | 
 | 812 |     // lock is already held by the input loop | 
 | 813 |     mReader->requestTimeoutAtTimeLocked(when); | 
 | 814 | } | 
 | 815 |  | 
 | 816 | int32_t InputReader::ContextImpl::bumpGeneration() { | 
 | 817 |     // lock is already held by the input loop | 
 | 818 |     return mReader->bumpGenerationLocked(); | 
 | 819 | } | 
 | 820 |  | 
| Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 821 | void InputReader::ContextImpl::getExternalStylusDevices(std::vector<InputDeviceInfo>& outDevices) { | 
| Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 822 |     // lock is already held by whatever called refreshConfigurationLocked | 
 | 823 |     mReader->getExternalStylusDevicesLocked(outDevices); | 
 | 824 | } | 
 | 825 |  | 
 | 826 | void InputReader::ContextImpl::dispatchExternalStylusState(const StylusState& state) { | 
 | 827 |     mReader->dispatchExternalStylusState(state); | 
 | 828 | } | 
 | 829 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 830 | InputReaderPolicyInterface* InputReader::ContextImpl::getPolicy() { | 
 | 831 |     return mReader->mPolicy.get(); | 
 | 832 | } | 
 | 833 |  | 
 | 834 | InputListenerInterface* InputReader::ContextImpl::getListener() { | 
 | 835 |     return mReader->mQueuedListener.get(); | 
 | 836 | } | 
 | 837 |  | 
 | 838 | EventHubInterface* InputReader::ContextImpl::getEventHub() { | 
 | 839 |     return mReader->mEventHub.get(); | 
 | 840 | } | 
 | 841 |  | 
| Garfield Tan | 6a5a14e | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 842 | int32_t InputReader::ContextImpl::getNextId() { | 
| Garfield Tan | ff1f1bb | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 843 |     return mIdGenerator.nextId(); | 
| Prabir Pradhan | 42611e0 | 2018-11-27 14:04:02 -0800 | [diff] [blame] | 844 | } | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 845 |  | 
| Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 846 | } // namespace android |