All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.android.system.Os Maven / Gradle / Ivy

Go to download

A library jar that provides APIs for Applications written for the Google Android Platform.

There is a newer version: 15-robolectric-12650502
Show newest version
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.system;

import dalvik.annotation.compat.UnsupportedAppUsage;

import libcore.io.Libcore;
import libcore.util.NonNull;
import libcore.util.Nullable;

import java.io.FileDescriptor;
import java.io.InterruptedIOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.SocketException;
import java.nio.ByteBuffer;

/**
 * Access to low-level system functionality. Most of these are system calls. Most users will want
 * to use higher-level APIs where available, but this class provides access to the underlying
 * primitives used to implement the higher-level APIs.
 *
 * 

The corresponding constants can be found in {@link OsConstants}. */ public final class Os { private Os() {} // Ideally we'd just have the version that accepts SocketAddress but we're stuck with // this one for legacy reasons. http://b/123568439 /** * See accept(2). */ public static FileDescriptor accept(FileDescriptor fd, InetSocketAddress peerAddress) throws ErrnoException, SocketException { return accept(fd, (SocketAddress) peerAddress); } /** * See accept(2). * @hide */ public static FileDescriptor accept(FileDescriptor fd, SocketAddress peerAddress) throws ErrnoException, SocketException { return Libcore.os.accept(fd, peerAddress); } /** * See access(2). */ public static boolean access(String path, int mode) throws ErrnoException { return Libcore.os.access(path, mode); } /** @hide */ public static InetAddress[] android_getaddrinfo(String node, StructAddrinfo hints, int netId) throws GaiException { return Libcore.os.android_getaddrinfo(node, hints, netId); } /** * See bind(2). */ public static void bind(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException { Libcore.os.bind(fd, address, port); } /** * See bind(2). */ public static void bind(@NonNull FileDescriptor fd, @NonNull SocketAddress address) throws ErrnoException, SocketException { Libcore.os.bind(fd, address); } /** * See capget(2). * * @hide */ @libcore.api.CorePlatformApi public static StructCapUserData[] capget(StructCapUserHeader hdr) throws ErrnoException { return Libcore.os.capget(hdr); } /** * See capset(2). * * @hide */ @libcore.api.CorePlatformApi public static void capset(StructCapUserHeader hdr, StructCapUserData[] data) throws ErrnoException { Libcore.os.capset(hdr, data); } /** * See chmod(2). */ public static void chmod(String path, int mode) throws ErrnoException { Libcore.os.chmod(path, mode); } /** * See chown(2). */ public static void chown(String path, int uid, int gid) throws ErrnoException { Libcore.os.chown(path, uid, gid); } /** * See close(2). */ public static void close(FileDescriptor fd) throws ErrnoException { Libcore.os.close(fd); } /** * See connect(2). */ public static void connect(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException { Libcore.os.connect(fd, address, port); } /** * See connect(2). */ public static void connect(@NonNull FileDescriptor fd, @NonNull SocketAddress address) throws ErrnoException, SocketException { Libcore.os.connect(fd, address); } /** * See dup(2). */ public static FileDescriptor dup(FileDescriptor oldFd) throws ErrnoException { return Libcore.os.dup(oldFd); } /** * See dup2(2). */ public static FileDescriptor dup2(FileDescriptor oldFd, int newFd) throws ErrnoException { return Libcore.os.dup2(oldFd, newFd); } /** * See environ(3). */ public static String[] environ() { return Libcore.os.environ(); } /** * See execv(2). */ public static void execv(String filename, String[] argv) throws ErrnoException { Libcore.os.execv(filename, argv); } /** * See execve(2). */ public static void execve(String filename, String[] argv, String[] envp) throws ErrnoException { Libcore.os.execve(filename, argv, envp); } /** * See fchmod(2). */ public static void fchmod(FileDescriptor fd, int mode) throws ErrnoException { Libcore.os.fchmod(fd, mode); } /** * See fchown(2). */ public static void fchown(FileDescriptor fd, int uid, int gid) throws ErrnoException { Libcore.os.fchown(fd, uid, gid); } /** @hide */ public static int fcntlFlock(FileDescriptor fd, int cmd, StructFlock arg) throws ErrnoException, InterruptedIOException { return Libcore.os.fcntlFlock(fd, cmd, arg); } /** @hide */ @libcore.api.CorePlatformApi public static int fcntlInt(FileDescriptor fd, int cmd, int arg) throws ErrnoException { return Libcore.os.fcntlInt(fd, cmd, arg); } /** @hide */ public static int fcntlVoid(FileDescriptor fd, int cmd) throws ErrnoException { return Libcore.os.fcntlVoid(fd, cmd); } /** * See fdatasync(2). */ public static void fdatasync(FileDescriptor fd) throws ErrnoException { Libcore.os.fdatasync(fd); } /** * See fstat(2). */ public static StructStat fstat(FileDescriptor fd) throws ErrnoException { return Libcore.os.fstat(fd); } /** * See fstatvfs(2). */ public static StructStatVfs fstatvfs(FileDescriptor fd) throws ErrnoException { return Libcore.os.fstatvfs(fd); } /** * See fsync(2). */ public static void fsync(FileDescriptor fd) throws ErrnoException { Libcore.os.fsync(fd); } /** * See ftruncate(2). */ public static void ftruncate(FileDescriptor fd, long length) throws ErrnoException { Libcore.os.ftruncate(fd, length); } /** * See gai_strerror(3). */ public static String gai_strerror(int error) { return Libcore.os.gai_strerror(error); } /** * See getegid(2). */ public static int getegid() { return Libcore.os.getegid(); } /** * See geteuid(2). */ public static int geteuid() { return Libcore.os.geteuid(); } /** * See getgid(2). */ public static int getgid() { return Libcore.os.getgid(); } /** * See getenv(3). */ public static String getenv(String name) { return Libcore.os.getenv(name); } /** * See getifaddrs(3). * @hide */ public static StructIfaddrs[] getifaddrs() throws ErrnoException { return Libcore.os.getifaddrs(); } /** @hide */ public static String getnameinfo(InetAddress address, int flags) throws GaiException { return Libcore.os.getnameinfo(address, flags); } /** * See getpeername(2). */ public static SocketAddress getpeername(FileDescriptor fd) throws ErrnoException { return Libcore.os.getpeername(fd); } /** * See getpgid(2). * @hide */ @libcore.api.CorePlatformApi public static int getpgid(int pid) throws ErrnoException { return Libcore.os.getpgid(pid); } /** * See getpid(2). */ public static int getpid() { return Libcore.os.getpid(); } /** * See getppid(2). */ public static int getppid() { return Libcore.os.getppid(); } /** @hide */ public static StructPasswd getpwnam(String name) throws ErrnoException { return Libcore.os.getpwnam(name); } /** @hide */ public static StructPasswd getpwuid(int uid) throws ErrnoException { return Libcore.os.getpwuid(uid); } /** @hide */ @libcore.api.CorePlatformApi public static StructRlimit getrlimit(int resource) throws ErrnoException { return Libcore.os.getrlimit(resource); } /** * See getsockname(2). */ public static SocketAddress getsockname(FileDescriptor fd) throws ErrnoException { return Libcore.os.getsockname(fd); } /** @hide */ public static int getsockoptByte(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptByte(fd, level, option); } /** @hide */ public static InetAddress getsockoptInAddr(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptInAddr(fd, level, option); } /** @hide */ @libcore.api.CorePlatformApi public static int getsockoptInt(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptInt(fd, level, option); } /** @hide */ @libcore.api.CorePlatformApi public static StructLinger getsockoptLinger(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptLinger(fd, level, option); } /** * See getsockopt(2). * *

Only for use with {@code option} values that return a {@code struct timeval} such as * {@link OsConstants#SO_RCVTIMEO} and {@link OsConstants#SO_SNDTIMEO}. Use with other * options may throw an {@code IllegalArgumentException} or return junk values. */ public static @NonNull StructTimeval getsockoptTimeval(@NonNull FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptTimeval(fd, level, option); } /** @hide */ public static StructUcred getsockoptUcred(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptUcred(fd, level, option); } /** * See gettid(2). */ public static int gettid() { return Libcore.os.gettid(); } /** * See getuid(2). */ public static int getuid() { return Libcore.os.getuid(); } /** * See getxattr(2) */ public static byte[] getxattr(String path, String name) throws ErrnoException { return Libcore.os.getxattr(path, name); } /** * See if_indextoname(3). */ public static String if_indextoname(int index) { return Libcore.os.if_indextoname(index); } /** * See if_nametoindex(3). */ public static int if_nametoindex(String name) { return Libcore.os.if_nametoindex(name); } /** * See inet_pton(3). */ public static InetAddress inet_pton(int family, String address) { return Libcore.os.inet_pton(family, address); } /** @hide */ public static InetAddress ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName) throws ErrnoException { return Libcore.os.ioctlInetAddress(fd, cmd, interfaceName); } /** @hide */ @libcore.api.CorePlatformApi public static int ioctlInt(FileDescriptor fd, int cmd, Int32Ref arg) throws ErrnoException { return Libcore.os.ioctlInt(fd, cmd, arg); } /** * See isatty(3). */ public static boolean isatty(FileDescriptor fd) { return Libcore.os.isatty(fd); } /** * See kill(2). */ public static void kill(int pid, int signal) throws ErrnoException { Libcore.os.kill(pid, signal); } /** * See lchown(2). */ public static void lchown(String path, int uid, int gid) throws ErrnoException { Libcore.os.lchown(path, uid, gid); } /** * See link(2). */ public static void link(String oldPath, String newPath) throws ErrnoException { Libcore.os.link(oldPath, newPath); } /** * See listen(2). */ public static void listen(FileDescriptor fd, int backlog) throws ErrnoException { Libcore.os.listen(fd, backlog); } /** * See listxattr(2) */ public static String[] listxattr(String path) throws ErrnoException { return Libcore.os.listxattr(path); } /** * See lseek(2). */ public static long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException { return Libcore.os.lseek(fd, offset, whence); } /** * See lstat(2). */ public static StructStat lstat(String path) throws ErrnoException { return Libcore.os.lstat(path); } /** * See mincore(2). */ public static void mincore(long address, long byteCount, byte[] vector) throws ErrnoException { Libcore.os.mincore(address, byteCount, vector); } /** * See mkdir(2). */ public static void mkdir(String path, int mode) throws ErrnoException { Libcore.os.mkdir(path, mode); } /** * See mkfifo(3). */ public static void mkfifo(String path, int mode) throws ErrnoException { Libcore.os.mkfifo(path, mode); } /** * See mlock(2). */ public static void mlock(long address, long byteCount) throws ErrnoException { Libcore.os.mlock(address, byteCount); } /** * See mmap(2). */ public static long mmap(long address, long byteCount, int prot, int flags, FileDescriptor fd, long offset) throws ErrnoException { return Libcore.os.mmap(address, byteCount, prot, flags, fd, offset); } /** * See msync(2). */ public static void msync(long address, long byteCount, int flags) throws ErrnoException { Libcore.os.msync(address, byteCount, flags); } /** * See munlock(2). */ public static void munlock(long address, long byteCount) throws ErrnoException { Libcore.os.munlock(address, byteCount); } /** * See munmap(2). */ public static void munmap(long address, long byteCount) throws ErrnoException { Libcore.os.munmap(address, byteCount); } /** * See open(2). */ public static FileDescriptor open(String path, int flags, int mode) throws ErrnoException { return Libcore.os.open(path, flags, mode); } /** * See pipe(2). */ public static FileDescriptor[] pipe() throws ErrnoException { return Libcore.os.pipe2(0); } /** @hide */ @libcore.api.CorePlatformApi public static FileDescriptor[] pipe2(int flags) throws ErrnoException { return Libcore.os.pipe2(flags); } /** * See poll(2). * *

Note that in Lollipop this could throw an {@code ErrnoException} with {@code EINTR}. * In later releases, the implementation will automatically just restart the system call with * an appropriately reduced timeout. */ public static int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException { return Libcore.os.poll(fds, timeoutMs); } /** * See posix_fallocate(3). */ public static void posix_fallocate(FileDescriptor fd, long offset, long length) throws ErrnoException { Libcore.os.posix_fallocate(fd, offset, length); } /** * See prctl(2). */ public static int prctl(int option, long arg2, long arg3, long arg4, long arg5) throws ErrnoException { return Libcore.os.prctl(option, arg2, arg3, arg4, arg5); }; /** * See pread(2). */ public static int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pread(fd, buffer, offset); } /** * See pread(2). */ public static int pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pread(fd, bytes, byteOffset, byteCount, offset); } /** * See pwrite(2). */ public static int pwrite(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pwrite(fd, buffer, offset); } /** * See pwrite(2). */ public static int pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pwrite(fd, bytes, byteOffset, byteCount, offset); } /** * See read(2). */ public static int read(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException { return Libcore.os.read(fd, buffer); } /** * See read(2). */ public static int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException { return Libcore.os.read(fd, bytes, byteOffset, byteCount); } /** * See readlink(2). */ public static String readlink(String path) throws ErrnoException { return Libcore.os.readlink(path); } /** * See realpath(3). * @hide */ @libcore.api.CorePlatformApi public static String realpath(String path) throws ErrnoException { return Libcore.os.realpath(path); } /** * See readv(2). */ public static int readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException { return Libcore.os.readv(fd, buffers, offsets, byteCounts); } /** * See recvfrom(2). */ public static int recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException { return Libcore.os.recvfrom(fd, buffer, flags, srcAddress); } /** * See recvfrom(2). */ public static int recvfrom(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException { return Libcore.os.recvfrom(fd, bytes, byteOffset, byteCount, flags, srcAddress); } /** * See remove(3). */ public static void remove(String path) throws ErrnoException { Libcore.os.remove(path); } /** * See removexattr(2). */ public static void removexattr(String path, String name) throws ErrnoException { Libcore.os.removexattr(path, name); } /** * See rename(2). */ public static void rename(String oldPath, String newPath) throws ErrnoException { Libcore.os.rename(oldPath, newPath); } /** * See sendfile(2). */ public static long sendfile(FileDescriptor outFd, FileDescriptor inFd, Int64Ref offset, long byteCount) throws ErrnoException { return Libcore.os.sendfile(outFd, inFd, offset, byteCount); } /** * See sendto(2). */ public static int sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException { return Libcore.os.sendto(fd, buffer, flags, inetAddress, port); } /** * See sendto(2). */ public static int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException { return Libcore.os.sendto(fd, bytes, byteOffset, byteCount, flags, inetAddress, port); } /** * See sendto(2). */ public static int sendto(@NonNull FileDescriptor fd, @NonNull byte[] bytes, int byteOffset, int byteCount, int flags, @Nullable SocketAddress address) throws ErrnoException, SocketException { return Libcore.os.sendto(fd, bytes, byteOffset, byteCount, flags, address); } /** * See setegid(2). * @deprecated Android Applications do not have sufficient privileges to call this method. */ @Deprecated public static void setegid(int egid) throws ErrnoException { Libcore.os.setegid(egid); } /** * See setenv(3). */ public static void setenv(String name, String value, boolean overwrite) throws ErrnoException { Libcore.os.setenv(name, value, overwrite); } /** * See seteuid(2). * @deprecated Android Applications do not have sufficient privileges to call this method. */ @Deprecated public static void seteuid(int euid) throws ErrnoException { Libcore.os.seteuid(euid); } /** * See setgid(2). * @deprecated Android Applications do not have sufficient privileges to call this method. */ @Deprecated public static void setgid(int gid) throws ErrnoException { Libcore.os.setgid(gid); } /** * See setpgid(2). * @hide */ @libcore.api.CorePlatformApi public static void setpgid(int pid, int pgid) throws ErrnoException { Libcore.os.setpgid(pid, pgid); } /** * See setregid(2). * @hide */ @libcore.api.CorePlatformApi public static void setregid(int rgid, int egid) throws ErrnoException { Libcore.os.setregid(rgid, egid); } /** * See setreuid(2). * @hide */ @libcore.api.CorePlatformApi public static void setreuid(int ruid, int euid) throws ErrnoException { Libcore.os.setreuid(ruid, euid); } /** * See setsid(2). */ public static int setsid() throws ErrnoException { return Libcore.os.setsid(); } /** @hide */ public static void setsockoptByte(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptByte(fd, level, option, value); } /** @hide */ @UnsupportedAppUsage @libcore.api.CorePlatformApi public static void setsockoptIfreq(FileDescriptor fd, int level, int option, String value) throws ErrnoException { Libcore.os.setsockoptIfreq(fd, level, option, value); } /** * See setsockopt(2). */ public static void setsockoptInt(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptInt(fd, level, option, value); } /** @hide */ public static void setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptIpMreqn(fd, level, option, value); } /** @hide */ public static void setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value) throws ErrnoException { Libcore.os.setsockoptGroupReq(fd, level, option, value); } /** @hide */ @libcore.api.CorePlatformApi public static void setsockoptLinger(FileDescriptor fd, int level, int option, StructLinger value) throws ErrnoException { Libcore.os.setsockoptLinger(fd, level, option, value); } /** * See setsockopt(2). * *

Only for use with {@code option} values that take a {@code struct timeval} such as * {@link OsConstants#SO_RCVTIMEO} and {@link OsConstants#SO_SNDTIMEO}. Use with other * options is likely to cause incorrect behavior. */ public static void setsockoptTimeval(@NonNull FileDescriptor fd, int level, int option, @NonNull StructTimeval value) throws ErrnoException { Libcore.os.setsockoptTimeval(fd, level, option, value); } /** * See setuid(2). * @deprecated Android Applications do not have sufficient privileges to call this method. */ @Deprecated public static void setuid(int uid) throws ErrnoException { Libcore.os.setuid(uid); } /** * See setxattr(2) */ public static void setxattr(String path, String name, byte[] value, int flags) throws ErrnoException { Libcore.os.setxattr(path, name, value, flags); }; /** * See shutdown(2). */ public static void shutdown(FileDescriptor fd, int how) throws ErrnoException { Libcore.os.shutdown(fd, how); } /** * See socket(2). */ public static FileDescriptor socket(int domain, int type, int protocol) throws ErrnoException { return Libcore.os.socket(domain, type, protocol); } /** * See socketpair(2). */ public static void socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2) throws ErrnoException { Libcore.os.socketpair(domain, type, protocol, fd1, fd2); } /** * See splice(2). * @hide */ @libcore.api.CorePlatformApi public static long splice(FileDescriptor fdIn, Int64Ref offIn, FileDescriptor fdOut, Int64Ref offOut, long len, int flags) throws ErrnoException { return Libcore.os.splice(fdIn, offIn, fdOut, offOut, len, flags); } /** * See stat(2). */ public static StructStat stat(String path) throws ErrnoException { return Libcore.os.stat(path); } /** * See statvfs(2). */ public static StructStatVfs statvfs(String path) throws ErrnoException { return Libcore.os.statvfs(path); } /** * See strerror(2). */ public static String strerror(int errno) { return Libcore.os.strerror(errno); } /** * See strsignal(3). */ public static String strsignal(int signal) { return Libcore.os.strsignal(signal); } /** * See symlink(2). */ public static void symlink(String oldPath, String newPath) throws ErrnoException { Libcore.os.symlink(oldPath, newPath); } /** * See sysconf(3). */ public static long sysconf(int name) { return Libcore.os.sysconf(name); } /** * See tcdrain(3). */ public static void tcdrain(FileDescriptor fd) throws ErrnoException { Libcore.os.tcdrain(fd); } /** * See tcsendbreak(3). */ public static void tcsendbreak(FileDescriptor fd, int duration) throws ErrnoException { Libcore.os.tcsendbreak(fd, duration); } /** * See umask(2). */ public static int umask(int mask) { return Libcore.os.umask(mask); } /** * See uname(2). */ public static StructUtsname uname() { return Libcore.os.uname(); } /** * @hide See unlink(2). */ @libcore.api.CorePlatformApi public static void unlink(String pathname) throws ErrnoException { Libcore.os.unlink(pathname); } /** * See unsetenv(3). */ public static void unsetenv(String name) throws ErrnoException { Libcore.os.unsetenv(name); } /** * @hide See waitpid(2). * * @throws IllegalArgumentException if {@code status != null && status.length != 1} */ public static int waitpid(int pid, Int32Ref status, int options) throws ErrnoException { return Libcore.os.waitpid(pid, status, options); } /** * See write(2). */ public static int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException { return Libcore.os.write(fd, buffer); } /** * See write(2). */ public static int write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException { return Libcore.os.write(fd, bytes, byteOffset, byteCount); } /** * See writev(2). */ public static int writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException { return Libcore.os.writev(fd, buffers, offsets, byteCounts); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy