summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmds/uinput/src/com/android/commands/uinput/EvemuParser.java14
-rw-r--r--cmds/uinput/tests/src/com/android/commands/uinput/tests/EvemuParserTest.java5
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