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