ActivityManager.java revision 0b2a6d0773211449fbde9d2706388714beeffebb
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 * @param flags Optional flags 290 * @param receiver Optional receiver for delayed thumbnails 291 * 292 * @return Returns a list of RunningTaskInfo records describing each of 293 * the running tasks. 294 * 295 * Some thumbnails may not be available at the time of this call. The optional 296 * receiver may be used to receive those thumbnails. 297 * 298 * @throws SecurityException Throws SecurityException if the caller does 299 * not hold the {@link android.Manifest.permission#GET_TASKS} permission. 300 * 301 * @hide 302 */ 303 public List<RunningTaskInfo> getRunningTasks(int maxNum, int flags, IThumbnailReceiver receiver) 304 throws SecurityException { 305 try { 306 return ActivityManagerNative.getDefault().getTasks(maxNum, flags, receiver); 307 } catch (RemoteException e) { 308 // System dead, we will be dead too soon! 309 return null; 310 } 311 } 312 313 /** 314 * Return a list of the tasks that are currently running, with 315 * the most recent being first and older ones after in order. Note that 316 * "running" does not mean any of the task's code is currently loaded or 317 * activity -- the task may have been frozen by the system, so that it 318 * can be restarted in its previous state when next brought to the 319 * foreground. 320 * 321 * @param maxNum The maximum number of entries to return in the list. The 322 * actual number returned may be smaller, depending on how many tasks the 323 * user has started. 324 * 325 * @return Returns a list of RunningTaskInfo records describing each of 326 * the running tasks. 327 * 328 * @throws SecurityException Throws SecurityException if the caller does 329 * not hold the {@link android.Manifest.permission#GET_TASKS} permission. 330 */ 331 public List<RunningTaskInfo> getRunningTasks(int maxNum) 332 throws SecurityException { 333 return getRunningTasks(maxNum, 0, null); 334 } 335 336 /** 337 * Information you can retrieve about a particular Service that is 338 * currently running in the system. 339 */ 340 public static class RunningServiceInfo implements Parcelable { 341 /** 342 * The service component. 343 */ 344 public ComponentName service; 345 346 /** 347 * If non-zero, this is the process the service is running in. 348 */ 349 public int pid; 350 351 /** 352 * The UID that owns this service. 353 */ 354 public int uid; 355 356 /** 357 * The name of the process this service runs in. 358 */ 359 public String process; 360 361 /** 362 * Set to true if the service has asked to run as a foreground process. 363 */ 364 public boolean foreground; 365 366 /** 367 * The time when the service was first made active, either by someone 368 * starting or binding to it. 369 */ 370 public long activeSince; 371 372 /** 373 * Set to true if this service has been explicitly started. 374 */ 375 public boolean started; 376 377 /** 378 * Number of clients connected to the service. 379 */ 380 public int clientCount; 381 382 /** 383 * Number of times the service's process has crashed while the service 384 * is running. 385 */ 386 public int crashCount; 387 388 /** 389 * The time when there was last activity in the service (either 390 * explicit requests to start it or clients binding to it). 391 */ 392 public long lastActivityTime; 393 394 /** 395 * If non-zero, this service is not currently running, but scheduled to 396 * restart at the given time. 397 */ 398 public long restarting; 399 400 /** 401 * Bit for {@link #flags}: set if this service has been 402 * explicitly started. 403 */ 404 public static final int FLAG_STARTED = 1<<0; 405 406 /** 407 * Bit for {@link #flags}: set if the service has asked to 408 * run as a foreground process. 409 */ 410 public static final int FLAG_FOREGROUND = 1<<1; 411 412 /** 413 * Bit for {@link #flags): set if the service is running in a 414 * core system process. 415 */ 416 public static final int FLAG_SYSTEM_PROCESS = 1<<2; 417 418 /** 419 * Bit for {@link #flags): set if the service is running in a 420 * persistent process. 421 */ 422 public static final int FLAG_PERSISTENT_PROCESS = 1<<3; 423 424 /** 425 * Running flags. 426 */ 427 public int flags; 428 429 /** 430 * For special services that are bound to by system code, this is 431 * the package that holds the binding. 432 */ 433 public String clientPackage; 434 435 /** 436 * For special services that are bound to by system code, this is 437 * a string resource providing a user-visible label for who the 438 * client is. 439 */ 440 public int clientLabel; 441 442 public RunningServiceInfo() { 443 } 444 445 public int describeContents() { 446 return 0; 447 } 448 449 public void writeToParcel(Parcel dest, int flags) { 450 ComponentName.writeToParcel(service, dest); 451 dest.writeInt(pid); 452 dest.writeInt(uid); 453 dest.writeString(process); 454 dest.writeInt(foreground ? 1 : 0); 455 dest.writeLong(activeSince); 456 dest.writeInt(started ? 1 : 0); 457 dest.writeInt(clientCount); 458 dest.writeInt(crashCount); 459 dest.writeLong(lastActivityTime); 460 dest.writeLong(restarting); 461 dest.writeInt(this.flags); 462 dest.writeString(clientPackage); 463 dest.writeInt(clientLabel); 464 } 465 466 public void readFromParcel(Parcel source) { 467 service = ComponentName.readFromParcel(source); 468 pid = source.readInt(); 469 uid = source.readInt(); 470 process = source.readString(); 471 foreground = source.readInt() != 0; 472 activeSince = source.readLong(); 473 started = source.readInt() != 0; 474 clientCount = source.readInt(); 475 crashCount = source.readInt(); 476 lastActivityTime = source.readLong(); 477 restarting = source.readLong(); 478 flags = source.readInt(); 479 clientPackage = source.readString(); 480 clientLabel = source.readInt(); 481 } 482 483 public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() { 484 public RunningServiceInfo createFromParcel(Parcel source) { 485 return new RunningServiceInfo(source); 486 } 487 public RunningServiceInfo[] newArray(int size) { 488 return new RunningServiceInfo[size]; 489 } 490 }; 491 492 private RunningServiceInfo(Parcel source) { 493 readFromParcel(source); 494 } 495 } 496 497 /** 498 * Return a list of the services that are currently running. 499 * 500 * @param maxNum The maximum number of entries to return in the list. The 501 * actual number returned may be smaller, depending on how many services 502 * are running. 503 * 504 * @return Returns a list of RunningServiceInfo records describing each of 505 * the running tasks. 506 */ 507 public List<RunningServiceInfo> getRunningServices(int maxNum) 508 throws SecurityException { 509 try { 510 return (List<RunningServiceInfo>)ActivityManagerNative.getDefault() 511 .getServices(maxNum, 0); 512 } catch (RemoteException e) { 513 // System dead, we will be dead too soon! 514 return null; 515 } 516 } 517 518 /** 519 * Returns a PendingIntent you can start to show a control panel for the 520 * given running service. If the service does not have a control panel, 521 * null is returned. 522 */ 523 public PendingIntent getRunningServiceControlPanel(ComponentName service) 524 throws SecurityException { 525 try { 526 return ActivityManagerNative.getDefault() 527 .getRunningServiceControlPanel(service); 528 } catch (RemoteException e) { 529 // System dead, we will be dead too soon! 530 return null; 531 } 532 } 533 534 /** 535 * Information you can retrieve about the available memory through 536 * {@link ActivityManager#getMemoryInfo}. 537 */ 538 public static class MemoryInfo implements Parcelable { 539 /** 540 * The total available memory on the system. This number should not 541 * be considered absolute: due to the nature of the kernel, a significant 542 * portion of this memory is actually in use and needed for the overall 543 * system to run well. 544 */ 545 public long availMem; 546 547 /** 548 * The threshold of {@link #availMem} at which we consider memory to be 549 * low and start killing background services and other non-extraneous 550 * processes. 551 */ 552 public long threshold; 553 554 /** 555 * Set to true if the system considers itself to currently be in a low 556 * memory situation. 557 */ 558 public boolean lowMemory; 559 560 public MemoryInfo() { 561 } 562 563 public int describeContents() { 564 return 0; 565 } 566 567 public void writeToParcel(Parcel dest, int flags) { 568 dest.writeLong(availMem); 569 dest.writeLong(threshold); 570 dest.writeInt(lowMemory ? 1 : 0); 571 } 572 573 public void readFromParcel(Parcel source) { 574 availMem = source.readLong(); 575 threshold = source.readLong(); 576 lowMemory = source.readInt() != 0; 577 } 578 579 public static final Creator<MemoryInfo> CREATOR 580 = new Creator<MemoryInfo>() { 581 public MemoryInfo createFromParcel(Parcel source) { 582 return new MemoryInfo(source); 583 } 584 public MemoryInfo[] newArray(int size) { 585 return new MemoryInfo[size]; 586 } 587 }; 588 589 private MemoryInfo(Parcel source) { 590 readFromParcel(source); 591 } 592 } 593 594 public void getMemoryInfo(MemoryInfo outInfo) { 595 try { 596 ActivityManagerNative.getDefault().getMemoryInfo(outInfo); 597 } catch (RemoteException e) { 598 } 599 } 600 601 /** 602 * @hide 603 */ 604 public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) { 605 try { 606 return ActivityManagerNative.getDefault().clearApplicationUserData(packageName, 607 observer); 608 } catch (RemoteException e) { 609 return false; 610 } 611 } 612 613 /** 614 * Information you can retrieve about any processes that are in an error condition. 615 */ 616 public static class ProcessErrorStateInfo implements Parcelable { 617 /** 618 * Condition codes 619 */ 620 public static final int NO_ERROR = 0; 621 public static final int CRASHED = 1; 622 public static final int NOT_RESPONDING = 2; 623 624 /** 625 * The condition that the process is in. 626 */ 627 public int condition; 628 629 /** 630 * The process name in which the crash or error occurred. 631 */ 632 public String processName; 633 634 /** 635 * The pid of this process; 0 if none 636 */ 637 public int pid; 638 639 /** 640 * The kernel user-ID that has been assigned to this process; 641 * currently this is not a unique ID (multiple applications can have 642 * the same uid). 643 */ 644 public int uid; 645 646 /** 647 * The activity name associated with the error, if known. May be null. 648 */ 649 public String tag; 650 651 /** 652 * A short message describing the error condition. 653 */ 654 public String shortMsg; 655 656 /** 657 * A long message describing the error condition. 658 */ 659 public String longMsg; 660 661 /** 662 * The stack trace where the error originated. May be null. 663 */ 664 public String stackTrace; 665 666 /** 667 * to be deprecated: This value will always be null. 668 */ 669 public byte[] crashData = null; 670 671 public ProcessErrorStateInfo() { 672 } 673 674 public int describeContents() { 675 return 0; 676 } 677 678 public void writeToParcel(Parcel dest, int flags) { 679 dest.writeInt(condition); 680 dest.writeString(processName); 681 dest.writeInt(pid); 682 dest.writeInt(uid); 683 dest.writeString(tag); 684 dest.writeString(shortMsg); 685 dest.writeString(longMsg); 686 dest.writeString(stackTrace); 687 } 688 689 public void readFromParcel(Parcel source) { 690 condition = source.readInt(); 691 processName = source.readString(); 692 pid = source.readInt(); 693 uid = source.readInt(); 694 tag = source.readString(); 695 shortMsg = source.readString(); 696 longMsg = source.readString(); 697 stackTrace = source.readString(); 698 } 699 700 public static final Creator<ProcessErrorStateInfo> CREATOR = 701 new Creator<ProcessErrorStateInfo>() { 702 public ProcessErrorStateInfo createFromParcel(Parcel source) { 703 return new ProcessErrorStateInfo(source); 704 } 705 public ProcessErrorStateInfo[] newArray(int size) { 706 return new ProcessErrorStateInfo[size]; 707 } 708 }; 709 710 private ProcessErrorStateInfo(Parcel source) { 711 readFromParcel(source); 712 } 713 } 714 715 /** 716 * Returns a list of any processes that are currently in an error condition. The result 717 * will be null if all processes are running properly at this time. 718 * 719 * @return Returns a list of ProcessErrorStateInfo records, or null if there are no 720 * current error conditions (it will not return an empty list). This list ordering is not 721 * specified. 722 */ 723 public List<ProcessErrorStateInfo> getProcessesInErrorState() { 724 try { 725 return ActivityManagerNative.getDefault().getProcessesInErrorState(); 726 } catch (RemoteException e) { 727 return null; 728 } 729 } 730 731 /** 732 * Information you can retrieve about a running process. 733 */ 734 public static class RunningAppProcessInfo implements Parcelable { 735 /** 736 * The name of the process that this object is associated with 737 */ 738 public String processName; 739 740 /** 741 * The pid of this process; 0 if none 742 */ 743 public int pid; 744 745 /** 746 * The user id of this process. 747 */ 748 public int uid; 749 750 /** 751 * All packages that have been loaded into the process. 752 */ 753 public String pkgList[]; 754 755 /** 756 * Constant for {@link #flags}: this is a heavy-weight process, 757 * meaning it will not be killed while in the background. 758 */ 759 public static final int FLAG_HEAVY_WEIGHT = 1<<0; 760 761 /** 762 * Flags of information. May be any of 763 * {@link #FLAG_HEAVY_WEIGHT}. 764 */ 765 public int flags; 766 767 /** 768 * Constant for {@link #importance}: this process is running the 769 * foreground UI. 770 */ 771 public static final int IMPORTANCE_FOREGROUND = 100; 772 773 /** 774 * Constant for {@link #importance}: this process is running something 775 * that is actively visible to the user, though not in the immediate 776 * foreground. 777 */ 778 public static final int IMPORTANCE_VISIBLE = 200; 779 780 /** 781 * Constant for {@link #importance}: this process is running something 782 * that is considered to be actively perceptible to the user. An 783 * example would be an application performing background music playback. 784 */ 785 public static final int IMPORTANCE_PERCEPTIBLE = 130; 786 787 /** 788 * Constant for {@link #importance}: this process is running a 789 * heavy-weight application and thus should not be killed. 790 */ 791 public static final int IMPORTANCE_HEAVY_WEIGHT = 170; 792 793 /** 794 * Constant for {@link #importance}: this process is contains services 795 * that should remain running. 796 */ 797 public static final int IMPORTANCE_SERVICE = 300; 798 799 /** 800 * Constant for {@link #importance}: this process process contains 801 * background code that is expendable. 802 */ 803 public static final int IMPORTANCE_BACKGROUND = 400; 804 805 /** 806 * Constant for {@link #importance}: this process is empty of any 807 * actively running code. 808 */ 809 public static final int IMPORTANCE_EMPTY = 500; 810 811 /** 812 * The relative importance level that the system places on this 813 * process. May be one of {@link #IMPORTANCE_FOREGROUND}, 814 * {@link #IMPORTANCE_VISIBLE}, {@link #IMPORTANCE_SERVICE}, 815 * {@link #IMPORTANCE_BACKGROUND}, or {@link #IMPORTANCE_EMPTY}. These 816 * constants are numbered so that "more important" values are always 817 * smaller than "less important" values. 818 */ 819 public int importance; 820 821 /** 822 * An additional ordering within a particular {@link #importance} 823 * category, providing finer-grained information about the relative 824 * utility of processes within a category. This number means nothing 825 * except that a smaller values are more recently used (and thus 826 * more important). Currently an LRU value is only maintained for 827 * the {@link #IMPORTANCE_BACKGROUND} category, though others may 828 * be maintained in the future. 829 */ 830 public int lru; 831 832 /** 833 * Constant for {@link #importanceReasonCode}: nothing special has 834 * been specified for the reason for this level. 835 */ 836 public static final int REASON_UNKNOWN = 0; 837 838 /** 839 * Constant for {@link #importanceReasonCode}: one of the application's 840 * content providers is being used by another process. The pid of 841 * the client process is in {@link #importanceReasonPid} and the 842 * target provider in this process is in 843 * {@link #importanceReasonComponent}. 844 */ 845 public static final int REASON_PROVIDER_IN_USE = 1; 846 847 /** 848 * Constant for {@link #importanceReasonCode}: one of the application's 849 * content providers is being used by another process. The pid of 850 * the client process is in {@link #importanceReasonPid} and the 851 * target provider in this process is in 852 * {@link #importanceReasonComponent}. 853 */ 854 public static final int REASON_SERVICE_IN_USE = 2; 855 856 /** 857 * The reason for {@link #importance}, if any. 858 */ 859 public int importanceReasonCode; 860 861 /** 862 * For the specified values of {@link #importanceReasonCode}, this 863 * is the process ID of the other process that is a client of this 864 * process. This will be 0 if no other process is using this one. 865 */ 866 public int importanceReasonPid; 867 868 /** 869 * For the specified values of {@link #importanceReasonCode}, this 870 * is the name of the component that is being used in this process. 871 */ 872 public ComponentName importanceReasonComponent; 873 874 public RunningAppProcessInfo() { 875 importance = IMPORTANCE_FOREGROUND; 876 importanceReasonCode = REASON_UNKNOWN; 877 } 878 879 public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) { 880 processName = pProcessName; 881 pid = pPid; 882 pkgList = pArr; 883 } 884 885 public int describeContents() { 886 return 0; 887 } 888 889 public void writeToParcel(Parcel dest, int flags) { 890 dest.writeString(processName); 891 dest.writeInt(pid); 892 dest.writeInt(uid); 893 dest.writeStringArray(pkgList); 894 dest.writeInt(this.flags); 895 dest.writeInt(importance); 896 dest.writeInt(lru); 897 dest.writeInt(importanceReasonCode); 898 dest.writeInt(importanceReasonPid); 899 ComponentName.writeToParcel(importanceReasonComponent, dest); 900 } 901 902 public void readFromParcel(Parcel source) { 903 processName = source.readString(); 904 pid = source.readInt(); 905 uid = source.readInt(); 906 pkgList = source.readStringArray(); 907 flags = source.readInt(); 908 importance = source.readInt(); 909 lru = source.readInt(); 910 importanceReasonCode = source.readInt(); 911 importanceReasonPid = source.readInt(); 912 importanceReasonComponent = ComponentName.readFromParcel(source); 913 } 914 915 public static final Creator<RunningAppProcessInfo> CREATOR = 916 new Creator<RunningAppProcessInfo>() { 917 public RunningAppProcessInfo createFromParcel(Parcel source) { 918 return new RunningAppProcessInfo(source); 919 } 920 public RunningAppProcessInfo[] newArray(int size) { 921 return new RunningAppProcessInfo[size]; 922 } 923 }; 924 925 private RunningAppProcessInfo(Parcel source) { 926 readFromParcel(source); 927 } 928 } 929 930 /** 931 * Returns a list of application processes installed on external media 932 * that are running on the device. 933 * 934 * @return Returns a list of ApplicationInfo records, or null if none 935 * This list ordering is not specified. 936 * @hide 937 */ 938 public List<ApplicationInfo> getRunningExternalApplications() { 939 try { 940 return ActivityManagerNative.getDefault().getRunningExternalApplications(); 941 } catch (RemoteException e) { 942 return null; 943 } 944 } 945 946 /** 947 * Returns a list of application processes that are running on the device. 948 * 949 * @return Returns a list of RunningAppProcessInfo records, or null if there are no 950 * running processes (it will not return an empty list). This list ordering is not 951 * specified. 952 */ 953 public List<RunningAppProcessInfo> getRunningAppProcesses() { 954 try { 955 return ActivityManagerNative.getDefault().getRunningAppProcesses(); 956 } catch (RemoteException e) { 957 return null; 958 } 959 } 960 961 /** 962 * Return information about the memory usage of one or more processes. 963 * 964 * @param pids The pids of the processes whose memory usage is to be 965 * retrieved. 966 * @return Returns an array of memory information, one for each 967 * requested pid. 968 */ 969 public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) { 970 try { 971 return ActivityManagerNative.getDefault().getProcessMemoryInfo(pids); 972 } catch (RemoteException e) { 973 return null; 974 } 975 } 976 977 /** 978 * @deprecated This is now just a wrapper for 979 * {@link #killBackgroundProcesses(String)}; the previous behavior here 980 * is no longer available to applications because it allows them to 981 * break other applications by removing their alarms, stopping their 982 * services, etc. 983 */ 984 @Deprecated 985 public void restartPackage(String packageName) { 986 killBackgroundProcesses(packageName); 987 } 988 989 /** 990 * Have the system immediately kill all background processes associated 991 * with the given package. This is the same as the kernel killing those 992 * processes to reclaim memory; the system will take care of restarting 993 * these processes in the future as needed. 994 * 995 * <p>You must hold the permission 996 * {@link android.Manifest.permission#KILL_BACKGROUND_PROCESSES} to be able to 997 * call this method. 998 * 999 * @param packageName The name of the package whose processes are to 1000 * be killed. 1001 */ 1002 public void killBackgroundProcesses(String packageName) { 1003 try { 1004 ActivityManagerNative.getDefault().killBackgroundProcesses(packageName); 1005 } catch (RemoteException e) { 1006 } 1007 } 1008 1009 /** 1010 * Have the system perform a force stop of everything associated with 1011 * the given application package. All processes that share its uid 1012 * will be killed, all services it has running stopped, all activities 1013 * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED} 1014 * broadcast will be sent, so that any of its registered alarms can 1015 * be stopped, notifications removed, etc. 1016 * 1017 * <p>You must hold the permission 1018 * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to 1019 * call this method. 1020 * 1021 * @param packageName The name of the package to be stopped. 1022 * 1023 * @hide This is not available to third party applications due to 1024 * it allowing them to break other applications by stopping their 1025 * services, removing their alarms, etc. 1026 */ 1027 public void forceStopPackage(String packageName) { 1028 try { 1029 ActivityManagerNative.getDefault().forceStopPackage(packageName); 1030 } catch (RemoteException e) { 1031 } 1032 } 1033 1034 /** 1035 * Get the device configuration attributes. 1036 */ 1037 public ConfigurationInfo getDeviceConfigurationInfo() { 1038 try { 1039 return ActivityManagerNative.getDefault().getDeviceConfigurationInfo(); 1040 } catch (RemoteException e) { 1041 } 1042 return null; 1043 } 1044 1045 /** 1046 * Returns "true" if the user interface is currently being messed with 1047 * by a monkey. 1048 */ 1049 public static boolean isUserAMonkey() { 1050 try { 1051 return ActivityManagerNative.getDefault().isUserAMonkey(); 1052 } catch (RemoteException e) { 1053 } 1054 return false; 1055 } 1056} 1057