summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Arpit Singh <arpitks@google.com> 2025-01-07 05:31:57 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2025-01-07 05:31:57 -0800
commit0ea3321806431e100e6784907711d6660dcaaebe (patch)
treeea537387fa6c57640a717696e3e7c032c32c6e44
parent0a18c9b06bc768ca4dc62703fa12e411868f504a (diff)
parent039418103eb548d5e420d729e3c35478bdc5eb30 (diff)
Merge "[7/n InputDispatcher refactor] refactor removeInputChannel" into main
-rw-r--r--services/inputflinger/dispatcher/InputDispatcher.cpp34
-rw-r--r--services/inputflinger/dispatcher/InputDispatcher.h5
2 files changed, 18 insertions, 21 deletions
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 28422d636a..93a3ace261 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -998,7 +998,7 @@ InputDispatcher::~InputDispatcher() {
while (!mConnectionsByToken.empty()) {
std::shared_ptr<Connection> connection = mConnectionsByToken.begin()->second;
- removeInputChannelLocked(connection->getToken(), /*notify=*/false);
+ removeInputChannelLocked(connection, /*notify=*/false);
}
}
@@ -3929,7 +3929,7 @@ void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime,
"event to it, status=%s(%d)",
connection->getInputChannelName().c_str(), statusToString(status).c_str(),
status);
- abortBrokenDispatchCycleLocked(currentTime, connection, /*notify=*/true);
+ abortBrokenDispatchCycleLocked(connection, /*notify=*/true);
} else {
// Pipe is full and we are waiting for the app to finish process some events
// before sending more events to it.
@@ -3944,7 +3944,7 @@ void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime,
"status=%s(%d)",
connection->getInputChannelName().c_str(), statusToString(status).c_str(),
status);
- abortBrokenDispatchCycleLocked(currentTime, connection, /*notify=*/true);
+ abortBrokenDispatchCycleLocked(connection, /*notify=*/true);
}
return;
}
@@ -4019,8 +4019,7 @@ void InputDispatcher::finishDispatchCycleLocked(nsecs_t currentTime,
postCommandLocked(std::move(command));
}
-void InputDispatcher::abortBrokenDispatchCycleLocked(nsecs_t currentTime,
- const std::shared_ptr<Connection>& connection,
+void InputDispatcher::abortBrokenDispatchCycleLocked(const std::shared_ptr<Connection>& connection,
bool notify) {
if (DEBUG_DISPATCH_CYCLE) {
LOG(INFO) << "channel '" << connection->getInputChannelName() << "'~ " << __func__
@@ -4136,7 +4135,7 @@ int InputDispatcher::handleReceiveCallback(int events, sp<IBinder> connectionTok
}
// Remove the channel.
- removeInputChannelLocked(connection->getToken(), notify);
+ removeInputChannelLocked(connection, notify);
return 0; // remove the callback
}
@@ -6313,8 +6312,14 @@ Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputMonitor(
status_t InputDispatcher::removeInputChannel(const sp<IBinder>& connectionToken) {
{ // acquire lock
std::scoped_lock _l(mLock);
+ std::shared_ptr<Connection> connection = getConnectionLocked(connectionToken);
+ if (connection == nullptr) {
+ // Connection can be removed via socket hang up or an explicit call to
+ // 'removeInputChannel'
+ return BAD_VALUE;
+ }
- status_t status = removeInputChannelLocked(connectionToken, /*notify=*/false);
+ status_t status = removeInputChannelLocked(connection, /*notify=*/false);
if (status) {
return status;
}
@@ -6326,25 +6331,18 @@ status_t InputDispatcher::removeInputChannel(const sp<IBinder>& connectionToken)
return OK;
}
-status_t InputDispatcher::removeInputChannelLocked(const sp<IBinder>& connectionToken,
+status_t InputDispatcher::removeInputChannelLocked(const std::shared_ptr<Connection>& connection,
bool notify) {
- std::shared_ptr<Connection> connection = getConnectionLocked(connectionToken);
- if (connection == nullptr) {
- // Connection can be removed via socket hang up or an explicit call to 'removeInputChannel'
- return BAD_VALUE;
- }
-
+ LOG_ALWAYS_FATAL_IF(connection == nullptr);
+ abortBrokenDispatchCycleLocked(connection, notify);
removeConnectionLocked(connection);
if (connection->monitor) {
- removeMonitorChannelLocked(connectionToken);
+ removeMonitorChannelLocked(connection->getToken());
}
mLooper->removeFd(connection->inputPublisher.getChannel().getFd());
- nsecs_t currentTime = now();
- abortBrokenDispatchCycleLocked(currentTime, connection, notify);
-
connection->status = Connection::Status::ZOMBIE;
return OK;
}
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index 8485b44a03..cfa4e95c16 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -649,8 +649,7 @@ private:
void finishDispatchCycleLocked(nsecs_t currentTime,
const std::shared_ptr<Connection>& connection, uint32_t seq,
bool handled, nsecs_t consumeTime) REQUIRES(mLock);
- void abortBrokenDispatchCycleLocked(nsecs_t currentTime,
- const std::shared_ptr<Connection>& connection, bool notify)
+ void abortBrokenDispatchCycleLocked(const std::shared_ptr<Connection>& connection, bool notify)
REQUIRES(mLock);
void drainDispatchQueue(std::deque<std::unique_ptr<DispatchEntry>>& queue);
void releaseDispatchEntry(std::unique_ptr<DispatchEntry> dispatchEntry);
@@ -696,7 +695,7 @@ private:
// Registration.
void removeMonitorChannelLocked(const sp<IBinder>& connectionToken) REQUIRES(mLock);
- status_t removeInputChannelLocked(const sp<IBinder>& connectionToken, bool notify)
+ status_t removeInputChannelLocked(const std::shared_ptr<Connection>& connection, bool notify)
REQUIRES(mLock);
// Interesting events that we might like to log or tell the framework about.