Skip to content

Commit 59a39ac

Browse files
Arpit SinghAndroid (Google) Code Review
authored andcommitted
Merge "Set Gesture start time in UserActivityPokeTests" into main
2 parents efccd08 + 660d53b commit 59a39ac

1 file changed

Lines changed: 49 additions & 51 deletions

File tree

services/inputflinger/tests/InputDispatcher_test.cpp

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9924,6 +9924,9 @@ class InputDispatcherUserActivityPokeTests : public InputDispatcherTest {
99249924
virtual void SetUp() override {
99259925
InputDispatcherTest::SetUp();
99269926

9927+
// Use current time as start time otherwise events may be dropped due to being stale.
9928+
mGestureStartTime = std::chrono::nanoseconds(systemTime(SYSTEM_TIME_MONOTONIC));
9929+
99279930
std::shared_ptr<FakeApplicationHandle> application =
99289931
std::make_shared<FakeApplicationHandle>();
99299932
application->setDispatchingTimeout(100ms);
@@ -9941,82 +9944,81 @@ class InputDispatcherUserActivityPokeTests : public InputDispatcherTest {
99419944
mWindow->consumeFocusEvent(true);
99429945
}
99439946

9944-
void notifyAndConsumeMotion(int32_t action, uint32_t source, ui::LogicalDisplayId displayId,
9945-
nsecs_t eventTime) {
9946-
mDispatcher->notifyMotion(MotionArgsBuilder(action, source)
9947-
.displayId(displayId)
9948-
.eventTime(eventTime)
9949-
.pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50))
9950-
.build());
9947+
NotifyMotionArgs notifyAndConsumeMotion(int32_t action, uint32_t source,
9948+
ui::LogicalDisplayId displayId,
9949+
std::chrono::nanoseconds timeDelay) {
9950+
const NotifyMotionArgs motionArgs =
9951+
MotionArgsBuilder(action, source)
9952+
.displayId(displayId)
9953+
.eventTime((mGestureStartTime + timeDelay).count())
9954+
.pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50))
9955+
.build();
9956+
mDispatcher->notifyMotion(motionArgs);
99519957
mWindow->consumeMotionEvent(WithMotionAction(action));
9958+
return motionArgs;
99529959
}
99539960

99549961
private:
99559962
sp<FakeWindowHandle> mWindow;
9963+
std::chrono::nanoseconds mGestureStartTime;
99569964
};
99579965

99589966
TEST_F_WITH_FLAGS(
99599967
InputDispatcherUserActivityPokeTests, MinPokeTimeObserved,
99609968
REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(com::android::input::flags,
99619969
rate_limit_user_activity_poke_in_dispatcher))) {
9962-
// Use current time otherwise events may be dropped due to being stale.
9963-
const nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC);
9964-
99659970
mDispatcher->setMinTimeBetweenUserActivityPokes(50ms);
99669971

99679972
// First event of type TOUCH. Should poke.
9968-
notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT,
9969-
currentTime + milliseconds_to_nanoseconds(50));
9973+
NotifyMotionArgs motionArgs =
9974+
notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
9975+
ui::LogicalDisplayId::DEFAULT, std::chrono::milliseconds(50));
99709976
mFakePolicy->assertUserActivityPoked(
9971-
{{currentTime + milliseconds_to_nanoseconds(50), USER_ACTIVITY_EVENT_TOUCH,
9972-
ui::LogicalDisplayId::DEFAULT}});
9977+
{{motionArgs.eventTime, USER_ACTIVITY_EVENT_TOUCH, ui::LogicalDisplayId::DEFAULT}});
99739978

