Added in API level 21

Os


class Os
kotlin.Any
   ↳ android.system.Os

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 OsConstants.

Summary

Public methods
static FileDescriptor!
accept(fd: FileDescriptor!, peerAddress: InetSocketAddress!)

See accept(2).

static Boolean
access(path: String!, mode: Int)

See access(2).

static Unit
bind(fd: FileDescriptor!, address: InetAddress!, port: Int)

See bind(2).

static Unit

See bind(2).

static Unit
chmod(path: String!, mode: Int)

See chmod(2).

static Unit
chown(path: String!, uid: Int, gid: Int)

See chown(2).

static Unit

See close(2).

static Unit
connect(fd: FileDescriptor!, address: InetAddress!, port: Int)

See connect(2).

static Unit

See connect(2).

static FileDescriptor!

See dup(2).

static FileDescriptor!
dup2(oldFd: FileDescriptor!, newFd: Int)

See dup2(2).

static Array<String!>!

See environ(3).

static Unit
execv(filename: String!, argv: Array<String!>!)

See exec(3).

static Unit
execve(filename: String!, argv: Array<String!>!, envp: Array<String!>!)

See execve(2).

static Unit
fchmod(fd: FileDescriptor!, mode: Int)

See fchmod(2).

static Unit
fchown(fd: FileDescriptor!, uid: Int, gid: Int)

See fchown(2).

static Int
fcntlInt(fd: FileDescriptor, cmd: Int, arg: Int)

See fcntl(2).

static Unit

See fdatasync(2).

static StructStat!

See fstat(2).

static StructStatVfs!

See fstatvfs(2).

static Unit

See fsync(2).

static Unit
ftruncate(fd: FileDescriptor!, length: Long)

See ftruncate(2).

static String!
gai_strerror(error: Int)

See gai_strerror(3).

static Int

See getegid(2).

static String!
getenv(name: String!)

See getenv(3).

static Int

See geteuid(2).

static Int

See getgid(2).

static SocketAddress!

See getpeername(2).

static Int

See getpid(2).

static Int

See getppid(2).

static SocketAddress!

See getsockname(2).

static StructTimeval
getsockoptTimeval(fd: FileDescriptor, level: Int, option: Int)

See getsockopt(2).

static Int

See gettid(2).

static Int

See getuid(2).

static ByteArray!
getxattr(path: String!, name: String!)

See getxattr(2)

static String!

See if_indextoname(3).

static Int

See if_nametoindex(3).

static InetAddress!
inet_pton(family: Int, address: String!)

See inet_pton(3).

static Boolean

See isatty(3).

static Unit
kill(pid: Int, signal: Int)

See kill(2).

static Unit
lchown(path: String!, uid: Int, gid: Int)

See lchown(2).

static Unit
link(oldPath: String!, newPath: String!)

See link(2).

static Unit
listen(fd: FileDescriptor!, backlog: Int)

See listen(2).

static Array<String!>!
listxattr(path: String!)

See listxattr(2)

static Long
lseek(fd: FileDescriptor!, offset: Long, whence: Int)

See lseek(2).

static StructStat!
lstat(path: String!)

See lstat(2).

static FileDescriptor
memfd_create(name: String, flags: Int)

See memfd_create(2).

static Unit
mincore(address: Long, byteCount: Long, vector: ByteArray!)

See mincore(2).

static Unit
mkdir(path: String!, mode: Int)

See mkdir(2).

static Unit
mkfifo(path: String!, mode: Int)

See mkfifo(3).

static Unit
mlock(address: Long, byteCount: Long)

See mlock(2).

static Long
mmap(address: Long, byteCount: Long, prot: Int, flags: Int, fd: FileDescriptor!, offset: Long)

See mmap(2).

static Unit
msync(address: Long, byteCount: Long, flags: Int)

See msync(2).

static Unit
munlock(address: Long, byteCount: Long)

See munlock(2).

static Unit
munmap(address: Long, byteCount: Long)

See munmap(2).

static FileDescriptor!
open(path: String!, flags: Int, mode: Int)

See open(2).

static Array<FileDescriptor!>!

See pipe(2).

static Int
poll(fds: Array<StructPollfd!>!, timeoutMs: Int)

See poll(2).

