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