Display and control your Android device
Fix IO.writeFully() on Android 5
Romain Vimont79014143b9cc
diff --git a/server/src/main/java/com/genymobile/scrcpy/util/IO.java b/server/src/main/java/com/genymobile/scrcpy/util/IO.javaindex 5c558c1b..8ef1500d 100644--- a/server/src/main/java/com/genymobile/scrcpy/util/IO.java+++ b/server/src/main/java/com/genymobile/scrcpy/util/IO.java@@ -31,8 +31,9 @@ public final class IO {public static void writeFully(FileDescriptor fd, ByteBuffer from) throws IOException {// ByteBuffer position is not updated as expected by Os.write() on old Android versions, so- // count the remaining bytes manually.+ // handle the position and the remaining bytes manually.// See <https://github.com/Genymobile/scrcpy/issues/291>.+ int position = from.position();int remaining = from.remaining();while (remaining > 0) {int w = write(fd, from);@@ -41,6 +42,8 @@ public final class IO {throw new AssertionError("Os.write() returned a negative value (" + w + ")");}remaining -= w;+ position += w;+ from.position(position);}}