From 2b6c32ca4177f1a97307f9cbd81ca485df28762c Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Tue, 13 Mar 2012 15:00:09 -0700 Subject: Fix spurious ANRs in native activities. Some native activities experienced ANRs when the input consumer deferred an input event due to client-side batching. If the input channel was fully emptied then the client had no way of knowing that it should wake up to handle the deferred input event. This patch also fixes some lock issues in the native activity input queue implementation. In at least one error case, it was possible for a function to exit without releasing the lock. Bug: 6051176 Change-Id: I4d9d843237e69b9834f8d8b360031b677fcab8c3 --- include/androidfw/Input.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'include/androidfw/Input.h') diff --git a/include/androidfw/Input.h b/include/androidfw/Input.h index f5db6e24e5d5..a4ebd95db552 100644 --- a/include/androidfw/Input.h +++ b/include/androidfw/Input.h @@ -615,6 +615,26 @@ private: MotionEvent mMotionEvent; }; +/* + * An input event factory implementation that maintains a pool of input events. + */ +class PooledInputEventFactory : public InputEventFactoryInterface { +public: + PooledInputEventFactory(size_t maxPoolSize = 20); + virtual ~PooledInputEventFactory(); + + virtual KeyEvent* createKeyEvent(); + virtual MotionEvent* createMotionEvent(); + + void recycle(InputEvent* event); + +private: + const size_t mMaxPoolSize; + + Vector mKeyEventPool; + Vector mMotionEventPool; +}; + /* * Calculates the velocity of pointer movements over time. */ -- cgit v1.2.3-59-g8ed1b