static Unit
posix_fallocate(fd: FileDescriptor!, offset: Long, length: Long)

See posix_fallocate(3).

static Int
prctl(option: Int, arg2: Long, arg3: Long, arg4: Long, arg5: Long)

See prctl(2).

static Int
pread(fd: FileDescriptor!, buffer: ByteBuffer!, offset: Long)

See pread(2).

static Int
pread(fd: FileDescriptor!, bytes: ByteArray!, byteOffset: Int, byteCount: Int, offset: Long)

See pread(2).

static Int
pwrite(fd: FileDescriptor!, buffer: ByteBuffer!, offset: Long)

See pwrite(2).

static Int
pwrite(fd: FileDescriptor!, bytes: ByteArray!, byteOffset: Int, byteCount: Int, offset: Long)

See pwrite(2).

static Int
read(fd: FileDescriptor!, buffer: ByteBuffer!)

See read(2).

static Int
read(fd: FileDescriptor!, bytes: ByteArray!, byteOffset: Int, byteCount: Int)

See read(2).

static String!
readlink(path: String!)

See readlink(2).

static Int
readv(fd: FileDescriptor!, buffers: Array<Any!>!, offsets: IntArray!, byteCounts: IntArray!)

See readv(2).

static Int
recvfrom(fd: FileDescriptor!, buffer: ByteBuffer!, flags: Int, srcAddress: InetSocketAddress!)

See recvfrom(2).

static Int
recvfrom(fd: FileDescriptor!, bytes: ByteArray!, byteOffset: Int, byteCount: Int, flags: Int, srcAddress: InetSocketAddress!)

See recvfrom(2).

static Int
recvmsg(fd: FileDescriptor, msg: StructMsghdr, flags: Int)

See recvmsg(2).

static Unit
remove(path: String!)

See remove(3).

static Unit
removexattr(path: String!, name: String!)

See removexattr(2).

static Unit
rename(oldPath: String!, newPath: String!)

See rename(2).

static Long
sendfile(outFd: FileDescriptor!, inFd: FileDescriptor!, offset: Int64Ref!, byteCount: Long)

See sendfile(2).

static Int
sendmsg(fd: FileDescriptor, msg: StructMsghdr, flags: Int)

See sendmsg(2).

static Int
sendto(fd: FileDescriptor!, buffer: ByteBuffer!, flags: Int, inetAddress: InetAddress!, port: Int)

See sendto(2).

static Int
sendto(fd: FileDescriptor!, bytes: ByteArray!, byteOffset: Int, byteCount: Int, flags: Int, inetAddress: InetAddress!, port: Int)

See sendto(2).

static Int
sendto(fd: FileDescriptor, bytes: ByteArray, byteOffset: Int, byteCount: Int, flags: Int, address: SocketAddress?)

See sendto(2).

static Unit
setegid(egid: Int)

See setegid(2).

static Unit
setenv(name: String!, value: String!, overwrite: Boolean)

See setenv(3).

static Unit
seteuid(euid: Int)

See seteuid(2).

static Unit
setgid(gid: Int)

See setgid(2).

static Int

See setsid(2).

static Unit
setsockoptInt(fd: FileDescriptor!, level: Int, option: Int, value: Int)

See setsockopt(2).

static Unit
setsockoptTimeval(fd: FileDescriptor, level: Int, option: Int, value: StructTimeval)

See setsockopt(2).

static Unit
setuid(uid: Int)

See setuid(2).

static Unit
setxattr(path: String!, name: String!, value: ByteArray!, flags: Int)

See setxattr(2)

static Unit

See shutdown(2).

static FileDescriptor!
socket(domain: Int, type: Int, protocol: Int)

See socket(2).

static Unit
socketpair(domain: Int, type: Int, protocol: Int, fd1: FileDescriptor!, fd2: FileDescriptor!)

See socketpair(2).

static StructStat!
stat(path: String!)

See stat(2).

static StructStatVfs!
statvfs(path: String!)

See statvfs(2).

static String!
strerror(errno: Int)

See strerror(2).

static String!
strsignal(signal: Int)

See strsignal(3).

static Unit
symlink(oldPath: String!, newPath: String!)

See symlink(2).

static Long
sysconf(name: Int)

See sysconf(3).

static Unit

See tcdrain(3).

