本文整理了Java中android.system.Os
类的一些代码示例,展示了Os
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Os
类的具体详情如下:
包路径:android.system.Os
类名称:Os
暂无
代码示例来源:origin: android-hacker/VirtualXposed
Os.fsync(mTarget);
write(mServer, temp, 0, MSG_LENGTH);
Os.fsync(mTarget);
Os.close(mTarget);
mClosed = true;
write(mServer, temp, 0, MSG_LENGTH);
代码示例来源:origin: android-hacker/VirtualXposed
/**
* @param path
* @param mode {@link FileMode}
* @throws Exception
*/
public static void chmod(String path, int mode) throws Exception {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
try {
Os.chmod(path, mode);
return;
} catch (Exception e) {
// ignore
}
}
File file = new File(path);
String cmd = "chmod ";
if (file.isDirectory()) {
cmd += " -R ";
}
String cmode = String.format("%o", mode);
Runtime.getRuntime().exec(cmd + cmode + " " + path).waitFor();
}
代码示例来源:origin: android-hacker/VirtualXposed
final FileDescriptor targetFd = Os.open(target.getAbsolutePath(),
O_CREAT | O_WRONLY, 0644);
Os.posix_fallocate(targetFd, 0, lengthBytes);
Os.lseek(targetFd, offsetBytes, OsConstants.SEEK_SET);
代码示例来源:origin: koral--/android-gif-drawable
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private static int getNativeFileDescriptor(FileDescriptor fileDescriptor, boolean closeOriginalDescriptor) throws GifIOException, ErrnoException {
try {
final int nativeFileDescriptor = createTempNativeFileDescriptor();
Os.dup2(fileDescriptor, nativeFileDescriptor);
return nativeFileDescriptor;
} finally {
if (closeOriginalDescriptor) {
Os.close(fileDescriptor);
}
}
}
代码示例来源:origin: termux/termux-app
Os.chmod(targetFile.getAbsolutePath(), 0700);
throw new RuntimeException("No SYMLINKS.txt encountered");
for (Pair<String, String> symlink : symlinks) {
Os.symlink(symlink.first, symlink.second);
代码示例来源:origin: android-hacker/VirtualXposed
public static void closeQuietly(FileDescriptor fd) {
if (fd != null && fd.valid()) {
try {
Os.close(fd);
} catch (ErrnoException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: android-hacker/VirtualXposed
public static void createSymlink(String oldPath, String newPath) throws Exception {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Os.symlink(oldPath, newPath);
} else {
Runtime.getRuntime().exec("ln -s " + oldPath + " " + newPath).waitFor();
}
}
代码示例来源:origin: iTXTech/Daedalus
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void process() {
try {
FileDescriptor[] pipes = Os.pipe();
mInterruptFd = pipes[0];
mBlockFd = pipes[1];
polls[0] = deviceFd;
polls[1] = blockFd;
Os.poll(polls, 100);
if (blockFd.revents != 0) {
Log.i(TAG, "Told to stop VPN");
代码示例来源:origin: julian-klode/dns66
/**
* Wrapper around {@link Os#poll(StructPollfd[], int)} that automatically restarts on EINTR
* While post-Lollipop devices handle that themselves, we need to do this for Lollipop.
*
* @param fds Descriptors and events to wait on
* @param timeout Timeout. Should be -1 for infinite, as we do not lower the timeout when
* retrying due to an interrupt
* @return The number of fds that have events
* @throws ErrnoException See {@link Os#poll(StructPollfd[], int)}
*/
public static int poll(StructPollfd[] fds, int timeout) throws ErrnoException, InterruptedException {
while (true) {
if (Thread.interrupted())
throw new InterruptedException();
try {
return Os.poll(fds, timeout);
} catch (ErrnoException e) {
if (e.errno == OsConstants.EINTR)
continue;
throw e;
}
}
}
代码示例来源:origin: lingochamp/okdownload
@Override
public void setLength(long newLength) {
final String tag = "DownloadUriOutputStream";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
try {
Os.posix_fallocate(pdf.getFileDescriptor(), 0, newLength);
} catch (Throwable e) {
if (e instanceof ErrnoException) {
if (((ErrnoException) e).errno == OsConstants.ENOSYS
|| ((ErrnoException) e).errno == OsConstants.ENOTSUP) {
Util.w(tag, "fallocate() not supported; falling back to ftruncate()");
try {
Os.ftruncate(pdf.getFileDescriptor(), newLength);
} catch (Throwable e1) {
Util.w(tag, "It can't pre-allocate length(" + newLength + ") on the sdk"
+ " version(" + Build.VERSION.SDK_INT + "), because of " + e1);
}
}
} else {
Util.w(tag, "It can't pre-allocate length(" + newLength + ") on the sdk"
+ " version(" + Build.VERSION.SDK_INT + "), because of " + e);
}
}
} else {
Util.w(tag,
"It can't pre-allocate length(" + newLength + ") on the sdk "
+ "version(" + Build.VERSION.SDK_INT + ")");
}
}
代码示例来源:origin: android-hacker/VirtualXposed
public FileBridge() {
try {
Os.socketpair(AF_UNIX, SOCK_STREAM, 0, mServer, mClient);
} catch (ErrnoException e) {
throw new RuntimeException("Failed to create bridge");
}
}
代码示例来源:origin: android-hacker/VirtualXposed
private ParcelFileDescriptor openReadInternal(String name) throws IOException {
assertPreparedAndNotSealed("openRead");
try {
if (!FileUtils.isValidExtFilename(name)) {
throw new IllegalArgumentException("Invalid name: " + name);
}
final File target = new File(resolveStageDir(), name);
final FileDescriptor targetFd = Os.open(target.getAbsolutePath(), O_RDONLY, 0);
return ParcelFileDescriptor.dup(targetFd);
} catch (ErrnoException e) {
throw new IOException(e);
}
}
代码示例来源:origin: android-hacker/VirtualXposed
/**
* java.io thinks that a read at EOF is an error and should return -1, contrary to traditional
* Unix practice where you'd read until you got 0 bytes (and any future read would return -1).
*/
public static int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws IOException {
ArrayUtils.checkOffsetAndCount(bytes.length, byteOffset, byteCount);
if (byteCount == 0) {
return 0;
}
try {
int readCount = Os.read(fd, bytes, byteOffset, byteCount);
if (readCount == 0) {
return -1;
}
return readCount;
} catch (ErrnoException errnoException) {
if (errnoException.errno == OsConstants.EAGAIN) {
// We return 0 rather than throw if we try to read from an empty non-blocking pipe.
return 0;
}
throw new IOException(errnoException);
}
}
代码示例来源:origin: julian-klode/dns66
public static FileDescriptor closeOrWarn(FileDescriptor fd, String tag, String message) {
try {
if (fd != null)
Os.close(fd);
} catch (ErrnoException e) {
Log.e(tag, "closeOrWarn: " + message, e);
} finally {
return null;
}
}
代码示例来源:origin: termux/termux-app
Os.symlink(sharedDir.getAbsolutePath(), new File(storageDir, "shared").getAbsolutePath());
Os.symlink(downloadsDir.getAbsolutePath(), new File(storageDir, "downloads").getAbsolutePath());
Os.symlink(dcimDir.getAbsolutePath(), new File(storageDir, "dcim").getAbsolutePath());
Os.symlink(picturesDir.getAbsolutePath(), new File(storageDir, "pictures").getAbsolutePath());
Os.symlink(musicDir.getAbsolutePath(), new File(storageDir, "music").getAbsolutePath());
Os.symlink(moviesDir.getAbsolutePath(), new File(storageDir, "movies").getAbsolutePath());
if (dir == null) continue;
String symlinkName = "external-" + i;
Os.symlink(dir.getAbsolutePath(), new File(storageDir, symlinkName).getAbsolutePath());
代码示例来源:origin: iTXTech/Daedalus
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void process() {
try {
FileDescriptor[] pipes = Os.pipe();
mInterruptFd = pipes[0];
mBlockFd = pipes[1];
Os.poll(polls, -1);
if (blockFd.revents != 0) {
Log.i(TAG, "Told to stop VPN");
代码示例来源:origin: julian-klode/dns66
@Test
@PrepareForTest({Log.class, Os.class})
public void testPoll_success() throws Exception {
mockStatic(Log.class);
mockStatic(Os.class);
when(Os.poll(any(StructPollfd[].class), anyInt())).then(new CountingAnswer(42));
assertEquals(42, FileHelper.poll(null, 0));
assertEquals(1, testResult);
}
代码示例来源:origin: darkskygit/VirtualApp
public FileBridge() {
try {
Os.socketpair(AF_UNIX, SOCK_STREAM, 0, mServer, mClient);
} catch (ErrnoException e) {
throw new RuntimeException("Failed to create bridge");
}
}
代码示例来源:origin: bzsome/VirtualApp-x326
private ParcelFileDescriptor openReadInternal(String name) throws IOException {
assertPreparedAndNotSealed("openRead");
try {
if (!FileUtils.isValidExtFilename(name)) {
throw new IllegalArgumentException("Invalid name: " + name);
}
final File target = new File(resolveStageDir(), name);
final FileDescriptor targetFd = Os.open(target.getAbsolutePath(), O_RDONLY, 0);
return ParcelFileDescriptor.dup(targetFd);
} catch (ErrnoException e) {
throw new IOException(e);
}
}
代码示例来源:origin: bzsome/VirtualApp-x326
/**
* java.io thinks that a read at EOF is an error and should return -1, contrary to traditional
* Unix practice where you'd read until you got 0 bytes (and any future read would return -1).
*/
public static int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws IOException {
ArrayUtils.checkOffsetAndCount(bytes.length, byteOffset, byteCount);
if (byteCount == 0) {
return 0;
}
try {
int readCount = Os.read(fd, bytes, byteOffset, byteCount);
if (readCount == 0) {
return -1;
}
return readCount;
} catch (ErrnoException errnoException) {
if (errnoException.errno == OsConstants.EAGAIN) {
// We return 0 rather than throw if we try to read from an empty non-blocking pipe.
return 0;
}
throw new IOException(errnoException);
}
}
内容来源于网络,如有侵权,请联系作者删除!