mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-12-17 05:24:19 +01:00
Fix IO.writeFully() on Android 5
Os.write() did not update the ByteBuffer position before Android 6. A workaround was added by commitb882322f73, which fixed part of the problem, but the position was still not updated across calls, causing the wrong chunk to be written. Refs <d9f7e57f5d%5E%21/>
This commit is contained in:
@@ -31,8 +31,9 @@ public final class IO {
|
|||||||
|
|
||||||
public static void writeFully(FileDescriptor fd, ByteBuffer from) throws IOException {
|
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
|
// 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>.
|
// See <https://github.com/Genymobile/scrcpy/issues/291>.
|
||||||
|
int position = from.position();
|
||||||
int remaining = from.remaining();
|
int remaining = from.remaining();
|
||||||
while (remaining > 0) {
|
while (remaining > 0) {
|
||||||
int w = write(fd, from);
|
int w = write(fd, from);
|
||||||
@@ -41,6 +42,8 @@ public final class IO {
|
|||||||
throw new AssertionError("Os.write() returned a negative value (" + w + ")");
|
throw new AssertionError("Os.write() returned a negative value (" + w + ")");
|
||||||
}
|
}
|
||||||
remaining -= w;
|
remaining -= w;
|
||||||
|
position += w;
|
||||||
|
from.position(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user