Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2024 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 | |
| 17 | #define LOG_TAG "InputTracer" |
| 18 | |
| 19 | #include "InputTracer.h" |
| 20 | |
| 21 | #include <android-base/logging.h> |
Prabir Pradhan | bf3c832 | 2024-02-23 02:38:36 +0000 | [diff] [blame] | 22 | #include <private/android_filesystem_config.h> |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 23 | |
| 24 | namespace android::inputdispatcher::trace::impl { |
| 25 | |
| 26 | namespace { |
| 27 | |
Prabir Pradhan | bb7a020 | 2024-02-10 02:09:01 +0000 | [diff] [blame] | 28 | // Helper to std::visit with lambdas. |
| 29 | template <typename... V> |
| 30 | struct Visitor : V... { |
| 31 | using V::operator()...; |
| 32 | }; |
| 33 | |
Prabir Pradhan | 4c49aad | 2024-02-08 20:42:35 +0000 | [diff] [blame] | 34 | TracedEvent createTracedEvent(const MotionEntry& e, EventType type) { |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 35 | return TracedMotionEvent{e.id, |
| 36 | e.eventTime, |
| 37 | e.policyFlags, |
| 38 | e.deviceId, |
| 39 | e.source, |
| 40 | e.displayId, |
| 41 | e.action, |
| 42 | e.actionButton, |
| 43 | e.flags, |
| 44 | e.metaState, |
| 45 | e.buttonState, |
| 46 | e.classification, |
| 47 | e.edgeFlags, |
| 48 | e.xPrecision, |
| 49 | e.yPrecision, |
| 50 | e.xCursorPosition, |
| 51 | e.yCursorPosition, |
| 52 | e.downTime, |
| 53 | e.pointerProperties, |
Prabir Pradhan | 4c49aad | 2024-02-08 20:42:35 +0000 | [diff] [blame] | 54 | e.pointerCoords, |
| 55 | type}; |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Prabir Pradhan | 4c49aad | 2024-02-08 20:42:35 +0000 | [diff] [blame] | 58 | TracedEvent createTracedEvent(const KeyEntry& e, EventType type) { |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 59 | return TracedKeyEvent{e.id, e.eventTime, e.policyFlags, e.deviceId, e.source, |
| 60 | e.displayId, e.action, e.keyCode, e.scanCode, e.metaState, |
Prabir Pradhan | 4c49aad | 2024-02-08 20:42:35 +0000 | [diff] [blame] | 61 | e.downTime, e.flags, e.repeatCount, type}; |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Prabir Pradhan | c7edaaa | 2024-03-15 15:31:02 +0000 | [diff] [blame] | 64 | void writeEventToBackend(const TracedEvent& event, const TracedEventMetadata metadata, |
Prabir Pradhan | 8c3b143 | 2024-02-09 23:34:16 +0000 | [diff] [blame] | 65 | InputTracingBackendInterface& backend) { |
Prabir Pradhan | c7edaaa | 2024-03-15 15:31:02 +0000 | [diff] [blame] | 66 | std::visit(Visitor{[&](const TracedMotionEvent& e) { backend.traceMotionEvent(e, metadata); }, |
| 67 | [&](const TracedKeyEvent& e) { backend.traceKeyEvent(e, metadata); }}, |
Prabir Pradhan | a67623c | 2024-02-21 06:57:36 +0000 | [diff] [blame] | 68 | event); |
| 69 | } |
| 70 | |
Prabir Pradhan | d6b2b05 | 2024-02-21 23:25:15 +0000 | [diff] [blame] | 71 | inline auto getId(const trace::TracedEvent& v) { |
| 72 | return std::visit([](const auto& event) { return event.id; }, v); |
| 73 | } |
| 74 | |
Prabir Pradhan | bf3c832 | 2024-02-23 02:38:36 +0000 | [diff] [blame] | 75 | // Helper class to extract relevant information from InputTarget. |
| 76 | struct InputTargetInfo { |
| 77 | gui::Uid uid; |
| 78 | bool isSecureWindow; |
| 79 | }; |
| 80 | |
| 81 | InputTargetInfo getTargetInfo(const InputTarget& target) { |
| 82 | if (target.windowHandle == nullptr) { |
| 83 | if (!target.connection->monitor) { |
| 84 | LOG(FATAL) << __func__ << ": Window is not set for non-monitor target"; |
| 85 | } |
| 86 | // This is a global monitor, assume its target is the system. |
| 87 | return {.uid = gui::Uid{AID_SYSTEM}, .isSecureWindow = false}; |
| 88 | } |
| 89 | return {target.windowHandle->getInfo()->ownerUid, |
| 90 | target.windowHandle->getInfo()->layoutParamsFlags.test(gui::WindowInfo::Flag::SECURE)}; |
| 91 | } |
| 92 | |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 93 | } // namespace |
| 94 | |
| 95 | // --- InputTracer --- |
| 96 | |
| 97 | InputTracer::InputTracer(std::unique_ptr<InputTracingBackendInterface> backend) |
Prabir Pradhan | bb7a020 | 2024-02-10 02:09:01 +0000 | [diff] [blame] | 98 | : mBackend(std::move(backend)) {} |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 99 | |
| 100 | std::unique_ptr<EventTrackerInterface> InputTracer::traceInboundEvent(const EventEntry& entry) { |
Prabir Pradhan | a67623c | 2024-02-21 06:57:36 +0000 | [diff] [blame] | 101 | // This is a newly traced inbound event. Create a new state to track it and its derived events. |
| 102 | auto eventState = std::make_shared<EventState>(*this); |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 103 | |
| 104 | if (entry.type == EventEntry::Type::MOTION) { |
| 105 | const auto& motion = static_cast<const MotionEntry&>(entry); |
Prabir Pradhan | 4c49aad | 2024-02-08 20:42:35 +0000 | [diff] [blame] | 106 | eventState->events.emplace_back(createTracedEvent(motion, EventType::INBOUND)); |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 107 | } else if (entry.type == EventEntry::Type::KEY) { |
| 108 | const auto& key = static_cast<const KeyEntry&>(entry); |
Prabir Pradhan | 4c49aad | 2024-02-08 20:42:35 +0000 | [diff] [blame] | 109 | eventState->events.emplace_back(createTracedEvent(key, EventType::INBOUND)); |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 110 | } else { |
| 111 | LOG(FATAL) << "Cannot trace EventEntry of type: " << ftl::enum_string(entry.type); |
| 112 | } |
| 113 | |
Prabir Pradhan | a67623c | 2024-02-21 06:57:36 +0000 | [diff] [blame] | 114 | return std::make_unique<EventTrackerImpl>(std::move(eventState), /*isDerived=*/false); |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Prabir Pradhan | d6b2b05 | 2024-02-21 23:25:15 +0000 | [diff] [blame] | 117 | std::unique_ptr<EventTrackerInterface> InputTracer::createTrackerForSyntheticEvent() { |
| 118 | // Create a new EventState to track events derived from this tracker. |
| 119 | return std::make_unique<EventTrackerImpl>(std::make_shared<EventState>(*this), |
| 120 | /*isDerived=*/false); |
| 121 | } |
| 122 | |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 123 | void InputTracer::dispatchToTargetHint(const EventTrackerInterface& cookie, |
| 124 | const InputTarget& target) { |
Prabir Pradhan | 1ea04a3 | 2024-02-10 03:02:59 +0000 | [diff] [blame] | 125 | auto& eventState = getState(cookie); |
Prabir Pradhan | bf3c832 | 2024-02-23 02:38:36 +0000 | [diff] [blame] | 126 | const InputTargetInfo& targetInfo = getTargetInfo(target); |
Prabir Pradhan | a67623c | 2024-02-21 06:57:36 +0000 | [diff] [blame] | 127 | if (eventState->isEventProcessingComplete) { |
Prabir Pradhan | bf3c832 | 2024-02-23 02:38:36 +0000 | [diff] [blame] | 128 | // Disallow adding new targets after eventProcessingComplete() is called. |
Prabir Pradhan | ac63702 | 2024-03-19 00:02:04 +0000 | [diff] [blame] | 129 | if (eventState->metadata.targets.count(targetInfo.uid) == 0) { |
Prabir Pradhan | bf3c832 | 2024-02-23 02:38:36 +0000 | [diff] [blame] | 130 | LOG(FATAL) << __func__ << ": Cannot add new target after eventProcessingComplete"; |
| 131 | } |
Prabir Pradhan | a67623c | 2024-02-21 06:57:36 +0000 | [diff] [blame] | 132 | return; |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 133 | } |
Prabir Pradhan | b95d4aa | 2024-03-11 22:48:04 +0000 | [diff] [blame] | 134 | if (isDerivedCookie(cookie)) { |
Prabir Pradhan | bf3c832 | 2024-02-23 02:38:36 +0000 | [diff] [blame] | 135 | // Disallow adding new targets from a derived cookie. |
Prabir Pradhan | ac63702 | 2024-03-19 00:02:04 +0000 | [diff] [blame] | 136 | if (eventState->metadata.targets.count(targetInfo.uid) == 0) { |
Prabir Pradhan | bf3c832 | 2024-02-23 02:38:36 +0000 | [diff] [blame] | 137 | LOG(FATAL) << __func__ << ": Cannot add new target from a derived cookie"; |
| 138 | } |
Prabir Pradhan | b95d4aa | 2024-03-11 22:48:04 +0000 | [diff] [blame] | 139 | return; |
| 140 | } |
Prabir Pradhan | bf3c832 | 2024-02-23 02:38:36 +0000 | [diff] [blame] | 141 | |
Prabir Pradhan | ac63702 | 2024-03-19 00:02:04 +0000 | [diff] [blame] | 142 | eventState->metadata.targets.emplace(targetInfo.uid); |
| 143 | eventState->metadata.isSecure |= targetInfo.isSecureWindow; |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | void InputTracer::eventProcessingComplete(const EventTrackerInterface& cookie) { |
Prabir Pradhan | a67623c | 2024-02-21 06:57:36 +0000 | [diff] [blame] | 147 | if (isDerivedCookie(cookie)) { |
| 148 | LOG(FATAL) << "Event processing cannot be set from a derived cookie."; |
| 149 | } |
Prabir Pradhan | 1ea04a3 | 2024-02-10 03:02:59 +0000 | [diff] [blame] | 150 | auto& eventState = getState(cookie); |
Prabir Pradhan | a67623c | 2024-02-21 06:57:36 +0000 | [diff] [blame] | 151 | if (eventState->isEventProcessingComplete) { |
Prabir Pradhan | bb7a020 | 2024-02-10 02:09:01 +0000 | [diff] [blame] | 152 | LOG(FATAL) << "Traced event was already logged. " |
| 153 | "eventProcessingComplete() was likely called more than once."; |
| 154 | } |
Prabir Pradhan | e770164 | 2024-02-22 04:06:53 +0000 | [diff] [blame] | 155 | eventState->onEventProcessingComplete(); |
Prabir Pradhan | a67623c | 2024-02-21 06:57:36 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | std::unique_ptr<EventTrackerInterface> InputTracer::traceDerivedEvent( |
| 159 | const EventEntry& entry, const EventTrackerInterface& originalEventCookie) { |
| 160 | // This is an event derived from an already-established event. Use the same state to track |
| 161 | // this event too. |
| 162 | auto eventState = getState(originalEventCookie); |
| 163 | |
| 164 | if (entry.type == EventEntry::Type::MOTION) { |
| 165 | const auto& motion = static_cast<const MotionEntry&>(entry); |
Prabir Pradhan | 4c49aad | 2024-02-08 20:42:35 +0000 | [diff] [blame] | 166 | eventState->events.emplace_back(createTracedEvent(motion, EventType::SYNTHESIZED)); |
Prabir Pradhan | a67623c | 2024-02-21 06:57:36 +0000 | [diff] [blame] | 167 | } else if (entry.type == EventEntry::Type::KEY) { |
| 168 | const auto& key = static_cast<const KeyEntry&>(entry); |
Prabir Pradhan | 4c49aad | 2024-02-08 20:42:35 +0000 | [diff] [blame] | 169 | eventState->events.emplace_back(createTracedEvent(key, EventType::SYNTHESIZED)); |
Prabir Pradhan | a67623c | 2024-02-21 06:57:36 +0000 | [diff] [blame] | 170 | } else { |
| 171 | LOG(FATAL) << "Cannot trace EventEntry of type: " << ftl::enum_string(entry.type); |
| 172 | } |
| 173 | |
| 174 | if (eventState->isEventProcessingComplete) { |
| 175 | // It is possible for a derived event to be dispatched some time after the original event |
| 176 | // is dispatched, such as in the case of key fallback events. To account for these cases, |
| 177 | // derived events can be traced after the processing is complete for the original event. |
Prabir Pradhan | 4c49aad | 2024-02-08 20:42:35 +0000 | [diff] [blame] | 178 | const auto& event = eventState->events.back(); |
Prabir Pradhan | ac63702 | 2024-03-19 00:02:04 +0000 | [diff] [blame] | 179 | writeEventToBackend(event, eventState->metadata, *mBackend); |
Prabir Pradhan | a67623c | 2024-02-21 06:57:36 +0000 | [diff] [blame] | 180 | } |
| 181 | return std::make_unique<EventTrackerImpl>(std::move(eventState), /*isDerived=*/true); |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | void InputTracer::traceEventDispatch(const DispatchEntry& dispatchEntry, |
Prabir Pradhan | d6b2b05 | 2024-02-21 23:25:15 +0000 | [diff] [blame] | 185 | const EventTrackerInterface& cookie) { |
| 186 | auto& eventState = getState(cookie); |
Prabir Pradhan | bb7a020 | 2024-02-10 02:09:01 +0000 | [diff] [blame] | 187 | const EventEntry& entry = *dispatchEntry.eventEntry; |
Prabir Pradhan | 4c49aad | 2024-02-08 20:42:35 +0000 | [diff] [blame] | 188 | const int32_t eventId = entry.id; |
Prabir Pradhan | 560d0d1 | 2024-03-07 18:08:27 +0000 | [diff] [blame] | 189 | // TODO(b/328618922): Remove resolved key repeats after making repeatCount non-mutable. |
| 190 | // The KeyEntry's repeatCount is mutable and can be modified after an event is initially traced, |
| 191 | // so we need to find the repeatCount at the time of dispatching to trace it accurately. |
| 192 | int32_t resolvedKeyRepeatCount = 0; |
Prabir Pradhan | 4c49aad | 2024-02-08 20:42:35 +0000 | [diff] [blame] | 193 | if (entry.type == EventEntry::Type::KEY) { |
| 194 | resolvedKeyRepeatCount = static_cast<const KeyEntry&>(entry).repeatCount; |
Prabir Pradhan | bb7a020 | 2024-02-10 02:09:01 +0000 | [diff] [blame] | 195 | } |
Prabir Pradhan | adc59b4 | 2023-12-15 05:34:11 +0000 | [diff] [blame] | 196 | |
Prabir Pradhan | d6b2b05 | 2024-02-21 23:25:15 +0000 | [diff] [blame] | 197 | auto tracedEventIt = |
| 198 | std::find_if(eventState->events.begin(), eventState->events.end(), |
Prabir Pradhan | 4c49aad | 2024-02-08 20:42:35 +0000 | [diff] [blame] | 199 | [eventId](const auto& event) { return eventId == getId(event); }); |
Prabir Pradhan | d6b2b05 | 2024-02-21 23:25:15 +0000 | [diff] [blame] | 200 | if (tracedEventIt == eventState->events.end()) { |
| 201 | LOG(FATAL) |
| 202 | << __func__ |
| 203 | << ": Failed to find a previously traced event that matches the dispatched event"; |
Prabir Pradhan | bb7a020 | 2024-02-10 02:09:01 +0000 | [diff] [blame] | 204 | } |
Prabir Pradhan | adc59b4 | 2023-12-15 05:34:11 +0000 | [diff] [blame] | 205 | |
Prabir Pradhan | ac63702 | 2024-03-19 00:02:04 +0000 | [diff] [blame] | 206 | if (eventState->metadata.targets.count(dispatchEntry.targetUid) == 0) { |
Prabir Pradhan | bf3c832 | 2024-02-23 02:38:36 +0000 | [diff] [blame] | 207 | LOG(FATAL) << __func__ << ": Event is being dispatched to UID that it is not targeting"; |
| 208 | } |
| 209 | |
Prabir Pradhan | bb7a020 | 2024-02-10 02:09:01 +0000 | [diff] [blame] | 210 | // The vsyncId only has meaning if the event is targeting a window. |
| 211 | const int32_t windowId = dispatchEntry.windowId.value_or(0); |
| 212 | const int32_t vsyncId = dispatchEntry.windowId.has_value() ? dispatchEntry.vsyncId : 0; |
Prabir Pradhan | adc59b4 | 2023-12-15 05:34:11 +0000 | [diff] [blame] | 213 | |
Prabir Pradhan | 8c3b143 | 2024-02-09 23:34:16 +0000 | [diff] [blame] | 214 | // TODO(b/210460522): Pass HMAC into traceEventDispatch. |
Prabir Pradhan | 4c49aad | 2024-02-08 20:42:35 +0000 | [diff] [blame] | 215 | const WindowDispatchArgs windowDispatchArgs{*tracedEventIt, |
Prabir Pradhan | 52ec3ff | 2024-02-22 03:26:38 +0000 | [diff] [blame] | 216 | dispatchEntry.deliveryTime, |
| 217 | dispatchEntry.resolvedFlags, |
| 218 | dispatchEntry.targetUid, |
| 219 | vsyncId, |
| 220 | windowId, |
| 221 | dispatchEntry.transform, |
| 222 | dispatchEntry.rawTransform, |
| 223 | /*hmac=*/{}, |
| 224 | resolvedKeyRepeatCount}; |
| 225 | if (eventState->isEventProcessingComplete) { |
Prabir Pradhan | ac63702 | 2024-03-19 00:02:04 +0000 | [diff] [blame] | 226 | mBackend->traceWindowDispatch(std::move(windowDispatchArgs), eventState->metadata); |
Prabir Pradhan | 52ec3ff | 2024-02-22 03:26:38 +0000 | [diff] [blame] | 227 | } else { |
| 228 | eventState->pendingDispatchArgs.emplace_back(std::move(windowDispatchArgs)); |
| 229 | } |
Prabir Pradhan | adc59b4 | 2023-12-15 05:34:11 +0000 | [diff] [blame] | 230 | } |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 231 | |
Prabir Pradhan | a67623c | 2024-02-21 06:57:36 +0000 | [diff] [blame] | 232 | std::shared_ptr<InputTracer::EventState>& InputTracer::getState( |
| 233 | const EventTrackerInterface& cookie) { |
Prabir Pradhan | bb7a020 | 2024-02-10 02:09:01 +0000 | [diff] [blame] | 234 | return static_cast<const EventTrackerImpl&>(cookie).mState; |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Prabir Pradhan | a67623c | 2024-02-21 06:57:36 +0000 | [diff] [blame] | 237 | bool InputTracer::isDerivedCookie(const EventTrackerInterface& cookie) { |
| 238 | return static_cast<const EventTrackerImpl&>(cookie).mIsDerived; |
| 239 | } |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 240 | |
Prabir Pradhan | a67623c | 2024-02-21 06:57:36 +0000 | [diff] [blame] | 241 | // --- InputTracer::EventState --- |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 242 | |
Prabir Pradhan | e770164 | 2024-02-22 04:06:53 +0000 | [diff] [blame] | 243 | void InputTracer::EventState::onEventProcessingComplete() { |
Prabir Pradhan | ac63702 | 2024-03-19 00:02:04 +0000 | [diff] [blame] | 244 | metadata.isImeConnectionActive = tracer.mIsImeConnectionActive; |
Prabir Pradhan | 04a6642 | 2024-03-15 22:45:27 +0000 | [diff] [blame] | 245 | |
Prabir Pradhan | e770164 | 2024-02-22 04:06:53 +0000 | [diff] [blame] | 246 | // Write all of the events known so far to the trace. |
| 247 | for (const auto& event : events) { |
Prabir Pradhan | ac63702 | 2024-03-19 00:02:04 +0000 | [diff] [blame] | 248 | writeEventToBackend(event, metadata, *tracer.mBackend); |
Prabir Pradhan | e770164 | 2024-02-22 04:06:53 +0000 | [diff] [blame] | 249 | } |
Prabir Pradhan | 52ec3ff | 2024-02-22 03:26:38 +0000 | [diff] [blame] | 250 | // Write all pending dispatch args to the trace. |
| 251 | for (const auto& windowDispatchArgs : pendingDispatchArgs) { |
Prabir Pradhan | 4c49aad | 2024-02-08 20:42:35 +0000 | [diff] [blame] | 252 | auto tracedEventIt = |
| 253 | std::find_if(events.begin(), events.end(), |
| 254 | [id = getId(windowDispatchArgs.eventEntry)](const auto& event) { |
| 255 | return id == getId(event); |
| 256 | }); |
| 257 | if (tracedEventIt == events.end()) { |
| 258 | LOG(FATAL) << __func__ |
| 259 | << ": Failed to find a previously traced event that matches the dispatched " |
| 260 | "event"; |
| 261 | } |
Prabir Pradhan | ac63702 | 2024-03-19 00:02:04 +0000 | [diff] [blame] | 262 | tracer.mBackend->traceWindowDispatch(windowDispatchArgs, metadata); |
Prabir Pradhan | 52ec3ff | 2024-02-22 03:26:38 +0000 | [diff] [blame] | 263 | } |
| 264 | pendingDispatchArgs.clear(); |
| 265 | |
Prabir Pradhan | e770164 | 2024-02-22 04:06:53 +0000 | [diff] [blame] | 266 | isEventProcessingComplete = true; |
| 267 | } |
| 268 | |
Prabir Pradhan | a67623c | 2024-02-21 06:57:36 +0000 | [diff] [blame] | 269 | InputTracer::EventState::~EventState() { |
| 270 | if (isEventProcessingComplete) { |
Prabir Pradhan | bb7a020 | 2024-02-10 02:09:01 +0000 | [diff] [blame] | 271 | // This event has already been written to the trace as expected. |
| 272 | return; |
| 273 | } |
Prabir Pradhan | 1ea04a3 | 2024-02-10 03:02:59 +0000 | [diff] [blame] | 274 | // The event processing was never marked as complete, so do it now. |
Prabir Pradhan | e770164 | 2024-02-22 04:06:53 +0000 | [diff] [blame] | 275 | // We should never end up here in normal operation. However, in tests, it's possible that we |
| 276 | // stop and destroy InputDispatcher without waiting for it to finish processing events, at |
| 277 | // which point an event (and thus its EventState) may be destroyed before processing finishes. |
| 278 | onEventProcessingComplete(); |
Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | } // namespace android::inputdispatcher::trace::impl |