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