ActivityManager.java revision dd8fab2629131b09367df747afd9a61e42dd1992
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 com.android.internal.app.IUsageStats; 20import com.android.internal.os.PkgUsageStats; 21import com.android.internal.util.MemInfoReader; 22 23import android.content.ComponentName; 24import android.content.Context; 25import android.content.Intent; 26import android.content.pm.ApplicationInfo; 27import android.content.pm.ConfigurationInfo; 28import android.content.pm.IPackageDataObserver; 29import android.content.res.Configuration; 30import android.content.res.Resources; 31import android.graphics.Bitmap; 32import android.graphics.Point; 33import android.os.Binder; 34import android.os.Bundle; 35import android.os.Debug; 36import android.os.Handler; 37import android.os.Parcel; 38import android.os.Parcelable; 39import android.os.RemoteException; 40import android.os.ServiceManager; 41import android.os.SystemProperties; 42import android.text.TextUtils; 43import android.util.DisplayMetrics; 44import android.util.Log; 45import android.util.Slog; 46import android.view.Display; 47 48import java.util.ArrayList; 49import java.util.HashMap; 50import java.util.List; 51import java.util.Map; 52 53/** 54 * Interact with the overall activities running in the system. 55 */ 56public class ActivityManager { 57 private static String TAG = "ActivityManager"; 58 private static boolean localLOGV = false; 59 60 private final Context mContext; 61 private final Handler mHandler; 62 63 /** 64 * Result for IActivityManager.startActivity: an error where the 65 * start had to be canceled. 66 * @hide 67 */ 68 public static final int START_CANCELED = -6; 69 70 /** 71 * Result for IActivityManager.startActivity: an error where the 72 * thing being started is not an activity. 73 * @hide 74 */ 75 public static final int START_NOT_ACTIVITY = -5; 76 77 /** 78 * Result for IActivityManager.startActivity: an error where the 79 * caller does not have permission to start the activity. 80 * @hide 81 */ 82 public static final int START_PERMISSION_DENIED = -4; 83 84 /** 85 * Result for IActivityManager.startActivity: an error where the 86 * caller has requested both to forward a result and to receive 87 * a result. 88 * @hide 89 */ 90 public static final int START_FORWARD_AND_REQUEST_CONFLICT = -3; 91 92 /** 93 * Result for IActivityManager.startActivity: an error where the 94 * requested class is not found. 95 * @hide 96 */ 97 public static final int START_CLASS_NOT_FOUND = -2; 98 99 /** 100 * Result for IActivityManager.startActivity: an error where the 101 * given Intent could not be resolved to an activity. 102 * @hide 103 */ 104 public static final int START_INTENT_NOT_RESOLVED = -1; 105 106 /** 107 * Result for IActivityManaqer.startActivity: the activity was started 108 * successfully as normal. 109 * @hide 110 */ 111 public static final int START_SUCCESS = 0; 112 113 /** 114 * Result for IActivityManaqer.startActivity: the caller asked that the Intent not 115 * be executed if it is the recipient, and that is indeed the case. 116 * @hide 117 */ 118 public static final int START_RETURN_INTENT_TO_CALLER = 1; 119 120 /** 121 * Result for IActivityManaqer.startActivity: activity wasn't really started, but 122 * a task was simply brought to the foreground. 123 * @hide 124 */ 125 public static final int START_TASK_TO_FRONT = 2; 126 127 /** 128 * Result for IActivityManaqer.startActivity: activity wasn't really started, but 129 * the given Intent was given to the existing top activity. 130 * @hide 131 */ 132 public static final int START_DELIVERED_TO_TOP = 3; 133 134 /** 135 * Result for IActivityManaqer.startActivity: request was canceled because 136 * app switches are temporarily canceled to ensure the user's last request 137 * (such as pressing home) is performed. 138 * @hide 139 */ 140 public static final int START_SWITCHES_CANCELED = 4; 141 142 /** 143 * Flag for IActivityManaqer.startActivity: do special start mode where 144 * a new activity is launched only if it is needed. 145 * @hide 146 */ 147 public static final int START_FLAG_ONLY_IF_NEEDED = 1<<0; 148 149 /** 150 * Flag for IActivityManaqer.startActivity: launch the app for 151 * debugging. 152 * @hide 153 */ 154 public static final int START_FLAG_DEBUG = 1<<1; 155 156 /** 157 * Flag for IActivityManaqer.startActivity: launch the app for 158 * OpenGL tracing. 159 * @hide 160 */ 161 public static final int START_FLAG_OPENGL_TRACES = 1<<2; 162 163 /** 164 * Flag for IActivityManaqer.startActivity: if the app is being 165 * launched for profiling, automatically stop the profiler once done. 166 * @hide 167 */ 168 public static final int START_FLAG_AUTO_STOP_PROFILER = 1<<3; 169 170 /** 171 * Result for IActivityManaqer.broadcastIntent: success! 172 * @hide 173 */ 174 public static final int BROADCAST_SUCCESS = 0; 175 176 /** 177 * Result for IActivityManaqer.broadcastIntent: attempt to broadcast 178 * a sticky intent without appropriate permission. 179 * @hide 180 */ 181 public static final int BROADCAST_STICKY_CANT_HAVE_PERMISSION = -1; 182 183 /** 184 * Type for IActivityManaqer.getIntentSender: this PendingIntent is 185 * for a sendBroadcast operation. 186 * @hide 187 */ 188 public static final int INTENT_SENDER_BROADCAST = 1; 189 190 /** 191 * Type for IActivityManaqer.getIntentSender: this PendingIntent is 192 * for a startActivity operation. 193 * @hide 194 */ 195 public static final int INTENT_SENDER_ACTIVITY = 2; 196 197 /** 198 * Type for IActivityManaqer.getIntentSender: this PendingIntent is 199 * for an activity result operation. 200 * @hide 201 */ 202 public static final int INTENT_SENDER_ACTIVITY_RESULT = 3; 203 204 /** 205 * Type for IActivityManaqer.getIntentSender: this PendingIntent is 206 * for a startService operation. 207 * @hide 208 */ 209 public static final int INTENT_SENDER_SERVICE = 4; 210 211 /*package*/ ActivityManager(Context context, Handler handler) { 212 mContext = context; 213 mHandler = handler; 214 } 215 216 /** 217 * Screen compatibility mode: the application most always run in 218 * compatibility mode. 219 * @hide 220 */ 221 public static final int COMPAT_MODE_ALWAYS = -1; 222 223 /** 224 * Screen compatibility mode: the application can never run in 225 * compatibility mode. 226 * @hide 227 */ 228 public static final int COMPAT_MODE_NEVER = -2; 229 230 /** 231 * Screen compatibility mode: unknown. 232 * @hide 233 */ 234 public static final int COMPAT_MODE_UNKNOWN = -3; 235 236 /** 237 * Screen compatibility mode: the application currently has compatibility 238 * mode disabled. 239 * @hide 240 */ 241 public static final int COMPAT_MODE_DISABLED = 0; 242 243 /** 244 * Screen compatibility mode: the application currently has compatibility 245 * mode enabled. 246 * @hide 247 */ 248 public static final int COMPAT_MODE_ENABLED = 1; 249 250 /** 251 * Screen compatibility mode: request to toggle the application's 252 * compatibility mode. 253 * @hide 254 */ 255 public static final int COMPAT_MODE_TOGGLE = 2; 256 257 /** @hide */ 258 public int getFrontActivityScreenCompatMode() { 259 try { 260 return ActivityManagerNative.getDefault().getFrontActivityScreenCompatMode(); 261 } catch (RemoteException e) { 262 // System dead, we will be dead too soon! 263 return 0; 264 } 265 } 266 267 /** @hide */ 268 public void setFrontActivityScreenCompatMode(int mode) { 269 try { 270 ActivityManagerNative.getDefault().setFrontActivityScreenCompatMode(mode); 271 } catch (RemoteException e) { 272 // System dead, we will be dead too soon! 273 } 274 } 275 276 /** @hide */ 277 public int getPackageScreenCompatMode(String packageName) { 278 try { 279 return ActivityManagerNative.getDefault().getPackageScreenCompatMode(packageName); 280 } catch (RemoteException e) { 281 // System dead, we will be dead too soon! 282 return 0; 283 } 284 } 285 286 /** @hide */ 287 public void setPackageScreenCompatMode(String packageName, int mode) { 288 try { 289 ActivityManagerNative.getDefault().setPackageScreenCompatMode(packageName, mode); 290 } catch (RemoteException e) { 291 // System dead, we will be dead too soon! 292 } 293 } 294 295 /** @hide */ 296 public boolean getPackageAskScreenCompat(String packageName) { 297 try { 298 return ActivityManagerNative.getDefault().getPackageAskScreenCompat(packageName); 299 } catch (RemoteException e) { 300 // System dead, we will be dead too soon! 301 return false; 302 } 303 } 304 305 /** @hide */ 306 public void setPackageAskScreenCompat(String packageName, boolean ask) { 307 try { 308 ActivityManagerNative.getDefault().setPackageAskScreenCompat(packageName, ask); 309 } catch (RemoteException e) { 310 // System dead, we will be dead too soon! 311 } 312 } 313 314 /** 315 * Return the approximate per-application memory class of the current 316 * device. This gives you an idea of how hard a memory limit you should 317 * impose on your application to let the overall system work best. The 318 * returned value is in megabytes; the baseline Android memory class is 319 * 16 (which happens to be the Java heap limit of those devices); some 320 * device with more memory may return 24 or even higher numbers. 321 */ 322 public int getMemoryClass() { 323 return staticGetMemoryClass(); 324 } 325 326 /** @hide */ 327 static public int staticGetMemoryClass() { 328 // Really brain dead right now -- just take this from the configured 329 // vm heap size, and assume it is in megabytes and thus ends with "m". 330 String vmHeapSize = SystemProperties.get("dalvik.vm.heapgrowthlimit", ""); 331 if (vmHeapSize != null && !"".equals(vmHeapSize)) { 332 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1)); 333 } 334 return staticGetLargeMemoryClass(); 335 } 336 337 /** 338 * Return the approximate per-application memory class of the current 339 * device when an application is running with a large heap. This is the 340 * space available for memory-intensive applications; most applications 341 * should not need this amount of memory, and should instead stay with the 342 * {@link #getMemoryClass()} limit. The returned value is in megabytes. 343 * This may be the same size as {@link #getMemoryClass()} on memory 344 * constrained devices, or it may be significantly larger on devices with 345 * a large amount of available RAM. 346 * 347 * <p>The is the size of the application's Dalvik heap if it has 348 * specified <code>android:largeHeap="true"</code> in its manifest. 349 */ 350 public int getLargeMemoryClass() { 351 return staticGetLargeMemoryClass(); 352 } 353 354 /** @hide */ 355 static public int staticGetLargeMemoryClass() { 356 // Really brain dead right now -- just take this from the configured 357 // vm heap size, and assume it is in megabytes and thus ends with "m". 358 String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m"); 359 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1)); 360 } 361 362 /** 363 * Used by persistent processes to determine if they are running on a 364 * higher-end device so should be okay using hardware drawing acceleration 365 * (which tends to consume a lot more RAM). 366 * @hide 367 */ 368 static public boolean isHighEndGfx(Display display) { 369 MemInfoReader reader = new MemInfoReader(); 370 reader.readMemInfo(); 371 if (reader.getTotalSize() >= (512*1024*1024)) { 372 // If the device has at least 512MB RAM available to the kernel, 373 // we can afford the overhead of graphics acceleration. 374 return true; 375 } 376 Point p = new Point(); 377 display.getRealSize(p); 378 int pixels = p.x * p.y; 379 if (pixels >= (1024*600)) { 380 // If this is a sufficiently large screen, then there are enough 381 // pixels on it that we'd really like to use hw drawing. 382 return true; 383 } 384 return false; 385 } 386 387 /** 388 * Use to decide whether the running device can be considered a "large 389 * RAM" device. Exactly what memory limit large RAM is will vary, but 390 * it essentially means there is plenty of RAM to have lots of background 391 * processes running under decent loads. 392 * @hide 393 */ 394 static public boolean isLargeRAM() { 395 MemInfoReader reader = new MemInfoReader(); 396 reader.readMemInfo(); 397 if (reader.getTotalSize() >= (640*1024*1024)) { 398 // Currently 640MB RAM available to the kernel is the point at 399 // which we have plenty of RAM to spare. 400 return true; 401 } 402 return false; 403 } 404 405 /** 406 * Information you can retrieve about tasks that the user has most recently 407 * started or visited. 408 */ 409 public static class RecentTaskInfo implements Parcelable { 410 /** 411 * If this task is currently running, this is the identifier for it. 412 * If it is not running, this will be -1. 413 */ 414 public int id; 415 416 /** 417 * The true identifier of this task, valid even if it is not running. 418 */ 419 public int persistentId; 420 421 /** 422 * The original Intent used to launch the task. You can use this 423 * Intent to re-launch the task (if it is no longer running) or bring 424 * the current task to the front. 425 */ 426 public Intent baseIntent; 427 428 /** 429 * If this task was started from an alias, this is the actual 430 * activity component that was initially started; the component of 431 * the baseIntent in this case is the name of the actual activity 432 * implementation that the alias referred to. Otherwise, this is null. 433 */ 434 public ComponentName origActivity; 435 436 /** 437 * Description of the task's last state. 438 */ 439 public CharSequence description; 440 441 public RecentTaskInfo() { 442 } 443 444 public int describeContents() { 445 return 0; 446 } 447 448 public void writeToParcel(Parcel dest, int flags) { 449 dest.writeInt(id); 450 dest.writeInt(persistentId); 451 if (baseIntent != null) { 452 dest.writeInt(1); 453 baseIntent.writeToParcel(dest, 0); 454 } else { 455 dest.writeInt(0); 456 } 457 ComponentName.writeToParcel(origActivity, dest); 458 TextUtils.writeToParcel(description, dest, 459 Parcelable.PARCELABLE_WRITE_RETURN_VALUE); 460 } 461 462 public void readFromParcel(Parcel source) { 463 id = source.readInt(); 464 persistentId = source.readInt(); 465 if (source.readInt() != 0) { 466 baseIntent = Intent.CREATOR.createFromParcel(source); 467 } else { 468 baseIntent = null; 469 } 470 origActivity = ComponentName.readFromParcel(source); 471 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); 472 } 473 474 public static final Creator<RecentTaskInfo> CREATOR 475 = new Creator<RecentTaskInfo>() { 476 public RecentTaskInfo createFromParcel(Parcel source) { 477 return new RecentTaskInfo(source); 478 } 479 public RecentTaskInfo[] newArray(int size) { 480 return new RecentTaskInfo[size]; 481 } 482 }; 483 484 private RecentTaskInfo(Parcel source) { 485 readFromParcel(source); 486 } 487 } 488 489 /** 490 * Flag for use with {@link #getRecentTasks}: return all tasks, even those 491 * that have set their 492 * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag. 493 */ 494 public static final int RECENT_WITH_EXCLUDED = 0x0001; 495 496 /** 497 * Provides a list that does not contain any 498 * recent tasks that currently are not available to the user. 499 */ 500 public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002; 501 502 /** 503 * Return a list of the tasks that the user has recently launched, with 504 * the most recent being first and older ones after in order. 505 * 506 * @param maxNum The maximum number of entries to return in the list. The 507 * actual number returned may be smaller, depending on how many tasks the 508 * user has started and the maximum number the system can remember. 509 * @param flags Information about what to return. May be any combination 510 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}. 511 * 512 * @return Returns a list of RecentTaskInfo records describing each of 513 * the recent tasks. 514 * 515 * @throws SecurityException Throws SecurityException if the caller does 516 * not hold the {@link android.Manifest.permission#GET_TASKS} permission. 517 */ 518 public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags) 519 throws SecurityException { 520 try { 521 return ActivityManagerNative.getDefault().getRecentTasks(maxNum, 522 flags); 523 } catch (RemoteException e) { 524 // System dead, we will be dead too soon! 525 return null; 526 } 527 } 528 529 /** 530 * Information you can retrieve about a particular task that is currently 531 * "running" in the system. Note that a running task does not mean the 532 * given task actually has a process it is actively running in; it simply 533 * means that the user has gone to it and never closed it, but currently 534 * the system may have killed its process and is only holding on to its 535 * last state in order to restart it when the user returns. 536 */ 537 public static class RunningTaskInfo implements Parcelable { 538 /** 539 * A unique identifier for this task. 540 */ 541 public int id; 542 543 /** 544 * The component launched as the first activity in the task. This can 545 * be considered the "application" of this task. 546 */ 547 public ComponentName baseActivity; 548 549 /** 550 * The activity component at the top of the history stack of the task. 551 * This is what the user is currently doing. 552 */ 553 public ComponentName topActivity; 554 555 /** 556 * Thumbnail representation of the task's current state. Currently 557 * always null. 558 */ 559 public Bitmap thumbnail; 560 561 /** 562 * Description of the task's current state. 563 */ 564 public CharSequence description; 565 566 /** 567 * Number of activities in this task. 568 */ 569 public int numActivities; 570 571 /** 572 * Number of activities that are currently running (not stopped 573 * and persisted) in this task. 574 */ 575 public int numRunning; 576 577 public RunningTaskInfo() { 578 } 579 580 public int describeContents() { 581 return 0; 582 } 583 584 public void writeToParcel(Parcel dest, int flags) { 585 dest.writeInt(id); 586 ComponentName.writeToParcel(baseActivity, dest); 587 ComponentName.writeToParcel(topActivity, dest); 588 if (thumbnail != null) { 589 dest.writeInt(1); 590 thumbnail.writeToParcel(dest, 0); 591 } else { 592 dest.writeInt(0); 593 } 594 TextUtils.writeToParcel(description, dest, 595 Parcelable.PARCELABLE_WRITE_RETURN_VALUE); 596 dest.writeInt(numActivities); 597 dest.writeInt(numRunning); 598 } 599 600 public void readFromParcel(Parcel source) { 601 id = source.readInt(); 602 baseActivity = ComponentName.readFromParcel(source); 603 topActivity = ComponentName.readFromParcel(source); 604 if (source.readInt() != 0) { 605 thumbnail = Bitmap.CREATOR.createFromParcel(source); 606 } else { 607 thumbnail = null; 608 } 609 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); 610 numActivities = source.readInt(); 611 numRunning = source.readInt(); 612 } 613 614 public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() { 615 public RunningTaskInfo createFromParcel(Parcel source) { 616 return new RunningTaskInfo(source); 617 } 618 public RunningTaskInfo[] newArray(int size) { 619 return new RunningTaskInfo[size]; 620 } 621 }; 622 623 private RunningTaskInfo(Parcel source) { 624 readFromParcel(source); 625 } 626 } 627 628 /** 629 * Return a list of the tasks that are currently running, with 630 * the most recent being first and older ones after in order. Note that 631 * "running" does not mean any of the task's code is currently loaded or 632 * activity -- the task may have been frozen by the system, so that it 633 * can be restarted in its previous state when next brought to the 634 * foreground. 635 * 636 * @param maxNum The maximum number of entries to return in the list. The 637 * actual number returned may be smaller, depending on how many tasks the 638 * user has started. 639 * 640 * @param flags Optional flags 641 * @param receiver Optional receiver for delayed thumbnails 642 * 643 * @return Returns a list of RunningTaskInfo records describing each of 644 * the running tasks. 645 * 646 * Some thumbnails may not be available at the time of this call. The optional 647 * receiver may be used to receive those thumbnails. 648 * 649 * @throws SecurityException Throws SecurityException if the caller does 650 * not hold the {@link android.Manifest.permission#GET_TASKS} permission. 651 * 652 * @hide 653 */ 654 public List<RunningTaskInfo> getRunningTasks(int maxNum, int flags, IThumbnailReceiver receiver) 655 throws SecurityException { 656 try { 657 return ActivityManagerNative.getDefault().getTasks(maxNum, flags, receiver); 658 } catch (RemoteException e) { 659 // System dead, we will be dead too soon! 660 return null; 661 } 662 } 663 664 /** 665 * Return a list of the tasks that are currently running, with 666 * the most recent being first and older ones after in order. Note that 667 * "running" does not mean any of the task's code is currently loaded or 668 * activity -- the task may have been frozen by the system, so that it 669 * can be restarted in its previous state when next brought to the 670 * foreground. 671 * 672 * @param maxNum The maximum number of entries to return in the list. The 673 * actual number returned may be smaller, depending on how many tasks the 674 * user has started. 675 * 676 * @return Returns a list of RunningTaskInfo records describing each of 677 * the running tasks. 678 * 679 * @throws SecurityException Throws SecurityException if the caller does 680 * not hold the {@link android.Manifest.permission#GET_TASKS} permission. 681 */ 682 public List<RunningTaskInfo> getRunningTasks(int maxNum) 683 throws SecurityException { 684 return getRunningTasks(maxNum, 0, null); 685 } 686 687 /** 688 * Remove some end of a task's activity stack that is not part of 689 * the main application. The selected activities will be finished, so 690 * they are no longer part of the main task. 691 * 692 * @param taskId The identifier of the task. 693 * @param subTaskIndex The number of the sub-task; this corresponds 694 * to the index of the thumbnail returned by {@link #getTaskThumbnails(int)}. 695 * @return Returns true if the sub-task was found and was removed. 696 * 697 * @hide 698 */ 699 public boolean removeSubTask(int taskId, int subTaskIndex) 700 throws SecurityException { 701 try { 702 return ActivityManagerNative.getDefault().removeSubTask(taskId, subTaskIndex); 703 } catch (RemoteException e) { 704 // System dead, we will be dead too soon! 705 return false; 706 } 707 } 708 709 /** 710 * If set, the process of the root activity of the task will be killed 711 * as part of removing the task. 712 * @hide 713 */ 714 public static final int REMOVE_TASK_KILL_PROCESS = 0x0001; 715 716 /** 717 * Completely remove the given task. 718 * 719 * @param taskId Identifier of the task to be removed. 720 * @param flags Additional operational flags. May be 0 or 721 * {@link #REMOVE_TASK_KILL_PROCESS}. 722 * @return Returns true if the given task was found and removed. 723 * 724 * @hide 725 */ 726 public boolean removeTask(int taskId, int flags) 727 throws SecurityException { 728 try { 729 return ActivityManagerNative.getDefault().removeTask(taskId, flags); 730 } catch (RemoteException e) { 731 // System dead, we will be dead too soon! 732 return false; 733 } 734 } 735 736 /** @hide */ 737 public static class TaskThumbnails implements Parcelable { 738 public Bitmap mainThumbnail; 739 740 public int numSubThumbbails; 741 742 /** @hide */ 743 public IThumbnailRetriever retriever; 744 745 public TaskThumbnails() { 746 } 747 748 public Bitmap getSubThumbnail(int index) { 749 try { 750 return retriever.getThumbnail(index); 751 } catch (RemoteException e) { 752 return null; 753 } 754 } 755 756 public int describeContents() { 757 return 0; 758 } 759 760 public void writeToParcel(Parcel dest, int flags) { 761 if (mainThumbnail != null) { 762 dest.writeInt(1); 763 mainThumbnail.writeToParcel(dest, 0); 764 } else { 765 dest.writeInt(0); 766 } 767 dest.writeInt(numSubThumbbails); 768 dest.writeStrongInterface(retriever); 769 } 770 771 public void readFromParcel(Parcel source) { 772 if (source.readInt() != 0) { 773 mainThumbnail = Bitmap.CREATOR.createFromParcel(source); 774 } else { 775 mainThumbnail = null; 776 } 777 numSubThumbbails = source.readInt(); 778 retriever = IThumbnailRetriever.Stub.asInterface(source.readStrongBinder()); 779 } 780 781 public static final Creator<TaskThumbnails> CREATOR = new Creator<TaskThumbnails>() { 782 public TaskThumbnails createFromParcel(Parcel source) { 783 return new TaskThumbnails(source); 784 } 785 public TaskThumbnails[] newArray(int size) { 786 return new TaskThumbnails[size]; 787 } 788 }; 789 790 private TaskThumbnails(Parcel source) { 791 readFromParcel(source); 792 } 793 } 794 795 /** @hide */ 796 public TaskThumbnails getTaskThumbnails(int id) throws SecurityException { 797 try { 798 return ActivityManagerNative.getDefault().getTaskThumbnails(id); 799 } catch (RemoteException e) { 800 // System dead, we will be dead too soon! 801 return null; 802 } 803 } 804 805 /** 806 * Flag for {@link #moveTaskToFront(int, int)}: also move the "home" 807 * activity along with the task, so it is positioned immediately behind 808 * the task. 809 */ 810 public static final int MOVE_TASK_WITH_HOME = 0x00000001; 811 812 /** 813 * Flag for {@link #moveTaskToFront(int, int)}: don't count this as a 814 * user-instigated action, so the current activity will not receive a 815 * hint that the user is leaving. 816 */ 817 public static final int MOVE_TASK_NO_USER_ACTION = 0x00000002; 818 819 /** 820 * Equivalent to calling {@link #moveTaskToFront(int, int, Bundle)} 821 * with a null options argument. 822 * 823 * @param taskId The identifier of the task to be moved, as found in 824 * {@link RunningTaskInfo} or {@link RecentTaskInfo}. 825 * @param flags Additional operational flags, 0 or more of 826 * {@link #MOVE_TASK_WITH_HOME}. 827 */ 828 public void moveTaskToFront(int taskId, int flags) { 829 moveTaskToFront(taskId, flags, null); 830 } 831 832 /** 833 * Ask that the task associated with a given task ID be moved to the 834 * front of the stack, so it is now visible to the user. Requires that 835 * the caller hold permission {@link android.Manifest.permission#REORDER_TASKS} 836 * or a SecurityException will be thrown. 837 * 838 * @param taskId The identifier of the task to be moved, as found in 839 * {@link RunningTaskInfo} or {@link RecentTaskInfo}. 840 * @param flags Additional operational flags, 0 or more of 841 * {@link #MOVE_TASK_WITH_HOME}. 842 * @param options Additional options for the operation, either null or 843 * as per {@link Context#startActivity(Intent, android.os.Bundle) 844 * Context.startActivity(Intent, Bundle)}. 845 */ 846 public void moveTaskToFront(int taskId, int flags, Bundle options) { 847 try { 848 ActivityManagerNative.getDefault().moveTaskToFront(taskId, flags, options); 849 } catch (RemoteException e) { 850 // System dead, we will be dead too soon! 851 } 852 } 853 854 /** 855 * Information you can retrieve about a particular Service that is 856 * currently running in the system. 857 */ 858 public static class RunningServiceInfo implements Parcelable { 859 /** 860 * The service component. 861 */ 862 public ComponentName service; 863 864 /** 865 * If non-zero, this is the process the service is running in. 866 */ 867 public int pid; 868 869 /** 870 * The UID that owns this service. 871 */ 872 public int uid; 873 874 /** 875 * The name of the process this service runs in. 876 */ 877 public String process; 878 879 /** 880 * Set to true if the service has asked to run as a foreground process. 881 */ 882 public boolean foreground; 883 884 /** 885 * The time when the service was first made active, either by someone 886 * starting or binding to it. This 887 * is in units of {@link android.os.SystemClock#elapsedRealtime()}. 888 */ 889 public long activeSince; 890 891 /** 892 * Set to true if this service has been explicitly started. 893 */ 894 public boolean started; 895 896 /** 897 * Number of clients connected to the service. 898 */ 899 public int clientCount; 900 901 /** 902 * Number of times the service's process has crashed while the service 903 * is running. 904 */ 905 public int crashCount; 906 907 /** 908 * The time when there was last activity in the service (either 909 * explicit requests to start it or clients binding to it). This 910 * is in units of {@link android.os.SystemClock#uptimeMillis()}. 911 */ 912 public long lastActivityTime; 913 914 /** 915 * If non-zero, this service is not currently running, but scheduled to 916 * restart at the given time. 917 */ 918 public long restarting; 919 920 /** 921 * Bit for {@link #flags}: set if this service has been 922 * explicitly started. 923 */ 924 public static final int FLAG_STARTED = 1<<0; 925 926 /** 927 * Bit for {@link #flags}: set if the service has asked to 928 * run as a foreground process. 929 */ 930 public static final int FLAG_FOREGROUND = 1<<1; 931 932 /** 933 * Bit for {@link #flags): set if the service is running in a 934 * core system process. 935 */ 936 public static final int FLAG_SYSTEM_PROCESS = 1<<2; 937 938 /** 939 * Bit for {@link #flags): set if the service is running in a 940 * persistent process. 941 */ 942 public static final int FLAG_PERSISTENT_PROCESS = 1<<3; 943 944 /** 945 * Running flags. 946 */ 947 public int flags; 948 949 /** 950 * For special services that are bound to by system code, this is 951 * the package that holds the binding. 952 */ 953 public String clientPackage; 954 955 /** 956 * For special services that are bound to by system code, this is 957 * a string resource providing a user-visible label for who the 958 * client is. 959 */ 960 public int clientLabel; 961 962 public RunningServiceInfo() { 963 } 964 965 public int describeContents() { 966 return 0; 967 } 968 969 public void writeToParcel(Parcel dest, int flags) { 970 ComponentName.writeToParcel(service, dest); 971 dest.writeInt(pid); 972 dest.writeInt(uid); 973 dest.writeString(process); 974 dest.writeInt(foreground ? 1 : 0); 975 dest.writeLong(activeSince); 976 dest.writeInt(started ? 1 : 0); 977 dest.writeInt(clientCount); 978 dest.writeInt(crashCount); 979 dest.writeLong(lastActivityTime); 980 dest.writeLong(restarting); 981 dest.writeInt(this.flags); 982 dest.writeString(clientPackage); 983 dest.writeInt(clientLabel); 984 } 985 986 public void readFromParcel(Parcel source) { 987 service = ComponentName.readFromParcel(source); 988 pid = source.readInt(); 989 uid = source.readInt(); 990 process = source.readString(); 991 foreground = source.readInt() != 0; 992 activeSince = source.readLong(); 993 started = source.readInt() != 0; 994 clientCount = source.readInt(); 995 crashCount = source.readInt(); 996 lastActivityTime = source.readLong(); 997 restarting = source.readLong(); 998 flags = source.readInt(); 999 clientPackage = source.readString(); 1000 clientLabel = source.readInt(); 1001 } 1002 1003 public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() { 1004 public RunningServiceInfo createFromParcel(Parcel source) { 1005 return new RunningServiceInfo(source); 1006 } 1007 public RunningServiceInfo[] newArray(int size) { 1008 return new RunningServiceInfo[size]; 1009 } 1010 }; 1011 1012 private RunningServiceInfo(Parcel source) { 1013 readFromParcel(source); 1014 } 1015 } 1016 1017 /** 1018 * Return a list of the services that are currently running. 1019 * 1020 * @param maxNum The maximum number of entries to return in the list. The 1021 * actual number returned may be smaller, depending on how many services 1022 * are running. 1023 * 1024 * @return Returns a list of RunningServiceInfo records describing each of 1025 * the running tasks. 1026 */ 1027 public List<RunningServiceInfo> getRunningServices(int maxNum) 1028 throws SecurityException { 1029 try { 1030 return ActivityManagerNative.getDefault() 1031 .getServices(maxNum, 0); 1032 } catch (RemoteException e) { 1033 // System dead, we will be dead too soon! 1034 return null; 1035 } 1036 } 1037 1038 /** 1039 * Returns a PendingIntent you can start to show a control panel for the 1040 * given running service. If the service does not have a control panel, 1041 * null is returned. 1042 */ 1043 public PendingIntent getRunningServiceControlPanel(ComponentName service) 1044 throws SecurityException { 1045 try { 1046 return ActivityManagerNative.getDefault() 1047 .getRunningServiceControlPanel(service); 1048 } catch (RemoteException e) { 1049 // System dead, we will be dead too soon! 1050 return null; 1051 } 1052 } 1053 1054 /** 1055 * Information you can retrieve about the available memory through 1056 * {@link ActivityManager#getMemoryInfo}. 1057 */ 1058 public static class MemoryInfo implements Parcelable { 1059 /** 1060 * The total available memory on the system. This number should not 1061 * be considered absolute: due to the nature of the kernel, a significant 1062 * portion of this memory is actually in use and needed for the overall 1063 * system to run well. 1064 */ 1065 public long availMem; 1066 1067 /** 1068 * The threshold of {@link #availMem} at which we consider memory to be 1069 * low and start killing background services and other non-extraneous 1070 * processes. 1071 */ 1072 public long threshold; 1073 1074 /** 1075 * Set to true if the system considers itself to currently be in a low 1076 * memory situation. 1077 */ 1078 public boolean lowMemory; 1079 1080 /** @hide */ 1081 public long hiddenAppThreshold; 1082 /** @hide */ 1083 public long secondaryServerThreshold; 1084 /** @hide */ 1085 public long visibleAppThreshold; 1086 /** @hide */ 1087 public long foregroundAppThreshold; 1088 1089 public MemoryInfo() { 1090 } 1091 1092 public int describeContents() { 1093 return 0; 1094 } 1095 1096 public void writeToParcel(Parcel dest, int flags) { 1097 dest.writeLong(availMem); 1098 dest.writeLong(threshold); 1099 dest.writeInt(lowMemory ? 1 : 0); 1100 dest.writeLong(hiddenAppThreshold); 1101 dest.writeLong(secondaryServerThreshold); 1102 dest.writeLong(visibleAppThreshold); 1103 dest.writeLong(foregroundAppThreshold); 1104 } 1105 1106 public void readFromParcel(Parcel source) { 1107 availMem = source.readLong(); 1108 threshold = source.readLong(); 1109 lowMemory = source.readInt() != 0; 1110 hiddenAppThreshold = source.readLong(); 1111 secondaryServerThreshold = source.readLong(); 1112 visibleAppThreshold = source.readLong(); 1113 foregroundAppThreshold = source.readLong(); 1114 } 1115 1116 public static final Creator<MemoryInfo> CREATOR 1117 = new Creator<MemoryInfo>() { 1118 public MemoryInfo createFromParcel(Parcel source) { 1119 return new MemoryInfo(source); 1120 } 1121 public MemoryInfo[] newArray(int size) { 1122 return new MemoryInfo[size]; 1123 } 1124 }; 1125 1126 private MemoryInfo(Parcel source) { 1127 readFromParcel(source); 1128 } 1129 } 1130 1131 public void getMemoryInfo(MemoryInfo outInfo) { 1132 try { 1133 ActivityManagerNative.getDefault().getMemoryInfo(outInfo); 1134 } catch (RemoteException e) { 1135 } 1136 } 1137 1138 /** 1139 * @hide 1140 */ 1141 public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) { 1142 try { 1143 return ActivityManagerNative.getDefault().clearApplicationUserData(packageName, 1144 observer, Binder.getOrigCallingUser()); 1145 } catch (RemoteException e) { 1146 return false; 1147 } 1148 } 1149 1150 /** 1151 * Information you can retrieve about any processes that are in an error condition. 1152 */ 1153 public static class ProcessErrorStateInfo implements Parcelable { 1154 /** 1155 * Condition codes 1156 */ 1157 public static final int NO_ERROR = 0; 1158 public static final int CRASHED = 1; 1159 public static final int NOT_RESPONDING = 2; 1160 1161 /** 1162 * The condition that the process is in. 1163 */ 1164 public int condition; 1165 1166 /** 1167 * The process name in which the crash or error occurred. 1168 */ 1169 public String processName; 1170 1171 /** 1172 * The pid of this process; 0 if none 1173 */ 1174 public int pid; 1175 1176 /** 1177 * The kernel user-ID that has been assigned to this process; 1178 * currently this is not a unique ID (multiple applications can have 1179 * the same uid). 1180 */ 1181 public int uid; 1182 1183 /** 1184 * The activity name associated with the error, if known. May be null. 1185 */ 1186 public String tag; 1187 1188 /** 1189 * A short message describing the error condition. 1190 */ 1191 public String shortMsg; 1192 1193 /** 1194 * A long message describing the error condition. 1195 */ 1196 public String longMsg; 1197 1198 /** 1199 * The stack trace where the error originated. May be null. 1200 */ 1201 public String stackTrace; 1202 1203 /** 1204 * to be deprecated: This value will always be null. 1205 */ 1206 public byte[] crashData = null; 1207 1208 public ProcessErrorStateInfo() { 1209 } 1210 1211 public int describeContents() { 1212 return 0; 1213 } 1214 1215 public void writeToParcel(Parcel dest, int flags) { 1216 dest.writeInt(condition); 1217 dest.writeString(processName); 1218 dest.writeInt(pid); 1219 dest.writeInt(uid); 1220 dest.writeString(tag); 1221 dest.writeString(shortMsg); 1222 dest.writeString(longMsg); 1223 dest.writeString(stackTrace); 1224 } 1225 1226 public void readFromParcel(Parcel source) { 1227 condition = source.readInt(); 1228 processName = source.readString(); 1229 pid = source.readInt(); 1230 uid = source.readInt(); 1231 tag = source.readString(); 1232 shortMsg = source.readString(); 1233 longMsg = source.readString(); 1234 stackTrace = source.readString(); 1235 } 1236 1237 public static final Creator<ProcessErrorStateInfo> CREATOR = 1238 new Creator<ProcessErrorStateInfo>() { 1239 public ProcessErrorStateInfo createFromParcel(Parcel source) { 1240 return new ProcessErrorStateInfo(source); 1241 } 1242 public ProcessErrorStateInfo[] newArray(int size) { 1243 return new ProcessErrorStateInfo[size]; 1244 } 1245 }; 1246 1247 private ProcessErrorStateInfo(Parcel source) { 1248 readFromParcel(source); 1249 } 1250 } 1251 1252 /** 1253 * Returns a list of any processes that are currently in an error condition. The result 1254 * will be null if all processes are running properly at this time. 1255 * 1256 * @return Returns a list of ProcessErrorStateInfo records, or null if there are no 1257 * current error conditions (it will not return an empty list). This list ordering is not 1258 * specified. 1259 */ 1260 public List<ProcessErrorStateInfo> getProcessesInErrorState() { 1261 try { 1262 return ActivityManagerNative.getDefault().getProcessesInErrorState(); 1263 } catch (RemoteException e) { 1264 return null; 1265 } 1266 } 1267 1268 /** 1269 * Information you can retrieve about a running process. 1270 */ 1271 public static class RunningAppProcessInfo implements Parcelable { 1272 /** 1273 * The name of the process that this object is associated with 1274 */ 1275 public String processName; 1276 1277 /** 1278 * The pid of this process; 0 if none 1279 */ 1280 public int pid; 1281 1282 /** 1283 * The user id of this process. 1284 */ 1285 public int uid; 1286 1287 /** 1288 * All packages that have been loaded into the process. 1289 */ 1290 public String pkgList[]; 1291 1292 /** 1293 * Constant for {@link #flags}: this is an app that is unable to 1294 * correctly save its state when going to the background, 1295 * so it can not be killed while in the background. 1296 * @hide 1297 */ 1298 public static final int FLAG_CANT_SAVE_STATE = 1<<0; 1299 1300 /** 1301 * Constant for {@link #flags}: this process is associated with a 1302 * persistent system app. 1303 * @hide 1304 */ 1305 public static final int FLAG_PERSISTENT = 1<<1; 1306 1307 /** 1308 * Flags of information. May be any of 1309 * {@link #FLAG_CANT_SAVE_STATE}. 1310 * @hide 1311 */ 1312 public int flags; 1313 1314 /** 1315 * Last memory trim level reported to the process: corresponds to 1316 * the values supplied to {@link android.content.ComponentCallbacks2#onTrimMemory(int) 1317 * ComponentCallbacks2.onTrimMemory(int)}. 1318 */ 1319 public int lastTrimLevel; 1320 1321 /** 1322 * Constant for {@link #importance}: this process is running the 1323 * foreground UI. 1324 */ 1325 public static final int IMPORTANCE_FOREGROUND = 100; 1326 1327 /** 1328 * Constant for {@link #importance}: this process is running something 1329 * that is actively visible to the user, though not in the immediate 1330 * foreground. 1331 */ 1332 public static final int IMPORTANCE_VISIBLE = 200; 1333 1334 /** 1335 * Constant for {@link #importance}: this process is running something 1336 * that is considered to be actively perceptible to the user. An 1337 * example would be an application performing background music playback. 1338 */ 1339 public static final int IMPORTANCE_PERCEPTIBLE = 130; 1340 1341 /** 1342 * Constant for {@link #importance}: this process is running an 1343 * application that can not save its state, and thus can't be killed 1344 * while in the background. 1345 * @hide 1346 */ 1347 public static final int IMPORTANCE_CANT_SAVE_STATE = 170; 1348 1349 /** 1350 * Constant for {@link #importance}: this process is contains services 1351 * that should remain running. 1352 */ 1353 public static final int IMPORTANCE_SERVICE = 300; 1354 1355 /** 1356 * Constant for {@link #importance}: this process process contains 1357 * background code that is expendable. 1358 */ 1359 public static final int IMPORTANCE_BACKGROUND = 400; 1360 1361 /** 1362 * Constant for {@link #importance}: this process is empty of any 1363 * actively running code. 1364 */ 1365 public static final int IMPORTANCE_EMPTY = 500; 1366 1367 /** 1368 * The relative importance level that the system places on this 1369 * process. May be one of {@link #IMPORTANCE_FOREGROUND}, 1370 * {@link #IMPORTANCE_VISIBLE}, {@link #IMPORTANCE_SERVICE}, 1371 * {@link #IMPORTANCE_BACKGROUND}, or {@link #IMPORTANCE_EMPTY}. These 1372 * constants are numbered so that "more important" values are always 1373 * smaller than "less important" values. 1374 */ 1375 public int importance; 1376 1377 /** 1378 * An additional ordering within a particular {@link #importance} 1379 * category, providing finer-grained information about the relative 1380 * utility of processes within a category. This number means nothing 1381 * except that a smaller values are more recently used (and thus 1382 * more important). Currently an LRU value is only maintained for 1383 * the {@link #IMPORTANCE_BACKGROUND} category, though others may 1384 * be maintained in the future. 1385 */ 1386 public int lru; 1387 1388 /** 1389 * Constant for {@link #importanceReasonCode}: nothing special has 1390 * been specified for the reason for this level. 1391 */ 1392 public static final int REASON_UNKNOWN = 0; 1393 1394 /** 1395 * Constant for {@link #importanceReasonCode}: one of the application's 1396 * content providers is being used by another process. The pid of 1397 * the client process is in {@link #importanceReasonPid} and the 1398 * target provider in this process is in 1399 * {@link #importanceReasonComponent}. 1400 */ 1401 public static final int REASON_PROVIDER_IN_USE = 1; 1402 1403 /** 1404 * Constant for {@link #importanceReasonCode}: one of the application's 1405 * content providers is being used by another process. The pid of 1406 * the client process is in {@link #importanceReasonPid} and the 1407 * target provider in this process is in 1408 * {@link #importanceReasonComponent}. 1409 */ 1410 public static final int REASON_SERVICE_IN_USE = 2; 1411 1412 /** 1413 * The reason for {@link #importance}, if any. 1414 */ 1415 public int importanceReasonCode; 1416 1417 /** 1418 * For the specified values of {@link #importanceReasonCode}, this 1419 * is the process ID of the other process that is a client of this 1420 * process. This will be 0 if no other process is using this one. 1421 */ 1422 public int importanceReasonPid; 1423 1424 /** 1425 * For the specified values of {@link #importanceReasonCode}, this 1426 * is the name of the component that is being used in this process. 1427 */ 1428 public ComponentName importanceReasonComponent; 1429 1430 /** 1431 * When {@link importanceReasonPid} is non-0, this is the importance 1432 * of the other pid. @hide 1433 */ 1434 public int importanceReasonImportance; 1435 1436 public RunningAppProcessInfo() { 1437 importance = IMPORTANCE_FOREGROUND; 1438 importanceReasonCode = REASON_UNKNOWN; 1439 } 1440 1441 public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) { 1442 processName = pProcessName; 1443 pid = pPid; 1444 pkgList = pArr; 1445 } 1446 1447 public int describeContents() { 1448 return 0; 1449 } 1450 1451 public void writeToParcel(Parcel dest, int flags) { 1452 dest.writeString(processName); 1453 dest.writeInt(pid); 1454 dest.writeInt(uid); 1455 dest.writeStringArray(pkgList); 1456 dest.writeInt(this.flags); 1457 dest.writeInt(lastTrimLevel); 1458 dest.writeInt(importance); 1459 dest.writeInt(lru); 1460 dest.writeInt(importanceReasonCode); 1461 dest.writeInt(importanceReasonPid); 1462 ComponentName.writeToParcel(importanceReasonComponent, dest); 1463 dest.writeInt(importanceReasonImportance); 1464 } 1465 1466 public void readFromParcel(Parcel source) { 1467 processName = source.readString(); 1468 pid = source.readInt(); 1469 uid = source.readInt(); 1470 pkgList = source.readStringArray(); 1471 flags = source.readInt(); 1472 lastTrimLevel = source.readInt(); 1473 importance = source.readInt(); 1474 lru = source.readInt(); 1475 importanceReasonCode = source.readInt(); 1476 importanceReasonPid = source.readInt(); 1477 importanceReasonComponent = ComponentName.readFromParcel(source); 1478 importanceReasonImportance = source.readInt(); 1479 } 1480 1481 public static final Creator<RunningAppProcessInfo> CREATOR = 1482 new Creator<RunningAppProcessInfo>() { 1483 public RunningAppProcessInfo createFromParcel(Parcel source) { 1484 return new RunningAppProcessInfo(source); 1485 } 1486 public RunningAppProcessInfo[] newArray(int size) { 1487 return new RunningAppProcessInfo[size]; 1488 } 1489 }; 1490 1491 private RunningAppProcessInfo(Parcel source) { 1492 readFromParcel(source); 1493 } 1494 } 1495 1496 /** 1497 * Returns a list of application processes installed on external media 1498 * that are running on the device. 1499 * 1500 * @return Returns a list of ApplicationInfo records, or null if none 1501 * This list ordering is not specified. 1502 * @hide 1503 */ 1504 public List<ApplicationInfo> getRunningExternalApplications() { 1505 try { 1506 return ActivityManagerNative.getDefault().getRunningExternalApplications(); 1507 } catch (RemoteException e) { 1508 return null; 1509 } 1510 } 1511 1512 /** 1513 * Returns a list of application processes that are running on the device. 1514 * 1515 * @return Returns a list of RunningAppProcessInfo records, or null if there are no 1516 * running processes (it will not return an empty list). This list ordering is not 1517 * specified. 1518 */ 1519 public List<RunningAppProcessInfo> getRunningAppProcesses() { 1520 try { 1521 return ActivityManagerNative.getDefault().getRunningAppProcesses(); 1522 } catch (RemoteException e) { 1523 return null; 1524 } 1525 } 1526 1527 /** 1528 * Return global memory state information for the calling process. This 1529 * does not fill in all fields of the {@link RunningAppProcessInfo}. The 1530 * only fields that will be filled in are 1531 * {@link RunningAppProcessInfo#pid}, 1532 * {@link RunningAppProcessInfo#uid}, 1533 * {@link RunningAppProcessInfo#lastTrimLevel}, 1534 * {@link RunningAppProcessInfo#importance}, 1535 * {@link RunningAppProcessInfo#lru}, and 1536 * {@link RunningAppProcessInfo#importanceReasonCode}. 1537 */ 1538 static public void getMyMemoryState(RunningAppProcessInfo outState) { 1539 try { 1540 ActivityManagerNative.getDefault().getMyMemoryState(outState); 1541 } catch (RemoteException e) { 1542 } 1543 } 1544 1545 /** 1546 * Return information about the memory usage of one or more processes. 1547 * 1548 * @param pids The pids of the processes whose memory usage is to be 1549 * retrieved. 1550 * @return Returns an array of memory information, one for each 1551 * requested pid. 1552 */ 1553 public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) { 1554 try { 1555 return ActivityManagerNative.getDefault().getProcessMemoryInfo(pids); 1556 } catch (RemoteException e) { 1557 return null; 1558 } 1559 } 1560 1561 /** 1562 * @deprecated This is now just a wrapper for 1563 * {@link #killBackgroundProcesses(String)}; the previous behavior here 1564 * is no longer available to applications because it allows them to 1565 * break other applications by removing their alarms, stopping their 1566 * services, etc. 1567 */ 1568 @Deprecated 1569 public void restartPackage(String packageName) { 1570 killBackgroundProcesses(packageName); 1571 } 1572 1573 /** 1574 * Have the system immediately kill all background processes associated 1575 * with the given package. This is the same as the kernel killing those 1576 * processes to reclaim memory; the system will take care of restarting 1577 * these processes in the future as needed. 1578 * 1579 * <p>You must hold the permission 1580 * {@link android.Manifest.permission#KILL_BACKGROUND_PROCESSES} to be able to 1581 * call this method. 1582 * 1583 * @param packageName The name of the package whose processes are to 1584 * be killed. 1585 */ 1586 public void killBackgroundProcesses(String packageName) { 1587 try { 1588 ActivityManagerNative.getDefault().killBackgroundProcesses(packageName); 1589 } catch (RemoteException e) { 1590 } 1591 } 1592 1593 /** 1594 * Have the system perform a force stop of everything associated with 1595 * the given application package. All processes that share its uid 1596 * will be killed, all services it has running stopped, all activities 1597 * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED} 1598 * broadcast will be sent, so that any of its registered alarms can 1599 * be stopped, notifications removed, etc. 1600 * 1601 * <p>You must hold the permission 1602 * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to 1603 * call this method. 1604 * 1605 * @param packageName The name of the package to be stopped. 1606 * 1607 * @hide This is not available to third party applications due to 1608 * it allowing them to break other applications by stopping their 1609 * services, removing their alarms, etc. 1610 */ 1611 public void forceStopPackage(String packageName) { 1612 try { 1613 ActivityManagerNative.getDefault().forceStopPackage(packageName); 1614 } catch (RemoteException e) { 1615 } 1616 } 1617 1618 /** 1619 * Get the device configuration attributes. 1620 */ 1621 public ConfigurationInfo getDeviceConfigurationInfo() { 1622 try { 1623 return ActivityManagerNative.getDefault().getDeviceConfigurationInfo(); 1624 } catch (RemoteException e) { 1625 } 1626 return null; 1627 } 1628 1629 /** 1630 * Get the preferred density of icons for the launcher. This is used when 1631 * custom drawables are created (e.g., for shortcuts). 1632 * 1633 * @return density in terms of DPI 1634 */ 1635 public int getLauncherLargeIconDensity() { 1636 final Resources res = mContext.getResources(); 1637 final int density = res.getDisplayMetrics().densityDpi; 1638 final int sw = res.getConfiguration().smallestScreenWidthDp; 1639 1640 if (sw < 600) { 1641 // Smaller than approx 7" tablets, use the regular icon size. 1642 return density; 1643 } 1644 1645 switch (density) { 1646 case DisplayMetrics.DENSITY_LOW: 1647 return DisplayMetrics.DENSITY_MEDIUM; 1648 case DisplayMetrics.DENSITY_MEDIUM: 1649 return DisplayMetrics.DENSITY_HIGH; 1650 case DisplayMetrics.DENSITY_HIGH: 1651 return DisplayMetrics.DENSITY_XHIGH; 1652 case DisplayMetrics.DENSITY_XHIGH: 1653 return DisplayMetrics.DENSITY_XXHIGH; 1654 case DisplayMetrics.DENSITY_XXHIGH: 1655 return DisplayMetrics.DENSITY_XHIGH * 2; 1656 default: 1657 // The density is some abnormal value. Return some other 1658 // abnormal value that is a reasonable scaling of it. 1659 return (int)(density*1.5f); 1660 } 1661 } 1662 1663 /** 1664 * Get the preferred launcher icon size. This is used when custom drawables 1665 * are created (e.g., for shortcuts). 1666 * 1667 * @return dimensions of square icons in terms of pixels 1668 */ 1669 public int getLauncherLargeIconSize() { 1670 final Resources res = mContext.getResources(); 1671 final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size); 1672 final int sw = res.getConfiguration().smallestScreenWidthDp; 1673 1674 if (sw < 600) { 1675 // Smaller than approx 7" tablets, use the regular icon size. 1676 return size; 1677 } 1678 1679 final int density = res.getDisplayMetrics().densityDpi; 1680 1681 switch (density) { 1682 case DisplayMetrics.DENSITY_LOW: 1683 return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW; 1684 case DisplayMetrics.DENSITY_MEDIUM: 1685 return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM; 1686 case DisplayMetrics.DENSITY_HIGH: 1687 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH; 1688 case DisplayMetrics.DENSITY_XHIGH: 1689 return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH; 1690 case DisplayMetrics.DENSITY_XXHIGH: 1691 return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH; 1692 default: 1693 // The density is some abnormal value. Return some other 1694 // abnormal value that is a reasonable scaling of it. 1695 return (int)(size*1.5f); 1696 } 1697 } 1698 1699 /** 1700 * Returns "true" if the user interface is currently being messed with 1701 * by a monkey. 1702 */ 1703 public static boolean isUserAMonkey() { 1704 try { 1705 return ActivityManagerNative.getDefault().isUserAMonkey(); 1706 } catch (RemoteException e) { 1707 } 1708 return false; 1709 } 1710 1711 /** 1712 * Returns "true" if device is running in a test harness. 1713 */ 1714 public static boolean isRunningInTestHarness() { 1715 return SystemProperties.getBoolean("ro.test_harness", false); 1716 } 1717 1718 /** 1719 * Returns the launch count of each installed package. 1720 * 1721 * @hide 1722 */ 1723 public Map<String, Integer> getAllPackageLaunchCounts() { 1724 try { 1725 IUsageStats usageStatsService = IUsageStats.Stub.asInterface( 1726 ServiceManager.getService("usagestats")); 1727 if (usageStatsService == null) { 1728 return new HashMap<String, Integer>(); 1729 } 1730 1731 PkgUsageStats[] allPkgUsageStats = usageStatsService.getAllPkgUsageStats(); 1732 if (allPkgUsageStats == null) { 1733 return new HashMap<String, Integer>(); 1734 } 1735 1736 Map<String, Integer> launchCounts = new HashMap<String, Integer>(); 1737 for (PkgUsageStats pkgUsageStats : allPkgUsageStats) { 1738 launchCounts.put(pkgUsageStats.packageName, pkgUsageStats.launchCount); 1739 } 1740 1741 return launchCounts; 1742 } catch (RemoteException e) { 1743 Log.w(TAG, "Could not query launch counts", e); 1744 return new HashMap<String, Integer>(); 1745 } 1746 } 1747 1748 /** 1749 * Returns the usage statistics of each installed package. 1750 * 1751 * @hide 1752 */ 1753 public PkgUsageStats[] getAllPackageUsageStats() { 1754 try { 1755 IUsageStats usageStatsService = IUsageStats.Stub.asInterface( 1756 ServiceManager.getService("usagestats")); 1757 if (usageStatsService != null) { 1758 return usageStatsService.getAllPkgUsageStats(); 1759 } 1760 } catch (RemoteException e) { 1761 Log.w(TAG, "Could not query usage stats", e); 1762 } 1763 return new PkgUsageStats[0]; 1764 } 1765 1766 /** 1767 * @param userid the user's id. Zero indicates the default user 1768 * @hide 1769 */ 1770 public boolean switchUser(int userid) { 1771 try { 1772 return ActivityManagerNative.getDefault().switchUser(userid); 1773 } catch (RemoteException e) { 1774 return false; 1775 } 1776 } 1777} 1778