Fix NPE in InputDispacher by enabling debug logs
InputDispatcher will manage input channels and input windows.
Once some input channel unregistered, there is a chance to
find the corresponded target before setInputWindow.
Then input channel of input target would access the null pointer.
Bug: 120307496
Test: Enable debug log, run monkey test serveral times.
Test: atest inputflinger_tests
Change-Id: Ia7b36e0732e0ac6c825f3910fd02b1cdbbf85161
diff --git a/services/inputflinger/InputDispatcher.cpp b/services/inputflinger/InputDispatcher.cpp
index 885348e..ac17dca 100644
--- a/services/inputflinger/InputDispatcher.cpp
+++ b/services/inputflinger/InputDispatcher.cpp
@@ -1663,11 +1663,17 @@
void InputDispatcher::addWindowTargetLocked(const sp<InputWindowHandle>& windowHandle,
int32_t targetFlags, BitSet32 pointerIds, Vector<InputTarget>& inputTargets) {
+ sp<InputChannel> inputChannel = getInputChannelLocked(windowHandle->getToken());
+ if (inputChannel == nullptr) {
+ ALOGW("Window %s already unregistered input channel", windowHandle->getName().c_str());
+ return;
+ }
+
inputTargets.push();
const InputWindowInfo* windowInfo = windowHandle->getInfo();
InputTarget& target = inputTargets.editTop();
- target.inputChannel = getInputChannelLocked(windowHandle->getToken());
+ target.inputChannel = inputChannel;
target.flags = targetFlags;
target.xOffset = - windowInfo->frameLeft;
target.yOffset = - windowInfo->frameTop;