Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 59a39ac5 authored by Arpit Singh's avatar Arpit Singh Committed by Android (Google) Code Review
Browse files

Merge "Set Gesture start time in UserActivityPokeTests" into main

parents efccd08d 660d53b1
Loading
Loading
Loading
Loading
+49 −51
Original line number Diff line number Diff line
@@ -9924,6 +9924,9 @@ protected:
    virtual void SetUp() override {
        InputDispatcherTest::SetUp();
        // Use current time as start time otherwise events may be dropped due to being stale.
        mGestureStartTime = std::chrono::nanoseconds(systemTime(SYSTEM_TIME_MONOTONIC));
        std::shared_ptr<FakeApplicationHandle> application =
                std::make_shared<FakeApplicationHandle>();
        application->setDispatchingTimeout(100ms);
@@ -9941,82 +9944,81 @@ protected:
        mWindow->consumeFocusEvent(true);
    }
    void notifyAndConsumeMotion(int32_t action, uint32_t source, ui::LogicalDisplayId displayId,
                                nsecs_t eventTime) {
        mDispatcher->notifyMotion(MotionArgsBuilder(action, source)
    NotifyMotionArgs notifyAndConsumeMotion(int32_t action, uint32_t source,
                                            ui::LogicalDisplayId displayId,
                                            std::chrono::nanoseconds timeDelay) {
        const NotifyMotionArgs motionArgs =
                MotionArgsBuilder(action, source)
                        .displayId(displayId)
                                          .eventTime(eventTime)
                        .eventTime((mGestureStartTime + timeDelay).count())
                        .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50))
                                          .build());
                        .build();
        mDispatcher->notifyMotion(motionArgs);
        mWindow->consumeMotionEvent(WithMotionAction(action));
        return motionArgs;
    }
private:
    sp<FakeWindowHandle> mWindow;
    std::chrono::nanoseconds mGestureStartTime;
};
TEST_F_WITH_FLAGS(
        InputDispatcherUserActivityPokeTests, MinPokeTimeObserved,
        REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(com::android::input::flags,
                                            rate_limit_user_activity_poke_in_dispatcher))) {
    // Use current time otherwise events may be dropped due to being stale.
    const nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC);
    mDispatcher->setMinTimeBetweenUserActivityPokes(50ms);
    // First event of type TOUCH. Should poke.
    notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT,
                           currentTime + milliseconds_to_nanoseconds(50));
    NotifyMotionArgs motionArgs =
            notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
                                   ui::LogicalDisplayId::DEFAULT, std::chrono::milliseconds(50));
    mFakePolicy->assertUserActivityPoked(
            {{currentTime + milliseconds_to_nanoseconds(50), USER_ACTIVITY_EVENT_TOUCH,
              ui::LogicalDisplayId::DEFAULT}});
            {{motionArgs.eventTime, USER_ACTIVITY_EVENT_TOUCH, ui::LogicalDisplayId::DEFAULT}});
    // 80ns > 50ns has passed since previous TOUCH event. Should poke.
    notifyAndConsumeMotion(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT,
                           currentTime + milliseconds_to_nanoseconds(130));
    motionArgs =
            notifyAndConsumeMotion(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN,
                                   ui::LogicalDisplayId::DEFAULT, std::chrono::milliseconds(130));
    mFakePolicy->assertUserActivityPoked(
            {{currentTime + milliseconds_to_nanoseconds(130), USER_ACTIVITY_EVENT_TOUCH,
              ui::LogicalDisplayId::DEFAULT}});
            {{motionArgs.eventTime, USER_ACTIVITY_EVENT_TOUCH, ui::LogicalDisplayId::DEFAULT}});
    // First event of type OTHER. Should poke (despite being within 50ns of previous TOUCH event).
    motionArgs =
            notifyAndConsumeMotion(ACTION_SCROLL, AINPUT_SOURCE_ROTARY_ENCODER,
                           ui::LogicalDisplayId::DEFAULT,
                           currentTime + milliseconds_to_nanoseconds(135));
                                   ui::LogicalDisplayId::DEFAULT, std::chrono::milliseconds(135));
    mFakePolicy->assertUserActivityPoked(
            {{currentTime + milliseconds_to_nanoseconds(135), USER_ACTIVITY_EVENT_OTHER,
              ui::LogicalDisplayId::DEFAULT}});
            {{motionArgs.eventTime, USER_ACTIVITY_EVENT_OTHER, ui::LogicalDisplayId::DEFAULT}});
    // Within 50ns of previous TOUCH event. Should NOT poke.
    notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT,
                           currentTime + milliseconds_to_nanoseconds(140));
                           std::chrono::milliseconds(140));
    mFakePolicy->assertUserActivityNotPoked();
    // Within 50ns of previous OTHER event. Should NOT poke.
    notifyAndConsumeMotion(ACTION_SCROLL, AINPUT_SOURCE_ROTARY_ENCODER,
                           ui::LogicalDisplayId::DEFAULT,
                           currentTime + milliseconds_to_nanoseconds(150));
                           ui::LogicalDisplayId::DEFAULT, std::chrono::milliseconds(150));
    mFakePolicy->assertUserActivityNotPoked();
    // Within 50ns of previous TOUCH event (which was at time 130). Should NOT poke.
    // Note that STYLUS is mapped to TOUCH user activity, since it's a pointer-type source.
    notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_STYLUS, ui::LogicalDisplayId::DEFAULT,
                           currentTime + milliseconds_to_nanoseconds(160));
                           std::chrono::milliseconds(160));
    mFakePolicy->assertUserActivityNotPoked();
    // 65ns > 50ns has passed since previous OTHER event. Should poke.
    motionArgs =
            notifyAndConsumeMotion(ACTION_SCROLL, AINPUT_SOURCE_ROTARY_ENCODER,
                           ui::LogicalDisplayId::DEFAULT,
                           currentTime + milliseconds_to_nanoseconds(200));
                                   ui::LogicalDisplayId::DEFAULT, std::chrono::milliseconds(200));
    mFakePolicy->assertUserActivityPoked(
            {{currentTime + milliseconds_to_nanoseconds(200), USER_ACTIVITY_EVENT_OTHER,
              ui::LogicalDisplayId::DEFAULT}});
            {{motionArgs.eventTime, USER_ACTIVITY_EVENT_OTHER, ui::LogicalDisplayId::DEFAULT}});
    // 170ns > 50ns has passed since previous TOUCH event. Should poke.
    motionArgs =
            notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_STYLUS, ui::LogicalDisplayId::DEFAULT,
                           currentTime + milliseconds_to_nanoseconds(300));
                                   std::chrono::milliseconds(300));
    mFakePolicy->assertUserActivityPoked(
            {{currentTime + milliseconds_to_nanoseconds(300), USER_ACTIVITY_EVENT_TOUCH,
              ui::LogicalDisplayId::DEFAULT}});
            {{motionArgs.eventTime, USER_ACTIVITY_EVENT_TOUCH, ui::LogicalDisplayId::DEFAULT}});
    // Assert that there's no more user activity poke event.
    mFakePolicy->assertUserActivityNotPoked();
