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