static Unit
tcsendbreak(fd: FileDescriptor!, duration: Int)

See tcsendbreak(3).

static Int
umask(mask: Int)

See umask(2).

static StructUtsname!

See uname(2).

static Unit
unsetenv(name: String!)

See unsetenv(3).

static Int
write(fd: FileDescriptor!, buffer: ByteBuffer!)

See write(2).

static Int
write(fd: FileDescriptor!, bytes: ByteArray!, byteOffset: Int, byteCount: Int)

See write(2).

static Int
writev(fd: FileDescriptor!, buffers: Array<Any!>!, offsets: IntArray!, byteCounts: IntArray!)

See writev(2).

Public methods

accept

Added in API level 21
static fun accept(
    fd: FileDescriptor!,
    peerAddress: InetSocketAddress!
): FileDescriptor!

See accept(2).

access

Added in API level 21
static fun access(
    path: String!,
    mode: Int
): Boolean

See access(2).

bind

Added in API level 21
static fun bind(
    fd: FileDescriptor!,
    address: InetAddress!,
    port: Int
): Unit

See bind(2).

bind

Added in API level 29
static fun bind(
    fd: FileDescriptor,
    address: SocketAddress
): Unit

See bind(2).

Parameters
fd FileDescriptor: This value cannot be null.
address SocketAddress: This value cannot be null.

chmod

Added in API level 21
static fun chmod(
    path: String!,
    mode: Int
): Unit

See chmod(2).

chown

Added in API level 21
static fun chown(
    path: String!,
    uid: Int,
    gid: Int
): Unit

See chown(2).

close

Added in API level 21
static fun close(fd: FileDescriptor!): Unit

See close(2).

connect

Added in API level 21
static fun connect(
    fd: FileDescriptor!,
    address: InetAddress!,
    port: Int
): Unit

See connect(2).

connect

Added in API level 29
static fun connect(
    fd: FileDescriptor,
    address: SocketAddress
): Unit

See connect(2).

Parameters
fd FileDescriptor: This value cannot be null.
address SocketAddress: This value cannot be null.

dup

Added in API level 21
static fun dup(oldFd: FileDescriptor!): FileDescriptor!

See dup(2).

dup2

Added in API level 21
static fun dup2(
    oldFd: FileDescriptor!,
    newFd: Int
): FileDescriptor!

See dup2(2).

environ

Added in API level 21
static fun environ(): Array<String!>!

See environ(3).

execv

Added in API level 21
static fun execv(
    filename: String!,
    argv: Array<String!>!
): Unit

See exec(3).

execve

Added in API level 21
static fun execve(
    filename: String!,
    argv: Array<String!>!,
    envp: Array<String!>!
): Unit

See execve(2).

fchmod

Added in API level 21
static fun fchmod(
    fd: FileDescriptor!,
    mode: Int
): Unit

See fchmod(2).

fchown

Added in API level 21
static fun fchown(
    fd: FileDescriptor!,
    uid: Int,
    gid: Int
): Unit

See fchown(2).

fcntlInt

Added in API level 30
static fun fcntlInt(
    fd: FileDescriptor,
    cmd: Int,
    arg: Int
): Int

See fcntl(2).

Parameters
fd FileDescriptor: This value cannot be null.

fdatasync

Added in API level 21
static fun fdatasync(fd: FileDescriptor!): Unit

See fdatasync(2).

fstat

Added in API level 21
static fun fstat(fd: FileDescriptor!): StructStat!

See fstat(2).

fstatvfs

Added in API level 21
static fun fstatvfs(fd: FileDescriptor!): StructStatVfs!

See fstatvfs(2).

fsync

Added in API level 21
static fun fsync(fd: FileDescriptor!): Unit

See fsync(2).

ftruncate

Added in API level 21
static fun ftruncate(
    fd: FileDescriptor!,
    length: Long
): Unit

See ftruncate(2).

gai_strerror

Added in API level 21
static fun gai_strerror(error: Int): String!

See gai_strerror(3).

getegid

Added in API level 21
static fun getegid(): Int

See getegid(2).

getenv

Added in API level 21
static fun getenv(name: String!): String!

See getenv(3).

geteuid

Added in API level 21
static fun geteuid(): Int

See geteuid(2).

getgid

Added in API level 21
static fun getgid(): Int

