1*38e8c45fSAndroid Build Coastguard Worker /* 2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2010 The Android Open Source Project 3*38e8c45fSAndroid Build Coastguard Worker * 4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*38e8c45fSAndroid Build Coastguard Worker * 8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*38e8c45fSAndroid Build Coastguard Worker * 10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License. 15*38e8c45fSAndroid Build Coastguard Worker */ 16*38e8c45fSAndroid Build Coastguard Worker 17*38e8c45fSAndroid Build Coastguard Worker #pragma once 18*38e8c45fSAndroid Build Coastguard Worker 19*38e8c45fSAndroid Build Coastguard Worker #include <com_android_input_flags.h> 20*38e8c45fSAndroid Build Coastguard Worker 21*38e8c45fSAndroid Build Coastguard Worker #include "AnrTracker.h" 22*38e8c45fSAndroid Build Coastguard Worker #include "CancelationOptions.h" 23*38e8c45fSAndroid Build Coastguard Worker #include "DragState.h" 24*38e8c45fSAndroid Build Coastguard Worker #include "Entry.h" 25*38e8c45fSAndroid Build Coastguard Worker #include "FocusResolver.h" 26*38e8c45fSAndroid Build Coastguard Worker #include "InjectionState.h" 27*38e8c45fSAndroid Build Coastguard Worker #include "InputDispatcherConfiguration.h" 28*38e8c45fSAndroid Build Coastguard Worker #include "InputDispatcherInterface.h" 29*38e8c45fSAndroid Build Coastguard Worker #include "InputDispatcherPolicyInterface.h" 30*38e8c45fSAndroid Build Coastguard Worker #include "InputTarget.h" 31*38e8c45fSAndroid Build Coastguard Worker #include "InputThread.h" 32*38e8c45fSAndroid Build Coastguard Worker #include "LatencyAggregator.h" 33*38e8c45fSAndroid Build Coastguard Worker #include "LatencyAggregatorWithHistograms.h" 34*38e8c45fSAndroid Build Coastguard Worker #include "LatencyTracker.h" 35*38e8c45fSAndroid Build Coastguard Worker #include "Monitor.h" 36*38e8c45fSAndroid Build Coastguard Worker #include "TouchState.h" 37*38e8c45fSAndroid Build Coastguard Worker #include "TouchedWindow.h" 38*38e8c45fSAndroid Build Coastguard Worker #include "trace/InputTracerInterface.h" 39*38e8c45fSAndroid Build Coastguard Worker #include "trace/InputTracingBackendInterface.h" 40*38e8c45fSAndroid Build Coastguard Worker 41*38e8c45fSAndroid Build Coastguard Worker #include <attestation/HmacKeyManager.h> 42*38e8c45fSAndroid Build Coastguard Worker #include <gui/InputApplication.h> 43*38e8c45fSAndroid Build Coastguard Worker #include <gui/WindowInfosUpdate.h> 44*38e8c45fSAndroid Build Coastguard Worker #include <input/Input.h> 45*38e8c45fSAndroid Build Coastguard Worker #include <input/InputTransport.h> 46*38e8c45fSAndroid Build Coastguard Worker #include <limits.h> 47*38e8c45fSAndroid Build Coastguard Worker #include <powermanager/PowerManager.h> 48*38e8c45fSAndroid Build Coastguard Worker #include <stddef.h> 49*38e8c45fSAndroid Build Coastguard Worker #include <unistd.h> 50*38e8c45fSAndroid Build Coastguard Worker #include <utils/BitSet.h> 51*38e8c45fSAndroid Build Coastguard Worker #include <utils/Looper.h> 52*38e8c45fSAndroid Build Coastguard Worker #include <utils/Timers.h> 53*38e8c45fSAndroid Build Coastguard Worker #include <utils/threads.h> 54*38e8c45fSAndroid Build Coastguard Worker #include <bitset> 55*38e8c45fSAndroid Build Coastguard Worker #include <condition_variable> 56*38e8c45fSAndroid Build Coastguard Worker #include <deque> 57*38e8c45fSAndroid Build Coastguard Worker #include <optional> 58*38e8c45fSAndroid Build Coastguard Worker #include <unordered_map> 59*38e8c45fSAndroid Build Coastguard Worker #include <unordered_set> 60*38e8c45fSAndroid Build Coastguard Worker 61*38e8c45fSAndroid Build Coastguard Worker #include <InputListener.h> 62*38e8c45fSAndroid Build Coastguard Worker #include <InputReporterInterface.h> 63*38e8c45fSAndroid Build Coastguard Worker #include <gui/WindowInfosListener.h> 64*38e8c45fSAndroid Build Coastguard Worker 65*38e8c45fSAndroid Build Coastguard Worker namespace android::inputdispatcher { 66*38e8c45fSAndroid Build Coastguard Worker 67*38e8c45fSAndroid Build Coastguard Worker class Connection; 68*38e8c45fSAndroid Build Coastguard Worker 69*38e8c45fSAndroid Build Coastguard Worker /* Dispatches events to input targets. Some functions of the input dispatcher, such as 70*38e8c45fSAndroid Build Coastguard Worker * identifying input targets, are controlled by a separate policy object. 71*38e8c45fSAndroid Build Coastguard Worker * 72*38e8c45fSAndroid Build Coastguard Worker * IMPORTANT INVARIANT: 73*38e8c45fSAndroid Build Coastguard Worker * Because the policy can potentially block or cause re-entrance into the input dispatcher, 74*38e8c45fSAndroid Build Coastguard Worker * the input dispatcher never calls into the policy while holding its internal locks. 75*38e8c45fSAndroid Build Coastguard Worker * The implementation is also carefully designed to recover from scenarios such as an 76*38e8c45fSAndroid Build Coastguard Worker * input channel becoming unregistered while identifying input targets or processing timeouts. 77*38e8c45fSAndroid Build Coastguard Worker * 78*38e8c45fSAndroid Build Coastguard Worker * Methods marked 'Locked' must be called with the lock acquired. 79*38e8c45fSAndroid Build Coastguard Worker * 80*38e8c45fSAndroid Build Coastguard Worker * Methods marked 'LockedInterruptible' must be called with the lock acquired but 81*38e8c45fSAndroid Build Coastguard Worker * may during the course of their execution release the lock, call into the policy, and 82*38e8c45fSAndroid Build Coastguard Worker * then reacquire the lock. The caller is responsible for recovering gracefully. 83*38e8c45fSAndroid Build Coastguard Worker * 84*38e8c45fSAndroid Build Coastguard Worker * A 'LockedInterruptible' method may called a 'Locked' method, but NOT vice-versa. 85*38e8c45fSAndroid Build Coastguard Worker */ 86*38e8c45fSAndroid Build Coastguard Worker class InputDispatcher : public android::InputDispatcherInterface { 87*38e8c45fSAndroid Build Coastguard Worker public: 88*38e8c45fSAndroid Build Coastguard Worker static constexpr bool kDefaultInTouchMode = true; 89*38e8c45fSAndroid Build Coastguard Worker 90*38e8c45fSAndroid Build Coastguard Worker explicit InputDispatcher(InputDispatcherPolicyInterface& policy); 91*38e8c45fSAndroid Build Coastguard Worker // Constructor used for testing. 92*38e8c45fSAndroid Build Coastguard Worker explicit InputDispatcher(InputDispatcherPolicyInterface&, 93*38e8c45fSAndroid Build Coastguard Worker std::unique_ptr<trace::InputTracingBackendInterface>); 94*38e8c45fSAndroid Build Coastguard Worker ~InputDispatcher() override; 95*38e8c45fSAndroid Build Coastguard Worker 96*38e8c45fSAndroid Build Coastguard Worker void dump(std::string& dump) const override; 97*38e8c45fSAndroid Build Coastguard Worker void monitor() override; 98*38e8c45fSAndroid Build Coastguard Worker bool waitForIdle() const override; 99*38e8c45fSAndroid Build Coastguard Worker status_t start() override; 100*38e8c45fSAndroid Build Coastguard Worker status_t stop() override; 101*38e8c45fSAndroid Build Coastguard Worker 102*38e8c45fSAndroid Build Coastguard Worker void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override; 103*38e8c45fSAndroid Build Coastguard Worker void notifyKey(const NotifyKeyArgs& args) override; 104*38e8c45fSAndroid Build Coastguard Worker void notifyMotion(const NotifyMotionArgs& args) override; 105*38e8c45fSAndroid Build Coastguard Worker void notifySwitch(const NotifySwitchArgs& args) override; 106*38e8c45fSAndroid Build Coastguard Worker void notifySensor(const NotifySensorArgs& args) override; 107*38e8c45fSAndroid Build Coastguard Worker void notifyVibratorState(const NotifyVibratorStateArgs& args) override; 108*38e8c45fSAndroid Build Coastguard Worker void notifyDeviceReset(const NotifyDeviceResetArgs& args) override; 109*38e8c45fSAndroid Build Coastguard Worker void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) override; 110*38e8c45fSAndroid Build Coastguard Worker 111*38e8c45fSAndroid Build Coastguard Worker android::os::InputEventInjectionResult injectInputEvent( 112*38e8c45fSAndroid Build Coastguard Worker const InputEvent* event, std::optional<gui::Uid> targetUid, 113*38e8c45fSAndroid Build Coastguard Worker android::os::InputEventInjectionSync syncMode, std::chrono::milliseconds timeout, 114*38e8c45fSAndroid Build Coastguard Worker uint32_t policyFlags) override; 115*38e8c45fSAndroid Build Coastguard Worker 116*38e8c45fSAndroid Build Coastguard Worker std::unique_ptr<VerifiedInputEvent> verifyInputEvent(const InputEvent& event) override; 117*38e8c45fSAndroid Build Coastguard Worker 118*38e8c45fSAndroid Build Coastguard Worker void setFocusedApplication( 119*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId displayId, 120*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) override; 121*38e8c45fSAndroid Build Coastguard Worker void setFocusedDisplay(ui::LogicalDisplayId displayId) override; 122*38e8c45fSAndroid Build Coastguard Worker void setMinTimeBetweenUserActivityPokes(std::chrono::milliseconds interval) override; 123*38e8c45fSAndroid Build Coastguard Worker void setInputDispatchMode(bool enabled, bool frozen) override; 124*38e8c45fSAndroid Build Coastguard Worker void setInputFilterEnabled(bool enabled) override; 125*38e8c45fSAndroid Build Coastguard Worker bool setInTouchMode(bool inTouchMode, gui::Pid pid, gui::Uid uid, bool hasPermission, 126*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId displayId) override; 127*38e8c45fSAndroid Build Coastguard Worker void setMaximumObscuringOpacityForTouch(float opacity) override; 128*38e8c45fSAndroid Build Coastguard Worker 129*38e8c45fSAndroid Build Coastguard Worker bool transferTouchGesture(const sp<IBinder>& fromToken, const sp<IBinder>& toToken, 130*38e8c45fSAndroid Build Coastguard Worker bool isDragDrop = false) override; 131*38e8c45fSAndroid Build Coastguard Worker bool transferTouchOnDisplay(const sp<IBinder>& destChannelToken, 132*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId displayId) override; 133*38e8c45fSAndroid Build Coastguard Worker 134*38e8c45fSAndroid Build Coastguard Worker base::Result<std::unique_ptr<InputChannel>> createInputChannel( 135*38e8c45fSAndroid Build Coastguard Worker const std::string& name) override; 136*38e8c45fSAndroid Build Coastguard Worker void setFocusedWindow(const android::gui::FocusRequest&) override; 137*38e8c45fSAndroid Build Coastguard Worker base::Result<std::unique_ptr<InputChannel>> createInputMonitor(ui::LogicalDisplayId displayId, 138*38e8c45fSAndroid Build Coastguard Worker const std::string& name, 139*38e8c45fSAndroid Build Coastguard Worker gui::Pid pid) override; 140*38e8c45fSAndroid Build Coastguard Worker status_t removeInputChannel(const sp<IBinder>& connectionToken) override; 141*38e8c45fSAndroid Build Coastguard Worker status_t pilferPointers(const sp<IBinder>& token) override; 142*38e8c45fSAndroid Build Coastguard Worker void requestPointerCapture(const sp<IBinder>& windowToken, bool enabled) override; 143*38e8c45fSAndroid Build Coastguard Worker bool flushSensor(int deviceId, InputDeviceSensorType sensorType) override; 144*38e8c45fSAndroid Build Coastguard Worker void setDisplayEligibilityForPointerCapture(ui::LogicalDisplayId displayId, 145*38e8c45fSAndroid Build Coastguard Worker bool isEligible) override; 146*38e8c45fSAndroid Build Coastguard Worker 147*38e8c45fSAndroid Build Coastguard Worker std::array<uint8_t, 32> sign(const VerifiedInputEvent& event) const; 148*38e8c45fSAndroid Build Coastguard Worker 149*38e8c45fSAndroid Build Coastguard Worker void displayRemoved(ui::LogicalDisplayId displayId) override; 150*38e8c45fSAndroid Build Coastguard Worker 151*38e8c45fSAndroid Build Coastguard Worker // Public because it's also used by tests to simulate the WindowInfosListener callback 152*38e8c45fSAndroid Build Coastguard Worker void onWindowInfosChanged(const gui::WindowInfosUpdate&); 153*38e8c45fSAndroid Build Coastguard Worker 154*38e8c45fSAndroid Build Coastguard Worker void cancelCurrentTouch() override; 155*38e8c45fSAndroid Build Coastguard Worker 156*38e8c45fSAndroid Build Coastguard Worker // Public to allow tests to verify that a Monitor can get ANR. 157*38e8c45fSAndroid Build Coastguard Worker void setMonitorDispatchingTimeoutForTest(std::chrono::nanoseconds timeout); 158*38e8c45fSAndroid Build Coastguard Worker 159*38e8c45fSAndroid Build Coastguard Worker void setKeyRepeatConfiguration(std::chrono::nanoseconds timeout, std::chrono::nanoseconds delay, 160*38e8c45fSAndroid Build Coastguard Worker bool keyRepeatEnabled) override; 161*38e8c45fSAndroid Build Coastguard Worker 162*38e8c45fSAndroid Build Coastguard Worker bool isPointerInWindow(const sp<IBinder>& token, ui::LogicalDisplayId displayId, 163*38e8c45fSAndroid Build Coastguard Worker DeviceId deviceId, int32_t pointerId) override; 164*38e8c45fSAndroid Build Coastguard Worker 165*38e8c45fSAndroid Build Coastguard Worker void setInputMethodConnectionIsActive(bool isActive) override; 166*38e8c45fSAndroid Build Coastguard Worker 167*38e8c45fSAndroid Build Coastguard Worker private: 168*38e8c45fSAndroid Build Coastguard Worker enum class DropReason { 169*38e8c45fSAndroid Build Coastguard Worker NOT_DROPPED, 170*38e8c45fSAndroid Build Coastguard Worker POLICY, 171*38e8c45fSAndroid Build Coastguard Worker DISABLED, 172*38e8c45fSAndroid Build Coastguard Worker BLOCKED, 173*38e8c45fSAndroid Build Coastguard Worker STALE, 174*38e8c45fSAndroid Build Coastguard Worker NO_POINTER_CAPTURE, 175*38e8c45fSAndroid Build Coastguard Worker }; 176*38e8c45fSAndroid Build Coastguard Worker 177*38e8c45fSAndroid Build Coastguard Worker std::unique_ptr<InputThread> mThread; 178*38e8c45fSAndroid Build Coastguard Worker 179*38e8c45fSAndroid Build Coastguard Worker InputDispatcherPolicyInterface& mPolicy; 180*38e8c45fSAndroid Build Coastguard Worker android::InputDispatcherConfiguration mConfig GUARDED_BY(mLock); 181*38e8c45fSAndroid Build Coastguard Worker 182*38e8c45fSAndroid Build Coastguard Worker mutable std::mutex mLock; 183*38e8c45fSAndroid Build Coastguard Worker 184*38e8c45fSAndroid Build Coastguard Worker std::condition_variable mDispatcherIsAlive; 185*38e8c45fSAndroid Build Coastguard Worker mutable std::condition_variable mDispatcherEnteredIdle; 186*38e8c45fSAndroid Build Coastguard Worker 187*38e8c45fSAndroid Build Coastguard Worker // Input event tracer. The tracer will only exist on builds where input tracing is allowed. 188*38e8c45fSAndroid Build Coastguard Worker std::unique_ptr<trace::InputTracerInterface> mTracer GUARDED_BY(mLock); 189*38e8c45fSAndroid Build Coastguard Worker 190*38e8c45fSAndroid Build Coastguard Worker sp<Looper> mLooper; 191*38e8c45fSAndroid Build Coastguard Worker 192*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<const EventEntry> mPendingEvent GUARDED_BY(mLock); 193*38e8c45fSAndroid Build Coastguard Worker std::deque<std::shared_ptr<const EventEntry>> mInboundQueue GUARDED_BY(mLock); 194*38e8c45fSAndroid Build Coastguard Worker std::deque<std::shared_ptr<const EventEntry>> mRecentQueue GUARDED_BY(mLock); 195*38e8c45fSAndroid Build Coastguard Worker 196*38e8c45fSAndroid Build Coastguard Worker // A command entry captures state and behavior for an action to be performed in the 197*38e8c45fSAndroid Build Coastguard Worker // dispatch loop after the initial processing has taken place. It is essentially 198*38e8c45fSAndroid Build Coastguard Worker // a kind of continuation used to postpone sensitive policy interactions to a point 199*38e8c45fSAndroid Build Coastguard Worker // in the dispatch loop where it is safe to release the lock (generally after finishing 200*38e8c45fSAndroid Build Coastguard Worker // the critical parts of the dispatch cycle). 201*38e8c45fSAndroid Build Coastguard Worker // 202*38e8c45fSAndroid Build Coastguard Worker // The special thing about commands is that they can voluntarily release and reacquire 203*38e8c45fSAndroid Build Coastguard Worker // the dispatcher lock at will. Initially when the command starts running, the 204*38e8c45fSAndroid Build Coastguard Worker // dispatcher lock is held. However, if the command needs to call into the policy to 205*38e8c45fSAndroid Build Coastguard Worker // do some work, it can release the lock, do the work, then reacquire the lock again 206*38e8c45fSAndroid Build Coastguard Worker // before returning. 207*38e8c45fSAndroid Build Coastguard Worker // 208*38e8c45fSAndroid Build Coastguard Worker // This mechanism is a bit clunky but it helps to preserve the invariant that the dispatch 209*38e8c45fSAndroid Build Coastguard Worker // never calls into the policy while holding its lock. 210*38e8c45fSAndroid Build Coastguard Worker // 211*38e8c45fSAndroid Build Coastguard Worker // Commands are called with the lock held, but they can release and re-acquire the lock from 212*38e8c45fSAndroid Build Coastguard Worker // within. 213*38e8c45fSAndroid Build Coastguard Worker using Command = std::function<void()>; 214*38e8c45fSAndroid Build Coastguard Worker std::deque<Command> mCommandQueue GUARDED_BY(mLock); 215*38e8c45fSAndroid Build Coastguard Worker 216*38e8c45fSAndroid Build Coastguard Worker DropReason mLastDropReason GUARDED_BY(mLock); 217*38e8c45fSAndroid Build Coastguard Worker 218*38e8c45fSAndroid Build Coastguard Worker const IdGenerator mIdGenerator GUARDED_BY(mLock); 219*38e8c45fSAndroid Build Coastguard Worker 220*38e8c45fSAndroid Build Coastguard Worker int64_t mWindowInfosVsyncId GUARDED_BY(mLock); 221*38e8c45fSAndroid Build Coastguard Worker 222*38e8c45fSAndroid Build Coastguard Worker std::chrono::milliseconds mMinTimeBetweenUserActivityPokes GUARDED_BY(mLock); 223*38e8c45fSAndroid Build Coastguard Worker 224*38e8c45fSAndroid Build Coastguard Worker /** Stores the latest user-activity poke event times per user activity types. */ 225*38e8c45fSAndroid Build Coastguard Worker std::array<nsecs_t, USER_ACTIVITY_EVENT_LAST + 1> mLastUserActivityTimes GUARDED_BY(mLock); 226*38e8c45fSAndroid Build Coastguard Worker 227*38e8c45fSAndroid Build Coastguard Worker // With each iteration, InputDispatcher nominally processes one queued event, 228*38e8c45fSAndroid Build Coastguard Worker // a timeout, or a response from an input consumer. 229*38e8c45fSAndroid Build Coastguard Worker // This method should only be called on the input dispatcher's own thread. 230*38e8c45fSAndroid Build Coastguard Worker void dispatchOnce(); 231*38e8c45fSAndroid Build Coastguard Worker 232*38e8c45fSAndroid Build Coastguard Worker void dispatchOnceInnerLocked(nsecs_t& nextWakeupTime) REQUIRES(mLock); 233*38e8c45fSAndroid Build Coastguard Worker 234*38e8c45fSAndroid Build Coastguard Worker // Enqueues an inbound event. Returns true if mLooper->wake() should be called. 235*38e8c45fSAndroid Build Coastguard Worker bool enqueueInboundEventLocked(std::unique_ptr<EventEntry> entry) REQUIRES(mLock); 236*38e8c45fSAndroid Build Coastguard Worker 237*38e8c45fSAndroid Build Coastguard Worker // Cleans up input state when dropping an inbound event. 238*38e8c45fSAndroid Build Coastguard Worker void dropInboundEventLocked(const EventEntry& entry, DropReason dropReason) REQUIRES(mLock); 239*38e8c45fSAndroid Build Coastguard Worker 240*38e8c45fSAndroid Build Coastguard Worker // Enqueues a focus event. 241*38e8c45fSAndroid Build Coastguard Worker void enqueueFocusEventLocked(const sp<IBinder>& windowToken, bool hasFocus, 242*38e8c45fSAndroid Build Coastguard Worker const std::string& reason) REQUIRES(mLock); 243*38e8c45fSAndroid Build Coastguard Worker // Enqueues a drag event. 244*38e8c45fSAndroid Build Coastguard Worker void enqueueDragEventLocked(const sp<android::gui::WindowInfoHandle>& windowToken, 245*38e8c45fSAndroid Build Coastguard Worker bool isExiting, const int32_t rawX, const int32_t rawY) 246*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 247*38e8c45fSAndroid Build Coastguard Worker 248*38e8c45fSAndroid Build Coastguard Worker // Adds an event to a queue of recent events for debugging purposes. 249*38e8c45fSAndroid Build Coastguard Worker void addRecentEventLocked(std::shared_ptr<const EventEntry> entry) REQUIRES(mLock); 250*38e8c45fSAndroid Build Coastguard Worker 251*38e8c45fSAndroid Build Coastguard Worker // Blocked event latency optimization. Drops old events when the user intends 252*38e8c45fSAndroid Build Coastguard Worker // to transfer focus to a new application. 253*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<const EventEntry> mNextUnblockedEvent GUARDED_BY(mLock); 254*38e8c45fSAndroid Build Coastguard Worker 255*38e8c45fSAndroid Build Coastguard Worker sp<android::gui::WindowInfoHandle> findTouchedWindowAtLocked( 256*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId displayId, float x, float y, bool isStylus = false, 257*38e8c45fSAndroid Build Coastguard Worker bool ignoreDragWindow = false) const REQUIRES(mLock); 258*38e8c45fSAndroid Build Coastguard Worker std::vector<InputTarget> findOutsideTargetsLocked( 259*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId displayId, const sp<android::gui::WindowInfoHandle>& touchedWindow, 260*38e8c45fSAndroid Build Coastguard Worker int32_t pointerId) const REQUIRES(mLock); 261*38e8c45fSAndroid Build Coastguard Worker 262*38e8c45fSAndroid Build Coastguard Worker std::vector<sp<android::gui::WindowInfoHandle>> findTouchedSpyWindowsAtLocked( 263*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId displayId, float x, float y, bool isStylus, 264*38e8c45fSAndroid Build Coastguard Worker DeviceId deviceId) const REQUIRES(mLock); 265*38e8c45fSAndroid Build Coastguard Worker 266*38e8c45fSAndroid Build Coastguard Worker sp<android::gui::WindowInfoHandle> findTouchedForegroundWindowLocked( 267*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId displayId) const REQUIRES(mLock); 268*38e8c45fSAndroid Build Coastguard Worker 269*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<Connection> getConnectionLocked(const sp<IBinder>& inputConnectionToken) const 270*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 271*38e8c45fSAndroid Build Coastguard Worker 272*38e8c45fSAndroid Build Coastguard Worker std::string getConnectionNameLocked(const sp<IBinder>& connectionToken) const REQUIRES(mLock); 273*38e8c45fSAndroid Build Coastguard Worker 274*38e8c45fSAndroid Build Coastguard Worker void removeConnectionLocked(const std::shared_ptr<Connection>& connection) REQUIRES(mLock); 275*38e8c45fSAndroid Build Coastguard Worker 276*38e8c45fSAndroid Build Coastguard Worker status_t pilferPointersLocked(const sp<IBinder>& token) REQUIRES(mLock); 277*38e8c45fSAndroid Build Coastguard Worker 278*38e8c45fSAndroid Build Coastguard Worker template <typename T> 279*38e8c45fSAndroid Build Coastguard Worker struct StrongPointerHash { operatorStrongPointerHash280*38e8c45fSAndroid Build Coastguard Worker std::size_t operator()(const sp<T>& b) const { return std::hash<T*>{}(b.get()); } 281*38e8c45fSAndroid Build Coastguard Worker }; 282*38e8c45fSAndroid Build Coastguard Worker 283*38e8c45fSAndroid Build Coastguard Worker // All registered connections mapped by input channel token. 284*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<sp<IBinder>, std::shared_ptr<Connection>, StrongPointerHash<IBinder>> 285*38e8c45fSAndroid Build Coastguard Worker mConnectionsByToken GUARDED_BY(mLock); 286*38e8c45fSAndroid Build Coastguard Worker 287*38e8c45fSAndroid Build Coastguard Worker // Find a monitor pid by the provided token. 288*38e8c45fSAndroid Build Coastguard Worker std::optional<gui::Pid> findMonitorPidByTokenLocked(const sp<IBinder>& token) REQUIRES(mLock); 289*38e8c45fSAndroid Build Coastguard Worker 290*38e8c45fSAndroid Build Coastguard Worker // Input channels that will receive a copy of all input events sent to the provided display. 291*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<ui::LogicalDisplayId, std::vector<Monitor>> mGlobalMonitorsByDisplay 292*38e8c45fSAndroid Build Coastguard Worker GUARDED_BY(mLock); 293*38e8c45fSAndroid Build Coastguard Worker 294*38e8c45fSAndroid Build Coastguard Worker const HmacKeyManager mHmacKeyManager; 295*38e8c45fSAndroid Build Coastguard Worker const std::array<uint8_t, 32> getSignature(const MotionEntry& motionEntry, 296*38e8c45fSAndroid Build Coastguard Worker const DispatchEntry& dispatchEntry) const; 297*38e8c45fSAndroid Build Coastguard Worker const std::array<uint8_t, 32> getSignature(const KeyEntry& keyEntry, 298*38e8c45fSAndroid Build Coastguard Worker const DispatchEntry& dispatchEntry) const; 299*38e8c45fSAndroid Build Coastguard Worker 300*38e8c45fSAndroid Build Coastguard Worker // Event injection and synchronization. 301*38e8c45fSAndroid Build Coastguard Worker std::condition_variable mInjectionResultAvailable; 302*38e8c45fSAndroid Build Coastguard Worker bool shouldRejectInjectedMotionLocked(const MotionEvent& motion, DeviceId deviceId, 303*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId displayId, 304*38e8c45fSAndroid Build Coastguard Worker std::optional<gui::Uid> targetUid, int32_t flags) 305*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 306*38e8c45fSAndroid Build Coastguard Worker void setInjectionResult(const EventEntry& entry, 307*38e8c45fSAndroid Build Coastguard Worker android::os::InputEventInjectionResult injectionResult); 308*38e8c45fSAndroid Build Coastguard Worker void transformMotionEntryForInjectionLocked(MotionEntry&, 309*38e8c45fSAndroid Build Coastguard Worker const ui::Transform& injectedTransform) const 310*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 311*38e8c45fSAndroid Build Coastguard Worker // Per-display correction of injected events 312*38e8c45fSAndroid Build Coastguard Worker std::map<android::ui::LogicalDisplayId, InputVerifier> mInputFilterVerifiersByDisplay 313*38e8c45fSAndroid Build Coastguard Worker GUARDED_BY(mLock); 314*38e8c45fSAndroid Build Coastguard Worker std::condition_variable mInjectionSyncFinished; 315*38e8c45fSAndroid Build Coastguard Worker void incrementPendingForegroundDispatches(const EventEntry& entry); 316*38e8c45fSAndroid Build Coastguard Worker void decrementPendingForegroundDispatches(const EventEntry& entry); 317*38e8c45fSAndroid Build Coastguard Worker 318*38e8c45fSAndroid Build Coastguard Worker // Key repeat tracking. 319*38e8c45fSAndroid Build Coastguard Worker struct KeyRepeatState { 320*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<const KeyEntry> lastKeyEntry; // or null if no repeat 321*38e8c45fSAndroid Build Coastguard Worker nsecs_t nextRepeatTime; 322*38e8c45fSAndroid Build Coastguard Worker } mKeyRepeatState GUARDED_BY(mLock); 323*38e8c45fSAndroid Build Coastguard Worker 324*38e8c45fSAndroid Build Coastguard Worker void resetKeyRepeatLocked() REQUIRES(mLock); 325*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<KeyEntry> synthesizeKeyRepeatLocked(nsecs_t currentTime) REQUIRES(mLock); 326*38e8c45fSAndroid Build Coastguard Worker 327*38e8c45fSAndroid Build Coastguard Worker // Deferred command processing. 328*38e8c45fSAndroid Build Coastguard Worker bool haveCommandsLocked() const REQUIRES(mLock); 329*38e8c45fSAndroid Build Coastguard Worker bool runCommandsLockedInterruptable() REQUIRES(mLock); 330*38e8c45fSAndroid Build Coastguard Worker void postCommandLocked(Command&& command) REQUIRES(mLock); 331*38e8c45fSAndroid Build Coastguard Worker 332*38e8c45fSAndroid Build Coastguard Worker // The dispatching timeout to use for Monitors. 333*38e8c45fSAndroid Build Coastguard Worker std::chrono::nanoseconds mMonitorDispatchingTimeout GUARDED_BY(mLock); 334*38e8c45fSAndroid Build Coastguard Worker 335*38e8c45fSAndroid Build Coastguard Worker nsecs_t processAnrsLocked() REQUIRES(mLock); 336*38e8c45fSAndroid Build Coastguard Worker void processLatencyStatisticsLocked() REQUIRES(mLock); 337*38e8c45fSAndroid Build Coastguard Worker std::chrono::nanoseconds getDispatchingTimeoutLocked( 338*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<Connection>& connection) REQUIRES(mLock); 339*38e8c45fSAndroid Build Coastguard Worker 340*38e8c45fSAndroid Build Coastguard Worker // Input filter processing. 341*38e8c45fSAndroid Build Coastguard Worker bool shouldSendKeyToInputFilterLocked(const NotifyKeyArgs& args) REQUIRES(mLock); 342*38e8c45fSAndroid Build Coastguard Worker bool shouldSendMotionToInputFilterLocked(const NotifyMotionArgs& args) REQUIRES(mLock); 343*38e8c45fSAndroid Build Coastguard Worker 344*38e8c45fSAndroid Build Coastguard Worker // Inbound event processing. 345*38e8c45fSAndroid Build Coastguard Worker void drainInboundQueueLocked() REQUIRES(mLock); 346*38e8c45fSAndroid Build Coastguard Worker void releasePendingEventLocked() REQUIRES(mLock); 347*38e8c45fSAndroid Build Coastguard Worker void releaseInboundEventLocked(std::shared_ptr<const EventEntry> entry) REQUIRES(mLock); 348*38e8c45fSAndroid Build Coastguard Worker 349*38e8c45fSAndroid Build Coastguard Worker // Dispatch state. 350*38e8c45fSAndroid Build Coastguard Worker bool mDispatchEnabled GUARDED_BY(mLock); 351*38e8c45fSAndroid Build Coastguard Worker bool mDispatchFrozen GUARDED_BY(mLock); 352*38e8c45fSAndroid Build Coastguard Worker bool mInputFilterEnabled GUARDED_BY(mLock); 353*38e8c45fSAndroid Build Coastguard Worker float mMaximumObscuringOpacityForTouch GUARDED_BY(mLock); 354*38e8c45fSAndroid Build Coastguard Worker 355*38e8c45fSAndroid Build Coastguard Worker // This map is not really needed, but it helps a lot with debugging (dumpsys input). 356*38e8c45fSAndroid Build Coastguard Worker // In the java layer, touch mode states are spread across multiple DisplayContent objects, 357*38e8c45fSAndroid Build Coastguard Worker // making harder to snapshot and retrieve them. 358*38e8c45fSAndroid Build Coastguard Worker std::map<ui::LogicalDisplayId /*displayId*/, bool /*inTouchMode*/> mTouchModePerDisplay 359*38e8c45fSAndroid Build Coastguard Worker GUARDED_BY(mLock); 360*38e8c45fSAndroid Build Coastguard Worker 361*38e8c45fSAndroid Build Coastguard Worker class DispatcherWindowListener : public gui::WindowInfosListener { 362*38e8c45fSAndroid Build Coastguard Worker public: DispatcherWindowListener(InputDispatcher & dispatcher)363*38e8c45fSAndroid Build Coastguard Worker explicit DispatcherWindowListener(InputDispatcher& dispatcher) : mDispatcher(dispatcher){}; 364*38e8c45fSAndroid Build Coastguard Worker void onWindowInfosChanged(const gui::WindowInfosUpdate&) override; 365*38e8c45fSAndroid Build Coastguard Worker 366*38e8c45fSAndroid Build Coastguard Worker private: 367*38e8c45fSAndroid Build Coastguard Worker InputDispatcher& mDispatcher; 368*38e8c45fSAndroid Build Coastguard Worker }; 369*38e8c45fSAndroid Build Coastguard Worker sp<gui::WindowInfosListener> mWindowInfoListener; 370*38e8c45fSAndroid Build Coastguard Worker 371*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<ui::LogicalDisplayId /*displayId*/, 372*38e8c45fSAndroid Build Coastguard Worker std::vector<sp<android::gui::WindowInfoHandle>>> 373*38e8c45fSAndroid Build Coastguard Worker mWindowHandlesByDisplay GUARDED_BY(mLock); 374*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<ui::LogicalDisplayId /*displayId*/, android::gui::DisplayInfo> mDisplayInfos 375*38e8c45fSAndroid Build Coastguard Worker GUARDED_BY(mLock); 376*38e8c45fSAndroid Build Coastguard Worker void setInputWindowsLocked( 377*38e8c45fSAndroid Build Coastguard Worker const std::vector<sp<android::gui::WindowInfoHandle>>& inputWindowHandles, 378*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId displayId) REQUIRES(mLock); 379*38e8c45fSAndroid Build Coastguard Worker // Get a reference to window handles by display, return an empty vector if not found. 380*38e8c45fSAndroid Build Coastguard Worker const std::vector<sp<android::gui::WindowInfoHandle>>& getWindowHandlesLocked( 381*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId displayId) const REQUIRES(mLock); 382*38e8c45fSAndroid Build Coastguard Worker ui::Transform getTransformLocked(ui::LogicalDisplayId displayId) const REQUIRES(mLock); 383*38e8c45fSAndroid Build Coastguard Worker 384*38e8c45fSAndroid Build Coastguard Worker sp<android::gui::WindowInfoHandle> getWindowHandleLocked( 385*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder>& windowHandleToken, 386*38e8c45fSAndroid Build Coastguard Worker std::optional<ui::LogicalDisplayId> displayId = {}) const REQUIRES(mLock); 387*38e8c45fSAndroid Build Coastguard Worker sp<android::gui::WindowInfoHandle> getWindowHandleLocked( 388*38e8c45fSAndroid Build Coastguard Worker const sp<android::gui::WindowInfoHandle>& windowHandle) const REQUIRES(mLock); 389*38e8c45fSAndroid Build Coastguard Worker sp<android::gui::WindowInfoHandle> getFocusedWindowHandleLocked( 390*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId displayId) const REQUIRES(mLock); 391*38e8c45fSAndroid Build Coastguard Worker bool canWindowReceiveMotionLocked(const sp<android::gui::WindowInfoHandle>& window, 392*38e8c45fSAndroid Build Coastguard Worker const MotionEntry& motionEntry) const REQUIRES(mLock); 393*38e8c45fSAndroid Build Coastguard Worker 394*38e8c45fSAndroid Build Coastguard Worker // Returns all the input targets (with their respective input channels) from the window handles 395*38e8c45fSAndroid Build Coastguard Worker // passed as argument. 396*38e8c45fSAndroid Build Coastguard Worker std::vector<InputTarget> getInputTargetsFromWindowHandlesLocked( 397*38e8c45fSAndroid Build Coastguard Worker const std::vector<sp<android::gui::WindowInfoHandle>>& windowHandles) const 398*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 399*38e8c45fSAndroid Build Coastguard Worker 400*38e8c45fSAndroid Build Coastguard Worker /* 401*38e8c45fSAndroid Build Coastguard Worker * Validate and update InputWindowHandles for a given display. 402*38e8c45fSAndroid Build Coastguard Worker */ 403*38e8c45fSAndroid Build Coastguard Worker void updateWindowHandlesForDisplayLocked( 404*38e8c45fSAndroid Build Coastguard Worker const std::vector<sp<android::gui::WindowInfoHandle>>& inputWindowHandles, 405*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId displayId) REQUIRES(mLock); 406*38e8c45fSAndroid Build Coastguard Worker 407*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<ui::LogicalDisplayId /*displayId*/, TouchState> mTouchStatesByDisplay 408*38e8c45fSAndroid Build Coastguard Worker GUARDED_BY(mLock); 409*38e8c45fSAndroid Build Coastguard Worker std::unique_ptr<DragState> mDragState GUARDED_BY(mLock); 410*38e8c45fSAndroid Build Coastguard Worker 411*38e8c45fSAndroid Build Coastguard Worker void setFocusedApplicationLocked( 412*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId displayId, 413*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) REQUIRES(mLock); 414*38e8c45fSAndroid Build Coastguard Worker // Focused applications. 415*38e8c45fSAndroid Build Coastguard Worker std::unordered_map<ui::LogicalDisplayId /*displayId*/, std::shared_ptr<InputApplicationHandle>> 416*38e8c45fSAndroid Build Coastguard Worker mFocusedApplicationHandlesByDisplay GUARDED_BY(mLock); 417*38e8c45fSAndroid Build Coastguard Worker 418*38e8c45fSAndroid Build Coastguard Worker // Top focused display. 419*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId mFocusedDisplayId GUARDED_BY(mLock); 420*38e8c45fSAndroid Build Coastguard Worker 421*38e8c45fSAndroid Build Coastguard Worker // Keeps track of the focused window per display and determines focus changes. 422*38e8c45fSAndroid Build Coastguard Worker FocusResolver mFocusResolver GUARDED_BY(mLock); 423*38e8c45fSAndroid Build Coastguard Worker 424*38e8c45fSAndroid Build Coastguard Worker // The enabled state of this request is true iff the focused window on the focused display has 425*38e8c45fSAndroid Build Coastguard Worker // requested Pointer Capture. This request also contains the sequence number associated with the 426*38e8c45fSAndroid Build Coastguard Worker // current request. The state of this variable should always be in sync with the state of 427*38e8c45fSAndroid Build Coastguard Worker // Pointer Capture in the policy, and is only updated through setPointerCaptureLocked(request). 428*38e8c45fSAndroid Build Coastguard Worker PointerCaptureRequest mCurrentPointerCaptureRequest GUARDED_BY(mLock); 429*38e8c45fSAndroid Build Coastguard Worker 430*38e8c45fSAndroid Build Coastguard Worker // The window token that has Pointer Capture. 431*38e8c45fSAndroid Build Coastguard Worker // This should be in sync with PointerCaptureChangedEvents dispatched to the input channel. 432*38e8c45fSAndroid Build Coastguard Worker sp<IBinder> mWindowTokenWithPointerCapture GUARDED_BY(mLock); 433*38e8c45fSAndroid Build Coastguard Worker 434*38e8c45fSAndroid Build Coastguard Worker // Displays that are ineligible for pointer capture. 435*38e8c45fSAndroid Build Coastguard Worker // TODO(b/214621487): Remove or move to a display flag. 436*38e8c45fSAndroid Build Coastguard Worker std::vector<ui::LogicalDisplayId /*displayId*/> mIneligibleDisplaysForPointerCapture 437*38e8c45fSAndroid Build Coastguard Worker GUARDED_BY(mLock); 438*38e8c45fSAndroid Build Coastguard Worker 439*38e8c45fSAndroid Build Coastguard Worker // Disable Pointer Capture as a result of loss of window focus. 440*38e8c45fSAndroid Build Coastguard Worker void disablePointerCaptureForcedLocked() REQUIRES(mLock); 441*38e8c45fSAndroid Build Coastguard Worker 442*38e8c45fSAndroid Build Coastguard Worker // Set the Pointer Capture state in the Policy. 443*38e8c45fSAndroid Build Coastguard Worker // The window is not nullptr for requests to enable, otherwise it is nullptr. 444*38e8c45fSAndroid Build Coastguard Worker void setPointerCaptureLocked(const sp<IBinder>& window) REQUIRES(mLock); 445*38e8c45fSAndroid Build Coastguard Worker 446*38e8c45fSAndroid Build Coastguard Worker // Dispatcher state at time of last ANR. 447*38e8c45fSAndroid Build Coastguard Worker std::string mLastAnrState GUARDED_BY(mLock); 448*38e8c45fSAndroid Build Coastguard Worker 449*38e8c45fSAndroid Build Coastguard Worker // The connection tokens of the channels that the user last interacted (used for debugging and 450*38e8c45fSAndroid Build Coastguard Worker // when switching touch mode state). 451*38e8c45fSAndroid Build Coastguard Worker std::unordered_set<sp<IBinder>, StrongPointerHash<IBinder>> mInteractionConnectionTokens 452*38e8c45fSAndroid Build Coastguard Worker GUARDED_BY(mLock); 453*38e8c45fSAndroid Build Coastguard Worker void processInteractionsLocked(const EventEntry& entry, const std::vector<InputTarget>& targets) 454*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 455*38e8c45fSAndroid Build Coastguard Worker 456*38e8c45fSAndroid Build Coastguard Worker // Dispatch inbound events. 457*38e8c45fSAndroid Build Coastguard Worker bool dispatchDeviceResetLocked(nsecs_t currentTime, const DeviceResetEntry& entry) 458*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 459*38e8c45fSAndroid Build Coastguard Worker bool dispatchKeyLocked(nsecs_t currentTime, std::shared_ptr<const KeyEntry> entry, 460*38e8c45fSAndroid Build Coastguard Worker DropReason* dropReason, nsecs_t& nextWakeupTime) REQUIRES(mLock); 461*38e8c45fSAndroid Build Coastguard Worker bool dispatchMotionLocked(nsecs_t currentTime, std::shared_ptr<const MotionEntry> entry, 462*38e8c45fSAndroid Build Coastguard Worker DropReason* dropReason, nsecs_t& nextWakeupTime) REQUIRES(mLock); 463*38e8c45fSAndroid Build Coastguard Worker void dispatchFocusLocked(nsecs_t currentTime, std::shared_ptr<const FocusEntry> entry) 464*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 465*38e8c45fSAndroid Build Coastguard Worker void dispatchPointerCaptureChangedLocked( 466*38e8c45fSAndroid Build Coastguard Worker nsecs_t currentTime, const std::shared_ptr<const PointerCaptureChangedEntry>& entry, 467*38e8c45fSAndroid Build Coastguard Worker DropReason& dropReason) REQUIRES(mLock); 468*38e8c45fSAndroid Build Coastguard Worker void dispatchTouchModeChangeLocked(nsecs_t currentTime, 469*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<const TouchModeEntry>& entry) 470*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 471*38e8c45fSAndroid Build Coastguard Worker void dispatchEventLocked(nsecs_t currentTime, std::shared_ptr<const EventEntry> entry, 472*38e8c45fSAndroid Build Coastguard Worker const std::vector<InputTarget>& inputTargets) REQUIRES(mLock); 473*38e8c45fSAndroid Build Coastguard Worker void dispatchSensorLocked(nsecs_t currentTime, const std::shared_ptr<const SensorEntry>& entry, 474*38e8c45fSAndroid Build Coastguard Worker DropReason* dropReason, nsecs_t& nextWakeupTime) REQUIRES(mLock); 475*38e8c45fSAndroid Build Coastguard Worker void dispatchDragLocked(nsecs_t currentTime, std::shared_ptr<const DragEntry> entry) 476*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 477*38e8c45fSAndroid Build Coastguard Worker void logOutboundKeyDetails(const char* prefix, const KeyEntry& entry); 478*38e8c45fSAndroid Build Coastguard Worker void logOutboundMotionDetails(const char* prefix, const MotionEntry& entry); 479*38e8c45fSAndroid Build Coastguard Worker 480*38e8c45fSAndroid Build Coastguard Worker /** 481*38e8c45fSAndroid Build Coastguard Worker * This field is set if there is no focused window, and we have an event that requires 482*38e8c45fSAndroid Build Coastguard Worker * a focused window to be dispatched (for example, a KeyEvent). 483*38e8c45fSAndroid Build Coastguard Worker * When this happens, we will wait until *mNoFocusedWindowTimeoutTime before 484*38e8c45fSAndroid Build Coastguard Worker * dropping the event and raising an ANR for that application. 485*38e8c45fSAndroid Build Coastguard Worker * This is useful if an application is slow to add a focused window. 486*38e8c45fSAndroid Build Coastguard Worker */ 487*38e8c45fSAndroid Build Coastguard Worker std::optional<nsecs_t> mNoFocusedWindowTimeoutTime GUARDED_BY(mLock); 488*38e8c45fSAndroid Build Coastguard Worker 489*38e8c45fSAndroid Build Coastguard Worker bool isStaleEvent(nsecs_t currentTime, const EventEntry& entry); 490*38e8c45fSAndroid Build Coastguard Worker 491*38e8c45fSAndroid Build Coastguard Worker bool shouldPruneInboundQueueLocked(const MotionEntry& motionEntry) const REQUIRES(mLock); 492*38e8c45fSAndroid Build Coastguard Worker 493*38e8c45fSAndroid Build Coastguard Worker /** 494*38e8c45fSAndroid Build Coastguard Worker * Time to stop waiting for the events to be processed while trying to dispatch a key. 495*38e8c45fSAndroid Build Coastguard Worker * When this time expires, we just send the pending key event to the currently focused window, 496*38e8c45fSAndroid Build Coastguard Worker * without waiting on other events to be processed first. 497*38e8c45fSAndroid Build Coastguard Worker */ 498*38e8c45fSAndroid Build Coastguard Worker std::optional<nsecs_t> mKeyIsWaitingForEventsTimeout GUARDED_BY(mLock); 499*38e8c45fSAndroid Build Coastguard Worker bool shouldWaitToSendKeyLocked(nsecs_t currentTime, const char* focusedWindowName) 500*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 501*38e8c45fSAndroid Build Coastguard Worker 502*38e8c45fSAndroid Build Coastguard Worker /** 503*38e8c45fSAndroid Build Coastguard Worker * The focused application at the time when no focused window was present. 504*38e8c45fSAndroid Build Coastguard Worker * Used to raise an ANR when we have no focused window. 505*38e8c45fSAndroid Build Coastguard Worker */ 506*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<InputApplicationHandle> mAwaitedFocusedApplication GUARDED_BY(mLock); 507*38e8c45fSAndroid Build Coastguard Worker /** 508*38e8c45fSAndroid Build Coastguard Worker * The displayId that the focused application is associated with. 509*38e8c45fSAndroid Build Coastguard Worker */ 510*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId mAwaitedApplicationDisplayId GUARDED_BY(mLock); 511*38e8c45fSAndroid Build Coastguard Worker void processNoFocusedWindowAnrLocked() REQUIRES(mLock); 512*38e8c45fSAndroid Build Coastguard Worker 513*38e8c45fSAndroid Build Coastguard Worker /** 514*38e8c45fSAndroid Build Coastguard Worker * Tell policy about a window or a monitor that just became unresponsive. Starts ANR. 515*38e8c45fSAndroid Build Coastguard Worker */ 516*38e8c45fSAndroid Build Coastguard Worker void processConnectionUnresponsiveLocked(const Connection& connection, std::string reason) 517*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 518*38e8c45fSAndroid Build Coastguard Worker /** 519*38e8c45fSAndroid Build Coastguard Worker * Tell policy about a window or a monitor that just became responsive. 520*38e8c45fSAndroid Build Coastguard Worker */ 521*38e8c45fSAndroid Build Coastguard Worker void processConnectionResponsiveLocked(const Connection& connection) REQUIRES(mLock); 522*38e8c45fSAndroid Build Coastguard Worker 523*38e8c45fSAndroid Build Coastguard Worker void sendWindowUnresponsiveCommandLocked(const sp<IBinder>& connectionToken, 524*38e8c45fSAndroid Build Coastguard Worker std::optional<gui::Pid> pid, std::string reason) 525*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 526*38e8c45fSAndroid Build Coastguard Worker void sendWindowResponsiveCommandLocked(const sp<IBinder>& connectionToken, 527*38e8c45fSAndroid Build Coastguard Worker std::optional<gui::Pid> pid) REQUIRES(mLock); 528*38e8c45fSAndroid Build Coastguard Worker 529*38e8c45fSAndroid Build Coastguard Worker // Optimization: AnrTracker is used to quickly find which connection is due for a timeout next. 530*38e8c45fSAndroid Build Coastguard Worker // AnrTracker must be kept in-sync with all responsive connection.waitQueues. 531*38e8c45fSAndroid Build Coastguard Worker // If a connection is not responsive, then the entries should not be added to the AnrTracker. 532*38e8c45fSAndroid Build Coastguard Worker // Once a connection becomes unresponsive, its entries are removed from AnrTracker to 533*38e8c45fSAndroid Build Coastguard Worker // prevent unneeded wakeups. 534*38e8c45fSAndroid Build Coastguard Worker AnrTracker mAnrTracker GUARDED_BY(mLock); 535*38e8c45fSAndroid Build Coastguard Worker 536*38e8c45fSAndroid Build Coastguard Worker void cancelEventsForAnrLocked(const std::shared_ptr<Connection>& connection) REQUIRES(mLock); 537*38e8c45fSAndroid Build Coastguard Worker // If a focused application changes, we should stop counting down the "no focused window" time, 538*38e8c45fSAndroid Build Coastguard Worker // because we will have no way of knowing when the previous application actually added a window. 539*38e8c45fSAndroid Build Coastguard Worker // This also means that we will miss cases like pulling down notification shade when the 540*38e8c45fSAndroid Build Coastguard Worker // focused application does not have a focused window (no ANR will be raised if notification 541*38e8c45fSAndroid Build Coastguard Worker // shade is pulled down while we are counting down the timeout). 542*38e8c45fSAndroid Build Coastguard Worker void resetNoFocusedWindowTimeoutLocked() REQUIRES(mLock); 543*38e8c45fSAndroid Build Coastguard Worker 544*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId getTargetDisplayId(const EventEntry& entry); 545*38e8c45fSAndroid Build Coastguard Worker base::Result<sp<android::gui::WindowInfoHandle>, android::os::InputEventInjectionResult> 546*38e8c45fSAndroid Build Coastguard Worker findFocusedWindowTargetLocked(nsecs_t currentTime, const EventEntry& entry, 547*38e8c45fSAndroid Build Coastguard Worker nsecs_t& nextWakeupTime) REQUIRES(mLock); 548*38e8c45fSAndroid Build Coastguard Worker base::Result<std::vector<InputTarget>, android::os::InputEventInjectionResult> 549*38e8c45fSAndroid Build Coastguard Worker findTouchedWindowTargetsLocked(nsecs_t currentTime, const MotionEntry& entry) REQUIRES(mLock); 550*38e8c45fSAndroid Build Coastguard Worker std::vector<Monitor> selectResponsiveMonitorsLocked( 551*38e8c45fSAndroid Build Coastguard Worker const std::vector<Monitor>& gestureMonitors) const REQUIRES(mLock); 552*38e8c45fSAndroid Build Coastguard Worker 553*38e8c45fSAndroid Build Coastguard Worker std::optional<InputTarget> createInputTargetLocked( 554*38e8c45fSAndroid Build Coastguard Worker const sp<android::gui::WindowInfoHandle>& windowHandle, 555*38e8c45fSAndroid Build Coastguard Worker InputTarget::DispatchMode dispatchMode, ftl::Flags<InputTarget::Flags> targetFlags, 556*38e8c45fSAndroid Build Coastguard Worker std::optional<nsecs_t> firstDownTimeInTarget) const REQUIRES(mLock); 557*38e8c45fSAndroid Build Coastguard Worker void addWindowTargetLocked(const sp<android::gui::WindowInfoHandle>& windowHandle, 558*38e8c45fSAndroid Build Coastguard Worker InputTarget::DispatchMode dispatchMode, 559*38e8c45fSAndroid Build Coastguard Worker ftl::Flags<InputTarget::Flags> targetFlags, 560*38e8c45fSAndroid Build Coastguard Worker std::optional<nsecs_t> firstDownTimeInTarget, 561*38e8c45fSAndroid Build Coastguard Worker std::vector<InputTarget>& inputTargets) const REQUIRES(mLock); 562*38e8c45fSAndroid Build Coastguard Worker void addPointerWindowTargetLocked(const sp<android::gui::WindowInfoHandle>& windowHandle, 563*38e8c45fSAndroid Build Coastguard Worker InputTarget::DispatchMode dispatchMode, 564*38e8c45fSAndroid Build Coastguard Worker ftl::Flags<InputTarget::Flags> targetFlags, 565*38e8c45fSAndroid Build Coastguard Worker std::bitset<MAX_POINTER_ID + 1> pointerIds, 566*38e8c45fSAndroid Build Coastguard Worker std::optional<nsecs_t> firstDownTimeInTarget, 567*38e8c45fSAndroid Build Coastguard Worker std::vector<InputTarget>& inputTargets) const REQUIRES(mLock); 568*38e8c45fSAndroid Build Coastguard Worker void addGlobalMonitoringTargetsLocked(std::vector<InputTarget>& inputTargets, 569*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId displayId) REQUIRES(mLock); 570*38e8c45fSAndroid Build Coastguard Worker void pokeUserActivityLocked(const EventEntry& eventEntry) REQUIRES(mLock); 571*38e8c45fSAndroid Build Coastguard Worker // Enqueue a drag event if needed, and update the touch state. 572*38e8c45fSAndroid Build Coastguard Worker // Uses findTouchedWindowTargetsLocked to make the decision 573*38e8c45fSAndroid Build Coastguard Worker void addDragEventLocked(const MotionEntry& entry) REQUIRES(mLock); 574*38e8c45fSAndroid Build Coastguard Worker void finishDragAndDrop(ui::LogicalDisplayId displayId, float x, float y) REQUIRES(mLock); 575*38e8c45fSAndroid Build Coastguard Worker 576*38e8c45fSAndroid Build Coastguard Worker struct TouchOcclusionInfo { 577*38e8c45fSAndroid Build Coastguard Worker bool hasBlockingOcclusion; 578*38e8c45fSAndroid Build Coastguard Worker float obscuringOpacity; 579*38e8c45fSAndroid Build Coastguard Worker std::string obscuringPackage; 580*38e8c45fSAndroid Build Coastguard Worker gui::Uid obscuringUid = gui::Uid::INVALID; 581*38e8c45fSAndroid Build Coastguard Worker std::vector<std::string> debugInfo; 582*38e8c45fSAndroid Build Coastguard Worker }; 583*38e8c45fSAndroid Build Coastguard Worker 584*38e8c45fSAndroid Build Coastguard Worker TouchOcclusionInfo computeTouchOcclusionInfoLocked( 585*38e8c45fSAndroid Build Coastguard Worker const sp<android::gui::WindowInfoHandle>& windowHandle, float x, float y) const 586*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 587*38e8c45fSAndroid Build Coastguard Worker bool isTouchTrustedLocked(const TouchOcclusionInfo& occlusionInfo) const REQUIRES(mLock); 588*38e8c45fSAndroid Build Coastguard Worker bool isWindowObscuredAtPointLocked(const sp<android::gui::WindowInfoHandle>& windowHandle, 589*38e8c45fSAndroid Build Coastguard Worker float x, float y) const REQUIRES(mLock); 590*38e8c45fSAndroid Build Coastguard Worker bool isWindowObscuredLocked(const sp<android::gui::WindowInfoHandle>& windowHandle) const 591*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 592*38e8c45fSAndroid Build Coastguard Worker std::string dumpWindowForTouchOcclusion(const android::gui::WindowInfo* info, 593*38e8c45fSAndroid Build Coastguard Worker bool isTouchWindow) const; 594*38e8c45fSAndroid Build Coastguard Worker std::string getApplicationWindowLabel(const InputApplicationHandle* applicationHandle, 595*38e8c45fSAndroid Build Coastguard Worker const sp<android::gui::WindowInfoHandle>& windowHandle); 596*38e8c45fSAndroid Build Coastguard Worker 597*38e8c45fSAndroid Build Coastguard Worker bool shouldDropInput(const EventEntry& entry, 598*38e8c45fSAndroid Build Coastguard Worker const sp<android::gui::WindowInfoHandle>& windowHandle) const 599*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 600*38e8c45fSAndroid Build Coastguard Worker 601*38e8c45fSAndroid Build Coastguard Worker // Manage the dispatch cycle for a single connection. 602*38e8c45fSAndroid Build Coastguard Worker // These methods are deliberately not Interruptible because doing all of the work 603*38e8c45fSAndroid Build Coastguard Worker // with the mutex held makes it easier to ensure that connection invariants are maintained. 604*38e8c45fSAndroid Build Coastguard Worker // If needed, the methods post commands to run later once the critical bits are done. 605*38e8c45fSAndroid Build Coastguard Worker void prepareDispatchCycleLocked(nsecs_t currentTime, 606*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<Connection>& connection, 607*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<const EventEntry>, 608*38e8c45fSAndroid Build Coastguard Worker const InputTarget& inputTarget) REQUIRES(mLock); 609*38e8c45fSAndroid Build Coastguard Worker void enqueueDispatchEntryAndStartDispatchCycleLocked( 610*38e8c45fSAndroid Build Coastguard Worker nsecs_t currentTime, const std::shared_ptr<Connection>& connection, 611*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<const EventEntry>, const InputTarget& inputTarget) REQUIRES(mLock); 612*38e8c45fSAndroid Build Coastguard Worker void enqueueDispatchEntryLocked(const std::shared_ptr<Connection>& connection, 613*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<const EventEntry>, 614*38e8c45fSAndroid Build Coastguard Worker const InputTarget& inputTarget) REQUIRES(mLock); 615*38e8c45fSAndroid Build Coastguard Worker status_t publishMotionEvent(Connection& connection, DispatchEntry& dispatchEntry) const; 616*38e8c45fSAndroid Build Coastguard Worker void startDispatchCycleLocked(nsecs_t currentTime, 617*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<Connection>& connection) REQUIRES(mLock); 618*38e8c45fSAndroid Build Coastguard Worker void finishDispatchCycleLocked(nsecs_t currentTime, 619*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<Connection>& connection, uint32_t seq, 620*38e8c45fSAndroid Build Coastguard Worker bool handled, nsecs_t consumeTime) REQUIRES(mLock); 621*38e8c45fSAndroid Build Coastguard Worker void abortBrokenDispatchCycleLocked(nsecs_t currentTime, 622*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<Connection>& connection, bool notify) 623*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 624*38e8c45fSAndroid Build Coastguard Worker void drainDispatchQueue(std::deque<std::unique_ptr<DispatchEntry>>& queue); 625*38e8c45fSAndroid Build Coastguard Worker void releaseDispatchEntry(std::unique_ptr<DispatchEntry> dispatchEntry); 626*38e8c45fSAndroid Build Coastguard Worker int handleReceiveCallback(int events, sp<IBinder> connectionToken); 627*38e8c45fSAndroid Build Coastguard Worker // The action sent should only be of type AMOTION_EVENT_* 628*38e8c45fSAndroid Build Coastguard Worker void dispatchPointerDownOutsideFocus(uint32_t source, int32_t action, 629*38e8c45fSAndroid Build Coastguard Worker const sp<IBinder>& newToken) REQUIRES(mLock); 630*38e8c45fSAndroid Build Coastguard Worker 631*38e8c45fSAndroid Build Coastguard Worker void synthesizeCancelationEventsForAllConnectionsLocked(const CancelationOptions& options) 632*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 633*38e8c45fSAndroid Build Coastguard Worker void synthesizeCancelationEventsForMonitorsLocked(const CancelationOptions& options) 634*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 635*38e8c45fSAndroid Build Coastguard Worker void synthesizeCancelationEventsForWindowLocked(const sp<gui::WindowInfoHandle>&, 636*38e8c45fSAndroid Build Coastguard Worker const CancelationOptions&, 637*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<Connection>& = nullptr) 638*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 639*38e8c45fSAndroid Build Coastguard Worker // This is a convenience function used to generate cancellation for a connection without having 640*38e8c45fSAndroid Build Coastguard Worker // to check whether it's a monitor or a window. For non-monitors, the window handle must not be 641*38e8c45fSAndroid Build Coastguard Worker // null. Always prefer the "-ForWindow" method above when explicitly dealing with windows. 642*38e8c45fSAndroid Build Coastguard Worker void synthesizeCancelationEventsForConnectionLocked( 643*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<Connection>& connection, const CancelationOptions& options, 644*38e8c45fSAndroid Build Coastguard Worker const sp<gui::WindowInfoHandle>& window) REQUIRES(mLock); 645*38e8c45fSAndroid Build Coastguard Worker 646*38e8c45fSAndroid Build Coastguard Worker void synthesizePointerDownEventsForConnectionLocked( 647*38e8c45fSAndroid Build Coastguard Worker const nsecs_t downTime, const std::shared_ptr<Connection>& connection, 648*38e8c45fSAndroid Build Coastguard Worker ftl::Flags<InputTarget::Flags> targetFlags, 649*38e8c45fSAndroid Build Coastguard Worker const std::unique_ptr<trace::EventTrackerInterface>& traceTracker) REQUIRES(mLock); 650*38e8c45fSAndroid Build Coastguard Worker 651*38e8c45fSAndroid Build Coastguard Worker // Splitting motion events across windows. When splitting motion event for a target, 652*38e8c45fSAndroid Build Coastguard Worker // splitDownTime refers to the time of first 'down' event on that particular target 653*38e8c45fSAndroid Build Coastguard Worker std::unique_ptr<MotionEntry> splitMotionEvent(const MotionEntry& originalMotionEntry, 654*38e8c45fSAndroid Build Coastguard Worker std::bitset<MAX_POINTER_ID + 1> pointerIds, 655*38e8c45fSAndroid Build Coastguard Worker nsecs_t splitDownTime) REQUIRES(mLock); 656*38e8c45fSAndroid Build Coastguard Worker 657*38e8c45fSAndroid Build Coastguard Worker // Reset and drop everything the dispatcher is doing. 658*38e8c45fSAndroid Build Coastguard Worker void resetAndDropEverythingLocked(const char* reason) REQUIRES(mLock); 659*38e8c45fSAndroid Build Coastguard Worker 660*38e8c45fSAndroid Build Coastguard Worker // Dump state. 661*38e8c45fSAndroid Build Coastguard Worker void dumpDispatchStateLocked(std::string& dump) const REQUIRES(mLock); 662*38e8c45fSAndroid Build Coastguard Worker void dumpMonitors(std::string& dump, const std::vector<Monitor>& monitors) const; 663*38e8c45fSAndroid Build Coastguard Worker void logDispatchStateLocked() const REQUIRES(mLock); 664*38e8c45fSAndroid Build Coastguard Worker std::string dumpPointerCaptureStateLocked() const REQUIRES(mLock); 665*38e8c45fSAndroid Build Coastguard Worker 666*38e8c45fSAndroid Build Coastguard Worker // Registration. 667*38e8c45fSAndroid Build Coastguard Worker void removeMonitorChannelLocked(const sp<IBinder>& connectionToken) REQUIRES(mLock); 668*38e8c45fSAndroid Build Coastguard Worker status_t removeInputChannelLocked(const sp<IBinder>& connectionToken, bool notify) 669*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 670*38e8c45fSAndroid Build Coastguard Worker 671*38e8c45fSAndroid Build Coastguard Worker // Interesting events that we might like to log or tell the framework about. 672*38e8c45fSAndroid Build Coastguard Worker void doDispatchCycleFinishedCommand(nsecs_t finishTime, 673*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<Connection>& connection, uint32_t seq, 674*38e8c45fSAndroid Build Coastguard Worker bool handled, nsecs_t consumeTime) REQUIRES(mLock); 675*38e8c45fSAndroid Build Coastguard Worker void doInterceptKeyBeforeDispatchingCommand(const sp<IBinder>& focusedWindowToken, 676*38e8c45fSAndroid Build Coastguard Worker const KeyEntry& entry) REQUIRES(mLock); 677*38e8c45fSAndroid Build Coastguard Worker void onFocusChangedLocked(const FocusResolver::FocusChanges& changes, 678*38e8c45fSAndroid Build Coastguard Worker const std::unique_ptr<trace::EventTrackerInterface>& traceTracker, 679*38e8c45fSAndroid Build Coastguard Worker const sp<gui::WindowInfoHandle> removedFocusedWindowHandle = nullptr) 680*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 681*38e8c45fSAndroid Build Coastguard Worker void sendFocusChangedCommandLocked(const sp<IBinder>& oldToken, const sp<IBinder>& newToken) 682*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 683*38e8c45fSAndroid Build Coastguard Worker void sendDropWindowCommandLocked(const sp<IBinder>& token, float x, float y) REQUIRES(mLock); 684*38e8c45fSAndroid Build Coastguard Worker void onAnrLocked(const std::shared_ptr<Connection>& connection) REQUIRES(mLock); 685*38e8c45fSAndroid Build Coastguard Worker void onAnrLocked(std::shared_ptr<InputApplicationHandle> application) REQUIRES(mLock); 686*38e8c45fSAndroid Build Coastguard Worker void updateLastAnrStateLocked(const sp<android::gui::WindowInfoHandle>& window, 687*38e8c45fSAndroid Build Coastguard Worker const std::string& reason) REQUIRES(mLock); 688*38e8c45fSAndroid Build Coastguard Worker void updateLastAnrStateLocked(const InputApplicationHandle& application, 689*38e8c45fSAndroid Build Coastguard Worker const std::string& reason) REQUIRES(mLock); 690*38e8c45fSAndroid Build Coastguard Worker void updateLastAnrStateLocked(const std::string& windowLabel, const std::string& reason) 691*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 692*38e8c45fSAndroid Build Coastguard Worker std::map<ui::LogicalDisplayId, InputVerifier> mVerifiersByDisplay; 693*38e8c45fSAndroid Build Coastguard Worker // Returns a fallback KeyEntry that should be sent to the connection, if required. 694*38e8c45fSAndroid Build Coastguard Worker std::unique_ptr<const KeyEntry> afterKeyEventLockedInterruptable( 695*38e8c45fSAndroid Build Coastguard Worker const std::shared_ptr<Connection>& connection, DispatchEntry* dispatchEntry, 696*38e8c45fSAndroid Build Coastguard Worker bool handled) REQUIRES(mLock); 697*38e8c45fSAndroid Build Coastguard Worker 698*38e8c45fSAndroid Build Coastguard Worker // Find touched state and touched window by token. 699*38e8c45fSAndroid Build Coastguard Worker std::tuple<TouchState*, TouchedWindow*, ui::LogicalDisplayId> 700*38e8c45fSAndroid Build Coastguard Worker findTouchStateWindowAndDisplayLocked(const sp<IBinder>& token) REQUIRES(mLock); 701*38e8c45fSAndroid Build Coastguard Worker 702*38e8c45fSAndroid Build Coastguard Worker std::tuple<const TouchState*, const TouchedWindow*, ui::LogicalDisplayId> 703*38e8c45fSAndroid Build Coastguard Worker findTouchStateWindowAndDisplayLocked(const sp<IBinder>& token) const REQUIRES(mLock); 704*38e8c45fSAndroid Build Coastguard Worker bool windowHasTouchingPointersLocked(const sp<android::gui::WindowInfoHandle>& windowHandle, 705*38e8c45fSAndroid Build Coastguard Worker DeviceId deviceId) const REQUIRES(mLock); 706*38e8c45fSAndroid Build Coastguard Worker 707*38e8c45fSAndroid Build Coastguard Worker // Statistics gathering. 708*38e8c45fSAndroid Build Coastguard Worker nsecs_t mLastStatisticPushTime = 0; 709*38e8c45fSAndroid Build Coastguard Worker std::unique_ptr<InputEventTimelineProcessor> mInputEventTimelineProcessor GUARDED_BY(mLock); 710*38e8c45fSAndroid Build Coastguard Worker LatencyTracker mLatencyTracker GUARDED_BY(mLock); 711*38e8c45fSAndroid Build Coastguard Worker void traceInboundQueueLengthLocked() REQUIRES(mLock); 712*38e8c45fSAndroid Build Coastguard Worker void traceOutboundQueueLength(const Connection& connection); 713*38e8c45fSAndroid Build Coastguard Worker void traceWaitQueueLength(const Connection& connection); 714*38e8c45fSAndroid Build Coastguard Worker 715*38e8c45fSAndroid Build Coastguard Worker // Check window ownership 716*38e8c45fSAndroid Build Coastguard Worker bool focusedWindowIsOwnedByLocked(gui::Pid pid, gui::Uid uid) REQUIRES(mLock); 717*38e8c45fSAndroid Build Coastguard Worker bool recentWindowsAreOwnedByLocked(gui::Pid pid, gui::Uid uid) REQUIRES(mLock); 718*38e8c45fSAndroid Build Coastguard Worker 719*38e8c45fSAndroid Build Coastguard Worker sp<InputReporterInterface> mReporter; 720*38e8c45fSAndroid Build Coastguard Worker 721*38e8c45fSAndroid Build Coastguard Worker /** 722*38e8c45fSAndroid Build Coastguard Worker * Slip the wallpaper touch if necessary. 723*38e8c45fSAndroid Build Coastguard Worker * 724*38e8c45fSAndroid Build Coastguard Worker * @param targetFlags the target flags 725*38e8c45fSAndroid Build Coastguard Worker * @param oldWindowHandle the old window that the touch slipped out of 726*38e8c45fSAndroid Build Coastguard Worker * @param newWindowHandle the new window that the touch is slipping into 727*38e8c45fSAndroid Build Coastguard Worker * @param state the current touch state. This will be updated if necessary to reflect the new 728*38e8c45fSAndroid Build Coastguard Worker * windows that are receiving touch. 729*38e8c45fSAndroid Build Coastguard Worker * @param deviceId the device id of the current motion being processed 730*38e8c45fSAndroid Build Coastguard Worker * @param pointerProperties the pointer properties of the current motion being processed 731*38e8c45fSAndroid Build Coastguard Worker * @param targets the current targets to add the walpaper ones to 732*38e8c45fSAndroid Build Coastguard Worker * @param eventTime the new downTime for the wallpaper target 733*38e8c45fSAndroid Build Coastguard Worker */ 734*38e8c45fSAndroid Build Coastguard Worker void slipWallpaperTouch(ftl::Flags<InputTarget::Flags> targetFlags, 735*38e8c45fSAndroid Build Coastguard Worker const sp<android::gui::WindowInfoHandle>& oldWindowHandle, 736*38e8c45fSAndroid Build Coastguard Worker const sp<android::gui::WindowInfoHandle>& newWindowHandle, 737*38e8c45fSAndroid Build Coastguard Worker TouchState& state, const MotionEntry& entry, 738*38e8c45fSAndroid Build Coastguard Worker std::vector<InputTarget>& targets) const REQUIRES(mLock); 739*38e8c45fSAndroid Build Coastguard Worker void transferWallpaperTouch(ftl::Flags<InputTarget::Flags> oldTargetFlags, 740*38e8c45fSAndroid Build Coastguard Worker ftl::Flags<InputTarget::Flags> newTargetFlags, 741*38e8c45fSAndroid Build Coastguard Worker const sp<android::gui::WindowInfoHandle> fromWindowHandle, 742*38e8c45fSAndroid Build Coastguard Worker const sp<android::gui::WindowInfoHandle> toWindowHandle, 743*38e8c45fSAndroid Build Coastguard Worker TouchState& state, DeviceId deviceId, 744*38e8c45fSAndroid Build Coastguard Worker const std::vector<PointerProperties>& pointers, 745*38e8c45fSAndroid Build Coastguard Worker const std::unique_ptr<trace::EventTrackerInterface>& traceTracker) 746*38e8c45fSAndroid Build Coastguard Worker REQUIRES(mLock); 747*38e8c45fSAndroid Build Coastguard Worker 748*38e8c45fSAndroid Build Coastguard Worker sp<android::gui::WindowInfoHandle> findWallpaperWindowBelow( 749*38e8c45fSAndroid Build Coastguard Worker const sp<android::gui::WindowInfoHandle>& windowHandle) const REQUIRES(mLock); 750*38e8c45fSAndroid Build Coastguard Worker 751*38e8c45fSAndroid Build Coastguard Worker /** Stores the value of the input flag for per device input latency metrics. */ 752*38e8c45fSAndroid Build Coastguard Worker const bool mPerDeviceInputLatencyMetricsFlag = 753*38e8c45fSAndroid Build Coastguard Worker com::android::input::flags::enable_per_device_input_latency_metrics(); 754*38e8c45fSAndroid Build Coastguard Worker }; 755*38e8c45fSAndroid Build Coastguard Worker 756*38e8c45fSAndroid Build Coastguard Worker } // namespace android::inputdispatcher 757