@@ -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(
63026301status_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}
0 commit comments