Revert "InputDispatcher: Blame the window from the focus request for ANR"
This reverts commit 2f5bc8b8cfda7762213268842c13e2280ac02466.
Breaks android.server.wm.AnrTests#slowUiThreadWithKeyEventTriggersAnr
Test: atest android.server.wm.AnrTests#slowUiThreadWithKeyEventTriggersAnr
Bug: 239907039
Change-Id: I45fcaf7d92fdedfa965d563cdb62ad2da3c8f5d4
diff --git a/services/inputflinger/dispatcher/FocusResolver.cpp b/services/inputflinger/dispatcher/FocusResolver.cpp
index 85dcf8f..4da846b 100644
--- a/services/inputflinger/dispatcher/FocusResolver.cpp
+++ b/services/inputflinger/dispatcher/FocusResolver.cpp
@@ -39,7 +39,7 @@
return it != mFocusedWindowTokenByDisplay.end() ? it->second.second : nullptr;
}
-std::optional<FocusRequest> FocusResolver::getFocusRequest(int32_t displayId) const {
+std::optional<FocusRequest> FocusResolver::getFocusRequest(int32_t displayId) {
auto it = mFocusRequestByDisplay.find(displayId);
return it != mFocusRequestByDisplay.end() ? std::make_optional<>(it->second) : std::nullopt;
}
diff --git a/services/inputflinger/dispatcher/FocusResolver.h b/services/inputflinger/dispatcher/FocusResolver.h
index 8a6dfa4..6d11a77 100644
--- a/services/inputflinger/dispatcher/FocusResolver.h
+++ b/services/inputflinger/dispatcher/FocusResolver.h
@@ -62,7 +62,6 @@
std::optional<FocusResolver::FocusChanges> setFocusedWindow(
const android::gui::FocusRequest& request,
const std::vector<sp<android::gui::WindowInfoHandle>>& windows);
- std::optional<android::gui::FocusRequest> getFocusRequest(int32_t displayId) const;
// Display has been removed from the system, clean up old references.
void displayRemoved(int32_t displayId);
@@ -113,6 +112,7 @@
std::optional<FocusResolver::FocusChanges> updateFocusedWindow(
int32_t displayId, const std::string& reason, const sp<IBinder>& token,
const std::string& tokenName = "");
+ std::optional<android::gui::FocusRequest> getFocusRequest(int32_t displayId);
};
} // namespace android::inputdispatcher
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index b52e312..ff63967 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -659,13 +659,6 @@
if (focusedWindowHandle != nullptr) {
return; // We now have a focused window. No need for ANR.
}
- std::optional<FocusRequest> pendingRequest =
- mFocusResolver.getFocusRequest(mAwaitedApplicationDisplayId);
- if (pendingRequest.has_value() && onAnrLocked(*pendingRequest)) {
- // We don't have a focusable window but we know which window should have
- // been focused. Blame that process in case it doesn't belong to the focused app.
- return;
- }
onAnrLocked(mAwaitedFocusedApplication);
}
@@ -5855,25 +5848,6 @@
postCommandLocked(std::move(command));
}
-bool InputDispatcher::onAnrLocked(const android::gui::FocusRequest& pendingFocusRequest) {
- if (pendingFocusRequest.token == nullptr) {
- return false;
- }
-
- const std::string reason = android::base::StringPrintf("%s is not focusable.",
- pendingFocusRequest.windowName.c_str());
- updateLastAnrStateLocked(pendingFocusRequest.windowName, reason);
- sp<Connection> connection = getConnectionLocked(pendingFocusRequest.token);
- if (connection != nullptr) {
- processConnectionUnresponsiveLocked(*connection, std::move(reason));
- // Stop waking up for events on this connection, it is already unresponsive
- cancelEventsForAnrLocked(connection);
- } else {
- sendWindowUnresponsiveCommandLocked(pendingFocusRequest.token, std::nullopt, reason);
- }
- return true;
-}
-
void InputDispatcher::onAnrLocked(const sp<Connection>& connection) {
if (connection == nullptr) {
LOG_ALWAYS_FATAL("Caller must check for nullness");
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index dc6dd5c..be619ae 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -658,7 +658,6 @@
void sendDropWindowCommandLocked(const sp<IBinder>& token, float x, float y) REQUIRES(mLock);
void onAnrLocked(const sp<Connection>& connection) REQUIRES(mLock);
void onAnrLocked(std::shared_ptr<InputApplicationHandle> application) REQUIRES(mLock);
- bool onAnrLocked(const android::gui::FocusRequest& pendingFocusRequest) REQUIRES(mLock);
void updateLastAnrStateLocked(const sp<android::gui::WindowInfoHandle>& window,
const std::string& reason) REQUIRES(mLock);
void updateLastAnrStateLocked(const InputApplicationHandle& application,