Allow sendMotionEvent from any thread
Before this CL, sendMotionEvent was only allowed to be called from the looper thread. However, this was not enforced in any way. This led to bugs where the event may not be added to the internal queue of NativeInputEventSender yet, but the fd is already getting processed and therefore the received event was dropped without any error. One option to fix this is to simply raise Exception when the call happens on the wrong thread. However, that still puts the burden on the caller to figure out how to call it properly. Instead, in this CL, allow this method to be called on any thread. If it's called on the looper thread, then great - return the result immediately. If it's called on another thread, then create a Handler and post a future to the looper thread. Then wait indefinitely until the action is executed on the looper thread, and return the result in the original thread. Bug: 290931418 Test: atest PointerEventDispatcherTest --rerun-until-failure 1000 Change-Id: I39396a8d04e73c090e7d71feafc734075ed27867
Loading
Please register or sign in to comment