summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Harry Cutts <hcutts@google.com> 2025-03-14 17:28:28 +0000
committer Harry Cutts <hcutts@google.com> 2025-03-14 17:28:28 +0000
commit54cbe9b562fd5e2381144578011201839f562745 (patch)
tree9bf1c8953bbf3a51bcc9cd037f0d749e363b3f76
parent79e6e3d4e1fb1975638158927edd6783ea7d10dc (diff)
uinput: don't read next line of evemu recording until peek
When EvemuParser "accepts" a line of an evemu recording (i.e. it's found the line type it was expecting and is ready to process it), it calls CommentAwareReader#advance() before processing the current line. advance() was reading the next line of the file, ready for peeking, even though the current line hadn't been processed yet. When playing from standard input, this meant that a line wouldn't be executed until the next one was written, requiring a no-op line to be added to the end of event recordings. To fix this, only load the next line when peekLine() is called after the advance(). Test: $ atest --host UinputTestsRavenwood Test: $ atest InputTests:com.android.test.input.UinputRecordingIntegrationTests Bug: 367419268 Flag: TEST_ONLY Change-Id: I69c2cb651cd871ea0ceea9702c66b76abb37285a
-rw-r--r--cmds/uinput/src/com/android/commands/uinput/EvemuParser.java33
1 files changed, 22 insertions, 11 deletions
diff --git a/cmds/uinput/src/com/android/commands/uinput/EvemuParser.java b/cmds/uinput/src/com/android/commands/uinput/EvemuParser.java
index da991624e685..d3e62d5351f0 100644
--- a/cmds/uinput/src/com/android/commands/uinput/EvemuParser.java
+++ b/cmds/uinput/src/com/android/commands/uinput/EvemuParser.java
@@ -48,12 +48,17 @@ public class EvemuParser implements EventParser {
private static class CommentAwareReader {
private final LineNumberReader mReader;
- private String mPreviousLine;
- private String mNextLine;
+ /** The previous line of the file, or {@code null} if we're at the start of the file. */
+ private @Nullable String mPreviousLine;
+ /**
+ * The next line of the file to be returned from {@link #peekLine()}, or {@code null} if we
+ * haven't peeked since the last {@link #advance()} or are at the end of the file.
+ */
+ private @Nullable String mNextLine;
+ private boolean mAtEndOfFile = false;
- CommentAwareReader(LineNumberReader in) throws IOException {
+ CommentAwareReader(LineNumberReader in) {
mReader = in;
- mNextLine = findNextLine();
}
private @Nullable String findNextLine() throws IOException {
@@ -61,7 +66,7 @@ public class EvemuParser implements EventParser {
while (line != null && line.length() == 0) {
String unstrippedLine = mReader.readLine();
if (unstrippedLine == null) {
- // End of file.
+ mAtEndOfFile = true;
return null;
}
line = stripComments(unstrippedLine);
@@ -85,22 +90,28 @@ public class EvemuParser implements EventParser {
* {@code null} if the end of the file is reached. However, it does not advance to the
* next line of the file.
*/
- public @Nullable String peekLine() {
+ public @Nullable String peekLine() throws IOException {
+ if (mNextLine == null && !mAtEndOfFile) {
+ mNextLine = findNextLine();
+ }
return mNextLine;
}
/** Moves to the next line of the file. */
- public void advance() throws IOException {
+ public void advance() {
mPreviousLine = mNextLine;
- mNextLine = findNextLine();
+ mNextLine = null;
}
public boolean isAtEndOfFile() {
- return mNextLine == null;
+ return mAtEndOfFile;
}
- /** Returns the previous line, for error messages. */
- public String getPreviousLine() {
+ /**
+ * Returns the previous line, for error messages. Will be {@code null} if we're at the start
+ * of the file.
+ */
+ public @Nullable String getPreviousLine() {
return mPreviousLine;
}