ActivityManager.java revision 32907cfb38bda2d3c052cf5139c5b592678fedbb
1/* 2 * Copyright (C) 2007 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.app; 18 19import android.content.ComponentName; 20import android.content.Context; 21import android.content.Intent; 22import android.content.pm.ApplicationInfo; 23import android.content.pm.ConfigurationInfo; 24import android.content.pm.IPackageDataObserver; 25import android.graphics.Bitmap; 26import android.os.Debug; 27import android.os.RemoteException; 28import android.os.Handler; 29import android.os.Parcel; 30import android.os.Parcelable; 31import android.os.SystemProperties; 32import android.text.TextUtils; 33import java.util.List; 34 35/** 36 * Interact with the overall activities running in the system. 37 */ 38public class ActivityManager { 39 private static String TAG = "ActivityManager"; 40 private static boolean DEBUG = false; 41 private static boolean localLOGV = DEBUG || android.util.Config.LOGV; 42 43 private final Context mContext; 44 private final Handler mHandler; 45 46 /*package*/ ActivityManager(Context context, Handler handler) { 47 mContext = context; 48 mHandler = handler; 49 } 50 51 /** 52 * Return the approximate per-application memory class of the current 53 * device. This gives you an idea of how hard a memory limit you should 54 * impose on your application to let the overall system work best. The 55 * returned value is in megabytes; the baseline Android memory class is 56 * 16 (which happens to be the Java heap limit of those devices); some 57 * device with more memory may return 24 or even higher numbers. 58 */ 59 public int getMemoryClass() { 60 return staticGetMemoryClass(); 61 } 62 63 /** @hide */ 64 static public int staticGetMemoryClass() { 65 // Really brain dead right now -- just take this from the configured 66 // vm heap size, and assume it is in megabytes and thus ends with "m". 67 String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m"); 68 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1)); 69 } 70 71 /** 72 * Information you can retrieve about tasks that the user has most recently 73 * started or visited. 74 */ 75 public static class RecentTaskInfo implements Parcelable { 76 /** 77 * If this task is currently running, this is the identifier for it. 78 * If it is not running, this will be -1. 79 */ 80 public int id; 81 82 /** 83 * The original Intent used to launch the task. You can use this 84 * Intent to re-launch the task (if it is no longer running) or bring 85 * the current task to the front. 86 */ 87 public Intent baseIntent; 88 89 /** 90 * If this task was started from an alias, this is the actual 91 * activity component that was initially started; the component of 92 * the baseIntent in this case is the name of the actual activity 93 * implementation that the alias referred to. Otherwise, this is null. 94 */ 95 public ComponentName origActivity; 96 97 public RecentTaskInfo() { 98 } 99 100 public int describeContents() { 101 return 0; 102 } 103 104 public void writeToParcel(Parcel dest, int flags) { 105 dest.writeInt(id); 106 if (baseIntent != null) { 107 dest.writeInt(1); 108 baseIntent.writeToParcel(dest, 0); 109 } else { 110 dest.writeInt(0); 111 } 112 ComponentName.writeToParcel(origActivity, dest); 113 } 114 115 public void readFromParcel(Parcel source) { 116 id = source.readInt(); 117 if (source.readInt() != 0) { 118 baseIntent = Intent.CREATOR.createFromParcel(source); 119 } else { 120 baseIntent = null; 121 } 122 origActivity = ComponentName.readFromParcel(source); 123 } 124 125 public static final Creator<RecentTaskInfo> CREATOR 126 = new Creator<RecentTaskInfo>() { 127 public RecentTaskInfo createFromParcel(Parcel source) { 128 return new RecentTaskInfo(source); 129 } 130 public RecentTaskInfo[] newArray(int size) { 131 return new RecentTaskInfo[size]; 132 } 133 }; 134 135 private RecentTaskInfo(Parcel source) { 136 readFromParcel(source); 137 } 138 } 139 140 /** 141 * Flag for use with {@link #getRecentTasks}: return all tasks, even those 142 * that have set their 143 * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag. 144 */ 145 public static final int RECENT_WITH_EXCLUDED = 0x0001; 146 147 /** 148 * @hide 149 * TODO: Make this public. Provides a list that does not contain any 150 * recent tasks that currently are not available to the user. 151 */ 152 public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002; 153 154 /** 155 * Return a list of the tasks that the user has recently launched, with 156 * the most recent being first and older ones after in order. 157 * 158 * @param maxNum The maximum number of entries to return in the list. The 159 * actual number returned may be smaller, depending on how many tasks the 160 * user has started and the maximum number the system can remember. 161 * 162 * @return Returns a list of RecentTaskInfo records describing each of 163 * the recent tasks. 164 * 165 * @throws SecurityException Throws SecurityException if the caller does 166 * not hold the {@link android.Manifest.permission#GET_TASKS} permission. 167 */ 168 public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags) 169 throws SecurityException { 170 try { 171 return ActivityManagerNative.getDefault().getRecentTasks(maxNum, 172 flags); 173 } catch (RemoteException e) { 174 // System dead, we will be dead too soon! 175 return null; 176 } 177 } 178 179 /** 180 * Information you can retrieve about a particular task that is currently 181 * "running" in the system. Note that a running task does not mean the 182 * given task actual has a process it is actively running in; it simply 183 * means that the user has gone to it and never closed it, but currently 184 * the system may have killed its process and is only holding on to its 185 * last state in order to restart it when the user returns. 186 */ 187 public static class RunningTaskInfo implements Parcelable { 188 /** 189 * A unique identifier for this task. 190 */ 191 public int id; 192 193 /** 194 * The component launched as the first activity in the task. This can 195 * be considered the "application" of this task. 196 */ 197 public ComponentName baseActivity; 198 199 /** 200 * The activity component at the top of the history stack of the task. 201 * This is what the user is currently doing. 202 */ 203 public ComponentName topActivity; 204 205 /** 206 * Thumbnail representation of the task's current state. 207 */ 208 public Bitmap thumbnail; 209 210 /** 211 * Description of the task's current state. 212 */ 213 public CharSequence description; 214 215 /** 216 * Number of activities in this task. 217 */ 218 public int numActivities; 219 220 /** 221 * Number of activities that are currently running (not stopped 222 * and persisted) in this task. 223 */ 224 public int numRunning; 225 226 public RunningTaskInfo() { 227 } 228 229 public int describeContents() { 230 return 0; 231 } 232 233 public void writeToParcel(Parcel dest, int flags) { 234 dest.writeInt(id); 235 ComponentName.writeToParcel(baseActivity, dest); 236 ComponentName.writeToParcel(topActivity, dest); 237 if (thumbnail != null) { 238 dest.writeInt(1); 239 thumbnail.writeToParcel(dest, 0); 240 } else { 241 dest.writeInt(0); 242 } 243 TextUtils.writeToParcel(description, dest, 244 Parcelable.PARCELABLE_WRITE_RETURN_VALUE); 245 dest.writeInt(numActivities); 246 dest.writeInt(numRunning); 247 } 248 249 public void readFromParcel(Parcel source) { 250 id = source.readInt(); 251 baseActivity = ComponentName.readFromParcel(source); 252 topActivity = ComponentName.readFromParcel(source); 253 if (source.readInt() != 0) { 254 thumbnail = Bitmap.CREATOR.createFromParcel(source); 255 } else { 256 thumbnail = null; 257 } 258 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); 259 numActivities = source.readInt(); 260 numRunning = source.readInt(); 261 } 262 263 public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() { 264 public RunningTaskInfo createFromParcel(Parcel source) { 265 return new RunningTaskInfo(source); 266 } 267 public RunningTaskInfo[] newArray(int size) { 268 return new RunningTaskInfo[size]; 269 } 270 }; 271 272 private RunningTaskInfo(Parcel source) { 273 readFromParcel(source); 274 } 275 } 276 277 /** 278 * Return a list of the tasks that are currently running, with 279 * the most recent being first and older ones after in order. Note that 280 * "running" does not mean any of the task's code is currently loaded or 281 * activity -- the task may have been frozen by the system, so that it 282 * can be restarted in its previous state when next brought to the 283 * foreground. 284 * 285 * @param maxNum The maximum number of entries to return in the list. The 286 * actual number returned may be smaller, depending on how many tasks the 287 * user has started. 288 * 289 * @return Returns a list of RunningTaskInfo records describing each of 290 * the running tasks. 291 * 292 * @throws SecurityException Throws SecurityException if the caller does 293 * not hold the {@link android.Manifest.permission#GET_TASKS} permission. 294 */ 295 public List<RunningTaskInfo> getRunningTasks(int maxNum) 296 throws SecurityException { 297 try { 298 return (List<RunningTaskInfo>)ActivityManagerNative.getDefault() 299 .getTasks(maxNum, 0, null); 300 } catch (RemoteException e) { 301 // System dead, we will be dead too soon! 302 return null; 303 } 304 } 305 306 /** 307 * Information you can retrieve about a particular Service that is 308 * currently running in the system. 309 */ 310 public static class RunningServiceInfo implements Parcelable { 311 /** 312 * The service component. 313 */ 314 public ComponentName service; 315 316 /** 317 * If non-zero, this is the process the service is running in. 318 */ 319 public int pid; 320 321 /** 322 * The UID that owns this service. 323 */ 324 public int uid; 325 326 /** 327 * The name of the process this service runs in. 328 */ 329 public String process; 330 331 /** 332 * Set to true if the service has asked to run as a foreground process. 333 */ 334 public boolean foreground; 335 336 /** 337 * The time when the service was first made active, either by someone 338 * starting or binding to it. 339 */ 340 public long activeSince; 341 342 /** 343 * Set to true if this service has been explicitly started. 344 */ 345 public boolean started; 346 347 /** 348 * Number of clients connected to the service. 349 */ 350 public int clientCount; 351 352 /** 353 * Number of times the service's process has crashed while the service 354 * is running. 355 */ 356 public int crashCount; 357 358 /** 359 * The time when there was last activity in the service (either 360 * explicit requests to start it or clients binding to it). 361 */ 362 public long lastActivityTime; 363 364 /** 365 * If non-zero, this service is not currently running, but scheduled to 366 * restart at the given time. 367 */ 368 public long restarting; 369 370 /** 371 * Bit for {@link #flags}: set if this service has been 372 * explicitly started. 373 */ 374 public static final int FLAG_STARTED = 1<<0; 375 376 /** 377 * Bit for {@link #flags}: set if the service has asked to 378 * run as a foreground process. 379 */ 380 public static final int FLAG_FOREGROUND = 1<<1; 381 382 /** 383 * Bit for {@link #flags): set if the service is running in a 384 * core system process. 385 */ 386 public static final int FLAG_SYSTEM_PROCESS = 1<<2; 387 388 /** 389 * Bit for {@link #flags): set if the service is running in a 390 * persistent process. 391 */ 392 public static final int FLAG_PERSISTENT_PROCESS = 1<<3; 393 394 /** 395 * Running flags. 396 */ 397 public int flags; 398 399 /** 400 * For special services that are bound to by system code, this is 401 * the package that holds the binding. 402 */ 403 public String clientPackage; 404 405 /** 406 * For special services that are bound to by system code, this is 407 * a string resource providing a user-visible label for who the 408 * client is. 409 */ 410 public int clientLabel; 411 412 public RunningServiceInfo() { 413 } 414 415 public int describeContents() { 416 return 0; 417 } 418 419 public void writeToParcel(Parcel dest, int flags) { 420 ComponentName.writeToParcel(service, dest); 421 dest.writeInt(pid); 422 dest.writeInt(uid); 423 dest.writeString(process); 424 dest.writeInt(foreground ? 1 : 0); 425 dest.writeLong(activeSince); 426 dest.writeInt(started ? 1 : 0); 427 dest.writeInt(clientCount); 428 dest.writeInt(crashCount); 429 dest.writeLong(lastActivityTime); 430 dest.writeLong(restarting); 431 dest.writeInt(this.flags); 432 dest.writeString(clientPackage); 433 dest.writeInt(clientLabel); 434 } 435 436 public void readFromParcel(Parcel source) { 437 service = ComponentName.readFromParcel(source); 438 pid = source.readInt(); 439 uid = source.readInt(); 440 process = source.readString(); 441 foreground = source.readInt() != 0; 442 activeSince = source.readLong(); 443 started = source.readInt() != 0; 444 clientCount = source.readInt(); 445 crashCount = source.readInt(); 446 lastActivityTime = source.readLong(); 447 restarting = source.readLong(); 448 flags = source.readInt(); 449 clientPackage = source.readString(); 450 clientLabel = source.readInt(); 451 } 452 453 public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() { 454 public RunningServiceInfo createFromParcel(Parcel source) { 455 return new RunningServiceInfo(source); 456 } 457 public RunningServiceInfo[] newArray(int size) { 458 return new RunningServiceInfo[size]; 459 } 460 }; 461 462 private RunningServiceInfo(Parcel source) { 463 readFromParcel(source); 464 } 465 } 466 467 /** 468 * Return a list of the services that are currently running. 469 * 470 * @param maxNum The maximum number of entries to return in the list. The 471 * actual number returned may be smaller, depending on how many services 472 * are running. 473 * 474 * @return Returns a list of RunningServiceInfo records describing each of 475 * the running tasks. 476 */ 477 public List<RunningServiceInfo> getRunningServices(int maxNum) 478 throws SecurityException { 479 try { 480 return (List<RunningServiceInfo>)ActivityManagerNative.getDefault() 481 .getServices(maxNum, 0); 482 } catch (RemoteException e) { 483 // System dead, we will be dead too soon! 484 return null; 485 } 486 } 487 488 /** 489 * Returns a PendingIntent you can start to show a control panel for the 490 * given running service. If the service does not have a control panel, 491 * null is returned. 492 */ 493 public PendingIntent getRunningServiceControlPanel(ComponentName service) 494 throws SecurityException { 495 try { 496 return ActivityManagerNative.getDefault() 497 .getRunningServiceControlPanel(service); 498 } catch (RemoteException e) { 499 // System dead, we will be dead too soon! 500 return null; 501 } 502 } 503 504 /** 505 * Information you can retrieve about the available memory through 506 * {@link ActivityManager#getMemoryInfo}. 507 */ 508 public static class MemoryInfo implements Parcelable { 509 /** 510 * The total available memory on the system. This number should not 511 * be considered absolute: due to the nature of the kernel, a significant 512 * portion of this memory is actually in use and needed for the overall 513 * system to run well. 514 */ 515 public long availMem; 516 517 /** 518 * The threshold of {@link #availMem} at which we consider memory to be 519 * low and start killing background services and other non-extraneous 520 * processes. 521 */ 522 public long threshold; 523 524 /** 525 * Set to true if the system considers itself to currently be in a low 526 * memory situation. 527 */ 528 public boolean lowMemory; 529 530 public MemoryInfo() { 531 } 532 533 public int describeContents() { 534 return 0; 535 } 536 537 public void writeToParcel(Parcel dest, int flags) { 538 dest.writeLong(availMem); 539 dest.writeLong(threshold); 540 dest.writeInt(lowMemory ? 1 : 0); 541 } 542 543 public void readFromParcel(Parcel source) { 544 availMem = source.readLong(); 545 threshold = source.readLong(); 546 lowMemory = source.readInt() != 0; 547 } 548 549 public static final Creator<MemoryInfo> CREATOR 550 = new Creator<MemoryInfo>() { 551 public MemoryInfo createFromParcel(Parcel source) { 552 return new MemoryInfo(source); 553 } 554 public MemoryInfo[] newArray(int size) { 555 return new MemoryInfo[size]; 556 } 557 }; 558 559 private MemoryInfo(Parcel source) { 560 readFromParcel(source); 561 } 562 } 563 564 public void getMemoryInfo(MemoryInfo outInfo) { 565 try { 566 ActivityManagerNative.getDefault().getMemoryInfo(outInfo); 567 } catch (RemoteException e) { 568 } 569 } 570 571 /** 572 * @hide 573 */ 574 public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) { 575 try { 576 return ActivityManagerNative.getDefault().clearApplicationUserData(packageName, 577 observer); 578 } catch (RemoteException e) { 579 return false; 580 } 581 } 582 583 /** 584 * Information you can retrieve about any processes that are in an error condition. 585 */ 586 public static class ProcessErrorStateInfo implements Parcelable { 587 /** 588 * Condition codes 589 */ 590 public static final int NO_ERROR = 0; 591 public static final int CRASHED = 1; 592 public static final int NOT_RESPONDING = 2; 593 594 /** 595 * The condition that the process is in. 596 */ 597 public int condition; 598 599 /** 600 * The process name in which the crash or error occurred. 601 */ 602 public String processName; 603 604 /** 605 * The pid of this process; 0 if none 606 */ 607 public int pid; 608 609 /** 610 * The kernel user-ID that has been assigned to this process; 611 * currently this is not a unique ID (multiple applications can have 612 * the same uid). 613 */ 614 public int uid; 615 616 /** 617 * The activity name associated with the error, if known. May be null. 618 */ 619 public String tag; 620 621 /** 622 * A short message describing the error condition. 623 */ 624 public String shortMsg; 625 626 /** 627 * A long message describing the error condition. 628 */ 629 public String longMsg; 630 631 /** 632 * The stack trace where the error originated. May be null. 633 */ 634 public String stackTrace; 635 636 /** 637 * to be deprecated: This value will always be null. 638 */ 639 public byte[] crashData = null; 640 641 public ProcessErrorStateInfo() { 642 } 643 644 public int describeContents() { 645 return 0; 646 } 647 648 public void writeToParcel(Parcel dest, int flags) { 649 dest.writeInt(condition); 650 dest.writeString(processName); 651 dest.writeInt(pid); 652 dest.writeInt(uid); 653 dest.writeString(tag); 654 dest.writeString(shortMsg); 655 dest.writeString(longMsg); 656 dest.writeString(stackTrace); 657 } 658 659 public void readFromParcel(Parcel source) { 660 condition = source.readInt(); 661 processName = source.readString(); 662 pid = source.readInt(); 663 uid = source.readInt(); 664 tag = source.readString(); 665 shortMsg = source.readString(); 666 longMsg = source.readString(); 667 stackTrace = source.readString(); 668 } 669 670 public static final Creator<ProcessErrorStateInfo> CREATOR = 671 new Creator<ProcessErrorStateInfo>() { 672 public ProcessErrorStateInfo createFromParcel(Parcel source) { 673 return new ProcessErrorStateInfo(source); 674 } 675 public ProcessErrorStateInfo[] newArray(int size) { 676 return new ProcessErrorStateInfo[size]; 677 } 678 }; 679 680 private ProcessErrorStateInfo(Parcel source) { 681 readFromParcel(source); 682 } 683 } 684 685 /** 686 * Returns a list of any processes that are currently in an error condition. The result 687 * will be null if all processes are running properly at this time. 688 * 689 * @return Returns a list of ProcessErrorStateInfo records, or null if there are no 690 * current error conditions (it will not return an empty list). This list ordering is not 691 * specified. 692 */ 693 public List<ProcessErrorStateInfo> getProcessesInErrorState() { 694 try { 695 return ActivityManagerNative.getDefault().getProcessesInErrorState(); 696 } catch (RemoteException e) { 697 return null; 698 } 699 } 700 701 /** 702 * Information you can retrieve about a running process. 703 */ 704 public static class RunningAppProcessInfo implements Parcelable { 705 /** 706 * The name of the process that this object is associated with 707 */ 708 public String processName; 709 710 /** 711 * The pid of this process; 0 if none 712 */ 713 public int pid; 714 715 /** 716 * The user id of this process. 717 */ 718 public int uid; 719 720 public String pkgList[]; 721 722 /** 723 * Constant for {@link #importance}: this process is running the 724 * foreground UI. 725 */ 726 public static final int IMPORTANCE_FOREGROUND = 100; 727 728 /** 729 * Constant for {@link #importance}: this process is running something 730 * that is actively visible to the user, though not in the immediate 731 * foreground. 732 */ 733 public static final int IMPORTANCE_VISIBLE = 200; 734 735 /** 736 * Constant for {@link #importance}: this process is running something 737 * that is considered to be actively perceptible to the user. An 738 * example would be an application performing background music playback. 739 */ 740 public static final int IMPORTANCE_PERCEPTIBLE = 130; 741 742 /** 743 * Constant for {@link #importance}: this process is running a 744 * heavy-weight application and thus should not be killed. 745 */ 746 public static final int IMPORTANCE_HEAVY_WEIGHT = 170; 747 748 /** 749 * Constant for {@link #importance}: this process is contains services 750 * that should remain running. 751 */ 752 public static final int IMPORTANCE_SERVICE = 300; 753 754 /** 755 * Constant for {@link #importance}: this process process contains 756 * background code that is expendable. 757 */ 758 public static final int IMPORTANCE_BACKGROUND = 400; 759 760 /** 761 * Constant for {@link #importance}: this process is empty of any 762 * actively running code. 763 */ 764 public static final int IMPORTANCE_EMPTY = 500; 765 766 /** 767 * The relative importance level that the system places on this 768 * process. May be one of {@link #IMPORTANCE_FOREGROUND}, 769 * {@link #IMPORTANCE_VISIBLE}, {@link #IMPORTANCE_SERVICE}, 770 * {@link #IMPORTANCE_BACKGROUND}, or {@link #IMPORTANCE_EMPTY}. These 771 * constants are numbered so that "more important" values are always 772 * smaller than "less important" values. 773 */ 774 public int importance; 775 776 /** 777 * An additional ordering within a particular {@link #importance} 778 * category, providing finer-grained information about the relative 779 * utility of processes within a category. This number means nothing 780 * except that a smaller values are more recently used (and thus 781 * more important). Currently an LRU value is only maintained for 782 * the {@link #IMPORTANCE_BACKGROUND} category, though others may 783 * be maintained in the future. 784 */ 785 public int lru; 786 787 /** 788 * Constant for {@link #importanceReasonCode}: nothing special has 789 * been specified for the reason for this level. 790 */ 791 public static final int REASON_UNKNOWN = 0; 792 793 /** 794 * Constant for {@link #importanceReasonCode}: one of the application's 795 * content providers is being used by another process. The pid of 796 * the client process is in {@link #importanceReasonPid} and the 797 * target provider in this process is in 798 * {@link #importanceReasonComponent}. 799 */ 800 public static final int REASON_PROVIDER_IN_USE = 1; 801 802 /** 803 * Constant for {@link #importanceReasonCode}: one of the application's 804 * content providers is being used by another process. The pid of 805 * the client process is in {@link #importanceReasonPid} and the 806 * target provider in this process is in 807 * {@link #importanceReasonComponent}. 808 */ 809 public static final int REASON_SERVICE_IN_USE = 2; 810 811 /** 812 * The reason for {@link #importance}, if any. 813 */ 814 public int importanceReasonCode; 815 816 /** 817 * For the specified values of {@link #importanceReasonCode}, this 818 * is the process ID of the other process that is a client of this 819 * process. This will be 0 if no other process is using this one. 820 */ 821 public int importanceReasonPid; 822 823 /** 824 * For the specified values of {@link #importanceReasonCode}, this 825 * is the name of the component that is being used in this process. 826 */ 827 public ComponentName importanceReasonComponent; 828 829 public RunningAppProcessInfo() { 830 importance = IMPORTANCE_FOREGROUND; 831 importanceReasonCode = REASON_UNKNOWN; 832 } 833 834 public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) { 835 processName = pProcessName; 836 pid = pPid; 837 pkgList = pArr; 838 } 839 840 public int describeContents() { 841 return 0; 842 } 843 844 public void writeToParcel(Parcel dest, int flags) { 845 dest.writeString(processName); 846 dest.writeInt(pid); 847 dest.writeInt(uid); 848 dest.writeStringArray(pkgList); 849 dest.writeInt(importance); 850 dest.writeInt(lru); 851 dest.writeInt(importanceReasonCode); 852 dest.writeInt(importanceReasonPid); 853 ComponentName.writeToParcel(importanceReasonComponent, dest); 854 } 855 856 public void readFromParcel(Parcel source) { 857 processName = source.readString(); 858 pid = source.readInt(); 859 uid = source.readInt(); 860 pkgList = source.readStringArray(); 861 importance = source.readInt(); 862 lru = source.readInt(); 863 importanceReasonCode = source.readInt(); 864 importanceReasonPid = source.readInt(); 865 importanceReasonComponent = ComponentName.readFromParcel(source); 866 } 867 868 public static final Creator<RunningAppProcessInfo> CREATOR = 869 new Creator<RunningAppProcessInfo>() { 870 public RunningAppProcessInfo createFromParcel(Parcel source) { 871 return new RunningAppProcessInfo(source); 872 } 873 public RunningAppProcessInfo[] newArray(int size) { 874 return new RunningAppProcessInfo[size]; 875 } 876 }; 877 878 private RunningAppProcessInfo(Parcel source) { 879 readFromParcel(source); 880 } 881 } 882 883 /** 884 * Returns a list of application processes installed on external media 885 * that are running on the device. 886 * 887 * @return Returns a list of ApplicationInfo records, or null if none 888 * This list ordering is not specified. 889 * @hide 890 */ 891 public List<ApplicationInfo> getRunningExternalApplications() { 892 try { 893 return ActivityManagerNative.getDefault().getRunningExternalApplications(); 894 } catch (RemoteException e) { 895 return null; 896 } 897 } 898 899 /** 900 * Returns a list of application processes that are running on the device. 901 * 902 * @return Returns a list of RunningAppProcessInfo records, or null if there are no 903 * running processes (it will not return an empty list). This list ordering is not 904 * specified. 905 */ 906 public List<RunningAppProcessInfo> getRunningAppProcesses() { 907 try { 908 return ActivityManagerNative.getDefault().getRunningAppProcesses(); 909 } catch (RemoteException e) { 910 return null; 911 } 912 } 913 914 /** 915 * Return information about the memory usage of one or more processes. 916 * 917 * @param pids The pids of the processes whose memory usage is to be 918 * retrieved. 919 * @return Returns an array of memory information, one for each 920 * requested pid. 921 */ 922 public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) { 923 try { 924 return ActivityManagerNative.getDefault().getProcessMemoryInfo(pids); 925 } catch (RemoteException e) { 926 return null; 927 } 928 } 929 930 /** 931 * @deprecated This is now just a wrapper for 932 * {@link #killBackgroundProcesses(String)}; the previous behavior here 933 * is no longer available to applications because it allows them to 934 * break other applications by removing their alarms, stopping their 935 * services, etc. 936 */ 937 @Deprecated 938 public void restartPackage(String packageName) { 939 killBackgroundProcesses(packageName); 940 } 941 942 /** 943 * Have the system immediately kill all background processes associated 944 * with the given package. This is the same as the kernel killing those 945 * processes to reclaim memory; the system will take care of restarting 946 * these processes in the future as needed. 947 * 948 * <p>You must hold the permission 949 * {@link android.Manifest.permission#KILL_BACKGROUND_PROCESSES} to be able to 950 * call this method. 951 * 952 * @param packageName The name of the package whose processes are to 953 * be killed. 954 */ 955 public void killBackgroundProcesses(String packageName) { 956 try { 957 ActivityManagerNative.getDefault().killBackgroundProcesses(packageName); 958 } catch (RemoteException e) { 959 } 960 } 961 962 /** 963 * Have the system perform a force stop of everything associated with 964 * the given application package. All processes that share its uid 965 * will be killed, all services it has running stopped, all activities 966 * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED} 967 * broadcast will be sent, so that any of its registered alarms can 968 * be stopped, notifications removed, etc. 969 * 970 * <p>You must hold the permission 971 * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to 972 * call this method. 973 * 974 * @param packageName The name of the package to be stopped. 975 * 976 * @hide This is not available to third party applications due to 977 * it allowing them to break other applications by stopping their 978 * services, removing their alarms, etc. 979 */ 980 public void forceStopPackage(String packageName) { 981 try { 982 ActivityManagerNative.getDefault().forceStopPackage(packageName); 983 } catch (RemoteException e) { 984 } 985 } 986 987 /** 988 * Get the device configuration attributes. 989 */ 990 public ConfigurationInfo getDeviceConfigurationInfo() { 991 try { 992 return ActivityManagerNative.getDefault().getDeviceConfigurationInfo(); 993 } catch (RemoteException e) { 994 } 995 return null; 996 } 997 998 /** 999 * Returns "true" if the user interface is currently being messed with 1000 * by a monkey. 1001 */ 1002 public static boolean isUserAMonkey() { 1003 try { 1004 return ActivityManagerNative.getDefault().isUserAMonkey(); 1005 } catch (RemoteException e) { 1006 } 1007 return false; 1008 } 1009} 1010