diff options
author | 2025-03-19 14:55:09 +0000 | |
---|---|---|
committer | 2025-03-19 15:15:28 +0000 | |
commit | 3ff756b85efa91d0c2da4b8a3a4fb006142ad1e4 (patch) | |
tree | 6e970c0f54b8db5ca8ca84e08a6abb2126764662 | |
parent | 1f27f396211bf9ea29dde977ca3dd499facceb94 (diff) |
uinput: fix end-of-file handling
Change I69c2cb651cd871ea0ceea9702c66b76abb37285a inadvertently broke
evemu playback from a file, because when getNextEvent() called
CommentAwareReader#isAtEndOfFile(), CommentAwareReader#findNextLine()
hadn't been called, so it hadn't realized it was at the end of the file.
That meant expectLine() failed because acceptLine() returned null.
This wasn't caught because when used in "interactive mode" (e.g. with a
test passing one line at a time and checking the injections), the
parsing exception only occurred at the end, by which time all events had
been injected. When passing a whole recording at once (either by setting
the command-line parameter or piping a file into standard input), the
parsing error occurred before any of the scheduled event injections. The
unit tests for EvemuParser didn't check the behaviour of getNextEvent()
at the end of the recording, something which this change also fixes.
Test: $ adb shell uinput - < some-recording.evemu
Test: $ adb shell uinput /sdcard/some-recording.evemu
Test: make an evemu recording with only an 'N:' line and check the
special EOF parsing error message shows up
Test: $ atest --host UinputTestsRavenwood
Test: $ atest \
InputTests:com.android.test.input.UinputRecordingIntegrationTests
Bug: 367419268
Flag: TEST_ONLY
Change-Id: I1f0e185cf42b3d57b0b384718ffeeb78d99248c5
-rw-r--r-- | cmds/uinput/src/com/android/commands/uinput/EvemuParser.java | 14 | ||||
-rw-r--r-- | cmds/uinput/tests/src/com/android/commands/uinput/tests/EvemuParserTest.java | 5 |
2 files changed, 14 insertions, 5 deletions
diff --git a/cmds/uinput/src/com/android/commands/uinput/EvemuParser.java b/cmds/uinput/src/com/android/commands/uinput/EvemuParser.java index d3e62d5351f0..017d9563b9a8 100644 --- a/cmds/uinput/src/com/android/commands/uinput/EvemuParser.java +++ b/cmds/uinput/src/com/android/commands/uinput/EvemuParser.java @@ -61,17 +61,18 @@ public class EvemuParser implements EventParser { mReader = in; } - private @Nullable String findNextLine() throws IOException { + private void findNextLine() throws IOException { String line = ""; while (line != null && line.length() == 0) { String unstrippedLine = mReader.readLine(); if (unstrippedLine == null) { mAtEndOfFile = true; - return null; + mNextLine = null; + return; } line = stripComments(unstrippedLine); } - return line; + mNextLine = line; } private static String stripComments(String line) { @@ -92,7 +93,7 @@ public class EvemuParser implements EventParser { */ public @Nullable String peekLine() throws IOException { if (mNextLine == null && !mAtEndOfFile) { - mNextLine = findNextLine(); + findNextLine(); } return mNextLine; } @@ -103,7 +104,10 @@ public class EvemuParser implements EventParser { mNextLine = null; } - public boolean isAtEndOfFile() { + public boolean isAtEndOfFile() throws IOException { + if (mNextLine == null && !mAtEndOfFile) { + findNextLine(); + } return mAtEndOfFile; } diff --git a/cmds/uinput/tests/src/com/android/commands/uinput/tests/EvemuParserTest.java b/cmds/uinput/tests/src/com/android/commands/uinput/tests/EvemuParserTest.java index 5239fbc7e0a8..f18cab51fb4d 100644 --- a/cmds/uinput/tests/src/com/android/commands/uinput/tests/EvemuParserTest.java +++ b/cmds/uinput/tests/src/com/android/commands/uinput/tests/EvemuParserTest.java @@ -216,6 +216,9 @@ public class EvemuParserTest { assertInjectEvent(parser.getNextEvent(), 0x2, 0x0, 1, -1); assertInjectEvent(parser.getNextEvent(), 0x2, 0x1, -2); assertInjectEvent(parser.getNextEvent(), 0x0, 0x0, 0); + + // Now we should be at the end of the file. + assertThat(parser.getNextEvent()).isNull(); } @Test @@ -246,6 +249,8 @@ public class EvemuParserTest { assertInjectEvent(parser.getNextEvent(), 0x1, 0x15, 1, 1_000_000); assertInjectEvent(parser.getNextEvent(), 0x0, 0x0, 0); + + assertThat(parser.getNextEvent()).isNull(); } @Test |