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

Commit 4c26ce03 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "uinput: fix end-of-file handling" into main

parents f592160b 3ff756b8
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -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;
        }

+5 −0
Original line number Diff line number Diff line
@@ -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