1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package libcore.io;
18 
19 import android.system.ErrnoException;
20 import android.system.GaiException;
21 import android.system.StructAddrinfo;
22 import android.system.StructFlock;
23 import android.system.StructGroupReq;
24 import android.system.StructGroupSourceReq;
25 import android.system.StructLinger;
26 import android.system.StructPasswd;
27 import android.system.StructPollfd;
28 import android.system.StructStat;
29 import android.system.StructStatVfs;
30 import android.system.StructTimeval;
31 import android.system.StructUcred;
32 import android.system.StructUtsname;
33 import android.util.MutableInt;
34 import android.util.MutableLong;
35 import java.io.FileDescriptor;
36 import java.io.InterruptedIOException;
37 import java.net.InetAddress;
38 import java.net.InetSocketAddress;
39 import java.net.SocketAddress;
40 import java.net.SocketException;
41 import java.nio.ByteBuffer;
42 
43 /**
44  * Subclass this if you want to override some {@link Os} methods but otherwise delegate.
45  */
46 public class ForwardingOs implements Os {
47     protected final Os os;
48 
ForwardingOs(Os os)49     public ForwardingOs(Os os) {
50         this.os = os;
51     }
52 
accept(FileDescriptor fd, SocketAddress peerAddress)53     public FileDescriptor accept(FileDescriptor fd, SocketAddress peerAddress) throws ErrnoException, SocketException { return os.accept(fd, peerAddress); }
access(String path, int mode)54     public boolean access(String path, int mode) throws ErrnoException { return os.access(path, mode); }
android_getaddrinfo(String node, StructAddrinfo hints, int netId)55     public InetAddress[] android_getaddrinfo(String node, StructAddrinfo hints, int netId) throws GaiException { return os.android_getaddrinfo(node, hints, netId); }
bind(FileDescriptor fd, InetAddress address, int port)56     public void bind(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException { os.bind(fd, address, port); }
bind(FileDescriptor fd, SocketAddress address)57     public void bind(FileDescriptor fd, SocketAddress address) throws ErrnoException, SocketException { os.bind(fd, address); }
chmod(String path, int mode)58     public void chmod(String path, int mode) throws ErrnoException { os.chmod(path, mode); }
chown(String path, int uid, int gid)59     public void chown(String path, int uid, int gid) throws ErrnoException { os.chown(path, uid, gid); }
close(FileDescriptor fd)60     public void close(FileDescriptor fd) throws ErrnoException { os.close(fd); }
connect(FileDescriptor fd, InetAddress address, int port)61     public void connect(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException { os.connect(fd, address, port); }
connect(FileDescriptor fd, SocketAddress address)62     public void connect(FileDescriptor fd, SocketAddress address) throws ErrnoException, SocketException { os.connect(fd, address); }
dup(FileDescriptor oldFd)63     public FileDescriptor dup(FileDescriptor oldFd) throws ErrnoException { return os.dup(oldFd); }
dup2(FileDescriptor oldFd, int newFd)64     public FileDescriptor dup2(FileDescriptor oldFd, int newFd) throws ErrnoException { return os.dup2(oldFd, newFd); }
environ()65     public String[] environ() { return os.environ(); }
execv(String filename, String[] argv)66     public void execv(String filename, String[] argv) throws ErrnoException { os.execv(filename, argv); }
execve(String filename, String[] argv, String[] envp)67     public void execve(String filename, String[] argv, String[] envp) throws ErrnoException { os.execve(filename, argv, envp); }
fchmod(FileDescriptor fd, int mode)68     public void fchmod(FileDescriptor fd, int mode) throws ErrnoException { os.fchmod(fd, mode); }
fchown(FileDescriptor fd, int uid, int gid)69     public void fchown(FileDescriptor fd, int uid, int gid) throws ErrnoException { os.fchown(fd, uid, gid); }
fcntlFlock(FileDescriptor fd, int cmd, StructFlock arg)70     public int fcntlFlock(FileDescriptor fd, int cmd, StructFlock arg) throws ErrnoException, InterruptedIOException { return os.fcntlFlock(fd, cmd, arg); }
fcntlInt(FileDescriptor fd, int cmd, int arg)71     public int fcntlInt(FileDescriptor fd, int cmd, int arg) throws ErrnoException { return os.fcntlInt(fd, cmd, arg); }
fcntlVoid(FileDescriptor fd, int cmd)72     public int fcntlVoid(FileDescriptor fd, int cmd) throws ErrnoException { return os.fcntlVoid(fd, cmd); }
fdatasync(FileDescriptor fd)73     public void fdatasync(FileDescriptor fd) throws ErrnoException { os.fdatasync(fd); }
fstat(FileDescriptor fd)74     public StructStat fstat(FileDescriptor fd) throws ErrnoException { return os.fstat(fd); }
fstatvfs(FileDescriptor fd)75     public StructStatVfs fstatvfs(FileDescriptor fd) throws ErrnoException { return os.fstatvfs(fd); }
fsync(FileDescriptor fd)76     public void fsync(FileDescriptor fd) throws ErrnoException { os.fsync(fd); }
ftruncate(FileDescriptor fd, long length)77     public void ftruncate(FileDescriptor fd, long length) throws ErrnoException { os.ftruncate(fd, length); }
gai_strerror(int error)78     public String gai_strerror(int error) { return os.gai_strerror(error); }
getegid()79     public int getegid() { return os.getegid(); }
geteuid()80     public int geteuid() { return os.geteuid(); }
getgid()81     public int getgid() { return os.getgid(); }
getenv(String name)82     public String getenv(String name) { return os.getenv(name); }
getnameinfo(InetAddress address, int flags)83     public String getnameinfo(InetAddress address, int flags) throws GaiException { return os.getnameinfo(address, flags); }
getpeername(FileDescriptor fd)84     public SocketAddress getpeername(FileDescriptor fd) throws ErrnoException { return os.getpeername(fd); }
getpgid(int pid)85     public int getpgid(int pid) throws ErrnoException { return os.getpgid(pid); }
getpid()86     public int getpid() { return os.getpid(); }
getppid()87     public int getppid() { return os.getppid(); }
getpwnam(String name)88     public StructPasswd getpwnam(String name) throws ErrnoException { return os.getpwnam(name); }
getpwuid(int uid)89     public StructPasswd getpwuid(int uid) throws ErrnoException { return os.getpwuid(uid); }
getsockname(FileDescriptor fd)90     public SocketAddress getsockname(FileDescriptor fd) throws ErrnoException { return os.getsockname(fd); }
getsockoptByte(FileDescriptor fd, int level, int option)91     public int getsockoptByte(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptByte(fd, level, option); }
getsockoptInAddr(FileDescriptor fd, int level, int option)92     public InetAddress getsockoptInAddr(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptInAddr(fd, level, option); }
getsockoptInt(FileDescriptor fd, int level, int option)93     public int getsockoptInt(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptInt(fd, level, option); }
getsockoptLinger(FileDescriptor fd, int level, int option)94     public StructLinger getsockoptLinger(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptLinger(fd, level, option); }
getsockoptTimeval(FileDescriptor fd, int level, int option)95     public StructTimeval getsockoptTimeval(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptTimeval(fd, level, option); }
getsockoptUcred(FileDescriptor fd, int level, int option)96     public StructUcred getsockoptUcred(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptUcred(fd, level, option); }
gettid()97     public int gettid() { return os.gettid(); }
getuid()98     public int getuid() { return os.getuid(); }
getxattr(String path, String name, byte[] outValue)99     public int getxattr(String path, String name, byte[] outValue) throws ErrnoException { return os.getxattr(path, name, outValue); }
if_indextoname(int index)100     public String if_indextoname(int index) { return os.if_indextoname(index); }
inet_pton(int family, String address)101     public InetAddress inet_pton(int family, String address) { return os.inet_pton(family, address); }
ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName)102     public InetAddress ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName) throws ErrnoException { return os.ioctlInetAddress(fd, cmd, interfaceName); }
ioctlInt(FileDescriptor fd, int cmd, MutableInt arg)103     public int ioctlInt(FileDescriptor fd, int cmd, MutableInt arg) throws ErrnoException { return os.ioctlInt(fd, cmd, arg); }
isatty(FileDescriptor fd)104     public boolean isatty(FileDescriptor fd) { return os.isatty(fd); }
kill(int pid, int signal)105     public void kill(int pid, int signal) throws ErrnoException { os.kill(pid, signal); }
lchown(String path, int uid, int gid)106     public void lchown(String path, int uid, int gid) throws ErrnoException { os.lchown(path, uid, gid); }
link(String oldPath, String newPath)107     public void link(String oldPath, String newPath) throws ErrnoException { os.link(oldPath, newPath); }
listen(FileDescriptor fd, int backlog)108     public void listen(FileDescriptor fd, int backlog) throws ErrnoException { os.listen(fd, backlog); }
lseek(FileDescriptor fd, long offset, int whence)109     public long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException { return os.lseek(fd, offset, whence); }
lstat(String path)110     public StructStat lstat(String path) throws ErrnoException { return os.lstat(path); }
mincore(long address, long byteCount, byte[] vector)111     public void mincore(long address, long byteCount, byte[] vector) throws ErrnoException { os.mincore(address, byteCount, vector); }
mkdir(String path, int mode)112     public void mkdir(String path, int mode) throws ErrnoException { os.mkdir(path, mode); }
mkfifo(String path, int mode)113     public void mkfifo(String path, int mode) throws ErrnoException { os.mkfifo(path, mode); }
mlock(long address, long byteCount)114     public void mlock(long address, long byteCount) throws ErrnoException { os.mlock(address, byteCount); }
mmap(long address, long byteCount, int prot, int flags, FileDescriptor fd, long offset)115     public long mmap(long address, long byteCount, int prot, int flags, FileDescriptor fd, long offset) throws ErrnoException { return os.mmap(address, byteCount, prot, flags, fd, offset); }
msync(long address, long byteCount, int flags)116     public void msync(long address, long byteCount, int flags) throws ErrnoException { os.msync(address, byteCount, flags); }
munlock(long address, long byteCount)117     public void munlock(long address, long byteCount) throws ErrnoException { os.munlock(address, byteCount); }
munmap(long address, long byteCount)118     public void munmap(long address, long byteCount) throws ErrnoException { os.munmap(address, byteCount); }
open(String path, int flags, int mode)119     public FileDescriptor open(String path, int flags, int mode) throws ErrnoException { return os.open(path, flags, mode); }
pipe2(int flags)120     public FileDescriptor[] pipe2(int flags) throws ErrnoException { return os.pipe2(flags); }
poll(StructPollfd[] fds, int timeoutMs)121     public int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException { return os.poll(fds, timeoutMs); }
posix_fallocate(FileDescriptor fd, long offset, long length)122     public void posix_fallocate(FileDescriptor fd, long offset, long length) throws ErrnoException { os.posix_fallocate(fd, offset, length); }
prctl(int option, long arg2, long arg3, long arg4, long arg5)123     public int prctl(int option, long arg2, long arg3, long arg4, long arg5) throws ErrnoException { return os.prctl(option, arg2, arg3, arg4, arg5); };
pread(FileDescriptor fd, ByteBuffer buffer, long offset)124     public int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return os.pread(fd, buffer, offset); }
pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset)125     public int pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException { return os.pread(fd, bytes, byteOffset, byteCount, offset); }
pwrite(FileDescriptor fd, ByteBuffer buffer, long offset)126     public int pwrite(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return os.pwrite(fd, buffer, offset); }
pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset)127     public int pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException { return os.pwrite(fd, bytes, byteOffset, byteCount, offset); }
read(FileDescriptor fd, ByteBuffer buffer)128     public int read(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException { return os.read(fd, buffer); }
read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount)129     public int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException { return os.read(fd, bytes, byteOffset, byteCount); }
readlink(String path)130     public String readlink(String path) throws ErrnoException { return os.readlink(path); }
realpath(String path)131     public String realpath(String path) throws ErrnoException { return os.realpath(path); }
readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts)132     public int readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException { return os.readv(fd, buffers, offsets, byteCounts); }
recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress)133     public int recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException { return os.recvfrom(fd, buffer, flags, srcAddress); }
recvfrom(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress)134     public int recvfrom(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException { return os.recvfrom(fd, bytes, byteOffset, byteCount, flags, srcAddress); }
remove(String path)135     public void remove(String path) throws ErrnoException { os.remove(path); }
removexattr(String path, String name)136     public void removexattr(String path, String name) throws ErrnoException { os.removexattr(path, name); }
rename(String oldPath, String newPath)137     public void rename(String oldPath, String newPath) throws ErrnoException { os.rename(oldPath, newPath); }
sendfile(FileDescriptor outFd, FileDescriptor inFd, MutableLong inOffset, long byteCount)138     public long sendfile(FileDescriptor outFd, FileDescriptor inFd, MutableLong inOffset, long byteCount) throws ErrnoException { return os.sendfile(outFd, inFd, inOffset, byteCount); }
sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port)139     public int sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException { return os.sendto(fd, buffer, flags, inetAddress, port); }
sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port)140     public int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException { return os.sendto(fd, bytes, byteOffset, byteCount, flags, inetAddress, port); }
sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, SocketAddress address)141     public int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, SocketAddress address) throws ErrnoException, SocketException { return os.sendto(fd, bytes, byteOffset, byteCount, flags, address); }
setegid(int egid)142     public void setegid(int egid) throws ErrnoException { os.setegid(egid); }
setenv(String name, String value, boolean overwrite)143     public void setenv(String name, String value, boolean overwrite) throws ErrnoException { os.setenv(name, value, overwrite); }
seteuid(int euid)144     public void seteuid(int euid) throws ErrnoException { os.seteuid(euid); }
setgid(int gid)145     public void setgid(int gid) throws ErrnoException { os.setgid(gid); }
setpgid(int pid, int pgid)146     public void setpgid(int pid, int pgid) throws ErrnoException { os.setpgid(pid, pgid); }
setregid(int rgid, int egid)147     public void setregid(int rgid, int egid) throws ErrnoException { os.setregid(rgid, egid); }
setreuid(int ruid, int euid)148     public void setreuid(int ruid, int euid) throws ErrnoException { os.setreuid(ruid, euid); }
setsid()149     public int setsid() throws ErrnoException { return os.setsid(); }
setsockoptByte(FileDescriptor fd, int level, int option, int value)150     public void setsockoptByte(FileDescriptor fd, int level, int option, int value) throws ErrnoException { os.setsockoptByte(fd, level, option, value); }
setsockoptIfreq(FileDescriptor fd, int level, int option, String value)151     public void setsockoptIfreq(FileDescriptor fd, int level, int option, String value) throws ErrnoException { os.setsockoptIfreq(fd, level, option, value); }
setsockoptInt(FileDescriptor fd, int level, int option, int value)152     public void setsockoptInt(FileDescriptor fd, int level, int option, int value) throws ErrnoException { os.setsockoptInt(fd, level, option, value); }
setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value)153     public void setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value) throws ErrnoException { os.setsockoptIpMreqn(fd, level, option, value); }
setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value)154     public void setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value) throws ErrnoException { os.setsockoptGroupReq(fd, level, option, value); }
setsockoptGroupSourceReq(FileDescriptor fd, int level, int option, StructGroupSourceReq value)155     public void setsockoptGroupSourceReq(FileDescriptor fd, int level, int option, StructGroupSourceReq value) throws ErrnoException { os.setsockoptGroupSourceReq(fd, level, option, value); }
setsockoptLinger(FileDescriptor fd, int level, int option, StructLinger value)156     public void setsockoptLinger(FileDescriptor fd, int level, int option, StructLinger value) throws ErrnoException { os.setsockoptLinger(fd, level, option, value); }
setsockoptTimeval(FileDescriptor fd, int level, int option, StructTimeval value)157     public void setsockoptTimeval(FileDescriptor fd, int level, int option, StructTimeval value) throws ErrnoException { os.setsockoptTimeval(fd, level, option, value); }
setuid(int uid)158     public void setuid(int uid) throws ErrnoException { os.setuid(uid); }
setxattr(String path, String name, byte[] value, int flags)159     public void setxattr(String path, String name, byte[] value, int flags) throws ErrnoException { os.setxattr(path, name, value, flags); }
shutdown(FileDescriptor fd, int how)160     public void shutdown(FileDescriptor fd, int how) throws ErrnoException { os.shutdown(fd, how); }
socket(int domain, int type, int protocol)161     public FileDescriptor socket(int domain, int type, int protocol) throws ErrnoException { return os.socket(domain, type, protocol); }
socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2)162     public void socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2) throws ErrnoException { os.socketpair(domain, type, protocol, fd1, fd2); }
stat(String path)163     public StructStat stat(String path) throws ErrnoException { return os.stat(path); }
statvfs(String path)164     public StructStatVfs statvfs(String path) throws ErrnoException { return os.statvfs(path); }
strerror(int errno)165     public String strerror(int errno) { return os.strerror(errno); }
strsignal(int signal)166     public String strsignal(int signal) { return os.strsignal(signal); }
symlink(String oldPath, String newPath)167     public void symlink(String oldPath, String newPath) throws ErrnoException { os.symlink(oldPath, newPath); }
sysconf(int name)168     public long sysconf(int name) { return os.sysconf(name); }
tcdrain(FileDescriptor fd)169     public void tcdrain(FileDescriptor fd) throws ErrnoException { os.tcdrain(fd); }
tcsendbreak(FileDescriptor fd, int duration)170     public void tcsendbreak(FileDescriptor fd, int duration) throws ErrnoException { os.tcsendbreak(fd, duration); }
umask(int mask)171     public int umask(int mask) { return os.umask(mask); }
uname()172     public StructUtsname uname() { return os.uname(); }
unlink(String pathname)173     public void unlink(String pathname) throws ErrnoException { os.unlink(pathname); }
unsetenv(String name)174     public void unsetenv(String name) throws ErrnoException { os.unsetenv(name); }
waitpid(int pid, MutableInt status, int options)175     public int waitpid(int pid, MutableInt status, int options) throws ErrnoException { return os.waitpid(pid, status, options); }
write(FileDescriptor fd, ByteBuffer buffer)176     public int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException { return os.write(fd, buffer); }
write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount)177     public int write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException { return os.write(fd, bytes, byteOffset, byteCount); }
writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts)178     public int writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException { return os.writev(fd, buffers, offsets, byteCounts); }
179 }
180