Skip to content

Commit 0e2f197

Browse files
prabirmspAndroid (Google) Code Review
authored andcommitted
Merge "InputDispatcher: Rename transferTouch APIs" into main
2 parents 04c80fc + 367f343 commit 0e2f197

4 files changed

Lines changed: 62 additions & 58 deletions

File tree

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5562,8 +5562,8 @@ InputDispatcher::findTouchStateWindowAndDisplayLocked(const sp<IBinder>& token)
55625562
return std::make_tuple(nullptr, nullptr, ADISPLAY_ID_DEFAULT);
55635563
}
55645564

5565-
bool InputDispatcher::transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken,
5566-
bool isDragDrop) {
5565+
bool InputDispatcher::transferTouchGesture(const sp<IBinder>& fromToken, const sp<IBinder>& toToken,
5566+
bool isDragDrop) {
55675567
if (fromToken == toToken) {
55685568
if (DEBUG_FOCUS) {
55695569
ALOGD("Trivial transfer to same window.");
@@ -5597,7 +5597,7 @@ bool InputDispatcher::transferTouchFocus(const sp<IBinder>& fromToken, const sp<
55975597
}
55985598

55995599
if (DEBUG_FOCUS) {
5600-
ALOGD("transferTouchFocus: fromWindowHandle=%s, toWindowHandle=%s",
5600+
ALOGD("%s: fromWindowHandle=%s, toWindowHandle=%s", __func__,
56015601
touchedWindow->windowHandle->getName().c_str(),
56025602
toWindowHandle->getName().c_str());
56035603
}
@@ -5683,7 +5683,8 @@ sp<WindowInfoHandle> InputDispatcher::findTouchedForegroundWindowLocked(int32_t
56835683
}
56845684

56855685
// Binder call
5686-
bool InputDispatcher::transferTouch(const sp<IBinder>& destChannelToken, int32_t displayId) {
5686+
bool InputDispatcher::transferTouchOnDisplay(const sp<IBinder>& destChannelToken,
5687+
int32_t displayId) {
56875688
sp<IBinder> fromToken;
56885689
{ // acquire lock
56895690
std::scoped_lock _l(mLock);
@@ -5703,7 +5704,7 @@ bool InputDispatcher::transferTouch(const sp<IBinder>& destChannelToken, int32_t
57035704
fromToken = from->getToken();
57045705
} // release lock
57055706

5706-
return transferTouchFocus(fromToken, destChannelToken);
5707+
return transferTouchGesture(fromToken, destChannelToken);
57075708
}
57085709

57095710
void InputDispatcher::resetAndDropEverythingLocked(const char* reason) {

services/inputflinger/dispatcher/InputDispatcher.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ class InputDispatcher : public android::InputDispatcherInterface {
124124
int32_t displayId) override;
125125
void setMaximumObscuringOpacityForTouch(float opacity) override;
126126

127-
bool transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken,
128-
bool isDragDrop = false) override;
129-
bool transferTouch(const sp<IBinder>& destChannelToken, int32_t displayId) override;
127+
bool transferTouchGesture(const sp<IBinder>& fromToken, const sp<IBinder>& toToken,
128+
bool isDragDrop = false) override;
129+
bool transferTouchOnDisplay(const sp<IBinder>& destChannelToken, int32_t displayId) override;
130130

131131
base::Result<std::unique_ptr<InputChannel>> createInputChannel(
132132
const std::string& name) override;

services/inputflinger/dispatcher/include/InputDispatcherInterface.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,22 @@ class InputDispatcherInterface : public InputListenerInterface {
141141
virtual void setMaximumObscuringOpacityForTouch(float opacity) = 0;
142142

143143
/**
144-
* Transfers touch focus from one window to another window. Transferring touch focus will not
144+
* Transfers a touch gesture from one window to another window. Transferring touch will not
145145
* have any effect on the focused window.
146146
*
147-
* Returns true on success. False if the window did not actually have touch focus.
147+
* Returns true on success. False if the window did not actually have an active touch gesture.
148148
*/
149-
virtual bool transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken,
150-
bool isDragDrop) = 0;
149+
virtual bool transferTouchGesture(const sp<IBinder>& fromToken, const sp<IBinder>& toToken,
150+
bool isDragDrop) = 0;
151151

152152
/**
153-
* Transfer touch focus to the provided channel, no matter where the current touch is.
154-
* Transferring touch focus will not have any effect on the focused window.
153+
* Transfer a touch gesture to the provided channel, no matter where the current touch is.
154+
* Transferring touch will not have any effect on the focused window.
155155
*
156-
* Return true on success, false if there was no on-going touch.
156+
* Returns true on success, false if there was no on-going touch on the display.
157+
* @deprecated
157158
*/
158-
virtual bool transferTouch(const sp<IBinder>& destChannelToken, int32_t displayId) = 0;
159+
virtual bool transferTouchOnDisplay(const sp<IBinder>& destChannelToken, int32_t displayId) = 0;
159160

160161
/**
161162
* Sets focus on the specified window.

services/inputflinger/tests/InputDispatcher_test.cpp

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5181,7 +5181,7 @@ TEST_F(InputDispatcherDisplayProjectionTest, SynthesizeDownWithCorrectCoordinate
51815181

51825182
// The pointer is transferred to the second window, and the second window receives it in the
51835183
// correct coordinate space.
5184-
mDispatcher->transferTouchFocus(firstWindow->getToken(), secondWindow->getToken());
5184+
mDispatcher->transferTouchGesture(firstWindow->getToken(), secondWindow->getToken());
51855185
firstWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithCoords(100, 400)));
51865186
secondWindow->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithCoords(-100, -400)));
51875187
}
@@ -5419,16 +5419,16 @@ TEST_P(TransferTouchFixture, TransferTouch_OnePointer) {
54195419
}
54205420

54215421
/**
5422-
* When 'transferTouch' API is invoked, dispatcher needs to find the "best" window to take touch
5423-
* from. When we have spy windows, there are several windows to choose from: either spy, or the
5424-
* 'real' (non-spy) window. Always prefer the 'real' window because that's what would be most
5422+
* When 'transferTouchGesture' API is invoked, dispatcher needs to find the "best" window to take
5423+
* touch from. When we have spy windows, there are several windows to choose from: either spy, or
5424+
* the 'real' (non-spy) window. Always prefer the 'real' window because that's what would be most
54255425
* natural to the user.
54265426
* In this test, we are sending a pointer to both spy window and first window. We then try to
54275427
* transfer touch to the second window. The dispatcher should identify the first window as the
54285428
* one that should lose the gesture, and therefore the action should be to move the gesture from
54295429
* the first window to the second.
5430-
* The main goal here is to test the behaviour of 'transferTouch' API, but it's still valid to test
5431-
* the other API, as well.
5430+
* The main goal here is to test the behaviour of 'transferTouchGesture' API, but it's still valid
5431+
* to test the other API, as well.
54325432
*/
54335433
TEST_P(TransferTouchFixture, TransferTouch_MultipleWindowsWithSpy) {
54345434
std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
@@ -5455,7 +5455,7 @@ TEST_P(TransferTouchFixture, TransferTouch_MultipleWindowsWithSpy) {
54555455
firstWindow->consumeMotionDown();
54565456

54575457
// Transfer touch to the second window. Non-spy window should be preferred over the spy window
5458-
// if f === 'transferTouch'.
5458+
// if f === 'transferTouchGesture'.
54595459
TransferFunction f = GetParam();
54605460
const bool success = f(mDispatcher, firstWindow->getToken(), secondWindow->getToken());
54615461
ASSERT_TRUE(success);
@@ -5593,22 +5593,23 @@ TEST_P(TransferTouchFixture, TransferTouch_MultipleWallpapers) {
55935593
}
55945594

55955595
// For the cases of single pointer touch and two pointers non-split touch, the api's
5596-
// 'transferTouch' and 'transferTouchFocus' are equivalent in behaviour. They only differ
5596+
// 'transferTouchGesture' and 'transferTouchOnDisplay' are equivalent in behaviour. They only differ
55975597
// for the case where there are multiple pointers split across several windows.
5598-
INSTANTIATE_TEST_SUITE_P(InputDispatcherTransferFunctionTests, TransferTouchFixture,
5599-
::testing::Values(
5600-
[&](const std::unique_ptr<InputDispatcher>& dispatcher,
5601-
sp<IBinder> /*ignored*/, sp<IBinder> destChannelToken) {
5602-
return dispatcher->transferTouch(destChannelToken,
5603-
ADISPLAY_ID_DEFAULT);
5604-
},
5605-
[&](const std::unique_ptr<InputDispatcher>& dispatcher,
5606-
sp<IBinder> from, sp<IBinder> to) {
5607-
return dispatcher->transferTouchFocus(from, to,
5608-
/*isDragAndDrop=*/false);
5609-
}));
5610-
5611-
TEST_F(InputDispatcherTest, TransferTouchFocus_TwoPointersSplitTouch) {
5598+
INSTANTIATE_TEST_SUITE_P(
5599+
InputDispatcherTransferFunctionTests, TransferTouchFixture,
5600+
::testing::Values(
5601+
[&](const std::unique_ptr<InputDispatcher>& dispatcher, sp<IBinder> /*ignored*/,
5602+
sp<IBinder> destChannelToken) {
5603+
return dispatcher->transferTouchOnDisplay(destChannelToken,
5604+
ADISPLAY_ID_DEFAULT);
5605+
},
5606+
[&](const std::unique_ptr<InputDispatcher>& dispatcher, sp<IBinder> from,
5607+
sp<IBinder> to) {
5608+
return dispatcher->transferTouchGesture(from, to,
5609+
/*isDragAndDrop=*/false);
5610+
}));
5611+
5612+
TEST_F(InputDispatcherTest, TransferTouch_TwoPointersSplitTouch) {
56125613
std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
56135614

56145615
sp<FakeWindowHandle> firstWindow =
@@ -5644,8 +5645,8 @@ TEST_F(InputDispatcherTest, TransferTouchFocus_TwoPointersSplitTouch) {
56445645
firstWindow->consumeMotionMove();
56455646
secondWindow->consumeMotionDown();
56465647

5647-
// Transfer touch focus to the second window
5648-
mDispatcher->transferTouchFocus(firstWindow->getToken(), secondWindow->getToken());
5648+
// Transfer touch to the second window
5649+
mDispatcher->transferTouchGesture(firstWindow->getToken(), secondWindow->getToken());
56495650
// The first window gets cancel and the new gets pointer down (it already saw down)
56505651
firstWindow->consumeMotionCancel();
56515652
secondWindow->consumeMotionPointerDown(1, ADISPLAY_ID_DEFAULT,
@@ -5668,11 +5669,11 @@ TEST_F(InputDispatcherTest, TransferTouchFocus_TwoPointersSplitTouch) {
56685669
secondWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE);
56695670
}
56705671

5671-
// Same as TransferTouchFocus_TwoPointersSplitTouch, but using 'transferTouch' api.
5672-
// Unlike 'transferTouchFocus', calling 'transferTouch' when there are two windows receiving
5673-
// touch is not supported, so the touch should continue on those windows and the transferred-to
5674-
// window should get nothing.
5675-
TEST_F(InputDispatcherTest, TransferTouch_TwoPointersSplitTouch) {
5672+
// Same as TransferTouch_TwoPointersSplitTouch, but using 'transferTouchOnDisplay' api.
5673+
// Unlike 'transferTouchGesture', calling 'transferTouchOnDisplay' when there are two windows
5674+
// receiving touch is not supported, so the touch should continue on those windows and the
5675+
// transferred-to window should get nothing.
5676+
TEST_F(InputDispatcherTest, TransferTouchOnDisplay_TwoPointersSplitTouch) {
56765677
std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
56775678

56785679
sp<FakeWindowHandle> firstWindow =
@@ -5710,8 +5711,8 @@ TEST_F(InputDispatcherTest, TransferTouch_TwoPointersSplitTouch) {
57105711

57115712
// Transfer touch focus to the second window
57125713
const bool transferred =
5713-
mDispatcher->transferTouch(secondWindow->getToken(), ADISPLAY_ID_DEFAULT);
5714-
// The 'transferTouch' call should not succeed, because there are 2 touched windows
5714+
mDispatcher->transferTouchOnDisplay(secondWindow->getToken(), ADISPLAY_ID_DEFAULT);
5715+
// The 'transferTouchOnDisplay' call should not succeed, because there are 2 touched windows
57155716
ASSERT_FALSE(transferred);
57165717
firstWindow->assertNoEvents();
57175718
secondWindow->assertNoEvents();
@@ -5734,9 +5735,9 @@ TEST_F(InputDispatcherTest, TransferTouch_TwoPointersSplitTouch) {
57345735
}
57355736

57365737
// This case will create two windows and one mirrored window on the default display and mirror
5737-
// two windows on the second display. It will test if 'transferTouchFocus' works fine if we put
5738+
// two windows on the second display. It will test if 'transferTouchGesture' works fine if we put
57385739
// the windows info of second display before default display.
5739-
TEST_F(InputDispatcherTest, TransferTouchFocus_CloneSurface) {
5740+
TEST_F(InputDispatcherTest, TransferTouch_CloneSurface) {
57405741
std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
57415742
sp<FakeWindowHandle> firstWindowInPrimary =
57425743
sp<FakeWindowHandle>::make(application, mDispatcher, "D_1_W1", ADISPLAY_ID_DEFAULT);
@@ -5771,9 +5772,9 @@ TEST_F(InputDispatcherTest, TransferTouchFocus_CloneSurface) {
57715772
// Window should receive motion event.
57725773
firstWindowInPrimary->consumeMotionDown(ADISPLAY_ID_DEFAULT);
57735774

5774-
// Transfer touch focus
5775-
ASSERT_TRUE(mDispatcher->transferTouchFocus(firstWindowInPrimary->getToken(),
5776-
secondWindowInPrimary->getToken()));
5775+
// Transfer touch
5776+
ASSERT_TRUE(mDispatcher->transferTouchGesture(firstWindowInPrimary->getToken(),
5777+
secondWindowInPrimary->getToken()));
57775778
// The first window gets cancel.
57785779
firstWindowInPrimary->consumeMotionCancel();
57795780
secondWindowInPrimary->consumeMotionDown(ADISPLAY_ID_DEFAULT,
@@ -5795,9 +5796,9 @@ TEST_F(InputDispatcherTest, TransferTouchFocus_CloneSurface) {
57955796
secondWindowInPrimary->consumeMotionUp(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE);
57965797
}
57975798

5798-
// Same as TransferTouchFocus_CloneSurface, but this touch on the secondary display and use
5799-
// 'transferTouch' api.
5800-
TEST_F(InputDispatcherTest, TransferTouch_CloneSurface) {
5799+
// Same as TransferTouch_CloneSurface, but this touch on the secondary display and use
5800+
// 'transferTouchOnDisplay' api.
5801+
TEST_F(InputDispatcherTest, TransferTouchOnDisplay_CloneSurface) {
58015802
std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
58025803
sp<FakeWindowHandle> firstWindowInPrimary =
58035804
sp<FakeWindowHandle>::make(application, mDispatcher, "D_1_W1", ADISPLAY_ID_DEFAULT);
@@ -5834,7 +5835,8 @@ TEST_F(InputDispatcherTest, TransferTouch_CloneSurface) {
58345835
firstWindowInSecondary->consumeMotionDown(SECOND_DISPLAY_ID);
58355836

58365837
// Transfer touch focus
5837-
ASSERT_TRUE(mDispatcher->transferTouch(secondWindowInSecondary->getToken(), SECOND_DISPLAY_ID));
5838+
ASSERT_TRUE(mDispatcher->transferTouchOnDisplay(secondWindowInSecondary->getToken(),
5839+
SECOND_DISPLAY_ID));
58385840

58395841
// The first window gets cancel.
58405842
firstWindowInSecondary->consumeMotionCancel(SECOND_DISPLAY_ID);
@@ -10520,8 +10522,8 @@ class InputDispatcherDragTests : public InputDispatcherTest {
1052010522

1052110523
// Transfer touch focus to the drag window
1052210524
bool transferred =
10523-
mDispatcher->transferTouchFocus(mWindow->getToken(), mDragWindow->getToken(),
10524-
/*isDragDrop=*/true);
10525+
mDispatcher->transferTouchGesture(mWindow->getToken(), mDragWindow->getToken(),
10526+
/*isDragDrop=*/true);
1052510527
if (transferred) {
1052610528
mWindow->consumeMotionCancel();
1052710529
mDragWindow->consumeMotionDown(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE);

0 commit comments

Comments
 (0)