ActivityManager.java revision 860755faa6bdd3c2aeae49c05b87b5bc080ae60c
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 a 730 * heavy-weight application and thus should not be killed. 731 */ 732 public static final int IMPORTANCE_HEAVY_WEIGHT = 150; 733 734 /** 735 * Constant for {@link #importance}: this process is running something 736 * that is considered to be actively visible to the user. 737 */ 738 public static final int IMPORTANCE_VISIBLE = 200; 739 740 /** 741 * Constant for {@link #importance}: this process is contains services 742 * that should remain running. 743 */ 744 public static final int IMPORTANCE_SERVICE = 300; 745 746 /** 747 * Constant for {@link #importance}: this process process contains 748 * background code that is expendable. 749 */ 750 public static final int IMPORTANCE_BACKGROUND = 400; 751 752 /** 753 * Constant for {@link #importance}: this process is empty of any 754 * actively running code. 755 */ 756 public static final int IMPORTANCE_EMPTY = 500; 757 758 /** 759 * The relative importance level that the system places on this 760 * process. May be one of {@link #IMPORTANCE_FOREGROUND}, 761 * {@link #IMPORTANCE_VISIBLE}, {@link #IMPORTANCE_SERVICE}, 762 * {@link #IMPORTANCE_BACKGROUND}, or {@link #IMPORTANCE_EMPTY}. These 763 * constants are numbered so that "more important" values are always 764 * smaller than "less important" values. 765 */ 766 public int importance; 767 768 /** 769 * An additional ordering within a particular {@link #importance} 770 * category, providing finer-grained information about the relative 771 * utility of processes within a category. This number means nothing 772 * except that a smaller values are more recently used (and thus 773 * more important). Currently an LRU value is only maintained for 774 * the {@link #IMPORTANCE_BACKGROUND} category, though others may 775 * be maintained in the future. 776 */ 777 public int lru; 778 779 /** 780 * Constant for {@link #importanceReasonCode}: nothing special has 781 * been specified for the reason for this level. 782 */ 783 public static final int REASON_UNKNOWN = 0; 784 785 /** 786 * Constant for {@link #importanceReasonCode}: one of the application's 787 * content providers is being used by another process. The pid of 788 * the client process is in {@link #importanceReasonPid} and the 789 * target provider in this process is in 790 * {@link #importanceReasonComponent}. 791 */ 792 public static final int REASON_PROVIDER_IN_USE = 1; 793 794 /** 795 * Constant for {@link #importanceReasonCode}: one of the application's 796 * content providers is being used by another process. The pid of 797 * the client process is in {@link #importanceReasonPid} and the 798 * target provider in this process is in 799 * {@link #importanceReasonComponent}. 800 */ 801 public static final int REASON_SERVICE_IN_USE = 2; 802 803 /** 804 * The reason for {@link #importance}, if any. 805 */ 806 public int importanceReasonCode; 807 808 /** 809 * For the specified values of {@link #importanceReasonCode}, this 810 * is the process ID of the other process that is a client of this 811 * process. This will be 0 if no other process is using this one. 812 */ 813 public int importanceReasonPid; 814 815 /** 816 * For the specified values of {@link #importanceReasonCode}, this 817 * is the name of the component that is being used in this process. 818 */ 819 public ComponentName importanceReasonComponent; 820 821 public RunningAppProcessInfo() { 822 importance = IMPORTANCE_FOREGROUND; 823 importanceReasonCode = REASON_UNKNOWN; 824 } 825 826 public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) { 827 processName = pProcessName; 828 pid = pPid; 829 pkgList = pArr; 830 } 831 832 public int describeContents() { 833 return 0; 834 } 835 836 public void writeToParcel(Parcel dest, int flags) { 837 dest.writeString(processName); 838 dest.writeInt(pid); 839 dest.writeInt(uid); 840 dest.writeStringArray(pkgList); 841 dest.writeInt(importance); 842 dest.writeInt(lru); 843 dest.writeInt(importanceReasonCode); 844 dest.writeInt(importanceReasonPid); 845 ComponentName.writeToParcel(importanceReasonComponent, dest); 846 } 847 848 public void readFromParcel(Parcel source) { 849 processName = source.readString(); 850 pid = source.readInt(); 851 uid = source.readInt(); 852 pkgList = source.readStringArray(); 853 importance = source.readInt(); 854 lru = source.readInt(); 855 importanceReasonCode = source.readInt(); 856 importanceReasonPid = source.readInt(); 857 importanceReasonComponent = ComponentName.readFromParcel(source); 858 } 859 860 public static final Creator<RunningAppProcessInfo> CREATOR = 861 new Creator<RunningAppProcessInfo>() { 862 public RunningAppProcessInfo createFromParcel(Parcel source) { 863 return new RunningAppProcessInfo(source); 864 } 865 public RunningAppProcessInfo[] newArray(int size) { 866 return new RunningAppProcessInfo[size]; 867 } 868 }; 869 870 private RunningAppProcessInfo(Parcel source) { 871 readFromParcel(source); 872 } 873 } 874 875 /** 876 * Returns a list of application processes installed on external media 877 * that are running on the device. 878 * 879 * @return Returns a list of ApplicationInfo records, or null if none 880 * This list ordering is not specified. 881 * @hide 882 */ 883 public List<ApplicationInfo> getRunningExternalApplications() { 884 try { 885 return ActivityManagerNative.getDefault().getRunningExternalApplications(); 886 } catch (RemoteException e) { 887 return null; 888 } 889 } 890 891 /** 892 * Returns a list of application processes that are running on the device. 893 * 894 * @return Returns a list of RunningAppProcessInfo records, or null if there are no 895 * running processes (it will not return an empty list). This list ordering is not 896 * specified. 897 */ 898 public List<RunningAppProcessInfo> getRunningAppProcesses() { 899 try { 900 return ActivityManagerNative.getDefault().getRunningAppProcesses(); 901 } catch (RemoteException e) { 902 return null; 903 } 904 } 905 906 /** 907 * Return information about the memory usage of one or more processes. 908 * 909 * @param pids The pids of the processes whose memory usage is to be 910 * retrieved. 911 * @return Returns an array of memory information, one for each 912 * requested pid. 913 */ 914 public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) { 915 try { 916 return ActivityManagerNative.getDefault().getProcessMemoryInfo(pids); 917 } catch (RemoteException e) { 918 return null; 919 } 920 } 921 922 /** 923 * @deprecated This is now just a wrapper for 924 * {@link #killBackgroundProcesses(String)}; the previous behavior here 925 * is no longer available to applications because it allows them to 926 * break other applications by removing their alarms, stopping their 927 * services, etc. 928 */ 929 @Deprecated 930 public void restartPackage(String packageName) { 931 killBackgroundProcesses(packageName); 932 } 933 934 /** 935 * Have the system immediately kill all background processes associated 936 * with the given package. This is the same as the kernel killing those 937 * processes to reclaim memory; the system will take care of restarting 938 * these processes in the future as needed. 939 * 940 * <p>You must hold the permission 941 * {@link android.Manifest.permission#KILL_BACKGROUND_PROCESSES} to be able to 942 * call this method. 943 * 944 * @param packageName The name of the package whose processes are to 945 * be killed. 946 */ 947 public void killBackgroundProcesses(String packageName) { 948 try { 949 ActivityManagerNative.getDefault().killBackgroundProcesses(packageName); 950 } catch (RemoteException e) { 951 } 952 } 953 954 /** 955 * Have the system perform a force stop of everything associated with 956 * the given application package. All processes that share its uid 957 * will be killed, all services it has running stopped, all activities 958 * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED} 959 * broadcast will be sent, so that any of its registered alarms can 960 * be stopped, notifications removed, etc. 961 * 962 * <p>You must hold the permission 963 * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to 964 * call this method. 965 * 966 * @param packageName The name of the package to be stopped. 967 * 968 * @hide This is not available to third party applications due to 969 * it allowing them to break other applications by stopping their 970 * services, removing their alarms, etc. 971 */ 972 public void forceStopPackage(String packageName) { 973 try { 974 ActivityManagerNative.getDefault().forceStopPackage(packageName); 975 } catch (RemoteException e) { 976 } 977 } 978 979 /** 980 * Get the device configuration attributes. 981 */ 982 public ConfigurationInfo getDeviceConfigurationInfo() { 983 try { 984 return ActivityManagerNative.getDefault().getDeviceConfigurationInfo(); 985 } catch (RemoteException e) { 986 } 987 return null; 988 } 989 990 /** 991 * Returns "true" if the user interface is currently being messed with 992 * by a monkey. 993 */ 994 public static boolean isUserAMonkey() { 995 try { 996 return ActivityManagerNative.getDefault().isUserAMonkey(); 997 } catch (RemoteException e) { 998 } 999 return false; 1000 } 1001} 1002