summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2021-02-08 19:39:50 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2021-02-08 19:39:50 +0000
commit302fee2499bb33dae85a8aa9d1e038fd23f9b8de (patch)
tree47c124e0c4a3e883ad857285220b5414576abb62
parent194d5d31cf24b8432e54314e2a315130b5d21b44 (diff)
parent167e6d9eadcb057125e2b0828edbebe521b88a17 (diff)
Merge "InputDispatcher: Fix crash with out-of-order pointer capture requests" into sc-dev
-rw-r--r--services/inputflinger/dispatcher/InputDispatcher.cpp7
-rw-r--r--services/inputflinger/tests/InputDispatcher_test.cpp23
2 files changed, 27 insertions, 3 deletions
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 5a577d4b99..290993935a 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -1247,9 +1247,10 @@ void InputDispatcher::dispatchPointerCaptureChangedLocked(
nsecs_t currentTime, const std::shared_ptr<PointerCaptureChangedEntry>& entry,
DropReason& dropReason) {
const bool haveWindowWithPointerCapture = mWindowTokenWithPointerCapture != nullptr;
- if (entry->pointerCaptureEnabled == haveWindowWithPointerCapture) {
- LOG_ALWAYS_FATAL_IF(mFocusedWindowRequestedPointerCapture,
- "The Pointer Capture state has already been dispatched to the window.");
+ if (entry->pointerCaptureEnabled && haveWindowWithPointerCapture) {
+ LOG_ALWAYS_FATAL("Pointer Capture has already been enabled for the window.");
+ }
+ if (!entry->pointerCaptureEnabled && !haveWindowWithPointerCapture) {
// Pointer capture was already forcefully disabled because of focus change.
dropReason = DropReason::NOT_DROPPED;
return;
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index e063dfc669..01945dbbf1 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -4217,4 +4217,27 @@ TEST_F(InputDispatcherPointerCaptureTests, UnexpectedStateChangeDisablesPointerC
mWindow->assertNoEvents();
}
+TEST_F(InputDispatcherPointerCaptureTests, OutOfOrderRequests) {
+ requestAndVerifyPointerCapture(mWindow, true);
+
+ // The first window loses focus.
+ setFocusedWindow(mSecondWindow);
+ mFakePolicy->waitForSetPointerCapture(false);
+ mWindow->consumeCaptureEvent(false);
+
+ // Request Pointer Capture from the second window before the notification from InputReader
+ // arrives.
+ mDispatcher->requestPointerCapture(mSecondWindow->getToken(), true);
+ mFakePolicy->waitForSetPointerCapture(true);
+
+ // InputReader notifies Pointer Capture was disabled (because of the focus change).
+ notifyPointerCaptureChanged(false);
+
+ // InputReader notifies Pointer Capture was enabled (because of mSecondWindow's request).
+ notifyPointerCaptureChanged(true);
+
+ mSecondWindow->consumeFocusEvent(true);
+ mSecondWindow->consumeCaptureEvent(true);
+}
+
} // namespace android::inputdispatcher