Process
open class Process
kotlin.Any | |
↳ | android.os.Process |
Tools for managing OS processes.
Summary
Constants | |
---|---|
static Int |
Defines the UID/GID for the Bluetooth service process. |
static Int |
Defines the start of a range of UIDs (and GIDs), going from this number to |
static Int |
An invalid PID value. |
static Int |
An invalid UID value. |
static Int |
Last of application-specific UIDs starting at |
static Int |
Defines the UID/GID under which the telephony code runs. |
static Int |
Defines the root UID. |
static Int |
Defines the UID/GID for the user shell. |
static Int | |
static Int | |
static Int | |
static Int |
Defines the UID/GID under which system code runs. |
static Int |
Standard priority of audio threads. |
static Int |
Standard priority background threads. |
static Int |
Standard priority of application threads. |
static Int |
Standard priority of system display threads, involved in updating the user interface. |
static Int |
Standard priority of threads that are currently running a user interface that the user is interacting with. |
static Int |
Minimum increment to make a priority less favorable. |
static Int |
Lowest available thread priority. |
static Int |
Minimum increment to make a priority more favorable. |
static Int |
Standard priority of the most important audio threads. |
static Int |
Standard priority of the most important display threads, for compositing the screen and retrieving input events. |
static Int |
Standard priority of video threads. |
static Int |
Defines the UID/GID for the WIFI native processes like wificond, supplicant, hostapd, vendor HAL, etc. |
Public constructors | |
---|---|
Process() |
Public methods | |
---|---|
static Int |
getAppUidForSdkSandboxUid(uid: Int) Returns the app uid corresponding to an sdk sandbox uid. |
static Long |
Returns elapsed milliseconds of the time this process has run. |
static IntArray! |
On some devices, the foreground process may have one or more CPU cores exclusively reserved for it. |
static Int |
getGidForName(name: String!) Returns the GID assigned to a particular user name, or -1 if there is none. |
static Int |
getSdkSandboxUidForAppUid(uid: Int) Returns the sdk sandbox uid corresponding to an app uid. |
open static Long |
Return the |
open static Long |
Return the |
open static Long |
Return the |
open static Long |
Return the |
static Int |
getThreadPriority(tid: Int) Return the current priority of a thread, based on Linux priorities. |
static Int |
getUidForName(name: String!) Returns the UID assigned to a particular user name, or -1 if there is none. |
static Boolean |
is64Bit() Returns true if the current process is a 64-bit runtime. |
open static Boolean |
isApplicationUid(uid: Int) Returns whether the given uid belongs to an application. |
static Boolean |
Returns whether the current process is in an isolated sandbox. |
static Boolean |
isIsolatedUid(uid: Int) Returns whether the process with the given |
static Boolean |
Returns whether the current process is a sdk sandbox process. |
static Boolean |
isSdkSandboxUid(uid: Int) Returns whether the provided UID belongs to an sdk sandbox process |
static Unit |
killProcess(pid: Int) Kill the process with the given PID. |
static Int |
myPid() Returns the identifier of this process, which can be used with |
open static String |
Return the name of this process. |
static Int |
myTid() Returns the identifier of the calling thread, which be used with |
static Int |
myUid() Returns the identifier of this process's uid. |
open static UserHandle! |
Returns this process's user handle. |
static Unit |
sendSignal(pid: Int, signal: Int) Send a signal to the given process. |
static Unit |
setThreadPriority(priority: Int) Set the priority of the calling thread, based on Linux priorities. |
static Unit |
setThreadPriority(tid: Int, priority: Int) Set the priority of a thread, based on Linux priorities. |
static Boolean |
Determine whether the current environment supports multiple processes. |
Constants
BLUETOOTH_UID
static val BLUETOOTH_UID: Int
Defines the UID/GID for the Bluetooth service process.
Value: 1002
FIRST_APPLICATION_UID
static val FIRST_APPLICATION_UID: Int
Defines the start of a range of UIDs (and GIDs), going from this number to LAST_APPLICATION_UID
that are reserved for assigning to applications.
Value: 10000
LAST_APPLICATION_UID
static val LAST_APPLICATION_UID: Int
Last of application-specific UIDs starting at FIRST_APPLICATION_UID
.
Value: 19999
PHONE_UID
static val PHONE_UID: Int
Defines the UID/GID under which the telephony code runs.
Value: 1001
SHELL_UID
static val SHELL_UID: Int
Defines the UID/GID for the user shell.
Value: 2000
SYSTEM_UID
static val SYSTEM_UID: Int
Defines the UID/GID under which system code runs.
Value: 1000
THREAD_PRIORITY_AUDIO
static val THREAD_PRIORITY_AUDIO: Int
Standard priority of audio threads. Applications can not normally change to this priority. Use with setThreadPriority(int)
and setThreadPriority(int,int)
, not with the normal java.lang.Thread
class.
Value: -16
THREAD_PRIORITY_BACKGROUND
static val THREAD_PRIORITY_BACKGROUND: Int
Standard priority background threads. This gives your thread a slightly lower than normal priority, so that it will have less chance of impacting the responsiveness of the user interface. Use with setThreadPriority(int)
and setThreadPriority(int,int)
, not with the normal java.lang.Thread
class.
Value: 10
THREAD_PRIORITY_DEFAULT
static val THREAD_PRIORITY_DEFAULT: Int
Standard priority of application threads. Use with setThreadPriority(int)
and setThreadPriority(int,int)
, not with the normal java.lang.Thread
class.
Value: 0
THREAD_PRIORITY_DISPLAY
static val THREAD_PRIORITY_DISPLAY: Int
Standard priority of system display threads, involved in updating the user interface. Applications can not normally change to this priority. Use with setThreadPriority(int)
and setThreadPriority(int,int)
, not with the normal java.lang.Thread
class.
Value: -4
THREAD_PRIORITY_FOREGROUND
static val THREAD_PRIORITY_FOREGROUND: Int
Standard priority of threads that are currently running a user interface that the user is interacting with. Applications can not normally change to this priority; the system will automatically adjust your application threads as the user moves through the UI. Use with setThreadPriority(int)
and setThreadPriority(int,int)
, not with the normal java.lang.Thread
class.
Value: -2
THREAD_PRIORITY_LESS_FAVORABLE
static val THREAD_PRIORITY_LESS_FAVORABLE: Int
Minimum increment to make a priority less favorable.
Value: 1
THREAD_PRIORITY_LOWEST
static val THREAD_PRIORITY_LOWEST: Int
Lowest available thread priority. Only for those who really, really don't want to run if anything else is happening. Use with setThreadPriority(int)
and setThreadPriority(int,int)
, not with the normal java.lang.Thread
class.
Value: 19
THREAD_PRIORITY_MORE_FAVORABLE
static val THREAD_PRIORITY_MORE_FAVORABLE: Int
Minimum increment to make a priority more favorable.
Value: -1
THREAD_PRIORITY_URGENT_AUDIO
static val THREAD_PRIORITY_URGENT_AUDIO: Int
Standard priority of the most important audio threads. Applications can not normally change to this priority. Use with setThreadPriority(int)
and setThreadPriority(int,int)
, not with the normal java.lang.Thread
class.
Value: -19
THREAD_PRIORITY_URGENT_DISPLAY
static val THREAD_PRIORITY_URGENT_DISPLAY: Int
Standard priority of the most important display threads, for compositing the screen and retrieving input events. Applications can not normally change to this priority. Use with setThreadPriority(int)
and setThreadPriority(int,int)
, not with the normal java.lang.Thread
class.
Value: -8
THREAD_PRIORITY_VIDEO
static val THREAD_PRIORITY_VIDEO: Int
Standard priority of video threads. Applications can not normally change to this priority. Use with setThreadPriority(int)
and setThreadPriority(int,int)
, not with the normal java.lang.Thread
class.
Value: -10
WIFI_UID
static val WIFI_UID: Int
Defines the UID/GID for the WIFI native processes like wificond, supplicant, hostapd, vendor HAL, etc.
Value: 1010
Public constructors
Process
Process()
Public methods
getAppUidForSdkSandboxUid
static fun getAppUidForSdkSandboxUid(uid: Int): Int
Returns the app uid corresponding to an sdk sandbox uid.
Parameters | |
---|---|
uid |
Int: the sdk sandbox uid |
Return | |
---|---|
Int |
the app uid for the given sdk sandbox uid |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if input is not an sdk sandbox uid |
getElapsedCpuTime
static fun getElapsedCpuTime(): Long
Returns elapsed milliseconds of the time this process has run.
Return | |
---|---|
Long |
Returns the number of milliseconds this process has return. |
getExclusiveCores
static fun getExclusiveCores(): IntArray!
On some devices, the foreground process may have one or more CPU cores exclusively reserved for it. This method can be used to retrieve which cores that are (if any), so the calling process can then use sched_setaffinity() to lock a thread to these cores. Note that the calling process must currently be running in the foreground for this method to return any cores. The CPU core(s) exclusively reserved for the foreground process will stay reserved for as long as the process stays in the foreground. As soon as a process leaves the foreground, those CPU cores will no longer be reserved for it, and will most likely be reserved for the new foreground process. It's not necessary to change the affinity of your process when it leaves the foreground (if you had previously set it to use a reserved core); the OS will automatically take care of resetting the affinity at that point.
Return | |
---|---|
IntArray! |
an array of integers, indicating the CPU cores exclusively reserved for this process. The array will have length zero if no CPU cores are exclusively reserved for this process at this point in time. |
getGidForName
static fun getGidForName(name: String!): Int
Returns the GID assigned to a particular user name, or -1 if there is none. If the given string consists of only numbers, it is converted directly to a gid.
getSdkSandboxUidForAppUid
static fun getSdkSandboxUidForAppUid(uid: Int): Int
Returns the sdk sandbox uid corresponding to an app uid.
Parameters | |
---|---|
uid |
Int: the app uid |
Return | |
---|---|
Int |
the sdk sandbox uid for the given app uid |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if input is not an app uid |
getStartElapsedRealtime
open static fun getStartElapsedRealtime(): Long
Return the SystemClock.elapsedRealtime()
at which this process was started, but before any of the application code was executed.
Value is a non-negative timestamp in the android.os.SystemClock#elapsedRealtime()
time base.
Return | |
---|---|
Long |
Value is a non-negative timestamp in the android.os.SystemClock#elapsedRealtime() time base. |
getStartRequestedElapsedRealtime
open static fun getStartRequestedElapsedRealtime(): Long
Return the SystemClock.elapsedRealtime()
at which the system was about to start this process. i.e. before a zygote fork.
More precisely, the system may start app processes before there's a start request, in order to reduce the process start up latency, in which case this is set when the system decides to "specialize" the process into a requested app.
Value is a non-negative timestamp in the android.os.SystemClock#elapsedRealtime()
time base.
Return | |
---|---|
Long |
Value is a non-negative timestamp in the android.os.SystemClock#elapsedRealtime() time base. |
getStartRequestedUptimeMillis
open static fun getStartRequestedUptimeMillis(): Long
Return the SystemClock.uptimeMillis()
at which the system was about to start this process. i.e. before a zygote fork.
More precisely, the system may start app processes before there's a start request, in order to reduce the process start up latency, in which case this is set when the system decides to "specialize" the process into a requested app.
Value is a non-negative timestamp in the android.os.SystemClock#uptimeMillis()
time base.
Return | |
---|---|
Long |
Value is a non-negative timestamp in the android.os.SystemClock#uptimeMillis() time base. |
getStartUptimeMillis
open static fun getStartUptimeMillis(): Long
Return the SystemClock.uptimeMillis()
at which this process was started, but before any of the application code was executed.
Value is a non-negative timestamp in the android.os.SystemClock#uptimeMillis()
time base.
Return | |
---|---|
Long |
Value is a non-negative timestamp in the android.os.SystemClock#uptimeMillis() time base. |
getThreadPriority
static fun getThreadPriority(tid: Int): Int
Return the current priority of a thread, based on Linux priorities.
Parameters | |
---|---|
tid |
Int: The identifier of the thread/process. If tid equals zero, the priority of the calling process/thread will be returned. |
Return | |
---|---|
Int |
Returns the current priority, as a Linux priority level, from -20 for highest scheduling priority to 19 for lowest scheduling priority. Value is between -20 and THREAD_PRIORITY_LOWEST inclusive |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
Throws IllegalArgumentException if tid does not exist. |
getUidForName
static fun getUidForName(name: String!): Int
Returns the UID assigned to a particular user name, or -1 if there is none. If the given string consists of only numbers, it is converted directly to a uid.
is64Bit
static fun is64Bit(): Boolean
Returns true if the current process is a 64-bit runtime.
isApplicationUid
open static fun isApplicationUid(uid: Int): Boolean
Returns whether the given uid belongs to an application.
Parameters | |
---|---|
uid |
Int: A kernel uid. |
Return | |
---|---|
Boolean |
Whether the uid corresponds to an application sandbox running in a specific user. |
isIsolated
static fun isIsolated(): Boolean
Returns whether the current process is in an isolated sandbox.
isIsolatedUid
static fun isIsolatedUid(uid: Int): Boolean
Returns whether the process with the given uid
is an isolated sandbox.
isSdkSandbox
static fun isSdkSandbox(): Boolean
Returns whether the current process is a sdk sandbox process.
isSdkSandboxUid
static fun isSdkSandboxUid(uid: Int): Boolean
Returns whether the provided UID belongs to an sdk sandbox process
killProcess
static fun killProcess(pid: Int): Unit
Kill the process with the given PID. Note that, though this API allows us to request to kill any process based on its PID, the kernel will still impose standard restrictions on which PIDs you are actually able to kill. Typically this means only the process running the caller's packages/application and any additional processes created by that app; packages sharing a common UID will also be able to kill each other's processes.
myPid
static fun myPid(): Int
Returns the identifier of this process, which can be used with killProcess
and sendSignal
.
myProcessName
open static fun myProcessName(): String
Return the name of this process. By default, the process name is the same as the app's package name, but this can be changed using android:process
.
Return | |
---|---|
String |
This value cannot be null . |
myTid
static fun myTid(): Int
Returns the identifier of the calling thread, which be used with setThreadPriority(int,int)
.
myUid
static fun myUid(): Int
Returns the identifier of this process's uid. This is the kernel uid that the process is running under, which is the identity of its app-specific sandbox. It is different from myUserHandle
in that a uid identifies a specific app sandbox in a specific user.
myUserHandle
open static fun myUserHandle(): UserHandle!
Returns this process's user handle. This is the user the process is running under. It is distinct from myUid()
in that a particular user will have multiple distinct apps running under it each with their own uid.
sendSignal
static fun sendSignal(
pid: Int,
signal: Int
): Unit
Send a signal to the given process.
Parameters | |
---|---|
pid |
Int: The pid of the target process. |
signal |
Int: The signal to send. |
setThreadPriority
static fun setThreadPriority(priority: Int): Unit
Set the priority of the calling thread, based on Linux priorities. See setThreadPriority(int,int)
for more information.
Parameters | |
---|---|
priority |
Int: A Linux priority level, from -20 for highest scheduling priority to 19 for lowest scheduling priority. Value is between -20 and THREAD_PRIORITY_LOWEST inclusive |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
Throws IllegalArgumentException if tid does not exist. |
java.lang.SecurityException |
Throws SecurityException if your process does not have permission to modify the given thread, or to use the given priority. |
See Also
setThreadPriority
static fun setThreadPriority(
tid: Int,
priority: Int
): Unit
Set the priority of a thread, based on Linux priorities.
Parameters | |
---|---|
tid |
Int: The identifier of the thread/process to change. |
priority |
Int: A Linux priority level, from -20 for highest scheduling priority to 19 for lowest scheduling priority. Value is between -20 and THREAD_PRIORITY_LOWEST inclusive |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
Throws IllegalArgumentException if tid does not exist. |
java.lang.SecurityException |
Throws SecurityException if your process does not have permission to modify the given thread, or to use the given priority. |
supportsProcesses
static funsupportsProcesses(): Boolean
Deprecated: This method always returns true. Do not use.
Determine whether the current environment supports multiple processes.
Return | |
---|---|
Boolean |
Returns true if the system can run in multiple processes, else false if everything is running in a single process. |