I'm currently running a command on Android, and am expecting an immediate result when the display is touched. The command, "su -c getevent -l", when run in a terminal works perfectly; every screen touch immediately prints that line to the terminal.
However, when running the following code, the read() command blocks, and doesn't unblock (and runs Log.d()) when new data comes in:
Process process = Runtime.getRuntime().exec(new String[] { "su", "-c", "getevent -l" });
InputStreamReader reader = new InputStreamReader(process.getInputStream());
while (reader.read() != -1) {
Log.d("", "Got data from reader.read()");
}
I can sometimes get this to unblock by saturating the su process with a ton of data. Hence, this seems like some kind of a buffering issue to me, but I'm not using a BufferedReader.
Furthermore, even if I manually check for more data in a loop (via reader.ready()), it still fails to detect that data is ready to be read until I touch the screen a number of times (again, seemingly filling some unknown buffer):
while(true){
while(reader.ready()){
Log.d("", "Got data from reader.read()");
}
Thread.sleep(100);
}
Is there any buffering that might be causing this? Or a better way to directly access the input stream?