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 | } |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 223 | |
| 224 | // Sensor input device is noisy, to save power disable it by default. |
Chris Ye | e14523a | 2020-12-19 13:46:00 -0800 | [diff] [blame] | 225 | // Input device is classified as SENSOR when any sub device is a SENSOR device, check Eventhub |
| 226 | // device class to disable SENSOR sub device only. |
| 227 | if (mEventHub->getDeviceClasses(eventHubId).test(InputDeviceClass::SENSOR)) { |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 228 | mEventHub->disableDevice(eventHubId); |
| 229 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 230 | } |
| 231 | |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 232 | void InputReader::removeDeviceLocked(nsecs_t when, int32_t eventHubId) { |
| 233 | auto deviceIt = mDevices.find(eventHubId); |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 234 | if (deviceIt == mDevices.end()) { |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 235 | ALOGW("Ignoring spurious device removed event for eventHubId %d.", eventHubId); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 236 | return; |
| 237 | } |
| 238 | |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 239 | std::shared_ptr<InputDevice> device = std::move(deviceIt->second); |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 240 | mDevices.erase(deviceIt); |
Chris Ye | e731003 | 2020-09-22 15:36:28 -0700 | [diff] [blame] | 241 | // Erase device from device to EventHub ids map. |
| 242 | auto mapIt = mDeviceToEventHubIdsMap.find(device); |
| 243 | if (mapIt != mDeviceToEventHubIdsMap.end()) { |
| 244 | std::vector<int32_t>& eventHubIds = mapIt->second; |
| 245 | eventHubIds.erase(std::remove_if(eventHubIds.begin(), eventHubIds.end(), |
| 246 | [eventHubId](int32_t eId) { return eId == eventHubId; }), |
| 247 | eventHubIds.end()); |
| 248 | if (eventHubIds.size() == 0) { |
| 249 | mDeviceToEventHubIdsMap.erase(mapIt); |
| 250 | } |
| 251 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 252 | bumpGenerationLocked(); |
| 253 | |
| 254 | if (device->isIgnored()) { |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 255 | ALOGI("Device removed: id=%d, eventHubId=%d, name='%s', descriptor='%s' " |
| 256 | "(ignored non-input device)", |
| 257 | device->getId(), eventHubId, device->getName().c_str(), |
| 258 | device->getDescriptor().c_str()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 259 | } else { |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 260 | ALOGI("Device removed: id=%d, eventHubId=%d, name='%s', descriptor='%s', sources=0x%08x", |
| 261 | device->getId(), eventHubId, device->getName().c_str(), |
| 262 | device->getDescriptor().c_str(), device->getSources()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 263 | } |
| 264 | |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 265 | device->removeEventHubDevice(eventHubId); |
| 266 | |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 267 | if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS)) { |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 268 | notifyExternalStylusPresenceChangedLocked(); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 271 | if (device->hasEventHubDevices()) { |
| 272 | device->configure(when, &mConfig, 0); |
| 273 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 274 | device->reset(when); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 275 | } |
| 276 | |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 277 | std::shared_ptr<InputDevice> InputReader::createDeviceLocked( |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 278 | int32_t eventHubId, const InputDeviceIdentifier& identifier) { |
| 279 | auto deviceIt = std::find_if(mDevices.begin(), mDevices.end(), [identifier](auto& devicePair) { |
| 280 | return devicePair.second->getDescriptor().size() && identifier.descriptor.size() && |
| 281 | devicePair.second->getDescriptor() == identifier.descriptor; |
| 282 | }); |
| 283 | |
| 284 | std::shared_ptr<InputDevice> device; |
| 285 | if (deviceIt != mDevices.end()) { |
| 286 | device = deviceIt->second; |
| 287 | } else { |
| 288 | int32_t deviceId = (eventHubId < END_RESERVED_ID) ? eventHubId : nextInputDeviceIdLocked(); |
| 289 | device = std::make_shared<InputDevice>(&mContext, deviceId, bumpGenerationLocked(), |
| 290 | identifier); |
| 291 | } |
| 292 | device->addEventHubDevice(eventHubId); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 293 | return device; |
| 294 | } |
| 295 | |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 296 | void InputReader::processEventsForDeviceLocked(int32_t eventHubId, const RawEvent* rawEvents, |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 297 | size_t count) { |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 298 | auto deviceIt = mDevices.find(eventHubId); |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 299 | if (deviceIt == mDevices.end()) { |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 300 | ALOGW("Discarding event for unknown eventHubId %d.", eventHubId); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 301 | return; |
| 302 | } |
| 303 | |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 304 | std::shared_ptr<InputDevice>& device = deviceIt->second; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 305 | if (device->isIgnored()) { |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 306 | // ALOGD("Discarding event for ignored deviceId %d.", deviceId); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 307 | return; |
| 308 | } |
| 309 | |
| 310 | device->process(rawEvents, count); |
| 311 | } |
| 312 | |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 313 | InputDevice* InputReader::findInputDeviceLocked(int32_t deviceId) { |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 314 | auto deviceIt = |
| 315 | std::find_if(mDevices.begin(), mDevices.end(), [deviceId](const auto& devicePair) { |
| 316 | return devicePair.second->getId() == deviceId; |
| 317 | }); |
| 318 | if (deviceIt != mDevices.end()) { |
| 319 | return deviceIt->second.get(); |
| 320 | } |
| 321 | return nullptr; |
| 322 | } |
| 323 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 324 | void InputReader::timeoutExpiredLocked(nsecs_t when) { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 325 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 326 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 327 | if (!device->isIgnored()) { |
| 328 | device->timeoutExpired(when); |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 333 | int32_t InputReader::nextInputDeviceIdLocked() { |
| 334 | return ++mNextInputDeviceId; |
| 335 | } |
| 336 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 337 | void InputReader::handleConfigurationChangedLocked(nsecs_t when) { |
| 338 | // Reset global meta state because it depends on the list of all configured devices. |
| 339 | updateGlobalMetaStateLocked(); |
| 340 | |
| 341 | // Enqueue configuration changed. |
Siarhei Vishniakou | f2f073b | 2021-02-09 21:59:56 +0000 | [diff] [blame] | 342 | NotifyConfigurationChangedArgs args(mContext.getNextId(), when); |
| 343 | mQueuedListener->notifyConfigurationChanged(&args); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | void InputReader::refreshConfigurationLocked(uint32_t changes) { |
| 347 | mPolicy->getReaderConfiguration(&mConfig); |
| 348 | mEventHub->setExcludedDevices(mConfig.excludedDeviceNames); |
| 349 | |
Prabir Pradhan | 7e18618 | 2020-11-10 13:56:45 -0800 | [diff] [blame] | 350 | if (!changes) return; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 351 | |
Prabir Pradhan | 7e18618 | 2020-11-10 13:56:45 -0800 | [diff] [blame] | 352 | ALOGI("Reconfiguring input devices, changes=%s", |
| 353 | InputReaderConfiguration::changesToString(changes).c_str()); |
| 354 | nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); |
Prabir Pradhan | c7ef27e | 2020-02-03 19:19:15 -0800 | [diff] [blame] | 355 | |
Prabir Pradhan | 7e18618 | 2020-11-10 13:56:45 -0800 | [diff] [blame] | 356 | if (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO) { |
| 357 | updatePointerDisplayLocked(); |
| 358 | } |
| 359 | |
| 360 | if (changes & InputReaderConfiguration::CHANGE_MUST_REOPEN) { |
| 361 | mEventHub->requestReopenDevices(); |
| 362 | } else { |
| 363 | for (auto& devicePair : mDevices) { |
| 364 | std::shared_ptr<InputDevice>& device = devicePair.second; |
| 365 | device->configure(now, &mConfig, changes); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 366 | } |
| 367 | } |
Prabir Pradhan | 7e18618 | 2020-11-10 13:56:45 -0800 | [diff] [blame] | 368 | |
| 369 | if (changes & InputReaderConfiguration::CHANGE_POINTER_CAPTURE) { |
Siarhei Vishniakou | f2f073b | 2021-02-09 21:59:56 +0000 | [diff] [blame] | 370 | const NotifyPointerCaptureChangedArgs args(mContext.getNextId(), now, |
| 371 | mConfig.pointerCapture); |
| 372 | mQueuedListener->notifyPointerCaptureChanged(&args); |
Prabir Pradhan | 7e18618 | 2020-11-10 13:56:45 -0800 | [diff] [blame] | 373 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | void InputReader::updateGlobalMetaStateLocked() { |
| 377 | mGlobalMetaState = 0; |
| 378 | |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 379 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 380 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 381 | mGlobalMetaState |= device->getMetaState(); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | int32_t InputReader::getGlobalMetaStateLocked() { |
| 386 | return mGlobalMetaState; |
| 387 | } |
| 388 | |
arthurhung | c903df1 | 2020-08-11 15:08:42 +0800 | [diff] [blame] | 389 | void InputReader::updateLedMetaStateLocked(int32_t metaState) { |
| 390 | mLedMetaState = metaState; |
| 391 | for (auto& devicePair : mDevices) { |
| 392 | std::shared_ptr<InputDevice>& device = devicePair.second; |
| 393 | device->updateLedState(false); |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | int32_t InputReader::getLedMetaStateLocked() { |
| 398 | return mLedMetaState; |
| 399 | } |
| 400 | |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 401 | void InputReader::notifyExternalStylusPresenceChangedLocked() { |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 402 | refreshConfigurationLocked(InputReaderConfiguration::CHANGE_EXTERNAL_STYLUS_PRESENCE); |
| 403 | } |
| 404 | |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 405 | void InputReader::getExternalStylusDevicesLocked(std::vector<InputDeviceInfo>& outDevices) { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 406 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 407 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 408 | if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS) && !device->isIgnored()) { |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 409 | InputDeviceInfo info; |
| 410 | device->getDeviceInfo(&info); |
| 411 | outDevices.push_back(info); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | } |
| 415 | |
Arthur Hung | cadce9d | 2021-05-07 17:24:04 +0800 | [diff] [blame] | 416 | void InputReader::dispatchExternalStylusStateLocked(const StylusState& state) { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 417 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 418 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 419 | device->updateExternalStylusState(state); |
| 420 | } |
| 421 | } |
| 422 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 423 | void InputReader::disableVirtualKeysUntilLocked(nsecs_t time) { |
| 424 | mDisableVirtualKeysTimeout = time; |
| 425 | } |
| 426 | |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 427 | bool InputReader::shouldDropVirtualKeyLocked(nsecs_t now, int32_t keyCode, int32_t scanCode) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 428 | if (now < mDisableVirtualKeysTimeout) { |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 429 | ALOGI("Dropping virtual key from device because virtual keys are " |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 430 | "temporarily disabled for the next %0.3fms. keyCode=%d, scanCode=%d", |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 431 | (mDisableVirtualKeysTimeout - now) * 0.000001, keyCode, scanCode); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 432 | return true; |
| 433 | } else { |
| 434 | return false; |
| 435 | } |
| 436 | } |
| 437 | |
Michael Wright | 17db18e | 2020-06-26 20:51:44 +0100 | [diff] [blame] | 438 | std::shared_ptr<PointerControllerInterface> InputReader::getPointerControllerLocked( |
| 439 | int32_t deviceId) { |
| 440 | std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock(); |
Prabir Pradhan | c7ef27e | 2020-02-03 19:19:15 -0800 | [diff] [blame] | 441 | if (controller == nullptr) { |
| 442 | controller = mPolicy->obtainPointerController(deviceId); |
| 443 | mPointerController = controller; |
| 444 | updatePointerDisplayLocked(); |
| 445 | } |
| 446 | return controller; |
| 447 | } |
| 448 | |
| 449 | void InputReader::updatePointerDisplayLocked() { |
Michael Wright | 17db18e | 2020-06-26 20:51:44 +0100 | [diff] [blame] | 450 | std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock(); |
Prabir Pradhan | c7ef27e | 2020-02-03 19:19:15 -0800 | [diff] [blame] | 451 | if (controller == nullptr) { |
| 452 | return; |
| 453 | } |
| 454 | |
| 455 | std::optional<DisplayViewport> viewport = |
| 456 | mConfig.getDisplayViewportById(mConfig.defaultPointerDisplayId); |
| 457 | if (!viewport) { |
| 458 | ALOGW("Can't find the designated viewport with ID %" PRId32 " to update cursor input " |
| 459 | "mapper. Fall back to default display", |
| 460 | mConfig.defaultPointerDisplayId); |
| 461 | viewport = mConfig.getDisplayViewportById(ADISPLAY_ID_DEFAULT); |
| 462 | } |
| 463 | if (!viewport) { |
| 464 | ALOGE("Still can't find a viable viewport to update cursor input mapper. Skip setting it to" |
| 465 | " PointerController."); |
| 466 | return; |
| 467 | } |
| 468 | |
| 469 | controller->setDisplayViewport(*viewport); |
| 470 | } |
| 471 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 472 | void InputReader::fadePointerLocked() { |
Michael Wright | 17db18e | 2020-06-26 20:51:44 +0100 | [diff] [blame] | 473 | std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock(); |
Prabir Pradhan | c7ef27e | 2020-02-03 19:19:15 -0800 | [diff] [blame] | 474 | if (controller != nullptr) { |
Michael Wright | ca5bede | 2020-07-02 00:00:29 +0100 | [diff] [blame] | 475 | controller->fade(PointerControllerInterface::Transition::GRADUAL); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | |
| 479 | void InputReader::requestTimeoutAtTimeLocked(nsecs_t when) { |
| 480 | if (when < mNextTimeout) { |
| 481 | mNextTimeout = when; |
| 482 | mEventHub->wake(); |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | int32_t InputReader::bumpGenerationLocked() { |
| 487 | return ++mGeneration; |
| 488 | } |
| 489 | |
Chris Ye | 98d3f53 | 2020-10-01 21:48:59 -0700 | [diff] [blame] | 490 | std::vector<InputDeviceInfo> InputReader::getInputDevices() const { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 491 | std::scoped_lock _l(mLock); |
Chris Ye | 98d3f53 | 2020-10-01 21:48:59 -0700 | [diff] [blame] | 492 | return getInputDevicesLocked(); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 493 | } |
| 494 | |
Chris Ye | 98d3f53 | 2020-10-01 21:48:59 -0700 | [diff] [blame] | 495 | std::vector<InputDeviceInfo> InputReader::getInputDevicesLocked() const { |
| 496 | std::vector<InputDeviceInfo> outInputDevices; |
| 497 | outInputDevices.reserve(mDeviceToEventHubIdsMap.size()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 498 | |
Chris Ye | e731003 | 2020-09-22 15:36:28 -0700 | [diff] [blame] | 499 | for (const auto& [device, eventHubIds] : mDeviceToEventHubIdsMap) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 500 | if (!device->isIgnored()) { |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 501 | InputDeviceInfo info; |
| 502 | device->getDeviceInfo(&info); |
| 503 | outInputDevices.push_back(info); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 504 | } |
| 505 | } |
Chris Ye | 98d3f53 | 2020-10-01 21:48:59 -0700 | [diff] [blame] | 506 | return outInputDevices; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 507 | } |
| 508 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 509 | 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] | 510 | std::scoped_lock _l(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 511 | |
| 512 | return getStateLocked(deviceId, sourceMask, keyCode, &InputDevice::getKeyCodeState); |
| 513 | } |
| 514 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 515 | 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] | 516 | std::scoped_lock _l(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 517 | |
| 518 | return getStateLocked(deviceId, sourceMask, scanCode, &InputDevice::getScanCodeState); |
| 519 | } |
| 520 | |
| 521 | 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] | 522 | std::scoped_lock _l(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 523 | |
| 524 | return getStateLocked(deviceId, sourceMask, switchCode, &InputDevice::getSwitchState); |
| 525 | } |
| 526 | |
| 527 | 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] | 528 | GetStateFunc getStateFunc) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 529 | int32_t result = AKEY_STATE_UNKNOWN; |
| 530 | if (deviceId >= 0) { |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 531 | InputDevice* device = findInputDeviceLocked(deviceId); |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 532 | if (device && !device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
| 533 | result = (device->*getStateFunc)(sourceMask, code); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 534 | } |
| 535 | } else { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 536 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 537 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 538 | if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 539 | // If any device reports AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL, return that |
| 540 | // 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] | 541 | int32_t currentResult = (device.get()->*getStateFunc)(sourceMask, code); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 542 | if (currentResult >= AKEY_STATE_DOWN) { |
| 543 | return currentResult; |
| 544 | } else if (currentResult == AKEY_STATE_UP) { |
| 545 | result = currentResult; |
| 546 | } |
| 547 | } |
| 548 | } |
| 549 | } |
| 550 | return result; |
| 551 | } |
| 552 | |
Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 553 | void InputReader::toggleCapsLockState(int32_t deviceId) { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 554 | std::scoped_lock _l(mLock); |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 555 | InputDevice* device = findInputDeviceLocked(deviceId); |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 556 | if (!device) { |
Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 557 | ALOGW("Ignoring toggleCapsLock for unknown deviceId %" PRId32 ".", deviceId); |
| 558 | return; |
| 559 | } |
| 560 | |
Andrii Kulian | 763a3a4 | 2016-03-08 10:46:16 -0800 | [diff] [blame] | 561 | if (device->isIgnored()) { |
| 562 | return; |
| 563 | } |
| 564 | |
| 565 | device->updateMetaState(AKEYCODE_CAPS_LOCK); |
| 566 | } |
| 567 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 568 | bool InputReader::hasKeys(int32_t deviceId, uint32_t sourceMask, size_t numCodes, |
| 569 | const int32_t* keyCodes, uint8_t* outFlags) { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 570 | std::scoped_lock _l(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 571 | |
| 572 | memset(outFlags, 0, numCodes); |
| 573 | return markSupportedKeyCodesLocked(deviceId, sourceMask, numCodes, keyCodes, outFlags); |
| 574 | } |
| 575 | |
| 576 | bool InputReader::markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask, |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 577 | size_t numCodes, const int32_t* keyCodes, |
| 578 | uint8_t* outFlags) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 579 | bool result = false; |
| 580 | if (deviceId >= 0) { |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 581 | InputDevice* device = findInputDeviceLocked(deviceId); |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 582 | if (device && !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 | } else { |
Nathaniel R. Lewis | 10793a6 | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 586 | for (auto& devicePair : mDevices) { |
Nathaniel R. Lewis | 0cab12d | 2019-11-05 02:17:02 +0000 | [diff] [blame] | 587 | std::shared_ptr<InputDevice>& device = devicePair.second; |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 588 | if (!device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) { |
| 589 | result |= device->markSupportedKeyCodes(sourceMask, numCodes, keyCodes, outFlags); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | } |
| 593 | return result; |
| 594 | } |
| 595 | |
| 596 | void InputReader::requestRefreshConfiguration(uint32_t changes) { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 597 | std::scoped_lock _l(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 598 | |
| 599 | if (changes) { |
| 600 | bool needWake = !mConfigurationChangesToRefresh; |
| 601 | mConfigurationChangesToRefresh |= changes; |
| 602 | |
| 603 | if (needWake) { |
| 604 | mEventHub->wake(); |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 609 | void InputReader::vibrate(int32_t deviceId, const VibrationSequence& sequence, ssize_t repeat, |
| 610 | int32_t token) { |
| 611 | std::scoped_lock _l(mLock); |
| 612 | |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 613 | InputDevice* device = findInputDeviceLocked(deviceId); |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 614 | if (device) { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 615 | device->vibrate(sequence, repeat, token); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
| 619 | void InputReader::cancelVibrate(int32_t deviceId, int32_t token) { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 620 | std::scoped_lock _l(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 621 | |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 622 | InputDevice* device = findInputDeviceLocked(deviceId); |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 623 | if (device) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 624 | device->cancelVibrate(token); |
| 625 | } |
| 626 | } |
| 627 | |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 628 | bool InputReader::isVibrating(int32_t deviceId) { |
| 629 | std::scoped_lock _l(mLock); |
| 630 | |
| 631 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 632 | if (device) { |
| 633 | return device->isVibrating(); |
| 634 | } |
| 635 | return false; |
| 636 | } |
| 637 | |
| 638 | std::vector<int32_t> InputReader::getVibratorIds(int32_t deviceId) { |
| 639 | std::scoped_lock _l(mLock); |
| 640 | |
| 641 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 642 | if (device) { |
| 643 | return device->getVibratorIds(); |
| 644 | } |
| 645 | return {}; |
| 646 | } |
| 647 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 648 | void InputReader::disableSensor(int32_t deviceId, InputDeviceSensorType sensorType) { |
| 649 | std::scoped_lock _l(mLock); |
| 650 | |
| 651 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 652 | if (device) { |
| 653 | device->disableSensor(sensorType); |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | bool InputReader::enableSensor(int32_t deviceId, InputDeviceSensorType sensorType, |
| 658 | std::chrono::microseconds samplingPeriod, |
| 659 | std::chrono::microseconds maxBatchReportLatency) { |
| 660 | std::scoped_lock _l(mLock); |
| 661 | |
| 662 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 663 | if (device) { |
| 664 | return device->enableSensor(sensorType, samplingPeriod, maxBatchReportLatency); |
| 665 | } |
| 666 | return false; |
| 667 | } |
| 668 | |
| 669 | void InputReader::flushSensor(int32_t deviceId, InputDeviceSensorType sensorType) { |
| 670 | std::scoped_lock _l(mLock); |
| 671 | |
| 672 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 673 | if (device) { |
| 674 | device->flushSensor(sensorType); |
| 675 | } |
| 676 | } |
| 677 | |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 678 | std::optional<int32_t> InputReader::getBatteryCapacity(int32_t deviceId) { |
| 679 | std::scoped_lock _l(mLock); |
| 680 | |
| 681 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 682 | if (device) { |
| 683 | return device->getBatteryCapacity(); |
| 684 | } |
| 685 | return std::nullopt; |
| 686 | } |
| 687 | |
| 688 | std::optional<int32_t> InputReader::getBatteryStatus(int32_t deviceId) { |
| 689 | std::scoped_lock _l(mLock); |
| 690 | |
| 691 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 692 | if (device) { |
| 693 | return device->getBatteryStatus(); |
| 694 | } |
| 695 | return std::nullopt; |
| 696 | } |
| 697 | |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 698 | std::vector<int32_t> InputReader::getLightIds(int32_t deviceId) { |
| 699 | std::scoped_lock _l(mLock); |
| 700 | |
| 701 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 702 | if (device) { |
| 703 | InputDeviceInfo info; |
| 704 | device->getDeviceInfo(&info); |
| 705 | return info.getLightIds(); |
| 706 | } |
| 707 | return {}; |
| 708 | } |
| 709 | |
| 710 | const InputDeviceLightInfo* InputReader::getLightInfo(int32_t deviceId, int32_t lightId) { |
| 711 | std::scoped_lock _l(mLock); |
| 712 | |
| 713 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 714 | if (device) { |
| 715 | InputDeviceInfo info; |
| 716 | device->getDeviceInfo(&info); |
| 717 | return info.getLightInfo(lightId); |
| 718 | } |
| 719 | return nullptr; |
| 720 | } |
| 721 | |
| 722 | bool InputReader::setLightColor(int32_t deviceId, int32_t lightId, int32_t color) { |
| 723 | std::scoped_lock _l(mLock); |
| 724 | |
| 725 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 726 | if (device) { |
| 727 | return device->setLightColor(lightId, color); |
| 728 | } |
| 729 | return false; |
| 730 | } |
| 731 | |
| 732 | bool InputReader::setLightPlayerId(int32_t deviceId, int32_t lightId, int32_t playerId) { |
| 733 | std::scoped_lock _l(mLock); |
| 734 | |
| 735 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 736 | if (device) { |
| 737 | return device->setLightPlayerId(lightId, playerId); |
| 738 | } |
| 739 | return false; |
| 740 | } |
| 741 | |
| 742 | std::optional<int32_t> InputReader::getLightColor(int32_t deviceId, int32_t lightId) { |
| 743 | std::scoped_lock _l(mLock); |
| 744 | |
| 745 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 746 | if (device) { |
| 747 | return device->getLightColor(lightId); |
| 748 | } |
| 749 | return std::nullopt; |
| 750 | } |
| 751 | |
| 752 | std::optional<int32_t> InputReader::getLightPlayerId(int32_t deviceId, int32_t lightId) { |
| 753 | std::scoped_lock _l(mLock); |
| 754 | |
| 755 | InputDevice* device = findInputDeviceLocked(deviceId); |
| 756 | if (device) { |
| 757 | return device->getLightPlayerId(lightId); |
| 758 | } |
| 759 | return std::nullopt; |
| 760 | } |
| 761 | |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 762 | bool InputReader::isInputDeviceEnabled(int32_t deviceId) { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 763 | std::scoped_lock _l(mLock); |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 764 | |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 765 | InputDevice* device = findInputDeviceLocked(deviceId); |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 766 | if (device) { |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 767 | return device->isEnabled(); |
| 768 | } |
| 769 | ALOGW("Ignoring invalid device id %" PRId32 ".", deviceId); |
| 770 | return false; |
| 771 | } |
| 772 | |
Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 773 | bool InputReader::canDispatchToDisplay(int32_t deviceId, int32_t displayId) { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 774 | std::scoped_lock _l(mLock); |
Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 775 | |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 776 | InputDevice* device = findInputDeviceLocked(deviceId); |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 777 | if (!device) { |
Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 778 | ALOGW("Ignoring invalid device id %" PRId32 ".", deviceId); |
| 779 | return false; |
| 780 | } |
| 781 | |
Arthur Hung | 2c9a334 | 2019-07-23 14:18:59 +0800 | [diff] [blame] | 782 | if (!device->isEnabled()) { |
| 783 | ALOGW("Ignoring disabled device %s", device->getName().c_str()); |
| 784 | return false; |
| 785 | } |
| 786 | |
| 787 | std::optional<int32_t> associatedDisplayId = device->getAssociatedDisplayId(); |
Arthur Hung | c23540e | 2018-11-29 20:42:11 +0800 | [diff] [blame] | 788 | // No associated display. By default, can dispatch to all displays. |
| 789 | if (!associatedDisplayId) { |
| 790 | return true; |
| 791 | } |
| 792 | |
| 793 | if (*associatedDisplayId == ADISPLAY_ID_NONE) { |
Arthur Hung | 2c9a334 | 2019-07-23 14:18:59 +0800 | [diff] [blame] | 794 | 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] | 795 | return true; |
| 796 | } |
| 797 | |
| 798 | return *associatedDisplayId == displayId; |
| 799 | } |
| 800 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 801 | void InputReader::dump(std::string& dump) { |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 802 | std::scoped_lock _l(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 803 | |
| 804 | mEventHub->dump(dump); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 805 | dump += "\n"; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 806 | |
Chris Ye | e731003 | 2020-09-22 15:36:28 -0700 | [diff] [blame] | 807 | dump += StringPrintf("Input Reader State (Nums of device: %zu):\n", |
| 808 | mDeviceToEventHubIdsMap.size()); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 809 | |
Chris Ye | e731003 | 2020-09-22 15:36:28 -0700 | [diff] [blame] | 810 | for (const auto& devicePair : mDeviceToEventHubIdsMap) { |
| 811 | const std::shared_ptr<InputDevice>& device = devicePair.first; |
| 812 | std::string eventHubDevStr = INDENT "EventHub Devices: [ "; |
| 813 | for (const auto& eId : devicePair.second) { |
| 814 | eventHubDevStr += StringPrintf("%d ", eId); |
| 815 | } |
| 816 | eventHubDevStr += "] \n"; |
| 817 | device->dump(dump, eventHubDevStr); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 818 | } |
| 819 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 820 | dump += INDENT "Configuration:\n"; |
| 821 | dump += INDENT2 "ExcludedDeviceNames: ["; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 822 | for (size_t i = 0; i < mConfig.excludedDeviceNames.size(); i++) { |
| 823 | if (i != 0) { |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 824 | dump += ", "; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 825 | } |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 826 | dump += mConfig.excludedDeviceNames[i]; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 827 | } |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 828 | dump += "]\n"; |
| 829 | dump += StringPrintf(INDENT2 "VirtualKeyQuietTime: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 830 | mConfig.virtualKeyQuietTime * 0.000001f); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 831 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 832 | dump += StringPrintf(INDENT2 "PointerVelocityControlParameters: " |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 833 | "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, " |
| 834 | "acceleration=%0.3f\n", |
| 835 | mConfig.pointerVelocityControlParameters.scale, |
| 836 | mConfig.pointerVelocityControlParameters.lowThreshold, |
| 837 | mConfig.pointerVelocityControlParameters.highThreshold, |
| 838 | mConfig.pointerVelocityControlParameters.acceleration); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 839 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 840 | dump += StringPrintf(INDENT2 "WheelVelocityControlParameters: " |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 841 | "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, " |
| 842 | "acceleration=%0.3f\n", |
| 843 | mConfig.wheelVelocityControlParameters.scale, |
| 844 | mConfig.wheelVelocityControlParameters.lowThreshold, |
| 845 | mConfig.wheelVelocityControlParameters.highThreshold, |
| 846 | mConfig.wheelVelocityControlParameters.acceleration); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 847 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 848 | dump += StringPrintf(INDENT2 "PointerGesture:\n"); |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 849 | dump += StringPrintf(INDENT3 "Enabled: %s\n", toString(mConfig.pointerGesturesEnabled)); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 850 | dump += StringPrintf(INDENT3 "QuietInterval: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 851 | mConfig.pointerGestureQuietInterval * 0.000001f); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 852 | dump += StringPrintf(INDENT3 "DragMinSwitchSpeed: %0.1fpx/s\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 853 | mConfig.pointerGestureDragMinSwitchSpeed); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 854 | dump += StringPrintf(INDENT3 "TapInterval: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 855 | mConfig.pointerGestureTapInterval * 0.000001f); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 856 | dump += StringPrintf(INDENT3 "TapDragInterval: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 857 | mConfig.pointerGestureTapDragInterval * 0.000001f); |
| 858 | dump += StringPrintf(INDENT3 "TapSlop: %0.1fpx\n", mConfig.pointerGestureTapSlop); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 859 | dump += StringPrintf(INDENT3 "MultitouchSettleInterval: %0.1fms\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 860 | mConfig.pointerGestureMultitouchSettleInterval * 0.000001f); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 861 | dump += StringPrintf(INDENT3 "MultitouchMinDistance: %0.1fpx\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 862 | mConfig.pointerGestureMultitouchMinDistance); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 863 | dump += StringPrintf(INDENT3 "SwipeTransitionAngleCosine: %0.1f\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 864 | mConfig.pointerGestureSwipeTransitionAngleCosine); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 865 | dump += StringPrintf(INDENT3 "SwipeMaxWidthRatio: %0.1f\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 866 | mConfig.pointerGestureSwipeMaxWidthRatio); |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 867 | dump += StringPrintf(INDENT3 "MovementSpeedRatio: %0.1f\n", |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 868 | mConfig.pointerGestureMovementSpeedRatio); |
| 869 | dump += StringPrintf(INDENT3 "ZoomSpeedRatio: %0.1f\n", mConfig.pointerGestureZoomSpeedRatio); |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 870 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 871 | dump += INDENT3 "Viewports:\n"; |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 872 | mConfig.dump(dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | void InputReader::monitor() { |
| 876 | // 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] | 877 | std::unique_lock<std::mutex> lock(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 878 | mEventHub->wake(); |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 879 | mReaderIsAliveCondition.wait(lock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 880 | // Check the EventHub |
| 881 | mEventHub->monitor(); |
| 882 | } |
| 883 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 884 | // --- InputReader::ContextImpl --- |
| 885 | |
Garfield Tan | ff1f1bb | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 886 | InputReader::ContextImpl::ContextImpl(InputReader* reader) |
| 887 | : mReader(reader), mIdGenerator(IdGenerator::Source::INPUT_READER) {} |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 888 | |
| 889 | void InputReader::ContextImpl::updateGlobalMetaState() { |
| 890 | // lock is already held by the input loop |
| 891 | mReader->updateGlobalMetaStateLocked(); |
| 892 | } |
| 893 | |
| 894 | int32_t InputReader::ContextImpl::getGlobalMetaState() { |
| 895 | // lock is already held by the input loop |
| 896 | return mReader->getGlobalMetaStateLocked(); |
| 897 | } |
| 898 | |
arthurhung | c903df1 | 2020-08-11 15:08:42 +0800 | [diff] [blame] | 899 | void InputReader::ContextImpl::updateLedMetaState(int32_t metaState) { |
| 900 | // lock is already held by the input loop |
| 901 | mReader->updateLedMetaStateLocked(metaState); |
| 902 | } |
| 903 | |
| 904 | int32_t InputReader::ContextImpl::getLedMetaState() { |
| 905 | // lock is already held by the input loop |
| 906 | return mReader->getLedMetaStateLocked(); |
| 907 | } |
| 908 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 909 | void InputReader::ContextImpl::disableVirtualKeysUntil(nsecs_t time) { |
| 910 | // lock is already held by the input loop |
| 911 | mReader->disableVirtualKeysUntilLocked(time); |
| 912 | } |
| 913 | |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 914 | bool InputReader::ContextImpl::shouldDropVirtualKey(nsecs_t now, int32_t keyCode, |
| 915 | int32_t scanCode) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 916 | // lock is already held by the input loop |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 917 | return mReader->shouldDropVirtualKeyLocked(now, keyCode, scanCode); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | void InputReader::ContextImpl::fadePointer() { |
| 921 | // lock is already held by the input loop |
| 922 | mReader->fadePointerLocked(); |
| 923 | } |
| 924 | |
Michael Wright | 17db18e | 2020-06-26 20:51:44 +0100 | [diff] [blame] | 925 | std::shared_ptr<PointerControllerInterface> InputReader::ContextImpl::getPointerController( |
| 926 | int32_t deviceId) { |
Prabir Pradhan | c7ef27e | 2020-02-03 19:19:15 -0800 | [diff] [blame] | 927 | // lock is already held by the input loop |
| 928 | return mReader->getPointerControllerLocked(deviceId); |
| 929 | } |
| 930 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 931 | void InputReader::ContextImpl::requestTimeoutAtTime(nsecs_t when) { |
| 932 | // lock is already held by the input loop |
| 933 | mReader->requestTimeoutAtTimeLocked(when); |
| 934 | } |
| 935 | |
| 936 | int32_t InputReader::ContextImpl::bumpGeneration() { |
| 937 | // lock is already held by the input loop |
| 938 | return mReader->bumpGenerationLocked(); |
| 939 | } |
| 940 | |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 941 | void InputReader::ContextImpl::getExternalStylusDevices(std::vector<InputDeviceInfo>& outDevices) { |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 942 | // lock is already held by whatever called refreshConfigurationLocked |
| 943 | mReader->getExternalStylusDevicesLocked(outDevices); |
| 944 | } |
| 945 | |
| 946 | void InputReader::ContextImpl::dispatchExternalStylusState(const StylusState& state) { |
Arthur Hung | cadce9d | 2021-05-07 17:24:04 +0800 | [diff] [blame] | 947 | mReader->dispatchExternalStylusStateLocked(state); |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 948 | } |
| 949 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 950 | InputReaderPolicyInterface* InputReader::ContextImpl::getPolicy() { |
| 951 | return mReader->mPolicy.get(); |
| 952 | } |
| 953 | |
Siarhei Vishniakou | f2f073b | 2021-02-09 21:59:56 +0000 | [diff] [blame] | 954 | InputListenerInterface* InputReader::ContextImpl::getListener() { |
| 955 | return mReader->mQueuedListener.get(); |
| 956 | } |
| 957 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 958 | EventHubInterface* InputReader::ContextImpl::getEventHub() { |
| 959 | return mReader->mEventHub.get(); |
| 960 | } |
| 961 | |
Siarhei Vishniakou | f2f073b | 2021-02-09 21:59:56 +0000 | [diff] [blame] | 962 | int32_t InputReader::ContextImpl::getNextId() { |
| 963 | return mIdGenerator.nextId(); |
Prabir Pradhan | 42611e0 | 2018-11-27 14:04:02 -0800 | [diff] [blame] | 964 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 965 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 966 | } // namespace android |