Skip to content

Commit 0be01b4

Browse files
TreeHugger RobotAndroid (Google) Code Review
authored andcommitted
Merge "Look up Connection by token"
2 parents ff4a17a + d0d71b6 commit 0be01b4

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ void InputDispatcher::dispatchEventLocked(nsecs_t currentTime, EventEntry* event
10381038
pokeUserActivityLocked(*eventEntry);
10391039

10401040
for (const InputTarget& inputTarget : inputTargets) {
1041-
sp<Connection> connection = getConnectionLocked(inputTarget.inputChannel);
1041+
sp<Connection> connection = getConnectionLocked(inputTarget.inputChannel->getToken());
10421042
if (connection != nullptr) {
10431043
prepareDispatchCycleLocked(currentTime, connection, eventEntry, &inputTarget);
10441044
} else {
@@ -1126,7 +1126,7 @@ void InputDispatcher::removeWindowByTokenLocked(const sp<IBinder>& token) {
11261126
}
11271127

11281128
void InputDispatcher::resumeAfterTargetsNotReadyTimeoutLocked(
1129-
nsecs_t newTimeout, const sp<InputChannel>& inputChannel) {
1129+
nsecs_t newTimeout, const sp<IBinder>& inputConnectionToken) {
11301130
if (newTimeout > 0) {
11311131
// Extend the timeout.
11321132
mInputTargetWaitTimeoutTime = now() + newTimeout;
@@ -1135,13 +1135,9 @@ void InputDispatcher::resumeAfterTargetsNotReadyTimeoutLocked(
11351135
mInputTargetWaitTimeoutExpired = true;
11361136

11371137
// Input state will not be realistic. Mark it out of sync.
1138-
sp<Connection> connection = getConnectionLocked(inputChannel);
1138+
sp<Connection> connection = getConnectionLocked(inputConnectionToken);
11391139
if (connection != nullptr) {
1140-
sp<IBinder> token = connection->inputChannel->getToken();
1141-
1142-
if (token != nullptr) {
1143-
removeWindowByTokenLocked(token);
1144-
}
1140+
removeWindowByTokenLocked(inputConnectionToken);
11451141

11461142
if (connection->status == Connection::STATUS_NORMAL) {
11471143
CancelationOptions options(CancelationOptions::CANCEL_ALL_EVENTS,
@@ -1828,8 +1824,7 @@ std::string InputDispatcher::checkWindowReadyForMoreInputLocked(
18281824
}
18291825

18301826
// If the window's connection is not registered then keep waiting.
1831-
sp<Connection> connection =
1832-
getConnectionLocked(getInputChannelLocked(windowHandle->getToken()));
1827+
sp<Connection> connection = getConnectionLocked(windowHandle->getToken());
18331828
if (connection == nullptr) {
18341829
return StringPrintf("Waiting because the %s window's input channel is not "
18351830
"registered with the input dispatcher. The window may be in the "
@@ -2477,7 +2472,7 @@ void InputDispatcher::synthesizeCancelationEventsForMonitorsLocked(
24772472

24782473
void InputDispatcher::synthesizeCancelationEventsForInputChannelLocked(
24792474
const sp<InputChannel>& channel, const CancelationOptions& options) {
2480-
sp<Connection> connection = getConnectionLocked(channel);
2475+
sp<Connection> connection = getConnectionLocked(channel->getToken());
24812476
if (connection == nullptr) {
24822477
return;
24832478
}
@@ -3571,10 +3566,8 @@ bool InputDispatcher::transferTouchFocus(const sp<IBinder>& fromToken, const sp<
35713566
return false;
35723567
}
35733568

3574-
sp<InputChannel> fromChannel = getInputChannelLocked(fromToken);
3575-
sp<InputChannel> toChannel = getInputChannelLocked(toToken);
3576-
sp<Connection> fromConnection = getConnectionLocked(fromChannel);
3577-
sp<Connection> toConnection = getConnectionLocked(toChannel);
3569+
sp<Connection> fromConnection = getConnectionLocked(fromToken);
3570+
sp<Connection> toConnection = getConnectionLocked(toToken);
35783571
if (fromConnection != nullptr && toConnection != nullptr) {
35793572
fromConnection->inputState.copyPointerStateTo(toConnection->inputState);
35803573
CancelationOptions
@@ -3873,7 +3866,7 @@ status_t InputDispatcher::registerInputChannel(const sp<InputChannel>& inputChan
38733866

38743867
{ // acquire lock
38753868
std::scoped_lock _l(mLock);
3876-
sp<Connection> existingConnection = getConnectionLocked(inputChannel);
3869+
sp<Connection> existingConnection = getConnectionLocked(inputChannel->getToken());
38773870
if (existingConnection != nullptr) {
38783871
ALOGW("Attempted to register already registered input channel '%s'",
38793872
inputChannel->getName().c_str());
@@ -3948,7 +3941,7 @@ status_t InputDispatcher::unregisterInputChannel(const sp<InputChannel>& inputCh
39483941

39493942
status_t InputDispatcher::unregisterInputChannelLocked(const sp<InputChannel>& inputChannel,
39503943
bool notify) {
3951-
sp<Connection> connection = getConnectionLocked(inputChannel);
3944+
sp<Connection> connection = getConnectionLocked(inputChannel->getToken());
39523945
if (connection == nullptr) {
39533946
ALOGW("Attempted to unregister already unregistered input channel '%s'",
39543947
inputChannel->getName().c_str());
@@ -4056,14 +4049,14 @@ std::optional<int32_t> InputDispatcher::findGestureMonitorDisplayByTokenLocked(
40564049
return std::nullopt;
40574050
}
40584051

4059-
sp<Connection> InputDispatcher::getConnectionLocked(const sp<InputChannel>& inputChannel) {
4060-
if (inputChannel == nullptr) {
4052+
sp<Connection> InputDispatcher::getConnectionLocked(const sp<IBinder>& inputConnectionToken) {
4053+
if (inputConnectionToken == nullptr) {
40614054
return nullptr;
40624055
}
40634056

40644057
for (const auto& pair : mConnectionsByFd) {
4065-
sp<Connection> connection = pair.second;
4066-
if (connection->inputChannel->getToken() == inputChannel->getToken()) {
4058+
const sp<Connection>& connection = pair.second;
4059+
if (connection->inputChannel->getToken() == inputConnectionToken) {
40674060
return connection;
40684061
}
40694062
}
@@ -4171,17 +4164,16 @@ void InputDispatcher::doNotifyFocusChangedLockedInterruptible(CommandEntry* comm
41714164
}
41724165

41734166
void InputDispatcher::doNotifyANRLockedInterruptible(CommandEntry* commandEntry) {
4167+
sp<IBinder> token =
4168+
commandEntry->inputChannel ? commandEntry->inputChannel->getToken() : nullptr;
41744169
mLock.unlock();
41754170

41764171
nsecs_t newTimeout =
4177-
mPolicy->notifyANR(commandEntry->inputApplicationHandle,
4178-
commandEntry->inputChannel ? commandEntry->inputChannel->getToken()
4179-
: nullptr,
4180-
commandEntry->reason);
4172+
mPolicy->notifyANR(commandEntry->inputApplicationHandle, token, commandEntry->reason);
41814173

41824174
mLock.lock();
41834175

4184-
resumeAfterTargetsNotReadyTimeoutLocked(newTimeout, commandEntry->inputChannel);
4176+
resumeAfterTargetsNotReadyTimeoutLocked(newTimeout, token);
41854177
}
41864178

41874179
void InputDispatcher::doInterceptKeyBeforeDispatchingLockedInterruptible(

services/inputflinger/dispatcher/InputDispatcher.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class InputDispatcher : public android::InputDispatcherInterface {
183183
std::optional<int32_t> findGestureMonitorDisplayByTokenLocked(const sp<IBinder>& token)
184184
REQUIRES(mLock);
185185

186-
sp<Connection> getConnectionLocked(const sp<InputChannel>& inputChannel) REQUIRES(mLock);
186+
sp<Connection> getConnectionLocked(const sp<IBinder>& inputConnectionToken) REQUIRES(mLock);
187187

188188
// Input channels that will receive a copy of all input events sent to the provided display.
189189
std::unordered_map<int32_t, std::vector<Monitor>> mGlobalMonitorsByDisplay GUARDED_BY(mLock);
@@ -322,7 +322,7 @@ class InputDispatcher : public android::InputDispatcherInterface {
322322
void removeWindowByTokenLocked(const sp<IBinder>& token) REQUIRES(mLock);
323323

324324
void resumeAfterTargetsNotReadyTimeoutLocked(nsecs_t newTimeout,
325-
const sp<InputChannel>& inputChannel)
325+
const sp<IBinder>& inputConnectionToken)
326326
REQUIRES(mLock);
327327
nsecs_t getTimeSpentWaitingForApplicationLocked(nsecs_t currentTime) REQUIRES(mLock);
328328
void resetANRTimeoutsLocked() REQUIRES(mLock);

0 commit comments

Comments
 (0)