blob: dccbbb1d00af2fc56acd85c6bb6c324e7dcb7969 [file] [log] [blame]
Michael Wrightd02c5b62014-02-10 15:10:22 -08001/*
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 Vishniakoue4623042020-03-25 16:16:40 -070020#include "AnrTracker.h"
Garfield Tane84e6f92019-08-29 17:28:41 -070021#include "CancelationOptions.h"
arthurhung6d4bed92021-03-17 11:59:33 +080022#include "DragState.h"
Garfield Tane84e6f92019-08-29 17:28:41 -070023#include "Entry.h"
Vishnu Nairc519ff72021-01-21 08:23:08 -080024#include "FocusResolver.h"
Garfield Tane84e6f92019-08-29 17:28:41 -070025#include "InjectionState.h"
26#include "InputDispatcherConfiguration.h"
27#include "InputDispatcherInterface.h"
28#include "InputDispatcherPolicyInterface.h"
29#include "InputState.h"
30#include "InputTarget.h"
Prabir Pradhan5a57cff2019-10-31 18:40:33 -070031#include "InputThread.h"
Garfield Tane84e6f92019-08-29 17:28:41 -070032#include "Monitor.h"
33#include "TouchState.h"
34#include "TouchedWindow.h"
35
chaviw09c8d2d2020-08-24 15:48:26 -070036#include <attestation/HmacKeyManager.h>
Siarhei Vishniakou2508b872020-12-03 16:33:53 -100037#include <com/android/internal/compat/IPlatformCompatNative.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080038#include <input/Input.h>
Robert Carr3720ed02018-08-08 16:08:27 -070039#include <input/InputApplication.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080040#include <input/InputTransport.h>
Robert Carr3720ed02018-08-08 16:08:27 -070041#include <input/InputWindow.h>
Garfield Tane84e6f92019-08-29 17:28:41 -070042#include <limits.h>
43#include <stddef.h>
Michael Wright3dd60e22019-03-27 22:06:44 +000044#include <ui/Region.h>
Garfield Tane84e6f92019-08-29 17:28:41 -070045#include <unistd.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080046#include <utils/BitSet.h>
Garfield Tan0fc2fa72019-08-29 17:22:15 -070047#include <utils/Looper.h>
48#include <utils/RefBase.h>
49#include <utils/Timers.h>
50#include <utils/threads.h>
51#include <condition_variable>
Garfield Tane84e6f92019-08-29 17:28:41 -070052#include <deque>
Garfield Tan0fc2fa72019-08-29 17:22:15 -070053#include <optional>
Robert Carr5c8a0262018-10-03 16:30:44 -070054#include <unordered_map>
Siarhei Vishniakou887b7d92020-06-18 00:43:02 +000055#include <unordered_set>
Michael Wrightd02c5b62014-02-10 15:10:22 -080056
Garfield Tane84e6f92019-08-29 17:28:41 -070057#include <InputListener.h>
58#include <InputReporterInterface.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080059
Garfield Tane84e6f92019-08-29 17:28:41 -070060namespace android::inputdispatcher {
Michael Wrightd02c5b62014-02-10 15:10:22 -080061
Garfield Tane84e6f92019-08-29 17:28:41 -070062class Connection;
Michael Wrightd02c5b62014-02-10 15:10:22 -080063
64/* Dispatches events to input targets. Some functions of the input dispatcher, such as
65 * identifying input targets, are controlled by a separate policy object.
66 *
67 * IMPORTANT INVARIANT:
68 * Because the policy can potentially block or cause re-entrance into the input dispatcher,
69 * the input dispatcher never calls into the policy while holding its internal locks.
70 * The implementation is also carefully designed to recover from scenarios such as an
71 * input channel becoming unregistered while identifying input targets or processing timeouts.
72 *
73 * Methods marked 'Locked' must be called with the lock acquired.
74 *
75 * Methods marked 'LockedInterruptible' must be called with the lock acquired but
76 * may during the course of their execution release the lock, call into the policy, and
77 * then reacquire the lock. The caller is responsible for recovering gracefully.
78 *
79 * A 'LockedInterruptible' method may called a 'Locked' method, but NOT vice-versa.
80 */
Garfield Tane84e6f92019-08-29 17:28:41 -070081class InputDispatcher : public android::InputDispatcherInterface {
Michael Wrightd02c5b62014-02-10 15:10:22 -080082protected:
Siarhei Vishniakoud0c6bc82021-03-13 03:14:52 +000083 ~InputDispatcher() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -080084
85public:
86 explicit InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy);
87
Siarhei Vishniakoud0c6bc82021-03-13 03:14:52 +000088 void dump(std::string& dump) override;
89 void monitor() override;
90 bool waitForIdle() override;
91 status_t start() override;
92 status_t stop() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -080093
Siarhei Vishniakoud0c6bc82021-03-13 03:14:52 +000094 void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override;
95 void notifyKey(const NotifyKeyArgs* args) override;
96 void notifyMotion(const NotifyMotionArgs* args) override;
97 void notifySwitch(const NotifySwitchArgs* args) override;
98 void notifySensor(const NotifySensorArgs* args) override;
99 void notifyVibratorState(const NotifyVibratorStateArgs* args) override;
100 void notifyDeviceReset(const NotifyDeviceResetArgs* args) override;
101 void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) override;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800102
Siarhei Vishniakoud0c6bc82021-03-13 03:14:52 +0000103 android::os::InputEventInjectionResult injectInputEvent(
Siarhei Vishniakouae6229e2019-12-30 16:23:19 -0800104 const InputEvent* event, int32_t injectorPid, int32_t injectorUid,
105 android::os::InputEventInjectionSync syncMode, std::chrono::milliseconds timeout,
106 uint32_t policyFlags) override;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800107
Siarhei Vishniakoud0c6bc82021-03-13 03:14:52 +0000108 std::unique_ptr<VerifiedInputEvent> verifyInputEvent(const InputEvent& event) override;
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -0800109
Siarhei Vishniakoud0c6bc82021-03-13 03:14:52 +0000110 void setInputWindows(const std::unordered_map<int32_t, std::vector<sp<InputWindowHandle>>>&
111 handlesPerDisplay) override;
112 void setFocusedApplication(
Chris Yea209fde2020-07-22 13:54:51 -0700113 int32_t displayId,
114 const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) override;
Siarhei Vishniakoud0c6bc82021-03-13 03:14:52 +0000115 void setFocusedDisplay(int32_t displayId) override;
116 void setInputDispatchMode(bool enabled, bool frozen) override;
117 void setInputFilterEnabled(bool enabled) override;
118 void setInTouchMode(bool inTouchMode) override;
119 void setMaximumObscuringOpacityForTouch(float opacity) override;
120 void setBlockUntrustedTouchesMode(android::os::BlockUntrustedTouchesMode mode) override;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800121
Siarhei Vishniakoud0c6bc82021-03-13 03:14:52 +0000122 bool transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken,
123 bool isDragDrop = false) override;
124 bool transferTouch(const sp<IBinder>& destChannelToken) override;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800125
Siarhei Vishniakoud0c6bc82021-03-13 03:14:52 +0000126 base::Result<std::unique_ptr<InputChannel>> createInputChannel(
Garfield Tan15601662020-09-22 15:32:38 -0700127 const std::string& name) override;
Siarhei Vishniakoud0c6bc82021-03-13 03:14:52 +0000128 void setFocusedWindow(const FocusRequest&) override;
129 base::Result<std::unique_ptr<InputChannel>> createInputMonitor(int32_t displayId,
130 bool isGestureMonitor,
131 const std::string& name,
132 int32_t pid) override;
133 status_t removeInputChannel(const sp<IBinder>& connectionToken) override;
134 status_t pilferPointers(const sp<IBinder>& token) override;
135 void requestPointerCapture(const sp<IBinder>& windowToken, bool enabled) override;
136 bool flushSensor(int deviceId, InputDeviceSensorType sensorType) override;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800137
chaviw09c8d2d2020-08-24 15:48:26 -0700138 std::array<uint8_t, 32> sign(const VerifiedInputEvent& event) const;
139
Michael Wrightd02c5b62014-02-10 15:10:22 -0800140private:
Siarhei Vishniakou0fb1a0e2019-10-22 11:23:36 -0700141 enum class DropReason {
142 NOT_DROPPED,
143 POLICY,
144 APP_SWITCH,
145 DISABLED,
146 BLOCKED,
147 STALE,
Prabir Pradhan99987712020-11-10 18:43:05 -0800148 NO_POINTER_CAPTURE,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800149 };
150
Prabir Pradhan5a57cff2019-10-31 18:40:33 -0700151 std::unique_ptr<InputThread> mThread;
Prabir Pradhan3608aad2019-10-02 17:08:26 -0700152
Michael Wrightd02c5b62014-02-10 15:10:22 -0800153 sp<InputDispatcherPolicyInterface> mPolicy;
Garfield Tane84e6f92019-08-29 17:28:41 -0700154 android::InputDispatcherConfiguration mConfig;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800155
Siarhei Vishniakou443ad902019-03-06 17:25:41 -0800156 std::mutex mLock;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800157
Siarhei Vishniakou443ad902019-03-06 17:25:41 -0800158 std::condition_variable mDispatcherIsAlive;
Siarhei Vishniakou2bfa9052019-11-21 18:10:54 -0800159 std::condition_variable mDispatcherEnteredIdle;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800160
161 sp<Looper> mLooper;
162
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700163 std::shared_ptr<EventEntry> mPendingEvent GUARDED_BY(mLock);
164 std::deque<std::shared_ptr<EventEntry>> mInboundQueue GUARDED_BY(mLock);
165 std::deque<std::shared_ptr<EventEntry>> mRecentQueue GUARDED_BY(mLock);
Siarhei Vishniakoue7c94b92019-07-29 09:17:54 -0700166 std::deque<std::unique_ptr<CommandEntry>> mCommandQueue GUARDED_BY(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800167
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800168 DropReason mLastDropReason GUARDED_BY(mLock);
Michael Wright3a981722015-06-10 15:26:13 +0100169
Garfield Tan1c7bc862020-01-28 13:24:04 -0800170 const IdGenerator mIdGenerator;
171
Prabir Pradhan3608aad2019-10-02 17:08:26 -0700172 // With each iteration, InputDispatcher nominally processes one queued event,
173 // a timeout, or a response from an input consumer.
174 // This method should only be called on the input dispatcher's own thread.
175 void dispatchOnce();
176
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800177 void dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800178
179 // Enqueues an inbound event. Returns true if mLooper->wake() should be called.
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700180 bool enqueueInboundEventLocked(std::unique_ptr<EventEntry> entry) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800181
182 // Cleans up input state when dropping an inbound event.
Siarhei Vishniakoud2770042019-10-29 11:08:14 -0700183 void dropInboundEventLocked(const EventEntry& entry, DropReason dropReason) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800184
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100185 // Enqueues a focus event.
Vishnu Nairad321cd2020-08-20 16:40:21 -0700186 void enqueueFocusEventLocked(const sp<IBinder>& windowToken, bool hasFocus,
Vishnu Nairc519ff72021-01-21 08:23:08 -0800187 const std::string& reason) REQUIRES(mLock);
arthurhungb89ccb02020-12-30 16:19:01 +0800188 // Enqueues a drag event.
189 void enqueueDragEventLocked(const sp<InputWindowHandle>& windowToken, bool isExiting,
190 const MotionEntry& motionEntry) REQUIRES(mLock);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100191
Michael Wrightd02c5b62014-02-10 15:10:22 -0800192 // Adds an event to a queue of recent events for debugging purposes.
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700193 void addRecentEventLocked(std::shared_ptr<EventEntry> entry) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800194
195 // App switch latency optimization.
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800196 bool mAppSwitchSawKeyDown GUARDED_BY(mLock);
197 nsecs_t mAppSwitchDueTime GUARDED_BY(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800198
Siarhei Vishniakoud2770042019-10-29 11:08:14 -0700199 bool isAppSwitchKeyEvent(const KeyEntry& keyEntry);
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800200 bool isAppSwitchPendingLocked() REQUIRES(mLock);
201 void resetPendingAppSwitchLocked(bool handled) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800202
Michael Wrightd02c5b62014-02-10 15:10:22 -0800203 // Blocked event latency optimization. Drops old events when the user intends
204 // to transfer focus to a new application.
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700205 std::shared_ptr<EventEntry> mNextUnblockedEvent GUARDED_BY(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800206
Tiger Huang85b8c5e2019-01-17 18:34:54 +0800207 sp<InputWindowHandle> findTouchedWindowAtLocked(int32_t displayId, int32_t x, int32_t y,
Siarhei Vishniakou1ea3cf12020-03-24 19:50:03 -0700208 TouchState* touchState,
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700209 bool addOutsideTargets = false,
arthurhungb89ccb02020-12-30 16:19:01 +0800210 bool addPortalWindows = false,
211 bool ignoreDragWindow = false) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800212
Siarhei Vishniakouffaa2b12020-05-26 21:43:02 -0700213 sp<Connection> getConnectionLocked(const sp<IBinder>& inputConnectionToken) const
214 REQUIRES(mLock);
215
Siarhei Vishniakouad991402020-10-28 11:40:09 -0500216 std::string getConnectionNameLocked(const sp<IBinder>& connectionToken) const REQUIRES(mLock);
217
Siarhei Vishniakouffaa2b12020-05-26 21:43:02 -0700218 void removeConnectionLocked(const sp<Connection>& connection) REQUIRES(mLock);
219
Prabir Pradhan6a9a8312021-04-23 11:59:31 -0700220 template <typename T>
221 struct StrongPointerHash {
222 std::size_t operator()(const sp<T>& b) const { return std::hash<T*>{}(b.get()); }
Robert Carr5c8a0262018-10-03 16:30:44 -0700223 };
Siarhei Vishniakouae02a1f2021-05-01 23:14:04 +0000224
225 // All registered connections mapped by input channel token.
226 std::unordered_map<sp<IBinder>, sp<Connection>, StrongPointerHash<IBinder>> mConnectionsByToken
227 GUARDED_BY(mLock);
Robert Carr5c8a0262018-10-03 16:30:44 -0700228
Michael Wright3dd60e22019-03-27 22:06:44 +0000229 // Finds the display ID of the gesture monitor identified by the provided token.
230 std::optional<int32_t> findGestureMonitorDisplayByTokenLocked(const sp<IBinder>& token)
231 REQUIRES(mLock);
Siarhei Vishniakou3c63fa42020-12-15 02:59:54 +0000232 // Find a monitor pid by the provided token.
233 std::optional<int32_t> findMonitorPidByTokenLocked(const sp<IBinder>& token) REQUIRES(mLock);
Michael Wright3dd60e22019-03-27 22:06:44 +0000234
Arthur Hung2fbf37f2018-09-13 18:16:41 +0800235 // Input channels that will receive a copy of all input events sent to the provided display.
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700236 std::unordered_map<int32_t, std::vector<Monitor>> mGlobalMonitorsByDisplay GUARDED_BY(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800237
Michael Wright3dd60e22019-03-27 22:06:44 +0000238 // Input channels that will receive pointer events that start within the corresponding display.
239 // These are a bit special when compared to global monitors since they'll cause gesture streams
240 // to continue even when there isn't a touched window,and have the ability to steal the rest of
241 // the pointer stream in order to claim it for a system gesture.
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700242 std::unordered_map<int32_t, std::vector<Monitor>> mGestureMonitorsByDisplay GUARDED_BY(mLock);
Michael Wright3dd60e22019-03-27 22:06:44 +0000243
Edgar Arriaga3d61bc12020-04-16 18:46:48 -0700244 const HmacKeyManager mHmacKeyManager;
245 const std::array<uint8_t, 32> getSignature(const MotionEntry& motionEntry,
246 const DispatchEntry& dispatchEntry) const;
247 const std::array<uint8_t, 32> getSignature(const KeyEntry& keyEntry,
248 const DispatchEntry& dispatchEntry) const;
Gang Wange9087892020-01-07 12:17:14 -0500249
Michael Wrightd02c5b62014-02-10 15:10:22 -0800250 // Event injection and synchronization.
Siarhei Vishniakou443ad902019-03-06 17:25:41 -0800251 std::condition_variable mInjectionResultAvailable;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800252 bool hasInjectionPermission(int32_t injectorPid, int32_t injectorUid);
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700253 void setInjectionResult(EventEntry& entry,
Siarhei Vishniakouae6229e2019-12-30 16:23:19 -0800254 android::os::InputEventInjectionResult injectionResult);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800255
Siarhei Vishniakou443ad902019-03-06 17:25:41 -0800256 std::condition_variable mInjectionSyncFinished;
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700257 void incrementPendingForegroundDispatches(EventEntry& entry);
258 void decrementPendingForegroundDispatches(EventEntry& entry);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800259
260 // Key repeat tracking.
261 struct KeyRepeatState {
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700262 std::shared_ptr<KeyEntry> lastKeyEntry; // or null if no repeat
Michael Wrightd02c5b62014-02-10 15:10:22 -0800263 nsecs_t nextRepeatTime;
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800264 } mKeyRepeatState GUARDED_BY(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800265
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800266 void resetKeyRepeatLocked() REQUIRES(mLock);
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700267 std::shared_ptr<KeyEntry> synthesizeKeyRepeatLocked(nsecs_t currentTime) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800268
Michael Wright78f24442014-08-06 15:55:28 -0700269 // Key replacement tracking
270 struct KeyReplacement {
271 int32_t keyCode;
272 int32_t deviceId;
273 bool operator==(const KeyReplacement& rhs) const {
274 return keyCode == rhs.keyCode && deviceId == rhs.deviceId;
275 }
Siarhei Vishniakoubde3d9e2020-03-24 19:05:54 -0700276 };
277 struct KeyReplacementHash {
278 size_t operator()(const KeyReplacement& key) const {
279 return std::hash<int32_t>()(key.keyCode) ^ (std::hash<int32_t>()(key.deviceId) << 1);
Michael Wright78f24442014-08-06 15:55:28 -0700280 }
281 };
282 // Maps the key code replaced, device id tuple to the key code it was replaced with
Siarhei Vishniakoubde3d9e2020-03-24 19:05:54 -0700283 std::unordered_map<KeyReplacement, int32_t, KeyReplacementHash> mReplacedKeys GUARDED_BY(mLock);
Siarhei Vishniakou61fafdd2018-04-13 11:00:58 -0500284 // Process certain Meta + Key combinations
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700285 void accelerateMetaShortcuts(const int32_t deviceId, const int32_t action, int32_t& keyCode,
286 int32_t& metaState);
Michael Wright78f24442014-08-06 15:55:28 -0700287
Michael Wrightd02c5b62014-02-10 15:10:22 -0800288 // Deferred command processing.
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800289 bool haveCommandsLocked() const REQUIRES(mLock);
290 bool runCommandsLockedInterruptible() REQUIRES(mLock);
Siarhei Vishniakoue7c94b92019-07-29 09:17:54 -0700291 void postCommandLocked(std::unique_ptr<CommandEntry> commandEntry) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800292
Siarhei Vishniakoue4623042020-03-25 16:16:40 -0700293 nsecs_t processAnrsLocked() REQUIRES(mLock);
Siarhei Vishniakou70622952020-07-30 11:17:23 -0500294 std::chrono::nanoseconds getDispatchingTimeoutLocked(const sp<IBinder>& token) REQUIRES(mLock);
Siarhei Vishniakoue4623042020-03-25 16:16:40 -0700295
Michael Wrightd02c5b62014-02-10 15:10:22 -0800296 // Input filter processing.
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800297 bool shouldSendKeyToInputFilterLocked(const NotifyKeyArgs* args) REQUIRES(mLock);
298 bool shouldSendMotionToInputFilterLocked(const NotifyMotionArgs* args) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800299
300 // Inbound event processing.
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800301 void drainInboundQueueLocked() REQUIRES(mLock);
302 void releasePendingEventLocked() REQUIRES(mLock);
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700303 void releaseInboundEventLocked(std::shared_ptr<EventEntry> entry) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800304
305 // Dispatch state.
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800306 bool mDispatchEnabled GUARDED_BY(mLock);
307 bool mDispatchFrozen GUARDED_BY(mLock);
308 bool mInputFilterEnabled GUARDED_BY(mLock);
Siarhei Vishniakouf3bc1aa2019-11-25 13:48:53 -0800309 bool mInTouchMode GUARDED_BY(mLock);
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100310 float mMaximumObscuringOpacityForTouch GUARDED_BY(mLock);
Siarhei Vishniakouae6229e2019-12-30 16:23:19 -0800311 android::os::BlockUntrustedTouchesMode mBlockUntrustedTouchesMode GUARDED_BY(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800312
Arthur Hung7c3ae9c2019-03-11 11:23:03 +0800313 std::unordered_map<int32_t, std::vector<sp<InputWindowHandle>>> mWindowHandlesByDisplay
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800314 GUARDED_BY(mLock);
Arthur Hung72d8dc32020-03-28 00:48:39 +0000315 void setInputWindowsLocked(const std::vector<sp<InputWindowHandle>>& inputWindowHandles,
316 int32_t displayId) REQUIRES(mLock);
Vishnu Nairad321cd2020-08-20 16:40:21 -0700317 // Get a reference to window handles by display, return an empty vector if not found.
318 const std::vector<sp<InputWindowHandle>>& getWindowHandlesLocked(int32_t displayId) const
Arthur Hung7c3ae9c2019-03-11 11:23:03 +0800319 REQUIRES(mLock);
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800320 sp<InputWindowHandle> getWindowHandleLocked(const sp<IBinder>& windowHandleToken) const
321 REQUIRES(mLock);
Vishnu Nairad321cd2020-08-20 16:40:21 -0700322
323 // Same function as above, but faster. Since displayId is provided, this avoids the need
324 // to loop through all displays.
325 sp<InputWindowHandle> getWindowHandleLocked(const sp<IBinder>& windowHandleToken,
326 int displayId) const REQUIRES(mLock);
Prabir Pradhan6a9a8312021-04-23 11:59:31 -0700327 sp<InputWindowHandle> getWindowHandleLocked(const sp<InputWindowHandle>& windowHandle) const
328 REQUIRES(mLock);
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -0500329 std::shared_ptr<InputChannel> getInputChannelLocked(const sp<IBinder>& windowToken) const
330 REQUIRES(mLock);
Vishnu Nairad321cd2020-08-20 16:40:21 -0700331 sp<InputWindowHandle> getFocusedWindowHandleLocked(int displayId) const REQUIRES(mLock);
Siarhei Vishniakoua2862a02020-07-20 16:36:46 -0500332 bool hasResponsiveConnectionLocked(InputWindowHandle& windowHandle) const REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800333
Siarhei Vishniakoub3ad35c2019-04-05 10:50:52 -0700334 /*
335 * Validate and update InputWindowHandles for a given display.
336 */
337 void updateWindowHandlesForDisplayLocked(
338 const std::vector<sp<InputWindowHandle>>& inputWindowHandles, int32_t displayId)
339 REQUIRES(mLock);
340
Siarhei Vishniakoubde3d9e2020-03-24 19:05:54 -0700341 std::unordered_map<int32_t, TouchState> mTouchStatesByDisplay GUARDED_BY(mLock);
arthurhung6d4bed92021-03-17 11:59:33 +0800342 std::unique_ptr<DragState> mDragState GUARDED_BY(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800343
Tiger Huang721e26f2018-07-24 22:26:19 +0800344 // Focused applications.
Chris Yea209fde2020-07-22 13:54:51 -0700345 std::unordered_map<int32_t, std::shared_ptr<InputApplicationHandle>>
346 mFocusedApplicationHandlesByDisplay GUARDED_BY(mLock);
Tiger Huang721e26f2018-07-24 22:26:19 +0800347
348 // Top focused display.
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800349 int32_t mFocusedDisplayId GUARDED_BY(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800350
Vishnu Nairc519ff72021-01-21 08:23:08 -0800351 // Keeps track of the focused window per display and determines focus changes.
352 FocusResolver mFocusResolver GUARDED_BY(mLock);
Prabir Pradhan99987712020-11-10 18:43:05 -0800353 // Whether the focused window on the focused display has requested Pointer Capture.
354 // The state of this variable should always be in sync with the state of Pointer Capture in the
355 // policy, which is updated through setPointerCaptureLocked(enabled).
356 bool mFocusedWindowRequestedPointerCapture GUARDED_BY(mLock);
357
358 // The window token that has Pointer Capture.
359 // This should be in sync with PointerCaptureChangedEvents dispatched to the input channel.
360 sp<IBinder> mWindowTokenWithPointerCapture GUARDED_BY(mLock);
361
362 // Disable Pointer Capture as a result of loss of window focus.
363 void disablePointerCaptureForcedLocked() REQUIRES(mLock);
364
365 // Set the Pointer Capture state in the Policy.
366 void setPointerCaptureLocked(bool enabled) REQUIRES(mLock);
367
Michael Wrightd02c5b62014-02-10 15:10:22 -0800368 // Dispatcher state at time of last ANR.
Siarhei Vishniakoub1a16272020-05-06 16:09:19 -0700369 std::string mLastAnrState GUARDED_BY(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800370
Siarhei Vishniakou887b7d92020-06-18 00:43:02 +0000371 // The connection tokens of the channels that the user last interacted, for debugging
Prabir Pradhan6a9a8312021-04-23 11:59:31 -0700372 std::unordered_set<sp<IBinder>, StrongPointerHash<IBinder>> mInteractionConnectionTokens
373 GUARDED_BY(mLock);
Siarhei Vishniakou887b7d92020-06-18 00:43:02 +0000374 void updateInteractionTokensLocked(const EventEntry& entry,
375 const std::vector<InputTarget>& targets) REQUIRES(mLock);
376
Michael Wrightd02c5b62014-02-10 15:10:22 -0800377 // Dispatch inbound events.
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700378 bool dispatchConfigurationChangedLocked(nsecs_t currentTime,
379 const ConfigurationChangedEntry& entry) REQUIRES(mLock);
380 bool dispatchDeviceResetLocked(nsecs_t currentTime, const DeviceResetEntry& entry)
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700381 REQUIRES(mLock);
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700382 bool dispatchKeyLocked(nsecs_t currentTime, std::shared_ptr<KeyEntry> entry,
383 DropReason* dropReason, nsecs_t* nextWakeupTime) REQUIRES(mLock);
384 bool dispatchMotionLocked(nsecs_t currentTime, std::shared_ptr<MotionEntry> entry,
385 DropReason* dropReason, nsecs_t* nextWakeupTime) REQUIRES(mLock);
386 void dispatchFocusLocked(nsecs_t currentTime, std::shared_ptr<FocusEntry> entry)
387 REQUIRES(mLock);
Prabir Pradhan99987712020-11-10 18:43:05 -0800388 void dispatchPointerCaptureChangedLocked(
389 nsecs_t currentTime, const std::shared_ptr<PointerCaptureChangedEntry>& entry,
390 DropReason& dropReason) REQUIRES(mLock);
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700391 void dispatchEventLocked(nsecs_t currentTime, std::shared_ptr<EventEntry> entry,
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700392 const std::vector<InputTarget>& inputTargets) REQUIRES(mLock);
Chris Yef59a2f42020-10-16 12:55:26 -0700393 void dispatchSensorLocked(nsecs_t currentTime, std::shared_ptr<SensorEntry> entry,
394 DropReason* dropReason, nsecs_t* nextWakeupTime) REQUIRES(mLock);
arthurhungb89ccb02020-12-30 16:19:01 +0800395 void dispatchDragLocked(nsecs_t currentTime, std::shared_ptr<DragEntry> entry) REQUIRES(mLock);
Siarhei Vishniakoud2770042019-10-29 11:08:14 -0700396 void logOutboundKeyDetails(const char* prefix, const KeyEntry& entry);
397 void logOutboundMotionDetails(const char* prefix, const MotionEntry& entry);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800398
Siarhei Vishniakoue4623042020-03-25 16:16:40 -0700399 /**
400 * This field is set if there is no focused window, and we have an event that requires
401 * a focused window to be dispatched (for example, a KeyEvent).
402 * When this happens, we will wait until *mNoFocusedWindowTimeoutTime before
403 * dropping the event and raising an ANR for that application.
404 * This is useful if an application is slow to add a focused window.
405 */
406 std::optional<nsecs_t> mNoFocusedWindowTimeoutTime GUARDED_BY(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800407
Siarhei Vishniakoude1bc4a2020-05-26 22:39:43 -0700408 bool shouldPruneInboundQueueLocked(const MotionEntry& motionEntry) REQUIRES(mLock);
409
Siarhei Vishniakoue4623042020-03-25 16:16:40 -0700410 /**
411 * Time to stop waiting for the events to be processed while trying to dispatch a key.
412 * When this time expires, we just send the pending key event to the currently focused window,
413 * without waiting on other events to be processed first.
414 */
415 std::optional<nsecs_t> mKeyIsWaitingForEventsTimeout GUARDED_BY(mLock);
416 bool shouldWaitToSendKeyLocked(nsecs_t currentTime, const char* focusedWindowName)
417 REQUIRES(mLock);
418
419 /**
420 * The focused application at the time when no focused window was present.
421 * Used to raise an ANR when we have no focused window.
422 */
Chris Yea209fde2020-07-22 13:54:51 -0700423 std::shared_ptr<InputApplicationHandle> mAwaitedFocusedApplication GUARDED_BY(mLock);
Siarhei Vishniakouf56b2692020-09-08 19:43:33 -0500424 /**
425 * The displayId that the focused application is associated with.
426 */
427 int32_t mAwaitedApplicationDisplayId GUARDED_BY(mLock);
428 void processNoFocusedWindowAnrLocked() REQUIRES(mLock);
Siarhei Vishniakoue4623042020-03-25 16:16:40 -0700429
Vishnu Nair958da932020-08-21 17:12:37 -0700430 /**
Siarhei Vishniakou3c63fa42020-12-15 02:59:54 +0000431 * Tell policy about a window or a monitor that just became unresponsive. Starts ANR.
432 */
433 void processConnectionUnresponsiveLocked(const Connection& connection, std::string reason)
434 REQUIRES(mLock);
435 /**
436 * Tell policy about a window or a monitor that just became responsive.
437 */
438 void processConnectionResponsiveLocked(const Connection& connection) REQUIRES(mLock);
439
440 /**
441 * Post `doNotifyMonitorUnresponsiveLockedInterruptible` command.
442 */
443 void sendMonitorUnresponsiveCommandLocked(int32_t pid, std::string reason) REQUIRES(mLock);
444 /**
445 * Post `doNotifyWindowUnresponsiveLockedInterruptible` command.
446 */
447 void sendWindowUnresponsiveCommandLocked(sp<IBinder> connectionToken, std::string reason)
448 REQUIRES(mLock);
449 /**
450 * Post `doNotifyMonitorResponsiveLockedInterruptible` command.
451 */
452 void sendMonitorResponsiveCommandLocked(int32_t pid) REQUIRES(mLock);
453 /**
454 * Post `doNotifyWindowResponsiveLockedInterruptible` command.
455 */
456 void sendWindowResponsiveCommandLocked(sp<IBinder> connectionToken) REQUIRES(mLock);
457
Vishnu Nair958da932020-08-21 17:12:37 -0700458
Siarhei Vishniakoue4623042020-03-25 16:16:40 -0700459 // Optimization: AnrTracker is used to quickly find which connection is due for a timeout next.
460 // AnrTracker must be kept in-sync with all responsive connection.waitQueues.
461 // If a connection is not responsive, then the entries should not be added to the AnrTracker.
462 // Once a connection becomes unresponsive, its entries are removed from AnrTracker to
463 // prevent unneeded wakeups.
464 AnrTracker mAnrTracker GUARDED_BY(mLock);
Siarhei Vishniakoue4623042020-03-25 16:16:40 -0700465
Michael Wrightd02c5b62014-02-10 15:10:22 -0800466 // Contains the last window which received a hover event.
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800467 sp<InputWindowHandle> mLastHoverWindowHandle GUARDED_BY(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800468
Siarhei Vishniakoue4623042020-03-25 16:16:40 -0700469 void cancelEventsForAnrLocked(const sp<Connection>& connection) REQUIRES(mLock);
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800470 nsecs_t getTimeSpentWaitingForApplicationLocked(nsecs_t currentTime) REQUIRES(mLock);
Siarhei Vishniakoue4623042020-03-25 16:16:40 -0700471 // If a focused application changes, we should stop counting down the "no focused window" time,
472 // because we will have no way of knowing when the previous application actually added a window.
473 // This also means that we will miss cases like pulling down notification shade when the
474 // focused application does not have a focused window (no ANR will be raised if notification
475 // shade is pulled down while we are counting down the timeout).
476 void resetNoFocusedWindowTimeoutLocked() REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800477
Siarhei Vishniakoud2770042019-10-29 11:08:14 -0700478 int32_t getTargetDisplayId(const EventEntry& entry);
Siarhei Vishniakouae6229e2019-12-30 16:23:19 -0800479 android::os::InputEventInjectionResult findFocusedWindowTargetsLocked(
480 nsecs_t currentTime, const EventEntry& entry, std::vector<InputTarget>& inputTargets,
481 nsecs_t* nextWakeupTime) REQUIRES(mLock);
482 android::os::InputEventInjectionResult findTouchedWindowTargetsLocked(
483 nsecs_t currentTime, const MotionEntry& entry, std::vector<InputTarget>& inputTargets,
484 nsecs_t* nextWakeupTime, bool* outConflictingPointerActions) REQUIRES(mLock);
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700485 std::vector<TouchedMonitor> findTouchedGestureMonitorsLocked(
Siarhei Vishniakoue0fb6bd2020-04-13 11:40:37 -0700486 int32_t displayId, const std::vector<sp<InputWindowHandle>>& portalWindows) const
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700487 REQUIRES(mLock);
Siarhei Vishniakoue4623042020-03-25 16:16:40 -0700488 std::vector<TouchedMonitor> selectResponsiveMonitorsLocked(
489 const std::vector<TouchedMonitor>& gestureMonitors) const REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800490
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700491 void addWindowTargetLocked(const sp<InputWindowHandle>& windowHandle, int32_t targetFlags,
492 BitSet32 pointerIds, std::vector<InputTarget>& inputTargets)
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800493 REQUIRES(mLock);
Michael Wright3dd60e22019-03-27 22:06:44 +0000494 void addMonitoringTargetLocked(const Monitor& monitor, float xOffset, float yOffset,
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700495 std::vector<InputTarget>& inputTargets) REQUIRES(mLock);
496 void addGlobalMonitoringTargetsLocked(std::vector<InputTarget>& inputTargets, int32_t displayId,
497 float xOffset = 0, float yOffset = 0) REQUIRES(mLock);
Siarhei Vishniakoud2770042019-10-29 11:08:14 -0700498 void pokeUserActivityLocked(const EventEntry& eventEntry) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800499 bool checkInjectionPermission(const sp<InputWindowHandle>& windowHandle,
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700500 const InjectionState* injectionState);
arthurhungb89ccb02020-12-30 16:19:01 +0800501 // Enqueue a drag event if needed, and update the touch state.
502 // Uses findTouchedWindowTargetsLocked to make the decision
arthurhung6d4bed92021-03-17 11:59:33 +0800503 void addDragEventLocked(const MotionEntry& entry) REQUIRES(mLock);
504 void finishDragAndDrop(int32_t displayId, float x, float y) REQUIRES(mLock);
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100505
506 struct TouchOcclusionInfo {
507 bool hasBlockingOcclusion;
508 float obscuringOpacity;
509 std::string obscuringPackage;
510 int32_t obscuringUid;
Bernardo Rufino4bae0ac2020-10-14 18:33:46 +0000511 std::vector<std::string> debugInfo;
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100512 };
513
514 TouchOcclusionInfo computeTouchOcclusionInfoLocked(const sp<InputWindowHandle>& windowHandle,
515 int32_t x, int32_t y) const REQUIRES(mLock);
516 bool isTouchTrustedLocked(const TouchOcclusionInfo& occlusionInfo) const REQUIRES(mLock);
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700517 bool isWindowObscuredAtPointLocked(const sp<InputWindowHandle>& windowHandle, int32_t x,
518 int32_t y) const REQUIRES(mLock);
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800519 bool isWindowObscuredLocked(const sp<InputWindowHandle>& windowHandle) const REQUIRES(mLock);
Bernardo Rufino4bae0ac2020-10-14 18:33:46 +0000520 std::string dumpWindowForTouchOcclusion(const InputWindowInfo* info, bool isTouchWindow) const;
Siarhei Vishniakou234129c2020-10-22 22:28:12 -0500521 std::string getApplicationWindowLabel(const InputApplicationHandle* applicationHandle,
522 const sp<InputWindowHandle>& windowHandle);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800523
Michael Wrightd02c5b62014-02-10 15:10:22 -0800524 // Manage the dispatch cycle for a single connection.
525 // These methods are deliberately not Interruptible because doing all of the work
526 // with the mutex held makes it easier to ensure that connection invariants are maintained.
527 // If needed, the methods post commands to run later once the critical bits are done.
528 void prepareDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection,
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700529 std::shared_ptr<EventEntry>, const InputTarget& inputTarget)
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700530 REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800531 void enqueueDispatchEntriesLocked(nsecs_t currentTime, const sp<Connection>& connection,
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700532 std::shared_ptr<EventEntry>, const InputTarget& inputTarget)
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700533 REQUIRES(mLock);
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700534 void enqueueDispatchEntryLocked(const sp<Connection>& connection, std::shared_ptr<EventEntry>,
Siarhei Vishniakou5d6b6612020-01-08 16:03:04 -0800535 const InputTarget& inputTarget, int32_t dispatchMode)
chaviw8c9cf542019-03-25 13:02:48 -0700536 REQUIRES(mLock);
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800537 void startDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection)
538 REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800539 void finishDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection,
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000540 uint32_t seq, bool handled, nsecs_t consumeTime) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800541 void abortBrokenDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection,
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700542 bool notify) REQUIRES(mLock);
Siarhei Vishniakou13bda6c2019-07-29 08:34:33 -0700543 void drainDispatchQueue(std::deque<DispatchEntry*>& queue);
Siarhei Vishniakou62683e82019-03-06 17:59:56 -0800544 void releaseDispatchEntry(DispatchEntry* dispatchEntry);
Siarhei Vishniakouae02a1f2021-05-01 23:14:04 +0000545 int handleReceiveCallback(int events, sp<IBinder> connectionToken);
chaviw8c9cf542019-03-25 13:02:48 -0700546 // The action sent should only be of type AMOTION_EVENT_*
chaviwfd6d3512019-03-25 13:23:49 -0700547 void dispatchPointerDownOutsideFocus(uint32_t source, int32_t action,
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700548 const sp<IBinder>& newToken) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800549
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700550 void synthesizeCancelationEventsForAllConnectionsLocked(const CancelationOptions& options)
551 REQUIRES(mLock);
552 void synthesizeCancelationEventsForMonitorsLocked(const CancelationOptions& options)
553 REQUIRES(mLock);
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800554 void synthesizeCancelationEventsForMonitorsLocked(
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700555 const CancelationOptions& options,
Michael Wright3dd60e22019-03-27 22:06:44 +0000556 std::unordered_map<int32_t, std::vector<Monitor>>& monitorsByDisplay) REQUIRES(mLock);
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -0500557 void synthesizeCancelationEventsForInputChannelLocked(
558 const std::shared_ptr<InputChannel>& channel, const CancelationOptions& options)
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700559 REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800560 void synthesizeCancelationEventsForConnectionLocked(const sp<Connection>& connection,
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700561 const CancelationOptions& options)
562 REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800563
Svet Ganov5d3bc372020-01-26 23:11:07 -0800564 void synthesizePointerDownEventsForConnectionLocked(const sp<Connection>& connection)
565 REQUIRES(mLock);
566
Michael Wrightd02c5b62014-02-10 15:10:22 -0800567 // Splitting motion events across windows.
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700568 std::unique_ptr<MotionEntry> splitMotionEvent(const MotionEntry& originalMotionEntry,
569 BitSet32 pointerIds);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800570
571 // Reset and drop everything the dispatcher is doing.
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800572 void resetAndDropEverythingLocked(const char* reason) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800573
574 // Dump state.
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800575 void dumpDispatchStateLocked(std::string& dump) REQUIRES(mLock);
Michael Wright3dd60e22019-03-27 22:06:44 +0000576 void dumpMonitors(std::string& dump, const std::vector<Monitor>& monitors);
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800577 void logDispatchStateLocked() REQUIRES(mLock);
Prabir Pradhan99987712020-11-10 18:43:05 -0800578 std::string dumpPointerCaptureStateLocked() REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800579
580 // Registration.
Siarhei Vishniakouadefc3e2020-09-02 22:28:29 -0500581 void removeMonitorChannelLocked(const sp<IBinder>& connectionToken) REQUIRES(mLock);
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700582 void removeMonitorChannelLocked(
Siarhei Vishniakouadefc3e2020-09-02 22:28:29 -0500583 const sp<IBinder>& connectionToken,
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700584 std::unordered_map<int32_t, std::vector<Monitor>>& monitorsByDisplay) REQUIRES(mLock);
Garfield Tan15601662020-09-22 15:32:38 -0700585 status_t removeInputChannelLocked(const sp<IBinder>& connectionToken, bool notify)
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800586 REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800587
588 // Interesting events that we might like to log or tell the framework about.
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700589 void onDispatchCycleFinishedLocked(nsecs_t currentTime, const sp<Connection>& connection,
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000590 uint32_t seq, bool handled, nsecs_t consumeTime)
591 REQUIRES(mLock);
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700592 void onDispatchCycleBrokenLocked(nsecs_t currentTime, const sp<Connection>& connection)
593 REQUIRES(mLock);
Vishnu Nairc519ff72021-01-21 08:23:08 -0800594 void onFocusChangedLocked(const FocusResolver::FocusChanges& changes) REQUIRES(mLock);
Vishnu Nairad321cd2020-08-20 16:40:21 -0700595 void notifyFocusChangedLocked(const sp<IBinder>& oldFocus, const sp<IBinder>& newFocus)
596 REQUIRES(mLock);
arthurhungf452d0b2021-01-06 00:19:52 +0800597 void notifyDropWindowLocked(const sp<IBinder>& token, float x, float y) REQUIRES(mLock);
Siarhei Vishniakou3c63fa42020-12-15 02:59:54 +0000598 void onAnrLocked(const sp<Connection>& connection) REQUIRES(mLock);
Siarhei Vishniakou234129c2020-10-22 22:28:12 -0500599 void onAnrLocked(std::shared_ptr<InputApplicationHandle> application) REQUIRES(mLock);
Bernardo Rufino2e1f6512020-10-08 13:42:07 +0000600 void onUntrustedTouchLocked(const std::string& obscuringPackage) REQUIRES(mLock);
Siarhei Vishniakoue4623042020-03-25 16:16:40 -0700601 void updateLastAnrStateLocked(const sp<InputWindowHandle>& window, const std::string& reason)
602 REQUIRES(mLock);
Siarhei Vishniakou234129c2020-10-22 22:28:12 -0500603 void updateLastAnrStateLocked(const InputApplicationHandle& application,
Siarhei Vishniakoue4623042020-03-25 16:16:40 -0700604 const std::string& reason) REQUIRES(mLock);
605 void updateLastAnrStateLocked(const std::string& windowLabel, const std::string& reason)
606 REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800607
608 // Outbound policy interactions.
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800609 void doNotifyConfigurationChangedLockedInterruptible(CommandEntry* commandEntry)
610 REQUIRES(mLock);
611 void doNotifyInputChannelBrokenLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
612 void doNotifyFocusChangedLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
arthurhungf452d0b2021-01-06 00:19:52 +0800613 void doNotifyDropWindowLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
614
Siarhei Vishniakou3c63fa42020-12-15 02:59:54 +0000615 // ANR-related callbacks - start
Siarhei Vishniakou234129c2020-10-22 22:28:12 -0500616 void doNotifyNoFocusedWindowAnrLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
Siarhei Vishniakou3c63fa42020-12-15 02:59:54 +0000617 void doNotifyWindowUnresponsiveLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
618 void doNotifyMonitorUnresponsiveLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
619 void doNotifyWindowResponsiveLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
620 void doNotifyMonitorResponsiveLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
621 // ANR-related callbacks - end
Chris Yef59a2f42020-10-16 12:55:26 -0700622 void doNotifySensorLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
Bernardo Rufino2e1f6512020-10-08 13:42:07 +0000623 void doNotifyUntrustedTouchLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800624 void doInterceptKeyBeforeDispatchingLockedInterruptible(CommandEntry* commandEntry)
625 REQUIRES(mLock);
626 void doDispatchCycleFinishedLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
Prabir Pradhan99987712020-11-10 18:43:05 -0800627 void doSetPointerCaptureLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800628 bool afterKeyEventLockedInterruptible(const sp<Connection>& connection,
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700629 DispatchEntry* dispatchEntry, KeyEntry& keyEntry,
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700630 bool handled) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800631 bool afterMotionEventLockedInterruptible(const sp<Connection>& connection,
Siarhei Vishniakoua9a7ee82019-10-14 16:28:19 -0700632 DispatchEntry* dispatchEntry, MotionEntry& motionEntry,
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700633 bool handled) REQUIRES(mLock);
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800634 void doPokeUserActivityLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
Garfield Tan0fc2fa72019-08-29 17:22:15 -0700635 void doOnPointerDownOutsideFocusLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800636
637 // Statistics gathering.
Siarhei Vishniakou61291d42019-02-11 18:13:20 -0800638 void traceInboundQueueLengthLocked() REQUIRES(mLock);
Siarhei Vishniakou060a7272021-02-03 19:40:10 +0000639 void traceOutboundQueueLength(const Connection& connection);
640 void traceWaitQueueLength(const Connection& connection);
Prabir Pradhanf93562f2018-11-29 12:13:37 -0800641
Prabir Pradhan79a4f0c2019-01-09 11:24:01 -0800642 sp<InputReporterInterface> mReporter;
Siarhei Vishniakou2508b872020-12-03 16:33:53 -1000643 sp<com::android::internal::compat::IPlatformCompatNative> mCompatService;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800644};
645
Garfield Tane84e6f92019-08-29 17:28:41 -0700646} // namespace android::inputdispatcher
Michael Wrightd02c5b62014-02-10 15:10:22 -0800647
648#endif // _UI_INPUT_DISPATCHER_H