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