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