See getgid(2).

getpeername

Added in API level 21
static fun getpeername(fd: FileDescriptor!): SocketAddress!

See getpeername(2).

getpid

Added in API level 21
static fun getpid(): Int

See getpid(2).

getppid

Added in API level 21
static fun getppid(): Int

See getppid(2).

getsockname

Added in API level 21
static fun getsockname(fd: FileDescriptor!): SocketAddress!

See getsockname(2).

getsockoptTimeval

Added in API level 29
static fun getsockoptTimeval(
    fd: FileDescriptor,
    level: Int,
    option: Int
): StructTimeval

See getsockopt(2).

Only for use with option values that return a struct timeval such as OsConstants#SO_RCVTIMEO and OsConstants#SO_SNDTIMEO. Use with other options may throw an IllegalArgumentException or return junk values.

Parameters
fd FileDescriptor: This value cannot be null.
Return
StructTimeval This value cannot be null.

gettid

Added in API level 21
static fun gettid(): Int

See gettid(2).

getuid

Added in API level 21
static fun getuid(): Int

See getuid(2).

getxattr

Added in API level 26
static fun getxattr(
    path: String!,
    name: String!
): ByteArray!

See getxattr(2)

if_indextoname

Added in API level 21
static fun if_indextoname(index: Int): String!

See if_indextoname(3).

if_nametoindex

Added in API level 26
static fun if_nametoindex(name: String!): Int

See if_nametoindex(3).

inet_pton

Added in API level 21
static fun inet_pton(
    family: Int,
    address: String!
): InetAddress!

See inet_pton(3).

isatty

Added in API level 21
static fun isatty(fd: FileDescriptor!): Boolean

See isatty(3).

kill

Added in API level 21
static fun kill(
    pid: Int,
    signal: Int
): Unit

See kill(2).

lchown

Added in API level 21
static fun lchown(
    path: String!,
    uid: Int,
    gid: Int
): Unit

See lchown(2).

Added in API level 21
static fun link(
    oldPath: String!,
    newPath: String!
): Unit

See link(2).

listen

Added in API level 21
static fun listen(
    fd: FileDescriptor!,
    backlog: Int
): Unit

See listen(2).

listxattr

Added in API level 26
static fun listxattr(path: String!): Array<String!>!

See listxattr(2)

lseek

Added in API level 21
static fun lseek(
    fd: FileDescriptor!,
    offset: Long,
    whence: Int
): Long

See lseek(2).

lstat

Added in API level 21
static fun lstat(path: String!): StructStat!

See lstat(2).

memfd_create

Added in API level 30
static fun memfd_create(
    name: String,
    flags: Int
): FileDescriptor

See memfd_create(2).

Parameters
name String: This value cannot be null.
Return
FileDescriptor This value cannot be null.

mincore

Added in API level 21
static fun mincore(
    address: Long,
    byteCount: Long,
    vector: ByteArray!
): Unit

See mincore(2).

mkdir

Added in API level 21
static fun mkdir(
    path: String!,
    mode: Int
): Unit

See mkdir(2).

mkfifo

Added in API level 21
static fun mkfifo(
    path: String!,
    mode: Int
): Unit

See mkfifo(3).

mlock

Added in API level 21
static fun mlock(
    address: Long,
    byteCount: Long
): Unit

See mlock(2).

mmap

Added in API level 21
static fun mmap(
    address: Long,
    byteCount: Long,
    prot: Int,
    flags: Int,
    fd: FileDescriptor!,
    offset: Long
): Long

See mmap(2).

msync

Added in API level 21
static fun msync(
    address: Long,
    byteCount: Long,
    flags: Int
): Unit

See msync(2).

munlock

Added in API level 21
static fun munlock(
    address: Long,
    byteCount: Long
): Unit

See munlock(2).

munmap

Added in API level 21
static fun munmap(
    address: Long,
    byteCount: Long
): Unit

See munmap(2).

open

Added in API level 21
static fun open(
    path: String!,
    flags: Int,
    mode: Int
): FileDescriptor!

See open(2).

pipe

Added in API level 21
static fun pipe(): Array<FileDescriptor!>!

See pipe(2).

poll

Added in API level 21
static fun poll(
    fds: Array<StructPollfd!>!,
    timeoutMs: Int
): Int