99749979
// 80ns > 50ns has passed since previous TOUCH event. Should poke.
9975-
notifyAndConsumeMotion(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT,
9976-
currentTime + milliseconds_to_nanoseconds(130));
9980+
motionArgs =
9981+
notifyAndConsumeMotion(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN,
9982+
ui::LogicalDisplayId::DEFAULT, std::chrono::milliseconds(130));
99779983
mFakePolicy->assertUserActivityPoked(
9978-
{{currentTime + milliseconds_to_nanoseconds(130), USER_ACTIVITY_EVENT_TOUCH,
9979-
ui::LogicalDisplayId::DEFAULT}});
9984+
{{motionArgs.eventTime, USER_ACTIVITY_EVENT_TOUCH, ui::LogicalDisplayId::DEFAULT}});
99809985

99819986
// First event of type OTHER. Should poke (despite being within 50ns of previous TOUCH event).
9982-
notifyAndConsumeMotion(ACTION_SCROLL, AINPUT_SOURCE_ROTARY_ENCODER,
9983-
ui::LogicalDisplayId::DEFAULT,
9984-
currentTime + milliseconds_to_nanoseconds(135));
9987+
motionArgs =
9988+
notifyAndConsumeMotion(ACTION_SCROLL, AINPUT_SOURCE_ROTARY_ENCODER,
9989+
ui::LogicalDisplayId::DEFAULT, std::chrono::milliseconds(135));
99859990
mFakePolicy->assertUserActivityPoked(
9986-
{{currentTime + milliseconds_to_nanoseconds(135), USER_ACTIVITY_EVENT_OTHER,
9987-
ui::LogicalDisplayId::DEFAULT}});
9991+
{{motionArgs.eventTime, USER_ACTIVITY_EVENT_OTHER, ui::LogicalDisplayId::DEFAULT}});
99889992

99899993
// Within 50ns of previous TOUCH event. Should NOT poke.
99909994
notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT,
9991-
currentTime + milliseconds_to_nanoseconds(140));
9995+
std::chrono::milliseconds(140));
99929996
mFakePolicy->assertUserActivityNotPoked();
99939997

99949998
// Within 50ns of previous OTHER event. Should NOT poke.
99959999
notifyAndConsumeMotion(ACTION_SCROLL, AINPUT_SOURCE_ROTARY_ENCODER,
9996-
ui::LogicalDisplayId::DEFAULT,
9997-
currentTime + milliseconds_to_nanoseconds(150));
10000+
ui::LogicalDisplayId::DEFAULT, std::chrono::milliseconds(150));
999810001
mFakePolicy->assertUserActivityNotPoked();
999910002

1000010003
// Within 50ns of previous TOUCH event (which was at time 130). Should NOT poke.
1000110004
// Note that STYLUS is mapped to TOUCH user activity, since it's a pointer-type source.
1000210005
notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_STYLUS, ui::LogicalDisplayId::DEFAULT,
10003-
currentTime + milliseconds_to_nanoseconds(160));
10006+
std::chrono::milliseconds(160));
1000410007
mFakePolicy->assertUserActivityNotPoked();
1000510008

1000610009
// 65ns > 50ns has passed since previous OTHER event. Should poke.
10007-
notifyAndConsumeMotion(ACTION_SCROLL, AINPUT_SOURCE_ROTARY_ENCODER,
10008-
ui::LogicalDisplayId::DEFAULT,
10009-
currentTime + milliseconds_to_nanoseconds(200));
10010+
motionArgs =
10011+
notifyAndConsumeMotion(ACTION_SCROLL, AINPUT_SOURCE_ROTARY_ENCODER,
10012+
ui::LogicalDisplayId::DEFAULT, std::chrono::milliseconds(200));
1001010013
mFakePolicy->assertUserActivityPoked(
10011-
{{currentTime + milliseconds_to_nanoseconds(200), USER_ACTIVITY_EVENT_OTHER,
10012-
ui::LogicalDisplayId::DEFAULT}});
10014+
{{motionArgs.eventTime, USER_ACTIVITY_EVENT_OTHER, ui::LogicalDisplayId::DEFAULT}});
1001310015

