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