2 * Copyright (C) 2006 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 import android.annotation.TestApi;
20 import android.system.Os;
21 import android.system.OsConstants;
22 import android.webkit.WebViewZygote;
24 import dalvik.system.VMRuntime;
27 * Tools for managing OS processes.
29 public class Process {
30 private static final String LOG_TAG = "Process";
33 * @hide for internal use only.
35 public static final String ZYGOTE_SOCKET = "zygote";
38 * @hide for internal use only.
40 public static final String SECONDARY_ZYGOTE_SOCKET = "zygote_secondary";
43 * Defines the root UID.
46 public static final int ROOT_UID = 0;
49 * Defines the UID/GID under which system code runs.
51 public static final int SYSTEM_UID = 1000;
54 * Defines the UID/GID under which the telephony code runs.
56 public static final int PHONE_UID = 1001;
59 * Defines the UID/GID for the user shell.
62 public static final int SHELL_UID = 2000;
65 * Defines the UID/GID for the log group.
68 public static final int LOG_UID = 1007;
71 * Defines the UID/GID for the WIFI supplicant process.
74 public static final int WIFI_UID = 1010;
77 * Defines the UID/GID for the mediaserver process.
80 public static final int MEDIA_UID = 1013;
83 * Defines the UID/GID for the DRM process.
86 public static final int DRM_UID = 1019;
89 * Defines the UID/GID for the group that controls VPN services.
92 public static final int VPN_UID = 1016;
95 * Defines the UID/GID for keystore.
98 public static final int KEYSTORE_UID = 1017;
101 * Defines the UID/GID for the NFC service process.
104 public static final int NFC_UID = 1027;
107 * Defines the UID/GID for the Bluetooth service process.
110 public static final int BLUETOOTH_UID = 1002;
113 * Defines the GID for the group that allows write access to the internal media storage.
116 public static final int MEDIA_RW_GID = 1023;
119 * Access to installed package details
122 public static final int PACKAGE_INFO_GID = 1032;
125 * Defines the UID/GID for the shared RELRO file updater process.
128 public static final int SHARED_RELRO_UID = 1037;
131 * Defines the UID/GID for the audioserver process.
134 public static final int AUDIOSERVER_UID = 1041;
137 * Defines the UID/GID for the cameraserver process
140 public static final int CAMERASERVER_UID = 1047;
143 * Defines the UID/GID for the WebView zygote process.
146 public static final int WEBVIEW_ZYGOTE_UID = 1053;
149 * Defines the UID used for resource tracking for OTA updates.
152 public static final int OTA_UPDATE_UID = 1061;
155 * Defines the UID/GID for the Secure Element service process.
158 public static final int SE_UID = 1068;
161 public static final int NOBODY_UID = 9999;
164 * Defines the start of a range of UIDs (and GIDs), going from this
165 * number to {@link #LAST_APPLICATION_UID} that are reserved for assigning
168 public static final int FIRST_APPLICATION_UID = 10000;
171 * Last of application-specific UIDs starting at
172 * {@link #FIRST_APPLICATION_UID}.
174 public static final int LAST_APPLICATION_UID = 19999;
177 * First uid used for fully isolated sandboxed processes (with no permissions of their own)
180 public static final int FIRST_ISOLATED_UID = 99000;
183 * Last uid used for fully isolated sandboxed processes (with no permissions of their own)
186 public static final int LAST_ISOLATED_UID = 99999;
189 * Defines the gid shared by all applications running under the same profile.
192 public static final int SHARED_USER_GID = 9997;
195 * First gid for applications to share resources. Used when forward-locking
196 * is enabled but all UserHandles need to be able to read the resources.
199 public static final int FIRST_SHARED_APPLICATION_GID = 50000;
202 * Last gid for applications to share resources. Used when forward-locking
203 * is enabled but all UserHandles need to be able to read the resources.
206 public static final int LAST_SHARED_APPLICATION_GID = 59999;
209 public static final int FIRST_APPLICATION_CACHE_GID = 20000;
211 public static final int LAST_APPLICATION_CACHE_GID = 29999;
214 * Standard priority of application threads.
215 * Use with {@link #setThreadPriority(int)} and
216 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal
217 * {@link java.lang.Thread} class.
219 public static final int THREAD_PRIORITY_DEFAULT = 0;
222 * ***************************************
223 * ** Keep in sync with utils/threads.h **
224 * ***************************************
228 * Lowest available thread priority. Only for those who really, really
229 * don't want to run if anything else is happening.
230 * Use with {@link #setThreadPriority(int)} and
231 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal
232 * {@link java.lang.Thread} class.
234 public static final int THREAD_PRIORITY_LOWEST = 19;
237 * Standard priority background threads. This gives your thread a slightly
238 * lower than normal priority, so that it will have less chance of impacting
239 * the responsiveness of the user interface.
240 * Use with {@link #setThreadPriority(int)} and
241 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal
242 * {@link java.lang.Thread} class.
244 public static final int THREAD_PRIORITY_BACKGROUND = 10;
247 * Standard priority of threads that are currently running a user interface
248 * that the user is interacting with. Applications can not normally
249 * change to this priority; the system will automatically adjust your
250 * application threads as the user moves through the UI.
251 * Use with {@link #setThreadPriority(int)} and
252 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal
253 * {@link java.lang.Thread} class.
255 public static final int THREAD_PRIORITY_FOREGROUND = -2;
258 * Standard priority of system display threads, involved in updating
259 * the user interface. Applications can not
260 * normally change to this priority.
261 * Use with {@link #setThreadPriority(int)} and
262 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal
263 * {@link java.lang.Thread} class.
265 public static final int THREAD_PRIORITY_DISPLAY = -4;
268 * Standard priority of the most important display threads, for compositing
269 * the screen and retrieving input events. Applications can not normally
270 * change to this priority.
271 * Use with {@link #setThreadPriority(int)} and
272 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal
273 * {@link java.lang.Thread} class.
275 public static final int THREAD_PRIORITY_URGENT_DISPLAY = -8;
278 * Standard priority of audio threads. Applications can not normally
279 * change to this priority.
280 * Use with {@link #setThreadPriority(int)} and
281 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal
282 * {@link java.lang.Thread} class.
284 public static final int THREAD_PRIORITY_AUDIO = -16;
287 * Standard priority of the most important audio threads.
288 * Applications can not normally change to this priority.
289 * Use with {@link #setThreadPriority(int)} and
290 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal
291 * {@link java.lang.Thread} class.
293 public static final int THREAD_PRIORITY_URGENT_AUDIO = -19;
296 * Minimum increment to make a priority more favorable.
298 public static final int THREAD_PRIORITY_MORE_FAVORABLE = -1;
301 * Minimum increment to make a priority less favorable.
303 public static final int THREAD_PRIORITY_LESS_FAVORABLE = +1;
306 * Default scheduling policy
309 public static final int SCHED_OTHER = 0;
312 * First-In First-Out scheduling policy
315 public static final int SCHED_FIFO = 1;
318 * Round-Robin scheduling policy
321 public static final int SCHED_RR = 2;
324 * Batch scheduling policy
327 public static final int SCHED_BATCH = 3;
330 * Idle scheduling policy
333 public static final int SCHED_IDLE = 5;
336 * Reset scheduler choice on fork.
339 public static final int SCHED_RESET_ON_FORK = 0x40000000;
341 // Keep in sync with SP_* constants of enum type SchedPolicy
342 // declared in system/core/include/cutils/sched_policy.h,
343 // except THREAD_GROUP_DEFAULT does not correspond to any SP_* value.
346 * Default thread group -
347 * has meaning with setProcessGroup() only, cannot be used with setThreadGroup().
348 * When used with setProcessGroup(), the group of each thread in the process
349 * is conditionally changed based on that thread's current priority, as follows:
350 * threads with priority numerically less than THREAD_PRIORITY_BACKGROUND
351 * are moved to foreground thread group. All other threads are left unchanged.
354 public static final int THREAD_GROUP_DEFAULT = -1;
357 * Background thread group - All threads in
358 * this group are scheduled with a reduced share of the CPU.
359 * Value is same as constant SP_BACKGROUND of enum SchedPolicy.
360 * FIXME rename to THREAD_GROUP_BACKGROUND.
363 public static final int THREAD_GROUP_BG_NONINTERACTIVE = 0;
366 * Foreground thread group - All threads in
367 * this group are scheduled with a normal share of the CPU.
368 * Value is same as constant SP_FOREGROUND of enum SchedPolicy.
369 * Not used at this level.
372 private static final int THREAD_GROUP_FOREGROUND = 1;
375 * System thread group.
378 public static final int THREAD_GROUP_SYSTEM = 2;
381 * Application audio thread group.
384 public static final int THREAD_GROUP_AUDIO_APP = 3;
387 * System audio thread group.
390 public static final int THREAD_GROUP_AUDIO_SYS = 4;
393 * Thread group for top foreground app.
396 public static final int THREAD_GROUP_TOP_APP = 5;
399 * Thread group for RT app.
402 public static final int THREAD_GROUP_RT_APP = 6;
404 public static final int SIGNAL_QUIT = 3;
405 public static final int SIGNAL_KILL = 9;
406 public static final int SIGNAL_USR1 = 10;
408 private static long sStartElapsedRealtime;
409 private static long sStartUptimeMillis;
412 * State associated with the zygote process.
415 public static final ZygoteProcess zygoteProcess =
416 new ZygoteProcess(ZYGOTE_SOCKET, SECONDARY_ZYGOTE_SOCKET);
419 * Start a new process.
421 * <p>If processes are enabled, a new process is created and the
422 * static main() function of a <var>processClass</var> is executed there.
423 * The process will continue running after this function returns.
425 * <p>If processes are not enabled, a new thread in the caller's
426 * process is created and main() of <var>processClass</var> called there.
428 * <p>The niceName parameter, if not an empty string, is a custom name to
429 * give to the process instead of using processClass. This allows you to
430 * make easily identifyable processes even if you are using the same base
431 * <var>processClass</var> to start them.
433 * When invokeWith is not null, the process will be started as a fresh app
434 * and not a zygote fork. Note that this is only allowed for uid 0 or when
435 * runtimeFlags contains DEBUG_ENABLE_DEBUGGER.
437 * @param processClass The class to use as the process's main entry
439 * @param niceName A more readable name to use for the process.
440 * @param uid The user-id under which the process will run.
441 * @param gid The group-id under which the process will run.
442 * @param gids Additional group-ids associated with the process.
443 * @param runtimeFlags Additional flags for the runtime.
444 * @param targetSdkVersion The target SDK version for the app.
445 * @param seInfo null-ok SELinux information for the new process.
446 * @param abi non-null the ABI this app should be started with.
447 * @param instructionSet null-ok the instruction set to use.
448 * @param appDataDir null-ok the data directory of the app.
449 * @param invokeWith null-ok the command to invoke with.
450 * @param zygoteArgs Additional arguments to supply to the zygote process.
452 * @return An object that describes the result of the attempt to start the process.
453 * @throws RuntimeException on fatal start failure
457 public static final ProcessStartResult start(final String processClass,
458 final String niceName,
459 int uid, int gid, int[] gids,
460 int runtimeFlags, int mountExternal,
461 int targetSdkVersion,
464 String instructionSet,
467 String[] zygoteArgs) {
468 return zygoteProcess.start(processClass, niceName, uid, gid, gids,
469 runtimeFlags, mountExternal, targetSdkVersion, seInfo,
470 abi, instructionSet, appDataDir, invokeWith, zygoteArgs);
474 public static final ProcessStartResult startWebView(final String processClass,
475 final String niceName,
476 int uid, int gid, int[] gids,
477 int runtimeFlags, int mountExternal,
478 int targetSdkVersion,
481 String instructionSet,
484 String[] zygoteArgs) {
485 return WebViewZygote.getProcess().start(processClass, niceName, uid, gid, gids,
486 runtimeFlags, mountExternal, targetSdkVersion, seInfo,
487 abi, instructionSet, appDataDir, invokeWith, zygoteArgs);
491 * Returns elapsed milliseconds of the time this process has run.
492 * @return Returns the number of milliseconds this process has return.
494 public static final native long getElapsedCpuTime();
497 * Return the {@link SystemClock#elapsedRealtime()} at which this process was started.
499 public static final long getStartElapsedRealtime() {
500 return sStartElapsedRealtime;
504 * Return the {@link SystemClock#uptimeMillis()} at which this process was started.
506 public static final long getStartUptimeMillis() {
507 return sStartUptimeMillis;
511 public static final void setStartTimes(long elapsedRealtime, long uptimeMillis) {
512 sStartElapsedRealtime = elapsedRealtime;
513 sStartUptimeMillis = uptimeMillis;
517 * Returns true if the current process is a 64-bit runtime.
519 public static final boolean is64Bit() {
520 return VMRuntime.getRuntime().is64Bit();
524 * Returns the identifier of this process, which can be used with
525 * {@link #killProcess} and {@link #sendSignal}.
527 public static final int myPid() {
532 * Returns the identifier of this process' parent.
535 public static final int myPpid() {
540 * Returns the identifier of the calling thread, which be used with
541 * {@link #setThreadPriority(int, int)}.
543 public static final int myTid() {
548 * Returns the identifier of this process's uid. This is the kernel uid
549 * that the process is running under, which is the identity of its
550 * app-specific sandbox. It is different from {@link #myUserHandle} in that
551 * a uid identifies a specific app sandbox in a specific user.
553 public static final int myUid() {
558 * Returns this process's user handle. This is the
559 * user the process is running under. It is distinct from
560 * {@link #myUid()} in that a particular user will have multiple
561 * distinct apps running under it each with their own uid.
563 public static UserHandle myUserHandle() {
564 return UserHandle.of(UserHandle.getUserId(myUid()));
568 * Returns whether the given uid belongs to an application.
569 * @param uid A kernel uid.
570 * @return Whether the uid corresponds to an application sandbox running in
573 public static boolean isApplicationUid(int uid) {
574 return UserHandle.isApp(uid);
578 * Returns whether the current process is in an isolated sandbox.
581 public static final boolean isIsolated() {
582 return isIsolated(myUid());
586 public static final boolean isIsolated(int uid) {
587 uid = UserHandle.getAppId(uid);
588 return uid >= FIRST_ISOLATED_UID && uid <= LAST_ISOLATED_UID;
592 * Returns the UID assigned to a particular user name, or -1 if there is
593 * none. If the given string consists of only numbers, it is converted
596 public static final native int getUidForName(String name);
599 * Returns the GID assigned to a particular user name, or -1 if there is
600 * none. If the given string consists of only numbers, it is converted
603 public static final native int getGidForName(String name);
606 * Returns a uid for a currently running process.
607 * @param pid the process id
608 * @return the uid of the process, or -1 if the process is not running.
609 * @hide pending API council review
611 public static final int getUidForPid(int pid) {
612 String[] procStatusLabels = { "Uid:" };
613 long[] procStatusValues = new long[1];
614 procStatusValues[0] = -1;
615 Process.readProcLines("/proc/" + pid + "/status", procStatusLabels, procStatusValues);
616 return (int) procStatusValues[0];
620 * Returns the parent process id for a currently running process.
621 * @param pid the process id
622 * @return the parent process id of the process, or -1 if the process is not running.
625 public static final int getParentPid(int pid) {
626 String[] procStatusLabels = { "PPid:" };
627 long[] procStatusValues = new long[1];
628 procStatusValues[0] = -1;
629 Process.readProcLines("/proc/" + pid + "/status", procStatusLabels, procStatusValues);
630 return (int) procStatusValues[0];
634 * Returns the thread group leader id for a currently running thread.
635 * @param tid the thread id
636 * @return the thread group leader id of the thread, or -1 if the thread is not running.
637 * This is same as what getpid(2) would return if called by tid.
640 public static final int getThreadGroupLeader(int tid) {
641 String[] procStatusLabels = { "Tgid:" };
642 long[] procStatusValues = new long[1];
643 procStatusValues[0] = -1;
644 Process.readProcLines("/proc/" + tid + "/status", procStatusLabels, procStatusValues);
645 return (int) procStatusValues[0];
649 * Set the priority of a thread, based on Linux priorities.
651 * @param tid The identifier of the thread/process to change.
652 * @param priority A Linux priority level, from -20 for highest scheduling
653 * priority to 19 for lowest scheduling priority.
655 * @throws IllegalArgumentException Throws IllegalArgumentException if
656 * <var>tid</var> does not exist.
657 * @throws SecurityException Throws SecurityException if your process does
658 * not have permission to modify the given thread, or to use the given
661 public static final native void setThreadPriority(int tid, int priority)
662 throws IllegalArgumentException, SecurityException;
665 * Call with 'false' to cause future calls to {@link #setThreadPriority(int)} to
666 * throw an exception if passed a background-level thread priority. This is only
667 * effective if the JNI layer is built with GUARD_THREAD_PRIORITY defined to 1.
671 public static final native void setCanSelfBackground(boolean backgroundOk);
674 * Sets the scheduling group for a thread.
676 * @param tid The identifier of the thread to change.
677 * @param group The target group for this thread from THREAD_GROUP_*.
679 * @throws IllegalArgumentException Throws IllegalArgumentException if
680 * <var>tid</var> does not exist.
681 * @throws SecurityException Throws SecurityException if your process does
682 * not have permission to modify the given thread, or to use the given
684 * If the thread is a thread group leader, that is it's gettid() == getpid(),
685 * then the other threads in the same thread group are _not_ affected.
687 * Does not set cpuset for some historical reason, just calls
688 * libcutils::set_sched_policy().
690 public static final native void setThreadGroup(int tid, int group)
691 throws IllegalArgumentException, SecurityException;
694 * Sets the scheduling group and the corresponding cpuset group
696 * @param tid The identifier of the thread to change.
697 * @param group The target group for this thread from THREAD_GROUP_*.
699 * @throws IllegalArgumentException Throws IllegalArgumentException if
700 * <var>tid</var> does not exist.
701 * @throws SecurityException Throws SecurityException if your process does
702 * not have permission to modify the given thread, or to use the given
705 public static final native void setThreadGroupAndCpuset(int tid, int group)
706 throws IllegalArgumentException, SecurityException;
709 * Sets the scheduling group for a process and all child threads
711 * @param pid The identifier of the process to change.
712 * @param group The target group for this process from THREAD_GROUP_*.
714 * @throws IllegalArgumentException Throws IllegalArgumentException if
715 * <var>tid</var> does not exist.
716 * @throws SecurityException Throws SecurityException if your process does
717 * not have permission to modify the given thread, or to use the given
720 * group == THREAD_GROUP_DEFAULT means to move all non-background priority
721 * threads to the foreground scheduling group, but to leave background
722 * priority threads alone. group == THREAD_GROUP_BG_NONINTERACTIVE moves all
723 * threads, regardless of priority, to the background scheduling group.
724 * group == THREAD_GROUP_FOREGROUND is not allowed.
726 * Always sets cpusets.
728 public static final native void setProcessGroup(int pid, int group)
729 throws IllegalArgumentException, SecurityException;
732 * Return the scheduling group of requested process.
736 public static final native int getProcessGroup(int pid)
737 throws IllegalArgumentException, SecurityException;
740 * On some devices, the foreground process may have one or more CPU
741 * cores exclusively reserved for it. This method can be used to
742 * retrieve which cores that are (if any), so the calling process
743 * can then use sched_setaffinity() to lock a thread to these cores.
744 * Note that the calling process must currently be running in the
745 * foreground for this method to return any cores.
747 * The CPU core(s) exclusively reserved for the foreground process will
748 * stay reserved for as long as the process stays in the foreground.
750 * As soon as a process leaves the foreground, those CPU cores will
751 * no longer be reserved for it, and will most likely be reserved for
752 * the new foreground process. It's not necessary to change the affinity
753 * of your process when it leaves the foreground (if you had previously
754 * set it to use a reserved core); the OS will automatically take care
755 * of resetting the affinity at that point.
757 * @return an array of integers, indicating the CPU cores exclusively
758 * reserved for this process. The array will have length zero if no
759 * CPU cores are exclusively reserved for this process at this point
762 public static final native int[] getExclusiveCores();
765 * Set the priority of the calling thread, based on Linux priorities. See
766 * {@link #setThreadPriority(int, int)} for more information.
768 * @param priority A Linux priority level, from -20 for highest scheduling
769 * priority to 19 for lowest scheduling priority.
771 * @throws IllegalArgumentException Throws IllegalArgumentException if
772 * <var>tid</var> does not exist.
773 * @throws SecurityException Throws SecurityException if your process does
774 * not have permission to modify the given thread, or to use the given
777 * @see #setThreadPriority(int, int)
779 public static final native void setThreadPriority(int priority)
780 throws IllegalArgumentException, SecurityException;
783 * Return the current priority of a thread, based on Linux priorities.
785 * @param tid The identifier of the thread/process. If tid equals zero, the priority of the
786 * calling process/thread will be returned.
788 * @return Returns the current priority, as a Linux priority level,
789 * from -20 for highest scheduling priority to 19 for lowest scheduling
792 * @throws IllegalArgumentException Throws IllegalArgumentException if
793 * <var>tid</var> does not exist.
795 public static final native int getThreadPriority(int tid)
796 throws IllegalArgumentException;
799 * Return the current scheduling policy of a thread, based on Linux.
801 * @param tid The identifier of the thread/process to get the scheduling policy.
803 * @throws IllegalArgumentException Throws IllegalArgumentException if
804 * <var>tid</var> does not exist, or if <var>priority</var> is out of range for the policy.
805 * @throws SecurityException Throws SecurityException if your process does
806 * not have permission to modify the given thread, or to use the given
807 * scheduling policy or priority.
813 public static final native int getThreadScheduler(int tid)
814 throws IllegalArgumentException;
817 * Set the scheduling policy and priority of a thread, based on Linux.
819 * @param tid The identifier of the thread/process to change.
820 * @param policy A Linux scheduling policy such as SCHED_OTHER etc.
821 * @param priority A Linux priority level in a range appropriate for the given policy.
823 * @throws IllegalArgumentException Throws IllegalArgumentException if
824 * <var>tid</var> does not exist, or if <var>priority</var> is out of range for the policy.
825 * @throws SecurityException Throws SecurityException if your process does
826 * not have permission to modify the given thread, or to use the given
827 * scheduling policy or priority.
832 public static final native void setThreadScheduler(int tid, int policy, int priority)
833 throws IllegalArgumentException;
836 * Determine whether the current environment supports multiple processes.
838 * @return Returns true if the system can run in multiple processes, else
839 * false if everything is running in a single process.
841 * @deprecated This method always returns true. Do not use.
844 public static final boolean supportsProcesses() {
849 * Adjust the swappiness level for a process.
851 * @param pid The process identifier to set.
852 * @param is_increased Whether swappiness should be increased or default.
854 * @return Returns true if the underlying system supports this
855 * feature, else false.
859 public static final native boolean setSwappiness(int pid, boolean is_increased);
862 * Change this process's argv[0] parameter. This can be useful to show
863 * more descriptive information in things like the 'ps' command.
865 * @param text The new name of this process.
869 public static final native void setArgV0(String text);
872 * Kill the process with the given PID.
873 * Note that, though this API allows us to request to
874 * kill any process based on its PID, the kernel will
875 * still impose standard restrictions on which PIDs you
876 * are actually able to kill. Typically this means only
877 * the process running the caller's packages/application
878 * and any additional processes created by that app; packages
879 * sharing a common UID will also be able to kill each
882 public static final void killProcess(int pid) {
883 sendSignal(pid, SIGNAL_KILL);
887 public static final native int setUid(int uid);
890 public static final native int setGid(int uid);
893 * Send a signal to the given process.
895 * @param pid The pid of the target process.
896 * @param signal The signal to send.
898 public static final native void sendSignal(int pid, int signal);
902 * Private impl for avoiding a log message... DO NOT USE without doing
903 * your own log, or the Android Illuminati will find you some night and
906 public static final void killProcessQuiet(int pid) {
907 sendSignalQuiet(pid, SIGNAL_KILL);
912 * Private impl for avoiding a log message... DO NOT USE without doing
913 * your own log, or the Android Illuminati will find you some night and
916 public static final native void sendSignalQuiet(int pid, int signal);
919 public static final native long getFreeMemory();
922 public static final native long getTotalMemory();
925 public static final native void readProcLines(String path,
926 String[] reqFields, long[] outSizes);
929 public static final native int[] getPids(String path, int[] lastArray);
932 public static final int PROC_TERM_MASK = 0xff;
934 public static final int PROC_ZERO_TERM = 0;
936 public static final int PROC_SPACE_TERM = (int)' ';
938 public static final int PROC_TAB_TERM = (int)'\t';
940 public static final int PROC_COMBINE = 0x100;
942 public static final int PROC_PARENS = 0x200;
944 public static final int PROC_QUOTES = 0x400;
946 public static final int PROC_CHAR = 0x800;
948 public static final int PROC_OUT_STRING = 0x1000;
950 public static final int PROC_OUT_LONG = 0x2000;
952 public static final int PROC_OUT_FLOAT = 0x4000;
955 public static final native boolean readProcFile(String file, int[] format,
956 String[] outStrings, long[] outLongs, float[] outFloats);
959 public static final native boolean parseProcLine(byte[] buffer, int startIndex,
960 int endIndex, int[] format, String[] outStrings, long[] outLongs, float[] outFloats);
963 public static final native int[] getPidsForCommands(String[] cmds);
966 * Gets the total Pss value for a given process, in bytes.
968 * @param pid the process to the Pss for
969 * @return the total Pss value for the given process in bytes,
970 * or -1 if the value cannot be determined
973 public static final native long getPss(int pid);
976 * Specifies the outcome of having started a process.
979 public static final class ProcessStartResult {
981 * The PID of the newly started process.
982 * Always >= 0. (If the start failed, an exception will have been thrown instead.)
987 * True if the process was started with a wrapper attached.
989 public boolean usingWrapper;
993 * Kill all processes in a process group started for the given
997 public static final native int killProcessGroup(int uid, int pid);
1000 * Remove all process groups. Expected to be called when ActivityManager
1004 public static final native void removeAllProcessGroups();
1007 * Check to see if a thread belongs to a given process. This may require
1008 * more permissions than apps generally have.
1009 * @return true if this thread belongs to a process
1012 public static final boolean isThreadInProcess(int tid, int pid) {
1013 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
1015 if (Os.access("/proc/" + tid + "/task/" + pid, OsConstants.F_OK)) {
1020 } catch (Exception e) {
1023 StrictMode.setThreadPolicy(oldPolicy);