@@ -224,6 +224,119 @@ class InputDispatcher : public android::InputDispatcherInterface {
224224 /* * Stores the latest user-activity poke event times per user activity types. */
225225 std::array<nsecs_t , USER_ACTIVITY_EVENT_LAST + 1 > mLastUserActivityTimes GUARDED_BY (mLock );
226226
227+ template <typename T>
228+ struct StrongPointerHash {
229+ std::size_t operator ()(const sp<T>& b) const { return std::hash<T*>{}(b.get ()); }
230+ };
231+
232+ class ConnectionManager {
233+ public:
234+ ConnectionManager (const sp<Looper>& lopper);
235+ ~ConnectionManager ();
236+
237+ std::shared_ptr<Connection> getConnection (const sp<IBinder>& inputConnectionToken) const ;
238+
239+ // Find a monitor pid by the provided token.
240+ std::optional<gui::Pid> findMonitorPidByToken (const sp<IBinder>& token) const ;
241+ void forEachGlobalMonitorConnection (
242+ std::function<void (const std::shared_ptr<Connection>&)> f) const ;
243+ void forEachGlobalMonitorConnection (
244+ ui::LogicalDisplayId displayId,
245+ std::function<void (const std::shared_ptr<Connection>&)> f) const ;
246+
247+ void createGlobalInputMonitor (ui::LogicalDisplayId displayId,
248+ std::unique_ptr<InputChannel>&& inputChannel,
249+ const IdGenerator& idGenerator, gui::Pid pid,
250+ std::function<int (int )> callback);
251+
252+ status_t removeConnection (const std::shared_ptr<Connection>& connection);
253+
254+ void createConnection (std::unique_ptr<InputChannel>&& inputChannel,
255+ const IdGenerator& idGenerator, std::function<int (int )> callback);
256+
257+ std::string dump (nsecs_t currentTime) const ;
258+
259+ private:
260+ const sp<Looper> mLooper ;
261+
262+ // All registered connections mapped by input channel token.
263+ std::unordered_map<sp<IBinder>, std::shared_ptr<Connection>, StrongPointerHash<IBinder>>
264+ mConnectionsByToken ;
265+
266+ // Input channels that will receive a copy of all input events sent to the provided display.
267+ std::unordered_map<ui::LogicalDisplayId, std::vector<Monitor>> mGlobalMonitorsByDisplay ;
268+
269+ void removeMonitorChannel (const sp<IBinder>& connectionToken);
270+ };
271+
272+ ConnectionManager mConnectionManager GUARDED_BY (mLock );
273+
274+ class DispatcherWindowInfo {
275+ public:
276+ struct TouchOcclusionInfo {
277+ bool hasBlockingOcclusion;
278+ float obscuringOpacity;
279+ std::string obscuringPackage;
280+ gui::Uid obscuringUid = gui::Uid::INVALID;
281+ std::vector<std::string> debugInfo;
282+ };
283+
284+ void setWindowHandlesForDisplay (
285+ ui::LogicalDisplayId displayId,
286+ std::vector<sp<android::gui::WindowInfoHandle>>&& windowHandles);
287+
288+ void setDisplayInfos (const std::vector<android::gui::DisplayInfo>& displayInfos);
289+
290+ void removeDisplay (ui::LogicalDisplayId displayId);
291+
292+ // Get a reference to window handles by display, return an empty vector if not found.
293+ const std::vector<sp<android::gui::WindowInfoHandle>>& getWindowHandlesForDisplay (
294+ ui::LogicalDisplayId displayId) const ;
295+
296+ void forEachWindowHandle (
297+ std::function<void (const sp<android::gui::WindowInfoHandle>&)> f) const ;
298+
299+ void forEachDisplayId (std::function<void (ui::LogicalDisplayId)> f) const ;
300+
301+ // Get the transform for display, returns Identity-transform if display is missing.
302+ ui::Transform getDisplayTransform (ui::LogicalDisplayId displayId) const ;
303+
304+ // Get the raw transform to use for motion events going to the given window.
305+ ui::Transform getRawTransform (const android::gui::WindowInfo&) const ;
306+
307+ // Lookup for WindowInfoHandle from token and optionally a display-id. In cases where
308+ // display-id is not provided lookup is done for all displays.
309+ sp<android::gui::WindowInfoHandle> findWindowHandle (
310+ const sp<IBinder>& windowHandleToken,
311+ std::optional<ui::LogicalDisplayId> displayId = {}) const ;
312+
313+ bool isWindowPresent (const sp<android::gui::WindowInfoHandle>& windowHandle) const ;
314+
315+ // Returns the touched window at the given location, excluding the ignoreWindow if provided.
316+ sp<android::gui::WindowInfoHandle> findTouchedWindowAt (
317+ ui::LogicalDisplayId displayId, float x, float y, bool isStylus = false ,
318+ const sp<android::gui::WindowInfoHandle> ignoreWindow = nullptr ) const ;
319+
320+ std::vector<sp<android::gui::WindowInfoHandle>> findTouchedSpyWindowsAt (
321+ ui::LogicalDisplayId displayId, float x, float y, bool isStylus, DeviceId deviceId,
322+ const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay)
323+ const ;
324+
325+ TouchOcclusionInfo computeTouchOcclusionInfo (
326+ const sp<android::gui::WindowInfoHandle>& windowHandle, float x, float y) const ;
327+
328+ std::string dumpDisplayAndWindowInfo () const ;
329+
330+ private:
331+ std::unordered_map<ui::LogicalDisplayId /* displayId*/ ,
332+ std::vector<sp<android::gui::WindowInfoHandle>>>
333+ mWindowHandlesByDisplay ;
334+ std::unordered_map<ui::LogicalDisplayId /* displayId*/ , android::gui::DisplayInfo>
335+ mDisplayInfos ;
336+ };
337+
338+ DispatcherWindowInfo mWindowInfos GUARDED_BY (mLock );
339+
227340 // With each iteration, InputDispatcher nominally processes one queued event,
228341 // a timeout, or a response from an input consumer.
229342 // This method should only be called on the input dispatcher's own thread.
@@ -262,11 +375,6 @@ class InputDispatcher : public android::InputDispatcherInterface {
262375
263376 status_t pilferPointersLocked (const sp<IBinder>& token) REQUIRES(mLock );
264377
265- template <typename T>
266- struct StrongPointerHash {
267- std::size_t operator ()(const sp<T>& b) const { return std::hash<T*>{}(b.get ()); }
268- };
269-
270378 const HmacKeyManager mHmacKeyManager ;
271379 const std::array<uint8_t , 32 > getSignature (const MotionEntry& motionEntry,
272380 const DispatchEntry& dispatchEntry) const ;
@@ -344,103 +452,6 @@ class InputDispatcher : public android::InputDispatcherInterface {
344452 };
345453 sp<gui::WindowInfosListener> mWindowInfoListener ;
346454
347- class DispatcherWindowInfo {
348- public:
349- void setWindowHandlesForDisplay (
350- ui::LogicalDisplayId displayId,
351- std::vector<sp<android::gui::WindowInfoHandle>>&& windowHandles);
352-
353- void setDisplayInfos (const std::vector<android::gui::DisplayInfo>& displayInfos);
354-
355- void removeDisplay (ui::LogicalDisplayId displayId);
356-
357- // Get a reference to window handles by display, return an empty vector if not found.
358- const std::vector<sp<android::gui::WindowInfoHandle>>& getWindowHandlesForDisplay (
359- ui::LogicalDisplayId displayId) const ;
360-
361- void forEachWindowHandle (
362- std::function<void (const sp<android::gui::WindowInfoHandle>&)> f) const ;
363-
364- void forEachDisplayId (std::function<void (ui::LogicalDisplayId)> f) const ;
365-
366- // Get the transform for display, returns Identity-transform if display is missing.
367- ui::Transform getDisplayTransform (ui::LogicalDisplayId displayId) const ;
368-
369- // Get the raw transform to use for motion events going to the given window.
370- ui::Transform getRawTransform (const android::gui::WindowInfo&) const ;
371-
372- // Lookup for WindowInfoHandle from token and optionally a display-id. In cases where
373- // display-id is not provided lookup is done for all displays.
374- sp<android::gui::WindowInfoHandle> findWindowHandle (
375- const sp<IBinder>& windowHandleToken,
376- std::optional<ui::LogicalDisplayId> displayId = {}) const ;
377-
378- bool isWindowPresent (const sp<android::gui::WindowInfoHandle>& windowHandle) const ;
379-
380- // Returns the touched window at the given location, excluding the ignoreWindow if provided.
381- sp<android::gui::WindowInfoHandle> findTouchedWindowAt (
382- ui::LogicalDisplayId displayId, float x, float y, bool isStylus = false ,
383- const sp<android::gui::WindowInfoHandle> ignoreWindow = nullptr ) const ;
384-
385- std::vector<sp<android::gui::WindowInfoHandle>> findTouchedSpyWindowsAt (
386- ui::LogicalDisplayId displayId, float x, float y, bool isStylus, DeviceId deviceId,
387- const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay)
388- const ;
389-
390- std::string dumpDisplayAndWindowInfo () const ;
391-
392- private:
393- std::unordered_map<ui::LogicalDisplayId /* displayId*/ ,
394- std::vector<sp<android::gui::WindowInfoHandle>>>
395- mWindowHandlesByDisplay ;
396- std::unordered_map<ui::LogicalDisplayId /* displayId*/ , android::gui::DisplayInfo>
397- mDisplayInfos ;
398- };
399-
400- DispatcherWindowInfo mWindowInfos GUARDED_BY (mLock );
401-
402- class ConnectionManager {
403- public:
404- ConnectionManager (const sp<Looper>& lopper);
405- ~ConnectionManager ();
406-
407- std::shared_ptr<Connection> getConnection (const sp<IBinder>& inputConnectionToken) const ;
408-
409- // Find a monitor pid by the provided token.
410- std::optional<gui::Pid> findMonitorPidByToken (const sp<IBinder>& token) const ;
411- void forEachGlobalMonitorConnection (
412- std::function<void (const std::shared_ptr<Connection>&)> f) const ;
413- void forEachGlobalMonitorConnection (
414- ui::LogicalDisplayId displayId,
415- std::function<void (const std::shared_ptr<Connection>&)> f) const ;
416-
417- void createGlobalInputMonitor (ui::LogicalDisplayId displayId,
418- std::unique_ptr<InputChannel>&& inputChannel,
419- const IdGenerator& idGenerator, gui::Pid pid,
420- std::function<int (int )> callback);
421-
422- status_t removeConnection (const std::shared_ptr<Connection>& connection);
423-
424- void createConnection (std::unique_ptr<InputChannel>&& inputChannel,
425- const IdGenerator& idGenerator, std::function<int (int )> callback);
426-
427- std::string dump (nsecs_t currentTime) const ;
428-
429- private:
430- const sp<Looper> mLooper ;
431-
432- // All registered connections mapped by input channel token.
433- std::unordered_map<sp<IBinder>, std::shared_ptr<Connection>, StrongPointerHash<IBinder>>
434- mConnectionsByToken ;
435-
436- // Input channels that will receive a copy of all input events sent to the provided display.
437- std::unordered_map<ui::LogicalDisplayId, std::vector<Monitor>> mGlobalMonitorsByDisplay ;
438-
439- void removeMonitorChannel (const sp<IBinder>& connectionToken);
440- };
441-
442- ConnectionManager mConnectionManager GUARDED_BY (mLock );
443-
444455 void setInputWindowsLocked (
445456 const std::vector<sp<android::gui::WindowInfoHandle>>& inputWindowHandles,
446457 ui::LogicalDisplayId displayId) REQUIRES(mLock );
@@ -626,24 +637,12 @@ class InputDispatcher : public android::InputDispatcherInterface {
626637 void addDragEventLocked (const MotionEntry& entry) REQUIRES(mLock );
627638 void finishDragAndDrop (ui::LogicalDisplayId displayId, float x, float y) REQUIRES(mLock );
628639
629- struct TouchOcclusionInfo {
630- bool hasBlockingOcclusion;
631- float obscuringOpacity;
632- std::string obscuringPackage;
633- gui::Uid obscuringUid = gui::Uid::INVALID;
634- std::vector<std::string> debugInfo;
635- };
636-
637- TouchOcclusionInfo computeTouchOcclusionInfoLocked (
638- const sp<android::gui::WindowInfoHandle>& windowHandle, float x, float y) const
640+ bool isTouchTrustedLocked (const DispatcherWindowInfo::TouchOcclusionInfo& occlusionInfo) const
639641 REQUIRES(mLock );
640- bool isTouchTrustedLocked (const TouchOcclusionInfo& occlusionInfo) const REQUIRES(mLock );
641642 bool isWindowObscuredAtPointLocked (const sp<android::gui::WindowInfoHandle>& windowHandle,
642643 float x, float y) const REQUIRES(mLock );
643644 bool isWindowObscuredLocked (const sp<android::gui::WindowInfoHandle>& windowHandle) const
644645 REQUIRES(mLock );
645- std::string dumpWindowForTouchOcclusion (const android::gui::WindowInfo* info,
646- bool isTouchWindow) const ;
647646 std::string getApplicationWindowLabel (const InputApplicationHandle* applicationHandle,
648647 const sp<android::gui::WindowInfoHandle>& windowHandle);
649648
0 commit comments