Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [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 <ui/Input.h> |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 21 | #include <ui/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> |
| 27 | #include <utils/String8.h> |
Jeff Brown | 59abe7e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 28 | #include <utils/Looper.h> |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 29 | #include <utils/Pool.h> |
| 30 | |
| 31 | #include <stddef.h> |
| 32 | #include <unistd.h> |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 33 | #include <limits.h> |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 34 | |
| 35 | |
| 36 | namespace android { |
| 37 | |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 38 | /* |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 39 | * Constants used to report the outcome of input event injection. |
| 40 | */ |
| 41 | enum { |
| 42 | /* (INTERNAL USE ONLY) Specifies that injection is pending and its outcome is unknown. */ |
| 43 | INPUT_EVENT_INJECTION_PENDING = -1, |
| 44 | |
| 45 | /* Injection succeeded. */ |
| 46 | INPUT_EVENT_INJECTION_SUCCEEDED = 0, |
| 47 | |
| 48 | /* Injection failed because the injector did not have permission to inject |
| 49 | * into the application with input focus. */ |
| 50 | INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1, |
| 51 | |
| 52 | /* Injection failed because there were no available input targets. */ |
| 53 | INPUT_EVENT_INJECTION_FAILED = 2, |
| 54 | |
| 55 | /* Injection failed due to a timeout. */ |
| 56 | INPUT_EVENT_INJECTION_TIMED_OUT = 3 |
| 57 | }; |
| 58 | |
Jeff Brown | f67c53e | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 59 | /* |
| 60 | * Constants used to determine the input event injection synchronization mode. |
| 61 | */ |
| 62 | enum { |
| 63 | /* Injection is asynchronous and is assumed always to be successful. */ |
| 64 | INPUT_EVENT_INJECTION_SYNC_NONE = 0, |
| 65 | |
| 66 | /* Waits for previous events to be dispatched so that the input dispatcher can determine |
| 67 | * whether input event injection willbe permitted based on the current input focus. |
| 68 | * Does not wait for the input event to finish processing. */ |
| 69 | INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT = 1, |
| 70 | |
| 71 | /* Waits for the input event to be completely processed. */ |
| 72 | INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISHED = 2, |
| 73 | }; |
| 74 | |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 75 | |
| 76 | /* |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 77 | * An input target specifies how an input event is to be dispatched to a particular window |
| 78 | * including the window's input channel, control flags, a timeout, and an X / Y offset to |
| 79 | * be added to input event coordinates to compensate for the absolute position of the |
| 80 | * window area. |
| 81 | */ |
| 82 | struct InputTarget { |
| 83 | enum { |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 84 | /* This flag indicates that the event is being delivered to a foreground application. */ |
| 85 | FLAG_FOREGROUND = 0x01, |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 86 | |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 87 | /* This flag indicates that a MotionEvent with AMOTION_EVENT_ACTION_DOWN falls outside |
| 88 | * of the area of this target and so should instead be delivered as an |
| 89 | * AMOTION_EVENT_ACTION_OUTSIDE to this target. */ |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 90 | FLAG_OUTSIDE = 0x02, |
| 91 | |
| 92 | /* This flag indicates that a KeyEvent or MotionEvent is being canceled. |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 93 | * In the case of a key event, it should be delivered with flag |
| 94 | * AKEY_EVENT_FLAG_CANCELED set. |
| 95 | * In the case of a motion event, it should be delivered with action |
| 96 | * AMOTION_EVENT_ACTION_CANCEL instead. */ |
| 97 | FLAG_CANCEL = 0x04, |
| 98 | |
| 99 | /* This flag indicates that the target of a MotionEvent is partly or wholly |
| 100 | * obscured by another visible window above it. The motion event should be |
| 101 | * delivered with flag AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED. */ |
| 102 | FLAG_WINDOW_IS_OBSCURED = 0x08, |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | // The input channel to be targeted. |
| 106 | sp<InputChannel> inputChannel; |
| 107 | |
| 108 | // Flags for the input target. |
| 109 | int32_t flags; |
| 110 | |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 111 | // The x and y offset to add to a MotionEvent as it is delivered. |
| 112 | // (ignored for KeyEvents) |
| 113 | float xOffset, yOffset; |
| 114 | }; |
| 115 | |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 116 | |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 117 | /* |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 118 | * An input window describes the bounds of a window that can receive input. |
| 119 | */ |
| 120 | struct InputWindow { |
| 121 | // Window flags from WindowManager.LayoutParams |
| 122 | enum { |
| 123 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001, |
| 124 | FLAG_DIM_BEHIND = 0x00000002, |
| 125 | FLAG_BLUR_BEHIND = 0x00000004, |
| 126 | FLAG_NOT_FOCUSABLE = 0x00000008, |
| 127 | FLAG_NOT_TOUCHABLE = 0x00000010, |
| 128 | FLAG_NOT_TOUCH_MODAL = 0x00000020, |
| 129 | FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040, |
| 130 | FLAG_KEEP_SCREEN_ON = 0x00000080, |
| 131 | FLAG_LAYOUT_IN_SCREEN = 0x00000100, |
| 132 | FLAG_LAYOUT_NO_LIMITS = 0x00000200, |
| 133 | FLAG_FULLSCREEN = 0x00000400, |
| 134 | FLAG_FORCE_NOT_FULLSCREEN = 0x00000800, |
| 135 | FLAG_DITHER = 0x00001000, |
| 136 | FLAG_SECURE = 0x00002000, |
| 137 | FLAG_SCALED = 0x00004000, |
| 138 | FLAG_IGNORE_CHEEK_PRESSES = 0x00008000, |
| 139 | FLAG_LAYOUT_INSET_DECOR = 0x00010000, |
| 140 | FLAG_ALT_FOCUSABLE_IM = 0x00020000, |
| 141 | FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000, |
| 142 | FLAG_SHOW_WHEN_LOCKED = 0x00080000, |
| 143 | FLAG_SHOW_WALLPAPER = 0x00100000, |
| 144 | FLAG_TURN_SCREEN_ON = 0x00200000, |
| 145 | FLAG_DISMISS_KEYGUARD = 0x00400000, |
| 146 | FLAG_IMMERSIVE = 0x00800000, |
| 147 | FLAG_KEEP_SURFACE_WHILE_ANIMATING = 0x10000000, |
| 148 | FLAG_COMPATIBLE_WINDOW = 0x20000000, |
| 149 | FLAG_SYSTEM_ERROR = 0x40000000, |
| 150 | }; |
| 151 | |
| 152 | // Window types from WindowManager.LayoutParams |
| 153 | enum { |
| 154 | FIRST_APPLICATION_WINDOW = 1, |
| 155 | TYPE_BASE_APPLICATION = 1, |
| 156 | TYPE_APPLICATION = 2, |
| 157 | TYPE_APPLICATION_STARTING = 3, |
| 158 | LAST_APPLICATION_WINDOW = 99, |
| 159 | FIRST_SUB_WINDOW = 1000, |
| 160 | TYPE_APPLICATION_PANEL = FIRST_SUB_WINDOW, |
| 161 | TYPE_APPLICATION_MEDIA = FIRST_SUB_WINDOW+1, |
| 162 | TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW+2, |
| 163 | TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW+3, |
| 164 | TYPE_APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW+4, |
| 165 | LAST_SUB_WINDOW = 1999, |
| 166 | FIRST_SYSTEM_WINDOW = 2000, |
| 167 | TYPE_STATUS_BAR = FIRST_SYSTEM_WINDOW, |
| 168 | TYPE_SEARCH_BAR = FIRST_SYSTEM_WINDOW+1, |
| 169 | TYPE_PHONE = FIRST_SYSTEM_WINDOW+2, |
| 170 | TYPE_SYSTEM_ALERT = FIRST_SYSTEM_WINDOW+3, |
| 171 | TYPE_KEYGUARD = FIRST_SYSTEM_WINDOW+4, |
| 172 | TYPE_TOAST = FIRST_SYSTEM_WINDOW+5, |
| 173 | TYPE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW+6, |
| 174 | TYPE_PRIORITY_PHONE = FIRST_SYSTEM_WINDOW+7, |
| 175 | TYPE_SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW+8, |
| 176 | TYPE_KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW+9, |
| 177 | TYPE_SYSTEM_ERROR = FIRST_SYSTEM_WINDOW+10, |
| 178 | TYPE_INPUT_METHOD = FIRST_SYSTEM_WINDOW+11, |
| 179 | TYPE_INPUT_METHOD_DIALOG= FIRST_SYSTEM_WINDOW+12, |
| 180 | TYPE_WALLPAPER = FIRST_SYSTEM_WINDOW+13, |
| 181 | TYPE_STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW+14, |
| 182 | LAST_SYSTEM_WINDOW = 2999, |
| 183 | }; |
| 184 | |
| 185 | sp<InputChannel> inputChannel; |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 186 | String8 name; |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 187 | int32_t layoutParamsFlags; |
| 188 | int32_t layoutParamsType; |
| 189 | nsecs_t dispatchingTimeout; |
| 190 | int32_t frameLeft; |
| 191 | int32_t frameTop; |
| 192 | int32_t frameRight; |
| 193 | int32_t frameBottom; |
| 194 | int32_t visibleFrameLeft; |
| 195 | int32_t visibleFrameTop; |
| 196 | int32_t visibleFrameRight; |
| 197 | int32_t visibleFrameBottom; |
| 198 | int32_t touchableAreaLeft; |
| 199 | int32_t touchableAreaTop; |
| 200 | int32_t touchableAreaRight; |
| 201 | int32_t touchableAreaBottom; |
| 202 | bool visible; |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 203 | bool canReceiveKeys; |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 204 | bool hasFocus; |
| 205 | bool hasWallpaper; |
| 206 | bool paused; |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 207 | int32_t layer; |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 208 | int32_t ownerPid; |
| 209 | int32_t ownerUid; |
| 210 | |
| 211 | bool visibleFrameIntersects(const InputWindow* other) const; |
| 212 | bool touchableAreaContainsPoint(int32_t x, int32_t y) const; |
| 213 | }; |
| 214 | |
| 215 | |
| 216 | /* |
| 217 | * A private handle type used by the input manager to track the window. |
| 218 | */ |
| 219 | class InputApplicationHandle : public RefBase { |
| 220 | protected: |
| 221 | InputApplicationHandle() { } |
| 222 | virtual ~InputApplicationHandle() { } |
| 223 | }; |
| 224 | |
| 225 | |
| 226 | /* |
| 227 | * An input application describes properties of an application that can receive input. |
| 228 | */ |
| 229 | struct InputApplication { |
| 230 | String8 name; |
| 231 | nsecs_t dispatchingTimeout; |
| 232 | sp<InputApplicationHandle> handle; |
| 233 | }; |
| 234 | |
| 235 | |
| 236 | /* |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 237 | * Input dispatcher policy interface. |
| 238 | * |
| 239 | * The input reader policy is used by the input reader to interact with the Window Manager |
| 240 | * and other system components. |
| 241 | * |
| 242 | * The actual implementation is partially supported by callbacks into the DVM |
| 243 | * via JNI. This interface is also mocked in the unit tests. |
| 244 | */ |
| 245 | class InputDispatcherPolicyInterface : public virtual RefBase { |
| 246 | protected: |
| 247 | InputDispatcherPolicyInterface() { } |
| 248 | virtual ~InputDispatcherPolicyInterface() { } |
| 249 | |
| 250 | public: |
| 251 | /* Notifies the system that a configuration change has occurred. */ |
| 252 | virtual void notifyConfigurationChanged(nsecs_t when) = 0; |
| 253 | |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 254 | /* Notifies the system that an application is not responding. |
| 255 | * Returns a new timeout to continue waiting, or 0 to abort dispatch. */ |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 256 | virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle, |
| 257 | const sp<InputChannel>& inputChannel) = 0; |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 258 | |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 259 | /* Notifies the system that an input channel is unrecoverably broken. */ |
| 260 | virtual void notifyInputChannelBroken(const sp<InputChannel>& inputChannel) = 0; |
| 261 | |
Jeff Brown | 61ce398 | 2010-09-07 10:44:57 -0700 | [diff] [blame] | 262 | /* Gets the key repeat initial timeout or -1 if automatic key repeating is disabled. */ |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 263 | virtual nsecs_t getKeyRepeatTimeout() = 0; |
| 264 | |
Jeff Brown | 61ce398 | 2010-09-07 10:44:57 -0700 | [diff] [blame] | 265 | /* Gets the key repeat inter-key delay. */ |
| 266 | virtual nsecs_t getKeyRepeatDelay() = 0; |
| 267 | |
Jeff Brown | 542412c | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 268 | /* Gets the maximum suggested event delivery rate per second. |
| 269 | * This value is used to throttle motion event movement actions on a per-device |
| 270 | * basis. It is not intended to be a hard limit. |
| 271 | */ |
| 272 | virtual int32_t getMaxEventsPerSecond() = 0; |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 273 | |
| 274 | /* Allows the policy a chance to intercept a key before dispatching. */ |
| 275 | virtual bool interceptKeyBeforeDispatching(const sp<InputChannel>& inputChannel, |
| 276 | const KeyEvent* keyEvent, uint32_t policyFlags) = 0; |
| 277 | |
| 278 | /* Poke user activity for an event dispatched to a window. */ |
| 279 | virtual void pokeUserActivity(nsecs_t eventTime, int32_t windowType, int32_t eventType) = 0; |
| 280 | |
| 281 | /* Checks whether a given application pid/uid has permission to inject input events |
| 282 | * into other applications. |
| 283 | * |
| 284 | * This method is special in that its implementation promises to be non-reentrant and |
| 285 | * is safe to call while holding other locks. (Most other methods make no such guarantees!) |
| 286 | */ |
| 287 | virtual bool checkInjectEventsPermissionNonReentrant( |
| 288 | int32_t injectorPid, int32_t injectorUid) = 0; |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 289 | }; |
| 290 | |
| 291 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 292 | /* Notifies the system about input events generated by the input reader. |
| 293 | * The dispatcher is expected to be mostly asynchronous. */ |
| 294 | class InputDispatcherInterface : public virtual RefBase { |
| 295 | protected: |
| 296 | InputDispatcherInterface() { } |
| 297 | virtual ~InputDispatcherInterface() { } |
| 298 | |
| 299 | public: |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 300 | /* Dumps the state of the input dispatcher. |
| 301 | * |
| 302 | * This method may be called on any thread (usually by the input manager). */ |
| 303 | virtual void dump(String8& dump) = 0; |
| 304 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 305 | /* Runs a single iteration of the dispatch loop. |
| 306 | * Nominally processes one queued event, a timeout, or a response from an input consumer. |
| 307 | * |
| 308 | * This method should only be called on the input dispatcher thread. |
| 309 | */ |
| 310 | virtual void dispatchOnce() = 0; |
| 311 | |
| 312 | /* Notifies the dispatcher about new events. |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 313 | * |
| 314 | * These methods should only be called on the input reader thread. |
| 315 | */ |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 316 | virtual void notifyConfigurationChanged(nsecs_t eventTime) = 0; |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 317 | virtual void notifyKey(nsecs_t eventTime, int32_t deviceId, int32_t source, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 318 | uint32_t policyFlags, int32_t action, int32_t flags, int32_t keyCode, |
| 319 | int32_t scanCode, int32_t metaState, nsecs_t downTime) = 0; |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 320 | virtual void notifyMotion(nsecs_t eventTime, int32_t deviceId, int32_t source, |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 321 | uint32_t policyFlags, int32_t action, int32_t flags, |
| 322 | int32_t metaState, int32_t edgeFlags, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 323 | uint32_t pointerCount, const int32_t* pointerIds, const PointerCoords* pointerCoords, |
| 324 | float xPrecision, float yPrecision, nsecs_t downTime) = 0; |
| 325 | |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 326 | /* Injects an input event and optionally waits for sync. |
Jeff Brown | f67c53e | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 327 | * The synchronization mode determines whether the method blocks while waiting for |
| 328 | * input injection to proceed. |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 329 | * Returns one of the INPUT_EVENT_INJECTION_XXX constants. |
| 330 | * |
| 331 | * This method may be called on any thread (usually by the input manager). |
| 332 | */ |
| 333 | virtual int32_t injectInputEvent(const InputEvent* event, |
Jeff Brown | f67c53e | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 334 | int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis) = 0; |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 335 | |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 336 | /* Sets the list of input windows. |
| 337 | * |
| 338 | * This method may be called on any thread (usually by the input manager). |
| 339 | */ |
| 340 | virtual void setInputWindows(const Vector<InputWindow>& inputWindows) = 0; |
| 341 | |
| 342 | /* Sets the focused application. |
| 343 | * |
| 344 | * This method may be called on any thread (usually by the input manager). |
| 345 | */ |
| 346 | virtual void setFocusedApplication(const InputApplication* inputApplication) = 0; |
| 347 | |
| 348 | /* Sets the input dispatching mode. |
| 349 | * |
| 350 | * This method may be called on any thread (usually by the input manager). |
| 351 | */ |
| 352 | virtual void setInputDispatchMode(bool enabled, bool frozen) = 0; |
| 353 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 354 | /* Registers or unregister input channels that may be used as targets for input events. |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 355 | * If monitor is true, the channel will receive a copy of all input events. |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 356 | * |
| 357 | * These methods may be called on any thread (usually by the input manager). |
| 358 | */ |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 359 | virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel, bool monitor) = 0; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 360 | virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel) = 0; |
| 361 | }; |
| 362 | |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 363 | /* Dispatches events to input targets. Some functions of the input dispatcher, such as |
| 364 | * identifying input targets, are controlled by a separate policy object. |
| 365 | * |
| 366 | * IMPORTANT INVARIANT: |
| 367 | * Because the policy can potentially block or cause re-entrance into the input dispatcher, |
| 368 | * the input dispatcher never calls into the policy while holding its internal locks. |
| 369 | * The implementation is also carefully designed to recover from scenarios such as an |
| 370 | * input channel becoming unregistered while identifying input targets or processing timeouts. |
| 371 | * |
| 372 | * Methods marked 'Locked' must be called with the lock acquired. |
| 373 | * |
| 374 | * Methods marked 'LockedInterruptible' must be called with the lock acquired but |
| 375 | * may during the course of their execution release the lock, call into the policy, and |
| 376 | * then reacquire the lock. The caller is responsible for recovering gracefully. |
| 377 | * |
| 378 | * A 'LockedInterruptible' method may called a 'Locked' method, but NOT vice-versa. |
| 379 | */ |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 380 | class InputDispatcher : public InputDispatcherInterface { |
| 381 | protected: |
| 382 | virtual ~InputDispatcher(); |
| 383 | |
| 384 | public: |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 385 | explicit InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 386 | |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 387 | virtual void dump(String8& dump); |
| 388 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 389 | virtual void dispatchOnce(); |
| 390 | |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 391 | virtual void notifyConfigurationChanged(nsecs_t eventTime); |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 392 | virtual void notifyKey(nsecs_t eventTime, int32_t deviceId, int32_t source, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 393 | uint32_t policyFlags, int32_t action, int32_t flags, int32_t keyCode, |
| 394 | int32_t scanCode, int32_t metaState, nsecs_t downTime); |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 395 | virtual void notifyMotion(nsecs_t eventTime, int32_t deviceId, int32_t source, |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 396 | uint32_t policyFlags, int32_t action, int32_t flags, |
| 397 | int32_t metaState, int32_t edgeFlags, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 398 | uint32_t pointerCount, const int32_t* pointerIds, const PointerCoords* pointerCoords, |
| 399 | float xPrecision, float yPrecision, nsecs_t downTime); |
| 400 | |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 401 | virtual int32_t injectInputEvent(const InputEvent* event, |
Jeff Brown | f67c53e | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 402 | int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis); |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 403 | |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 404 | virtual void setInputWindows(const Vector<InputWindow>& inputWindows); |
| 405 | virtual void setFocusedApplication(const InputApplication* inputApplication); |
| 406 | virtual void setInputDispatchMode(bool enabled, bool frozen); |
Jeff Brown | 50de30a | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 407 | |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 408 | virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel, bool monitor); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 409 | virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel); |
| 410 | |
| 411 | private: |
| 412 | template <typename T> |
| 413 | struct Link { |
| 414 | T* next; |
| 415 | T* prev; |
| 416 | }; |
| 417 | |
| 418 | struct EventEntry : Link<EventEntry> { |
| 419 | enum { |
| 420 | TYPE_SENTINEL, |
| 421 | TYPE_CONFIGURATION_CHANGED, |
| 422 | TYPE_KEY, |
| 423 | TYPE_MOTION |
| 424 | }; |
| 425 | |
| 426 | int32_t refCount; |
| 427 | int32_t type; |
| 428 | nsecs_t eventTime; |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 429 | |
Jeff Brown | f67c53e | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 430 | int32_t injectionResult; // initially INPUT_EVENT_INJECTION_PENDING |
| 431 | bool injectionIsAsync; // set to true if injection is not waiting for the result |
| 432 | int32_t injectorPid; // -1 if not injected |
| 433 | int32_t injectorUid; // -1 if not injected |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 434 | |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 435 | bool dispatchInProgress; // initially false, set to true while dispatching |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 436 | int32_t pendingForegroundDispatches; // the number of foreground dispatches in progress |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 437 | |
| 438 | inline bool isInjected() { return injectorPid >= 0; } |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 439 | |
| 440 | void recycle(); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 441 | }; |
| 442 | |
| 443 | struct ConfigurationChangedEntry : EventEntry { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 444 | }; |
| 445 | |
| 446 | struct KeyEntry : EventEntry { |
| 447 | int32_t deviceId; |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 448 | int32_t source; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 449 | uint32_t policyFlags; |
| 450 | int32_t action; |
| 451 | int32_t flags; |
| 452 | int32_t keyCode; |
| 453 | int32_t scanCode; |
| 454 | int32_t metaState; |
| 455 | int32_t repeatCount; |
| 456 | nsecs_t downTime; |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 457 | |
| 458 | bool syntheticRepeat; // set to true for synthetic key repeats |
| 459 | |
| 460 | enum InterceptKeyResult { |
| 461 | INTERCEPT_KEY_RESULT_UNKNOWN, |
| 462 | INTERCEPT_KEY_RESULT_SKIP, |
| 463 | INTERCEPT_KEY_RESULT_CONTINUE, |
| 464 | }; |
| 465 | InterceptKeyResult interceptKeyResult; // set based on the interception result |
| 466 | |
| 467 | void recycle(); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 468 | }; |
| 469 | |
| 470 | struct MotionSample { |
| 471 | MotionSample* next; |
| 472 | |
| 473 | nsecs_t eventTime; |
| 474 | PointerCoords pointerCoords[MAX_POINTERS]; |
| 475 | }; |
| 476 | |
| 477 | struct MotionEntry : EventEntry { |
| 478 | int32_t deviceId; |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 479 | int32_t source; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 480 | uint32_t policyFlags; |
| 481 | int32_t action; |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 482 | int32_t flags; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 483 | int32_t metaState; |
| 484 | int32_t edgeFlags; |
| 485 | float xPrecision; |
| 486 | float yPrecision; |
| 487 | nsecs_t downTime; |
| 488 | uint32_t pointerCount; |
| 489 | int32_t pointerIds[MAX_POINTERS]; |
| 490 | |
| 491 | // Linked list of motion samples associated with this motion event. |
| 492 | MotionSample firstSample; |
| 493 | MotionSample* lastSample; |
Jeff Brown | 542412c | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 494 | |
| 495 | uint32_t countSamples() const; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 496 | }; |
| 497 | |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 498 | // Tracks the progress of dispatching a particular event to a particular connection. |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 499 | struct DispatchEntry : Link<DispatchEntry> { |
| 500 | EventEntry* eventEntry; // the event to dispatch |
| 501 | int32_t targetFlags; |
| 502 | float xOffset; |
| 503 | float yOffset; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 504 | |
| 505 | // True if dispatch has started. |
| 506 | bool inProgress; |
| 507 | |
| 508 | // For motion events: |
| 509 | // Pointer to the first motion sample to dispatch in this cycle. |
| 510 | // Usually NULL to indicate that the list of motion samples begins at |
| 511 | // MotionEntry::firstSample. Otherwise, some samples were dispatched in a previous |
| 512 | // cycle and this pointer indicates the location of the first remainining sample |
| 513 | // to dispatch during the current cycle. |
| 514 | MotionSample* headMotionSample; |
| 515 | // Pointer to a motion sample to dispatch in the next cycle if the dispatcher was |
| 516 | // unable to send all motion samples during this cycle. On the next cycle, |
| 517 | // headMotionSample will be initialized to tailMotionSample and tailMotionSample |
| 518 | // will be set to NULL. |
| 519 | MotionSample* tailMotionSample; |
Jeff Brown | f67c53e | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 520 | |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 521 | inline bool hasForegroundTarget() const { |
| 522 | return targetFlags & InputTarget::FLAG_FOREGROUND; |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 523 | } |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 524 | }; |
| 525 | |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 526 | // A command entry captures state and behavior for an action to be performed in the |
| 527 | // dispatch loop after the initial processing has taken place. It is essentially |
| 528 | // a kind of continuation used to postpone sensitive policy interactions to a point |
| 529 | // in the dispatch loop where it is safe to release the lock (generally after finishing |
| 530 | // the critical parts of the dispatch cycle). |
| 531 | // |
| 532 | // The special thing about commands is that they can voluntarily release and reacquire |
| 533 | // the dispatcher lock at will. Initially when the command starts running, the |
| 534 | // dispatcher lock is held. However, if the command needs to call into the policy to |
| 535 | // do some work, it can release the lock, do the work, then reacquire the lock again |
| 536 | // before returning. |
| 537 | // |
| 538 | // This mechanism is a bit clunky but it helps to preserve the invariant that the dispatch |
| 539 | // never calls into the policy while holding its lock. |
| 540 | // |
| 541 | // Commands are implicitly 'LockedInterruptible'. |
| 542 | struct CommandEntry; |
| 543 | typedef void (InputDispatcher::*Command)(CommandEntry* commandEntry); |
| 544 | |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 545 | class Connection; |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 546 | struct CommandEntry : Link<CommandEntry> { |
| 547 | CommandEntry(); |
| 548 | ~CommandEntry(); |
| 549 | |
| 550 | Command command; |
| 551 | |
| 552 | // parameters for the command (usage varies by command) |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 553 | sp<Connection> connection; |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 554 | nsecs_t eventTime; |
| 555 | KeyEntry* keyEntry; |
| 556 | sp<InputChannel> inputChannel; |
| 557 | sp<InputApplicationHandle> inputApplicationHandle; |
| 558 | int32_t windowType; |
| 559 | int32_t userActivityEventType; |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 560 | }; |
| 561 | |
| 562 | // Generic queue implementation. |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 563 | template <typename T> |
| 564 | struct Queue { |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 565 | T headSentinel; |
| 566 | T tailSentinel; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 567 | |
| 568 | inline Queue() { |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 569 | headSentinel.prev = NULL; |
| 570 | headSentinel.next = & tailSentinel; |
| 571 | tailSentinel.prev = & headSentinel; |
| 572 | tailSentinel.next = NULL; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 575 | inline bool isEmpty() const { |
| 576 | return headSentinel.next == & tailSentinel; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | inline void enqueueAtTail(T* entry) { |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 580 | T* last = tailSentinel.prev; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 581 | last->next = entry; |
| 582 | entry->prev = last; |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 583 | entry->next = & tailSentinel; |
| 584 | tailSentinel.prev = entry; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | inline void enqueueAtHead(T* entry) { |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 588 | T* first = headSentinel.next; |
| 589 | headSentinel.next = entry; |
| 590 | entry->prev = & headSentinel; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 591 | entry->next = first; |
| 592 | first->prev = entry; |
| 593 | } |
| 594 | |
| 595 | inline void dequeue(T* entry) { |
| 596 | entry->prev->next = entry->next; |
| 597 | entry->next->prev = entry->prev; |
| 598 | } |
| 599 | |
| 600 | inline T* dequeueAtHead() { |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 601 | T* first = headSentinel.next; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 602 | dequeue(first); |
| 603 | return first; |
| 604 | } |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 605 | |
| 606 | uint32_t count() const; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 607 | }; |
| 608 | |
| 609 | /* Allocates queue entries and performs reference counting as needed. */ |
| 610 | class Allocator { |
| 611 | public: |
| 612 | Allocator(); |
| 613 | |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 614 | ConfigurationChangedEntry* obtainConfigurationChangedEntry(nsecs_t eventTime); |
| 615 | KeyEntry* obtainKeyEntry(nsecs_t eventTime, |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 616 | int32_t deviceId, int32_t source, uint32_t policyFlags, int32_t action, |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 617 | int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState, |
| 618 | int32_t repeatCount, nsecs_t downTime); |
| 619 | MotionEntry* obtainMotionEntry(nsecs_t eventTime, |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 620 | int32_t deviceId, int32_t source, uint32_t policyFlags, int32_t action, |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 621 | int32_t flags, int32_t metaState, int32_t edgeFlags, |
| 622 | float xPrecision, float yPrecision, |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 623 | nsecs_t downTime, uint32_t pointerCount, |
| 624 | const int32_t* pointerIds, const PointerCoords* pointerCoords); |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 625 | DispatchEntry* obtainDispatchEntry(EventEntry* eventEntry, |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 626 | int32_t targetFlags, float xOffset, float yOffset); |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 627 | CommandEntry* obtainCommandEntry(Command command); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 628 | |
| 629 | void releaseEventEntry(EventEntry* entry); |
| 630 | void releaseConfigurationChangedEntry(ConfigurationChangedEntry* entry); |
| 631 | void releaseKeyEntry(KeyEntry* entry); |
| 632 | void releaseMotionEntry(MotionEntry* entry); |
| 633 | void releaseDispatchEntry(DispatchEntry* entry); |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 634 | void releaseCommandEntry(CommandEntry* entry); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 635 | |
| 636 | void appendMotionSample(MotionEntry* motionEntry, |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 637 | nsecs_t eventTime, const PointerCoords* pointerCoords); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 638 | |
| 639 | private: |
| 640 | Pool<ConfigurationChangedEntry> mConfigurationChangeEntryPool; |
| 641 | Pool<KeyEntry> mKeyEntryPool; |
| 642 | Pool<MotionEntry> mMotionEntryPool; |
| 643 | Pool<MotionSample> mMotionSamplePool; |
| 644 | Pool<DispatchEntry> mDispatchEntryPool; |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 645 | Pool<CommandEntry> mCommandEntryPool; |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 646 | |
| 647 | void initializeEventEntry(EventEntry* entry, int32_t type, nsecs_t eventTime); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 648 | }; |
| 649 | |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 650 | /* Tracks dispatched key and motion event state so that cancelation events can be |
| 651 | * synthesized when events are dropped. */ |
| 652 | class InputState { |
| 653 | public: |
| 654 | // Specifies whether a given event will violate input state consistency. |
| 655 | enum Consistency { |
| 656 | // The event is consistent with the current input state. |
| 657 | CONSISTENT, |
| 658 | // The event is inconsistent with the current input state but applications |
| 659 | // will tolerate it. eg. Down followed by another down. |
| 660 | TOLERABLE, |
| 661 | // The event is inconsistent with the current input state and will probably |
| 662 | // cause applications to crash. eg. Up without prior down, move with |
| 663 | // unexpected number of pointers. |
| 664 | BROKEN |
| 665 | }; |
| 666 | |
| 667 | InputState(); |
| 668 | ~InputState(); |
| 669 | |
| 670 | // Returns true if there is no state to be canceled. |
| 671 | bool isNeutral() const; |
| 672 | |
| 673 | // Returns true if the input state believes it is out of sync. |
| 674 | bool isOutOfSync() const; |
| 675 | |
| 676 | // Sets the input state to be out of sync if it is not neutral. |
| 677 | void setOutOfSync(); |
| 678 | |
| 679 | // Resets the input state out of sync flag. |
| 680 | void resetOutOfSync(); |
| 681 | |
| 682 | // Records tracking information for an event that has just been published. |
| 683 | // Returns whether the event is consistent with the current input state. |
| 684 | Consistency trackEvent(const EventEntry* entry); |
| 685 | |
| 686 | // Records tracking information for a key event that has just been published. |
| 687 | // Returns whether the event is consistent with the current input state. |
| 688 | Consistency trackKey(const KeyEntry* entry); |
| 689 | |
| 690 | // Records tracking information for a motion event that has just been published. |
| 691 | // Returns whether the event is consistent with the current input state. |
| 692 | Consistency trackMotion(const MotionEntry* entry); |
| 693 | |
| 694 | // Synthesizes cancelation events for the current state. |
| 695 | void synthesizeCancelationEvents(Allocator* allocator, |
| 696 | Vector<EventEntry*>& outEvents) const; |
| 697 | |
| 698 | // Clears the current state. |
| 699 | void clear(); |
| 700 | |
| 701 | private: |
| 702 | bool mIsOutOfSync; |
| 703 | |
| 704 | struct KeyMemento { |
| 705 | int32_t deviceId; |
| 706 | int32_t source; |
| 707 | int32_t keyCode; |
| 708 | int32_t scanCode; |
| 709 | nsecs_t downTime; |
| 710 | }; |
| 711 | |
| 712 | struct MotionMemento { |
| 713 | int32_t deviceId; |
| 714 | int32_t source; |
| 715 | float xPrecision; |
| 716 | float yPrecision; |
| 717 | nsecs_t downTime; |
| 718 | uint32_t pointerCount; |
| 719 | int32_t pointerIds[MAX_POINTERS]; |
| 720 | PointerCoords pointerCoords[MAX_POINTERS]; |
| 721 | |
| 722 | void setPointers(const MotionEntry* entry); |
| 723 | }; |
| 724 | |
| 725 | Vector<KeyMemento> mKeyMementos; |
| 726 | Vector<MotionMemento> mMotionMementos; |
| 727 | }; |
| 728 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 729 | /* Manages the dispatch state associated with a single input channel. */ |
| 730 | class Connection : public RefBase { |
| 731 | protected: |
| 732 | virtual ~Connection(); |
| 733 | |
| 734 | public: |
| 735 | enum Status { |
| 736 | // Everything is peachy. |
| 737 | STATUS_NORMAL, |
| 738 | // An unrecoverable communication error has occurred. |
| 739 | STATUS_BROKEN, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 740 | // The input channel has been unregistered. |
| 741 | STATUS_ZOMBIE |
| 742 | }; |
| 743 | |
| 744 | Status status; |
| 745 | sp<InputChannel> inputChannel; |
| 746 | InputPublisher inputPublisher; |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 747 | InputState inputState; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 748 | Queue<DispatchEntry> outboundQueue; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 749 | |
| 750 | nsecs_t lastEventTime; // the time when the event was originally captured |
| 751 | nsecs_t lastDispatchTime; // the time when the last event was dispatched |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 752 | |
| 753 | explicit Connection(const sp<InputChannel>& inputChannel); |
| 754 | |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 755 | inline const char* getInputChannelName() const { return inputChannel->getName().string(); } |
| 756 | |
| 757 | const char* getStatusLabel() const; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 758 | |
| 759 | // Finds a DispatchEntry in the outbound queue associated with the specified event. |
| 760 | // Returns NULL if not found. |
| 761 | DispatchEntry* findQueuedDispatchEntryForEvent(const EventEntry* eventEntry) const; |
| 762 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 763 | // Gets the time since the current event was originally obtained from the input driver. |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 764 | inline double getEventLatencyMillis(nsecs_t currentTime) const { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 765 | return (currentTime - lastEventTime) / 1000000.0; |
| 766 | } |
| 767 | |
| 768 | // Gets the time since the current event entered the outbound dispatch queue. |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 769 | inline double getDispatchLatencyMillis(nsecs_t currentTime) const { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 770 | return (currentTime - lastDispatchTime) / 1000000.0; |
| 771 | } |
| 772 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 773 | status_t initialize(); |
| 774 | }; |
| 775 | |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 776 | sp<InputDispatcherPolicyInterface> mPolicy; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 777 | |
| 778 | Mutex mLock; |
| 779 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 780 | Allocator mAllocator; |
Jeff Brown | 59abe7e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 781 | sp<Looper> mLooper; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 782 | |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 783 | EventEntry* mPendingEvent; |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 784 | Queue<EventEntry> mInboundQueue; |
| 785 | Queue<CommandEntry> mCommandQueue; |
| 786 | |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 787 | Vector<EventEntry*> mTempCancelationEvents; |
| 788 | |
| 789 | void dispatchOnceInnerLocked(nsecs_t keyRepeatTimeout, nsecs_t keyRepeatDelay, |
| 790 | nsecs_t* nextWakeupTime); |
| 791 | |
Jeff Brown | 59abe7e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 792 | // Enqueues an inbound event. Returns true if mLooper->wake() should be called. |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 793 | bool enqueueInboundEventLocked(EventEntry* entry); |
| 794 | |
| 795 | // App switch latency optimization. |
| 796 | nsecs_t mAppSwitchDueTime; |
| 797 | |
| 798 | static bool isAppSwitchKey(int32_t keyCode); |
| 799 | bool isAppSwitchPendingLocked(); |
| 800 | bool detectPendingAppSwitchLocked(KeyEntry* inboundKeyEntry); |
| 801 | void resetPendingAppSwitchLocked(bool handled); |
| 802 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 803 | // All registered connections mapped by receive pipe file descriptor. |
| 804 | KeyedVector<int, sp<Connection> > mConnectionsByReceiveFd; |
| 805 | |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 806 | ssize_t getConnectionIndexLocked(const sp<InputChannel>& inputChannel); |
Jeff Brown | 0cacb87 | 2010-08-17 15:59:26 -0700 | [diff] [blame] | 807 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 808 | // Active connections are connections that have a non-empty outbound queue. |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 809 | // We don't use a ref-counted pointer here because we explicitly abort connections |
| 810 | // during unregistration which causes the connection's outbound queue to be cleared |
| 811 | // and the connection itself to be deactivated. |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 812 | Vector<Connection*> mActiveConnections; |
| 813 | |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 814 | // Input channels that will receive a copy of all input events. |
| 815 | Vector<sp<InputChannel> > mMonitoringChannels; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 816 | |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 817 | // Preallocated key event object used for policy inquiries. |
| 818 | KeyEvent mReusableKeyEvent; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 819 | |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 820 | // Event injection and synchronization. |
| 821 | Condition mInjectionResultAvailableCondition; |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 822 | EventEntry* createEntryFromInjectedInputEventLocked(const InputEvent* event); |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 823 | void setInjectionResultLocked(EventEntry* entry, int32_t injectionResult); |
| 824 | |
Jeff Brown | f67c53e | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 825 | Condition mInjectionSyncFinishedCondition; |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 826 | void decrementPendingForegroundDispatchesLocked(EventEntry* entry); |
Jeff Brown | f67c53e | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 827 | |
Jeff Brown | 542412c | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 828 | // Throttling state. |
| 829 | struct ThrottleState { |
| 830 | nsecs_t minTimeBetweenEvents; |
| 831 | |
| 832 | nsecs_t lastEventTime; |
| 833 | int32_t lastDeviceId; |
| 834 | uint32_t lastSource; |
| 835 | |
| 836 | uint32_t originalSampleCount; // only collected during debugging |
| 837 | } mThrottleState; |
| 838 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 839 | // Key repeat tracking. |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 840 | struct KeyRepeatState { |
| 841 | KeyEntry* lastKeyEntry; // or null if no repeat |
| 842 | nsecs_t nextRepeatTime; |
| 843 | } mKeyRepeatState; |
| 844 | |
| 845 | void resetKeyRepeatLocked(); |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 846 | KeyEntry* synthesizeKeyRepeatLocked(nsecs_t currentTime, nsecs_t keyRepeatTimeout); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 847 | |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 848 | // Deferred command processing. |
| 849 | bool runCommandsLockedInterruptible(); |
| 850 | CommandEntry* postCommandLocked(Command command); |
| 851 | |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 852 | // Inbound event processing. |
| 853 | void drainInboundQueueLocked(); |
Jeff Brown | d8816c3 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 854 | void releasePendingEventLocked(); |
| 855 | void releaseInboundEventLocked(EventEntry* entry); |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 856 | bool isEventFromReliableSourceLocked(EventEntry* entry); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 857 | |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 858 | // Dispatch state. |
| 859 | bool mDispatchEnabled; |
| 860 | bool mDispatchFrozen; |
| 861 | Vector<InputWindow> mWindows; |
| 862 | Vector<InputWindow*> mWallpaperWindows; |
| 863 | |
| 864 | // Focus tracking for keys, trackball, etc. |
| 865 | InputWindow* mFocusedWindow; |
| 866 | |
| 867 | // Focus tracking for touch. |
| 868 | bool mTouchDown; |
| 869 | InputWindow* mTouchedWindow; // primary target for current down |
| 870 | bool mTouchedWindowIsObscured; // true if other windows may obscure the target |
| 871 | Vector<InputWindow*> mTouchedWallpaperWindows; // wallpaper targets |
| 872 | struct OutsideTarget { |
| 873 | InputWindow* window; |
| 874 | bool obscured; |
| 875 | }; |
| 876 | Vector<OutsideTarget> mTempTouchedOutsideTargets; // temporary outside touch targets |
| 877 | Vector<sp<InputChannel> > mTempTouchedWallpaperChannels; // temporary wallpaper targets |
| 878 | |
| 879 | // Focused application. |
| 880 | InputApplication* mFocusedApplication; |
| 881 | InputApplication mFocusedApplicationStorage; // preallocated storage for mFocusedApplication |
| 882 | void releaseFocusedApplicationLocked(); |
| 883 | |
| 884 | // Dispatch inbound events. |
| 885 | bool dispatchConfigurationChangedLocked( |
| 886 | nsecs_t currentTime, ConfigurationChangedEntry* entry); |
| 887 | bool dispatchKeyLocked( |
| 888 | nsecs_t currentTime, KeyEntry* entry, nsecs_t keyRepeatTimeout, |
Jeff Brown | d8816c3 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 889 | bool dropEvent, nsecs_t* nextWakeupTime); |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 890 | bool dispatchMotionLocked( |
| 891 | nsecs_t currentTime, MotionEntry* entry, |
Jeff Brown | d8816c3 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 892 | bool dropEvent, nsecs_t* nextWakeupTime); |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 893 | void dispatchEventToCurrentInputTargetsLocked( |
| 894 | nsecs_t currentTime, EventEntry* entry, bool resumeWithAppendedMotionSample); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 895 | |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 896 | void logOutboundKeyDetailsLocked(const char* prefix, const KeyEntry* entry); |
| 897 | void logOutboundMotionDetailsLocked(const char* prefix, const MotionEntry* entry); |
| 898 | |
| 899 | // The input targets that were most recently identified for dispatch. |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 900 | bool mCurrentInputTargetsValid; // false while targets are being recomputed |
| 901 | Vector<InputTarget> mCurrentInputTargets; |
| 902 | int32_t mCurrentInputWindowType; |
| 903 | sp<InputChannel> mCurrentInputChannel; |
| 904 | |
| 905 | enum InputTargetWaitCause { |
| 906 | INPUT_TARGET_WAIT_CAUSE_NONE, |
| 907 | INPUT_TARGET_WAIT_CAUSE_SYSTEM_NOT_READY, |
| 908 | INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY, |
| 909 | }; |
| 910 | |
| 911 | InputTargetWaitCause mInputTargetWaitCause; |
| 912 | nsecs_t mInputTargetWaitStartTime; |
| 913 | nsecs_t mInputTargetWaitTimeoutTime; |
| 914 | bool mInputTargetWaitTimeoutExpired; |
| 915 | |
| 916 | // Finding targets for input events. |
Jeff Brown | d8816c3 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 917 | void resetTargetsLocked(); |
| 918 | void commitTargetsLocked(const InputWindow* window); |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 919 | int32_t handleTargetsNotReadyLocked(nsecs_t currentTime, const EventEntry* entry, |
| 920 | const InputApplication* application, const InputWindow* window, |
| 921 | nsecs_t* nextWakeupTime); |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 922 | void resumeAfterTargetsNotReadyTimeoutLocked(nsecs_t newTimeout, |
| 923 | const sp<InputChannel>& inputChannel); |
| 924 | nsecs_t getTimeSpentWaitingForApplicationLocked(nsecs_t currentTime); |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 925 | void resetANRTimeoutsLocked(); |
| 926 | |
| 927 | int32_t findFocusedWindowLocked(nsecs_t currentTime, const EventEntry* entry, |
| 928 | nsecs_t* nextWakeupTime, InputWindow** outWindow); |
| 929 | int32_t findTouchedWindowLocked(nsecs_t currentTime, const MotionEntry* entry, |
| 930 | nsecs_t* nextWakeupTime, InputWindow** outWindow); |
| 931 | |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 932 | void addWindowTargetLocked(const InputWindow* window, int32_t targetFlags); |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 933 | void addMonitoringTargetsLocked(); |
| 934 | void pokeUserActivityLocked(nsecs_t eventTime, int32_t windowType, int32_t eventType); |
| 935 | bool checkInjectionPermission(const InputWindow* window, |
| 936 | int32_t injectorPid, int32_t injectorUid); |
| 937 | bool isWindowObscuredLocked(const InputWindow* window); |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 938 | bool isWindowFinishedWithPreviousInputLocked(const InputWindow* window); |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 939 | void releaseTouchedWindowLocked(); |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 940 | String8 getApplicationWindowLabelLocked(const InputApplication* application, |
| 941 | const InputWindow* window); |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 942 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 943 | // Manage the dispatch cycle for a single connection. |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 944 | // These methods are deliberately not Interruptible because doing all of the work |
| 945 | // with the mutex held makes it easier to ensure that connection invariants are maintained. |
| 946 | // If needed, the methods post commands to run later once the critical bits are done. |
| 947 | void prepareDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 948 | EventEntry* eventEntry, const InputTarget* inputTarget, |
| 949 | bool resumeWithAppendedMotionSample); |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 950 | void startDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection); |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 951 | void finishDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection); |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 952 | void startNextDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection); |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 953 | void abortDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 954 | bool broken); |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 955 | void drainOutboundQueueLocked(Connection* connection); |
Jeff Brown | 59abe7e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 956 | static int handleReceiveCallback(int receiveFd, int events, void* data); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 957 | |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 958 | // Dump state. |
| 959 | void dumpDispatchStateLocked(String8& dump); |
| 960 | void logDispatchStateLocked(); |
| 961 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 962 | // Add or remove a connection to the mActiveConnections vector. |
| 963 | void activateConnectionLocked(Connection* connection); |
| 964 | void deactivateConnectionLocked(Connection* connection); |
| 965 | |
| 966 | // Interesting events that we might like to log or tell the framework about. |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 967 | void onDispatchCycleStartedLocked( |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 968 | nsecs_t currentTime, const sp<Connection>& connection); |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 969 | void onDispatchCycleFinishedLocked( |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 970 | nsecs_t currentTime, const sp<Connection>& connection); |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 971 | void onDispatchCycleBrokenLocked( |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 972 | nsecs_t currentTime, const sp<Connection>& connection); |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 973 | void onANRLocked( |
| 974 | nsecs_t currentTime, const InputApplication* application, const InputWindow* window, |
| 975 | nsecs_t eventTime, nsecs_t waitStartTime); |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 976 | |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 977 | // Outbound policy interactions. |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 978 | void doNotifyConfigurationChangedInterruptible(CommandEntry* commandEntry); |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 979 | void doNotifyInputChannelBrokenLockedInterruptible(CommandEntry* commandEntry); |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 980 | void doNotifyANRLockedInterruptible(CommandEntry* commandEntry); |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 981 | void doInterceptKeyBeforeDispatchingLockedInterruptible(CommandEntry* commandEntry); |
| 982 | void doPokeUserActivityLockedInterruptible(CommandEntry* commandEntry); |
Jeff Brown | 53a415e | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 983 | |
| 984 | // Statistics gathering. |
| 985 | void updateDispatchStatisticsLocked(nsecs_t currentTime, const EventEntry* entry, |
| 986 | int32_t injectionResult, nsecs_t timeSpentWaitingForApplication); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 987 | }; |
| 988 | |
| 989 | /* Enqueues and dispatches input events, endlessly. */ |
| 990 | class InputDispatcherThread : public Thread { |
| 991 | public: |
| 992 | explicit InputDispatcherThread(const sp<InputDispatcherInterface>& dispatcher); |
| 993 | ~InputDispatcherThread(); |
| 994 | |
| 995 | private: |
| 996 | virtual bool threadLoop(); |
| 997 | |
| 998 | sp<InputDispatcherInterface> mDispatcher; |
| 999 | }; |
| 1000 | |
| 1001 | } // namespace android |
| 1002 | |
Jeff Brown | a665ca8 | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1003 | #endif // _UI_INPUT_DISPATCHER_H |