See poll(2).

Note that in Lollipop this could throw an ErrnoException with EINTR. In later releases, the implementation will automatically just restart the system call with an appropriately reduced timeout.

posix_fallocate

Added in API level 21
static fun posix_fallocate(
    fd: FileDescriptor!,
    offset: Long,
    length: Long
): Unit

See posix_fallocate(3).

prctl

Added in API level 21
static fun prctl(
    option: Int,
    arg2: Long,
    arg3: Long,
    arg4: Long,
    arg5: Long
): Int

See prctl(2).

pread

Added in API level 21
static fun pread(
    fd: FileDescriptor!,
    buffer: ByteBuffer!,
    offset: Long
): Int

See pread(2).

pread

Added in API level 21
static fun pread(
    fd: FileDescriptor!,
    bytes: ByteArray!,
    byteOffset: Int,
    byteCount: Int,
    offset: Long
): Int

See pread(2).

pwrite

Added in API level 21
static fun pwrite(
    fd: FileDescriptor!,
    buffer: ByteBuffer!,
    offset: Long
): Int

See pwrite(2).

pwrite

Added in API level 21
static fun pwrite(
    fd: FileDescriptor!,
    bytes: ByteArray!,
    byteOffset: Int,
    byteCount: Int,
    offset: Long
): Int

See pwrite(2).

read

Added in API level 21
static fun read(
    fd: FileDescriptor!,
    buffer: ByteBuffer!
): Int

See read(2).

read

Added in API level 21
static fun read(
    fd: FileDescriptor!,
    bytes: ByteArray!,
    byteOffset: Int,
    byteCount: Int
): Int

See read(2).

Added in API level 21
static fun readlink(path: String!): String!

See readlink(2).

readv

Added in API level 21
static fun readv(
    fd: FileDescriptor!,
    buffers: Array<Any!>!,
    offsets: IntArray!,
    byteCounts: IntArray!
): Int

See readv(2).

recvfrom

Added in API level 21
static fun recvfrom(
    fd: FileDescriptor!,
    buffer: ByteBuffer!,
    flags: Int,
    srcAddress: InetSocketAddress!
): Int

See recvfrom(2).

recvfrom

Added in API level 21
static fun recvfrom(
    fd: FileDescriptor!,
    bytes: ByteArray!,
    byteOffset: Int,
    byteCount: Int,
    flags: Int,
    srcAddress: InetSocketAddress!
): Int

See recvfrom(2).

recvmsg

Added in API level 31
static fun recvmsg(
    fd: FileDescriptor,
    msg: StructMsghdr,
    flags: Int
): Int

See recvmsg(2).

Parameters
fd FileDescriptor: This value cannot be null.
msg StructMsghdr: This value cannot be null.

remove

Added in API level 21
static fun remove(path: String!): Unit

See remove(3).

removexattr

Added in API level 26
static fun removexattr(
    path: String!,
    name: String!
): Unit

See removexattr(2).

rename

Added in API level 21
static fun rename(
    oldPath: String!,
    newPath: String!
): Unit

See rename(2).

sendfile

Added in API level 28
static fun sendfile(
    outFd: FileDescriptor!,
    inFd: FileDescriptor!,
    offset: Int64Ref!,
    byteCount: Long
): Long

See sendfile(2).

sendmsg

Added in API level 31
static fun sendmsg(
    fd: FileDescriptor,
    msg: StructMsghdr,
    flags: Int
): Int

See sendmsg(2).

Parameters
fd FileDescriptor: This value cannot be null.
msg StructMsghdr: This value cannot be null.

sendto

Added in API level 21
static fun sendto(
    fd: FileDescriptor!,
    buffer: ByteBuffer!,
    flags: Int,
    inetAddress: InetAddress!,
    port: Int
): Int

See sendto(2).

sendto

Added in API level 21
static fun sendto(
    fd: FileDescriptor!,
    bytes: ByteArray!,
    byteOffset: Int,
    byteCount: Int,
    flags: Int,
    inetAddress: InetAddress!,
    port: Int
): Int

See sendto(2).

sendto

Added in API level 29
static fun sendto(
    fd: FileDescriptor,
    bytes: ByteArray,
    byteOffset: Int,
    byteCount: Int,
    flags: Int,
    address: SocketAddress?
): Int