1001410016
// 170ns > 50ns has passed since previous TOUCH event. Should poke.
10015-
notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_STYLUS, ui::LogicalDisplayId::DEFAULT,
10016-
currentTime + milliseconds_to_nanoseconds(300));
10017+
motionArgs =
10018+
notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_STYLUS, ui::LogicalDisplayId::DEFAULT,
10019+
std::chrono::milliseconds(300));
1001710020
mFakePolicy->assertUserActivityPoked(
10018-
{{currentTime + milliseconds_to_nanoseconds(300), USER_ACTIVITY_EVENT_TOUCH,
10019-
ui::LogicalDisplayId::DEFAULT}});
10021+
{{motionArgs.eventTime, USER_ACTIVITY_EVENT_TOUCH, ui::LogicalDisplayId::DEFAULT}});
1002010022

1002110023
// Assert that there's no more user activity poke event.
1002210024
mFakePolicy->assertUserActivityNotPoked();
@@ -10026,39 +10028,35 @@ TEST_F_WITH_FLAGS(
1002610028
InputDispatcherUserActivityPokeTests, DefaultMinPokeTimeOf100MsUsed,
1002710029
REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(com::android::input::flags,
1002810030
rate_limit_user_activity_poke_in_dispatcher))) {
10029-
// Use current time otherwise events may be dropped due to being stale.
10030-
const nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC);
10031-
notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT,
10032-
currentTime + milliseconds_to_nanoseconds(200));
10031+
NotifyMotionArgs motionArgs =
10032+
notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
10033+
ui::LogicalDisplayId::DEFAULT, std::chrono::milliseconds(200));
1003310034
mFakePolicy->assertUserActivityPoked(
10034-
{{currentTime + milliseconds_to_nanoseconds(200), USER_ACTIVITY_EVENT_TOUCH,
10035-
ui::LogicalDisplayId::DEFAULT}});
10035+
{{motionArgs.eventTime, USER_ACTIVITY_EVENT_TOUCH, ui::LogicalDisplayId::DEFAULT}});
1003610036

1003710037
notifyAndConsumeMotion(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT,
10038-
currentTime + milliseconds_to_nanoseconds(280));
10038+
std::chrono::milliseconds(280));
1003910039
mFakePolicy->assertUserActivityNotPoked();
1004010040

10041-
notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT,
10042-
currentTime + milliseconds_to_nanoseconds(340));
10041+
motionArgs =
10042+
notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
10043+
ui::LogicalDisplayId::DEFAULT, std::chrono::milliseconds(340));
1004310044
mFakePolicy->assertUserActivityPoked(
10044-
{{currentTime + milliseconds_to_nanoseconds(340), USER_ACTIVITY_EVENT_TOUCH,
10045-
ui::LogicalDisplayId::DEFAULT}});
10045+
{{motionArgs.eventTime, USER_ACTIVITY_EVENT_TOUCH, ui::LogicalDisplayId::DEFAULT}});
1004610046
}
1004710047

1004810048
TEST_F_WITH_FLAGS(
1004910049
InputDispatcherUserActivityPokeTests, ZeroMinPokeTimeDisablesRateLimiting,
1005010050
REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(com::android::input::flags,
1005110051
rate_limit_user_activity_poke_in_dispatcher))) {
10052-
// Use current time otherwise events may be dropped due to being stale.
10053-
const nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC);
1005410052
mDispatcher->setMinTimeBetweenUserActivityPokes(0ms);
1005510053

1005610054
notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT,
10057-
currentTime + 20);
10055+
std::chrono::milliseconds(20));
1005810056
mFakePolicy->assertUserActivityPoked();
1005910057

1006010058
notifyAndConsumeMotion(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT,
10061-
currentTime + 30);
10059+
std::chrono::milliseconds(30));
1006210060
mFakePolicy->assertUserActivityPoked();
1006310061
}
1006410062

0 commit comments

Comments
 (0)