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