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