public class Process extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Process.ProcessStartResult
Specifies the outcome of having started a process.
|
static class |
Process.ZygoteState
State for communicating with the zygote process.
|
Modifier and Type | Field and Description |
---|---|
static int |
AUDIOSERVER_UID
Defines the UID/GID for the audioserver process.
|
static int |
BLUETOOTH_UID
Defines the UID/GID for the Bluetooth service process.
|
static int |
CAMERASERVER_UID
Defines the UID/GID for the cameraserver process
|
static int |
DRM_UID
Defines the UID/GID for the DRM process.
|
static 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. |
static int |
FIRST_ISOLATED_UID
First uid used for fully isolated sandboxed processes (with no permissions of their own)
|
static int |
FIRST_SHARED_APPLICATION_GID
First gid for applications to share resources.
|
static int |
LAST_APPLICATION_UID
Last of application-specific UIDs starting at
FIRST_APPLICATION_UID . |
static int |
LAST_ISOLATED_UID
Last uid used for fully isolated sandboxed processes (with no permissions of their own)
|
static int |
LAST_SHARED_APPLICATION_GID
Last gid for applications to share resources.
|
static int |
LOG_UID
Defines the UID/GID for the log group.
|
static int |
MEDIA_RW_GID
Defines the GID for the group that allows write access to the internal media storage.
|
static int |
MEDIA_UID
Defines the UID/GID for the mediaserver process.
|
static int |
NFC_UID
Defines the UID/GID for the NFC service process.
|
static int |
PACKAGE_INFO_GID
Access to installed package details
|
static int |
PHONE_UID
Defines the UID/GID under which the telephony code runs.
|
static int |
PROC_CHAR |
static int |
PROC_COMBINE |
static int |
PROC_OUT_FLOAT |
static int |
PROC_OUT_LONG |
static int |
PROC_OUT_STRING |
static int |
PROC_PARENS |
static int |
PROC_QUOTES |
static int |
PROC_SPACE_TERM |
static int |
PROC_TAB_TERM |
static int |
PROC_TERM_MASK |
static int |
PROC_ZERO_TERM |
static int |
ROOT_UID
Defines the root UID.
|
static int |
SCHED_BATCH
Batch scheduling policy
|
static int |
SCHED_FIFO
First-In First-Out scheduling policy
|
static int |
SCHED_IDLE
Idle scheduling policy
|
static int |
SCHED_OTHER
Default scheduling policy
|
static int |
SCHED_RESET_ON_FORK
Reset scheduler choice on fork.
|
static int |
SCHED_RR
Round-Robin scheduling policy
|
static String |
SECONDARY_ZYGOTE_SOCKET |
static int |
SHARED_RELRO_UID
Defines the UID/GID for the shared RELRO file updater process.
|
static int |
SHARED_USER_GID
Defines the gid shared by all applications running under the same profile.
|
static int |
SHELL_UID
Defines the UID/GID for the user shell.
|
static int |
SIGNAL_KILL |
static int |
SIGNAL_QUIT |
static int |
SIGNAL_USR1 |
static int |
SYSTEM_UID
Defines the UID/GID under which system code runs.
|
static int |
THREAD_GROUP_AUDIO_APP
Application audio thread group.
|
static int |
THREAD_GROUP_AUDIO_SYS
System audio thread group.
|
static int |
THREAD_GROUP_BG_NONINTERACTIVE
Background thread group - All threads in
this group are scheduled with a reduced share of the CPU.
|
static int |
THREAD_GROUP_DEFAULT
Default thread group -
has meaning with setProcessGroup() only, cannot be used with setThreadGroup().
|
static int |
THREAD_GROUP_SYSTEM
System thread group.
|
static int |
THREAD_GROUP_TOP_APP
Thread group for top foreground app.
|
static int |
THREAD_PRIORITY_AUDIO
Standard priority of audio threads.
|
static int |
THREAD_PRIORITY_BACKGROUND
Standard priority background threads.
|
static int |
THREAD_PRIORITY_DEFAULT
Standard priority of application threads.
|
static int |
THREAD_PRIORITY_DISPLAY
Standard priority of system display threads, involved in updating
the user interface.
|
static int |
THREAD_PRIORITY_FOREGROUND
Standard priority of threads that are currently running a user interface
that the user is interacting with.
|
static int |
THREAD_PRIORITY_LESS_FAVORABLE
Minimum increment to make a priority less favorable.
|
static int |
THREAD_PRIORITY_LOWEST
Lowest available thread priority.
|
static int |
THREAD_PRIORITY_MORE_FAVORABLE
Minimum increment to make a priority more favorable.
|
static int |
THREAD_PRIORITY_URGENT_AUDIO
Standard priority of the most important audio threads.
|
static int |
THREAD_PRIORITY_URGENT_DISPLAY
Standard priority of the most important display threads, for compositing
the screen and retrieving input events.
|
static int |
VPN_UID
Defines the UID/GID for the group that controls VPN services.
|
static int |
WIFI_UID
Defines the UID/GID for the WIFI supplicant process.
|
static String |
ZYGOTE_SOCKET |
Constructor and Description |
---|
Process() |
Modifier and Type | Method and Description |
---|---|
static void |
establishZygoteConnectionForAbi(String abi)
Tries to establish a connection to the zygote that handles a given
abi . |
static long |
getElapsedCpuTime()
Returns elapsed milliseconds of the time this process has run.
|
static int[] |
getExclusiveCores()
On some devices, the foreground process may have one or more CPU
cores exclusively reserved for it.
|
static long |
getFreeMemory() |
static int |
getGidForName(String name)
Returns the GID assigned to a particular user name, or -1 if there is
none.
|
static int |
getParentPid(int pid)
Returns the parent process id for a currently running process.
|
static int[] |
getPids(String path,
int[] lastArray) |
static int[] |
getPidsForCommands(String[] cmds) |
static int |
getProcessGroup(int pid)
Return the scheduling group of requested process.
|
static long |
getPss(int pid)
Gets the total Pss value for a given process, in bytes.
|
static long |
getStartElapsedRealtime()
Return the
SystemClock.elapsedRealtime() at which this process was started. |
static long |
getStartUptimeMillis()
Return the
SystemClock.uptimeMillis() at which this process was started. |
static int |
getThreadGroupLeader(int tid)
Returns the thread group leader id for a currently running thread.
|
static int |
getThreadPriority(int tid)
Return the current priority of a thread, based on Linux priorities.
|
static int |
getThreadScheduler(int tid)
Return the current scheduling policy of a thread, based on Linux.
|
static long |
getTotalMemory() |
static int |
getUidForName(String name)
Returns the UID assigned to a particular user name, or -1 if there is
none.
|
static int |
getUidForPid(int pid)
Returns a uid for a currently running process.
|
static 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 boolean |
isIsolated()
Returns whether the current process is in an isolated sandbox.
|
static boolean |
isIsolated(int uid) |
static boolean |
isThreadInProcess(int tid,
int pid)
Check to see if a thread belongs to a given process.
|
static void |
killProcess(int pid)
Kill the process with the given PID.
|
static int |
killProcessGroup(int uid,
int pid)
Kill all processes in a process group started for the given
pid.
|
static void |
killProcessQuiet(int pid) |
static int |
myPid()
Returns the identifier of this process, which can be used with
killProcess(int) and sendSignal(int, int) . |
static int |
myPpid()
Returns the identifier of this process' parent.
|
static int |
myTid()
Returns the identifier of the calling thread, which be used with
setThreadPriority(int, int) . |
static int |
myUid()
Returns the identifier of this process's uid.
|
static UserHandle |
myUserHandle()
Returns this process's user handle.
|
static boolean |
parseProcLine(byte[] buffer,
int startIndex,
int endIndex,
int[] format,
String[] outStrings,
long[] outLongs,
float[] outFloats) |
static boolean |
readProcFile(String file,
int[] format,
String[] outStrings,
long[] outLongs,
float[] outFloats) |
static void |
readProcLines(String path,
String[] reqFields,
long[] outSizes) |
static void |
removeAllProcessGroups()
Remove all process groups.
|
static void |
sendSignal(int pid,
int signal)
Send a signal to the given process.
|
static void |
sendSignalQuiet(int pid,
int signal) |
static void |
setArgV0(String text)
Change this process's argv[0] parameter.
|
static void |
setCanSelfBackground(boolean backgroundOk)
Call with 'false' to cause future calls to
setThreadPriority(int) to
throw an exception if passed a background-level thread priority. |
static int |
setGid(int uid) |
static void |
setProcessGroup(int pid,
int group)
Sets the scheduling group for a process and all child threads
|
static void |
setStartTimes(long elapsedRealtime,
long uptimeMillis) |
static boolean |
setSwappiness(int pid,
boolean is_increased)
Adjust the swappiness level for a process.
|
static void |
setThreadGroup(int tid,
int group)
Sets the scheduling group for a thread.
|
static void |
setThreadPriority(int priority)
Set the priority of the calling thread, based on Linux priorities.
|
static void |
setThreadPriority(int tid,
int priority)
Set the priority of a thread, based on Linux priorities.
|
static void |
setThreadScheduler(int tid,
int policy,
int priority)
Set the scheduling policy and priority of a thread, based on Linux.
|
static int |
setUid(int uid) |
static Process.ProcessStartResult |
start(String processClass,
String niceName,
int uid,
int gid,
int[] gids,
int debugFlags,
int mountExternal,
int targetSdkVersion,
String seInfo,
String abi,
String instructionSet,
String appDataDir,
String[] zygoteArgs)
Start a new process.
|
static boolean |
supportsProcesses()
Deprecated.
This method always returns true. Do not use.
|
public static final String ZYGOTE_SOCKET
public static final String SECONDARY_ZYGOTE_SOCKET
public static final int ROOT_UID
public static final int SYSTEM_UID
public static final int PHONE_UID
public static final int SHELL_UID
public static final int LOG_UID
public static final int WIFI_UID
public static final int MEDIA_UID
public static final int DRM_UID
public static final int VPN_UID
public static final int NFC_UID
public static final int BLUETOOTH_UID
public static final int MEDIA_RW_GID
public static final int PACKAGE_INFO_GID
public static final int SHARED_RELRO_UID
public static final int AUDIOSERVER_UID
public static final int CAMERASERVER_UID
public static final int FIRST_APPLICATION_UID
LAST_APPLICATION_UID
that are reserved for assigning
to applications.public static final int LAST_APPLICATION_UID
FIRST_APPLICATION_UID
.public static final int FIRST_ISOLATED_UID
public static final int LAST_ISOLATED_UID
public static final int SHARED_USER_GID
public static final int FIRST_SHARED_APPLICATION_GID
public static final int LAST_SHARED_APPLICATION_GID
public static final int THREAD_PRIORITY_DEFAULT
setThreadPriority(int)
and
setThreadPriority(int, int)
, not with the normal
Thread
class.public static final int THREAD_PRIORITY_LOWEST
setThreadPriority(int)
and
setThreadPriority(int, int)
, not with the normal
Thread
class.public static final int THREAD_PRIORITY_BACKGROUND
setThreadPriority(int)
and
setThreadPriority(int, int)
, not with the normal
Thread
class.public static final int THREAD_PRIORITY_FOREGROUND
setThreadPriority(int)
and
setThreadPriority(int, int)
, not with the normal
Thread
class.public static final int THREAD_PRIORITY_DISPLAY
setThreadPriority(int)
and
setThreadPriority(int, int)
, not with the normal
Thread
class.public static final int THREAD_PRIORITY_URGENT_DISPLAY
setThreadPriority(int)
and
setThreadPriority(int, int)
, not with the normal
Thread
class.public static final int THREAD_PRIORITY_AUDIO
setThreadPriority(int)
and
setThreadPriority(int, int)
, not with the normal
Thread
class.public static final int THREAD_PRIORITY_URGENT_AUDIO
setThreadPriority(int)
and
setThreadPriority(int, int)
, not with the normal
Thread
class.public static final int THREAD_PRIORITY_MORE_FAVORABLE
public static final int THREAD_PRIORITY_LESS_FAVORABLE
public static final int SCHED_OTHER
public static final int SCHED_FIFO
public static final int SCHED_RR
public static final int SCHED_BATCH
public static final int SCHED_IDLE
public static final int SCHED_RESET_ON_FORK
public static final int THREAD_GROUP_DEFAULT
public static final int THREAD_GROUP_BG_NONINTERACTIVE
public static final int THREAD_GROUP_SYSTEM
public static final int THREAD_GROUP_AUDIO_APP
public static final int THREAD_GROUP_AUDIO_SYS
public static final int THREAD_GROUP_TOP_APP
public static final int SIGNAL_QUIT
public static final int SIGNAL_KILL
public static final int SIGNAL_USR1
public static final int PROC_TERM_MASK
public static final int PROC_ZERO_TERM
public static final int PROC_SPACE_TERM
public static final int PROC_TAB_TERM
public static final int PROC_COMBINE
public static final int PROC_PARENS
public static final int PROC_QUOTES
public static final int PROC_CHAR
public static final int PROC_OUT_STRING
public static final int PROC_OUT_LONG
public static final int PROC_OUT_FLOAT
public static final Process.ProcessStartResult start(String processClass, String niceName, int uid, int gid, int[] gids, int debugFlags, int mountExternal, int targetSdkVersion, String seInfo, String abi, String instructionSet, String appDataDir, String[] zygoteArgs)
If processes are enabled, a new process is created and the static main() function of a processClass is executed there. The process will continue running after this function returns.
If processes are not enabled, a new thread in the caller's process is created and main() of processClass called there.
The niceName parameter, if not an empty string, is a custom name to give to the process instead of using processClass. This allows you to make easily identifyable processes even if you are using the same base processClass to start them.
processClass
- The class to use as the process's main entry
point.niceName
- A more readable name to use for the process.uid
- The user-id under which the process will run.gid
- The group-id under which the process will run.gids
- Additional group-ids associated with the process.debugFlags
- Additional flags.targetSdkVersion
- The target SDK version for the app.seInfo
- null-ok SELinux information for the new process.abi
- non-null the ABI this app should be started with.instructionSet
- null-ok the instruction set to use.appDataDir
- null-ok the data directory of the app.zygoteArgs
- Additional arguments to supply to the zygote process.RuntimeException
- on fatal start failure
public static void establishZygoteConnectionForAbi(String abi)
abi
. Might block and retry if the
zygote is unresponsive. This method is a no-op if a connection is already open.public static final long getElapsedCpuTime()
public static final long getStartElapsedRealtime()
SystemClock.elapsedRealtime()
at which this process was started.public static final long getStartUptimeMillis()
SystemClock.uptimeMillis()
at which this process was started.public static final void setStartTimes(long elapsedRealtime, long uptimeMillis)
public static final boolean is64Bit()
public static final int myPid()
killProcess(int)
and sendSignal(int, int)
.public static final int myPpid()
public static final int myTid()
setThreadPriority(int, int)
.public static final int myUid()
myUserHandle()
in that
a uid identifies a specific app sandbox in a specific user.public static UserHandle myUserHandle()
myUid()
in that a particular user will have multiple
distinct apps running under it each with their own uid.public static boolean isApplicationUid(int uid)
uid
- A kernel uid.public static final boolean isIsolated()
public static final boolean isIsolated(int uid)
public static final int getUidForName(String name)
public static final int getGidForName(String name)
public static final int getUidForPid(int pid)
pid
- the process idpublic static final int getParentPid(int pid)
pid
- the process idpublic static final int getThreadGroupLeader(int tid)
tid
- the thread idpublic static final void setThreadPriority(int tid, int priority) throws IllegalArgumentException, SecurityException
tid
- The identifier of the thread/process to change.priority
- A Linux priority level, from -20 for highest scheduling
priority to 19 for lowest scheduling priority.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.public static final void setCanSelfBackground(boolean backgroundOk)
setThreadPriority(int)
to
throw an exception if passed a background-level thread priority. This is only
effective if the JNI layer is built with GUARD_THREAD_PRIORITY defined to 1.public static final void setThreadGroup(int tid, int group) throws IllegalArgumentException, SecurityException
tid
- The identifier of the thread to change.group
- The target group for this thread from THREAD_GROUP_*.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.
If the thread is a thread group leader, that is it's gettid() == getpid(),
then the other threads in the same thread group are _not_ affected.
Does not set cpuset for some historical reason, just calls
libcutils::set_sched_policy().public static final void setProcessGroup(int pid, int group) throws IllegalArgumentException, SecurityException
pid
- The identifier of the process to change.group
- The target group for this process from THREAD_GROUP_*.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.
group == THREAD_GROUP_DEFAULT means to move all non-background priority
threads to the foreground scheduling group, but to leave background
priority threads alone. group == THREAD_GROUP_BG_NONINTERACTIVE moves all
threads, regardless of priority, to the background scheduling group.
group == THREAD_GROUP_FOREGROUND is not allowed.
Always sets cpusets.public static final int getProcessGroup(int pid) throws IllegalArgumentException, SecurityException
public static final int[] getExclusiveCores()
public static final void setThreadPriority(int priority) throws IllegalArgumentException, SecurityException
setThreadPriority(int, int)
for more information.priority
- A Linux priority level, from -20 for highest scheduling
priority to 19 for lowest scheduling priority.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(int, int)
public static final int getThreadPriority(int tid) throws IllegalArgumentException
tid
- The identifier of the thread/process to change.IllegalArgumentException
- Throws IllegalArgumentException if
tid does not exist.public static final int getThreadScheduler(int tid) throws IllegalArgumentException
tid
- The identifier of the thread/process to get the scheduling policy.IllegalArgumentException
- Throws IllegalArgumentException if
tid does not exist, or if priority is out of range for the policy.SecurityException
- Throws SecurityException if your process does
not have permission to modify the given thread, or to use the given
scheduling policy or priority.
public static final void setThreadScheduler(int tid, int policy, int priority) throws IllegalArgumentException
tid
- The identifier of the thread/process to change.policy
- A Linux scheduling policy such as SCHED_OTHER etc.priority
- A Linux priority level in a range appropriate for the given policy.IllegalArgumentException
- Throws IllegalArgumentException if
tid does not exist, or if priority is out of range for the policy.SecurityException
- Throws SecurityException if your process does
not have permission to modify the given thread, or to use the given
scheduling policy or priority.
@Deprecated public static final boolean supportsProcesses()
public static final boolean setSwappiness(int pid, boolean is_increased)
pid
- The process identifier to set.is_increased
- Whether swappiness should be increased or default.public static final void setArgV0(String text)
text
- The new name of this process.
public static final void killProcess(int pid)
public static final int setUid(int uid)
public static final int setGid(int uid)
public static final void sendSignal(int pid, int signal)
pid
- The pid of the target process.signal
- The signal to send.public static final void killProcessQuiet(int pid)
public static final void sendSignalQuiet(int pid, int signal)
public static final long getFreeMemory()
public static final long getTotalMemory()
public static final void readProcLines(String path, String[] reqFields, long[] outSizes)
public static final int[] getPids(String path, int[] lastArray)
public static final boolean readProcFile(String file, int[] format, String[] outStrings, long[] outLongs, float[] outFloats)
public static final boolean parseProcLine(byte[] buffer, int startIndex, int endIndex, int[] format, String[] outStrings, long[] outLongs, float[] outFloats)
public static final int[] getPidsForCommands(String[] cmds)
public static final long getPss(int pid)
pid
- the process to the Pss forpublic static final int killProcessGroup(int uid, int pid)
public static final void removeAllProcessGroups()
public static final boolean isThreadInProcess(int tid, int pid)