OSDN Git Service

Fix NPE in InputDispacher by enabling debug logs
authorArthur Hung <arthurhung@google.com>
Wed, 5 Dec 2018 08:14:18 +0000 (16:14 +0800)
committerArthur Hung <arthurhung@google.com>
Thu, 6 Dec 2018 03:53:53 +0000 (11:53 +0800)
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

services/inputflinger/InputDispatcher.cpp

index 885348e..ac17dca 100644 (file)
@@ -1663,11 +1663,17 @@ Unresponsive:
 
 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;