Skip to content

Commit a1635a6

Browse files
Treehugger RobotAndroid (Google) Code Review
authored andcommitted
Merge "Remove non-split touch from input code" into main
2 parents cbded5e + 2b5d249 commit a1635a6

9 files changed

Lines changed: 103 additions & 248 deletions

File tree

libs/gui/WindowInfo.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ void WindowInfo::addTouchableRegion(const Rect& region) {
9999
touchableRegion.orSelf(region);
100100
}
101101

102-
bool WindowInfo::supportsSplitTouch() const {
103-
return !inputConfig.test(InputConfig::PREVENT_SPLITTING);
104-
}
105-
106102
bool WindowInfo::isSpy() const {
107103
return inputConfig.test(InputConfig::SPY);
108104
}

libs/gui/include/gui/WindowInfo.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ struct WindowInfo : public Parcelable {
150150
static_cast<uint32_t>(os::InputConfig::NOT_FOCUSABLE),
151151
NOT_TOUCHABLE =
152152
static_cast<uint32_t>(os::InputConfig::NOT_TOUCHABLE),
153-
PREVENT_SPLITTING =
154-
static_cast<uint32_t>(os::InputConfig::PREVENT_SPLITTING),
155153
DUPLICATE_TOUCH_TO_WALLPAPER =
156154
static_cast<uint32_t>(os::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER),
157155
IS_WALLPAPER =

libs/input/android/os/InputConfig.aidl

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,9 @@ enum InputConfig {
5757
NOT_TOUCHABLE = 1 << 3,
5858

5959
/**
60-
* Indicates that this window will not accept a touch event that is split between
61-
* more than one window. When set:
62-
* - If this window receives a DOWN event with the first pointer, all successive
63-
* pointers that go down, regardless of their location on the screen, will be
64-
* directed to this window;
65-
* - If the DOWN event lands outside the touchable bounds of this window, no
66-
* successive pointers that go down, regardless of their location on the screen,
67-
* will be directed to this window.
68-
*/
69-
PREVENT_SPLITTING = 1 << 4,
60+
* This flag is now deprecated and should not be used.
61+
*/
62+
DEPRECATED_PREVENT_SPLITTING = 1 << 4,
7063

7164
/**
7265
* Indicates that this window shows the wallpaper behind it, so all touch events

libs/input/input_flags.aconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ flag {
3737
}
3838

3939
flag {
40-
name: "split_all_touches"
40+
name: "deprecate_split_touch_apis"
4141
namespace: "input"
42-
description: "Set FLAG_SPLIT_TOUCHES to true for all windows, regardless of what they specify. This is essentially deprecating this flag by forcefully enabling the split functionality"
42+
description: "Deprecate all public APIs related to split touch because now all windows behave as if split touch is permanently enabled and there's no way for a window to disable split touch."
4343
bug: "239934827"
4444
}
4545

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 13 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -788,38 +788,14 @@ void filterUntrustedTargets(TouchState& touchState, std::vector<InputTarget>& ta
788788
});
789789
}
790790

791-
/**
792-
* In general, touch should be always split between windows. Some exceptions:
793-
* 1. Don't split touch if all of the below is true:
794-
* (a) we have an active pointer down *and*
795-
* (b) a new pointer is going down that's from the same device *and*
796-
* (c) the window that's receiving the current pointer does not support split touch.
797-
* 2. Don't split mouse events
798-
*/
799-
bool shouldSplitTouch(const TouchState& touchState, const MotionEntry& entry) {
800-
if (isFromSource(entry.source, AINPUT_SOURCE_MOUSE)) {
801-
// We should never split mouse events
802-
return false;
803-
}
804-
for (const TouchedWindow& touchedWindow : touchState.windows) {
805-
if (touchedWindow.windowHandle->getInfo()->isSpy()) {
806-
// Spy windows should not affect whether or not touch is split.
807-
continue;
808-
}
809-
if (touchedWindow.windowHandle->getInfo()->supportsSplitTouch()) {
810-
continue;
811-
}
812-
if (touchedWindow.windowHandle->getInfo()->inputConfig.test(
813-
gui::WindowInfo::InputConfig::IS_WALLPAPER)) {
814-
// Wallpaper window should not affect whether or not touch is split
815-
continue;
816-
}
817-
818-
if (touchedWindow.hasTouchingPointers(entry.deviceId)) {
819-
return false;
820-
}
821-
}
822-
return true;
791+
bool shouldSplitTouch(int32_t source) {
792+
// We should never split mouse events. This is because the events that are produced by touchpad
793+
// are sent to InputDispatcher as two fingers (for example, pinch zoom), but they need to be
794+
// dispatched to the same window. In those cases, the behaviour is also slightly different from
795+
// default because the events should be sent to the cursor position rather than the x,y values
796+
// of each of the fingers.
797+
// The "normal" (uncaptured) events produced by touchpad and by mouse have SOURCE_MOUSE.
798+
return !isFromSource(source, AINPUT_SOURCE_MOUSE);
823799
}
824800

825801
/**
@@ -1528,20 +1504,8 @@ std::vector<sp<WindowInfoHandle>> InputDispatcher::DispatcherWindowInfo::findTou
15281504
const WindowInfo& info = *windowHandle->getInfo();
15291505
if (!windowAcceptsTouchAt(info, displayId, x, y, isStylus,
15301506
getDisplayTransform(displayId))) {
1531-
// Generally, we would skip any pointer that's outside of the window. However, if the
1532-
// spy prevents splitting, and already has some of the pointers from this device, then
1533-
// it should get more pointers from the same device, even if they are outside of that
1534-
// window
1535-
if (info.supportsSplitTouch()) {
1536-
continue;
1537-
}
1538-
1539-
// We know that split touch is not supported. Skip this window only if it doesn't have
1540-
// any touching pointers for this device already.
1541-
if (!windowHasTouchingPointers(windowHandle, deviceId, touchStatesByDisplay)) {
1542-
continue;
1543-
}
1544-
// If it already has pointers down for this device, then give it this pointer, too.
1507+
// Skip if the pointer is outside of the window.
1508+
continue;
15451509
}
15461510
if (!info.isSpy()) {
15471511
// The first touched non-spy window was found, so return the spy windows touched so far.
@@ -2448,7 +2412,7 @@ InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, const Motio
24482412
tempTouchState = *oldState;
24492413
}
24502414

2451-
bool isSplit = shouldSplitTouch(tempTouchState, entry);
2415+
bool isSplit = shouldSplitTouch(entry.source);
24522416

24532417
const bool isHoverAction = (maskedAction == AMOTION_EVENT_ACTION_HOVER_MOVE ||
24542418
maskedAction == AMOTION_EVENT_ACTION_HOVER_ENTER ||
@@ -2501,42 +2465,14 @@ InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, const Motio
25012465
LOG_IF(INFO, newTouchedWindowHandle == nullptr)
25022466
<< "No new touched window at (" << std::format("{:.1f}, {:.1f}", x, y)
25032467
<< ") in display " << displayId;
2504-
// Handle the case where we did not find a window.
2505-
if (!input_flags::split_all_touches()) {
2506-
// If we are force splitting all touches, then touches outside of the window should
2507-
// be dropped, even if this device already has pointers down in another window.
2508-
if (newTouchedWindowHandle == nullptr) {
2509-
// Try to assign the pointer to the first foreground window we find, if there is
2510-
// one.
2511-
newTouchedWindowHandle =
2512-
tempTouchState.getFirstForegroundWindowHandle(entry.deviceId);
2513-
}
2514-
}
25152468

25162469
// Verify targeted injection.
25172470
if (const auto err = verifyTargetedInjection(newTouchedWindowHandle, entry); err) {
25182471
ALOGW("Dropping injected touch event: %s", (*err).c_str());
25192472
return injectionError(InputEventInjectionResult::TARGET_MISMATCH);
25202473
}
25212474

2522-
// Figure out whether splitting will be allowed for this window.
2523-
if (newTouchedWindowHandle != nullptr) {
2524-
if (newTouchedWindowHandle->getInfo()->supportsSplitTouch()) {
2525-
// New window supports splitting, but we should never split mouse events.
2526-
isSplit = !isFromMouse;
2527-
} else if (isSplit) {
2528-
// New window does not support splitting but we have already split events.
2529-
// Ignore the new window.
2530-
LOG(INFO) << "Skipping " << newTouchedWindowHandle->getName()
2531-
<< " because it doesn't support split touch";
2532-
newTouchedWindowHandle = nullptr;
2533-
}
2534-
} else {
2535-
// No window is touched, so set split to true. This will allow the next pointer down to
2536-
// be delivered to a new window which supports split touch. Pointers from a mouse device
2537-
// should never be split.
2538-
isSplit = !isFromMouse;
2539-
}
2475+
isSplit = !isFromMouse;
25402476

25412477
std::vector<sp<WindowInfoHandle>> newTouchedWindows =
25422478
mWindowInfos.findTouchedSpyWindowsAt(displayId, x, y, isStylus, entry.deviceId,
@@ -2711,9 +2647,7 @@ InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, const Motio
27112647
targets);
27122648

27132649
// Make a slippery entrance into the new window.
2714-
if (newTouchedWindowHandle->getInfo()->supportsSplitTouch()) {
2715-
isSplit = !isFromMouse;
2716-
}
2650+
isSplit = !isFromMouse;
27172651

27182652
ftl::Flags<InputTarget::Flags> targetFlags;
27192653
if (canReceiveForegroundTouches(*newTouchedWindowHandle->getInfo())) {
@@ -5845,18 +5779,6 @@ InputDispatcher::findTouchStateWindowAndDisplay(
58455779
const_cast<TouchedWindow*>(constTouchedWindow), displayId);
58465780
}
58475781

5848-
bool InputDispatcher::windowHasTouchingPointers(
5849-
const sp<WindowInfoHandle>& windowHandle, DeviceId deviceId,
5850-
const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay) {
5851-
const auto& [touchState, touchedWindow, _] =
5852-
findTouchStateWindowAndDisplay(windowHandle->getToken(), touchStatesByDisplay);
5853-
if (touchState == nullptr) {
5854-
// No touching pointers at all
5855-
return false;
5856-
}
5857-
return touchState->hasTouchingPointers(deviceId);
5858-
}
5859-
58605782
bool InputDispatcher::transferTouchGesture(const sp<IBinder>& fromToken, const sp<IBinder>& toToken,
58615783
bool isDragDrop) {
58625784
if (fromToken == toToken) {
@@ -7176,13 +7098,6 @@ void InputDispatcher::onWindowInfosChanged(const gui::WindowInfosUpdate& update)
71767098
for (const auto& info : update.windowInfos) {
71777099
handlesPerDisplay.emplace(info.displayId, std::vector<sp<WindowInfoHandle>>());
71787100
handlesPerDisplay[info.displayId].push_back(sp<WindowInfoHandle>::make(info));
7179-
if (input_flags::split_all_touches()) {
7180-
handlesPerDisplay[info.displayId]
7181-
.back()
7182-
->editInfo()
7183-
->setInputConfig(android::gui::WindowInfo::InputConfig::PREVENT_SPLITTING,
7184-
false);
7185-
}
71867101
}
71877102

71887103
{ // acquire lock

services/inputflinger/dispatcher/InputDispatcher.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,10 +736,6 @@ class InputDispatcher : public android::InputDispatcherInterface {
736736
const sp<IBinder>& token,
737737
const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay);
738738

739-
static bool windowHasTouchingPointers(
740-
const sp<android::gui::WindowInfoHandle>& windowHandle, DeviceId deviceId,
741-
const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay);
742-
743739
// Statistics gathering.
744740
nsecs_t mLastStatisticPushTime = 0;
745741
std::unique_ptr<InputEventTimelineProcessor> mInputEventTimelineProcessor GUARDED_BY(mLock);

services/inputflinger/tests/FakeWindows.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ class FakeWindowHandle : public gui::WindowInfoHandle {
144144
mInfo.setInputConfig(InputConfig::PAUSE_DISPATCHING, paused);
145145
}
146146

147-
inline void setPreventSplitting(bool preventSplitting) {
148-
mInfo.setInputConfig(InputConfig::PREVENT_SPLITTING, preventSplitting);
149-
}
150-
151147
inline void setSlippery(bool slippery) {
152148
mInfo.setInputConfig(InputConfig::SLIPPERY, slippery);
153149
}

0 commit comments

Comments
 (0)