See sendto(2).

Parameters
fd FileDescriptor: This value cannot be null.
bytes ByteArray: This value cannot be null.
address SocketAddress?: This value may be null.

setegid

Added in API level 21
Deprecated in API level 29
static fun setegid(egid: Int): Unit

Deprecated: Android Applications do not have sufficient privileges to call this method.

See setegid(2).

setenv

Added in API level 21
static fun setenv(
    name: String!,
    value: String!,
    overwrite: Boolean
): Unit

See setenv(3).

seteuid

Added in API level 21
Deprecated in API level 29
static fun seteuid(euid: Int): Unit

Deprecated: Android Applications do not have sufficient privileges to call this method.

See seteuid(2).

setgid

Added in API level 21
Deprecated in API level 29
static fun setgid(gid: Int): Unit

Deprecated: Android Applications do not have sufficient privileges to call this method.

See setgid(2).

setsid

Added in API level 21
static fun setsid(): Int

See setsid(2).

setsockoptInt

Added in API level 26
static fun setsockoptInt(
    fd: FileDescriptor!,
    level: Int,
    option: Int,
    value: Int
): Unit

See setsockopt(2).

setsockoptTimeval

Added in API level 29
static fun setsockoptTimeval(
    fd: FileDescriptor,
    level: Int,
    option: Int,
    value: StructTimeval
): Unit

See setsockopt(2).

Only for use with option values that take a struct timeval such as OsConstants#SO_RCVTIMEO and OsConstants#SO_SNDTIMEO. Use with other options is likely to cause incorrect behavior.

Parameters
fd FileDescriptor: This value cannot be null.
value StructTimeval: This value cannot be null.

setuid

Added in API level 21
Deprecated in API level 29
static fun setuid(uid: Int): Unit

Deprecated: Android Applications do not have sufficient privileges to call this method.

See setuid(2).

setxattr

Added in API level 26
static fun setxattr(
    path: String!,
    name: String!,
    value: ByteArray!,
    flags: Int
): Unit

See setxattr(2)

shutdown

Added in API level 21
static fun shutdown(
    fd: FileDescriptor!,
    how: Int
): Unit

See shutdown(2).

socket

Added in API level 21
static fun socket(
    domain: Int,
    type: Int,
    protocol: Int
): FileDescriptor!

See socket(2).

socketpair

Added in API level 21
static fun socketpair(
    domain: Int,
    type: Int,
    protocol: Int,
    fd1: FileDescriptor!,
    fd2: FileDescriptor!
): Unit

See socketpair(2).

stat

Added in API level 21
static fun stat(path: String!): StructStat!

See stat(2).

statvfs

Added in API level 21
static fun statvfs(path: String!): StructStatVfs!

See statvfs(2).

strerror

Added in API level 21
static fun strerror(errno: Int): String!

See strerror(2).

strsignal

Added in API level 21
static fun strsignal(signal: Int): String!

See strsignal(3).

Added in API level 21
static fun symlink(
    oldPath: String!,
    newPath: String!
): Unit

See symlink(2).

sysconf

Added in API level 21
static fun sysconf(name: Int): Long

See sysconf(3).

tcdrain

Added in API level 21
static fun tcdrain(fd: FileDescriptor!): Unit

See tcdrain(3).

tcsendbreak

Added in API level 21
static fun tcsendbreak(
    fd: FileDescriptor!,
    duration: Int
): Unit

See tcsendbreak(3).

umask

Added in API level 21
static fun umask(mask: Int): Int

See umask(2).

uname

Added in API level 21
static fun uname(): StructUtsname!

See uname(2).

unsetenv

Added in API level 21
static fun unsetenv(name: String!): Unit

See unsetenv(3).

write

Added in API level 21
static fun write(
    fd: FileDescriptor!,
    buffer: ByteBuffer!
): Int

See write(2).

write

Added in API level 21
static fun write(
    fd: FileDescriptor!,
    bytes: ByteArray!,
    byteOffset: Int,
    byteCount: Int
): Int

See write(2).

writev

Added in API level 21
static fun writev(
    fd: FileDescriptor!,
    buffers: Array<Any!>!,
    offsets: IntArray!,
    byteCounts: IntArray!
): Int

See writev(2).