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