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

Commit 97b0d3b5 authored by liushenxiang's avatar liushenxiang Committed by Siarhei Vishniakou
Browse files

[BugFix] Reset key repeating in case a keyboard device was disabled or enabled.



The "resetKeyRepeatLocked" will never be called when we disable a keyboard device. In this case, if we long click a key on keyboard and it began to repeat. Then we disable the keyboard. We find that the key repeating will never stop until a next key event come.

Test: atest inputflinger_tests
Signed-off-by: default avatarliushenxiang <liushenxiang@xiaomi.com>
Change-Id: Ic0e37d1e1e447d4965f3fbb479e0eca7c726a6ab
parent 161a5f38
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -1256,6 +1256,11 @@ bool InputDispatcher::dispatchDeviceResetLocked(nsecs_t currentTime,
          entry.deviceId);
          entry.deviceId);
#endif
#endif


    // Reset key repeating in case a keyboard device was disabled or enabled.
    if (mKeyRepeatState.lastKeyEntry && mKeyRepeatState.lastKeyEntry->deviceId == entry.deviceId) {
        resetKeyRepeatLocked();
    }

    CancelationOptions options(CancelationOptions::CANCEL_ALL_EVENTS, "device was reset");
    CancelationOptions options(CancelationOptions::CANCEL_ALL_EVENTS, "device was reset");
    options.deviceId = entry.deviceId;
    options.deviceId = entry.deviceId;
    synthesizeCancelationEventsForAllConnectionsLocked(options);
    synthesizeCancelationEventsForAllConnectionsLocked(options);
+10 −0
Original line number Original line Diff line number Diff line
@@ -2858,6 +2858,16 @@ TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_KeyRepeatStopsAfterRepeatingK
    mWindow->assertNoEvents();
    mWindow->assertNoEvents();
}
}


TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_StopsKeyRepeatAfterDisableInputDevice) {
    sendAndConsumeKeyDown(DEVICE_ID);
    expectKeyRepeatOnce(1 /*repeatCount*/);
    NotifyDeviceResetArgs args(10 /*id*/, 20 /*eventTime*/, DEVICE_ID);
    mDispatcher->notifyDeviceReset(&args);
    mWindow->consumeKeyUp(ADISPLAY_ID_DEFAULT,
                          AKEY_EVENT_FLAG_CANCELED | AKEY_EVENT_FLAG_LONG_PRESS);
    mWindow->assertNoEvents();
}

TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_RepeatKeyEventsUseEventIdFromInputDispatcher) {
TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_RepeatKeyEventsUseEventIdFromInputDispatcher) {
    sendAndConsumeKeyDown(1 /* deviceId */);
    sendAndConsumeKeyDown(1 /* deviceId */);
    for (int32_t repeatCount = 1; repeatCount <= 10; ++repeatCount) {
    for (int32_t repeatCount = 1; repeatCount <= 10; ++repeatCount) {