mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-06 16:18:59 +00:00
Simplify IO.writeFully() for Android >= 6
Do not handle buffer properties manually for Android >= 6 (where it is already handled by Os.write()). Refs <https://android.googlesource.com/platform/libcore/+/d9f7e57f5d09b587d8c8d1bd42b895f7de8fbf54%5E%21/>
This commit is contained in:
parent
79014143b9
commit
e724ff4349
1 changed files with 20 additions and 13 deletions
|
@ -2,6 +2,7 @@ package com.genymobile.scrcpy.util;
|
||||||
|
|
||||||
import com.genymobile.scrcpy.BuildConfig;
|
import com.genymobile.scrcpy.BuildConfig;
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
import android.system.ErrnoException;
|
import android.system.ErrnoException;
|
||||||
import android.system.Os;
|
import android.system.Os;
|
||||||
import android.system.OsConstants;
|
import android.system.OsConstants;
|
||||||
|
@ -30,6 +31,11 @@ public final class IO {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeFully(FileDescriptor fd, ByteBuffer from) throws IOException {
|
public static void writeFully(FileDescriptor fd, ByteBuffer from) throws IOException {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
while (from.hasRemaining()) {
|
||||||
|
write(fd, from);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// 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
|
||||||
// handle the position and 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>.
|
||||||
|
@ -46,6 +52,7 @@ public final class IO {
|
||||||
from.position(position);
|
from.position(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void writeFully(FileDescriptor fd, byte[] buffer, int offset, int len) throws IOException {
|
public static void writeFully(FileDescriptor fd, byte[] buffer, int offset, int len) throws IOException {
|
||||||
writeFully(fd, ByteBuffer.wrap(buffer, offset, len));
|
writeFully(fd, ByteBuffer.wrap(buffer, offset, len));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue