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