@@ -10026,39 +10028,35 @@ TEST_F_WITH_FLAGS(
        InputDispatcherUserActivityPokeTests, DefaultMinPokeTimeOf100MsUsed,
        REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(com::android::input::flags,
                                            rate_limit_user_activity_poke_in_dispatcher))) {
    // Use current time otherwise events may be dropped due to being stale.
    const nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC);
    notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT,
                           currentTime + milliseconds_to_nanoseconds(200));
    NotifyMotionArgs motionArgs =
            notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
                                   ui::LogicalDisplayId::DEFAULT, std::chrono::milliseconds(200));
    mFakePolicy->assertUserActivityPoked(
            {{currentTime + milliseconds_to_nanoseconds(200), USER_ACTIVITY_EVENT_TOUCH,
              ui::LogicalDisplayId::DEFAULT}});
            {{motionArgs.eventTime, USER_ACTIVITY_EVENT_TOUCH, ui::LogicalDisplayId::DEFAULT}});
    notifyAndConsumeMotion(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT,
                           currentTime + milliseconds_to_nanoseconds(280));
                           std::chrono::milliseconds(280));
    mFakePolicy->assertUserActivityNotPoked();
    notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT,
                           currentTime + milliseconds_to_nanoseconds(340));
    motionArgs =
            notifyAndConsumeMotion(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
                                   ui::LogicalDisplayId::DEFAULT, std::chrono::milliseconds(340));
    mFakePolicy->assertUserActivityPoked(
            {{currentTime + milliseconds_to_nanoseconds(340), USER_ACTIVITY_EVENT_TOUCH,
              ui::LogicalDisplayId::DEFAULT}});
            {{motionArgs.eventTime, USER_ACTIVITY_EVENT_TOUCH, ui::LogicalDisplayId::DEFAULT}});
}
TEST_F_WITH_FLAGS(
        InputDispatcherUserActivityPokeTests, ZeroMinPokeTimeDisablesRateLimiting,
        REQUIRES_FLAGS_ENABLED(ACONFIG_FLAG(com::android::input::flags,
                                            rate_limit_user_activity_poke_in_dispatcher))) {
    // Use current time otherwise events may be dropped due to being stale.
    const nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC);
    mDispatcher->setMinTimeBetweenUserActivityPokes(0ms);
    notifyAndConsumeMotion(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT,
                           currentTime + 20);
                           std::chrono::milliseconds(20));
    mFakePolicy->assertUserActivityPoked();
    notifyAndConsumeMotion(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN, ui::LogicalDisplayId::DEFAULT,
                           currentTime + 30);
                           std::chrono::milliseconds(30));
    mFakePolicy->assertUserActivityPoked();
}