Skip to content

Commit 0394181

Browse files
author
Arpit Singh
committed
[7/n InputDispatcher refactor] refactor removeInputChannel
Refactor removeInputChannelLocked so that it can be moved out to a separate class in upcoming CL. Bug: 367661487 Bug: 245989146 Test: atest inputflinger_tests Flag: EXEMPT refactor Change-Id: Ieac763aa5ada504b4ee76ff6d9a872949cb49e14
1 parent 5ba84c7 commit 0394181

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

@@ -3930,7 +3930,7 @@ void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime,
39303930
"event to it, status=%s(%d)",
39313931
connection->getInputChannelName().c_str(), statusToString(status).c_str(),
39323932
status);
3933-
abortBrokenDispatchCycleLocked(currentTime, connection, /*notify=*/true);
3933+
abortBrokenDispatchCycleLocked(connection, /*notify=*/true);
39343934
} else {
39353935
// Pipe is full and we are waiting for the app to finish process some events
39363936
// before sending more events to it.
@@ -3945,7 +3945,7 @@ void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime,
39453945
"status=%s(%d)",
39463946
connection->getInputChannelName().c_str(), statusToString(status).c_str(),
39473947
status);
3948-
abortBrokenDispatchCycleLocked(currentTime, connection, /*notify=*/true);
3948+
abortBrokenDispatchCycleLocked(connection, /*notify=*/true);
39493949
}
39503950
return;
39513951
}
@@ -4020,8 +4020,7 @@ void InputDispatcher::finishDispatchCycleLocked(nsecs_t currentTime,
40204020
postCommandLocked(std::move(command));
40214021
}
40224022

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

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

@@ -6302,8 +6301,14 @@ Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputMonitor(
63026301
status_t InputDispatcher::removeInputChannel(const sp<IBinder>& connectionToken) {
63036302
{ // acquire lock
63046303
std::scoped_lock _l(mLock);
6304+
std::shared_ptr<Connection> connection = getConnectionLocked(connectionToken);
6305+
if (connection == nullptr) {
6306+
// Connection can be removed via socket hang up or an explicit call to
6307+
// 'removeInputChannel'
6308+
return BAD_VALUE;
6309+
}
63056310

6306-
status_t status = removeInputChannelLocked(connectionToken, /*notify=*/false);
6311+
status_t status = removeInputChannelLocked(connection, /*notify=*/false);
63076312
if (status) {
63086313
return status;
63096314
}
@@ -6315,25 +6320,18 @@ status_t InputDispatcher::removeInputChannel(const sp<IBinder>& connectionToken)
63156320
return OK;
63166321
}
63176322

6318-
status_t InputDispatcher::removeInputChannelLocked(const sp<IBinder>& connectionToken,
6323+
status_t InputDispatcher::removeInputChannelLocked(const std::shared_ptr<Connection>& connection,
63196324
bool notify) {
6320-
std::shared_ptr<Connection> connection = getConnectionLocked(connectionToken);
6321-
if (connection == nullptr) {
6322-
// Connection can be removed via socket hang up or an explicit call to 'removeInputChannel'
6323-
return BAD_VALUE;
6324-
}
6325-
6325+
LOG_ALWAYS_FATAL_IF(connection == nullptr);
6326+
abortBrokenDispatchCycleLocked(connection, notify);
63266327
removeConnectionLocked(connection);
63276328

63286329
if (connection->monitor) {
6329-
removeMonitorChannelLocked(connectionToken);
6330+
removeMonitorChannelLocked(connection->getToken());
63306331
}
63316332

63326333
mLooper->removeFd(connection->inputPublisher.getChannel().getFd());
63336334

6334-
nsecs_t currentTime = now();
6335-
abortBrokenDispatchCycleLocked(currentTime, connection, notify);
6336-
63376335
connection->status = Connection::Status::ZOMBIE;
63386336
return OK;
63396337
}

services/inputflinger/dispatcher/InputDispatcher.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,7 @@ class InputDispatcher : public android::InputDispatcherInterface {
646646
void finishDispatchCycleLocked(nsecs_t currentTime,
647647
const std::shared_ptr<Connection>& connection, uint32_t seq,
648648
bool handled, nsecs_t consumeTime) REQUIRES(mLock);
649-
void abortBrokenDispatchCycleLocked(nsecs_t currentTime,
650-
const std::shared_ptr<Connection>& connection, bool notify)
649+
void abortBrokenDispatchCycleLocked(const std::shared_ptr<Connection>& connection, bool notify)
651650
REQUIRES(mLock);
652651
void drainDispatchQueue(std::deque<std::unique_ptr<DispatchEntry>>& queue);
653652
void releaseDispatchEntry(std::unique_ptr<DispatchEntry> dispatchEntry);
@@ -693,7 +692,7 @@ class InputDispatcher : public android::InputDispatcherInterface {
693692

694693
// Registration.
695694
void removeMonitorChannelLocked(const sp<IBinder>& connectionToken) REQUIRES(mLock);
696-
status_t removeInputChannelLocked(const sp<IBinder>& connectionToken, bool notify)
695+
status_t removeInputChannelLocked(const std::shared_ptr<Connection>& connection, bool notify)
697696
REQUIRES(mLock);
698697

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

0 commit comments

Comments
 (0)