Process.java revision 10e89712863f5b91a2982dc1783fbdfe39c1485d
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 = 1025; 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 debugFlags Additional flags. 270 * @param targetSdkVersion The target SDK version for the app. 271 * @param zygoteArgs Additional arguments to supply to the zygote process. 272 * 273 * @return int If > 0 the pid of the new process; if 0 the process is 274 * being emulated by a thread 275 * @throws RuntimeException on fatal start failure 276 * 277 * {@hide} 278 */ 279 public static final int start(final String processClass, 280 final String niceName, 281 int uid, int gid, int[] gids, 282 int debugFlags, int targetSdkVersion, 283 String[] zygoteArgs) { 284 try { 285 return startViaZygote(processClass, niceName, uid, gid, gids, 286 debugFlags, targetSdkVersion, zygoteArgs); 287 } catch (ZygoteStartFailedEx ex) { 288 Log.e(LOG_TAG, 289 "Starting VM process through Zygote failed"); 290 throw new RuntimeException( 291 "Starting VM process through Zygote failed", ex); 292 } 293 } 294 295 /** retry interval for opening a zygote socket */ 296 static final int ZYGOTE_RETRY_MILLIS = 500; 297 298 /** 299 * Tries to open socket to Zygote process if not already open. If 300 * already open, does nothing. May block and retry. 301 */ 302 private static void openZygoteSocketIfNeeded() 303 throws ZygoteStartFailedEx { 304 305 int retryCount; 306 307 if (sPreviousZygoteOpenFailed) { 308 /* 309 * If we've failed before, expect that we'll fail again and 310 * don't pause for retries. 311 */ 312 retryCount = 0; 313 } else { 314 retryCount = 10; 315 } 316 317 /* 318 * See bug #811181: Sometimes runtime can make it up before zygote. 319 * Really, we'd like to do something better to avoid this condition, 320 * but for now just wait a bit... 321 */ 322 for (int retry = 0 323 ; (sZygoteSocket == null) && (retry < (retryCount + 1)) 324 ; retry++ ) { 325 326 if (retry > 0) { 327 try { 328 Log.i("Zygote", "Zygote not up yet, sleeping..."); 329 Thread.sleep(ZYGOTE_RETRY_MILLIS); 330 } catch (InterruptedException ex) { 331 // should never happen 332 } 333 } 334 335 try { 336 sZygoteSocket = new LocalSocket(); 337 338 sZygoteSocket.connect(new LocalSocketAddress(ZYGOTE_SOCKET, 339 LocalSocketAddress.Namespace.RESERVED)); 340 341 sZygoteInputStream 342 = new DataInputStream(sZygoteSocket.getInputStream()); 343 344 sZygoteWriter = 345 new BufferedWriter( 346 new OutputStreamWriter( 347 sZygoteSocket.getOutputStream()), 348 256); 349 350 Log.i("Zygote", "Process: zygote socket opened"); 351 352 sPreviousZygoteOpenFailed = false; 353 break; 354 } catch (IOException ex) { 355 if (sZygoteSocket != null) { 356 try { 357 sZygoteSocket.close(); 358 } catch (IOException ex2) { 359 Log.e(LOG_TAG,"I/O exception on close after exception", 360 ex2); 361 } 362 } 363 364 sZygoteSocket = null; 365 } 366 } 367 368 if (sZygoteSocket == null) { 369 sPreviousZygoteOpenFailed = true; 370 throw new ZygoteStartFailedEx("connect failed"); 371 } 372 } 373 374 /** 375 * Sends an argument list to the zygote process, which starts a new child 376 * and returns the child's pid. Please note: the present implementation 377 * replaces newlines in the argument list with spaces. 378 * @param args argument list 379 * @return PID of new child process 380 * @throws ZygoteStartFailedEx if process start failed for any reason 381 */ 382 private static int zygoteSendArgsAndGetPid(ArrayList<String> args) 383 throws ZygoteStartFailedEx { 384 385 int pid; 386 387 openZygoteSocketIfNeeded(); 388 389 try { 390 /** 391 * See com.android.internal.os.ZygoteInit.readArgumentList() 392 * Presently the wire format to the zygote process is: 393 * a) a count of arguments (argc, in essence) 394 * b) a number of newline-separated argument strings equal to count 395 * 396 * After the zygote process reads these it will write the pid of 397 * the child or -1 on failure. 398 */ 399 400 sZygoteWriter.write(Integer.toString(args.size())); 401 sZygoteWriter.newLine(); 402 403 int sz = args.size(); 404 for (int i = 0; i < sz; i++) { 405 String arg = args.get(i); 406 if (arg.indexOf('\n') >= 0) { 407 throw new ZygoteStartFailedEx( 408 "embedded newlines not allowed"); 409 } 410 sZygoteWriter.write(arg); 411 sZygoteWriter.newLine(); 412 } 413 414 sZygoteWriter.flush(); 415 416 // Should there be a timeout on this? 417 pid = sZygoteInputStream.readInt(); 418 419 if (pid < 0) { 420 throw new ZygoteStartFailedEx("fork() failed"); 421 } 422 } catch (IOException ex) { 423 try { 424 if (sZygoteSocket != null) { 425 sZygoteSocket.close(); 426 } 427 } catch (IOException ex2) { 428 // we're going to fail anyway 429 Log.e(LOG_TAG,"I/O exception on routine close", ex2); 430 } 431 432 sZygoteSocket = null; 433 434 throw new ZygoteStartFailedEx(ex); 435 } 436 437 return pid; 438 } 439 440 /** 441 * Starts a new process via the zygote mechanism. 442 * 443 * @param processClass Class name whose static main() to run 444 * @param niceName 'nice' process name to appear in ps 445 * @param uid a POSIX uid that the new process should setuid() to 446 * @param gid a POSIX gid that the new process shuold setgid() to 447 * @param gids null-ok; a list of supplementary group IDs that the 448 * new process should setgroup() to. 449 * @param debugFlags Additional flags. 450 * @param targetSdkVersion The target SDK version for the app. 451 * @param extraArgs Additional arguments to supply to the zygote process. 452 * @return PID 453 * @throws ZygoteStartFailedEx if process start failed for any reason 454 */ 455 private static int startViaZygote(final String processClass, 456 final String niceName, 457 final int uid, final int gid, 458 final int[] gids, 459 int debugFlags, int targetSdkVersion, 460 String[] extraArgs) 461 throws ZygoteStartFailedEx { 462 int pid; 463 464 synchronized(Process.class) { 465 ArrayList<String> argsForZygote = new ArrayList<String>(); 466 467 // --runtime-init, --setuid=, --setgid=, 468 // and --setgroups= must go first 469 argsForZygote.add("--runtime-init"); 470 argsForZygote.add("--setuid=" + uid); 471 argsForZygote.add("--setgid=" + gid); 472 if ((debugFlags & Zygote.DEBUG_ENABLE_JNI_LOGGING) != 0) { 473 argsForZygote.add("--enable-jni-logging"); 474 } 475 if ((debugFlags & Zygote.DEBUG_ENABLE_SAFEMODE) != 0) { 476 argsForZygote.add("--enable-safemode"); 477 } 478 if ((debugFlags & Zygote.DEBUG_ENABLE_DEBUGGER) != 0) { 479 argsForZygote.add("--enable-debugger"); 480 } 481 if ((debugFlags & Zygote.DEBUG_ENABLE_CHECKJNI) != 0) { 482 argsForZygote.add("--enable-checkjni"); 483 } 484 if ((debugFlags & Zygote.DEBUG_ENABLE_ASSERT) != 0) { 485 argsForZygote.add("--enable-assert"); 486 } 487 argsForZygote.add("--target-sdk-version=" + targetSdkVersion); 488 489 //TODO optionally enable debuger 490 //argsForZygote.add("--enable-debugger"); 491 492 // --setgroups is a comma-separated list 493 if (gids != null && gids.length > 0) { 494 StringBuilder sb = new StringBuilder(); 495 sb.append("--setgroups="); 496 497 int sz = gids.length; 498 for (int i = 0; i < sz; i++) { 499 if (i != 0) { 500 sb.append(','); 501 } 502 sb.append(gids[i]); 503 } 504 505 argsForZygote.add(sb.toString()); 506 } 507 508 if (niceName != null) { 509 argsForZygote.add("--nice-name=" + niceName); 510 } 511 512 argsForZygote.add(processClass); 513 514 if (extraArgs != null) { 515 for (String arg : extraArgs) { 516 argsForZygote.add(arg); 517 } 518 } 519 520 pid = zygoteSendArgsAndGetPid(argsForZygote); 521 } 522 523 if (pid <= 0) { 524 throw new ZygoteStartFailedEx("zygote start failed:" + pid); 525 } 526 527 return pid; 528 } 529 530 /** 531 * Returns elapsed milliseconds of the time this process has run. 532 * @return Returns the number of milliseconds this process has return. 533 */ 534 public static final native long getElapsedCpuTime(); 535 536 /** 537 * Returns the identifier of this process, which can be used with 538 * {@link #killProcess} and {@link #sendSignal}. 539 */ 540 public static final native int myPid(); 541 542 /** 543 * Returns the identifier of the calling thread, which be used with 544 * {@link #setThreadPriority(int, int)}. 545 */ 546 public static final native int myTid(); 547 548 /** 549 * Returns the identifier of this process's user. 550 */ 551 public static final native int myUid(); 552 553 /** 554 * Returns the UID assigned to a particular user name, or -1 if there is 555 * none. If the given string consists of only numbers, it is converted 556 * directly to a uid. 557 */ 558 public static final native int getUidForName(String name); 559 560 /** 561 * Returns the GID assigned to a particular user name, or -1 if there is 562 * none. If the given string consists of only numbers, it is converted 563 * directly to a gid. 564 */ 565 public static final native int getGidForName(String name); 566 567 /** 568 * Returns a uid for a currently running process. 569 * @param pid the process id 570 * @return the uid of the process, or -1 if the process is not running. 571 * @hide pending API council review 572 */ 573 public static final int getUidForPid(int pid) { 574 String[] procStatusLabels = { "Uid:" }; 575 long[] procStatusValues = new long[1]; 576 procStatusValues[0] = -1; 577 Process.readProcLines("/proc/" + pid + "/status", procStatusLabels, procStatusValues); 578 return (int) procStatusValues[0]; 579 } 580 581 /** 582 * Returns the parent process id for a currently running process. 583 * @param pid the process id 584 * @return the parent process id of the process, or -1 if the process is not running. 585 * @hide 586 */ 587 public static final int getParentPid(int pid) { 588 String[] procStatusLabels = { "PPid:" }; 589 long[] procStatusValues = new long[1]; 590 procStatusValues[0] = -1; 591 Process.readProcLines("/proc/" + pid + "/status", procStatusLabels, procStatusValues); 592 return (int) procStatusValues[0]; 593 } 594 595 /** 596 * Set the priority of a thread, based on Linux priorities. 597 * 598 * @param tid The identifier of the thread/process to change. 599 * @param priority A Linux priority level, from -20 for highest scheduling 600 * priority to 19 for lowest scheduling priority. 601 * 602 * @throws IllegalArgumentException Throws IllegalArgumentException if 603 * <var>tid</var> does not exist. 604 * @throws SecurityException Throws SecurityException if your process does 605 * not have permission to modify the given thread, or to use the given 606 * priority. 607 */ 608 public static final native void setThreadPriority(int tid, int priority) 609 throws IllegalArgumentException, SecurityException; 610 611 /** 612 * Call with 'false' to cause future calls to {@link #setThreadPriority(int)} to 613 * throw an exception if passed a background-level thread priority. This is only 614 * effective if the JNI layer is built with GUARD_THREAD_PRIORITY defined to 1. 615 * 616 * @hide 617 */ 618 public static final native void setCanSelfBackground(boolean backgroundOk); 619 620 /** 621 * Sets the scheduling group for a thread. 622 * @hide 623 * @param tid The indentifier of the thread/process to change. 624 * @param group The target group for this thread/process. 625 * 626 * @throws IllegalArgumentException Throws IllegalArgumentException if 627 * <var>tid</var> does not exist. 628 * @throws SecurityException Throws SecurityException if your process does 629 * not have permission to modify the given thread, or to use the given 630 * priority. 631 */ 632 public static final native void setThreadGroup(int tid, int group) 633 throws IllegalArgumentException, SecurityException; 634 /** 635 * Sets the scheduling group for a process and all child threads 636 * @hide 637 * @param pid The indentifier of the process to change. 638 * @param group The target group for this process. 639 * 640 * @throws IllegalArgumentException Throws IllegalArgumentException if 641 * <var>tid</var> does not exist. 642 * @throws SecurityException Throws SecurityException if your process does 643 * not have permission to modify the given thread, or to use the given 644 * priority. 645 */ 646 public static final native void setProcessGroup(int pid, int group) 647 throws IllegalArgumentException, SecurityException; 648 649 /** 650 * Set the priority of the calling thread, based on Linux priorities. See 651 * {@link #setThreadPriority(int, int)} for more information. 652 * 653 * @param priority A Linux priority level, from -20 for highest scheduling 654 * priority to 19 for lowest scheduling priority. 655 * 656 * @throws IllegalArgumentException Throws IllegalArgumentException if 657 * <var>tid</var> does not exist. 658 * @throws SecurityException Throws SecurityException if your process does 659 * not have permission to modify the given thread, or to use the given 660 * priority. 661 * 662 * @see #setThreadPriority(int, int) 663 */ 664 public static final native void setThreadPriority(int priority) 665 throws IllegalArgumentException, SecurityException; 666 667 /** 668 * Return the current priority of a thread, based on Linux priorities. 669 * 670 * @param tid The identifier of the thread/process to change. 671 * 672 * @return Returns the current priority, as a Linux priority level, 673 * from -20 for highest scheduling priority to 19 for lowest scheduling 674 * priority. 675 * 676 * @throws IllegalArgumentException Throws IllegalArgumentException if 677 * <var>tid</var> does not exist. 678 */ 679 public static final native int getThreadPriority(int tid) 680 throws IllegalArgumentException; 681 682 /** 683 * Determine whether the current environment supports multiple processes. 684 * 685 * @return Returns true if the system can run in multiple processes, else 686 * false if everything is running in a single process. 687 * 688 * @deprecated This method always returns true. Do not use. 689 */ 690 @Deprecated 691 public static final boolean supportsProcesses() { 692 return true; 693 } 694 695 /** 696 * Set the out-of-memory badness adjustment for a process. 697 * 698 * @param pid The process identifier to set. 699 * @param amt Adjustment value -- linux allows -16 to +15. 700 * 701 * @return Returns true if the underlying system supports this 702 * feature, else false. 703 * 704 * {@hide} 705 */ 706 public static final native boolean setOomAdj(int pid, int amt); 707 708 /** 709 * Change this process's argv[0] parameter. This can be useful to show 710 * more descriptive information in things like the 'ps' command. 711 * 712 * @param text The new name of this process. 713 * 714 * {@hide} 715 */ 716 public static final native void setArgV0(String text); 717 718 /** 719 * Kill the process with the given PID. 720 * Note that, though this API allows us to request to 721 * kill any process based on its PID, the kernel will 722 * still impose standard restrictions on which PIDs you 723 * are actually able to kill. Typically this means only 724 * the process running the caller's packages/application 725 * and any additional processes created by that app; packages 726 * sharing a common UID will also be able to kill each 727 * other's processes. 728 */ 729 public static final void killProcess(int pid) { 730 sendSignal(pid, SIGNAL_KILL); 731 } 732 733 /** @hide */ 734 public static final native int setUid(int uid); 735 736 /** @hide */ 737 public static final native int setGid(int uid); 738 739 /** 740 * Send a signal to the given process. 741 * 742 * @param pid The pid of the target process. 743 * @param signal The signal to send. 744 */ 745 public static final native void sendSignal(int pid, int signal); 746 747 /** 748 * @hide 749 * Private impl for avoiding a log message... DO NOT USE without doing 750 * your own log, or the Android Illuminati will find you some night and 751 * beat you up. 752 */ 753 public static final void killProcessQuiet(int pid) { 754 sendSignalQuiet(pid, SIGNAL_KILL); 755 } 756 757 /** 758 * @hide 759 * Private impl for avoiding a log message... DO NOT USE without doing 760 * your own log, or the Android Illuminati will find you some night and 761 * beat you up. 762 */ 763 public static final native void sendSignalQuiet(int pid, int signal); 764 765 /** @hide */ 766 public static final native long getFreeMemory(); 767 768 /** @hide */ 769 public static final native void readProcLines(String path, 770 String[] reqFields, long[] outSizes); 771 772 /** @hide */ 773 public static final native int[] getPids(String path, int[] lastArray); 774 775 /** @hide */ 776 public static final int PROC_TERM_MASK = 0xff; 777 /** @hide */ 778 public static final int PROC_ZERO_TERM = 0; 779 /** @hide */ 780 public static final int PROC_SPACE_TERM = (int)' '; 781 /** @hide */ 782 public static final int PROC_TAB_TERM = (int)'\t'; 783 /** @hide */ 784 public static final int PROC_COMBINE = 0x100; 785 /** @hide */ 786 public static final int PROC_PARENS = 0x200; 787 /** @hide */ 788 public static final int PROC_OUT_STRING = 0x1000; 789 /** @hide */ 790 public static final int PROC_OUT_LONG = 0x2000; 791 /** @hide */ 792 public static final int PROC_OUT_FLOAT = 0x4000; 793 794 /** @hide */ 795 public static final native boolean readProcFile(String file, int[] format, 796 String[] outStrings, long[] outLongs, float[] outFloats); 797 798 /** @hide */ 799 public static final native boolean parseProcLine(byte[] buffer, int startIndex, 800 int endIndex, int[] format, String[] outStrings, long[] outLongs, float[] outFloats); 801 802 /** 803 * Gets the total Pss value for a given process, in bytes. 804 * 805 * @param pid the process to the Pss for 806 * @return the total Pss value for the given process in bytes, 807 * or -1 if the value cannot be determined 808 * @hide 809 */ 810 public static final native long getPss(int pid); 811} 812