InputDispatcher.h 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156
  1. /*
  2. * Copyright (C) 2010 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef _UI_INPUT_DISPATCHER_H
  17. #define _UI_INPUT_DISPATCHER_H
  18. #include <input/Input.h>
  19. #include <input/InputTransport.h>
  20. #include <utils/KeyedVector.h>
  21. #include <utils/Vector.h>
  22. #include <utils/threads.h>
  23. #include <utils/Timers.h>
  24. #include <utils/RefBase.h>
  25. #include <utils/String8.h>
  26. #include <utils/Looper.h>
  27. #include <utils/BitSet.h>
  28. #include <cutils/atomic.h>
  29. #include <stddef.h>
  30. #include <unistd.h>
  31. #include <limits.h>
  32. #include "InputWindow.h"
  33. #include "InputApplication.h"
  34. #include "InputListener.h"
  35. namespace android {
  36. /*
  37. * Constants used to report the outcome of input event injection.
  38. */
  39. enum {
  40. /* (INTERNAL USE ONLY) Specifies that injection is pending and its outcome is unknown. */
  41. INPUT_EVENT_INJECTION_PENDING = -1,
  42. /* Injection succeeded. */
  43. INPUT_EVENT_INJECTION_SUCCEEDED = 0,
  44. /* Injection failed because the injector did not have permission to inject
  45. * into the application with input focus. */
  46. INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1,
  47. /* Injection failed because there were no available input targets. */
  48. INPUT_EVENT_INJECTION_FAILED = 2,
  49. /* Injection failed due to a timeout. */
  50. INPUT_EVENT_INJECTION_TIMED_OUT = 3
  51. };
  52. /*
  53. * Constants used to determine the input event injection synchronization mode.
  54. */
  55. enum {
  56. /* Injection is asynchronous and is assumed always to be successful. */
  57. INPUT_EVENT_INJECTION_SYNC_NONE = 0,
  58. /* Waits for previous events to be dispatched so that the input dispatcher can determine
  59. * whether input event injection willbe permitted based on the current input focus.
  60. * Does not wait for the input event to finish processing. */
  61. INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT = 1,
  62. /* Waits for the input event to be completely processed. */
  63. INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISHED = 2,
  64. };
  65. /*
  66. * An input target specifies how an input event is to be dispatched to a particular window
  67. * including the window's input channel, control flags, a timeout, and an X / Y offset to
  68. * be added to input event coordinates to compensate for the absolute position of the
  69. * window area.
  70. */
  71. struct InputTarget {
  72. enum {
  73. /* This flag indicates that the event is being delivered to a foreground application. */
  74. FLAG_FOREGROUND = 1 << 0,
  75. /* This flag indicates that the MotionEvent falls within the area of the target
  76. * obscured by another visible window above it. The motion event should be
  77. * delivered with flag AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED. */
  78. FLAG_WINDOW_IS_OBSCURED = 1 << 1,
  79. /* This flag indicates that a motion event is being split across multiple windows. */
  80. FLAG_SPLIT = 1 << 2,
  81. /* This flag indicates that the pointer coordinates dispatched to the application
  82. * will be zeroed out to avoid revealing information to an application. This is
  83. * used in conjunction with FLAG_DISPATCH_AS_OUTSIDE to prevent apps not sharing
  84. * the same UID from watching all touches. */
  85. FLAG_ZERO_COORDS = 1 << 3,
  86. /* This flag indicates that the event should be sent as is.
  87. * Should always be set unless the event is to be transmuted. */
  88. FLAG_DISPATCH_AS_IS = 1 << 8,
  89. /* This flag indicates that a MotionEvent with AMOTION_EVENT_ACTION_DOWN falls outside
  90. * of the area of this target and so should instead be delivered as an
  91. * AMOTION_EVENT_ACTION_OUTSIDE to this target. */
  92. FLAG_DISPATCH_AS_OUTSIDE = 1 << 9,
  93. /* This flag indicates that a hover sequence is starting in the given window.
  94. * The event is transmuted into ACTION_HOVER_ENTER. */
  95. FLAG_DISPATCH_AS_HOVER_ENTER = 1 << 10,
  96. /* This flag indicates that a hover event happened outside of a window which handled
  97. * previous hover events, signifying the end of the current hover sequence for that
  98. * window.
  99. * The event is transmuted into ACTION_HOVER_ENTER. */
  100. FLAG_DISPATCH_AS_HOVER_EXIT = 1 << 11,
  101. /* This flag indicates that the event should be canceled.
  102. * It is used to transmute ACTION_MOVE into ACTION_CANCEL when a touch slips
  103. * outside of a window. */
  104. FLAG_DISPATCH_AS_SLIPPERY_EXIT = 1 << 12,
  105. /* This flag indicates that the event should be dispatched as an initial down.
  106. * It is used to transmute ACTION_MOVE into ACTION_DOWN when a touch slips
  107. * into a new window. */
  108. FLAG_DISPATCH_AS_SLIPPERY_ENTER = 1 << 13,
  109. /* Mask for all dispatch modes. */
  110. FLAG_DISPATCH_MASK = FLAG_DISPATCH_AS_IS
  111. | FLAG_DISPATCH_AS_OUTSIDE
  112. | FLAG_DISPATCH_AS_HOVER_ENTER
  113. | FLAG_DISPATCH_AS_HOVER_EXIT
  114. | FLAG_DISPATCH_AS_SLIPPERY_EXIT
  115. | FLAG_DISPATCH_AS_SLIPPERY_ENTER,
  116. /* This flag indicates that the target of a MotionEvent is partly or wholly
  117. * obscured by another visible window above it. The motion event should be
  118. * delivered with flag AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED. */
  119. FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 1 << 14,
  120. };
  121. // The input channel to be targeted.
  122. sp<InputChannel> inputChannel;
  123. // Flags for the input target.
  124. int32_t flags;
  125. // The x and y offset to add to a MotionEvent as it is delivered.
  126. // (ignored for KeyEvents)
  127. float xOffset, yOffset;
  128. // Scaling factor to apply to MotionEvent as it is delivered.
  129. // (ignored for KeyEvents)
  130. float scaleFactor;
  131. // The subset of pointer ids to include in motion events dispatched to this input target
  132. // if FLAG_SPLIT is set.
  133. BitSet32 pointerIds;
  134. };
  135. /*
  136. * Input dispatcher configuration.
  137. *
  138. * Specifies various options that modify the behavior of the input dispatcher.
  139. * The values provided here are merely defaults. The actual values will come from ViewConfiguration
  140. * and are passed into the dispatcher during initialization.
  141. */
  142. struct InputDispatcherConfiguration {
  143. // The key repeat initial timeout.
  144. nsecs_t keyRepeatTimeout;
  145. // The key repeat inter-key delay.
  146. nsecs_t keyRepeatDelay;
  147. InputDispatcherConfiguration() :
  148. keyRepeatTimeout(500 * 1000000LL),
  149. keyRepeatDelay(50 * 1000000LL) { }
  150. };
  151. /*
  152. * Input dispatcher policy interface.
  153. *
  154. * The input reader policy is used by the input reader to interact with the Window Manager
  155. * and other system components.
  156. *
  157. * The actual implementation is partially supported by callbacks into the DVM
  158. * via JNI. This interface is also mocked in the unit tests.
  159. */
  160. class InputDispatcherPolicyInterface : public virtual RefBase {
  161. protected:
  162. InputDispatcherPolicyInterface() { }
  163. virtual ~InputDispatcherPolicyInterface() { }
  164. public:
  165. /* Notifies the system that a configuration change has occurred. */
  166. virtual void notifyConfigurationChanged(nsecs_t when) = 0;
  167. /* Notifies the system that an application is not responding.
  168. * Returns a new timeout to continue waiting, or 0 to abort dispatch. */
  169. virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
  170. const sp<InputWindowHandle>& inputWindowHandle,
  171. const String8& reason) = 0;
  172. /* Notifies the system that an input channel is unrecoverably broken. */
  173. virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) = 0;
  174. /* Gets the input dispatcher configuration. */
  175. virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) = 0;
  176. /* Filters an input event.
  177. * Return true to dispatch the event unmodified, false to consume the event.
  178. * A filter can also transform and inject events later by passing POLICY_FLAG_FILTERED
  179. * to injectInputEvent.
  180. */
  181. virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) = 0;
  182. /* Intercepts a key event immediately before queueing it.
  183. * The policy can use this method as an opportunity to perform power management functions
  184. * and early event preprocessing such as updating policy flags.
  185. *
  186. * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event
  187. * should be dispatched to applications.
  188. */
  189. virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags) = 0;
  190. /* Intercepts a touch, trackball or other motion event before queueing it.
  191. * The policy can use this method as an opportunity to perform power management functions
  192. * and early event preprocessing such as updating policy flags.
  193. *
  194. * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event
  195. * should be dispatched to applications.
  196. */
  197. virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) = 0;
  198. /* Allows the policy a chance to intercept a key before dispatching. */
  199. virtual nsecs_t interceptKeyBeforeDispatching(const sp<InputWindowHandle>& inputWindowHandle,
  200. const KeyEvent* keyEvent, uint32_t policyFlags) = 0;
  201. /* Allows the policy a chance to perform default processing for an unhandled key.
  202. * Returns an alternate keycode to redispatch as a fallback, or 0 to give up. */
  203. virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
  204. const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) = 0;
  205. /* Notifies the policy about switch events.
  206. */
  207. virtual void notifySwitch(nsecs_t when,
  208. uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) = 0;
  209. /* Poke user activity for an event dispatched to a window. */
  210. virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType) = 0;
  211. /* Checks whether a given application pid/uid has permission to inject input events
  212. * into other applications.
  213. *
  214. * This method is special in that its implementation promises to be non-reentrant and
  215. * is safe to call while holding other locks. (Most other methods make no such guarantees!)
  216. */
  217. virtual bool checkInjectEventsPermissionNonReentrant(
  218. int32_t injectorPid, int32_t injectorUid) = 0;
  219. };
  220. /* Notifies the system about input events generated by the input reader.
  221. * The dispatcher is expected to be mostly asynchronous. */
  222. class InputDispatcherInterface : public virtual RefBase, public InputListenerInterface {
  223. protected:
  224. InputDispatcherInterface() { }
  225. virtual ~InputDispatcherInterface() { }
  226. public:
  227. /* Dumps the state of the input dispatcher.
  228. *
  229. * This method may be called on any thread (usually by the input manager). */
  230. virtual void dump(String8& dump) = 0;
  231. /* Called by the heatbeat to ensures that the dispatcher has not deadlocked. */
  232. virtual void monitor() = 0;
  233. /* Runs a single iteration of the dispatch loop.
  234. * Nominally processes one queued event, a timeout, or a response from an input consumer.
  235. *
  236. * This method should only be called on the input dispatcher thread.
  237. */
  238. virtual void dispatchOnce() = 0;
  239. /* Injects an input event and optionally waits for sync.
  240. * The synchronization mode determines whether the method blocks while waiting for
  241. * input injection to proceed.
  242. * Returns one of the INPUT_EVENT_INJECTION_XXX constants.
  243. *
  244. * This method may be called on any thread (usually by the input manager).
  245. */
  246. virtual int32_t injectInputEvent(const InputEvent* event, int32_t displayId,
  247. int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis,
  248. uint32_t policyFlags) = 0;
  249. /* Sets the list of input windows.
  250. *
  251. * This method may be called on any thread (usually by the input manager).
  252. */
  253. virtual void setInputWindows(const Vector<sp<InputWindowHandle> >& inputWindowHandles) = 0;
  254. /* Sets the focused application.
  255. *
  256. * This method may be called on any thread (usually by the input manager).
  257. */
  258. virtual void setFocusedApplication(
  259. const sp<InputApplicationHandle>& inputApplicationHandle) = 0;
  260. /* Sets the input dispatching mode.
  261. *
  262. * This method may be called on any thread (usually by the input manager).
  263. */
  264. virtual void setInputDispatchMode(bool enabled, bool frozen) = 0;
  265. /* Sets whether input event filtering is enabled.
  266. * When enabled, incoming input events are sent to the policy's filterInputEvent
  267. * method instead of being dispatched. The filter is expected to use
  268. * injectInputEvent to inject the events it would like to have dispatched.
  269. * It should include POLICY_FLAG_FILTERED in the policy flags during injection.
  270. */
  271. virtual void setInputFilterEnabled(bool enabled) = 0;
  272. /* Transfers touch focus from the window associated with one channel to the
  273. * window associated with the other channel.
  274. *
  275. * Returns true on success. False if the window did not actually have touch focus.
  276. */
  277. virtual bool transferTouchFocus(const sp<InputChannel>& fromChannel,
  278. const sp<InputChannel>& toChannel) = 0;
  279. /* Registers or unregister input channels that may be used as targets for input events.
  280. * If monitor is true, the channel will receive a copy of all input events.
  281. *
  282. * These methods may be called on any thread (usually by the input manager).
  283. */
  284. virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel,
  285. const sp<InputWindowHandle>& inputWindowHandle, bool monitor) = 0;
  286. virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel) = 0;
  287. };
  288. /* Dispatches events to input targets. Some functions of the input dispatcher, such as
  289. * identifying input targets, are controlled by a separate policy object.
  290. *
  291. * IMPORTANT INVARIANT:
  292. * Because the policy can potentially block or cause re-entrance into the input dispatcher,
  293. * the input dispatcher never calls into the policy while holding its internal locks.
  294. * The implementation is also carefully designed to recover from scenarios such as an
  295. * input channel becoming unregistered while identifying input targets or processing timeouts.
  296. *
  297. * Methods marked 'Locked' must be called with the lock acquired.
  298. *
  299. * Methods marked 'LockedInterruptible' must be called with the lock acquired but
  300. * may during the course of their execution release the lock, call into the policy, and
  301. * then reacquire the lock. The caller is responsible for recovering gracefully.
  302. *
  303. * A 'LockedInterruptible' method may called a 'Locked' method, but NOT vice-versa.
  304. */
  305. class InputDispatcher : public InputDispatcherInterface {
  306. protected:
  307. virtual ~InputDispatcher();
  308. public:
  309. explicit InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy);
  310. virtual void dump(String8& dump);
  311. virtual void monitor();
  312. virtual void dispatchOnce();
  313. virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args);
  314. virtual void notifyKey(const NotifyKeyArgs* args);
  315. virtual void notifyMotion(const NotifyMotionArgs* args);
  316. virtual void notifySwitch(const NotifySwitchArgs* args);
  317. virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args);
  318. virtual int32_t injectInputEvent(const InputEvent* event, int32_t displayId,
  319. int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis,
  320. uint32_t policyFlags);
  321. virtual void setInputWindows(const Vector<sp<InputWindowHandle> >& inputWindowHandles);
  322. virtual void setFocusedApplication(const sp<InputApplicationHandle>& inputApplicationHandle);
  323. virtual void setInputDispatchMode(bool enabled, bool frozen);
  324. virtual void setInputFilterEnabled(bool enabled);
  325. virtual bool transferTouchFocus(const sp<InputChannel>& fromChannel,
  326. const sp<InputChannel>& toChannel);
  327. virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel,
  328. const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
  329. virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel);
  330. private:
  331. template <typename T>
  332. struct Link {
  333. T* next;
  334. T* prev;
  335. protected:
  336. inline Link() : next(NULL), prev(NULL) { }
  337. };
  338. struct InjectionState {
  339. mutable int32_t refCount;
  340. int32_t injectorPid;
  341. int32_t injectorUid;
  342. int32_t injectionResult; // initially INPUT_EVENT_INJECTION_PENDING
  343. bool injectionIsAsync; // set to true if injection is not waiting for the result
  344. int32_t pendingForegroundDispatches; // the number of foreground dispatches in progress
  345. InjectionState(int32_t injectorPid, int32_t injectorUid);
  346. void release();
  347. private:
  348. ~InjectionState();
  349. };
  350. struct EventEntry : Link<EventEntry> {
  351. enum {
  352. TYPE_CONFIGURATION_CHANGED,
  353. TYPE_DEVICE_RESET,
  354. TYPE_KEY,
  355. TYPE_MOTION
  356. };
  357. mutable int32_t refCount;
  358. int32_t type;
  359. nsecs_t eventTime;
  360. uint32_t policyFlags;
  361. InjectionState* injectionState;
  362. bool dispatchInProgress; // initially false, set to true while dispatching
  363. inline bool isInjected() const { return injectionState != NULL; }
  364. void release();
  365. virtual void appendDescription(String8& msg) const = 0;
  366. protected:
  367. EventEntry(int32_t type, nsecs_t eventTime, uint32_t policyFlags);
  368. virtual ~EventEntry();
  369. void releaseInjectionState();
  370. };
  371. struct ConfigurationChangedEntry : EventEntry {
  372. ConfigurationChangedEntry(nsecs_t eventTime);
  373. virtual void appendDescription(String8& msg) const;
  374. protected:
  375. virtual ~ConfigurationChangedEntry();
  376. };
  377. struct DeviceResetEntry : EventEntry {
  378. int32_t deviceId;
  379. DeviceResetEntry(nsecs_t eventTime, int32_t deviceId);
  380. virtual void appendDescription(String8& msg) const;
  381. protected:
  382. virtual ~DeviceResetEntry();
  383. };
  384. struct KeyEntry : EventEntry {
  385. int32_t deviceId;
  386. uint32_t source;
  387. int32_t action;
  388. int32_t flags;
  389. int32_t keyCode;
  390. int32_t scanCode;
  391. int32_t metaState;
  392. int32_t repeatCount;
  393. nsecs_t downTime;
  394. bool syntheticRepeat; // set to true for synthetic key repeats
  395. enum InterceptKeyResult {
  396. INTERCEPT_KEY_RESULT_UNKNOWN,
  397. INTERCEPT_KEY_RESULT_SKIP,
  398. INTERCEPT_KEY_RESULT_CONTINUE,
  399. INTERCEPT_KEY_RESULT_TRY_AGAIN_LATER,
  400. };
  401. InterceptKeyResult interceptKeyResult; // set based on the interception result
  402. nsecs_t interceptKeyWakeupTime; // used with INTERCEPT_KEY_RESULT_TRY_AGAIN_LATER
  403. KeyEntry(nsecs_t eventTime,
  404. int32_t deviceId, uint32_t source, uint32_t policyFlags, int32_t action,
  405. int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState,
  406. int32_t repeatCount, nsecs_t downTime);
  407. virtual void appendDescription(String8& msg) const;
  408. void recycle();
  409. protected:
  410. virtual ~KeyEntry();
  411. };
  412. struct MotionEntry : EventEntry {
  413. nsecs_t eventTime;
  414. int32_t deviceId;
  415. uint32_t source;
  416. int32_t action;
  417. int32_t actionButton;
  418. int32_t flags;
  419. int32_t metaState;
  420. int32_t buttonState;
  421. int32_t edgeFlags;
  422. float xPrecision;
  423. float yPrecision;
  424. nsecs_t downTime;
  425. int32_t displayId;
  426. uint32_t pointerCount;
  427. PointerProperties pointerProperties[MAX_POINTERS];
  428. PointerCoords pointerCoords[MAX_POINTERS];
  429. MotionEntry(nsecs_t eventTime,
  430. int32_t deviceId, uint32_t source, uint32_t policyFlags,
  431. int32_t action, int32_t actionButton, int32_t flags,
  432. int32_t metaState, int32_t buttonState, int32_t edgeFlags,
  433. float xPrecision, float yPrecision, nsecs_t downTime,
  434. int32_t displayId, uint32_t pointerCount,
  435. const PointerProperties* pointerProperties, const PointerCoords* pointerCoords,
  436. float xOffset, float yOffset);
  437. virtual void appendDescription(String8& msg) const;
  438. protected:
  439. virtual ~MotionEntry();
  440. };
  441. // Tracks the progress of dispatching a particular event to a particular connection.
  442. struct DispatchEntry : Link<DispatchEntry> {
  443. const uint32_t seq; // unique sequence number, never 0
  444. EventEntry* eventEntry; // the event to dispatch
  445. int32_t targetFlags;
  446. float xOffset;
  447. float yOffset;
  448. float scaleFactor;
  449. nsecs_t deliveryTime; // time when the event was actually delivered
  450. // Set to the resolved action and flags when the event is enqueued.
  451. int32_t resolvedAction;
  452. int32_t resolvedFlags;
  453. DispatchEntry(EventEntry* eventEntry,
  454. int32_t targetFlags, float xOffset, float yOffset, float scaleFactor);
  455. ~DispatchEntry();
  456. inline bool hasForegroundTarget() const {
  457. return targetFlags & InputTarget::FLAG_FOREGROUND;
  458. }
  459. inline bool isSplit() const {
  460. return targetFlags & InputTarget::FLAG_SPLIT;
  461. }
  462. private:
  463. static volatile int32_t sNextSeqAtomic;
  464. static uint32_t nextSeq();
  465. };
  466. // A command entry captures state and behavior for an action to be performed in the
  467. // dispatch loop after the initial processing has taken place. It is essentially
  468. // a kind of continuation used to postpone sensitive policy interactions to a point
  469. // in the dispatch loop where it is safe to release the lock (generally after finishing
  470. // the critical parts of the dispatch cycle).
  471. //
  472. // The special thing about commands is that they can voluntarily release and reacquire
  473. // the dispatcher lock at will. Initially when the command starts running, the
  474. // dispatcher lock is held. However, if the command needs to call into the policy to
  475. // do some work, it can release the lock, do the work, then reacquire the lock again
  476. // before returning.
  477. //
  478. // This mechanism is a bit clunky but it helps to preserve the invariant that the dispatch
  479. // never calls into the policy while holding its lock.
  480. //
  481. // Commands are implicitly 'LockedInterruptible'.
  482. struct CommandEntry;
  483. typedef void (InputDispatcher::*Command)(CommandEntry* commandEntry);
  484. class Connection;
  485. struct CommandEntry : Link<CommandEntry> {
  486. CommandEntry(Command command);
  487. ~CommandEntry();
  488. Command command;
  489. // parameters for the command (usage varies by command)
  490. sp<Connection> connection;
  491. nsecs_t eventTime;
  492. KeyEntry* keyEntry;
  493. sp<InputApplicationHandle> inputApplicationHandle;
  494. sp<InputWindowHandle> inputWindowHandle;
  495. String8 reason;
  496. int32_t userActivityEventType;
  497. uint32_t seq;
  498. bool handled;
  499. };
  500. // Generic queue implementation.
  501. template <typename T>
  502. struct Queue {
  503. T* head;
  504. T* tail;
  505. uint32_t entryCount;
  506. inline Queue() : head(NULL), tail(NULL), entryCount(0) {
  507. }
  508. inline bool isEmpty() const {
  509. return !head;
  510. }
  511. inline void enqueueAtTail(T* entry) {
  512. entryCount++;
  513. entry->prev = tail;
  514. if (tail) {
  515. tail->next = entry;
  516. } else {
  517. head = entry;
  518. }
  519. entry->next = NULL;
  520. tail = entry;
  521. }
  522. inline void enqueueAtHead(T* entry) {
  523. entryCount++;
  524. entry->next = head;
  525. if (head) {
  526. head->prev = entry;
  527. } else {
  528. tail = entry;
  529. }
  530. entry->prev = NULL;
  531. head = entry;
  532. }
  533. inline void dequeue(T* entry) {
  534. entryCount--;
  535. if (entry->prev) {
  536. entry->prev->next = entry->next;
  537. } else {
  538. head = entry->next;
  539. }
  540. if (entry->next) {
  541. entry->next->prev = entry->prev;
  542. } else {
  543. tail = entry->prev;
  544. }
  545. }
  546. inline T* dequeueAtHead() {
  547. entryCount--;
  548. T* entry = head;
  549. head = entry->next;
  550. if (head) {
  551. head->prev = NULL;
  552. } else {
  553. tail = NULL;
  554. }
  555. return entry;
  556. }
  557. uint32_t count() const {
  558. return entryCount;
  559. }
  560. };
  561. /* Specifies which events are to be canceled and why. */
  562. struct CancelationOptions {
  563. enum Mode {
  564. CANCEL_ALL_EVENTS = 0,
  565. CANCEL_POINTER_EVENTS = 1,
  566. CANCEL_NON_POINTER_EVENTS = 2,
  567. CANCEL_FALLBACK_EVENTS = 3,
  568. };
  569. // The criterion to use to determine which events should be canceled.
  570. Mode mode;
  571. // Descriptive reason for the cancelation.
  572. const char* reason;
  573. // The specific keycode of the key event to cancel, or -1 to cancel any key event.
  574. int32_t keyCode;
  575. // The specific device id of events to cancel, or -1 to cancel events from any device.
  576. int32_t deviceId;
  577. CancelationOptions(Mode mode, const char* reason) :
  578. mode(mode), reason(reason), keyCode(-1), deviceId(-1) { }
  579. };
  580. /* Tracks dispatched key and motion event state so that cancelation events can be
  581. * synthesized when events are dropped. */
  582. class InputState {
  583. public:
  584. InputState();
  585. ~InputState();
  586. // Returns true if there is no state to be canceled.
  587. bool isNeutral() const;
  588. // Returns true if the specified source is known to have received a hover enter
  589. // motion event.
  590. bool isHovering(int32_t deviceId, uint32_t source, int32_t displayId) const;
  591. // Records tracking information for a key event that has just been published.
  592. // Returns true if the event should be delivered, false if it is inconsistent
  593. // and should be skipped.
  594. bool trackKey(const KeyEntry* entry, int32_t action, int32_t flags);
  595. // Records tracking information for a motion event that has just been published.
  596. // Returns true if the event should be delivered, false if it is inconsistent
  597. // and should be skipped.
  598. bool trackMotion(const MotionEntry* entry, int32_t action, int32_t flags);
  599. // Synthesizes cancelation events for the current state and resets the tracked state.
  600. void synthesizeCancelationEvents(nsecs_t currentTime,
  601. Vector<EventEntry*>& outEvents, const CancelationOptions& options);
  602. // Clears the current state.
  603. void clear();
  604. // Copies pointer-related parts of the input state to another instance.
  605. void copyPointerStateTo(InputState& other) const;
  606. // Gets the fallback key associated with a keycode.
  607. // Returns -1 if none.
  608. // Returns AKEYCODE_UNKNOWN if we are only dispatching the unhandled key to the policy.
  609. int32_t getFallbackKey(int32_t originalKeyCode);
  610. // Sets the fallback key for a particular keycode.
  611. void setFallbackKey(int32_t originalKeyCode, int32_t fallbackKeyCode);
  612. // Removes the fallback key for a particular keycode.
  613. void removeFallbackKey(int32_t originalKeyCode);
  614. inline const KeyedVector<int32_t, int32_t>& getFallbackKeys() const {
  615. return mFallbackKeys;
  616. }
  617. private:
  618. struct KeyMemento {
  619. int32_t deviceId;
  620. uint32_t source;
  621. int32_t keyCode;
  622. int32_t scanCode;
  623. int32_t metaState;
  624. int32_t flags;
  625. nsecs_t downTime;
  626. uint32_t policyFlags;
  627. };
  628. struct MotionMemento {
  629. int32_t deviceId;
  630. uint32_t source;
  631. int32_t flags;
  632. float xPrecision;
  633. float yPrecision;
  634. nsecs_t downTime;
  635. int32_t displayId;
  636. uint32_t pointerCount;
  637. PointerProperties pointerProperties[MAX_POINTERS];
  638. PointerCoords pointerCoords[MAX_POINTERS];
  639. bool hovering;
  640. uint32_t policyFlags;
  641. void setPointers(const MotionEntry* entry);
  642. };
  643. Vector<KeyMemento> mKeyMementos;
  644. Vector<MotionMemento> mMotionMementos;
  645. KeyedVector<int32_t, int32_t> mFallbackKeys;
  646. ssize_t findKeyMemento(const KeyEntry* entry) const;
  647. ssize_t findMotionMemento(const MotionEntry* entry, bool hovering) const;
  648. void addKeyMemento(const KeyEntry* entry, int32_t flags);
  649. void addMotionMemento(const MotionEntry* entry, int32_t flags, bool hovering);
  650. static bool shouldCancelKey(const KeyMemento& memento,
  651. const CancelationOptions& options);
  652. static bool shouldCancelMotion(const MotionMemento& memento,
  653. const CancelationOptions& options);
  654. };
  655. /* Manages the dispatch state associated with a single input channel. */
  656. class Connection : public RefBase {
  657. protected:
  658. virtual ~Connection();
  659. public:
  660. enum Status {
  661. // Everything is peachy.
  662. STATUS_NORMAL,
  663. // An unrecoverable communication error has occurred.
  664. STATUS_BROKEN,
  665. // The input channel has been unregistered.
  666. STATUS_ZOMBIE
  667. };
  668. Status status;
  669. sp<InputChannel> inputChannel; // never null
  670. sp<InputWindowHandle> inputWindowHandle; // may be null
  671. bool monitor;
  672. InputPublisher inputPublisher;
  673. InputState inputState;
  674. // True if the socket is full and no further events can be published until
  675. // the application consumes some of the input.
  676. bool inputPublisherBlocked;
  677. // Queue of events that need to be published to the connection.
  678. Queue<DispatchEntry> outboundQueue;
  679. // Queue of events that have been published to the connection but that have not
  680. // yet received a "finished" response from the application.
  681. Queue<DispatchEntry> waitQueue;
  682. explicit Connection(const sp<InputChannel>& inputChannel,
  683. const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
  684. inline const char* getInputChannelName() const { return inputChannel->getName().string(); }
  685. const char* getWindowName() const;
  686. const char* getStatusLabel() const;
  687. DispatchEntry* findWaitQueueEntry(uint32_t seq);
  688. };
  689. enum DropReason {
  690. DROP_REASON_NOT_DROPPED = 0,
  691. DROP_REASON_POLICY = 1,
  692. DROP_REASON_APP_SWITCH = 2,
  693. DROP_REASON_DISABLED = 3,
  694. DROP_REASON_BLOCKED = 4,
  695. DROP_REASON_STALE = 5,
  696. };
  697. sp<InputDispatcherPolicyInterface> mPolicy;
  698. InputDispatcherConfiguration mConfig;
  699. Mutex mLock;
  700. Condition mDispatcherIsAliveCondition;
  701. sp<Looper> mLooper;
  702. EventEntry* mPendingEvent;
  703. Queue<EventEntry> mInboundQueue;
  704. Queue<EventEntry> mRecentQueue;
  705. Queue<CommandEntry> mCommandQueue;
  706. DropReason mLastDropReason;
  707. void dispatchOnceInnerLocked(nsecs_t* nextWakeupTime);
  708. // Enqueues an inbound event. Returns true if mLooper->wake() should be called.
  709. bool enqueueInboundEventLocked(EventEntry* entry);
  710. // Cleans up input state when dropping an inbound event.
  711. void dropInboundEventLocked(EventEntry* entry, DropReason dropReason);
  712. // Adds an event to a queue of recent events for debugging purposes.
  713. void addRecentEventLocked(EventEntry* entry);
  714. // App switch latency optimization.
  715. bool mAppSwitchSawKeyDown;
  716. nsecs_t mAppSwitchDueTime;
  717. static bool isAppSwitchKeyCode(int32_t keyCode);
  718. bool isAppSwitchKeyEventLocked(KeyEntry* keyEntry);
  719. bool isAppSwitchPendingLocked();
  720. void resetPendingAppSwitchLocked(bool handled);
  721. // Stale event latency optimization.
  722. static bool isStaleEventLocked(nsecs_t currentTime, EventEntry* entry);
  723. // Blocked event latency optimization. Drops old events when the user intends
  724. // to transfer focus to a new application.
  725. EventEntry* mNextUnblockedEvent;
  726. sp<InputWindowHandle> findTouchedWindowAtLocked(int32_t displayId, int32_t x, int32_t y);
  727. // All registered connections mapped by channel file descriptor.
  728. KeyedVector<int, sp<Connection> > mConnectionsByFd;
  729. ssize_t getConnectionIndexLocked(const sp<InputChannel>& inputChannel);
  730. // Input channels that will receive a copy of all input events.
  731. Vector<sp<InputChannel> > mMonitoringChannels;
  732. // Event injection and synchronization.
  733. Condition mInjectionResultAvailableCondition;
  734. bool hasInjectionPermission(int32_t injectorPid, int32_t injectorUid);
  735. void setInjectionResultLocked(EventEntry* entry, int32_t injectionResult);
  736. Condition mInjectionSyncFinishedCondition;
  737. void incrementPendingForegroundDispatchesLocked(EventEntry* entry);
  738. void decrementPendingForegroundDispatchesLocked(EventEntry* entry);
  739. // Key repeat tracking.
  740. struct KeyRepeatState {
  741. KeyEntry* lastKeyEntry; // or null if no repeat
  742. nsecs_t nextRepeatTime;
  743. } mKeyRepeatState;
  744. void resetKeyRepeatLocked();
  745. KeyEntry* synthesizeKeyRepeatLocked(nsecs_t currentTime);
  746. // Key replacement tracking
  747. struct KeyReplacement {
  748. int32_t keyCode;
  749. int32_t deviceId;
  750. bool operator==(const KeyReplacement& rhs) const {
  751. return keyCode == rhs.keyCode && deviceId == rhs.deviceId;
  752. }
  753. bool operator<(const KeyReplacement& rhs) const {
  754. return keyCode != rhs.keyCode ? keyCode < rhs.keyCode : deviceId < rhs.deviceId;
  755. }
  756. };
  757. // Maps the key code replaced, device id tuple to the key code it was replaced with
  758. KeyedVector<KeyReplacement, int32_t> mReplacedKeys;
  759. // Deferred command processing.
  760. bool haveCommandsLocked() const;
  761. bool runCommandsLockedInterruptible();
  762. CommandEntry* postCommandLocked(Command command);
  763. // Input filter processing.
  764. bool shouldSendKeyToInputFilterLocked(const NotifyKeyArgs* args);
  765. bool shouldSendMotionToInputFilterLocked(const NotifyMotionArgs* args);
  766. // Inbound event processing.
  767. void drainInboundQueueLocked();
  768. void releasePendingEventLocked();
  769. void releaseInboundEventLocked(EventEntry* entry);
  770. // Dispatch state.
  771. bool mDispatchEnabled;
  772. bool mDispatchFrozen;
  773. bool mInputFilterEnabled;
  774. Vector<sp<InputWindowHandle> > mWindowHandles;
  775. sp<InputWindowHandle> getWindowHandleLocked(const sp<InputChannel>& inputChannel) const;
  776. bool hasWindowHandleLocked(const sp<InputWindowHandle>& windowHandle) const;
  777. // Focus tracking for keys, trackball, etc.
  778. sp<InputWindowHandle> mFocusedWindowHandle;
  779. // Focus tracking for touch.
  780. struct TouchedWindow {
  781. sp<InputWindowHandle> windowHandle;
  782. int32_t targetFlags;
  783. BitSet32 pointerIds; // zero unless target flag FLAG_SPLIT is set
  784. };
  785. struct TouchState {
  786. bool down;
  787. bool split;
  788. int32_t deviceId; // id of the device that is currently down, others are rejected
  789. uint32_t source; // source of the device that is current down, others are rejected
  790. int32_t displayId; // id to the display that currently has a touch, others are rejected
  791. Vector<TouchedWindow> windows;
  792. TouchState();
  793. ~TouchState();
  794. void reset();
  795. void copyFrom(const TouchState& other);
  796. void addOrUpdateWindow(const sp<InputWindowHandle>& windowHandle,
  797. int32_t targetFlags, BitSet32 pointerIds);
  798. void removeWindow(const sp<InputWindowHandle>& windowHandle);
  799. void filterNonAsIsTouchWindows();
  800. sp<InputWindowHandle> getFirstForegroundWindowHandle() const;
  801. bool isSlippery() const;
  802. };
  803. KeyedVector<int32_t, TouchState> mTouchStatesByDisplay;
  804. TouchState mTempTouchState;
  805. // Focused application.
  806. sp<InputApplicationHandle> mFocusedApplicationHandle;
  807. // Dispatcher state at time of last ANR.
  808. String8 mLastANRState;
  809. // Dispatch inbound events.
  810. bool dispatchConfigurationChangedLocked(
  811. nsecs_t currentTime, ConfigurationChangedEntry* entry);
  812. bool dispatchDeviceResetLocked(
  813. nsecs_t currentTime, DeviceResetEntry* entry);
  814. bool dispatchKeyLocked(
  815. nsecs_t currentTime, KeyEntry* entry,
  816. DropReason* dropReason, nsecs_t* nextWakeupTime);
  817. bool dispatchMotionLocked(
  818. nsecs_t currentTime, MotionEntry* entry,
  819. DropReason* dropReason, nsecs_t* nextWakeupTime);
  820. void dispatchEventLocked(nsecs_t currentTime, EventEntry* entry,
  821. const Vector<InputTarget>& inputTargets);
  822. void logOutboundKeyDetailsLocked(const char* prefix, const KeyEntry* entry);
  823. void logOutboundMotionDetailsLocked(const char* prefix, const MotionEntry* entry);
  824. // Keeping track of ANR timeouts.
  825. enum InputTargetWaitCause {
  826. INPUT_TARGET_WAIT_CAUSE_NONE,
  827. INPUT_TARGET_WAIT_CAUSE_SYSTEM_NOT_READY,
  828. INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY,
  829. };
  830. InputTargetWaitCause mInputTargetWaitCause;
  831. nsecs_t mInputTargetWaitStartTime;
  832. nsecs_t mInputTargetWaitTimeoutTime;
  833. bool mInputTargetWaitTimeoutExpired;
  834. sp<InputApplicationHandle> mInputTargetWaitApplicationHandle;
  835. // Contains the last window which received a hover event.
  836. sp<InputWindowHandle> mLastHoverWindowHandle;
  837. // Finding targets for input events.
  838. int32_t handleTargetsNotReadyLocked(nsecs_t currentTime, const EventEntry* entry,
  839. const sp<InputApplicationHandle>& applicationHandle,
  840. const sp<InputWindowHandle>& windowHandle,
  841. nsecs_t* nextWakeupTime, const char* reason);
  842. void resumeAfterTargetsNotReadyTimeoutLocked(nsecs_t newTimeout,
  843. const sp<InputChannel>& inputChannel);
  844. nsecs_t getTimeSpentWaitingForApplicationLocked(nsecs_t currentTime);
  845. void resetANRTimeoutsLocked();
  846. int32_t findFocusedWindowTargetsLocked(nsecs_t currentTime, const EventEntry* entry,
  847. Vector<InputTarget>& inputTargets, nsecs_t* nextWakeupTime);
  848. int32_t findTouchedWindowTargetsLocked(nsecs_t currentTime, const MotionEntry* entry,
  849. Vector<InputTarget>& inputTargets, nsecs_t* nextWakeupTime,
  850. bool* outConflictingPointerActions);
  851. void addWindowTargetLocked(const sp<InputWindowHandle>& windowHandle,
  852. int32_t targetFlags, BitSet32 pointerIds, Vector<InputTarget>& inputTargets);
  853. void addMonitoringTargetsLocked(Vector<InputTarget>& inputTargets);
  854. void pokeUserActivityLocked(const EventEntry* eventEntry);
  855. bool checkInjectionPermission(const sp<InputWindowHandle>& windowHandle,
  856. const InjectionState* injectionState);
  857. bool isWindowObscuredAtPointLocked(const sp<InputWindowHandle>& windowHandle,
  858. int32_t x, int32_t y) const;
  859. bool isWindowObscuredLocked(const sp<InputWindowHandle>& windowHandle) const;
  860. String8 getApplicationWindowLabelLocked(const sp<InputApplicationHandle>& applicationHandle,
  861. const sp<InputWindowHandle>& windowHandle);
  862. String8 checkWindowReadyForMoreInputLocked(nsecs_t currentTime,
  863. const sp<InputWindowHandle>& windowHandle, const EventEntry* eventEntry,
  864. const char* targetType);
  865. // Manage the dispatch cycle for a single connection.
  866. // These methods are deliberately not Interruptible because doing all of the work
  867. // with the mutex held makes it easier to ensure that connection invariants are maintained.
  868. // If needed, the methods post commands to run later once the critical bits are done.
  869. void prepareDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection,
  870. EventEntry* eventEntry, const InputTarget* inputTarget);
  871. void enqueueDispatchEntriesLocked(nsecs_t currentTime, const sp<Connection>& connection,
  872. EventEntry* eventEntry, const InputTarget* inputTarget);
  873. void enqueueDispatchEntryLocked(const sp<Connection>& connection,
  874. EventEntry* eventEntry, const InputTarget* inputTarget, int32_t dispatchMode);
  875. void startDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection);
  876. void finishDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection,
  877. uint32_t seq, bool handled);
  878. void abortBrokenDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection,
  879. bool notify);
  880. void drainDispatchQueueLocked(Queue<DispatchEntry>* queue);
  881. void releaseDispatchEntryLocked(DispatchEntry* dispatchEntry);
  882. static int handleReceiveCallback(int fd, int events, void* data);
  883. void synthesizeCancelationEventsForAllConnectionsLocked(
  884. const CancelationOptions& options);
  885. void synthesizeCancelationEventsForMonitorsLocked(const CancelationOptions& options);
  886. void synthesizeCancelationEventsForInputChannelLocked(const sp<InputChannel>& channel,
  887. const CancelationOptions& options);
  888. void synthesizeCancelationEventsForConnectionLocked(const sp<Connection>& connection,
  889. const CancelationOptions& options);
  890. // Splitting motion events across windows.
  891. MotionEntry* splitMotionEvent(const MotionEntry* originalMotionEntry, BitSet32 pointerIds);
  892. // Reset and drop everything the dispatcher is doing.
  893. void resetAndDropEverythingLocked(const char* reason);
  894. // Dump state.
  895. void dumpDispatchStateLocked(String8& dump);
  896. void logDispatchStateLocked();
  897. // Registration.
  898. void removeMonitorChannelLocked(const sp<InputChannel>& inputChannel);
  899. status_t unregisterInputChannelLocked(const sp<InputChannel>& inputChannel, bool notify);
  900. // Add or remove a connection to the mActiveConnections vector.
  901. void activateConnectionLocked(Connection* connection);
  902. void deactivateConnectionLocked(Connection* connection);
  903. // Interesting events that we might like to log or tell the framework about.
  904. void onDispatchCycleFinishedLocked(
  905. nsecs_t currentTime, const sp<Connection>& connection, uint32_t seq, bool handled);
  906. void onDispatchCycleBrokenLocked(
  907. nsecs_t currentTime, const sp<Connection>& connection);
  908. void onANRLocked(
  909. nsecs_t currentTime, const sp<InputApplicationHandle>& applicationHandle,
  910. const sp<InputWindowHandle>& windowHandle,
  911. nsecs_t eventTime, nsecs_t waitStartTime, const char* reason);
  912. // Outbound policy interactions.
  913. void doNotifyConfigurationChangedInterruptible(CommandEntry* commandEntry);
  914. void doNotifyInputChannelBrokenLockedInterruptible(CommandEntry* commandEntry);
  915. void doNotifyANRLockedInterruptible(CommandEntry* commandEntry);
  916. void doInterceptKeyBeforeDispatchingLockedInterruptible(CommandEntry* commandEntry);
  917. void doDispatchCycleFinishedLockedInterruptible(CommandEntry* commandEntry);
  918. bool afterKeyEventLockedInterruptible(const sp<Connection>& connection,
  919. DispatchEntry* dispatchEntry, KeyEntry* keyEntry, bool handled);
  920. bool afterMotionEventLockedInterruptible(const sp<Connection>& connection,
  921. DispatchEntry* dispatchEntry, MotionEntry* motionEntry, bool handled);
  922. void doPokeUserActivityLockedInterruptible(CommandEntry* commandEntry);
  923. void initializeKeyEvent(KeyEvent* event, const KeyEntry* entry);
  924. // Statistics gathering.
  925. void updateDispatchStatisticsLocked(nsecs_t currentTime, const EventEntry* entry,
  926. int32_t injectionResult, nsecs_t timeSpentWaitingForApplication);
  927. void traceInboundQueueLengthLocked();
  928. void traceOutboundQueueLengthLocked(const sp<Connection>& connection);
  929. void traceWaitQueueLengthLocked(const sp<Connection>& connection);
  930. };
  931. /* Enqueues and dispatches input events, endlessly. */
  932. class InputDispatcherThread : public Thread {
  933. public:
  934. explicit InputDispatcherThread(const sp<InputDispatcherInterface>& dispatcher);
  935. ~InputDispatcherThread();
  936. private:
  937. virtual bool threadLoop();
  938. sp<InputDispatcherInterface> mDispatcher;
  939. };
  940. } // namespace android
  941. #endif // _UI_INPUT_DISPATCHER_H