Skip to content

Commit b487466

Browse files
committed
CursorInputMapper_test: Verify acceleration updated on display change
Bug: 323409820 Test: atest inputflinger_tests Change-Id: Iea731089e0af8ab9d4b26b2c6c566f16c714b98b
1 parent 02c9716 commit b487466

1 file changed

Lines changed: 44 additions & 3 deletions

File tree

services/inputflinger/tests/CursorInputMapper_test.cpp

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ DisplayViewport createSecondaryViewport() {
105105
class ViewportFakingInputDeviceContext : public InputDeviceContext {
106106
public:
107107
ViewportFakingInputDeviceContext(InputDevice& device, int32_t eventHubId,
108-
DisplayViewport viewport)
108+
std::optional<DisplayViewport> viewport)
109109
: InputDeviceContext(device, eventHubId), mAssociatedViewport(viewport) {}
110110

111111
ViewportFakingInputDeviceContext(InputDevice& device, int32_t eventHubId,
@@ -117,10 +117,12 @@ class ViewportFakingInputDeviceContext : public InputDeviceContext {
117117
return mAssociatedViewport;
118118
}
119119

120-
void setViewport(const DisplayViewport& viewport) { mAssociatedViewport = viewport; }
120+
void setViewport(const std::optional<DisplayViewport>& viewport) {
121+
mAssociatedViewport = viewport;
122+
}
121123

122124
private:
123-
DisplayViewport mAssociatedViewport;
125+
std::optional<DisplayViewport> mAssociatedViewport;
124126
};
125127

126128
} // namespace
@@ -1351,6 +1353,45 @@ TEST_F(CursorInputMapperUnitTestWithNewBallistics, ConfigureAccelerationWithAsso
13511353
InputReaderConfiguration::Change::POINTER_SPEED);
13521354
args.clear();
13531355

1356+
args += process(ARBITRARY_TIME, EV_REL, REL_X, 10);
1357+
args += process(ARBITRARY_TIME, EV_REL, REL_Y, 20);
1358+
args += process(ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
1359+
ASSERT_THAT(args,
1360+
ElementsAre(VariantWith<NotifyMotionArgs>(AllOf(WithMotionAction(HOVER_MOVE),
1361+
WithDisplayId(DISPLAY_ID),
1362+
WithRelativeMotion(10, 20)))));
1363+
}
1364+
1365+
TEST_F(CursorInputMapperUnitTestWithNewBallistics, ConfigureAccelerationOnDisplayChange) {
1366+
mPropertyMap.addProperty("cursor.mode", "pointer");
1367+
DisplayViewport primaryViewport = createPrimaryViewport(ui::Rotation::Rotation0);
1368+
mReaderConfiguration.setDisplayViewports({primaryViewport});
1369+
// Disable acceleration for the display.
1370+
mReaderConfiguration.displaysWithMousePointerAccelerationDisabled.emplace(DISPLAY_ID);
1371+
createDevice();
1372+
1373+
// Don't associate the device with the display yet.
1374+
ViewportFakingInputDeviceContext deviceContext(*mDevice, EVENTHUB_ID,
1375+
/*viewport=*/std::nullopt);
1376+
mMapper = createInputMapper<CursorInputMapper>(deviceContext, mReaderConfiguration);
1377+
1378+
std::list<NotifyArgs> args;
1379+
1380+
// Verify that acceleration is being applied by default by checking that the movement is scaled.
1381+
args += process(ARBITRARY_TIME, EV_REL, REL_X, 10);
1382+
args += process(ARBITRARY_TIME, EV_REL, REL_Y, 20);
1383+
args += process(ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);
1384+
ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>(WithMotionAction(HOVER_MOVE))));
1385+
const auto& coords = get<NotifyMotionArgs>(args.back()).pointerCoords[0];
1386+
ASSERT_GT(coords.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X), 10.f);
1387+
ASSERT_GT(coords.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y), 20.f);
1388+
1389+
// Now associate the device with the display, and verify that acceleration is disabled.
1390+
deviceContext.setViewport(primaryViewport);
1391+
args += mMapper->reconfigure(ARBITRARY_TIME, mReaderConfiguration,
1392+
InputReaderConfiguration::Change::DISPLAY_INFO);
1393+
args.clear();
1394+
13541395
args += process(ARBITRARY_TIME, EV_REL, REL_X, 10);
13551396
args += process(ARBITRARY_TIME, EV_REL, REL_Y, 20);
13561397
args += process(ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0);

0 commit comments

Comments
 (0)