InputDispatcher: Update tests to verify spy window gesture monitors
Before we enable spy window gesture monitors, we update the tests to
ensure that the behavior of a gesture monitor will not change when its
implementation is switched to a spy window.
Bug: 162194035
Test: atest inputflinger_tests
Change-Id: Id2130d782a04abbdcbf0cc412e53ad849ccb9275
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index d1982fc..aa3643c 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -548,6 +548,7 @@
mAppSwitchSawKeyDown(false),
mAppSwitchDueTime(LONG_LONG_MAX),
mNextUnblockedEvent(nullptr),
+ mMonitorDispatchingTimeout(DEFAULT_INPUT_DISPATCHING_TIMEOUT),
mDispatchEnabled(false),
mDispatchFrozen(false),
mInputFilterEnabled(false),
@@ -707,8 +708,13 @@
return LONG_LONG_MIN;
}
-std::chrono::nanoseconds InputDispatcher::getDispatchingTimeoutLocked(const sp<IBinder>& token) {
- sp<WindowInfoHandle> window = getWindowHandleLocked(token);
+std::chrono::nanoseconds InputDispatcher::getDispatchingTimeoutLocked(
+ const sp<Connection>& connection) {
+ if (connection->monitor) {
+ return mMonitorDispatchingTimeout;
+ }
+ const sp<WindowInfoHandle> window =
+ getWindowHandleLocked(connection->inputChannel->getConnectionToken());
if (window != nullptr) {
return window->getDispatchingTimeout(DEFAULT_INPUT_DISPATCHING_TIMEOUT);
}
@@ -3205,8 +3211,7 @@
while (connection->status == Connection::Status::NORMAL && !connection->outboundQueue.empty()) {
DispatchEntry* dispatchEntry = connection->outboundQueue.front();
dispatchEntry->deliveryTime = currentTime;
- const std::chrono::nanoseconds timeout =
- getDispatchingTimeoutLocked(connection->inputChannel->getConnectionToken());
+ const std::chrono::nanoseconds timeout = getDispatchingTimeoutLocked(connection);
dispatchEntry->timeoutTime = currentTime + timeout.count();
// Publish the event.
@@ -6400,4 +6405,9 @@
mLooper->wake();
}
+void InputDispatcher::setMonitorDispatchingTimeoutForTest(std::chrono::nanoseconds timeout) {
+ std::scoped_lock _l(mLock);
+ mMonitorDispatchingTimeout = timeout;
+}
+
} // namespace android::inputdispatcher
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index 7564839..bff6cac 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -148,6 +148,9 @@
void cancelCurrentTouch() override;
+ // Public to allow tests to verify that a Monitor can get ANR.
+ void setMonitorDispatchingTimeoutForTest(std::chrono::nanoseconds timeout);
+
private:
enum class DropReason {
NOT_DROPPED,
@@ -324,8 +327,12 @@
bool runCommandsLockedInterruptable() REQUIRES(mLock);
void postCommandLocked(Command&& command) REQUIRES(mLock);
+ // The dispatching timeout to use for Monitors.
+ std::chrono::nanoseconds mMonitorDispatchingTimeout GUARDED_BY(mLock);
+
nsecs_t processAnrsLocked() REQUIRES(mLock);
- std::chrono::nanoseconds getDispatchingTimeoutLocked(const sp<IBinder>& token) REQUIRES(mLock);
+ std::chrono::nanoseconds getDispatchingTimeoutLocked(const sp<Connection>& connection)
+ REQUIRES(mLock);
// Input filter processing.
bool shouldSendKeyToInputFilterLocked(const NotifyKeyArgs* args) REQUIRES(mLock);