Skip to content

Commit 749b11b

Browse files
author
Arpit Singh
committed
[21/n Dispatcher refactor] Make touchStatesByDisplay private
In this Cl we make mTouchStatesbyDisplay private in DispatcherTouchState. For this we need to 1. Move canWindowReceiveMotion as a private method in the DispatcherTouchState along with isStylusActiveInDisplay. 2. Make findTouchedSpyWindowsAt static moving it back to Dispatcher. Bug: 367661487 Bug: 245989146 Test: atest inputflinger_tests Flag: EXEMPT refactor Change-Id: Ifc970b091b90cbeaf41d4932415417b161c2ae34
1 parent 8ce652f commit 749b11b

2 files changed

Lines changed: 37 additions & 43 deletions

File tree

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -798,20 +798,6 @@ bool shouldSplitTouch(int32_t source) {
798798
return !isFromSource(source, AINPUT_SOURCE_MOUSE);
799799
}
800800

801-
/**
802-
* Return true if stylus is currently down anywhere on the specified display, and false otherwise.
803-
*/
804-
bool isStylusActiveInDisplay(ui::LogicalDisplayId displayId,
805-
const std::unordered_map<ui::LogicalDisplayId /*displayId*/,
806-
TouchState>& touchStatesByDisplay) {
807-
const auto it = touchStatesByDisplay.find(displayId);
808-
if (it == touchStatesByDisplay.end()) {
809-
return false;
810-
}
811-
const TouchState& state = it->second;
812-
return state.hasActiveStylus();
813-
}
814-
815801
Result<void> validateWindowInfosUpdate(const gui::WindowInfosUpdate& update) {
816802
std::unordered_set<int32_t> windowIds;
817803
for (const WindowInfo& info : update.windowInfos) {
@@ -1350,9 +1336,8 @@ bool InputDispatcher::shouldPruneInboundQueueLocked(const MotionEntry& motionEnt
13501336

13511337
// Alternatively, maybe there's a spy window that could handle this event.
13521338
const std::vector<sp<WindowInfoHandle>> touchedSpies =
1353-
mWindowInfos.findTouchedSpyWindowsAt(displayId, x, y, isStylus,
1354-
motionEntry.deviceId,
1355-
mTouchStates.mTouchStatesByDisplay);
1339+
findTouchedSpyWindowsAt(displayId, x, y, isStylus, motionEntry.deviceId,
1340+
mWindowInfos);
13561341
for (const auto& windowHandle : touchedSpies) {
13571342
const std::shared_ptr<Connection> connection =
13581343
mConnectionManager.getConnection(windowHandle->getToken());
@@ -1510,16 +1495,16 @@ std::vector<InputTarget> InputDispatcher::DispatcherTouchState::findOutsideTarge
15101495
return outsideTargets;
15111496
}
15121497

1513-
std::vector<sp<WindowInfoHandle>> InputDispatcher::DispatcherWindowInfo::findTouchedSpyWindowsAt(
1498+
std::vector<sp<WindowInfoHandle>> InputDispatcher::findTouchedSpyWindowsAt(
15141499
ui::LogicalDisplayId displayId, float x, float y, bool isStylus, DeviceId deviceId,
1515-
const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay) const {
1500+
const DispatcherWindowInfo& windowInfos) {
15161501
// Traverse windows from front to back and gather the touched spy windows.
15171502
std::vector<sp<WindowInfoHandle>> spyWindows;
1518-
const auto& windowHandles = getWindowHandlesForDisplay(displayId);
1503+
const ui::Transform displayTransform = windowInfos.getDisplayTransform(displayId);
1504+
const auto& windowHandles = windowInfos.getWindowHandlesForDisplay(displayId);
15191505
for (const sp<WindowInfoHandle>& windowHandle : windowHandles) {
15201506
const WindowInfo& info = *windowHandle->getInfo();
1521-
if (!windowAcceptsTouchAt(info, displayId, x, y, isStylus,
1522-
getDisplayTransform(displayId))) {
1507+
if (!windowAcceptsTouchAt(info, displayId, x, y, isStylus, displayTransform)) {
15231508
// Skip if the pointer is outside of the window.
15241509
continue;
15251510
}
@@ -2480,8 +2465,7 @@ InputDispatcher::DispatcherTouchState::findTouchedWindowTargets(
24802465
}
24812466

24822467
std::vector<sp<WindowInfoHandle>> newTouchedWindows =
2483-
windowInfos.findTouchedSpyWindowsAt(displayId, x, y, isStylus, entry.deviceId,
2484-
mTouchStatesByDisplay);
2468+
findTouchedSpyWindowsAt(displayId, x, y, isStylus, entry.deviceId, windowInfos);
24852469
if (newTouchedWindowHandle != nullptr) {
24862470
// Process the foreground window first so that it is the first to receive the event.
24872471
newTouchedWindows.insert(newTouchedWindows.begin(), newTouchedWindowHandle);
@@ -2494,8 +2478,7 @@ InputDispatcher::DispatcherTouchState::findTouchedWindowTargets(
24942478
}
24952479

24962480
for (const sp<WindowInfoHandle>& windowHandle : newTouchedWindows) {
2497-
if (!canWindowReceiveMotion(windowHandle, entry, connections, windowInfos,
2498-
mTouchStatesByDisplay)) {
2481+
if (!canWindowReceiveMotion(windowHandle, entry, connections, windowInfos)) {
24992482
continue;
25002483
}
25012484

@@ -2618,8 +2601,7 @@ InputDispatcher::DispatcherTouchState::findTouchedWindowTargets(
26182601

26192602
// Do not slide events to the window which can not receive motion event
26202603
if (newTouchedWindowHandle != nullptr &&
2621-
!canWindowReceiveMotion(newTouchedWindowHandle, entry, connections, windowInfos,
2622-
mTouchStatesByDisplay)) {
2604+
!canWindowReceiveMotion(newTouchedWindowHandle, entry, connections, windowInfos)) {
26232605
newTouchedWindowHandle = nullptr;
26242606
}
26252607

@@ -5277,11 +5259,10 @@ std::string InputDispatcher::DispatcherWindowInfo::dumpDisplayAndWindowInfo() co
52775259
return dump;
52785260
}
52795261

5280-
bool InputDispatcher::canWindowReceiveMotion(
5262+
bool InputDispatcher::DispatcherTouchState::canWindowReceiveMotion(
52815263
const sp<android::gui::WindowInfoHandle>& window,
52825264
const android::inputdispatcher::MotionEntry& motionEntry,
5283-
const ConnectionManager& connections, const DispatcherWindowInfo& windowInfos,
5284-
const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStates) {
5265+
const ConnectionManager& connections, const DispatcherWindowInfo& windowInfos) const {
52855266
const WindowInfo& info = *window->getInfo();
52865267

52875268
// Skip spy window targets that are not valid for targeted injection.
@@ -5335,7 +5316,7 @@ bool InputDispatcher::canWindowReceiveMotion(
53355316

53365317
// Ignore touches if stylus is down anywhere on screen
53375318
if (info.inputConfig.test(WindowInfo::InputConfig::GLOBAL_STYLUS_BLOCKS_TOUCH) &&
5338-
isStylusActiveInDisplay(info.displayId, touchStates)) {
5319+
isStylusActiveInDisplay(info.displayId)) {
53395320
LOG(INFO) << "Dropping touch from " << window->getName() << " because stylus is active";
53405321
return false;
53415322
}
@@ -7539,4 +7520,14 @@ InputDispatcher::DispatcherTouchState::findTouchStateWindowAndDisplay(
75397520
return std::nullopt;
75407521
}
75417522

7523+
bool InputDispatcher::DispatcherTouchState::isStylusActiveInDisplay(
7524+
ui::LogicalDisplayId displayId) const {
7525+
const auto it = mTouchStatesByDisplay.find(displayId);
7526+
if (it == mTouchStatesByDisplay.end()) {
7527+
return false;
7528+
}
7529+
const TouchState& state = it->second;
7530+
return state.hasActiveStylus();
7531+
}
7532+
75427533
} // namespace android::inputdispatcher

services/inputflinger/dispatcher/InputDispatcher.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,6 @@ class InputDispatcher : public android::InputDispatcherInterface {
319319
ui::LogicalDisplayId displayId, float x, float y, bool isStylus = false,
320320
const sp<android::gui::WindowInfoHandle> ignoreWindow = nullptr) const;
321321

322-
std::vector<sp<android::gui::WindowInfoHandle>> findTouchedSpyWindowsAt(
323-
ui::LogicalDisplayId displayId, float x, float y, bool isStylus, DeviceId deviceId,
324-
const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay)
325-
const;
326-
327322
TouchOcclusionInfo computeTouchOcclusionInfo(
328323
const sp<android::gui::WindowInfoHandle>& windowHandle, float x, float y) const;
329324

@@ -425,9 +420,9 @@ class InputDispatcher : public android::InputDispatcherInterface {
425420

426421
void clear();
427422

423+
private:
428424
std::unordered_map<ui::LogicalDisplayId, TouchState> mTouchStatesByDisplay;
429425

430-
private:
431426
std::optional<std::tuple<TouchState&, TouchedWindow&, ui::LogicalDisplayId>>
432427
findTouchStateWindowAndDisplay(const sp<IBinder>& token);
433428

@@ -439,6 +434,15 @@ class InputDispatcher : public android::InputDispatcherInterface {
439434
ftl::Flags<InputTarget::Flags> newTargetFlags,
440435
const DispatcherWindowInfo& windowInfos, const ConnectionManager& connections);
441436

437+
bool canWindowReceiveMotion(const sp<android::gui::WindowInfoHandle>& window,
438+
const MotionEntry& motionEntry,
439+
const ConnectionManager& connections,
440+
const DispatcherWindowInfo& windowInfos) const;
441+
442+
// Return true if stylus is currently down anywhere on the specified display,
443+
// and false otherwise.
444+
bool isStylusActiveInDisplay(ui::LogicalDisplayId displayId) const;
445+
442446
static std::list<CancellationArgs> eraseRemovedWindowsFromWindowInfo(
443447
TouchState& state, ui::LogicalDisplayId displayId,
444448
const DispatcherWindowInfo& windowInfos);
@@ -594,11 +598,6 @@ class InputDispatcher : public android::InputDispatcherInterface {
594598
sp<android::gui::WindowInfoHandle> getFocusedWindowHandleLocked(
595599
ui::LogicalDisplayId displayId) const REQUIRES(mLock);
596600

597-
static bool canWindowReceiveMotion(
598-
const sp<android::gui::WindowInfoHandle>& window, const MotionEntry& motionEntry,
599-
const ConnectionManager& connections, const DispatcherWindowInfo& windowInfos,
600-
const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStates);
601-
602601
// Returns all the input targets (with their respective input channels) from the window handles
603602
// passed as argument.
604603
std::vector<InputTarget> getInputTargetsFromWindowHandlesLocked(
@@ -768,6 +767,10 @@ class InputDispatcher : public android::InputDispatcherInterface {
768767
std::string getApplicationWindowLabel(const InputApplicationHandle* applicationHandle,
769768
const sp<android::gui::WindowInfoHandle>& windowHandle);
770769

770+
static std::vector<sp<android::gui::WindowInfoHandle>> findTouchedSpyWindowsAt(
771+
ui::LogicalDisplayId displayId, float x, float y, bool isStylus, DeviceId deviceId,
772+
const DispatcherWindowInfo& windowInfos);
773+
771774
static bool shouldDropInput(const EventEntry& entry,
772775
const sp<android::gui::WindowInfoHandle>& windowHandle,
773776
const DispatcherWindowInfo& windowInfo);

0 commit comments

Comments
 (0)