Skip to content

Commit 0ea3321

Browse files
Arpit SinghAndroid (Google) Code Review
authored andcommitted
Merge "[7/n InputDispatcher refactor] refactor removeInputChannel" into main
2 parents 0a18c9b + 0394181 commit 0ea3321

2 files changed

Lines changed: 18 additions & 21 deletions

File tree

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ InputDispatcher::~InputDispatcher() {
998998

999999
while (!mConnectionsByToken.empty()) {
10001000
std::shared_ptr<Connection> connection = mConnectionsByToken.begin()->second;
1001-
removeInputChannelLocked(connection->getToken(), /*notify=*/false);
1001+
removeInputChannelLocked(connection, /*notify=*/false);
10021002
}
10031003
}
10041004

@@ -3929,7 +3929,7 @@ void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime,
39293929
"event to it, status=%s(%d)",
39303930
connection->getInputChannelName().c_str(), statusToString(status).c_str(),
39313931
status);
3932-
abortBrokenDispatchCycleLocked(currentTime, connection, /*notify=*/true);
3932+
abortBrokenDispatchCycleLocked(connection, /*notify=*/true);
39333933
} else {
39343934
// Pipe is full and we are waiting for the app to finish process some events
39353935
// before sending more events to it.
@@ -3944,7 +3944,7 @@ void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime,
39443944
"status=%s(%d)",
39453945
connection->getInputChannelName().c_str(), statusToString(status).c_str(),
39463946
status);
3947-
abortBrokenDispatchCycleLocked(currentTime, connection, /*notify=*/true);
3947+
abortBrokenDispatchCycleLocked(connection, /*notify=*/true);
39483948
}
39493949
return;
39503950
}
@@ -4019,8 +4019,7 @@ void InputDispatcher::finishDispatchCycleLocked(nsecs_t currentTime,
40194019
postCommandLocked(std::move(command));
40204020
}
40214021

4022-
void InputDispatcher::abortBrokenDispatchCycleLocked(nsecs_t currentTime,
4023-
const std::shared_ptr<Connection>& connection,
4022+
void InputDispatcher::abortBrokenDispatchCycleLocked(const std::shared_ptr<Connection>& connection,
40244023
bool notify) {
40254024
if (DEBUG_DISPATCH_CYCLE) {
40264025
LOG(INFO) << "channel '" << connection->getInputChannelName() << "'~ " << __func__
@@ -4136,7 +4135,7 @@ int InputDispatcher::handleReceiveCallback(int events, sp<IBinder> connectionTok
41364135
}
41374136

41384137
// Remove the channel.
4139-
removeInputChannelLocked(connection->getToken(), notify);
4138+
removeInputChannelLocked(connection, notify);
41404139
return 0; // remove the callback
41414140
}
41424141

@@ -6313,8 +6312,14 @@ Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputMonitor(
63136312
status_t InputDispatcher::removeInputChannel(const sp<IBinder>& connectionToken) {
63146313
{ // acquire lock
63156314
std::scoped_lock _l(mLock);
6315+
std::shared_ptr<Connection> connection = getConnectionLocked(connectionToken);
6316+
if (connection == nullptr) {
6317+
// Connection can be removed via socket hang up or an explicit call to
6318+
// 'removeInputChannel'
6319+
return BAD_VALUE;
6320+
}
63166321

6317-
status_t status = removeInputChannelLocked(connectionToken, /*notify=*/false);
6322+
status_t status = removeInputChannelLocked(connection, /*notify=*/false);
63186323
if (status) {
63196324
return status;
63206325
}
@@ -6326,25 +6331,18 @@ status_t InputDispatcher::removeInputChannel(const sp<IBinder>& connectionToken)
63266331
return OK;
63276332
}
63286333

6329-
status_t InputDispatcher::removeInputChannelLocked(const sp<IBinder>& connectionToken,
6334+
status_t InputDispatcher::removeInputChannelLocked(const std::shared_ptr<Connection>& connection,
63306335
bool notify) {
6331-
std::shared_ptr<Connection> connection = getConnectionLocked(connectionToken);
6332-
if (connection == nullptr) {
6333-
// Connection can be removed via socket hang up or an explicit call to 'removeInputChannel'
6334-
return BAD_VALUE;
6335-
}
6336-
6336+
LOG_ALWAYS_FATAL_IF(connection == nullptr);
6337+
abortBrokenDispatchCycleLocked(connection, notify);
63376338
removeConnectionLocked(connection);
63386339

63396340
if (connection->monitor) {
6340-
removeMonitorChannelLocked(connectionToken);
6341+
removeMonitorChannelLocked(connection->getToken());
63416342
}
63426343

63436344
mLooper->removeFd(connection->inputPublisher.getChannel().getFd());
63446345

6345-
nsecs_t currentTime = now();
6346-
abortBrokenDispatchCycleLocked(currentTime, connection, notify);
6347-
63486346
connection->status = Connection::Status::ZOMBIE;
63496347
return OK;
63506348
}

services/inputflinger/dispatcher/InputDispatcher.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,7 @@ class InputDispatcher : public android::InputDispatcherInterface {
649649
void finishDispatchCycleLocked(nsecs_t currentTime,
650650
const std::shared_ptr<Connection>& connection, uint32_t seq,
651651
bool handled, nsecs_t consumeTime) REQUIRES(mLock);
652-
void abortBrokenDispatchCycleLocked(nsecs_t currentTime,
653-
const std::shared_ptr<Connection>& connection, bool notify)
652+
void abortBrokenDispatchCycleLocked(const std::shared_ptr<Connection>& connection, bool notify)
654653
REQUIRES(mLock);
655654
void drainDispatchQueue(std::deque<std::unique_ptr<DispatchEntry>>& queue);
656655
void releaseDispatchEntry(std::unique_ptr<DispatchEntry> dispatchEntry);
@@ -696,7 +695,7 @@ class InputDispatcher : public android::InputDispatcherInterface {
696695

697696
// Registration.
698697
void removeMonitorChannelLocked(const sp<IBinder>& connectionToken) REQUIRES(mLock);
699-
status_t removeInputChannelLocked(const sp<IBinder>& connectionToken, bool notify)
698+
status_t removeInputChannelLocked(const std::shared_ptr<Connection>& connection, bool notify)
700699
REQUIRES(mLock);
701700

702701
// Interesting events that we might like to log or tell the framework about.

0 commit comments

Comments
 (0)