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 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 20 | #include "CancelationOptions.h" |
| 21 | #include "Entry.h" |
| 22 | #include "InjectionState.h" |
| 23 | #include "InputDispatcherConfiguration.h" |
| 24 | #include "InputDispatcherInterface.h" |
| 25 | #include "InputDispatcherPolicyInterface.h" |
| 26 | #include "InputState.h" |
| 27 | #include "InputTarget.h" |
| 28 | #include "Monitor.h" |
| 29 | #include "TouchState.h" |
| 30 | #include "TouchedWindow.h" |
| 31 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 32 | #include <input/Input.h> |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 33 | #include <input/InputApplication.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 34 | #include <input/InputTransport.h> |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 35 | #include <input/InputWindow.h> |
Siarhei Vishniakou | de4bf15 | 2019-08-16 11:12:52 -0500 | [diff] [blame] | 36 | #include <input/LatencyStatistics.h> |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 37 | #include <limits.h> |
| 38 | #include <stddef.h> |
Michael Wright | 3dd60e2 | 2019-03-27 22:06:44 +0000 | [diff] [blame] | 39 | #include <ui/Region.h> |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 40 | #include <unistd.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 41 | #include <utils/BitSet.h> |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 42 | #include <utils/Looper.h> |
| 43 | #include <utils/RefBase.h> |
| 44 | #include <utils/Timers.h> |
| 45 | #include <utils/threads.h> |
| 46 | #include <condition_variable> |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 47 | #include <deque> |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 48 | #include <optional> |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 49 | #include <unordered_map> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 50 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 51 | #include <InputListener.h> |
| 52 | #include <InputReporterInterface.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 53 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 54 | namespace android::inputdispatcher { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 55 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 56 | class Connection; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 57 | |
| 58 | /* Dispatches events to input targets. Some functions of the input dispatcher, such as |
| 59 | * identifying input targets, are controlled by a separate policy object. |
| 60 | * |
| 61 | * IMPORTANT INVARIANT: |
| 62 | * Because the policy can potentially block or cause re-entrance into the input dispatcher, |
| 63 | * the input dispatcher never calls into the policy while holding its internal locks. |
| 64 | * The implementation is also carefully designed to recover from scenarios such as an |
| 65 | * input channel becoming unregistered while identifying input targets or processing timeouts. |
| 66 | * |
| 67 | * Methods marked 'Locked' must be called with the lock acquired. |
| 68 | * |
| 69 | * Methods marked 'LockedInterruptible' must be called with the lock acquired but |
| 70 | * may during the course of their execution release the lock, call into the policy, and |
| 71 | * then reacquire the lock. The caller is responsible for recovering gracefully. |
| 72 | * |
| 73 | * A 'LockedInterruptible' method may called a 'Locked' method, but NOT vice-versa. |
| 74 | */ |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 75 | class InputDispatcher : public android::InputDispatcherInterface { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 76 | protected: |
| 77 | virtual ~InputDispatcher(); |
| 78 | |
| 79 | public: |
| 80 | explicit InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy); |
| 81 | |
Michael Wright | 3dd60e2 | 2019-03-27 22:06:44 +0000 | [diff] [blame] | 82 | virtual void dump(std::string& dump) override; |
| 83 | virtual void monitor() override; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 84 | |
Michael Wright | 3dd60e2 | 2019-03-27 22:06:44 +0000 | [diff] [blame] | 85 | virtual void dispatchOnce() override; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 86 | |
Michael Wright | 3dd60e2 | 2019-03-27 22:06:44 +0000 | [diff] [blame] | 87 | virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override; |
| 88 | virtual void notifyKey(const NotifyKeyArgs* args) override; |
| 89 | virtual void notifyMotion(const NotifyMotionArgs* args) override; |
| 90 | virtual void notifySwitch(const NotifySwitchArgs* args) override; |
| 91 | virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) override; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 92 | |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 93 | virtual int32_t injectInputEvent(const InputEvent* event, int32_t injectorPid, |
| 94 | int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis, |
| 95 | uint32_t policyFlags) override; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 96 | |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 97 | virtual void setInputWindows( |
| 98 | const std::vector<sp<InputWindowHandle>>& inputWindowHandles, int32_t displayId, |
Michael Wright | 3dd60e2 | 2019-03-27 22:06:44 +0000 | [diff] [blame] | 99 | const sp<ISetInputWindowsListener>& setInputWindowsListener = nullptr) override; |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 100 | virtual void setFocusedApplication( |
| 101 | int32_t displayId, const sp<InputApplicationHandle>& inputApplicationHandle) override; |
Michael Wright | 3dd60e2 | 2019-03-27 22:06:44 +0000 | [diff] [blame] | 102 | virtual void setFocusedDisplay(int32_t displayId) override; |
| 103 | virtual void setInputDispatchMode(bool enabled, bool frozen) override; |
| 104 | virtual void setInputFilterEnabled(bool enabled) override; |
Siarhei Vishniakou | f3bc1aa | 2019-11-25 13:48:53 -0800 | [diff] [blame^] | 105 | virtual void setInTouchMode(bool inTouchMode) override; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 106 | |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 107 | virtual bool transferTouchFocus(const sp<IBinder>& fromToken, |
| 108 | const sp<IBinder>& toToken) override; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 109 | |
Siarhei Vishniakou | 7c34b23 | 2019-10-11 19:08:48 -0700 | [diff] [blame] | 110 | virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel) override; |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 111 | virtual status_t registerInputMonitor(const sp<InputChannel>& inputChannel, int32_t displayId, |
| 112 | bool isGestureMonitor) override; |
Michael Wright | 3dd60e2 | 2019-03-27 22:06:44 +0000 | [diff] [blame] | 113 | virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel) override; |
| 114 | virtual status_t pilferPointers(const sp<IBinder>& token) override; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 115 | |
| 116 | private: |
Siarhei Vishniakou | 0fb1a0e | 2019-10-22 11:23:36 -0700 | [diff] [blame] | 117 | enum class DropReason { |
| 118 | NOT_DROPPED, |
| 119 | POLICY, |
| 120 | APP_SWITCH, |
| 121 | DISABLED, |
| 122 | BLOCKED, |
| 123 | STALE, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | sp<InputDispatcherPolicyInterface> mPolicy; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 127 | android::InputDispatcherConfiguration mConfig; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 128 | |
Siarhei Vishniakou | 443ad90 | 2019-03-06 17:25:41 -0800 | [diff] [blame] | 129 | std::mutex mLock; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 130 | |
Siarhei Vishniakou | 443ad90 | 2019-03-06 17:25:41 -0800 | [diff] [blame] | 131 | std::condition_variable mDispatcherIsAlive; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 132 | |
| 133 | sp<Looper> mLooper; |
| 134 | |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 135 | EventEntry* mPendingEvent GUARDED_BY(mLock); |
Siarhei Vishniakou | 44a2aed | 2019-07-29 08:59:52 -0700 | [diff] [blame] | 136 | std::deque<EventEntry*> mInboundQueue GUARDED_BY(mLock); |
| 137 | std::deque<EventEntry*> mRecentQueue GUARDED_BY(mLock); |
Siarhei Vishniakou | e7c94b9 | 2019-07-29 09:17:54 -0700 | [diff] [blame] | 138 | std::deque<std::unique_ptr<CommandEntry>> mCommandQueue GUARDED_BY(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 139 | |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 140 | DropReason mLastDropReason GUARDED_BY(mLock); |
Michael Wright | 3a98172 | 2015-06-10 15:26:13 +0100 | [diff] [blame] | 141 | |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 142 | void dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 143 | |
| 144 | // Enqueues an inbound event. Returns true if mLooper->wake() should be called. |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 145 | bool enqueueInboundEventLocked(EventEntry* entry) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 146 | |
| 147 | // Cleans up input state when dropping an inbound event. |
Siarhei Vishniakou | d277004 | 2019-10-29 11:08:14 -0700 | [diff] [blame] | 148 | void dropInboundEventLocked(const EventEntry& entry, DropReason dropReason) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 149 | |
| 150 | // Adds an event to a queue of recent events for debugging purposes. |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 151 | void addRecentEventLocked(EventEntry* entry) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 152 | |
| 153 | // App switch latency optimization. |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 154 | bool mAppSwitchSawKeyDown GUARDED_BY(mLock); |
| 155 | nsecs_t mAppSwitchDueTime GUARDED_BY(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 156 | |
Siarhei Vishniakou | d277004 | 2019-10-29 11:08:14 -0700 | [diff] [blame] | 157 | bool isAppSwitchKeyEvent(const KeyEntry& keyEntry); |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 158 | bool isAppSwitchPendingLocked() REQUIRES(mLock); |
| 159 | void resetPendingAppSwitchLocked(bool handled) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 160 | |
| 161 | // Stale event latency optimization. |
Siarhei Vishniakou | d277004 | 2019-10-29 11:08:14 -0700 | [diff] [blame] | 162 | static bool isStaleEvent(nsecs_t currentTime, const EventEntry& entry); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 163 | |
| 164 | // Blocked event latency optimization. Drops old events when the user intends |
| 165 | // to transfer focus to a new application. |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 166 | EventEntry* mNextUnblockedEvent GUARDED_BY(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 167 | |
Tiger Huang | 85b8c5e | 2019-01-17 18:34:54 +0800 | [diff] [blame] | 168 | sp<InputWindowHandle> findTouchedWindowAtLocked(int32_t displayId, int32_t x, int32_t y, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 169 | bool addOutsideTargets = false, |
| 170 | bool addPortalWindows = false) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 171 | |
| 172 | // All registered connections mapped by channel file descriptor. |
Siarhei Vishniakou | 146ecfd | 2019-07-29 16:04:31 -0700 | [diff] [blame] | 173 | std::unordered_map<int, sp<Connection>> mConnectionsByFd GUARDED_BY(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 174 | |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 175 | struct IBinderHash { |
| 176 | std::size_t operator()(const sp<IBinder>& b) const { |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 177 | return std::hash<IBinder*>{}(b.get()); |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 178 | } |
| 179 | }; |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 180 | std::unordered_map<sp<IBinder>, sp<InputChannel>, IBinderHash> mInputChannelsByToken |
| 181 | GUARDED_BY(mLock); |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 182 | |
Michael Wright | 3dd60e2 | 2019-03-27 22:06:44 +0000 | [diff] [blame] | 183 | // Finds the display ID of the gesture monitor identified by the provided token. |
| 184 | std::optional<int32_t> findGestureMonitorDisplayByTokenLocked(const sp<IBinder>& token) |
| 185 | REQUIRES(mLock); |
| 186 | |
Siarhei Vishniakou | d0d71b6 | 2019-10-14 14:50:45 -0700 | [diff] [blame] | 187 | sp<Connection> getConnectionLocked(const sp<IBinder>& inputConnectionToken) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 188 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 189 | // Input channels that will receive a copy of all input events sent to the provided display. |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 190 | std::unordered_map<int32_t, std::vector<Monitor>> mGlobalMonitorsByDisplay GUARDED_BY(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 191 | |
Michael Wright | 3dd60e2 | 2019-03-27 22:06:44 +0000 | [diff] [blame] | 192 | // Input channels that will receive pointer events that start within the corresponding display. |
| 193 | // These are a bit special when compared to global monitors since they'll cause gesture streams |
| 194 | // to continue even when there isn't a touched window,and have the ability to steal the rest of |
| 195 | // the pointer stream in order to claim it for a system gesture. |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 196 | std::unordered_map<int32_t, std::vector<Monitor>> mGestureMonitorsByDisplay GUARDED_BY(mLock); |
Michael Wright | 3dd60e2 | 2019-03-27 22:06:44 +0000 | [diff] [blame] | 197 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 198 | // Event injection and synchronization. |
Siarhei Vishniakou | 443ad90 | 2019-03-06 17:25:41 -0800 | [diff] [blame] | 199 | std::condition_variable mInjectionResultAvailable; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 200 | bool hasInjectionPermission(int32_t injectorPid, int32_t injectorUid); |
Siarhei Vishniakou | 62683e8 | 2019-03-06 17:59:56 -0800 | [diff] [blame] | 201 | void setInjectionResult(EventEntry* entry, int32_t injectionResult); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 202 | |
Siarhei Vishniakou | 443ad90 | 2019-03-06 17:25:41 -0800 | [diff] [blame] | 203 | std::condition_variable mInjectionSyncFinished; |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 204 | void incrementPendingForegroundDispatches(EventEntry* entry); |
Siarhei Vishniakou | 62683e8 | 2019-03-06 17:59:56 -0800 | [diff] [blame] | 205 | void decrementPendingForegroundDispatches(EventEntry* entry); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 206 | |
| 207 | // Key repeat tracking. |
| 208 | struct KeyRepeatState { |
| 209 | KeyEntry* lastKeyEntry; // or null if no repeat |
| 210 | nsecs_t nextRepeatTime; |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 211 | } mKeyRepeatState GUARDED_BY(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 212 | |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 213 | void resetKeyRepeatLocked() REQUIRES(mLock); |
| 214 | KeyEntry* synthesizeKeyRepeatLocked(nsecs_t currentTime) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 215 | |
Michael Wright | 78f2444 | 2014-08-06 15:55:28 -0700 | [diff] [blame] | 216 | // Key replacement tracking |
| 217 | struct KeyReplacement { |
| 218 | int32_t keyCode; |
| 219 | int32_t deviceId; |
| 220 | bool operator==(const KeyReplacement& rhs) const { |
| 221 | return keyCode == rhs.keyCode && deviceId == rhs.deviceId; |
| 222 | } |
| 223 | bool operator<(const KeyReplacement& rhs) const { |
| 224 | return keyCode != rhs.keyCode ? keyCode < rhs.keyCode : deviceId < rhs.deviceId; |
| 225 | } |
| 226 | }; |
| 227 | // 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] | 228 | KeyedVector<KeyReplacement, int32_t> mReplacedKeys GUARDED_BY(mLock); |
Siarhei Vishniakou | 61fafdd | 2018-04-13 11:00:58 -0500 | [diff] [blame] | 229 | // Process certain Meta + Key combinations |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 230 | void accelerateMetaShortcuts(const int32_t deviceId, const int32_t action, int32_t& keyCode, |
| 231 | int32_t& metaState); |
Michael Wright | 78f2444 | 2014-08-06 15:55:28 -0700 | [diff] [blame] | 232 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 233 | // Deferred command processing. |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 234 | bool haveCommandsLocked() const REQUIRES(mLock); |
| 235 | bool runCommandsLockedInterruptible() REQUIRES(mLock); |
Siarhei Vishniakou | e7c94b9 | 2019-07-29 09:17:54 -0700 | [diff] [blame] | 236 | void postCommandLocked(std::unique_ptr<CommandEntry> commandEntry) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 237 | |
| 238 | // Input filter processing. |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 239 | bool shouldSendKeyToInputFilterLocked(const NotifyKeyArgs* args) REQUIRES(mLock); |
| 240 | bool shouldSendMotionToInputFilterLocked(const NotifyMotionArgs* args) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 241 | |
| 242 | // Inbound event processing. |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 243 | void drainInboundQueueLocked() REQUIRES(mLock); |
| 244 | void releasePendingEventLocked() REQUIRES(mLock); |
| 245 | void releaseInboundEventLocked(EventEntry* entry) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 246 | |
| 247 | // Dispatch state. |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 248 | bool mDispatchEnabled GUARDED_BY(mLock); |
| 249 | bool mDispatchFrozen GUARDED_BY(mLock); |
| 250 | bool mInputFilterEnabled GUARDED_BY(mLock); |
Siarhei Vishniakou | f3bc1aa | 2019-11-25 13:48:53 -0800 | [diff] [blame^] | 251 | bool mInTouchMode GUARDED_BY(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 252 | |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 253 | std::unordered_map<int32_t, std::vector<sp<InputWindowHandle>>> mWindowHandlesByDisplay |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 254 | GUARDED_BY(mLock); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 255 | // Get window handles by display, return an empty vector if not found. |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 256 | std::vector<sp<InputWindowHandle>> getWindowHandlesLocked(int32_t displayId) const |
| 257 | REQUIRES(mLock); |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 258 | sp<InputWindowHandle> getWindowHandleLocked(const sp<IBinder>& windowHandleToken) const |
| 259 | REQUIRES(mLock); |
| 260 | sp<InputChannel> getInputChannelLocked(const sp<IBinder>& windowToken) const REQUIRES(mLock); |
| 261 | bool hasWindowHandleLocked(const sp<InputWindowHandle>& windowHandle) const REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 262 | |
Siarhei Vishniakou | b3ad35c | 2019-04-05 10:50:52 -0700 | [diff] [blame] | 263 | /* |
| 264 | * Validate and update InputWindowHandles for a given display. |
| 265 | */ |
| 266 | void updateWindowHandlesForDisplayLocked( |
| 267 | const std::vector<sp<InputWindowHandle>>& inputWindowHandles, int32_t displayId) |
| 268 | REQUIRES(mLock); |
| 269 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 270 | // Focus tracking for keys, trackball, etc. |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 271 | std::unordered_map<int32_t, sp<InputWindowHandle>> mFocusedWindowHandlesByDisplay |
| 272 | GUARDED_BY(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 273 | |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 274 | KeyedVector<int32_t, TouchState> mTouchStatesByDisplay GUARDED_BY(mLock); |
| 275 | TouchState mTempTouchState GUARDED_BY(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 276 | |
Tiger Huang | 721e26f | 2018-07-24 22:26:19 +0800 | [diff] [blame] | 277 | // Focused applications. |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 278 | std::unordered_map<int32_t, sp<InputApplicationHandle>> mFocusedApplicationHandlesByDisplay |
| 279 | GUARDED_BY(mLock); |
Tiger Huang | 721e26f | 2018-07-24 22:26:19 +0800 | [diff] [blame] | 280 | |
| 281 | // Top focused display. |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 282 | int32_t mFocusedDisplayId GUARDED_BY(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 283 | |
| 284 | // Dispatcher state at time of last ANR. |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 285 | std::string mLastANRState GUARDED_BY(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 286 | |
| 287 | // Dispatch inbound events. |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 288 | bool dispatchConfigurationChangedLocked(nsecs_t currentTime, ConfigurationChangedEntry* entry) |
| 289 | REQUIRES(mLock); |
| 290 | bool dispatchDeviceResetLocked(nsecs_t currentTime, DeviceResetEntry* entry) REQUIRES(mLock); |
| 291 | bool dispatchKeyLocked(nsecs_t currentTime, KeyEntry* entry, DropReason* dropReason, |
| 292 | nsecs_t* nextWakeupTime) REQUIRES(mLock); |
| 293 | bool dispatchMotionLocked(nsecs_t currentTime, MotionEntry* entry, DropReason* dropReason, |
| 294 | nsecs_t* nextWakeupTime) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 295 | void dispatchEventLocked(nsecs_t currentTime, EventEntry* entry, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 296 | const std::vector<InputTarget>& inputTargets) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 297 | |
Siarhei Vishniakou | d277004 | 2019-10-29 11:08:14 -0700 | [diff] [blame] | 298 | void logOutboundKeyDetails(const char* prefix, const KeyEntry& entry); |
| 299 | void logOutboundMotionDetails(const char* prefix, const MotionEntry& entry); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 300 | |
| 301 | // Keeping track of ANR timeouts. |
| 302 | enum InputTargetWaitCause { |
| 303 | INPUT_TARGET_WAIT_CAUSE_NONE, |
| 304 | INPUT_TARGET_WAIT_CAUSE_SYSTEM_NOT_READY, |
| 305 | INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY, |
| 306 | }; |
| 307 | |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 308 | InputTargetWaitCause mInputTargetWaitCause GUARDED_BY(mLock); |
| 309 | nsecs_t mInputTargetWaitStartTime GUARDED_BY(mLock); |
| 310 | nsecs_t mInputTargetWaitTimeoutTime GUARDED_BY(mLock); |
| 311 | bool mInputTargetWaitTimeoutExpired GUARDED_BY(mLock); |
| 312 | sp<IBinder> mInputTargetWaitApplicationToken GUARDED_BY(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 313 | |
| 314 | // Contains the last window which received a hover event. |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 315 | sp<InputWindowHandle> mLastHoverWindowHandle GUARDED_BY(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 316 | |
| 317 | // Finding targets for input events. |
Siarhei Vishniakou | d277004 | 2019-10-29 11:08:14 -0700 | [diff] [blame] | 318 | int32_t handleTargetsNotReadyLocked(nsecs_t currentTime, const EventEntry& entry, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 319 | const sp<InputApplicationHandle>& applicationHandle, |
| 320 | const sp<InputWindowHandle>& windowHandle, |
| 321 | nsecs_t* nextWakeupTime, const char* reason) |
| 322 | REQUIRES(mLock); |
Robert Carr | 803535b | 2018-08-02 16:38:15 -0700 | [diff] [blame] | 323 | |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 324 | void removeWindowByTokenLocked(const sp<IBinder>& token) REQUIRES(mLock); |
Robert Carr | 803535b | 2018-08-02 16:38:15 -0700 | [diff] [blame] | 325 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 326 | void resumeAfterTargetsNotReadyTimeoutLocked(nsecs_t newTimeout, |
Siarhei Vishniakou | d0d71b6 | 2019-10-14 14:50:45 -0700 | [diff] [blame] | 327 | const sp<IBinder>& inputConnectionToken) |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 328 | REQUIRES(mLock); |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 329 | nsecs_t getTimeSpentWaitingForApplicationLocked(nsecs_t currentTime) REQUIRES(mLock); |
| 330 | void resetANRTimeoutsLocked() REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 331 | |
Siarhei Vishniakou | d277004 | 2019-10-29 11:08:14 -0700 | [diff] [blame] | 332 | int32_t getTargetDisplayId(const EventEntry& entry); |
| 333 | int32_t findFocusedWindowTargetsLocked(nsecs_t currentTime, const EventEntry& entry, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 334 | std::vector<InputTarget>& inputTargets, |
| 335 | nsecs_t* nextWakeupTime) REQUIRES(mLock); |
Siarhei Vishniakou | d277004 | 2019-10-29 11:08:14 -0700 | [diff] [blame] | 336 | int32_t findTouchedWindowTargetsLocked(nsecs_t currentTime, const MotionEntry& entry, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 337 | std::vector<InputTarget>& inputTargets, |
| 338 | nsecs_t* nextWakeupTime, |
| 339 | bool* outConflictingPointerActions) REQUIRES(mLock); |
| 340 | std::vector<TouchedMonitor> findTouchedGestureMonitorsLocked( |
| 341 | int32_t displayId, const std::vector<sp<InputWindowHandle>>& portalWindows) |
| 342 | REQUIRES(mLock); |
Michael Wright | 3dd60e2 | 2019-03-27 22:06:44 +0000 | [diff] [blame] | 343 | void addGestureMonitors(const std::vector<Monitor>& monitors, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 344 | std::vector<TouchedMonitor>& outTouchedMonitors, float xOffset = 0, |
| 345 | float yOffset = 0); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 346 | |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 347 | void addWindowTargetLocked(const sp<InputWindowHandle>& windowHandle, int32_t targetFlags, |
| 348 | BitSet32 pointerIds, std::vector<InputTarget>& inputTargets) |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 349 | REQUIRES(mLock); |
Michael Wright | 3dd60e2 | 2019-03-27 22:06:44 +0000 | [diff] [blame] | 350 | void addMonitoringTargetLocked(const Monitor& monitor, float xOffset, float yOffset, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 351 | std::vector<InputTarget>& inputTargets) REQUIRES(mLock); |
| 352 | void addGlobalMonitoringTargetsLocked(std::vector<InputTarget>& inputTargets, int32_t displayId, |
| 353 | float xOffset = 0, float yOffset = 0) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 354 | |
Siarhei Vishniakou | d277004 | 2019-10-29 11:08:14 -0700 | [diff] [blame] | 355 | void pokeUserActivityLocked(const EventEntry& eventEntry) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 356 | bool checkInjectionPermission(const sp<InputWindowHandle>& windowHandle, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 357 | const InjectionState* injectionState); |
| 358 | bool isWindowObscuredAtPointLocked(const sp<InputWindowHandle>& windowHandle, int32_t x, |
| 359 | int32_t y) const REQUIRES(mLock); |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 360 | bool isWindowObscuredLocked(const sp<InputWindowHandle>& windowHandle) const REQUIRES(mLock); |
| 361 | std::string getApplicationWindowLabel(const sp<InputApplicationHandle>& applicationHandle, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 362 | const sp<InputWindowHandle>& windowHandle); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 363 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 364 | std::string checkWindowReadyForMoreInputLocked(nsecs_t currentTime, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 365 | const sp<InputWindowHandle>& windowHandle, |
Siarhei Vishniakou | d277004 | 2019-10-29 11:08:14 -0700 | [diff] [blame] | 366 | const EventEntry& eventEntry, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 367 | const char* targetType) REQUIRES(mLock); |
Jeff Brown | ffb4977 | 2014-10-10 19:01:34 -0700 | [diff] [blame] | 368 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 369 | // Manage the dispatch cycle for a single connection. |
| 370 | // These methods are deliberately not Interruptible because doing all of the work |
| 371 | // with the mutex held makes it easier to ensure that connection invariants are maintained. |
| 372 | // If needed, the methods post commands to run later once the critical bits are done. |
| 373 | void prepareDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 374 | EventEntry* eventEntry, const InputTarget* inputTarget) |
| 375 | REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 376 | void enqueueDispatchEntriesLocked(nsecs_t currentTime, const sp<Connection>& connection, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 377 | EventEntry* eventEntry, const InputTarget* inputTarget) |
| 378 | REQUIRES(mLock); |
| 379 | void enqueueDispatchEntryLocked(const sp<Connection>& connection, EventEntry* eventEntry, |
| 380 | const InputTarget* inputTarget, int32_t dispatchMode) |
chaviw | 8c9cf54 | 2019-03-25 13:02:48 -0700 | [diff] [blame] | 381 | REQUIRES(mLock); |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 382 | void startDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection) |
| 383 | REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 384 | void finishDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 385 | uint32_t seq, bool handled) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 386 | void abortBrokenDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 387 | bool notify) REQUIRES(mLock); |
Siarhei Vishniakou | 13bda6c | 2019-07-29 08:34:33 -0700 | [diff] [blame] | 388 | void drainDispatchQueue(std::deque<DispatchEntry*>& queue); |
Siarhei Vishniakou | 62683e8 | 2019-03-06 17:59:56 -0800 | [diff] [blame] | 389 | void releaseDispatchEntry(DispatchEntry* dispatchEntry); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 390 | static int handleReceiveCallback(int fd, int events, void* data); |
chaviw | 8c9cf54 | 2019-03-25 13:02:48 -0700 | [diff] [blame] | 391 | // The action sent should only be of type AMOTION_EVENT_* |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 392 | void dispatchPointerDownOutsideFocus(uint32_t source, int32_t action, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 393 | const sp<IBinder>& newToken) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 394 | |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 395 | void synthesizeCancelationEventsForAllConnectionsLocked(const CancelationOptions& options) |
| 396 | REQUIRES(mLock); |
| 397 | void synthesizeCancelationEventsForMonitorsLocked(const CancelationOptions& options) |
| 398 | REQUIRES(mLock); |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 399 | void synthesizeCancelationEventsForMonitorsLocked( |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 400 | const CancelationOptions& options, |
Michael Wright | 3dd60e2 | 2019-03-27 22:06:44 +0000 | [diff] [blame] | 401 | std::unordered_map<int32_t, std::vector<Monitor>>& monitorsByDisplay) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 402 | void synthesizeCancelationEventsForInputChannelLocked(const sp<InputChannel>& channel, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 403 | const CancelationOptions& options) |
| 404 | REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 405 | void synthesizeCancelationEventsForConnectionLocked(const sp<Connection>& connection, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 406 | const CancelationOptions& options) |
| 407 | REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 408 | |
| 409 | // Splitting motion events across windows. |
Siarhei Vishniakou | d277004 | 2019-10-29 11:08:14 -0700 | [diff] [blame] | 410 | MotionEntry* splitMotionEvent(const MotionEntry& originalMotionEntry, BitSet32 pointerIds); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 411 | |
| 412 | // Reset and drop everything the dispatcher is doing. |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 413 | void resetAndDropEverythingLocked(const char* reason) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 414 | |
| 415 | // Dump state. |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 416 | void dumpDispatchStateLocked(std::string& dump) REQUIRES(mLock); |
Michael Wright | 3dd60e2 | 2019-03-27 22:06:44 +0000 | [diff] [blame] | 417 | void dumpMonitors(std::string& dump, const std::vector<Monitor>& monitors); |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 418 | void logDispatchStateLocked() REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 419 | |
| 420 | // Registration. |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 421 | void removeMonitorChannelLocked(const sp<InputChannel>& inputChannel) REQUIRES(mLock); |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 422 | void removeMonitorChannelLocked( |
| 423 | const sp<InputChannel>& inputChannel, |
| 424 | std::unordered_map<int32_t, std::vector<Monitor>>& monitorsByDisplay) REQUIRES(mLock); |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 425 | status_t unregisterInputChannelLocked(const sp<InputChannel>& inputChannel, bool notify) |
| 426 | REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 427 | |
| 428 | // Interesting events that we might like to log or tell the framework about. |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 429 | void onDispatchCycleFinishedLocked(nsecs_t currentTime, const sp<Connection>& connection, |
| 430 | uint32_t seq, bool handled) REQUIRES(mLock); |
| 431 | void onDispatchCycleBrokenLocked(nsecs_t currentTime, const sp<Connection>& connection) |
| 432 | REQUIRES(mLock); |
chaviw | 0c06c6e | 2019-01-09 13:27:07 -0800 | [diff] [blame] | 433 | void onFocusChangedLocked(const sp<InputWindowHandle>& oldFocus, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 434 | const sp<InputWindowHandle>& newFocus) REQUIRES(mLock); |
| 435 | void onANRLocked(nsecs_t currentTime, const sp<InputApplicationHandle>& applicationHandle, |
| 436 | const sp<InputWindowHandle>& windowHandle, nsecs_t eventTime, |
| 437 | nsecs_t waitStartTime, const char* reason) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 438 | |
| 439 | // Outbound policy interactions. |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 440 | void doNotifyConfigurationChangedLockedInterruptible(CommandEntry* commandEntry) |
| 441 | REQUIRES(mLock); |
| 442 | void doNotifyInputChannelBrokenLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock); |
| 443 | void doNotifyFocusChangedLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock); |
| 444 | void doNotifyANRLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock); |
| 445 | void doInterceptKeyBeforeDispatchingLockedInterruptible(CommandEntry* commandEntry) |
| 446 | REQUIRES(mLock); |
| 447 | void doDispatchCycleFinishedLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 448 | bool afterKeyEventLockedInterruptible(const sp<Connection>& connection, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 449 | DispatchEntry* dispatchEntry, KeyEntry* keyEntry, |
| 450 | bool handled) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 451 | bool afterMotionEventLockedInterruptible(const sp<Connection>& connection, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 452 | DispatchEntry* dispatchEntry, MotionEntry* motionEntry, |
| 453 | bool handled) REQUIRES(mLock); |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 454 | void doPokeUserActivityLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock); |
Siarhei Vishniakou | 9757f78 | 2019-10-29 12:53:08 -0700 | [diff] [blame] | 455 | KeyEvent createKeyEvent(const KeyEntry& entry); |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 456 | void doOnPointerDownOutsideFocusLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 457 | |
| 458 | // Statistics gathering. |
Siarhei Vishniakou | de4bf15 | 2019-08-16 11:12:52 -0500 | [diff] [blame] | 459 | static constexpr std::chrono::duration TOUCH_STATS_REPORT_PERIOD = 5min; |
| 460 | LatencyStatistics mTouchStatistics{TOUCH_STATS_REPORT_PERIOD}; |
| 461 | |
| 462 | void reportTouchEventForStatistics(const MotionEntry& entry); |
Siarhei Vishniakou | d277004 | 2019-10-29 11:08:14 -0700 | [diff] [blame] | 463 | void updateDispatchStatistics(nsecs_t currentTime, const EventEntry& entry, |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 464 | int32_t injectionResult, nsecs_t timeSpentWaitingForApplication); |
Siarhei Vishniakou | 61291d4 | 2019-02-11 18:13:20 -0800 | [diff] [blame] | 465 | void traceInboundQueueLengthLocked() REQUIRES(mLock); |
| 466 | void traceOutboundQueueLength(const sp<Connection>& connection); |
| 467 | void traceWaitQueueLength(const sp<Connection>& connection); |
Prabir Pradhan | f93562f | 2018-11-29 12:13:37 -0800 | [diff] [blame] | 468 | |
Prabir Pradhan | 79a4f0c | 2019-01-09 11:24:01 -0800 | [diff] [blame] | 469 | sp<InputReporterInterface> mReporter; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 470 | }; |
| 471 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 472 | } // namespace android::inputdispatcher |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 473 | |
| 474 | #endif // _UI_INPUT_DISPATCHER_H |