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
17package libcore.io;
18
19import android.system.ErrnoException;
20import android.system.GaiException;
21import android.system.StructAddrinfo;
22import android.system.StructCapUserData;
23import android.system.StructCapUserHeader;
24import android.system.StructFlock;
25import android.system.StructGroupReq;
26import android.system.StructGroupSourceReq;
27import android.system.StructIfaddrs;
28import android.system.StructLinger;
29import android.system.StructPasswd;
30import android.system.StructPollfd;
31import android.system.StructRlimit;
32import android.system.StructStat;
33import android.system.StructStatVfs;
34import android.system.StructTimeval;
35import android.system.StructUcred;
36import android.system.StructUtsname;
37import android.util.MutableInt;
38import android.util.MutableLong;
39import java.io.FileDescriptor;
40import java.io.InterruptedIOException;
41import java.net.InetAddress;
42import java.net.InetSocketAddress;
43import java.net.SocketAddress;
44import java.net.SocketException;
45import java.nio.ByteBuffer;
46
47/**
48 * Subclass this if you want to override some {@link Os} methods but otherwise delegate.
49 */
50public class ForwardingOs implements Os {
51    protected final Os os;
52
53    public ForwardingOs(Os os) {
54        this.os = os;
55    }
56
57    public FileDescriptor accept(FileDescriptor fd, SocketAddress peerAddress) throws ErrnoException, SocketException { return os.accept(fd, peerAddress); }
58    public boolean access(String path, int mode) throws ErrnoException { return os.access(path, mode); }
59    public InetAddress[] android_getaddrinfo(String node, StructAddrinfo hints, int netId) throws GaiException { return os.android_getaddrinfo(node, hints, netId); }
60    public void bind(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException { os.bind(fd, address, port); }
61    public void bind(FileDescriptor fd, SocketAddress address) throws ErrnoException, SocketException { os.bind(fd, address); }
62    @Override
63    public StructCapUserData[] capget(StructCapUserHeader hdr) throws ErrnoException {
64        return os.capget(hdr);
65    }
66    @Override
67    public void capset(StructCapUserHeader hdr, StructCapUserData[] data) throws ErrnoException {
68        os.capset(hdr, data);
69    }
70    public void chmod(String path, int mode) throws ErrnoException { os.chmod(path, mode); }
71    public void chown(String path, int uid, int gid) throws ErrnoException { os.chown(path, uid, gid); }
72    public void close(FileDescriptor fd) throws ErrnoException { os.close(fd); }
73    public void connect(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException { os.connect(fd, address, port); }
74    public void connect(FileDescriptor fd, SocketAddress address) throws ErrnoException, SocketException { os.connect(fd, address); }
75    public FileDescriptor dup(FileDescriptor oldFd) throws ErrnoException { return os.dup(oldFd); }
76    public FileDescriptor dup2(FileDescriptor oldFd, int newFd) throws ErrnoException { return os.dup2(oldFd, newFd); }
77    public String[] environ() { return os.environ(); }
78    public void execv(String filename, String[] argv) throws ErrnoException { os.execv(filename, argv); }
79    public void execve(String filename, String[] argv, String[] envp) throws ErrnoException { os.execve(filename, argv, envp); }
80    public void fchmod(FileDescriptor fd, int mode) throws ErrnoException { os.fchmod(fd, mode); }
81    public void fchown(FileDescriptor fd, int uid, int gid) throws ErrnoException { os.fchown(fd, uid, gid); }
82    public int fcntlFlock(FileDescriptor fd, int cmd, StructFlock arg) throws ErrnoException, InterruptedIOException { return os.fcntlFlock(fd, cmd, arg); }
83    public int fcntlInt(FileDescriptor fd, int cmd, int arg) throws ErrnoException { return os.fcntlInt(fd, cmd, arg); }
84    public int fcntlVoid(FileDescriptor fd, int cmd) throws ErrnoException { return os.fcntlVoid(fd, cmd); }
85    public void fdatasync(FileDescriptor fd) throws ErrnoException { os.fdatasync(fd); }
86    public StructStat fstat(FileDescriptor fd) throws ErrnoException { return os.fstat(fd); }
87    public StructStatVfs fstatvfs(FileDescriptor fd) throws ErrnoException { return os.fstatvfs(fd); }
88    public void fsync(FileDescriptor fd) throws ErrnoException { os.fsync(fd); }
89    public void ftruncate(FileDescriptor fd, long length) throws ErrnoException { os.ftruncate(fd, length); }
90    public String gai_strerror(int error) { return os.gai_strerror(error); }
91    public int getegid() { return os.getegid(); }
92    public int geteuid() { return os.geteuid(); }
93    public int getgid() { return os.getgid(); }
94    public String getenv(String name) { return os.getenv(name); }
95    public String getnameinfo(InetAddress address, int flags) throws GaiException { return os.getnameinfo(address, flags); }
96    public SocketAddress getpeername(FileDescriptor fd) throws ErrnoException { return os.getpeername(fd); }
97    public int getpgid(int pid) throws ErrnoException { return os.getpgid(pid); }
98    public int getpid() { return os.getpid(); }
99    public int getppid() { return os.getppid(); }
100    public StructPasswd getpwnam(String name) throws ErrnoException { return os.getpwnam(name); }
101    public StructPasswd getpwuid(int uid) throws ErrnoException { return os.getpwuid(uid); }
102    public StructRlimit getrlimit(int resource) throws ErrnoException { return os.getrlimit(resource); }
103    public SocketAddress getsockname(FileDescriptor fd) throws ErrnoException { return os.getsockname(fd); }
104    public int getsockoptByte(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptByte(fd, level, option); }
105    public InetAddress getsockoptInAddr(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptInAddr(fd, level, option); }
106    public int getsockoptInt(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptInt(fd, level, option); }
107    public StructLinger getsockoptLinger(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptLinger(fd, level, option); }
108    public StructTimeval getsockoptTimeval(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptTimeval(fd, level, option); }
109    public StructUcred getsockoptUcred(FileDescriptor fd, int level, int option) throws ErrnoException { return os.getsockoptUcred(fd, level, option); }
110    public int gettid() { return os.gettid(); }
111    public int getuid() { return os.getuid(); }
112    public byte[] getxattr(String path, String name) throws ErrnoException { return os.getxattr(path, name); }
113    public StructIfaddrs[] getifaddrs() throws ErrnoException { return os.getifaddrs(); }
114    public String if_indextoname(int index) { return os.if_indextoname(index); }
115    public int if_nametoindex(String name) { return os.if_nametoindex(name); }
116    public InetAddress inet_pton(int family, String address) { return os.inet_pton(family, address); }
117    public int ioctlFlags(FileDescriptor fd, String interfaceName) throws ErrnoException { return os.ioctlFlags(fd, interfaceName); };
118    public InetAddress ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName) throws ErrnoException { return os.ioctlInetAddress(fd, cmd, interfaceName); }
119    public int ioctlInt(FileDescriptor fd, int cmd, MutableInt arg) throws ErrnoException { return os.ioctlInt(fd, cmd, arg); }
120    public int ioctlMTU(FileDescriptor fd, String interfaceName) throws ErrnoException { return os.ioctlMTU(fd, interfaceName); };
121    public boolean isatty(FileDescriptor fd) { return os.isatty(fd); }
122    public void kill(int pid, int signal) throws ErrnoException { os.kill(pid, signal); }
123    public void lchown(String path, int uid, int gid) throws ErrnoException { os.lchown(path, uid, gid); }
124    public void link(String oldPath, String newPath) throws ErrnoException { os.link(oldPath, newPath); }
125    public void listen(FileDescriptor fd, int backlog) throws ErrnoException { os.listen(fd, backlog); }
126    public String[] listxattr(String path) throws ErrnoException { return os.listxattr(path); }
127    public long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException { return os.lseek(fd, offset, whence); }
128    public StructStat lstat(String path) throws ErrnoException { return os.lstat(path); }
129    public void mincore(long address, long byteCount, byte[] vector) throws ErrnoException { os.mincore(address, byteCount, vector); }
130    public void mkdir(String path, int mode) throws ErrnoException { os.mkdir(path, mode); }
131    public void mkfifo(String path, int mode) throws ErrnoException { os.mkfifo(path, mode); }
132    public void mlock(long address, long byteCount) throws ErrnoException { os.mlock(address, byteCount); }
133    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); }
134    public void msync(long address, long byteCount, int flags) throws ErrnoException { os.msync(address, byteCount, flags); }
135    public void munlock(long address, long byteCount) throws ErrnoException { os.munlock(address, byteCount); }
136    public void munmap(long address, long byteCount) throws ErrnoException { os.munmap(address, byteCount); }
137    public FileDescriptor open(String path, int flags, int mode) throws ErrnoException { return os.open(path, flags, mode); }
138    public FileDescriptor[] pipe2(int flags) throws ErrnoException { return os.pipe2(flags); }
139    public int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException { return os.poll(fds, timeoutMs); }
140    public void posix_fallocate(FileDescriptor fd, long offset, long length) throws ErrnoException { os.posix_fallocate(fd, offset, length); }
141    public int prctl(int option, long arg2, long arg3, long arg4, long arg5) throws ErrnoException { return os.prctl(option, arg2, arg3, arg4, arg5); };
142    public int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return os.pread(fd, buffer, offset); }
143    public int pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException { return os.pread(fd, bytes, byteOffset, byteCount, offset); }
144    public int pwrite(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return os.pwrite(fd, buffer, offset); }
145    public int pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException { return os.pwrite(fd, bytes, byteOffset, byteCount, offset); }
146    public int read(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException { return os.read(fd, buffer); }
147    public int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException { return os.read(fd, bytes, byteOffset, byteCount); }
148    public String readlink(String path) throws ErrnoException { return os.readlink(path); }
149    public String realpath(String path) throws ErrnoException { return os.realpath(path); }
150    public int readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException { return os.readv(fd, buffers, offsets, byteCounts); }
151    public int recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException { return os.recvfrom(fd, buffer, flags, srcAddress); }
152    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); }
153    public void remove(String path) throws ErrnoException { os.remove(path); }
154    public void removexattr(String path, String name) throws ErrnoException { os.removexattr(path, name); }
155    public void rename(String oldPath, String newPath) throws ErrnoException { os.rename(oldPath, newPath); }
156    public long sendfile(FileDescriptor outFd, FileDescriptor inFd, MutableLong inOffset, long byteCount) throws ErrnoException { return os.sendfile(outFd, inFd, inOffset, byteCount); }
157    public int sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException { return os.sendto(fd, buffer, flags, inetAddress, port); }
158    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); }
159    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); }
160    public void setegid(int egid) throws ErrnoException { os.setegid(egid); }
161    public void setenv(String name, String value, boolean overwrite) throws ErrnoException { os.setenv(name, value, overwrite); }
162    public void seteuid(int euid) throws ErrnoException { os.seteuid(euid); }
163    public void setgid(int gid) throws ErrnoException { os.setgid(gid); }
164    public void setpgid(int pid, int pgid) throws ErrnoException { os.setpgid(pid, pgid); }
165    public void setregid(int rgid, int egid) throws ErrnoException { os.setregid(rgid, egid); }
166    public void setreuid(int ruid, int euid) throws ErrnoException { os.setreuid(ruid, euid); }
167    public int setsid() throws ErrnoException { return os.setsid(); }
168    public void setsockoptByte(FileDescriptor fd, int level, int option, int value) throws ErrnoException { os.setsockoptByte(fd, level, option, value); }
169    public void setsockoptIfreq(FileDescriptor fd, int level, int option, String value) throws ErrnoException { os.setsockoptIfreq(fd, level, option, value); }
170    public void setsockoptInt(FileDescriptor fd, int level, int option, int value) throws ErrnoException { os.setsockoptInt(fd, level, option, value); }
171    public void setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value) throws ErrnoException { os.setsockoptIpMreqn(fd, level, option, value); }
172    public void setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value) throws ErrnoException { os.setsockoptGroupReq(fd, level, option, value); }
173    public void setsockoptGroupSourceReq(FileDescriptor fd, int level, int option, StructGroupSourceReq value) throws ErrnoException { os.setsockoptGroupSourceReq(fd, level, option, value); }
174    public void setsockoptLinger(FileDescriptor fd, int level, int option, StructLinger value) throws ErrnoException { os.setsockoptLinger(fd, level, option, value); }
175    public void setsockoptTimeval(FileDescriptor fd, int level, int option, StructTimeval value) throws ErrnoException { os.setsockoptTimeval(fd, level, option, value); }
176    public void setuid(int uid) throws ErrnoException { os.setuid(uid); }
177    public void setxattr(String path, String name, byte[] value, int flags) throws ErrnoException { os.setxattr(path, name, value, flags); }
178    public void shutdown(FileDescriptor fd, int how) throws ErrnoException { os.shutdown(fd, how); }
179    public FileDescriptor socket(int domain, int type, int protocol) throws ErrnoException { return os.socket(domain, type, protocol); }
180    public void socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2) throws ErrnoException { os.socketpair(domain, type, protocol, fd1, fd2); }
181    public StructStat stat(String path) throws ErrnoException { return os.stat(path); }
182    public StructStatVfs statvfs(String path) throws ErrnoException { return os.statvfs(path); }
183    public String strerror(int errno) { return os.strerror(errno); }
184    public String strsignal(int signal) { return os.strsignal(signal); }
185    public void symlink(String oldPath, String newPath) throws ErrnoException { os.symlink(oldPath, newPath); }
186    public long sysconf(int name) { return os.sysconf(name); }
187    public void tcdrain(FileDescriptor fd) throws ErrnoException { os.tcdrain(fd); }
188    public void tcsendbreak(FileDescriptor fd, int duration) throws ErrnoException { os.tcsendbreak(fd, duration); }
189    public int umask(int mask) { return os.umask(mask); }
190    public StructUtsname uname() { return os.uname(); }
191    public void unlink(String pathname) throws ErrnoException { os.unlink(pathname); }
192    public void unsetenv(String name) throws ErrnoException { os.unsetenv(name); }
193    public int waitpid(int pid, MutableInt status, int options) throws ErrnoException { return os.waitpid(pid, status, options); }
194    public int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException { return os.write(fd, buffer); }
195    public int write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException { return os.write(fd, bytes, byteOffset, byteCount); }
196    public int writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException { return os.writev(fd, buffers, offsets, byteCounts); }
197}
198