blob: 980cff39801ff7fd176550474fdcc455d84922b5 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17package android.os;
18
19import android.net.LocalSocketAddress;
20import android.net.LocalSocket;
21import android.util.Log;
22import dalvik.system.Zygote;
23
24import java.io.BufferedWriter;
25import java.io.DataInputStream;
26import java.io.IOException;
27import java.io.OutputStreamWriter;
28import java.util.ArrayList;
29
30/*package*/ class ZygoteStartFailedEx extends Exception {
31 /**
32 * Something prevented the zygote process startup from happening normally
33 */
34
35 ZygoteStartFailedEx() {};
36 ZygoteStartFailedEx(String s) {super(s);}
37 ZygoteStartFailedEx(Throwable cause) {super(cause);}
38}
39
40/**
41 * Tools for managing OS processes.
42 */
43public class Process {
44 private static final String LOG_TAG = "Process";
45
46 private static final String ZYGOTE_SOCKET = "zygote";
47
48 /**
49 * Name of a process for running the platform's media services.
50 * {@hide}
51 */
52 public static final String ANDROID_SHARED_MEDIA = "com.android.process.media";
53
54 /**
55 * Name of the process that Google content providers can share.
56 * {@hide}
57 */
58 public static final String GOOGLE_SHARED_APP_CONTENT = "com.google.process.content";
59
60 /**
61 * Defines the UID/GID under which system code runs.
62 */
63 public static final int SYSTEM_UID = 1000;
64
65 /**
66 * Defines the UID/GID under which the telephony code runs.
67 */
68 public static final int PHONE_UID = 1001;
69
70 /**
Dianne Hackborn854060af2009-07-09 18:14:31 -070071 * Defines the UID/GID for the user shell.
72 * @hide
73 */
74 public static final int SHELL_UID = 2000;
75
76 /**
Amith Yamasanid1582142009-07-08 20:04:55 -070077 * Defines the UID/GID for the WIFI supplicant process.
78 * @hide
79 */
80 public static final int WIFI_UID = 1010;
81
82 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 * Defines the start of a range of UIDs (and GIDs), going from this
84 * number to {@link #LAST_APPLICATION_UID} that are reserved for assigning
85 * to applications.
86 */
87 public static final int FIRST_APPLICATION_UID = 10000;
88 /**
89 * Last of application-specific UIDs starting at
90 * {@link #FIRST_APPLICATION_UID}.
91 */
92 public static final int LAST_APPLICATION_UID = 99999;
93
94 /**
95 * Defines a secondary group id for access to the bluetooth hardware.
96 */
97 public static final int BLUETOOTH_GID = 2000;
98
99 /**
100 * Standard priority of application threads.
101 * Use with {@link #setThreadPriority(int)} and
102 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal
103 * {@link java.lang.Thread} class.
104 */
105 public static final int THREAD_PRIORITY_DEFAULT = 0;
106
107 /*
108 * ***************************************
109 * ** Keep in sync with utils/threads.h **
110 * ***************************************
111 */
112
113 /**
114 * Lowest available thread priority. Only for those who really, really
115 * don't want to run if anything else is happening.
116 * Use with {@link #setThreadPriority(int)} and
117 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal
118 * {@link java.lang.Thread} class.
119 */
120 public static final int THREAD_PRIORITY_LOWEST = 19;
121
122 /**
123 * Standard priority background threads. This gives your thread a slightly
124 * lower than normal priority, so that it will have less chance of impacting
125 * the responsiveness of the user interface.
126 * Use with {@link #setThreadPriority(int)} and
127 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal
128 * {@link java.lang.Thread} class.
129 */
130 public static final int THREAD_PRIORITY_BACKGROUND = 10;
131
132 /**
133 * Standard priority of threads that are currently running a user interface
134 * that the user is interacting with. Applications can not normally
135 * change to this priority; the system will automatically adjust your
136 * application threads as the user moves through the UI.
137 * Use with {@link #setThreadPriority(int)} and
138 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal
139 * {@link java.lang.Thread} class.
140 */
141 public static final int THREAD_PRIORITY_FOREGROUND = -2;
142
143 /**
144 * Standard priority of system display threads, involved in updating
145 * the user interface. Applications can not
146 * normally change to this priority.
147 * Use with {@link #setThreadPriority(int)} and
148 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal
149 * {@link java.lang.Thread} class.
150 */
151 public static final int THREAD_PRIORITY_DISPLAY = -4;
152
153 /**
154 * Standard priority of the most important display threads, for compositing
155 * the screen and retrieving input events. Applications can not normally
156 * change to this priority.
157 * Use with {@link #setThreadPriority(int)} and
158 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal
159 * {@link java.lang.Thread} class.
160 */
161 public static final int THREAD_PRIORITY_URGENT_DISPLAY = -8;
162
163 /**
164 * Standard priority of audio threads. Applications can not normally
165 * change to this priority.
166 * Use with {@link #setThreadPriority(int)} and
167 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal
168 * {@link java.lang.Thread} class.
169 */
170 public static final int THREAD_PRIORITY_AUDIO = -16;
171
172 /**
173 * Standard priority of the most important audio threads.
174 * Applications can not normally change to this priority.
175 * Use with {@link #setThreadPriority(int)} and
176 * {@link #setThreadPriority(int, int)}, <b>not</b> with the normal
177 * {@link java.lang.Thread} class.
178 */
179 public static final int THREAD_PRIORITY_URGENT_AUDIO = -19;
180
181 /**
182 * Minimum increment to make a priority more favorable.
183 */
184 public static final int THREAD_PRIORITY_MORE_FAVORABLE = -1;
185
186 /**
187 * Minimum increment to make a priority less favorable.
188 */
189 public static final int THREAD_PRIORITY_LESS_FAVORABLE = +1;
190
San Mehate9d376b2009-04-21 14:06:36 -0700191 /**
192 * Default thread group - gets a 'normal' share of the CPU
193 * @hide
194 */
195 public static final int THREAD_GROUP_DEFAULT = 0;
196
197 /**
198 * Background non-interactive thread group - All threads in
199 * this group are scheduled with a reduced share of the CPU.
200 * @hide
201 */
202 public static final int THREAD_GROUP_BG_NONINTERACTIVE = 1;
203
204 /**
205 * Foreground 'boost' thread group - All threads in
206 * this group are scheduled with an increased share of the CPU
207 * @hide
208 **/
209 public static final int THREAD_GROUP_FG_BOOST = 2;
210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 public static final int SIGNAL_QUIT = 3;
212 public static final int SIGNAL_KILL = 9;
213 public static final int SIGNAL_USR1 = 10;
214
215 // State for communicating with zygote process
216
217 static LocalSocket sZygoteSocket;
218 static DataInputStream sZygoteInputStream;
219 static BufferedWriter sZygoteWriter;
220
221 /** true if previous zygote open failed */
222 static boolean sPreviousZygoteOpenFailed;
223
224 /**
225 * Start a new process.
226 *
227 * <p>If processes are enabled, a new process is created and the
228 * static main() function of a <var>processClass</var> is executed there.
229 * The process will continue running after this function returns.
230 *
231 * <p>If processes are not enabled, a new thread in the caller's
232 * process is created and main() of <var>processClass</var> called there.
233 *
234 * <p>The niceName parameter, if not an empty string, is a custom name to
235 * give to the process instead of using processClass. This allows you to
236 * make easily identifyable processes even if you are using the same base
237 * <var>processClass</var> to start them.
238 *
239 * @param processClass The class to use as the process's main entry
240 * point.
241 * @param niceName A more readable name to use for the process.
242 * @param uid The user-id under which the process will run.
243 * @param gid The group-id under which the process will run.
244 * @param gids Additional group-ids associated with the process.
245 * @param enableDebugger True if debugging should be enabled for this process.
246 * @param zygoteArgs Additional arguments to supply to the zygote process.
247 *
248 * @return int If > 0 the pid of the new process; if 0 the process is
249 * being emulated by a thread
250 * @throws RuntimeException on fatal start failure
251 *
252 * {@hide}
253 */
254 public static final int start(final String processClass,
255 final String niceName,
256 int uid, int gid, int[] gids,
257 int debugFlags,
258 String[] zygoteArgs)
259 {
260 if (supportsProcesses()) {
261 try {
262 return startViaZygote(processClass, niceName, uid, gid, gids,
263 debugFlags, zygoteArgs);
264 } catch (ZygoteStartFailedEx ex) {
265 Log.e(LOG_TAG,
266 "Starting VM process through Zygote failed");
267 throw new RuntimeException(
268 "Starting VM process through Zygote failed", ex);
269 }
270 } else {
271 // Running in single-process mode
272
273 Runnable runnable = new Runnable() {
274 public void run() {
275 Process.invokeStaticMain(processClass);
276 }
277 };
278
279 // Thread constructors must not be called with null names (see spec).
280 if (niceName != null) {
281 new Thread(runnable, niceName).start();
282 } else {
283 new Thread(runnable).start();
284 }
285
286 return 0;
287 }
288 }
289
290 /**
291 * Start a new process. Don't supply a custom nice name.
292 * {@hide}
293 */
294 public static final int start(String processClass, int uid, int gid,
295 int[] gids, int debugFlags, String[] zygoteArgs) {
296 return start(processClass, "", uid, gid, gids,
297 debugFlags, zygoteArgs);
298 }
299
300 private static void invokeStaticMain(String className) {
301 Class cl;
302 Object args[] = new Object[1];
303
304 args[0] = new String[0]; //this is argv
305
306 try {
307 cl = Class.forName(className);
308 cl.getMethod("main", new Class[] { String[].class })
309 .invoke(null, args);
310 } catch (Exception ex) {
311 // can be: ClassNotFoundException,
312 // NoSuchMethodException, SecurityException,
313 // IllegalAccessException, IllegalArgumentException
314 // InvocationTargetException
315 // or uncaught exception from main()
316
317 Log.e(LOG_TAG, "Exception invoking static main on "
318 + className, ex);
319
320 throw new RuntimeException(ex);
321 }
322
323 }
324
325 /** retry interval for opening a zygote socket */
326 static final int ZYGOTE_RETRY_MILLIS = 500;
327
328 /**
329 * Tries to open socket to Zygote process if not already open. If
330 * already open, does nothing. May block and retry.
331 */
332 private static void openZygoteSocketIfNeeded()
333 throws ZygoteStartFailedEx {
334
335 int retryCount;
336
337 if (sPreviousZygoteOpenFailed) {
338 /*
339 * If we've failed before, expect that we'll fail again and
340 * don't pause for retries.
341 */
342 retryCount = 0;
343 } else {
344 retryCount = 10;
345 }
346
347 /*
348 * See bug #811181: Sometimes runtime can make it up before zygote.
349 * Really, we'd like to do something better to avoid this condition,
350 * but for now just wait a bit...
351 */
352 for (int retry = 0
353 ; (sZygoteSocket == null) && (retry < (retryCount + 1))
354 ; retry++ ) {
355
356 if (retry > 0) {
357 try {
358 Log.i("Zygote", "Zygote not up yet, sleeping...");
359 Thread.sleep(ZYGOTE_RETRY_MILLIS);
360 } catch (InterruptedException ex) {
361 // should never happen
362 }
363 }
364
365 try {
366 sZygoteSocket = new LocalSocket();
367
368 sZygoteSocket.connect(new LocalSocketAddress(ZYGOTE_SOCKET,
369 LocalSocketAddress.Namespace.RESERVED));
370
371 sZygoteInputStream
372 = new DataInputStream(sZygoteSocket.getInputStream());
373
374 sZygoteWriter =
375 new BufferedWriter(
376 new OutputStreamWriter(
377 sZygoteSocket.getOutputStream()),
378 256);
379
380 Log.i("Zygote", "Process: zygote socket opened");
381
382 sPreviousZygoteOpenFailed = false;
383 break;
384 } catch (IOException ex) {
385 if (sZygoteSocket != null) {
386 try {
387 sZygoteSocket.close();
388 } catch (IOException ex2) {
389 Log.e(LOG_TAG,"I/O exception on close after exception",
390 ex2);
391 }
392 }
393
394 sZygoteSocket = null;
395 }
396 }
397
398 if (sZygoteSocket == null) {
399 sPreviousZygoteOpenFailed = true;
400 throw new ZygoteStartFailedEx("connect failed");
401 }
402 }
403
404 /**
405 * Sends an argument list to the zygote process, which starts a new child
406 * and returns the child's pid. Please note: the present implementation
407 * replaces newlines in the argument list with spaces.
408 * @param args argument list
409 * @return PID of new child process
410 * @throws ZygoteStartFailedEx if process start failed for any reason
411 */
412 private static int zygoteSendArgsAndGetPid(ArrayList<String> args)
413 throws ZygoteStartFailedEx {
414
415 int pid;
416
417 openZygoteSocketIfNeeded();
418
419 try {
420 /**
421 * See com.android.internal.os.ZygoteInit.readArgumentList()
422 * Presently the wire format to the zygote process is:
423 * a) a count of arguments (argc, in essence)
424 * b) a number of newline-separated argument strings equal to count
425 *
426 * After the zygote process reads these it will write the pid of
427 * the child or -1 on failure.
428 */
429
430 sZygoteWriter.write(Integer.toString(args.size()));
431 sZygoteWriter.newLine();
432
433 int sz = args.size();
434 for (int i = 0; i < sz; i++) {
435 String arg = args.get(i);
436 if (arg.indexOf('\n') >= 0) {
437 throw new ZygoteStartFailedEx(
438 "embedded newlines not allowed");
439 }
440 sZygoteWriter.write(arg);
441 sZygoteWriter.newLine();
442 }
443
444 sZygoteWriter.flush();
445
446 // Should there be a timeout on this?
447 pid = sZygoteInputStream.readInt();
448
449 if (pid < 0) {
450 throw new ZygoteStartFailedEx("fork() failed");
451 }
452 } catch (IOException ex) {
453 try {
454 if (sZygoteSocket != null) {
455 sZygoteSocket.close();
456 }
457 } catch (IOException ex2) {
458 // we're going to fail anyway
459 Log.e(LOG_TAG,"I/O exception on routine close", ex2);
460 }
461
462 sZygoteSocket = null;
463
464 throw new ZygoteStartFailedEx(ex);
465 }
466
467 return pid;
468 }
469
470 /**
471 * Starts a new process via the zygote mechanism.
472 *
473 * @param processClass Class name whose static main() to run
474 * @param niceName 'nice' process name to appear in ps
475 * @param uid a POSIX uid that the new process should setuid() to
476 * @param gid a POSIX gid that the new process shuold setgid() to
477 * @param gids null-ok; a list of supplementary group IDs that the
478 * new process should setgroup() to.
479 * @param enableDebugger True if debugging should be enabled for this process.
480 * @param extraArgs Additional arguments to supply to the zygote process.
481 * @return PID
482 * @throws ZygoteStartFailedEx if process start failed for any reason
483 */
484 private static int startViaZygote(final String processClass,
485 final String niceName,
486 final int uid, final int gid,
487 final int[] gids,
488 int debugFlags,
489 String[] extraArgs)
490 throws ZygoteStartFailedEx {
491 int pid;
492
493 synchronized(Process.class) {
494 ArrayList<String> argsForZygote = new ArrayList<String>();
495
496 // --runtime-init, --setuid=, --setgid=,
497 // and --setgroups= must go first
498 argsForZygote.add("--runtime-init");
499 argsForZygote.add("--setuid=" + uid);
500 argsForZygote.add("--setgid=" + gid);
501 if ((debugFlags & Zygote.DEBUG_ENABLE_DEBUGGER) != 0) {
502 argsForZygote.add("--enable-debugger");
503 }
504 if ((debugFlags & Zygote.DEBUG_ENABLE_CHECKJNI) != 0) {
505 argsForZygote.add("--enable-checkjni");
506 }
507 if ((debugFlags & Zygote.DEBUG_ENABLE_ASSERT) != 0) {
508 argsForZygote.add("--enable-assert");
509 }
510
511 //TODO optionally enable debuger
512 //argsForZygote.add("--enable-debugger");
513
514 // --setgroups is a comma-separated list
515 if (gids != null && gids.length > 0) {
516 StringBuilder sb = new StringBuilder();
517 sb.append("--setgroups=");
518
519 int sz = gids.length;
520 for (int i = 0; i < sz; i++) {
521 if (i != 0) {
522 sb.append(',');
523 }
524 sb.append(gids[i]);
525 }
526
527 argsForZygote.add(sb.toString());
528 }
529
530 if (niceName != null) {
531 argsForZygote.add("--nice-name=" + niceName);
532 }
533
534 argsForZygote.add(processClass);
535
536 if (extraArgs != null) {
537 for (String arg : extraArgs) {
538 argsForZygote.add(arg);
539 }
540 }
541
542 pid = zygoteSendArgsAndGetPid(argsForZygote);
543 }
544
545 if (pid <= 0) {
546 throw new ZygoteStartFailedEx("zygote start failed:" + pid);
547 }
548
549 return pid;
550 }
551
552 /**
553 * Returns elapsed milliseconds of the time this process has run.
554 * @return Returns the number of milliseconds this process has return.
555 */
556 public static final native long getElapsedCpuTime();
557
558 /**
559 * Returns the identifier of this process, which can be used with
560 * {@link #killProcess} and {@link #sendSignal}.
561 */
562 public static final native int myPid();
563
564 /**
565 * Returns the identifier of the calling thread, which be used with
566 * {@link #setThreadPriority(int, int)}.
567 */
568 public static final native int myTid();
569
570 /**
571 * Returns the identifier of this process's user.
572 */
573 public static final native int myUid();
574
575 /**
576 * Returns the UID assigned to a particular user name, or -1 if there is
577 * none. If the given string consists of only numbers, it is converted
578 * directly to a uid.
579 */
580 public static final native int getUidForName(String name);
581
582 /**
583 * Returns the GID assigned to a particular user name, or -1 if there is
584 * none. If the given string consists of only numbers, it is converted
585 * directly to a gid.
586 */
587 public static final native int getGidForName(String name);
Amith Yamasani819f9282009-06-24 23:18:15 -0700588
589 /**
590 * Returns a uid for a currently running process.
591 * @param pid the process id
592 * @return the uid of the process, or -1 if the process is not running.
593 * @hide pending API council review
594 */
595 public static final int getUidForPid(int pid) {
596 String[] procStatusLabels = { "Uid:" };
597 long[] procStatusValues = new long[1];
598 procStatusValues[0] = -1;
599 Process.readProcLines("/proc/" + pid + "/status", procStatusLabels, procStatusValues);
600 return (int) procStatusValues[0];
601 }
602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 /**
604 * Set the priority of a thread, based on Linux priorities.
605 *
606 * @param tid The identifier of the thread/process to change.
607 * @param priority A Linux priority level, from -20 for highest scheduling
608 * priority to 19 for lowest scheduling priority.
609 *
610 * @throws IllegalArgumentException Throws IllegalArgumentException if
611 * <var>tid</var> does not exist.
612 * @throws SecurityException Throws SecurityException if your process does
613 * not have permission to modify the given thread, or to use the given
614 * priority.
615 */
616 public static final native void setThreadPriority(int tid, int priority)
617 throws IllegalArgumentException, SecurityException;
San Mehate9d376b2009-04-21 14:06:36 -0700618
619 /**
620 * Sets the scheduling group for a thread.
621 * @hide
622 * @param tid The indentifier of the thread/process to change.
623 * @param group The target group for this thread/process.
624 *
625 * @throws IllegalArgumentException Throws IllegalArgumentException if
626 * <var>tid</var> does not exist.
627 * @throws SecurityException Throws SecurityException if your process does
628 * not have permission to modify the given thread, or to use the given
629 * priority.
630 */
631 public static final native void setThreadGroup(int tid, int group)
632 throws IllegalArgumentException, SecurityException;
San Mehat3e458242009-05-19 14:44:16 -0700633 /**
634 * Sets the scheduling group for a process and all child threads
635 * @hide
636 * @param pid The indentifier of the process to change.
637 * @param group The target group for this process.
638 *
639 * @throws IllegalArgumentException Throws IllegalArgumentException if
640 * <var>tid</var> does not exist.
641 * @throws SecurityException Throws SecurityException if your process does
642 * not have permission to modify the given thread, or to use the given
643 * priority.
644 */
645 public static final native void setProcessGroup(int pid, int group)
646 throws IllegalArgumentException, SecurityException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647
648 /**
649 * Set the priority of the calling thread, based on Linux priorities. See
650 * {@link #setThreadPriority(int, int)} for more information.
651 *
652 * @param priority A Linux priority level, from -20 for highest scheduling
653 * priority to 19 for lowest scheduling priority.
654 *
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
659 * priority.
660 *
661 * @see #setThreadPriority(int, int)
662 */
663 public static final native void setThreadPriority(int priority)
664 throws IllegalArgumentException, SecurityException;
665
666 /**
667 * Return the current priority of a thread, based on Linux priorities.
668 *
669 * @param tid The identifier of the thread/process to change.
670 *
671 * @return Returns the current priority, as a Linux priority level,
672 * from -20 for highest scheduling priority to 19 for lowest scheduling
673 * priority.
674 *
675 * @throws IllegalArgumentException Throws IllegalArgumentException if
676 * <var>tid</var> does not exist.
677 */
678 public static final native int getThreadPriority(int tid)
679 throws IllegalArgumentException;
680
681 /**
682 * Determine whether the current environment supports multiple processes.
683 *
684 * @return Returns true if the system can run in multiple processes, else
685 * false if everything is running in a single process.
686 */
687 public static final native boolean supportsProcesses();
688
689 /**
690 * Set the out-of-memory badness adjustment for a process.
691 *
692 * @param pid The process identifier to set.
693 * @param amt Adjustment value -- linux allows -16 to +15.
694 *
695 * @return Returns true if the underlying system supports this
696 * feature, else false.
697 *
698 * {@hide}
699 */
700 public static final native boolean setOomAdj(int pid, int amt);
701
702 /**
703 * Change this process's argv[0] parameter. This can be useful to show
704 * more descriptive information in things like the 'ps' command.
705 *
706 * @param text The new name of this process.
707 *
708 * {@hide}
709 */
710 public static final native void setArgV0(String text);
711
712 /**
713 * Kill the process with the given PID.
714 * Note that, though this API allows us to request to
715 * kill any process based on its PID, the kernel will
716 * still impose standard restrictions on which PIDs you
717 * are actually able to kill. Typically this means only
718 * the process running the caller's packages/application
719 * and any additional processes created by that app; packages
720 * sharing a common UID will also be able to kill each
721 * other's processes.
722 */
723 public static final void killProcess(int pid) {
724 sendSignal(pid, SIGNAL_KILL);
725 }
726
727 /** @hide */
728 public static final native int setUid(int uid);
729
730 /** @hide */
731 public static final native int setGid(int uid);
732
733 /**
734 * Send a signal to the given process.
735 *
736 * @param pid The pid of the target process.
737 * @param signal The signal to send.
738 */
739 public static final native void sendSignal(int pid, int signal);
740
741 /** @hide */
Marco Nelissen0bca96b2009-07-17 12:59:25 -0700742 public static final native long getFreeMemory();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743
744 /** @hide */
745 public static final native void readProcLines(String path,
746 String[] reqFields, long[] outSizes);
747
748 /** @hide */
749 public static final native int[] getPids(String path, int[] lastArray);
750
751 /** @hide */
752 public static final int PROC_TERM_MASK = 0xff;
753 /** @hide */
754 public static final int PROC_ZERO_TERM = 0;
755 /** @hide */
756 public static final int PROC_SPACE_TERM = (int)' ';
757 /** @hide */
Evan Millarc64edde2009-04-18 12:26:32 -0700758 public static final int PROC_TAB_TERM = (int)'\t';
759 /** @hide */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 public static final int PROC_COMBINE = 0x100;
761 /** @hide */
762 public static final int PROC_PARENS = 0x200;
763 /** @hide */
764 public static final int PROC_OUT_STRING = 0x1000;
765 /** @hide */
766 public static final int PROC_OUT_LONG = 0x2000;
767 /** @hide */
768 public static final int PROC_OUT_FLOAT = 0x4000;
769
770 /** @hide */
771 public static final native boolean readProcFile(String file, int[] format,
772 String[] outStrings, long[] outLongs, float[] outFloats);
Evan Millarc64edde2009-04-18 12:26:32 -0700773
774 /** @hide */
775 public static final native boolean parseProcLine(byte[] buffer, int startIndex,
776 int endIndex, int[] format, String[] outStrings, long[] outLongs, float[] outFloats);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777
778 /**
779 * Gets the total Pss value for a given process, in bytes.
780 *
781 * @param pid the process to the Pss for
782 * @return the total Pss value for the given process in bytes,
783 * or -1 if the value cannot be determined
784 * @hide
785 */
786 public static final native long getPss(int pid);
787}