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