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

Commit a8fe7c57 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

InputDispatcher_test: Use InputEvent::nextId() for all injected events

Input events are tracked through the pipeline using their event ID.
There is an underlying assumption that each new event will have a
different ID (apart from the small chance that there's a collission in
the randomly-generated IDs). This assumption needs to be fulfilled for
features like tracing and latency tracking to work as intended.

Before adding tests to ensure all events are traced correctly in
tests for InputDispatcher, we must uphold this assumption and use a new
eventId for each injected event.

Bug: 210460522
Test: atest inputflinger_tests
Change-Id: Icbbd3eb6d62f9de1c9320207a4d6fa6070f2b30b
parent b507b71c
Loading
Loading
Loading
Loading
+18 −15
Original line number Diff line number Diff line
@@ -572,7 +572,8 @@ private:
        /** We simply reconstruct NotifySwitchArgs in policy because InputDispatcher is
         * essentially a passthrough for notifySwitch.
         */
        mLastNotifySwitch = NotifySwitchArgs(/*id=*/1, when, policyFlags, switchValues, switchMask);
        mLastNotifySwitch =
                NotifySwitchArgs(InputEvent::nextId(), when, policyFlags, switchValues, switchMask);
    }
    void pokeUserActivity(nsecs_t, int32_t, int32_t) override {
@@ -836,7 +837,8 @@ TEST_F(InputDispatcherTest, NotifyConfigurationChanged_CallsPolicy) {
}
TEST_F(InputDispatcherTest, NotifySwitch_CallsPolicy) {
    NotifySwitchArgs args(/*id=*/10, /*eventTime=*/20, /*policyFlags=*/0, /*switchValues=*/1,
    NotifySwitchArgs args(InputEvent::nextId(), /*eventTime=*/20, /*policyFlags=*/0,
                          /*switchValues=*/1,
                          /*switchMask=*/2);
    mDispatcher->notifySwitch(args);
@@ -1579,9 +1581,9 @@ static InputEventInjectionResult injectMotionUp(InputDispatcher& dispatcher, int
static NotifyKeyArgs generateKeyArgs(int32_t action, int32_t displayId = ADISPLAY_ID_NONE) {
    nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC);
    // Define a valid key event.
    NotifyKeyArgs args(/*id=*/0, currentTime, /*readTime=*/0, DEVICE_ID, AINPUT_SOURCE_KEYBOARD,
                       displayId, POLICY_FLAG_PASS_TO_USER, action, /*flags=*/0, AKEYCODE_A, KEY_A,
                       AMETA_NONE, currentTime);
    NotifyKeyArgs args(InputEvent::nextId(), currentTime, /*readTime=*/0, DEVICE_ID,
                       AINPUT_SOURCE_KEYBOARD, displayId, POLICY_FLAG_PASS_TO_USER, action,
                       /*flags=*/0, AKEYCODE_A, KEY_A, AMETA_NONE, currentTime);
    return args;
}
@@ -1590,9 +1592,9 @@ static NotifyKeyArgs generateSystemShortcutArgs(int32_t action,
                                                int32_t displayId = ADISPLAY_ID_NONE) {
    nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC);
    // Define a valid key event.
    NotifyKeyArgs args(/*id=*/0, currentTime, /*readTime=*/0, DEVICE_ID, AINPUT_SOURCE_KEYBOARD,
                       displayId, 0, action, /*flags=*/0, AKEYCODE_C, KEY_C, AMETA_META_ON,
                       currentTime);
    NotifyKeyArgs args(InputEvent::nextId(), currentTime, /*readTime=*/0, DEVICE_ID,
                       AINPUT_SOURCE_KEYBOARD, displayId, 0, action, /*flags=*/0, AKEYCODE_C, KEY_C,
                       AMETA_META_ON, currentTime);
    return args;
}
@@ -1601,9 +1603,9 @@ static NotifyKeyArgs generateAssistantKeyArgs(int32_t action,
                                              int32_t displayId = ADISPLAY_ID_NONE) {
    nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC);
    // Define a valid key event.
    NotifyKeyArgs args(/*id=*/0, currentTime, /*readTime=*/0, DEVICE_ID, AINPUT_SOURCE_KEYBOARD,
                       displayId, 0, action, /*flags=*/0, AKEYCODE_ASSIST, KEY_ASSISTANT,
                       AMETA_NONE, currentTime);
    NotifyKeyArgs args(InputEvent::nextId(), currentTime, /*readTime=*/0, DEVICE_ID,
                       AINPUT_SOURCE_KEYBOARD, displayId, 0, action, /*flags=*/0, AKEYCODE_ASSIST,
                       KEY_ASSISTANT, AMETA_NONE, currentTime);
    return args;
}
@@ -1631,9 +1633,9 @@ static NotifyKeyArgs generateAssistantKeyArgs(int32_t action,
    nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC);
    // Define a valid motion event.
    NotifyMotionArgs args(/*id=*/0, currentTime, /*readTime=*/0, DEVICE_ID, source, displayId,
                          POLICY_FLAG_PASS_TO_USER, action, /*actionButton=*/0, /*flags=*/0,
                          AMETA_NONE, /*buttonState=*/0, MotionClassification::NONE,
    NotifyMotionArgs args(InputEvent::nextId(), currentTime, /*readTime=*/0, DEVICE_ID, source,
                          displayId, POLICY_FLAG_PASS_TO_USER, action, /*actionButton=*/0,
                          /*flags=*/0, AMETA_NONE, /*buttonState=*/0, MotionClassification::NONE,
                          AMOTION_EVENT_EDGE_FLAG_NONE, pointerCount, pointerProperties,
                          pointerCoords, /*xPrecision=*/0, /*yPrecision=*/0,
                          AMOTION_EVENT_INVALID_CURSOR_POSITION,
@@ -1652,7 +1654,8 @@ static NotifyMotionArgs generateMotionArgs(int32_t action, int32_t source, int32
static NotifyPointerCaptureChangedArgs generatePointerCaptureChangedArgs(
        const PointerCaptureRequest& request) {
    return NotifyPointerCaptureChangedArgs(/*id=*/0, systemTime(SYSTEM_TIME_MONOTONIC), request);
    return NotifyPointerCaptureChangedArgs(InputEvent::nextId(), systemTime(SYSTEM_TIME_MONOTONIC),
                                           request);
}
} // namespace