Process
public
class
Process
extends Object
java.lang.Object | |
↳ | android.os.Process |
Tools for managing OS processes.
Summary
Constants | |
---|---|
int |
BLUETOOTH_UID
Defines the UID/GID for the Bluetooth service process. |
int |
FIRST_APPLICATION_UID
Defines the start of a range of UIDs (and GIDs), going from this
number to |
int |
INVALID_PID
An invalid PID value. |
int |
INVALID_UID
An invalid UID value. |
int |
LAST_APPLICATION_UID
Last of application-specific UIDs starting at
|
int |
PHONE_UID
Defines the UID/GID under which the telephony code runs. |
int |
ROOT_UID
Defines the root UID. |
int |
SHELL_UID
Defines the UID/GID for the user shell. |
int |
SIGNAL_KILL
|
int |
SIGNAL_QUIT
|
int |
SIGNAL_USR1
|
int |
SYSTEM_UID
Defines the UID/GID under which system code runs. |
int |
THREAD_PRIORITY_AUDIO
Standard priority of audio threads. |
int |
THREAD_PRIORITY_BACKGROUND
Standard priority background threads. |
int |
THREAD_PRIORITY_DEFAULT
Standard priority of application threads. |
int |
THREAD_PRIORITY_DISPLAY
Standard priority of system display threads, involved in updating the user interface. |
int |
THREAD_PRIORITY_FOREGROUND
Standard priority of threads that are currently running a user interface that the user is interacting with. |
int |
THREAD_PRIORITY_LESS_FAVORABLE
Minimum increment to make a priority less favorable. |
int |
THREAD_PRIORITY_LOWEST
Lowest available thread priority. |
int |
THREAD_PRIORITY_MORE_FAVORABLE
Minimum increment to make a priority more favorable. |
int |
THREAD_PRIORITY_URGENT_AUDIO
Standard priority of the most important audio threads. |
int |
THREAD_PRIORITY_URGENT_DISPLAY
Standard priority of the most important display threads, for compositing the screen and retrieving input events. |
int |
THREAD_PRIORITY_VIDEO
Standard priority of video threads. |
int |
WIFI_UID
Defines the UID/GID for the WIFI native processes like wificond, supplicant, hostapd, vendor HAL, etc. |
Public constructors | |
---|---|
Process()
|
Public methods | |
---|---|
static
final
int
|
getAppUidForSdkSandboxUid(int uid)
Returns the app uid corresponding to an sdk sandbox uid. |
static
final
long
|
getElapsedCpuTime()
Returns elapsed milliseconds of the time this process has run. |
static
final
int[]
|
getExclusiveCores()
On some devices, the foreground process may have one or more CPU cores exclusively reserved for it. |
static
final
int
|
getGidForName(String name)
Returns the GID assigned to a particular user name, or -1 if there is none. |
static
final
int
|
getSdkSandboxUidForAppUid(int uid)
Returns the sdk sandbox uid corresponding to an app uid. |
static
long
|
getStartElapsedRealtime()
Return the |
static
long
|
getStartRequestedElapsedRealtime()
Return the |
static
long
|
getStartRequestedUptimeMillis()
Return the |
static
long
|
getStartUptimeMillis()
Return the |
static
final
int
|
getThreadPriority(int tid)
Return the current priority of a thread, based on Linux priorities. |
static
final
int
|
getUidForName(String name)
Returns the UID assigned to a particular user name, or -1 if there is none. |
static
final
boolean
|
is64Bit()
Returns true if the current process is a 64-bit runtime. |
static
boolean
|
isApplicationUid(int uid)
Returns whether the given uid belongs to an application. |
static
final
boolean
|
isIsolated()
Returns whether the current process is in an isolated sandbox. |
static
final
boolean
|
isIsolatedUid(int uid)
Returns whether the process with the given |
static
final
boolean
|
isSdkSandbox()
Returns whether the current process is a sdk sandbox process. |
static
final
boolean
|
isSdkSandboxUid(int uid)
Returns whether the provided UID belongs to an sdk sandbox process |
static
final
void
|
killProcess(int pid)
Kill the process with the given PID. |
static
final
int
|
myPid()
Returns the identifier of this process, which can be used with
|
static
String
|
myProcessName()
Return the name of this process. |
static
final
int
|
myTid()
Returns the identifier of the calling thread, which be used with
|
static
final
int
|
myUid()
Returns the identifier of this process's uid. |
static
UserHandle
|
myUserHandle()
Returns this process's user handle. |
static
final
void
|
sendSignal(int pid, int signal)
Send a signal to the given process. |
static
final
void
|
setThreadPriority(int tid, int priority)
Set the priority of a thread, based on Linux priorities. |
static
final
void
|
setThreadPriority(int priority)
Set the priority of the calling thread, based on Linux priorities. |
static
final
boolean
|
supportsProcesses()
This method was deprecated in API level 15. This method always returns true. Do not use. |
Inherited methods | |
---|---|
Constants
BLUETOOTH_UID
public static final int BLUETOOTH_UID
Defines the UID/GID for the Bluetooth service process.
Constant Value: 1002 (0x000003ea)
FIRST_APPLICATION_UID
public static final int FIRST_APPLICATION_UID
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.
Constant Value: 10000 (0x00002710)
INVALID_PID
public static final int INVALID_PID
An invalid PID value.
Constant Value: -1 (0xffffffff)
INVALID_UID
public static final int INVALID_UID
An invalid UID value.
Constant Value: -1 (0xffffffff)
LAST_APPLICATION_UID
public static final int LAST_APPLICATION_UID
Last of application-specific UIDs starting at
FIRST_APPLICATION_UID
.
Constant Value: 19999 (0x00004e1f)
PHONE_UID
public static final int PHONE_UID
Defines the UID/GID under which the telephony code runs.
Constant Value: 1001 (0x000003e9)
ROOT_UID
public static final int ROOT_UID
Defines the root UID.
Constant Value: 0 (0x00000000)
SHELL_UID
public static final int SHELL_UID
Defines the UID/GID for the user shell.
Constant Value: 2000 (0x000007d0)
SIGNAL_USR1
public static final int SIGNAL_USR1
Constant Value: 10 (0x0000000a)
SYSTEM_UID
public static final int SYSTEM_UID
Defines the UID/GID under which system code runs.
Constant Value: 1000 (0x000003e8)
THREAD_PRIORITY_AUDIO
public static final int THREAD_PRIORITY_AUDIO
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
Thread
class.
Constant Value: -16 (0xfffffff0)
THREAD_PRIORITY_BACKGROUND
public static final int THREAD_PRIORITY_BACKGROUND
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
Thread
class.
Constant Value: 10 (0x0000000a)
THREAD_PRIORITY_DEFAULT
public static final int THREAD_PRIORITY_DEFAULT
Standard priority of application threads.
Use with setThreadPriority(int)
and
setThreadPriority(int, int)
, not with the normal
Thread
class.
Constant Value: 0 (0x00000000)
THREAD_PRIORITY_DISPLAY
public static final int THREAD_PRIORITY_DISPLAY
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
Thread
class.
Constant Value: -4 (0xfffffffc)
THREAD_PRIORITY_FOREGROUND
public static final int THREAD_PRIORITY_FOREGROUND
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
Thread
class.
Constant Value: -2 (0xfffffffe)
THREAD_PRIORITY_LESS_FAVORABLE
public static final int THREAD_PRIORITY_LESS_FAVORABLE
Minimum increment to make a priority less favorable.
Constant Value: 1 (0x00000001)
THREAD_PRIORITY_LOWEST
public static final int THREAD_PRIORITY_LOWEST
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
Thread
class.
Constant Value: 19 (0x00000013)
THREAD_PRIORITY_MORE_FAVORABLE
public static final int THREAD_PRIORITY_MORE_FAVORABLE
Minimum increment to make a priority more favorable.
Constant Value: -1 (0xffffffff)
THREAD_PRIORITY_URGENT_AUDIO
public static final int THREAD_PRIORITY_URGENT_AUDIO
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
Thread
class.
Constant Value: -19 (0xffffffed)
THREAD_PRIORITY_URGENT_DISPLAY
public static final int THREAD_PRIORITY_URGENT_DISPLAY
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
Thread
class.
Constant Value: -8 (0xfffffff8)
THREAD_PRIORITY_VIDEO
public static final int THREAD_PRIORITY_VIDEO
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
Thread
class.
Constant Value: -10 (0xfffffff6)
WIFI_UID
public static final int WIFI_UID
Defines the UID/GID for the WIFI native processes like wificond, supplicant, hostapd, vendor HAL, etc.
Constant Value: 1010 (0x000003f2)
Public constructors
Process
public Process ()
Public methods
getAppUidForSdkSandboxUid
public static final int getAppUidForSdkSandboxUid (int uid)
Returns the app uid corresponding to an sdk sandbox uid.
Parameters | |
---|---|
uid |
int : the sdk sandbox uid |
Returns | |
---|---|
int |
the app uid for the given sdk sandbox uid |
Throws | |
---|---|
IllegalArgumentException |
if input is not an sdk sandbox uid |
See also:
getElapsedCpuTime
public static final long getElapsedCpuTime ()
Returns elapsed milliseconds of the time this process has run.
Returns | |
---|---|
long |
Returns the number of milliseconds this process has return. |
getExclusiveCores
public static final int[] getExclusiveCores ()
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.
Returns | |
---|---|
int[] |
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
public static final int getGidForName (String name)
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.
Parameters | |
---|---|
name |
String |
Returns | |
---|---|
int |
getSdkSandboxUidForAppUid
public static final int getSdkSandboxUidForAppUid (int uid)
Returns the sdk sandbox uid corresponding to an app uid.
Parameters | |
---|---|
uid |
int : the app uid |
Returns | |
---|---|
int |
the sdk sandbox uid for the given app uid |
Throws | |
---|---|
IllegalArgumentException |
if input is not an app uid |
See also:
getStartElapsedRealtime
public static long getStartElapsedRealtime ()
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
SystemClock.elapsedRealtime()
time base.
Returns | |
---|---|
long |
Value is a non-negative timestamp in the
SystemClock.elapsedRealtime() time base. |
getStartRequestedElapsedRealtime
public static long getStartRequestedElapsedRealtime ()
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
SystemClock.elapsedRealtime()
time base.
Returns | |
---|---|
long |
Value is a non-negative timestamp in the
SystemClock.elapsedRealtime() time base. |
getStartRequestedUptimeMillis
public static long getStartRequestedUptimeMillis ()
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
SystemClock.uptimeMillis()
time base.
Returns | |
---|---|
long |
Value is a non-negative timestamp in the
SystemClock.uptimeMillis() time base. |
getStartUptimeMillis
public static long getStartUptimeMillis ()
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
SystemClock.uptimeMillis()
time base.
Returns | |
---|---|
long |
Value is a non-negative timestamp in the
SystemClock.uptimeMillis() time base. |
getThreadPriority
public static final int getThreadPriority (int tid)
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. |
Returns | |
---|---|
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 |
Throws | |
---|---|
IllegalArgumentException |
Throws IllegalArgumentException if tid does not exist. |
getUidForName
public static final int getUidForName (String name)
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.
Parameters | |
---|---|
name |
String |
Returns | |
---|---|
int |
is64Bit
public static final boolean is64Bit ()
Returns true if the current process is a 64-bit runtime.
Returns | |
---|---|
boolean |
isApplicationUid
public static boolean isApplicationUid (int uid)
Returns whether the given uid belongs to an application.
Parameters | |
---|---|
uid |
int : A kernel uid. |
Returns | |
---|---|
boolean |
Whether the uid corresponds to an application sandbox running in a specific user. |
isIsolated
public static final boolean isIsolated ()
Returns whether the current process is in an isolated sandbox.
Returns | |
---|---|
boolean |
isIsolatedUid
public static final boolean isIsolatedUid (int uid)
Returns whether the process with the given uid
is an isolated sandbox.
Parameters | |
---|---|
uid |
int |
Returns | |
---|---|
boolean |
isSdkSandbox
public static final boolean isSdkSandbox ()
Returns whether the current process is a sdk sandbox process.
Returns | |
---|---|
boolean |
isSdkSandboxUid
public static final boolean isSdkSandboxUid (int uid)
Returns whether the provided UID belongs to an sdk sandbox process
Parameters | |
---|---|
uid |
int |
Returns | |
---|---|
boolean |
See also:
killProcess
public static final void killProcess (int pid)
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.
Parameters | |
---|---|
pid |
int |
myPid
public static final int myPid ()
Returns the identifier of this process, which can be used with
killProcess(int)
and sendSignal(int, int)
.
Returns | |
---|---|
int |
myProcessName
public static String myProcessName ()
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
.
Returns | |
---|---|
String |
This value cannot be null . |
myTid
public static final int myTid ()
Returns the identifier of the calling thread, which be used with
setThreadPriority(int, int)
.
Returns | |
---|---|
int |
myUid
public static final int myUid ()
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.
Returns | |
---|---|
int |
myUserHandle
public static UserHandle myUserHandle ()
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.
Returns | |
---|---|
UserHandle |
sendSignal
public static final void sendSignal (int pid, int signal)
Send a signal to the given process.
Parameters | |
---|---|
pid |
int : The pid of the target process. |
signal |
int : The signal to send. |
setThreadPriority
public static final void setThreadPriority (int tid, int priority)
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 |
Throws | |
---|---|
IllegalArgumentException |
Throws IllegalArgumentException if tid does not exist. |
SecurityException |
Throws SecurityException if your process does not have permission to modify the given thread, or to use the given priority. |
setThreadPriority
public static final void setThreadPriority (int priority)
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 |
Throws | |
---|---|
IllegalArgumentException |
Throws IllegalArgumentException if tid does not exist. |
SecurityException |
Throws SecurityException if your process does not have permission to modify the given thread, or to use the given priority. |
See also:
supportsProcesses
public static final boolean supportsProcesses ()
This method was deprecated
in API level 15.
This method always returns true. Do not use.
Determine whether the current environment supports multiple processes.
Returns | |
---|---|
boolean |
Returns true if the system can run in multiple processes, else false if everything is running in a single process. |