ActivityManager.java revision 21b6058fff4fb2448394b4b4ea3ae28e44c0f69d
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.Manifest; 20import android.annotation.IntDef; 21import android.annotation.NonNull; 22import android.annotation.Nullable; 23import android.annotation.RequiresPermission; 24import android.annotation.SystemApi; 25import android.graphics.Canvas; 26import android.graphics.Matrix; 27import android.graphics.Point; 28import android.os.BatteryStats; 29import android.os.IBinder; 30import android.os.ParcelFileDescriptor; 31 32import android.util.Log; 33import com.android.internal.app.ProcessStats; 34import com.android.internal.os.TransferPipe; 35import com.android.internal.util.FastPrintWriter; 36 37import android.content.ComponentName; 38import android.content.Context; 39import android.content.Intent; 40import android.content.UriPermission; 41import android.content.pm.ApplicationInfo; 42import android.content.pm.ConfigurationInfo; 43import android.content.pm.IPackageDataObserver; 44import android.content.pm.PackageManager; 45import android.content.pm.ParceledListSlice; 46import android.content.pm.UserInfo; 47import android.content.res.Resources; 48import android.graphics.Bitmap; 49import android.graphics.Color; 50import android.graphics.Rect; 51import android.os.Bundle; 52import android.os.Debug; 53import android.os.Handler; 54import android.os.Parcel; 55import android.os.Parcelable; 56import android.os.Process; 57import android.os.RemoteException; 58import android.os.ServiceManager; 59import android.os.SystemProperties; 60import android.os.UserHandle; 61import android.text.TextUtils; 62import android.util.DisplayMetrics; 63import android.util.Size; 64import android.util.Slog; 65 66import org.xmlpull.v1.XmlSerializer; 67 68import java.io.FileDescriptor; 69import java.io.FileOutputStream; 70import java.io.IOException; 71import java.io.PrintWriter; 72import java.lang.annotation.Retention; 73import java.lang.annotation.RetentionPolicy; 74import java.util.ArrayList; 75import java.util.List; 76 77/** 78 * Interact with the overall activities running in the system. 79 */ 80public class ActivityManager { 81 private static String TAG = "ActivityManager"; 82 83 private static int gMaxRecentTasks = -1; 84 85 private final Context mContext; 86 private final Handler mHandler; 87 88 /** 89 * Defines acceptable types of bugreports. 90 * @hide 91 */ 92 @Retention(RetentionPolicy.SOURCE) 93 @IntDef({ 94 BUGREPORT_OPTION_FULL, 95 BUGREPORT_OPTION_INTERACTIVE, 96 BUGREPORT_OPTION_REMOTE 97 }) 98 public @interface BugreportMode {} 99 /** 100 * Takes a bugreport without user interference (and hence causing less 101 * interference to the system), but includes all sections. 102 * @hide 103 */ 104 public static final int BUGREPORT_OPTION_FULL = 0; 105 /** 106 * Allows user to monitor progress and enter additional data; might not include all 107 * sections. 108 * @hide 109 */ 110 public static final int BUGREPORT_OPTION_INTERACTIVE = 1; 111 /** 112 * Takes a bugreport requested remotely by administrator of the Device Owner app, 113 * not the device's user. 114 * @hide 115 */ 116 public static final int BUGREPORT_OPTION_REMOTE = 2; 117 118 /** 119 * <a href="{@docRoot}guide/topics/manifest/meta-data-element.html">{@code 120 * <meta-data>}</a> name for a 'home' Activity that declares a package that is to be 121 * uninstalled in lieu of the declaring one. The package named here must be 122 * signed with the same certificate as the one declaring the {@code <meta-data>}. 123 */ 124 public static final String META_HOME_ALTERNATE = "android.app.home.alternate"; 125 126 /** 127 * Result for IActivityManager.startActivity: trying to start a background user 128 * activity that shouldn't be displayed for all users. 129 * @hide 130 */ 131 public static final int START_NOT_CURRENT_USER_ACTIVITY = -8; 132 133 /** 134 * Result for IActivityManager.startActivity: trying to start an activity under voice 135 * control when that activity does not support the VOICE category. 136 * @hide 137 */ 138 public static final int START_NOT_VOICE_COMPATIBLE = -7; 139 140 /** 141 * Result for IActivityManager.startActivity: an error where the 142 * start had to be canceled. 143 * @hide 144 */ 145 public static final int START_CANCELED = -6; 146 147 /** 148 * Result for IActivityManager.startActivity: an error where the 149 * thing being started is not an activity. 150 * @hide 151 */ 152 public static final int START_NOT_ACTIVITY = -5; 153 154 /** 155 * Result for IActivityManager.startActivity: an error where the 156 * caller does not have permission to start the activity. 157 * @hide 158 */ 159 public static final int START_PERMISSION_DENIED = -4; 160 161 /** 162 * Result for IActivityManager.startActivity: an error where the 163 * caller has requested both to forward a result and to receive 164 * a result. 165 * @hide 166 */ 167 public static final int START_FORWARD_AND_REQUEST_CONFLICT = -3; 168 169 /** 170 * Result for IActivityManager.startActivity: an error where the 171 * requested class is not found. 172 * @hide 173 */ 174 public static final int START_CLASS_NOT_FOUND = -2; 175 176 /** 177 * Result for IActivityManager.startActivity: an error where the 178 * given Intent could not be resolved to an activity. 179 * @hide 180 */ 181 public static final int START_INTENT_NOT_RESOLVED = -1; 182 183 /** 184 * Result for IActivityManaqer.startActivity: the activity was started 185 * successfully as normal. 186 * @hide 187 */ 188 public static final int START_SUCCESS = 0; 189 190 /** 191 * Result for IActivityManaqer.startActivity: the caller asked that the Intent not 192 * be executed if it is the recipient, and that is indeed the case. 193 * @hide 194 */ 195 public static final int START_RETURN_INTENT_TO_CALLER = 1; 196 197 /** 198 * Result for IActivityManaqer.startActivity: activity wasn't really started, but 199 * a task was simply brought to the foreground. 200 * @hide 201 */ 202 public static final int START_TASK_TO_FRONT = 2; 203 204 /** 205 * Result for IActivityManaqer.startActivity: activity wasn't really started, but 206 * the given Intent was given to the existing top activity. 207 * @hide 208 */ 209 public static final int START_DELIVERED_TO_TOP = 3; 210 211 /** 212 * Result for IActivityManaqer.startActivity: request was canceled because 213 * app switches are temporarily canceled to ensure the user's last request 214 * (such as pressing home) is performed. 215 * @hide 216 */ 217 public static final int START_SWITCHES_CANCELED = 4; 218 219 /** 220 * Result for IActivityManaqer.startActivity: a new activity was attempted to be started 221 * while in Lock Task Mode. 222 * @hide 223 */ 224 public static final int START_RETURN_LOCK_TASK_MODE_VIOLATION = 5; 225 226 /** 227 * Flag for IActivityManaqer.startActivity: do special start mode where 228 * a new activity is launched only if it is needed. 229 * @hide 230 */ 231 public static final int START_FLAG_ONLY_IF_NEEDED = 1<<0; 232 233 /** 234 * Flag for IActivityManaqer.startActivity: launch the app for 235 * debugging. 236 * @hide 237 */ 238 public static final int START_FLAG_DEBUG = 1<<1; 239 240 /** 241 * Flag for IActivityManaqer.startActivity: launch the app for 242 * allocation tracking. 243 * @hide 244 */ 245 public static final int START_FLAG_TRACK_ALLOCATION = 1<<2; 246 247 /** 248 * Result for IActivityManaqer.broadcastIntent: success! 249 * @hide 250 */ 251 public static final int BROADCAST_SUCCESS = 0; 252 253 /** 254 * Result for IActivityManaqer.broadcastIntent: attempt to broadcast 255 * a sticky intent without appropriate permission. 256 * @hide 257 */ 258 public static final int BROADCAST_STICKY_CANT_HAVE_PERMISSION = -1; 259 260 /** 261 * Result for IActivityManager.broadcastIntent: trying to send a broadcast 262 * to a stopped user. Fail. 263 * @hide 264 */ 265 public static final int BROADCAST_FAILED_USER_STOPPED = -2; 266 267 /** 268 * Type for IActivityManaqer.getIntentSender: this PendingIntent is 269 * for a sendBroadcast operation. 270 * @hide 271 */ 272 public static final int INTENT_SENDER_BROADCAST = 1; 273 274 /** 275 * Type for IActivityManaqer.getIntentSender: this PendingIntent is 276 * for a startActivity operation. 277 * @hide 278 */ 279 public static final int INTENT_SENDER_ACTIVITY = 2; 280 281 /** 282 * Type for IActivityManaqer.getIntentSender: this PendingIntent is 283 * for an activity result operation. 284 * @hide 285 */ 286 public static final int INTENT_SENDER_ACTIVITY_RESULT = 3; 287 288 /** 289 * Type for IActivityManaqer.getIntentSender: this PendingIntent is 290 * for a startService operation. 291 * @hide 292 */ 293 public static final int INTENT_SENDER_SERVICE = 4; 294 295 /** @hide User operation call: success! */ 296 public static final int USER_OP_SUCCESS = 0; 297 298 /** @hide User operation call: given user id is not known. */ 299 public static final int USER_OP_UNKNOWN_USER = -1; 300 301 /** @hide User operation call: given user id is the current user, can't be stopped. */ 302 public static final int USER_OP_IS_CURRENT = -2; 303 304 /** @hide User operation call: system user can't be stopped. */ 305 public static final int USER_OP_ERROR_IS_SYSTEM = -3; 306 307 /** @hide User operation call: one of related users cannot be stopped. */ 308 public static final int USER_OP_ERROR_RELATED_USERS_CANNOT_STOP = -4; 309 310 /** @hide Process does not exist. */ 311 public static final int PROCESS_STATE_NONEXISTENT = -1; 312 313 /** @hide Process is a persistent system process. */ 314 public static final int PROCESS_STATE_PERSISTENT = 0; 315 316 /** @hide Process is a persistent system process and is doing UI. */ 317 public static final int PROCESS_STATE_PERSISTENT_UI = 1; 318 319 /** @hide Process is hosting the current top activities. Note that this covers 320 * all activities that are visible to the user. */ 321 public static final int PROCESS_STATE_TOP = 2; 322 323 /** @hide Process is hosting a foreground service due to a system binding. */ 324 public static final int PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 3; 325 326 /** @hide Process is hosting a foreground service. */ 327 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 4; 328 329 /** @hide Same as {@link #PROCESS_STATE_TOP} but while device is sleeping. */ 330 public static final int PROCESS_STATE_TOP_SLEEPING = 5; 331 332 /** @hide Process is important to the user, and something they are aware of. */ 333 public static final int PROCESS_STATE_IMPORTANT_FOREGROUND = 6; 334 335 /** @hide Process is important to the user, but not something they are aware of. */ 336 public static final int PROCESS_STATE_IMPORTANT_BACKGROUND = 7; 337 338 /** @hide Process is in the background running a backup/restore operation. */ 339 public static final int PROCESS_STATE_BACKUP = 8; 340 341 /** @hide Process is in the background, but it can't restore its state so we want 342 * to try to avoid killing it. */ 343 public static final int PROCESS_STATE_HEAVY_WEIGHT = 9; 344 345 /** @hide Process is in the background running a service. Unlike oom_adj, this level 346 * is used for both the normal running in background state and the executing 347 * operations state. */ 348 public static final int PROCESS_STATE_SERVICE = 10; 349 350 /** @hide Process is in the background running a receiver. Note that from the 351 * perspective of oom_adj receivers run at a higher foreground level, but for our 352 * prioritization here that is not necessary and putting them below services means 353 * many fewer changes in some process states as they receive broadcasts. */ 354 public static final int PROCESS_STATE_RECEIVER = 11; 355 356 /** @hide Process is in the background but hosts the home activity. */ 357 public static final int PROCESS_STATE_HOME = 12; 358 359 /** @hide Process is in the background but hosts the last shown activity. */ 360 public static final int PROCESS_STATE_LAST_ACTIVITY = 13; 361 362 /** @hide Process is being cached for later use and contains activities. */ 363 public static final int PROCESS_STATE_CACHED_ACTIVITY = 14; 364 365 /** @hide Process is being cached for later use and is a client of another cached 366 * process that contains activities. */ 367 public static final int PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 15; 368 369 /** @hide Process is being cached for later use and is empty. */ 370 public static final int PROCESS_STATE_CACHED_EMPTY = 16; 371 372 /** @hide Should this process state be considered a background state? */ 373 public static final boolean isProcStateBackground(int procState) { 374 return procState >= PROCESS_STATE_BACKUP; 375 } 376 377 /** @hide requestType for assist context: only basic information. */ 378 public static final int ASSIST_CONTEXT_BASIC = 0; 379 380 /** @hide requestType for assist context: generate full AssistStructure. */ 381 public static final int ASSIST_CONTEXT_FULL = 1; 382 383 /** @hide Flag for registerUidObserver: report changes in process state. */ 384 public static final int UID_OBSERVER_PROCSTATE = 1<<0; 385 386 /** @hide Flag for registerUidObserver: report uid gone. */ 387 public static final int UID_OBSERVER_GONE = 1<<1; 388 389 /** @hide Flag for registerUidObserver: report uid has become idle. */ 390 public static final int UID_OBSERVER_IDLE = 1<<2; 391 392 /** @hide Flag for registerUidObserver: report uid has become active. */ 393 public static final int UID_OBSERVER_ACTIVE = 1<<3; 394 395 /** @hide Mode for {@link IActivityManager#getAppStartMode}: normal free-to-run operation. */ 396 public static final int APP_START_MODE_NORMAL = 0; 397 398 /** @hide Mode for {@link IActivityManager#getAppStartMode}: delay running until later. */ 399 public static final int APP_START_MODE_DELAYED = 1; 400 401 /** @hide Mode for {@link IActivityManager#getAppStartMode}: disable/cancel pending 402 * launches. */ 403 public static final int APP_START_MODE_DISABLED = 2; 404 405 /** 406 * Lock task mode is not active. 407 */ 408 public static final int LOCK_TASK_MODE_NONE = 0; 409 410 /** 411 * Full lock task mode is active. 412 */ 413 public static final int LOCK_TASK_MODE_LOCKED = 1; 414 415 /** 416 * App pinning mode is active. 417 */ 418 public static final int LOCK_TASK_MODE_PINNED = 2; 419 420 Point mAppTaskThumbnailSize; 421 422 /*package*/ ActivityManager(Context context, Handler handler) { 423 mContext = context; 424 mHandler = handler; 425 } 426 427 /** 428 * Screen compatibility mode: the application most always run in 429 * compatibility mode. 430 * @hide 431 */ 432 public static final int COMPAT_MODE_ALWAYS = -1; 433 434 /** 435 * Screen compatibility mode: the application can never run in 436 * compatibility mode. 437 * @hide 438 */ 439 public static final int COMPAT_MODE_NEVER = -2; 440 441 /** 442 * Screen compatibility mode: unknown. 443 * @hide 444 */ 445 public static final int COMPAT_MODE_UNKNOWN = -3; 446 447 /** 448 * Screen compatibility mode: the application currently has compatibility 449 * mode disabled. 450 * @hide 451 */ 452 public static final int COMPAT_MODE_DISABLED = 0; 453 454 /** 455 * Screen compatibility mode: the application currently has compatibility 456 * mode enabled. 457 * @hide 458 */ 459 public static final int COMPAT_MODE_ENABLED = 1; 460 461 /** 462 * Screen compatibility mode: request to toggle the application's 463 * compatibility mode. 464 * @hide 465 */ 466 public static final int COMPAT_MODE_TOGGLE = 2; 467 468 /** @hide */ 469 public static class StackId { 470 /** Invalid stack ID. */ 471 public static final int INVALID_STACK_ID = -1; 472 473 /** First static stack ID. */ 474 public static final int FIRST_STATIC_STACK_ID = 0; 475 476 /** Home activity stack ID. */ 477 public static final int HOME_STACK_ID = FIRST_STATIC_STACK_ID; 478 479 /** ID of stack where fullscreen activities are normally launched into. */ 480 public static final int FULLSCREEN_WORKSPACE_STACK_ID = 1; 481 482 /** ID of stack where freeform/resized activities are normally launched into. */ 483 public static final int FREEFORM_WORKSPACE_STACK_ID = FULLSCREEN_WORKSPACE_STACK_ID + 1; 484 485 /** ID of stack that occupies a dedicated region of the screen. */ 486 public static final int DOCKED_STACK_ID = FREEFORM_WORKSPACE_STACK_ID + 1; 487 488 /** ID of stack that always on top (always visible) when it exist. */ 489 public static final int PINNED_STACK_ID = DOCKED_STACK_ID + 1; 490 491 /** Last static stack stack ID. */ 492 public static final int LAST_STATIC_STACK_ID = PINNED_STACK_ID; 493 494 /** Start of ID range used by stacks that are created dynamically. */ 495 public static final int FIRST_DYNAMIC_STACK_ID = LAST_STATIC_STACK_ID + 1; 496 497 public static boolean isStaticStack(int stackId) { 498 return stackId >= FIRST_STATIC_STACK_ID && stackId <= LAST_STATIC_STACK_ID; 499 } 500 501 /** 502 * Returns true if the activities contained in the input stack display a shadow around 503 * their border. 504 */ 505 public static boolean hasWindowShadow(int stackId) { 506 return stackId == FREEFORM_WORKSPACE_STACK_ID || stackId == PINNED_STACK_ID; 507 } 508 509 /** 510 * Returns true if the activities contained in the input stack display a decor view. 511 */ 512 public static boolean hasWindowDecor(int stackId) { 513 return stackId == FREEFORM_WORKSPACE_STACK_ID; 514 } 515 516 /** 517 * Returns true if the tasks contained in the stack can be resized independently of the 518 * stack. 519 */ 520 public static boolean isTaskResizeAllowed(int stackId) { 521 return stackId == FREEFORM_WORKSPACE_STACK_ID; 522 } 523 524 /** Returns true if the task bounds should persist across power cycles. */ 525 public static boolean persistTaskBounds(int stackId) { 526 return stackId == FREEFORM_WORKSPACE_STACK_ID; 527 } 528 529 /** 530 * Returns true if dynamic stacks are allowed to be visible behind the input stack. 531 */ 532 public static boolean isDynamicStacksVisibleBehindAllowed(int stackId) { 533 return stackId == PINNED_STACK_ID; 534 } 535 536 /** 537 * Returns true if we try to maintain focus in the current stack when the top activity 538 * finishes. 539 */ 540 public static boolean keepFocusInStackIfPossible(int stackId) { 541 return stackId == FREEFORM_WORKSPACE_STACK_ID 542 || stackId == DOCKED_STACK_ID || stackId == PINNED_STACK_ID; 543 } 544 545 /** 546 * Returns true if Stack size is affected by the docked stack changing size. 547 */ 548 public static boolean isResizeableByDockedStack(int stackId) { 549 return isStaticStack(stackId) && 550 stackId != DOCKED_STACK_ID && stackId != PINNED_STACK_ID; 551 } 552 553 /** 554 * Returns true if the size of tasks in the input stack are affected by the docked stack 555 * changing size. 556 */ 557 public static boolean isTaskResizeableByDockedStack(int stackId) { 558 return isStaticStack(stackId) && stackId != FREEFORM_WORKSPACE_STACK_ID 559 && stackId != DOCKED_STACK_ID && stackId != PINNED_STACK_ID; 560 } 561 562 /** 563 * Returns true if the windows of tasks being moved to this stack should be preserved so 564 * there isn't a display gap. 565 */ 566 public static boolean preserveWindowOnTaskMove(int stackId) { 567 return stackId == FULLSCREEN_WORKSPACE_STACK_ID || stackId == DOCKED_STACK_ID; 568 } 569 570 /** 571 * Returns true if animation specs should be constructed for app transition that moves 572 * the task to the specified stack. 573 */ 574 public static boolean useAnimationSpecForAppTransition(int stackId) { 575 return stackId == FREEFORM_WORKSPACE_STACK_ID 576 || stackId == FULLSCREEN_WORKSPACE_STACK_ID || stackId == DOCKED_STACK_ID; 577 } 578 579 /** Returns true if the windows in the stack can receive input keys. */ 580 public static boolean canReceiveKeys(int stackId) { 581 return stackId != PINNED_STACK_ID; 582 } 583 584 /** 585 * Returns true if the stack can be visible above lockscreen. 586 */ 587 public static boolean isAllowedOverLockscreen(int stackId) { 588 return stackId == HOME_STACK_ID || stackId == FULLSCREEN_WORKSPACE_STACK_ID; 589 } 590 591 public static boolean isAlwaysOnTop(int stackId) { 592 return stackId == PINNED_STACK_ID; 593 } 594 595 /** 596 * Returns true if the top task in the task is allowed to return home when finished and 597 * there are other tasks in the stack. 598 */ 599 public static boolean allowTopTaskToReturnHome(int stackId) { 600 return stackId != PINNED_STACK_ID; 601 } 602 603 /** 604 * Returns true if the stack should be resized to match the bounds specified by 605 * {@link ActivityOptions#setLaunchBounds} when launching an activity into the stack. 606 */ 607 public static boolean resizeStackWithLaunchBounds(int stackId) { 608 return stackId == PINNED_STACK_ID; 609 } 610 611 /** 612 * Returns true if any visible windows belonging to apps in this stack should be kept on 613 * screen when the app is killed due to something like the low memory killer. 614 */ 615 public static boolean keepVisibleDeadAppWindowOnScreen(int stackId) { 616 return stackId != PINNED_STACK_ID; 617 } 618 619 /** 620 * Returns true if the backdrop on the client side should match the frame of the window. 621 * Returns false, if the backdrop should be fullscreen. 622 */ 623 public static boolean useWindowFrameForBackdrop(int stackId) { 624 return stackId == FREEFORM_WORKSPACE_STACK_ID || stackId == PINNED_STACK_ID; 625 } 626 } 627 628 /** 629 * Input parameter to {@link android.app.IActivityManager#moveTaskToDockedStack} which 630 * specifies the position of the created docked stack at the top half of the screen if 631 * in portrait mode or at the left half of the screen if in landscape mode. 632 * @hide 633 */ 634 public static final int DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT = 0; 635 636 /** 637 * Input parameter to {@link android.app.IActivityManager#moveTaskToDockedStack} which 638 * specifies the position of the created docked stack at the bottom half of the screen if 639 * in portrait mode or at the right half of the screen if in landscape mode. 640 * @hide 641 */ 642 public static final int DOCKED_STACK_CREATE_MODE_BOTTOM_OR_RIGHT = 1; 643 644 /** 645 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates 646 * that the resize doesn't need to preserve the window, and can be skipped if bounds 647 * is unchanged. This mode is used by window manager in most cases. 648 * @hide 649 */ 650 public static final int RESIZE_MODE_SYSTEM = 0; 651 652 /** 653 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates 654 * that the resize should preserve the window if possible. 655 * @hide 656 */ 657 public static final int RESIZE_MODE_PRESERVE_WINDOW = (0x1 << 0); 658 659 /** 660 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates 661 * that the resize should be performed even if the bounds appears unchanged. 662 * @hide 663 */ 664 public static final int RESIZE_MODE_FORCED = (0x1 << 1); 665 666 /** 667 * Input parameter to {@link android.app.IActivityManager#resizeTask} used by window 668 * manager during a screen rotation. 669 * @hide 670 */ 671 public static final int RESIZE_MODE_SYSTEM_SCREEN_ROTATION = RESIZE_MODE_PRESERVE_WINDOW; 672 673 /** 674 * Input parameter to {@link android.app.IActivityManager#resizeTask} used when the 675 * resize is due to a drag action. 676 * @hide 677 */ 678 public static final int RESIZE_MODE_USER = RESIZE_MODE_PRESERVE_WINDOW; 679 680 /** 681 * Input parameter to {@link android.app.IActivityManager#resizeTask} which indicates 682 * that the resize should preserve the window if possible, and should not be skipped 683 * even if the bounds is unchanged. Usually used to force a resizing when a drag action 684 * is ending. 685 * @hide 686 */ 687 public static final int RESIZE_MODE_USER_FORCED = 688 RESIZE_MODE_PRESERVE_WINDOW | RESIZE_MODE_FORCED; 689 690 /** @hide */ 691 public int getFrontActivityScreenCompatMode() { 692 try { 693 return ActivityManagerNative.getDefault().getFrontActivityScreenCompatMode(); 694 } catch (RemoteException e) { 695 // System dead, we will be dead too soon! 696 return 0; 697 } 698 } 699 700 /** @hide */ 701 public void setFrontActivityScreenCompatMode(int mode) { 702 try { 703 ActivityManagerNative.getDefault().setFrontActivityScreenCompatMode(mode); 704 } catch (RemoteException e) { 705 // System dead, we will be dead too soon! 706 } 707 } 708 709 /** @hide */ 710 public int getPackageScreenCompatMode(String packageName) { 711 try { 712 return ActivityManagerNative.getDefault().getPackageScreenCompatMode(packageName); 713 } catch (RemoteException e) { 714 // System dead, we will be dead too soon! 715 return 0; 716 } 717 } 718 719 /** @hide */ 720 public void setPackageScreenCompatMode(String packageName, int mode) { 721 try { 722 ActivityManagerNative.getDefault().setPackageScreenCompatMode(packageName, mode); 723 } catch (RemoteException e) { 724 // System dead, we will be dead too soon! 725 } 726 } 727 728 /** @hide */ 729 public boolean getPackageAskScreenCompat(String packageName) { 730 try { 731 return ActivityManagerNative.getDefault().getPackageAskScreenCompat(packageName); 732 } catch (RemoteException e) { 733 // System dead, we will be dead too soon! 734 return false; 735 } 736 } 737 738 /** @hide */ 739 public void setPackageAskScreenCompat(String packageName, boolean ask) { 740 try { 741 ActivityManagerNative.getDefault().setPackageAskScreenCompat(packageName, ask); 742 } catch (RemoteException e) { 743 // System dead, we will be dead too soon! 744 } 745 } 746 747 /** 748 * Return the approximate per-application memory class of the current 749 * device. This gives you an idea of how hard a memory limit you should 750 * impose on your application to let the overall system work best. The 751 * returned value is in megabytes; the baseline Android memory class is 752 * 16 (which happens to be the Java heap limit of those devices); some 753 * device with more memory may return 24 or even higher numbers. 754 */ 755 public int getMemoryClass() { 756 return staticGetMemoryClass(); 757 } 758 759 /** @hide */ 760 static public int staticGetMemoryClass() { 761 // Really brain dead right now -- just take this from the configured 762 // vm heap size, and assume it is in megabytes and thus ends with "m". 763 String vmHeapSize = SystemProperties.get("dalvik.vm.heapgrowthlimit", ""); 764 if (vmHeapSize != null && !"".equals(vmHeapSize)) { 765 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length()-1)); 766 } 767 return staticGetLargeMemoryClass(); 768 } 769 770 /** 771 * Return the approximate per-application memory class of the current 772 * device when an application is running with a large heap. This is the 773 * space available for memory-intensive applications; most applications 774 * should not need this amount of memory, and should instead stay with the 775 * {@link #getMemoryClass()} limit. The returned value is in megabytes. 776 * This may be the same size as {@link #getMemoryClass()} on memory 777 * constrained devices, or it may be significantly larger on devices with 778 * a large amount of available RAM. 779 * 780 * <p>The is the size of the application's Dalvik heap if it has 781 * specified <code>android:largeHeap="true"</code> in its manifest. 782 */ 783 public int getLargeMemoryClass() { 784 return staticGetLargeMemoryClass(); 785 } 786 787 /** @hide */ 788 static public int staticGetLargeMemoryClass() { 789 // Really brain dead right now -- just take this from the configured 790 // vm heap size, and assume it is in megabytes and thus ends with "m". 791 String vmHeapSize = SystemProperties.get("dalvik.vm.heapsize", "16m"); 792 return Integer.parseInt(vmHeapSize.substring(0, vmHeapSize.length() - 1)); 793 } 794 795 /** 796 * Returns true if this is a low-RAM device. Exactly whether a device is low-RAM 797 * is ultimately up to the device configuration, but currently it generally means 798 * something in the class of a 512MB device with about a 800x480 or less screen. 799 * This is mostly intended to be used by apps to determine whether they should turn 800 * off certain features that require more RAM. 801 */ 802 public boolean isLowRamDevice() { 803 return isLowRamDeviceStatic(); 804 } 805 806 /** @hide */ 807 public static boolean isLowRamDeviceStatic() { 808 return "true".equals(SystemProperties.get("ro.config.low_ram", "false")); 809 } 810 811 /** 812 * Used by persistent processes to determine if they are running on a 813 * higher-end device so should be okay using hardware drawing acceleration 814 * (which tends to consume a lot more RAM). 815 * @hide 816 */ 817 static public boolean isHighEndGfx() { 818 return !isLowRamDeviceStatic() && 819 !Resources.getSystem().getBoolean(com.android.internal.R.bool.config_avoidGfxAccel); 820 } 821 822 /** 823 * Return the maximum number of recents entries that we will maintain and show. 824 * @hide 825 */ 826 static public int getMaxRecentTasksStatic() { 827 if (gMaxRecentTasks < 0) { 828 return gMaxRecentTasks = isLowRamDeviceStatic() ? 50 : 100; 829 } 830 return gMaxRecentTasks; 831 } 832 833 /** 834 * Return the default limit on the number of recents that an app can make. 835 * @hide 836 */ 837 static public int getDefaultAppRecentsLimitStatic() { 838 return getMaxRecentTasksStatic() / 6; 839 } 840 841 /** 842 * Return the maximum limit on the number of recents that an app can make. 843 * @hide 844 */ 845 static public int getMaxAppRecentsLimitStatic() { 846 return getMaxRecentTasksStatic() / 2; 847 } 848 849 /** 850 * Information you can set and retrieve about the current activity within the recent task list. 851 */ 852 public static class TaskDescription implements Parcelable { 853 /** @hide */ 854 public static final String ATTR_TASKDESCRIPTION_PREFIX = "task_description_"; 855 private static final String ATTR_TASKDESCRIPTIONLABEL = 856 ATTR_TASKDESCRIPTION_PREFIX + "label"; 857 private static final String ATTR_TASKDESCRIPTIONCOLOR = 858 ATTR_TASKDESCRIPTION_PREFIX + "color"; 859 private static final String ATTR_TASKDESCRIPTIONICONFILENAME = 860 ATTR_TASKDESCRIPTION_PREFIX + "icon_filename"; 861 862 private String mLabel; 863 private Bitmap mIcon; 864 private String mIconFilename; 865 private int mColorPrimary; 866 867 /** 868 * Creates the TaskDescription to the specified values. 869 * 870 * @param label A label and description of the current state of this task. 871 * @param icon An icon that represents the current state of this task. 872 * @param colorPrimary A color to override the theme's primary color. This color must be opaque. 873 */ 874 public TaskDescription(String label, Bitmap icon, int colorPrimary) { 875 if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) { 876 throw new RuntimeException("A TaskDescription's primary color should be opaque"); 877 } 878 879 mLabel = label; 880 mIcon = icon; 881 mColorPrimary = colorPrimary; 882 } 883 884 /** @hide */ 885 public TaskDescription(String label, int colorPrimary, String iconFilename) { 886 this(label, null, colorPrimary); 887 mIconFilename = iconFilename; 888 } 889 890 /** 891 * Creates the TaskDescription to the specified values. 892 * 893 * @param label A label and description of the current state of this activity. 894 * @param icon An icon that represents the current state of this activity. 895 */ 896 public TaskDescription(String label, Bitmap icon) { 897 this(label, icon, 0); 898 } 899 900 /** 901 * Creates the TaskDescription to the specified values. 902 * 903 * @param label A label and description of the current state of this activity. 904 */ 905 public TaskDescription(String label) { 906 this(label, null, 0); 907 } 908 909 /** 910 * Creates an empty TaskDescription. 911 */ 912 public TaskDescription() { 913 this(null, null, 0); 914 } 915 916 /** 917 * Creates a copy of another TaskDescription. 918 */ 919 public TaskDescription(TaskDescription td) { 920 mLabel = td.mLabel; 921 mIcon = td.mIcon; 922 mColorPrimary = td.mColorPrimary; 923 mIconFilename = td.mIconFilename; 924 } 925 926 private TaskDescription(Parcel source) { 927 readFromParcel(source); 928 } 929 930 /** 931 * Sets the label for this task description. 932 * @hide 933 */ 934 public void setLabel(String label) { 935 mLabel = label; 936 } 937 938 /** 939 * Sets the primary color for this task description. 940 * @hide 941 */ 942 public void setPrimaryColor(int primaryColor) { 943 // Ensure that the given color is valid 944 if ((primaryColor != 0) && (Color.alpha(primaryColor) != 255)) { 945 throw new RuntimeException("A TaskDescription's primary color should be opaque"); 946 } 947 mColorPrimary = primaryColor; 948 } 949 950 /** 951 * Sets the icon for this task description. 952 * @hide 953 */ 954 public void setIcon(Bitmap icon) { 955 mIcon = icon; 956 } 957 958 /** 959 * Moves the icon bitmap reference from an actual Bitmap to a file containing the 960 * bitmap. 961 * @hide 962 */ 963 public void setIconFilename(String iconFilename) { 964 mIconFilename = iconFilename; 965 mIcon = null; 966 } 967 968 /** 969 * @return The label and description of the current state of this task. 970 */ 971 public String getLabel() { 972 return mLabel; 973 } 974 975 /** 976 * @return The icon that represents the current state of this task. 977 */ 978 public Bitmap getIcon() { 979 if (mIcon != null) { 980 return mIcon; 981 } 982 return loadTaskDescriptionIcon(mIconFilename, UserHandle.myUserId()); 983 } 984 985 /** @hide */ 986 public String getIconFilename() { 987 return mIconFilename; 988 } 989 990 /** @hide */ 991 public Bitmap getInMemoryIcon() { 992 return mIcon; 993 } 994 995 /** @hide */ 996 public static Bitmap loadTaskDescriptionIcon(String iconFilename, int userId) { 997 if (iconFilename != null) { 998 try { 999 return ActivityManagerNative.getDefault(). 1000 getTaskDescriptionIcon(iconFilename, userId); 1001 } catch (RemoteException e) { 1002 } 1003 } 1004 return null; 1005 } 1006 1007 /** 1008 * @return The color override on the theme's primary color. 1009 */ 1010 public int getPrimaryColor() { 1011 return mColorPrimary; 1012 } 1013 1014 /** @hide */ 1015 public void saveToXml(XmlSerializer out) throws IOException { 1016 if (mLabel != null) { 1017 out.attribute(null, ATTR_TASKDESCRIPTIONLABEL, mLabel); 1018 } 1019 if (mColorPrimary != 0) { 1020 out.attribute(null, ATTR_TASKDESCRIPTIONCOLOR, Integer.toHexString(mColorPrimary)); 1021 } 1022 if (mIconFilename != null) { 1023 out.attribute(null, ATTR_TASKDESCRIPTIONICONFILENAME, mIconFilename); 1024 } 1025 } 1026 1027 /** @hide */ 1028 public void restoreFromXml(String attrName, String attrValue) { 1029 if (ATTR_TASKDESCRIPTIONLABEL.equals(attrName)) { 1030 setLabel(attrValue); 1031 } else if (ATTR_TASKDESCRIPTIONCOLOR.equals(attrName)) { 1032 setPrimaryColor((int) Long.parseLong(attrValue, 16)); 1033 } else if (ATTR_TASKDESCRIPTIONICONFILENAME.equals(attrName)) { 1034 setIconFilename(attrValue); 1035 } 1036 } 1037 1038 @Override 1039 public int describeContents() { 1040 return 0; 1041 } 1042 1043 @Override 1044 public void writeToParcel(Parcel dest, int flags) { 1045 if (mLabel == null) { 1046 dest.writeInt(0); 1047 } else { 1048 dest.writeInt(1); 1049 dest.writeString(mLabel); 1050 } 1051 if (mIcon == null) { 1052 dest.writeInt(0); 1053 } else { 1054 dest.writeInt(1); 1055 mIcon.writeToParcel(dest, 0); 1056 } 1057 dest.writeInt(mColorPrimary); 1058 if (mIconFilename == null) { 1059 dest.writeInt(0); 1060 } else { 1061 dest.writeInt(1); 1062 dest.writeString(mIconFilename); 1063 } 1064 } 1065 1066 public void readFromParcel(Parcel source) { 1067 mLabel = source.readInt() > 0 ? source.readString() : null; 1068 mIcon = source.readInt() > 0 ? Bitmap.CREATOR.createFromParcel(source) : null; 1069 mColorPrimary = source.readInt(); 1070 mIconFilename = source.readInt() > 0 ? source.readString() : null; 1071 } 1072 1073 public static final Creator<TaskDescription> CREATOR 1074 = new Creator<TaskDescription>() { 1075 public TaskDescription createFromParcel(Parcel source) { 1076 return new TaskDescription(source); 1077 } 1078 public TaskDescription[] newArray(int size) { 1079 return new TaskDescription[size]; 1080 } 1081 }; 1082 1083 @Override 1084 public String toString() { 1085 return "TaskDescription Label: " + mLabel + " Icon: " + mIcon + 1086 " colorPrimary: " + mColorPrimary; 1087 } 1088 } 1089 1090 /** 1091 * Information you can retrieve about tasks that the user has most recently 1092 * started or visited. 1093 */ 1094 public static class RecentTaskInfo implements Parcelable { 1095 /** 1096 * If this task is currently running, this is the identifier for it. 1097 * If it is not running, this will be -1. 1098 */ 1099 public int id; 1100 1101 /** 1102 * The true identifier of this task, valid even if it is not running. 1103 */ 1104 public int persistentId; 1105 1106 /** 1107 * The original Intent used to launch the task. You can use this 1108 * Intent to re-launch the task (if it is no longer running) or bring 1109 * the current task to the front. 1110 */ 1111 public Intent baseIntent; 1112 1113 /** 1114 * If this task was started from an alias, this is the actual 1115 * activity component that was initially started; the component of 1116 * the baseIntent in this case is the name of the actual activity 1117 * implementation that the alias referred to. Otherwise, this is null. 1118 */ 1119 public ComponentName origActivity; 1120 1121 /** 1122 * The actual activity component that started the task. 1123 * @hide 1124 */ 1125 @Nullable 1126 public ComponentName realActivity; 1127 1128 /** 1129 * Description of the task's last state. 1130 */ 1131 public CharSequence description; 1132 1133 /** 1134 * The id of the ActivityStack this Task was on most recently. 1135 * @hide 1136 */ 1137 public int stackId; 1138 1139 /** 1140 * The id of the user the task was running as. 1141 * @hide 1142 */ 1143 public int userId; 1144 1145 /** 1146 * The first time this task was active. 1147 * @hide 1148 */ 1149 public long firstActiveTime; 1150 1151 /** 1152 * The last time this task was active. 1153 * @hide 1154 */ 1155 public long lastActiveTime; 1156 1157 /** 1158 * The recent activity values for the highest activity in the stack to have set the values. 1159 * {@link Activity#setTaskDescription(android.app.ActivityManager.TaskDescription)}. 1160 */ 1161 public TaskDescription taskDescription; 1162 1163 /** 1164 * Task affiliation for grouping with other tasks. 1165 */ 1166 public int affiliatedTaskId; 1167 1168 /** 1169 * Task affiliation color of the source task with the affiliated task id. 1170 * 1171 * @hide 1172 */ 1173 public int affiliatedTaskColor; 1174 1175 /** 1176 * The component launched as the first activity in the task. 1177 * This can be considered the "application" of this task. 1178 */ 1179 public ComponentName baseActivity; 1180 1181 /** 1182 * The activity component at the top of the history stack of the task. 1183 * This is what the user is currently doing. 1184 */ 1185 public ComponentName topActivity; 1186 1187 /** 1188 * Number of activities in this task. 1189 */ 1190 public int numActivities; 1191 1192 /** 1193 * The bounds of the task. 1194 * @hide 1195 */ 1196 public Rect bounds; 1197 1198 /** 1199 * True if the task can go in the docked stack. 1200 * @hide 1201 */ 1202 public boolean isDockable; 1203 1204 public RecentTaskInfo() { 1205 } 1206 1207 @Override 1208 public int describeContents() { 1209 return 0; 1210 } 1211 1212 @Override 1213 public void writeToParcel(Parcel dest, int flags) { 1214 dest.writeInt(id); 1215 dest.writeInt(persistentId); 1216 if (baseIntent != null) { 1217 dest.writeInt(1); 1218 baseIntent.writeToParcel(dest, 0); 1219 } else { 1220 dest.writeInt(0); 1221 } 1222 ComponentName.writeToParcel(origActivity, dest); 1223 ComponentName.writeToParcel(realActivity, dest); 1224 TextUtils.writeToParcel(description, dest, 1225 Parcelable.PARCELABLE_WRITE_RETURN_VALUE); 1226 if (taskDescription != null) { 1227 dest.writeInt(1); 1228 taskDescription.writeToParcel(dest, 0); 1229 } else { 1230 dest.writeInt(0); 1231 } 1232 dest.writeInt(stackId); 1233 dest.writeInt(userId); 1234 dest.writeLong(firstActiveTime); 1235 dest.writeLong(lastActiveTime); 1236 dest.writeInt(affiliatedTaskId); 1237 dest.writeInt(affiliatedTaskColor); 1238 ComponentName.writeToParcel(baseActivity, dest); 1239 ComponentName.writeToParcel(topActivity, dest); 1240 dest.writeInt(numActivities); 1241 if (bounds != null) { 1242 dest.writeInt(1); 1243 bounds.writeToParcel(dest, 0); 1244 } else { 1245 dest.writeInt(0); 1246 } 1247 dest.writeInt(isDockable ? 1 : 0); 1248 } 1249 1250 public void readFromParcel(Parcel source) { 1251 id = source.readInt(); 1252 persistentId = source.readInt(); 1253 baseIntent = source.readInt() > 0 ? Intent.CREATOR.createFromParcel(source) : null; 1254 origActivity = ComponentName.readFromParcel(source); 1255 realActivity = ComponentName.readFromParcel(source); 1256 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); 1257 taskDescription = source.readInt() > 0 ? 1258 TaskDescription.CREATOR.createFromParcel(source) : null; 1259 stackId = source.readInt(); 1260 userId = source.readInt(); 1261 firstActiveTime = source.readLong(); 1262 lastActiveTime = source.readLong(); 1263 affiliatedTaskId = source.readInt(); 1264 affiliatedTaskColor = source.readInt(); 1265 baseActivity = ComponentName.readFromParcel(source); 1266 topActivity = ComponentName.readFromParcel(source); 1267 numActivities = source.readInt(); 1268 bounds = source.readInt() > 0 ? 1269 Rect.CREATOR.createFromParcel(source) : null; 1270 isDockable = source.readInt() == 1; 1271 } 1272 1273 public static final Creator<RecentTaskInfo> CREATOR 1274 = new Creator<RecentTaskInfo>() { 1275 public RecentTaskInfo createFromParcel(Parcel source) { 1276 return new RecentTaskInfo(source); 1277 } 1278 public RecentTaskInfo[] newArray(int size) { 1279 return new RecentTaskInfo[size]; 1280 } 1281 }; 1282 1283 private RecentTaskInfo(Parcel source) { 1284 readFromParcel(source); 1285 } 1286 } 1287 1288 /** 1289 * Flag for use with {@link #getRecentTasks}: return all tasks, even those 1290 * that have set their 1291 * {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag. 1292 */ 1293 public static final int RECENT_WITH_EXCLUDED = 0x0001; 1294 1295 /** 1296 * Provides a list that does not contain any 1297 * recent tasks that currently are not available to the user. 1298 */ 1299 public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002; 1300 1301 /** 1302 * Provides a list that contains recent tasks for all 1303 * profiles of a user. 1304 * @hide 1305 */ 1306 public static final int RECENT_INCLUDE_PROFILES = 0x0004; 1307 1308 /** 1309 * Ignores all tasks that are on the home stack. 1310 * @hide 1311 */ 1312 public static final int RECENT_IGNORE_HOME_STACK_TASKS = 0x0008; 1313 1314 /** 1315 * Ignores all tasks that are on the docked stack. 1316 * @hide 1317 */ 1318 public static final int RECENT_INGORE_DOCKED_STACK_TASKS = 0x0010; 1319 1320 /** 1321 * Ignores all tasks that are on the pinned stack. 1322 * @hide 1323 */ 1324 public static final int RECENT_INGORE_PINNED_STACK_TASKS = 0x0020; 1325 1326 /** 1327 * <p></p>Return a list of the tasks that the user has recently launched, with 1328 * the most recent being first and older ones after in order. 1329 * 1330 * <p><b>Note: this method is only intended for debugging and presenting 1331 * task management user interfaces</b>. This should never be used for 1332 * core logic in an application, such as deciding between different 1333 * behaviors based on the information found here. Such uses are 1334 * <em>not</em> supported, and will likely break in the future. For 1335 * example, if multiple applications can be actively running at the 1336 * same time, assumptions made about the meaning of the data here for 1337 * purposes of control flow will be incorrect.</p> 1338 * 1339 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method is 1340 * no longer available to third party applications: the introduction of 1341 * document-centric recents means 1342 * it can leak personal information to the caller. For backwards compatibility, 1343 * it will still return a small subset of its data: at least the caller's 1344 * own tasks (though see {@link #getAppTasks()} for the correct supported 1345 * way to retrieve that information), and possibly some other tasks 1346 * such as home that are known to not be sensitive. 1347 * 1348 * @param maxNum The maximum number of entries to return in the list. The 1349 * actual number returned may be smaller, depending on how many tasks the 1350 * user has started and the maximum number the system can remember. 1351 * @param flags Information about what to return. May be any combination 1352 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}. 1353 * 1354 * @return Returns a list of RecentTaskInfo records describing each of 1355 * the recent tasks. 1356 */ 1357 @Deprecated 1358 public List<RecentTaskInfo> getRecentTasks(int maxNum, int flags) 1359 throws SecurityException { 1360 try { 1361 return ActivityManagerNative.getDefault().getRecentTasks(maxNum, 1362 flags, UserHandle.myUserId()); 1363 } catch (RemoteException e) { 1364 // System dead, we will be dead too soon! 1365 return null; 1366 } 1367 } 1368 1369 /** 1370 * Same as {@link #getRecentTasks(int, int)} but returns the recent tasks for a 1371 * specific user. It requires holding 1372 * the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission. 1373 * @param maxNum The maximum number of entries to return in the list. The 1374 * actual number returned may be smaller, depending on how many tasks the 1375 * user has started and the maximum number the system can remember. 1376 * @param flags Information about what to return. May be any combination 1377 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}. 1378 * 1379 * @return Returns a list of RecentTaskInfo records describing each of 1380 * the recent tasks. Most recently activated tasks go first. 1381 * 1382 * @hide 1383 */ 1384 public List<RecentTaskInfo> getRecentTasksForUser(int maxNum, int flags, int userId) 1385 throws SecurityException { 1386 try { 1387 return ActivityManagerNative.getDefault().getRecentTasks(maxNum, 1388 flags, userId); 1389 } catch (RemoteException e) { 1390 // System dead, we will be dead too soon! 1391 return null; 1392 } 1393 } 1394 1395 /** 1396 * Information you can retrieve about a particular task that is currently 1397 * "running" in the system. Note that a running task does not mean the 1398 * given task actually has a process it is actively running in; it simply 1399 * means that the user has gone to it and never closed it, but currently 1400 * the system may have killed its process and is only holding on to its 1401 * last state in order to restart it when the user returns. 1402 */ 1403 public static class RunningTaskInfo implements Parcelable { 1404 /** 1405 * A unique identifier for this task. 1406 */ 1407 public int id; 1408 1409 /** 1410 * The stack that currently contains this task. 1411 * @hide 1412 */ 1413 public int stackId; 1414 1415 /** 1416 * The component launched as the first activity in the task. This can 1417 * be considered the "application" of this task. 1418 */ 1419 public ComponentName baseActivity; 1420 1421 /** 1422 * The activity component at the top of the history stack of the task. 1423 * This is what the user is currently doing. 1424 */ 1425 public ComponentName topActivity; 1426 1427 /** 1428 * Thumbnail representation of the task's current state. Currently 1429 * always null. 1430 */ 1431 public Bitmap thumbnail; 1432 1433 /** 1434 * Description of the task's current state. 1435 */ 1436 public CharSequence description; 1437 1438 /** 1439 * Number of activities in this task. 1440 */ 1441 public int numActivities; 1442 1443 /** 1444 * Number of activities that are currently running (not stopped 1445 * and persisted) in this task. 1446 */ 1447 public int numRunning; 1448 1449 /** 1450 * Last time task was run. For sorting. 1451 * @hide 1452 */ 1453 public long lastActiveTime; 1454 1455 /** 1456 * True if the task can go in the docked stack. 1457 * @hide 1458 */ 1459 public boolean isDockable; 1460 1461 public RunningTaskInfo() { 1462 } 1463 1464 public int describeContents() { 1465 return 0; 1466 } 1467 1468 public void writeToParcel(Parcel dest, int flags) { 1469 dest.writeInt(id); 1470 dest.writeInt(stackId); 1471 ComponentName.writeToParcel(baseActivity, dest); 1472 ComponentName.writeToParcel(topActivity, dest); 1473 if (thumbnail != null) { 1474 dest.writeInt(1); 1475 thumbnail.writeToParcel(dest, 0); 1476 } else { 1477 dest.writeInt(0); 1478 } 1479 TextUtils.writeToParcel(description, dest, 1480 Parcelable.PARCELABLE_WRITE_RETURN_VALUE); 1481 dest.writeInt(numActivities); 1482 dest.writeInt(numRunning); 1483 } 1484 1485 public void readFromParcel(Parcel source) { 1486 id = source.readInt(); 1487 stackId = source.readInt(); 1488 baseActivity = ComponentName.readFromParcel(source); 1489 topActivity = ComponentName.readFromParcel(source); 1490 if (source.readInt() != 0) { 1491 thumbnail = Bitmap.CREATOR.createFromParcel(source); 1492 } else { 1493 thumbnail = null; 1494 } 1495 description = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); 1496 numActivities = source.readInt(); 1497 numRunning = source.readInt(); 1498 } 1499 1500 public static final Creator<RunningTaskInfo> CREATOR = new Creator<RunningTaskInfo>() { 1501 public RunningTaskInfo createFromParcel(Parcel source) { 1502 return new RunningTaskInfo(source); 1503 } 1504 public RunningTaskInfo[] newArray(int size) { 1505 return new RunningTaskInfo[size]; 1506 } 1507 }; 1508 1509 private RunningTaskInfo(Parcel source) { 1510 readFromParcel(source); 1511 } 1512 } 1513 1514 /** 1515 * Get the list of tasks associated with the calling application. 1516 * 1517 * @return The list of tasks associated with the application making this call. 1518 * @throws SecurityException 1519 */ 1520 public List<ActivityManager.AppTask> getAppTasks() { 1521 ArrayList<AppTask> tasks = new ArrayList<AppTask>(); 1522 List<IAppTask> appTasks; 1523 try { 1524 appTasks = ActivityManagerNative.getDefault().getAppTasks(mContext.getPackageName()); 1525 } catch (RemoteException e) { 1526 // System dead, we will be dead too soon! 1527 return null; 1528 } 1529 int numAppTasks = appTasks.size(); 1530 for (int i = 0; i < numAppTasks; i++) { 1531 tasks.add(new AppTask(appTasks.get(i))); 1532 } 1533 return tasks; 1534 } 1535 1536 /** 1537 * Return the current design dimensions for {@link AppTask} thumbnails, for use 1538 * with {@link #addAppTask}. 1539 */ 1540 public Size getAppTaskThumbnailSize() { 1541 synchronized (this) { 1542 ensureAppTaskThumbnailSizeLocked(); 1543 return new Size(mAppTaskThumbnailSize.x, mAppTaskThumbnailSize.y); 1544 } 1545 } 1546 1547 private void ensureAppTaskThumbnailSizeLocked() { 1548 if (mAppTaskThumbnailSize == null) { 1549 try { 1550 mAppTaskThumbnailSize = ActivityManagerNative.getDefault().getAppTaskThumbnailSize(); 1551 } catch (RemoteException e) { 1552 throw new IllegalStateException("System dead?", e); 1553 } 1554 } 1555 } 1556 1557 /** 1558 * Add a new {@link AppTask} for the calling application. This will create a new 1559 * recents entry that is added to the <b>end</b> of all existing recents. 1560 * 1561 * @param activity The activity that is adding the entry. This is used to help determine 1562 * the context that the new recents entry will be in. 1563 * @param intent The Intent that describes the recents entry. This is the same Intent that 1564 * you would have used to launch the activity for it. In generally you will want to set 1565 * both {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT} and 1566 * {@link Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS}; the latter is required since this recents 1567 * entry will exist without an activity, so it doesn't make sense to not retain it when 1568 * its activity disappears. The given Intent here also must have an explicit ComponentName 1569 * set on it. 1570 * @param description Optional additional description information. 1571 * @param thumbnail Thumbnail to use for the recents entry. Should be the size given by 1572 * {@link #getAppTaskThumbnailSize()}. If the bitmap is not that exact size, it will be 1573 * recreated in your process, probably in a way you don't like, before the recents entry 1574 * is added. 1575 * 1576 * @return Returns the task id of the newly added app task, or -1 if the add failed. The 1577 * most likely cause of failure is that there is no more room for more tasks for your app. 1578 */ 1579 public int addAppTask(@NonNull Activity activity, @NonNull Intent intent, 1580 @Nullable TaskDescription description, @NonNull Bitmap thumbnail) { 1581 Point size; 1582 synchronized (this) { 1583 ensureAppTaskThumbnailSizeLocked(); 1584 size = mAppTaskThumbnailSize; 1585 } 1586 final int tw = thumbnail.getWidth(); 1587 final int th = thumbnail.getHeight(); 1588 if (tw != size.x || th != size.y) { 1589 Bitmap bm = Bitmap.createBitmap(size.x, size.y, thumbnail.getConfig()); 1590 1591 // Use ScaleType.CENTER_CROP, except we leave the top edge at the top. 1592 float scale; 1593 float dx = 0, dy = 0; 1594 if (tw * size.x > size.y * th) { 1595 scale = (float) size.x / (float) th; 1596 dx = (size.y - tw * scale) * 0.5f; 1597 } else { 1598 scale = (float) size.y / (float) tw; 1599 dy = (size.x - th * scale) * 0.5f; 1600 } 1601 Matrix matrix = new Matrix(); 1602 matrix.setScale(scale, scale); 1603 matrix.postTranslate((int) (dx + 0.5f), 0); 1604 1605 Canvas canvas = new Canvas(bm); 1606 canvas.drawBitmap(thumbnail, matrix, null); 1607 canvas.setBitmap(null); 1608 1609 thumbnail = bm; 1610 } 1611 if (description == null) { 1612 description = new TaskDescription(); 1613 } 1614 try { 1615 return ActivityManagerNative.getDefault().addAppTask(activity.getActivityToken(), 1616 intent, description, thumbnail); 1617 } catch (RemoteException e) { 1618 throw new IllegalStateException("System dead?", e); 1619 } 1620 } 1621 1622 /** 1623 * Return a list of the tasks that are currently running, with 1624 * the most recent being first and older ones after in order. Note that 1625 * "running" does not mean any of the task's code is currently loaded or 1626 * activity -- the task may have been frozen by the system, so that it 1627 * can be restarted in its previous state when next brought to the 1628 * foreground. 1629 * 1630 * <p><b>Note: this method is only intended for debugging and presenting 1631 * task management user interfaces</b>. This should never be used for 1632 * core logic in an application, such as deciding between different 1633 * behaviors based on the information found here. Such uses are 1634 * <em>not</em> supported, and will likely break in the future. For 1635 * example, if multiple applications can be actively running at the 1636 * same time, assumptions made about the meaning of the data here for 1637 * purposes of control flow will be incorrect.</p> 1638 * 1639 * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method 1640 * is no longer available to third party 1641 * applications: the introduction of document-centric recents means 1642 * it can leak person information to the caller. For backwards compatibility, 1643 * it will still retu rn a small subset of its data: at least the caller's 1644 * own tasks, and possibly some other tasks 1645 * such as home that are known to not be sensitive. 1646 * 1647 * @param maxNum The maximum number of entries to return in the list. The 1648 * actual number returned may be smaller, depending on how many tasks the 1649 * user has started. 1650 * 1651 * @return Returns a list of RunningTaskInfo records describing each of 1652 * the running tasks. 1653 */ 1654 @Deprecated 1655 public List<RunningTaskInfo> getRunningTasks(int maxNum) 1656 throws SecurityException { 1657 try { 1658 return ActivityManagerNative.getDefault().getTasks(maxNum, 0); 1659 } catch (RemoteException e) { 1660 // System dead, we will be dead too soon! 1661 return null; 1662 } 1663 } 1664 1665 /** 1666 * Completely remove the given task. 1667 * 1668 * @param taskId Identifier of the task to be removed. 1669 * @return Returns true if the given task was found and removed. 1670 * 1671 * @hide 1672 */ 1673 public boolean removeTask(int taskId) throws SecurityException { 1674 try { 1675 return ActivityManagerNative.getDefault().removeTask(taskId); 1676 } catch (RemoteException e) { 1677 // System dead, we will be dead too soon! 1678 return false; 1679 } 1680 } 1681 1682 /** 1683 * Metadata related to the {@link TaskThumbnail}. 1684 * 1685 * @hide 1686 */ 1687 public static class TaskThumbnailInfo implements Parcelable { 1688 /** @hide */ 1689 public static final String ATTR_TASK_THUMBNAILINFO_PREFIX = "task_thumbnailinfo_"; 1690 private static final String ATTR_TASK_WIDTH = 1691 ATTR_TASK_THUMBNAILINFO_PREFIX + "task_width"; 1692 private static final String ATTR_TASK_HEIGHT = 1693 ATTR_TASK_THUMBNAILINFO_PREFIX + "task_height"; 1694 private static final String ATTR_SCREEN_ORIENTATION = 1695 ATTR_TASK_THUMBNAILINFO_PREFIX + "screen_orientation"; 1696 1697 public int taskWidth; 1698 public int taskHeight; 1699 public int screenOrientation; 1700 1701 public TaskThumbnailInfo() { 1702 // Do nothing 1703 } 1704 1705 private TaskThumbnailInfo(Parcel source) { 1706 readFromParcel(source); 1707 } 1708 1709 /** 1710 * Resets this info state to the initial state. 1711 * @hide 1712 */ 1713 public void reset() { 1714 taskWidth = 0; 1715 taskHeight = 0; 1716 screenOrientation = 0; 1717 } 1718 1719 /** @hide */ 1720 public void saveToXml(XmlSerializer out) throws IOException { 1721 out.attribute(null, ATTR_TASK_WIDTH, Integer.toString(taskWidth)); 1722 out.attribute(null, ATTR_TASK_HEIGHT, Integer.toString(taskHeight)); 1723 out.attribute(null, ATTR_SCREEN_ORIENTATION, Integer.toString(screenOrientation)); 1724 } 1725 1726 /** @hide */ 1727 public void restoreFromXml(String attrName, String attrValue) { 1728 if (ATTR_TASK_WIDTH.equals(attrName)) { 1729 taskWidth = Integer.parseInt(attrValue); 1730 } else if (ATTR_TASK_HEIGHT.equals(attrName)) { 1731 taskHeight = Integer.parseInt(attrValue); 1732 } else if (ATTR_SCREEN_ORIENTATION.equals(attrName)) { 1733 screenOrientation = Integer.parseInt(attrValue); 1734 } 1735 } 1736 1737 public int describeContents() { 1738 return 0; 1739 } 1740 1741 public void writeToParcel(Parcel dest, int flags) { 1742 dest.writeInt(taskWidth); 1743 dest.writeInt(taskHeight); 1744 dest.writeInt(screenOrientation); 1745 } 1746 1747 public void readFromParcel(Parcel source) { 1748 taskWidth = source.readInt(); 1749 taskHeight = source.readInt(); 1750 screenOrientation = source.readInt(); 1751 } 1752 1753 public static final Creator<TaskThumbnailInfo> CREATOR = new Creator<TaskThumbnailInfo>() { 1754 public TaskThumbnailInfo createFromParcel(Parcel source) { 1755 return new TaskThumbnailInfo(source); 1756 } 1757 public TaskThumbnailInfo[] newArray(int size) { 1758 return new TaskThumbnailInfo[size]; 1759 } 1760 }; 1761 } 1762 1763 /** @hide */ 1764 public static class TaskThumbnail implements Parcelable { 1765 public Bitmap mainThumbnail; 1766 public ParcelFileDescriptor thumbnailFileDescriptor; 1767 public TaskThumbnailInfo thumbnailInfo; 1768 1769 public TaskThumbnail() { 1770 } 1771 1772 private TaskThumbnail(Parcel source) { 1773 readFromParcel(source); 1774 } 1775 1776 public int describeContents() { 1777 if (thumbnailFileDescriptor != null) { 1778 return thumbnailFileDescriptor.describeContents(); 1779 } 1780 return 0; 1781 } 1782 1783 public void writeToParcel(Parcel dest, int flags) { 1784 if (mainThumbnail != null) { 1785 dest.writeInt(1); 1786 mainThumbnail.writeToParcel(dest, flags); 1787 } else { 1788 dest.writeInt(0); 1789 } 1790 if (thumbnailFileDescriptor != null) { 1791 dest.writeInt(1); 1792 thumbnailFileDescriptor.writeToParcel(dest, flags); 1793 } else { 1794 dest.writeInt(0); 1795 } 1796 if (thumbnailInfo != null) { 1797 dest.writeInt(1); 1798 thumbnailInfo.writeToParcel(dest, flags); 1799 } else { 1800 dest.writeInt(0); 1801 } 1802 } 1803 1804 public void readFromParcel(Parcel source) { 1805 if (source.readInt() != 0) { 1806 mainThumbnail = Bitmap.CREATOR.createFromParcel(source); 1807 } else { 1808 mainThumbnail = null; 1809 } 1810 if (source.readInt() != 0) { 1811 thumbnailFileDescriptor = ParcelFileDescriptor.CREATOR.createFromParcel(source); 1812 } else { 1813 thumbnailFileDescriptor = null; 1814 } 1815 if (source.readInt() != 0) { 1816 thumbnailInfo = TaskThumbnailInfo.CREATOR.createFromParcel(source); 1817 } else { 1818 thumbnailInfo = null; 1819 } 1820 } 1821 1822 public static final Creator<TaskThumbnail> CREATOR = new Creator<TaskThumbnail>() { 1823 public TaskThumbnail createFromParcel(Parcel source) { 1824 return new TaskThumbnail(source); 1825 } 1826 public TaskThumbnail[] newArray(int size) { 1827 return new TaskThumbnail[size]; 1828 } 1829 }; 1830 } 1831 1832 /** @hide */ 1833 public TaskThumbnail getTaskThumbnail(int id) throws SecurityException { 1834 try { 1835 return ActivityManagerNative.getDefault().getTaskThumbnail(id); 1836 } catch (RemoteException e) { 1837 // System dead, we will be dead too soon! 1838 return null; 1839 } 1840 } 1841 1842 /** @hide */ 1843 public boolean isInHomeStack(int taskId) { 1844 try { 1845 return ActivityManagerNative.getDefault().isInHomeStack(taskId); 1846 } catch (RemoteException e) { 1847 // System dead, we will be dead too soon! 1848 return false; 1849 } 1850 } 1851 1852 /** 1853 * Flag for {@link #moveTaskToFront(int, int)}: also move the "home" 1854 * activity along with the task, so it is positioned immediately behind 1855 * the task. 1856 */ 1857 public static final int MOVE_TASK_WITH_HOME = 0x00000001; 1858 1859 /** 1860 * Flag for {@link #moveTaskToFront(int, int)}: don't count this as a 1861 * user-instigated action, so the current activity will not receive a 1862 * hint that the user is leaving. 1863 */ 1864 public static final int MOVE_TASK_NO_USER_ACTION = 0x00000002; 1865 1866 /** 1867 * Equivalent to calling {@link #moveTaskToFront(int, int, Bundle)} 1868 * with a null options argument. 1869 * 1870 * @param taskId The identifier of the task to be moved, as found in 1871 * {@link RunningTaskInfo} or {@link RecentTaskInfo}. 1872 * @param flags Additional operational flags, 0 or more of 1873 * {@link #MOVE_TASK_WITH_HOME}, {@link #MOVE_TASK_NO_USER_ACTION}. 1874 */ 1875 public void moveTaskToFront(int taskId, int flags) { 1876 moveTaskToFront(taskId, flags, null); 1877 } 1878 1879 /** 1880 * Ask that the task associated with a given task ID be moved to the 1881 * front of the stack, so it is now visible to the user. Requires that 1882 * the caller hold permission {@link android.Manifest.permission#REORDER_TASKS} 1883 * or a SecurityException will be thrown. 1884 * 1885 * @param taskId The identifier of the task to be moved, as found in 1886 * {@link RunningTaskInfo} or {@link RecentTaskInfo}. 1887 * @param flags Additional operational flags, 0 or more of 1888 * {@link #MOVE_TASK_WITH_HOME}, {@link #MOVE_TASK_NO_USER_ACTION}. 1889 * @param options Additional options for the operation, either null or 1890 * as per {@link Context#startActivity(Intent, android.os.Bundle) 1891 * Context.startActivity(Intent, Bundle)}. 1892 */ 1893 public void moveTaskToFront(int taskId, int flags, Bundle options) { 1894 try { 1895 ActivityManagerNative.getDefault().moveTaskToFront(taskId, flags, options); 1896 } catch (RemoteException e) { 1897 // System dead, we will be dead too soon! 1898 } 1899 } 1900 1901 /** 1902 * Information you can retrieve about a particular Service that is 1903 * currently running in the system. 1904 */ 1905 public static class RunningServiceInfo implements Parcelable { 1906 /** 1907 * The service component. 1908 */ 1909 public ComponentName service; 1910 1911 /** 1912 * If non-zero, this is the process the service is running in. 1913 */ 1914 public int pid; 1915 1916 /** 1917 * The UID that owns this service. 1918 */ 1919 public int uid; 1920 1921 /** 1922 * The name of the process this service runs in. 1923 */ 1924 public String process; 1925 1926 /** 1927 * Set to true if the service has asked to run as a foreground process. 1928 */ 1929 public boolean foreground; 1930 1931 /** 1932 * The time when the service was first made active, either by someone 1933 * starting or binding to it. This 1934 * is in units of {@link android.os.SystemClock#elapsedRealtime()}. 1935 */ 1936 public long activeSince; 1937 1938 /** 1939 * Set to true if this service has been explicitly started. 1940 */ 1941 public boolean started; 1942 1943 /** 1944 * Number of clients connected to the service. 1945 */ 1946 public int clientCount; 1947 1948 /** 1949 * Number of times the service's process has crashed while the service 1950 * is running. 1951 */ 1952 public int crashCount; 1953 1954 /** 1955 * The time when there was last activity in the service (either 1956 * explicit requests to start it or clients binding to it). This 1957 * is in units of {@link android.os.SystemClock#uptimeMillis()}. 1958 */ 1959 public long lastActivityTime; 1960 1961 /** 1962 * If non-zero, this service is not currently running, but scheduled to 1963 * restart at the given time. 1964 */ 1965 public long restarting; 1966 1967 /** 1968 * Bit for {@link #flags}: set if this service has been 1969 * explicitly started. 1970 */ 1971 public static final int FLAG_STARTED = 1<<0; 1972 1973 /** 1974 * Bit for {@link #flags}: set if the service has asked to 1975 * run as a foreground process. 1976 */ 1977 public static final int FLAG_FOREGROUND = 1<<1; 1978 1979 /** 1980 * Bit for {@link #flags): set if the service is running in a 1981 * core system process. 1982 */ 1983 public static final int FLAG_SYSTEM_PROCESS = 1<<2; 1984 1985 /** 1986 * Bit for {@link #flags): set if the service is running in a 1987 * persistent process. 1988 */ 1989 public static final int FLAG_PERSISTENT_PROCESS = 1<<3; 1990 1991 /** 1992 * Running flags. 1993 */ 1994 public int flags; 1995 1996 /** 1997 * For special services that are bound to by system code, this is 1998 * the package that holds the binding. 1999 */ 2000 public String clientPackage; 2001 2002 /** 2003 * For special services that are bound to by system code, this is 2004 * a string resource providing a user-visible label for who the 2005 * client is. 2006 */ 2007 public int clientLabel; 2008 2009 public RunningServiceInfo() { 2010 } 2011 2012 public int describeContents() { 2013 return 0; 2014 } 2015 2016 public void writeToParcel(Parcel dest, int flags) { 2017 ComponentName.writeToParcel(service, dest); 2018 dest.writeInt(pid); 2019 dest.writeInt(uid); 2020 dest.writeString(process); 2021 dest.writeInt(foreground ? 1 : 0); 2022 dest.writeLong(activeSince); 2023 dest.writeInt(started ? 1 : 0); 2024 dest.writeInt(clientCount); 2025 dest.writeInt(crashCount); 2026 dest.writeLong(lastActivityTime); 2027 dest.writeLong(restarting); 2028 dest.writeInt(this.flags); 2029 dest.writeString(clientPackage); 2030 dest.writeInt(clientLabel); 2031 } 2032 2033 public void readFromParcel(Parcel source) { 2034 service = ComponentName.readFromParcel(source); 2035 pid = source.readInt(); 2036 uid = source.readInt(); 2037 process = source.readString(); 2038 foreground = source.readInt() != 0; 2039 activeSince = source.readLong(); 2040 started = source.readInt() != 0; 2041 clientCount = source.readInt(); 2042 crashCount = source.readInt(); 2043 lastActivityTime = source.readLong(); 2044 restarting = source.readLong(); 2045 flags = source.readInt(); 2046 clientPackage = source.readString(); 2047 clientLabel = source.readInt(); 2048 } 2049 2050 public static final Creator<RunningServiceInfo> CREATOR = new Creator<RunningServiceInfo>() { 2051 public RunningServiceInfo createFromParcel(Parcel source) { 2052 return new RunningServiceInfo(source); 2053 } 2054 public RunningServiceInfo[] newArray(int size) { 2055 return new RunningServiceInfo[size]; 2056 } 2057 }; 2058 2059 private RunningServiceInfo(Parcel source) { 2060 readFromParcel(source); 2061 } 2062 } 2063 2064 /** 2065 * Return a list of the services that are currently running. 2066 * 2067 * <p><b>Note: this method is only intended for debugging or implementing 2068 * service management type user interfaces.</b></p> 2069 * 2070 * @param maxNum The maximum number of entries to return in the list. The 2071 * actual number returned may be smaller, depending on how many services 2072 * are running. 2073 * 2074 * @return Returns a list of RunningServiceInfo records describing each of 2075 * the running tasks. 2076 */ 2077 public List<RunningServiceInfo> getRunningServices(int maxNum) 2078 throws SecurityException { 2079 try { 2080 return ActivityManagerNative.getDefault() 2081 .getServices(maxNum, 0); 2082 } catch (RemoteException e) { 2083 // System dead, we will be dead too soon! 2084 return null; 2085 } 2086 } 2087 2088 /** 2089 * Returns a PendingIntent you can start to show a control panel for the 2090 * given running service. If the service does not have a control panel, 2091 * null is returned. 2092 */ 2093 public PendingIntent getRunningServiceControlPanel(ComponentName service) 2094 throws SecurityException { 2095 try { 2096 return ActivityManagerNative.getDefault() 2097 .getRunningServiceControlPanel(service); 2098 } catch (RemoteException e) { 2099 // System dead, we will be dead too soon! 2100 return null; 2101 } 2102 } 2103 2104 /** 2105 * Information you can retrieve about the available memory through 2106 * {@link ActivityManager#getMemoryInfo}. 2107 */ 2108 public static class MemoryInfo implements Parcelable { 2109 /** 2110 * The available memory on the system. This number should not 2111 * be considered absolute: due to the nature of the kernel, a significant 2112 * portion of this memory is actually in use and needed for the overall 2113 * system to run well. 2114 */ 2115 public long availMem; 2116 2117 /** 2118 * The total memory accessible by the kernel. This is basically the 2119 * RAM size of the device, not including below-kernel fixed allocations 2120 * like DMA buffers, RAM for the baseband CPU, etc. 2121 */ 2122 public long totalMem; 2123 2124 /** 2125 * The threshold of {@link #availMem} at which we consider memory to be 2126 * low and start killing background services and other non-extraneous 2127 * processes. 2128 */ 2129 public long threshold; 2130 2131 /** 2132 * Set to true if the system considers itself to currently be in a low 2133 * memory situation. 2134 */ 2135 public boolean lowMemory; 2136 2137 /** @hide */ 2138 public long hiddenAppThreshold; 2139 /** @hide */ 2140 public long secondaryServerThreshold; 2141 /** @hide */ 2142 public long visibleAppThreshold; 2143 /** @hide */ 2144 public long foregroundAppThreshold; 2145 2146 public MemoryInfo() { 2147 } 2148 2149 public int describeContents() { 2150 return 0; 2151 } 2152 2153 public void writeToParcel(Parcel dest, int flags) { 2154 dest.writeLong(availMem); 2155 dest.writeLong(totalMem); 2156 dest.writeLong(threshold); 2157 dest.writeInt(lowMemory ? 1 : 0); 2158 dest.writeLong(hiddenAppThreshold); 2159 dest.writeLong(secondaryServerThreshold); 2160 dest.writeLong(visibleAppThreshold); 2161 dest.writeLong(foregroundAppThreshold); 2162 } 2163 2164 public void readFromParcel(Parcel source) { 2165 availMem = source.readLong(); 2166 totalMem = source.readLong(); 2167 threshold = source.readLong(); 2168 lowMemory = source.readInt() != 0; 2169 hiddenAppThreshold = source.readLong(); 2170 secondaryServerThreshold = source.readLong(); 2171 visibleAppThreshold = source.readLong(); 2172 foregroundAppThreshold = source.readLong(); 2173 } 2174 2175 public static final Creator<MemoryInfo> CREATOR 2176 = new Creator<MemoryInfo>() { 2177 public MemoryInfo createFromParcel(Parcel source) { 2178 return new MemoryInfo(source); 2179 } 2180 public MemoryInfo[] newArray(int size) { 2181 return new MemoryInfo[size]; 2182 } 2183 }; 2184 2185 private MemoryInfo(Parcel source) { 2186 readFromParcel(source); 2187 } 2188 } 2189 2190 /** 2191 * Return general information about the memory state of the system. This 2192 * can be used to help decide how to manage your own memory, though note 2193 * that polling is not recommended and 2194 * {@link android.content.ComponentCallbacks2#onTrimMemory(int) 2195 * ComponentCallbacks2.onTrimMemory(int)} is the preferred way to do this. 2196 * Also see {@link #getMyMemoryState} for how to retrieve the current trim 2197 * level of your process as needed, which gives a better hint for how to 2198 * manage its memory. 2199 */ 2200 public void getMemoryInfo(MemoryInfo outInfo) { 2201 try { 2202 ActivityManagerNative.getDefault().getMemoryInfo(outInfo); 2203 } catch (RemoteException e) { 2204 } 2205 } 2206 2207 /** 2208 * Information you can retrieve about an ActivityStack in the system. 2209 * @hide 2210 */ 2211 public static class StackInfo implements Parcelable { 2212 public int stackId; 2213 public Rect bounds = new Rect(); 2214 public int[] taskIds; 2215 public String[] taskNames; 2216 public Rect[] taskBounds; 2217 public int[] taskUserIds; 2218 public int displayId; 2219 public int userId; 2220 2221 @Override 2222 public int describeContents() { 2223 return 0; 2224 } 2225 2226 @Override 2227 public void writeToParcel(Parcel dest, int flags) { 2228 dest.writeInt(stackId); 2229 dest.writeInt(bounds.left); 2230 dest.writeInt(bounds.top); 2231 dest.writeInt(bounds.right); 2232 dest.writeInt(bounds.bottom); 2233 dest.writeIntArray(taskIds); 2234 dest.writeStringArray(taskNames); 2235 final int boundsCount = taskBounds == null ? 0 : taskBounds.length; 2236 dest.writeInt(boundsCount); 2237 for (int i = 0; i < boundsCount; i++) { 2238 dest.writeInt(taskBounds[i].left); 2239 dest.writeInt(taskBounds[i].top); 2240 dest.writeInt(taskBounds[i].right); 2241 dest.writeInt(taskBounds[i].bottom); 2242 } 2243 dest.writeIntArray(taskUserIds); 2244 dest.writeInt(displayId); 2245 dest.writeInt(userId); 2246 } 2247 2248 public void readFromParcel(Parcel source) { 2249 stackId = source.readInt(); 2250 bounds = new Rect( 2251 source.readInt(), source.readInt(), source.readInt(), source.readInt()); 2252 taskIds = source.createIntArray(); 2253 taskNames = source.createStringArray(); 2254 final int boundsCount = source.readInt(); 2255 if (boundsCount > 0) { 2256 taskBounds = new Rect[boundsCount]; 2257 for (int i = 0; i < boundsCount; i++) { 2258 taskBounds[i] = new Rect(); 2259 taskBounds[i].set( 2260 source.readInt(), source.readInt(), source.readInt(), source.readInt()); 2261 } 2262 } else { 2263 taskBounds = null; 2264 } 2265 taskUserIds = source.createIntArray(); 2266 displayId = source.readInt(); 2267 userId = source.readInt(); 2268 } 2269 2270 public static final Creator<StackInfo> CREATOR = new Creator<StackInfo>() { 2271 @Override 2272 public StackInfo createFromParcel(Parcel source) { 2273 return new StackInfo(source); 2274 } 2275 @Override 2276 public StackInfo[] newArray(int size) { 2277 return new StackInfo[size]; 2278 } 2279 }; 2280 2281 public StackInfo() { 2282 } 2283 2284 private StackInfo(Parcel source) { 2285 readFromParcel(source); 2286 } 2287 2288 public String toString(String prefix) { 2289 StringBuilder sb = new StringBuilder(256); 2290 sb.append(prefix); sb.append("Stack id="); sb.append(stackId); 2291 sb.append(" bounds="); sb.append(bounds.toShortString()); 2292 sb.append(" displayId="); sb.append(displayId); 2293 sb.append(" userId="); sb.append(userId); 2294 sb.append("\n"); 2295 prefix = prefix + " "; 2296 for (int i = 0; i < taskIds.length; ++i) { 2297 sb.append(prefix); sb.append("taskId="); sb.append(taskIds[i]); 2298 sb.append(": "); sb.append(taskNames[i]); 2299 if (taskBounds != null) { 2300 sb.append(" bounds="); sb.append(taskBounds[i].toShortString()); 2301 } 2302 sb.append(" userId=").append(taskUserIds[i]); 2303 sb.append("\n"); 2304 } 2305 return sb.toString(); 2306 } 2307 2308 @Override 2309 public String toString() { 2310 return toString(""); 2311 } 2312 } 2313 2314 /** 2315 * @hide 2316 */ 2317 public boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) { 2318 try { 2319 return ActivityManagerNative.getDefault().clearApplicationUserData(packageName, 2320 observer, UserHandle.myUserId()); 2321 } catch (RemoteException e) { 2322 return false; 2323 } 2324 } 2325 2326 /** 2327 * Permits an application to erase its own data from disk. This is equivalent to 2328 * the user choosing to clear the app's data from within the device settings UI. It 2329 * erases all dynamic data associated with the app -- its private data and data in its 2330 * private area on external storage -- but does not remove the installed application 2331 * itself, nor any OBB files. 2332 * 2333 * @return {@code true} if the application successfully requested that the application's 2334 * data be erased; {@code false} otherwise. 2335 */ 2336 public boolean clearApplicationUserData() { 2337 return clearApplicationUserData(mContext.getPackageName(), null); 2338 } 2339 2340 2341 /** 2342 * Permits an application to get the persistent URI permissions granted to another. 2343 * 2344 * <p>Typically called by Settings. 2345 * 2346 * @param packageName application to look for the granted permissions 2347 * @return list of granted URI permissions 2348 * 2349 * @hide 2350 */ 2351 public ParceledListSlice<UriPermission> getGrantedUriPermissions(String packageName) { 2352 try { 2353 return ActivityManagerNative.getDefault().getGrantedUriPermissions(packageName, 2354 UserHandle.myUserId()); 2355 } catch (RemoteException e) { 2356 Log.e(TAG, "Couldn't get granted URI permissions for :" + packageName, e); 2357 return ParceledListSlice.emptyList(); 2358 } 2359 } 2360 2361 /** 2362 * Permits an application to clear the persistent URI permissions granted to another. 2363 * 2364 * <p>Typically called by Settings. 2365 * 2366 * @param packageName application to clear its granted permissions 2367 * 2368 * @hide 2369 */ 2370 public void clearGrantedUriPermissions(String packageName) { 2371 try { 2372 ActivityManagerNative.getDefault().clearGrantedUriPermissions(packageName, 2373 UserHandle.myUserId()); 2374 } catch (RemoteException e) { 2375 Log.e(TAG, "Couldn't clear granted URI permissions for :" + packageName, e); 2376 } 2377 } 2378 2379 /** 2380 * Information you can retrieve about any processes that are in an error condition. 2381 */ 2382 public static class ProcessErrorStateInfo implements Parcelable { 2383 /** 2384 * Condition codes 2385 */ 2386 public static final int NO_ERROR = 0; 2387 public static final int CRASHED = 1; 2388 public static final int NOT_RESPONDING = 2; 2389 2390 /** 2391 * The condition that the process is in. 2392 */ 2393 public int condition; 2394 2395 /** 2396 * The process name in which the crash or error occurred. 2397 */ 2398 public String processName; 2399 2400 /** 2401 * The pid of this process; 0 if none 2402 */ 2403 public int pid; 2404 2405 /** 2406 * The kernel user-ID that has been assigned to this process; 2407 * currently this is not a unique ID (multiple applications can have 2408 * the same uid). 2409 */ 2410 public int uid; 2411 2412 /** 2413 * The activity name associated with the error, if known. May be null. 2414 */ 2415 public String tag; 2416 2417 /** 2418 * A short message describing the error condition. 2419 */ 2420 public String shortMsg; 2421 2422 /** 2423 * A long message describing the error condition. 2424 */ 2425 public String longMsg; 2426 2427 /** 2428 * The stack trace where the error originated. May be null. 2429 */ 2430 public String stackTrace; 2431 2432 /** 2433 * to be deprecated: This value will always be null. 2434 */ 2435 public byte[] crashData = null; 2436 2437 public ProcessErrorStateInfo() { 2438 } 2439 2440 @Override 2441 public int describeContents() { 2442 return 0; 2443 } 2444 2445 @Override 2446 public void writeToParcel(Parcel dest, int flags) { 2447 dest.writeInt(condition); 2448 dest.writeString(processName); 2449 dest.writeInt(pid); 2450 dest.writeInt(uid); 2451 dest.writeString(tag); 2452 dest.writeString(shortMsg); 2453 dest.writeString(longMsg); 2454 dest.writeString(stackTrace); 2455 } 2456 2457 public void readFromParcel(Parcel source) { 2458 condition = source.readInt(); 2459 processName = source.readString(); 2460 pid = source.readInt(); 2461 uid = source.readInt(); 2462 tag = source.readString(); 2463 shortMsg = source.readString(); 2464 longMsg = source.readString(); 2465 stackTrace = source.readString(); 2466 } 2467 2468 public static final Creator<ProcessErrorStateInfo> CREATOR = 2469 new Creator<ProcessErrorStateInfo>() { 2470 public ProcessErrorStateInfo createFromParcel(Parcel source) { 2471 return new ProcessErrorStateInfo(source); 2472 } 2473 public ProcessErrorStateInfo[] newArray(int size) { 2474 return new ProcessErrorStateInfo[size]; 2475 } 2476 }; 2477 2478 private ProcessErrorStateInfo(Parcel source) { 2479 readFromParcel(source); 2480 } 2481 } 2482 2483 /** 2484 * Returns a list of any processes that are currently in an error condition. The result 2485 * will be null if all processes are running properly at this time. 2486 * 2487 * @return Returns a list of ProcessErrorStateInfo records, or null if there are no 2488 * current error conditions (it will not return an empty list). This list ordering is not 2489 * specified. 2490 */ 2491 public List<ProcessErrorStateInfo> getProcessesInErrorState() { 2492 try { 2493 return ActivityManagerNative.getDefault().getProcessesInErrorState(); 2494 } catch (RemoteException e) { 2495 return null; 2496 } 2497 } 2498 2499 /** 2500 * Information you can retrieve about a running process. 2501 */ 2502 public static class RunningAppProcessInfo implements Parcelable { 2503 /** 2504 * The name of the process that this object is associated with 2505 */ 2506 public String processName; 2507 2508 /** 2509 * The pid of this process; 0 if none 2510 */ 2511 public int pid; 2512 2513 /** 2514 * The user id of this process. 2515 */ 2516 public int uid; 2517 2518 /** 2519 * All packages that have been loaded into the process. 2520 */ 2521 public String pkgList[]; 2522 2523 /** 2524 * Constant for {@link #flags}: this is an app that is unable to 2525 * correctly save its state when going to the background, 2526 * so it can not be killed while in the background. 2527 * @hide 2528 */ 2529 public static final int FLAG_CANT_SAVE_STATE = 1<<0; 2530 2531 /** 2532 * Constant for {@link #flags}: this process is associated with a 2533 * persistent system app. 2534 * @hide 2535 */ 2536 public static final int FLAG_PERSISTENT = 1<<1; 2537 2538 /** 2539 * Constant for {@link #flags}: this process is associated with a 2540 * persistent system app. 2541 * @hide 2542 */ 2543 public static final int FLAG_HAS_ACTIVITIES = 1<<2; 2544 2545 /** 2546 * Flags of information. May be any of 2547 * {@link #FLAG_CANT_SAVE_STATE}. 2548 * @hide 2549 */ 2550 public int flags; 2551 2552 /** 2553 * Last memory trim level reported to the process: corresponds to 2554 * the values supplied to {@link android.content.ComponentCallbacks2#onTrimMemory(int) 2555 * ComponentCallbacks2.onTrimMemory(int)}. 2556 */ 2557 public int lastTrimLevel; 2558 2559 /** 2560 * Constant for {@link #importance}: This process is running the 2561 * foreground UI; that is, it is the thing currently at the top of the screen 2562 * that the user is interacting with. 2563 */ 2564 public static final int IMPORTANCE_FOREGROUND = 100; 2565 2566 /** 2567 * Constant for {@link #importance}: This process is running a foreground 2568 * service, for example to perform music playback even while the user is 2569 * not immediately in the app. This generally indicates that the process 2570 * is doing something the user actively cares about. 2571 */ 2572 public static final int IMPORTANCE_FOREGROUND_SERVICE = 125; 2573 2574 /** 2575 * Constant for {@link #importance}: This process is running the foreground 2576 * UI, but the device is asleep so it is not visible to the user. This means 2577 * the user is not really aware of the process, because they can not see or 2578 * interact with it, but it is quite important because it what they expect to 2579 * return to once unlocking the device. 2580 */ 2581 public static final int IMPORTANCE_TOP_SLEEPING = 150; 2582 2583 /** 2584 * Constant for {@link #importance}: This process is running something 2585 * that is actively visible to the user, though not in the immediate 2586 * foreground. This may be running a window that is behind the current 2587 * foreground (so paused and with its state saved, not interacting with 2588 * the user, but visible to them to some degree); it may also be running 2589 * other services under the system's control that it inconsiders important. 2590 */ 2591 public static final int IMPORTANCE_VISIBLE = 200; 2592 2593 /** 2594 * Constant for {@link #importance}: This process is not something the user 2595 * is directly aware of, but is otherwise perceptable to them to some degree. 2596 */ 2597 public static final int IMPORTANCE_PERCEPTIBLE = 130; 2598 2599 /** 2600 * Constant for {@link #importance}: This process is running an 2601 * application that can not save its state, and thus can't be killed 2602 * while in the background. 2603 * @hide 2604 */ 2605 public static final int IMPORTANCE_CANT_SAVE_STATE = 170; 2606 2607 /** 2608 * Constant for {@link #importance}: This process is contains services 2609 * that should remain running. These are background services apps have 2610 * started, not something the user is aware of, so they may be killed by 2611 * the system relatively freely (though it is generally desired that they 2612 * stay running as long as they want to). 2613 */ 2614 public static final int IMPORTANCE_SERVICE = 300; 2615 2616 /** 2617 * Constant for {@link #importance}: This process process contains 2618 * background code that is expendable. 2619 */ 2620 public static final int IMPORTANCE_BACKGROUND = 400; 2621 2622 /** 2623 * Constant for {@link #importance}: This process is empty of any 2624 * actively running code. 2625 */ 2626 public static final int IMPORTANCE_EMPTY = 500; 2627 2628 /** 2629 * Constant for {@link #importance}: This process does not exist. 2630 */ 2631 public static final int IMPORTANCE_GONE = 1000; 2632 2633 /** @hide */ 2634 public static int procStateToImportance(int procState) { 2635 if (procState == PROCESS_STATE_NONEXISTENT) { 2636 return IMPORTANCE_GONE; 2637 } else if (procState >= PROCESS_STATE_HOME) { 2638 return IMPORTANCE_BACKGROUND; 2639 } else if (procState >= PROCESS_STATE_SERVICE) { 2640 return IMPORTANCE_SERVICE; 2641 } else if (procState > PROCESS_STATE_HEAVY_WEIGHT) { 2642 return IMPORTANCE_CANT_SAVE_STATE; 2643 } else if (procState >= PROCESS_STATE_IMPORTANT_BACKGROUND) { 2644 return IMPORTANCE_PERCEPTIBLE; 2645 } else if (procState >= PROCESS_STATE_IMPORTANT_FOREGROUND) { 2646 return IMPORTANCE_VISIBLE; 2647 } else if (procState >= PROCESS_STATE_TOP_SLEEPING) { 2648 return IMPORTANCE_TOP_SLEEPING; 2649 } else if (procState >= PROCESS_STATE_FOREGROUND_SERVICE) { 2650 return IMPORTANCE_FOREGROUND_SERVICE; 2651 } else { 2652 return IMPORTANCE_FOREGROUND; 2653 } 2654 } 2655 2656 /** 2657 * The relative importance level that the system places on this 2658 * process. May be one of {@link #IMPORTANCE_FOREGROUND}, 2659 * {@link #IMPORTANCE_VISIBLE}, {@link #IMPORTANCE_SERVICE}, 2660 * {@link #IMPORTANCE_BACKGROUND}, or {@link #IMPORTANCE_EMPTY}. These 2661 * constants are numbered so that "more important" values are always 2662 * smaller than "less important" values. 2663 */ 2664 public int importance; 2665 2666 /** 2667 * An additional ordering within a particular {@link #importance} 2668 * category, providing finer-grained information about the relative 2669 * utility of processes within a category. This number means nothing 2670 * except that a smaller values are more recently used (and thus 2671 * more important). Currently an LRU value is only maintained for 2672 * the {@link #IMPORTANCE_BACKGROUND} category, though others may 2673 * be maintained in the future. 2674 */ 2675 public int lru; 2676 2677 /** 2678 * Constant for {@link #importanceReasonCode}: nothing special has 2679 * been specified for the reason for this level. 2680 */ 2681 public static final int REASON_UNKNOWN = 0; 2682 2683 /** 2684 * Constant for {@link #importanceReasonCode}: one of the application's 2685 * content providers is being used by another process. The pid of 2686 * the client process is in {@link #importanceReasonPid} and the 2687 * target provider in this process is in 2688 * {@link #importanceReasonComponent}. 2689 */ 2690 public static final int REASON_PROVIDER_IN_USE = 1; 2691 2692 /** 2693 * Constant for {@link #importanceReasonCode}: one of the application's 2694 * content providers is being used by another process. The pid of 2695 * the client process is in {@link #importanceReasonPid} and the 2696 * target provider in this process is in 2697 * {@link #importanceReasonComponent}. 2698 */ 2699 public static final int REASON_SERVICE_IN_USE = 2; 2700 2701 /** 2702 * The reason for {@link #importance}, if any. 2703 */ 2704 public int importanceReasonCode; 2705 2706 /** 2707 * For the specified values of {@link #importanceReasonCode}, this 2708 * is the process ID of the other process that is a client of this 2709 * process. This will be 0 if no other process is using this one. 2710 */ 2711 public int importanceReasonPid; 2712 2713 /** 2714 * For the specified values of {@link #importanceReasonCode}, this 2715 * is the name of the component that is being used in this process. 2716 */ 2717 public ComponentName importanceReasonComponent; 2718 2719 /** 2720 * When {@link #importanceReasonPid} is non-0, this is the importance 2721 * of the other pid. @hide 2722 */ 2723 public int importanceReasonImportance; 2724 2725 /** 2726 * Current process state, as per PROCESS_STATE_* constants. 2727 * @hide 2728 */ 2729 public int processState; 2730 2731 public RunningAppProcessInfo() { 2732 importance = IMPORTANCE_FOREGROUND; 2733 importanceReasonCode = REASON_UNKNOWN; 2734 processState = PROCESS_STATE_IMPORTANT_FOREGROUND; 2735 } 2736 2737 public RunningAppProcessInfo(String pProcessName, int pPid, String pArr[]) { 2738 processName = pProcessName; 2739 pid = pPid; 2740 pkgList = pArr; 2741 } 2742 2743 public int describeContents() { 2744 return 0; 2745 } 2746 2747 public void writeToParcel(Parcel dest, int flags) { 2748 dest.writeString(processName); 2749 dest.writeInt(pid); 2750 dest.writeInt(uid); 2751 dest.writeStringArray(pkgList); 2752 dest.writeInt(this.flags); 2753 dest.writeInt(lastTrimLevel); 2754 dest.writeInt(importance); 2755 dest.writeInt(lru); 2756 dest.writeInt(importanceReasonCode); 2757 dest.writeInt(importanceReasonPid); 2758 ComponentName.writeToParcel(importanceReasonComponent, dest); 2759 dest.writeInt(importanceReasonImportance); 2760 dest.writeInt(processState); 2761 } 2762 2763 public void readFromParcel(Parcel source) { 2764 processName = source.readString(); 2765 pid = source.readInt(); 2766 uid = source.readInt(); 2767 pkgList = source.readStringArray(); 2768 flags = source.readInt(); 2769 lastTrimLevel = source.readInt(); 2770 importance = source.readInt(); 2771 lru = source.readInt(); 2772 importanceReasonCode = source.readInt(); 2773 importanceReasonPid = source.readInt(); 2774 importanceReasonComponent = ComponentName.readFromParcel(source); 2775 importanceReasonImportance = source.readInt(); 2776 processState = source.readInt(); 2777 } 2778 2779 public static final Creator<RunningAppProcessInfo> CREATOR = 2780 new Creator<RunningAppProcessInfo>() { 2781 public RunningAppProcessInfo createFromParcel(Parcel source) { 2782 return new RunningAppProcessInfo(source); 2783 } 2784 public RunningAppProcessInfo[] newArray(int size) { 2785 return new RunningAppProcessInfo[size]; 2786 } 2787 }; 2788 2789 private RunningAppProcessInfo(Parcel source) { 2790 readFromParcel(source); 2791 } 2792 } 2793 2794 /** 2795 * Returns a list of application processes installed on external media 2796 * that are running on the device. 2797 * 2798 * <p><b>Note: this method is only intended for debugging or building 2799 * a user-facing process management UI.</b></p> 2800 * 2801 * @return Returns a list of ApplicationInfo records, or null if none 2802 * This list ordering is not specified. 2803 * @hide 2804 */ 2805 public List<ApplicationInfo> getRunningExternalApplications() { 2806 try { 2807 return ActivityManagerNative.getDefault().getRunningExternalApplications(); 2808 } catch (RemoteException e) { 2809 return null; 2810 } 2811 } 2812 2813 /** 2814 * Sets the memory trim mode for a process and schedules a memory trim operation. 2815 * 2816 * <p><b>Note: this method is only intended for testing framework.</b></p> 2817 * 2818 * @return Returns true if successful. 2819 * @hide 2820 */ 2821 public boolean setProcessMemoryTrimLevel(String process, int userId, int level) { 2822 try { 2823 return ActivityManagerNative.getDefault().setProcessMemoryTrimLevel(process, userId, 2824 level); 2825 } catch (RemoteException e) { 2826 return false; 2827 } 2828 } 2829 2830 /** 2831 * Returns a list of application processes that are running on the device. 2832 * 2833 * <p><b>Note: this method is only intended for debugging or building 2834 * a user-facing process management UI.</b></p> 2835 * 2836 * @return Returns a list of RunningAppProcessInfo records, or null if there are no 2837 * running processes (it will not return an empty list). This list ordering is not 2838 * specified. 2839 */ 2840 public List<RunningAppProcessInfo> getRunningAppProcesses() { 2841 try { 2842 return ActivityManagerNative.getDefault().getRunningAppProcesses(); 2843 } catch (RemoteException e) { 2844 return null; 2845 } 2846 } 2847 2848 /** 2849 * Return the importance of a given package name, based on the processes that are 2850 * currently running. The return value is one of the importance constants defined 2851 * in {@link RunningAppProcessInfo}, giving you the highest importance of all the 2852 * processes that this package has code running inside of. If there are no processes 2853 * running its code, {@link RunningAppProcessInfo#IMPORTANCE_GONE} is returned. 2854 * @hide 2855 */ 2856 @SystemApi 2857 public int getPackageImportance(String packageName) { 2858 try { 2859 int procState = ActivityManagerNative.getDefault().getPackageProcessState(packageName, 2860 mContext.getOpPackageName()); 2861 return RunningAppProcessInfo.procStateToImportance(procState); 2862 } catch (RemoteException e) { 2863 return RunningAppProcessInfo.IMPORTANCE_GONE; 2864 } 2865 } 2866 2867 /** 2868 * Return global memory state information for the calling process. This 2869 * does not fill in all fields of the {@link RunningAppProcessInfo}. The 2870 * only fields that will be filled in are 2871 * {@link RunningAppProcessInfo#pid}, 2872 * {@link RunningAppProcessInfo#uid}, 2873 * {@link RunningAppProcessInfo#lastTrimLevel}, 2874 * {@link RunningAppProcessInfo#importance}, 2875 * {@link RunningAppProcessInfo#lru}, and 2876 * {@link RunningAppProcessInfo#importanceReasonCode}. 2877 */ 2878 static public void getMyMemoryState(RunningAppProcessInfo outState) { 2879 try { 2880 ActivityManagerNative.getDefault().getMyMemoryState(outState); 2881 } catch (RemoteException e) { 2882 } 2883 } 2884 2885 /** 2886 * Return information about the memory usage of one or more processes. 2887 * 2888 * <p><b>Note: this method is only intended for debugging or building 2889 * a user-facing process management UI.</b></p> 2890 * 2891 * @param pids The pids of the processes whose memory usage is to be 2892 * retrieved. 2893 * @return Returns an array of memory information, one for each 2894 * requested pid. 2895 */ 2896 public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) { 2897 try { 2898 return ActivityManagerNative.getDefault().getProcessMemoryInfo(pids); 2899 } catch (RemoteException e) { 2900 return null; 2901 } 2902 } 2903 2904 /** 2905 * @deprecated This is now just a wrapper for 2906 * {@link #killBackgroundProcesses(String)}; the previous behavior here 2907 * is no longer available to applications because it allows them to 2908 * break other applications by removing their alarms, stopping their 2909 * services, etc. 2910 */ 2911 @Deprecated 2912 public void restartPackage(String packageName) { 2913 killBackgroundProcesses(packageName); 2914 } 2915 2916 /** 2917 * Have the system immediately kill all background processes associated 2918 * with the given package. This is the same as the kernel killing those 2919 * processes to reclaim memory; the system will take care of restarting 2920 * these processes in the future as needed. 2921 * 2922 * <p>You must hold the permission 2923 * {@link android.Manifest.permission#KILL_BACKGROUND_PROCESSES} to be able to 2924 * call this method. 2925 * 2926 * @param packageName The name of the package whose processes are to 2927 * be killed. 2928 */ 2929 public void killBackgroundProcesses(String packageName) { 2930 try { 2931 ActivityManagerNative.getDefault().killBackgroundProcesses(packageName, 2932 UserHandle.myUserId()); 2933 } catch (RemoteException e) { 2934 } 2935 } 2936 2937 /** 2938 * Kills the specified UID. 2939 * @param uid The UID to kill. 2940 * @param reason The reason for the kill. 2941 * 2942 * @hide 2943 */ 2944 @RequiresPermission(Manifest.permission.KILL_UID) 2945 public void killUid(int uid, String reason) { 2946 try { 2947 ActivityManagerNative.getDefault().killUid(UserHandle.getAppId(uid), 2948 UserHandle.getUserId(uid), reason); 2949 } catch (RemoteException e) { 2950 Log.e(TAG, "Couldn't kill uid:" + uid, e); 2951 } 2952 } 2953 2954 /** 2955 * Have the system perform a force stop of everything associated with 2956 * the given application package. All processes that share its uid 2957 * will be killed, all services it has running stopped, all activities 2958 * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED} 2959 * broadcast will be sent, so that any of its registered alarms can 2960 * be stopped, notifications removed, etc. 2961 * 2962 * <p>You must hold the permission 2963 * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to 2964 * call this method. 2965 * 2966 * @param packageName The name of the package to be stopped. 2967 * @param userId The user for which the running package is to be stopped. 2968 * 2969 * @hide This is not available to third party applications due to 2970 * it allowing them to break other applications by stopping their 2971 * services, removing their alarms, etc. 2972 */ 2973 public void forceStopPackageAsUser(String packageName, int userId) { 2974 try { 2975 ActivityManagerNative.getDefault().forceStopPackage(packageName, userId); 2976 } catch (RemoteException e) { 2977 } 2978 } 2979 2980 /** 2981 * @see #forceStopPackageAsUser(String, int) 2982 * @hide 2983 */ 2984 public void forceStopPackage(String packageName) { 2985 forceStopPackageAsUser(packageName, UserHandle.myUserId()); 2986 } 2987 2988 /** 2989 * Get the device configuration attributes. 2990 */ 2991 public ConfigurationInfo getDeviceConfigurationInfo() { 2992 try { 2993 return ActivityManagerNative.getDefault().getDeviceConfigurationInfo(); 2994 } catch (RemoteException e) { 2995 } 2996 return null; 2997 } 2998 2999 /** 3000 * Get the preferred density of icons for the launcher. This is used when 3001 * custom drawables are created (e.g., for shortcuts). 3002 * 3003 * @return density in terms of DPI 3004 */ 3005 public int getLauncherLargeIconDensity() { 3006 final Resources res = mContext.getResources(); 3007 final int density = res.getDisplayMetrics().densityDpi; 3008 final int sw = res.getConfiguration().smallestScreenWidthDp; 3009 3010 if (sw < 600) { 3011 // Smaller than approx 7" tablets, use the regular icon size. 3012 return density; 3013 } 3014 3015 switch (density) { 3016 case DisplayMetrics.DENSITY_LOW: 3017 return DisplayMetrics.DENSITY_MEDIUM; 3018 case DisplayMetrics.DENSITY_MEDIUM: 3019 return DisplayMetrics.DENSITY_HIGH; 3020 case DisplayMetrics.DENSITY_TV: 3021 return DisplayMetrics.DENSITY_XHIGH; 3022 case DisplayMetrics.DENSITY_HIGH: 3023 return DisplayMetrics.DENSITY_XHIGH; 3024 case DisplayMetrics.DENSITY_XHIGH: 3025 return DisplayMetrics.DENSITY_XXHIGH; 3026 case DisplayMetrics.DENSITY_XXHIGH: 3027 return DisplayMetrics.DENSITY_XHIGH * 2; 3028 default: 3029 // The density is some abnormal value. Return some other 3030 // abnormal value that is a reasonable scaling of it. 3031 return (int)((density*1.5f)+.5f); 3032 } 3033 } 3034 3035 /** 3036 * Get the preferred launcher icon size. This is used when custom drawables 3037 * are created (e.g., for shortcuts). 3038 * 3039 * @return dimensions of square icons in terms of pixels 3040 */ 3041 public int getLauncherLargeIconSize() { 3042 return getLauncherLargeIconSizeInner(mContext); 3043 } 3044 3045 static int getLauncherLargeIconSizeInner(Context context) { 3046 final Resources res = context.getResources(); 3047 final int size = res.getDimensionPixelSize(android.R.dimen.app_icon_size); 3048 final int sw = res.getConfiguration().smallestScreenWidthDp; 3049 3050 if (sw < 600) { 3051 // Smaller than approx 7" tablets, use the regular icon size. 3052 return size; 3053 } 3054 3055 final int density = res.getDisplayMetrics().densityDpi; 3056 3057 switch (density) { 3058 case DisplayMetrics.DENSITY_LOW: 3059 return (size * DisplayMetrics.DENSITY_MEDIUM) / DisplayMetrics.DENSITY_LOW; 3060 case DisplayMetrics.DENSITY_MEDIUM: 3061 return (size * DisplayMetrics.DENSITY_HIGH) / DisplayMetrics.DENSITY_MEDIUM; 3062 case DisplayMetrics.DENSITY_TV: 3063 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH; 3064 case DisplayMetrics.DENSITY_HIGH: 3065 return (size * DisplayMetrics.DENSITY_XHIGH) / DisplayMetrics.DENSITY_HIGH; 3066 case DisplayMetrics.DENSITY_XHIGH: 3067 return (size * DisplayMetrics.DENSITY_XXHIGH) / DisplayMetrics.DENSITY_XHIGH; 3068 case DisplayMetrics.DENSITY_XXHIGH: 3069 return (size * DisplayMetrics.DENSITY_XHIGH*2) / DisplayMetrics.DENSITY_XXHIGH; 3070 default: 3071 // The density is some abnormal value. Return some other 3072 // abnormal value that is a reasonable scaling of it. 3073 return (int)((size*1.5f) + .5f); 3074 } 3075 } 3076 3077 /** 3078 * Returns "true" if the user interface is currently being messed with 3079 * by a monkey. 3080 */ 3081 public static boolean isUserAMonkey() { 3082 try { 3083 return ActivityManagerNative.getDefault().isUserAMonkey(); 3084 } catch (RemoteException e) { 3085 } 3086 return false; 3087 } 3088 3089 /** 3090 * Returns "true" if device is running in a test harness. 3091 */ 3092 public static boolean isRunningInTestHarness() { 3093 return SystemProperties.getBoolean("ro.test_harness", false); 3094 } 3095 3096 /** 3097 * Returns the launch count of each installed package. 3098 * 3099 * @hide 3100 */ 3101 /*public Map<String, Integer> getAllPackageLaunchCounts() { 3102 try { 3103 IUsageStats usageStatsService = IUsageStats.Stub.asInterface( 3104 ServiceManager.getService("usagestats")); 3105 if (usageStatsService == null) { 3106 return new HashMap<String, Integer>(); 3107 } 3108 3109 UsageStats.PackageStats[] allPkgUsageStats = usageStatsService.getAllPkgUsageStats( 3110 ActivityThread.currentPackageName()); 3111 if (allPkgUsageStats == null) { 3112 return new HashMap<String, Integer>(); 3113 } 3114 3115 Map<String, Integer> launchCounts = new HashMap<String, Integer>(); 3116 for (UsageStats.PackageStats pkgUsageStats : allPkgUsageStats) { 3117 launchCounts.put(pkgUsageStats.getPackageName(), pkgUsageStats.getLaunchCount()); 3118 } 3119 3120 return launchCounts; 3121 } catch (RemoteException e) { 3122 Log.w(TAG, "Could not query launch counts", e); 3123 return new HashMap<String, Integer>(); 3124 } 3125 }*/ 3126 3127 /** @hide */ 3128 public static int checkComponentPermission(String permission, int uid, 3129 int owningUid, boolean exported) { 3130 // Root, system server get to do everything. 3131 final int appId = UserHandle.getAppId(uid); 3132 if (appId == Process.ROOT_UID || appId == Process.SYSTEM_UID) { 3133 return PackageManager.PERMISSION_GRANTED; 3134 } 3135 // Isolated processes don't get any permissions. 3136 if (UserHandle.isIsolated(uid)) { 3137 return PackageManager.PERMISSION_DENIED; 3138 } 3139 // If there is a uid that owns whatever is being accessed, it has 3140 // blanket access to it regardless of the permissions it requires. 3141 if (owningUid >= 0 && UserHandle.isSameApp(uid, owningUid)) { 3142 return PackageManager.PERMISSION_GRANTED; 3143 } 3144 // If the target is not exported, then nobody else can get to it. 3145 if (!exported) { 3146 /* 3147 RuntimeException here = new RuntimeException("here"); 3148 here.fillInStackTrace(); 3149 Slog.w(TAG, "Permission denied: checkComponentPermission() owningUid=" + owningUid, 3150 here); 3151 */ 3152 return PackageManager.PERMISSION_DENIED; 3153 } 3154 if (permission == null) { 3155 return PackageManager.PERMISSION_GRANTED; 3156 } 3157 try { 3158 return AppGlobals.getPackageManager() 3159 .checkUidPermission(permission, uid); 3160 } catch (RemoteException e) { 3161 // Should never happen, but if it does... deny! 3162 Slog.e(TAG, "PackageManager is dead?!?", e); 3163 } 3164 return PackageManager.PERMISSION_DENIED; 3165 } 3166 3167 /** @hide */ 3168 public static int checkUidPermission(String permission, int uid) { 3169 try { 3170 return AppGlobals.getPackageManager() 3171 .checkUidPermission(permission, uid); 3172 } catch (RemoteException e) { 3173 // Should never happen, but if it does... deny! 3174 Slog.e(TAG, "PackageManager is dead?!?", e); 3175 } 3176 return PackageManager.PERMISSION_DENIED; 3177 } 3178 3179 /** 3180 * @hide 3181 * Helper for dealing with incoming user arguments to system service calls. 3182 * Takes care of checking permissions and converting USER_CURRENT to the 3183 * actual current user. 3184 * 3185 * @param callingPid The pid of the incoming call, as per Binder.getCallingPid(). 3186 * @param callingUid The uid of the incoming call, as per Binder.getCallingUid(). 3187 * @param userId The user id argument supplied by the caller -- this is the user 3188 * they want to run as. 3189 * @param allowAll If true, we will allow USER_ALL. This means you must be prepared 3190 * to get a USER_ALL returned and deal with it correctly. If false, 3191 * an exception will be thrown if USER_ALL is supplied. 3192 * @param requireFull If true, the caller must hold 3193 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} to be able to run as a 3194 * different user than their current process; otherwise they must hold 3195 * {@link android.Manifest.permission#INTERACT_ACROSS_USERS}. 3196 * @param name Optional textual name of the incoming call; only for generating error messages. 3197 * @param callerPackage Optional package name of caller; only for error messages. 3198 * 3199 * @return Returns the user ID that the call should run as. Will always be a concrete 3200 * user number, unless <var>allowAll</var> is true in which case it could also be 3201 * USER_ALL. 3202 */ 3203 public static int handleIncomingUser(int callingPid, int callingUid, int userId, 3204 boolean allowAll, boolean requireFull, String name, String callerPackage) { 3205 if (UserHandle.getUserId(callingUid) == userId) { 3206 return userId; 3207 } 3208 try { 3209 return ActivityManagerNative.getDefault().handleIncomingUser(callingPid, 3210 callingUid, userId, allowAll, requireFull, name, callerPackage); 3211 } catch (RemoteException e) { 3212 throw new SecurityException("Failed calling activity manager", e); 3213 } 3214 } 3215 3216 /** 3217 * Gets the userId of the current foreground user. Requires system permissions. 3218 * @hide 3219 */ 3220 @SystemApi 3221 public static int getCurrentUser() { 3222 UserInfo ui; 3223 try { 3224 ui = ActivityManagerNative.getDefault().getCurrentUser(); 3225 return ui != null ? ui.id : 0; 3226 } catch (RemoteException e) { 3227 return 0; 3228 } 3229 } 3230 3231 /** 3232 * @param userid the user's id. Zero indicates the default user. 3233 * @hide 3234 */ 3235 public boolean switchUser(int userid) { 3236 try { 3237 return ActivityManagerNative.getDefault().switchUser(userid); 3238 } catch (RemoteException e) { 3239 return false; 3240 } 3241 } 3242 3243 /** {@hide} */ 3244 public static final int FLAG_OR_STOPPED = 1 << 0; 3245 /** {@hide} */ 3246 public static final int FLAG_AND_LOCKED = 1 << 1; 3247 /** {@hide} */ 3248 public static final int FLAG_AND_UNLOCKED = 1 << 2; 3249 3250 /** 3251 * Return whether the given user is actively running. This means that 3252 * the user is in the "started" state, not "stopped" -- it is currently 3253 * allowed to run code through scheduled alarms, receiving broadcasts, 3254 * etc. A started user may be either the current foreground user or a 3255 * background user; the result here does not distinguish between the two. 3256 * @param userid the user's id. Zero indicates the default user. 3257 * @hide 3258 */ 3259 public boolean isUserRunning(int userId) { 3260 try { 3261 return ActivityManagerNative.getDefault().isUserRunning(userId, 0); 3262 } catch (RemoteException e) { 3263 return false; 3264 } 3265 } 3266 3267 /** {@hide} */ 3268 public boolean isUserRunningAndLocked(int userId) { 3269 try { 3270 return ActivityManagerNative.getDefault().isUserRunning(userId, 3271 ActivityManager.FLAG_AND_LOCKED); 3272 } catch (RemoteException e) { 3273 return false; 3274 } 3275 } 3276 3277 /** {@hide} */ 3278 public boolean isUserRunningAndUnlocked(int userId) { 3279 try { 3280 return ActivityManagerNative.getDefault().isUserRunning(userId, 3281 ActivityManager.FLAG_AND_UNLOCKED); 3282 } catch (RemoteException e) { 3283 return false; 3284 } 3285 } 3286 3287 /** 3288 * Perform a system dump of various state associated with the given application 3289 * package name. This call blocks while the dump is being performed, so should 3290 * not be done on a UI thread. The data will be written to the given file 3291 * descriptor as text. An application must hold the 3292 * {@link android.Manifest.permission#DUMP} permission to make this call. 3293 * @param fd The file descriptor that the dump should be written to. The file 3294 * descriptor is <em>not</em> closed by this function; the caller continues to 3295 * own it. 3296 * @param packageName The name of the package that is to be dumped. 3297 */ 3298 public void dumpPackageState(FileDescriptor fd, String packageName) { 3299 dumpPackageStateStatic(fd, packageName); 3300 } 3301 3302 /** 3303 * @hide 3304 */ 3305 public static void dumpPackageStateStatic(FileDescriptor fd, String packageName) { 3306 FileOutputStream fout = new FileOutputStream(fd); 3307 PrintWriter pw = new FastPrintWriter(fout); 3308 dumpService(pw, fd, "package", new String[] { packageName }); 3309 pw.println(); 3310 dumpService(pw, fd, Context.ACTIVITY_SERVICE, new String[] { 3311 "-a", "package", packageName }); 3312 pw.println(); 3313 dumpService(pw, fd, "meminfo", new String[] { "--local", "--package", packageName }); 3314 pw.println(); 3315 dumpService(pw, fd, ProcessStats.SERVICE_NAME, new String[] { packageName }); 3316 pw.println(); 3317 dumpService(pw, fd, "usagestats", new String[] { "--packages", packageName }); 3318 pw.println(); 3319 dumpService(pw, fd, BatteryStats.SERVICE_NAME, new String[] { packageName }); 3320 pw.flush(); 3321 } 3322 3323 private static void dumpService(PrintWriter pw, FileDescriptor fd, String name, String[] args) { 3324 pw.print("DUMP OF SERVICE "); pw.print(name); pw.println(":"); 3325 IBinder service = ServiceManager.checkService(name); 3326 if (service == null) { 3327 pw.println(" (Service not found)"); 3328 return; 3329 } 3330 TransferPipe tp = null; 3331 try { 3332 pw.flush(); 3333 tp = new TransferPipe(); 3334 tp.setBufferPrefix(" "); 3335 service.dumpAsync(tp.getWriteFd().getFileDescriptor(), args); 3336 tp.go(fd, 10000); 3337 } catch (Throwable e) { 3338 if (tp != null) { 3339 tp.kill(); 3340 } 3341 pw.println("Failure dumping service:"); 3342 e.printStackTrace(pw); 3343 } 3344 } 3345 3346 /** 3347 * Request that the system start watching for the calling process to exceed a pss 3348 * size as given here. Once called, the system will look for any occasions where it 3349 * sees the associated process with a larger pss size and, when this happens, automatically 3350 * pull a heap dump from it and allow the user to share the data. Note that this request 3351 * continues running even if the process is killed and restarted. To remove the watch, 3352 * use {@link #clearWatchHeapLimit()}. 3353 * 3354 * <p>This API only work if the calling process has been marked as 3355 * {@link ApplicationInfo#FLAG_DEBUGGABLE} or this is running on a debuggable 3356 * (userdebug or eng) build.</p> 3357 * 3358 * <p>Callers can optionally implement {@link #ACTION_REPORT_HEAP_LIMIT} to directly 3359 * handle heap limit reports themselves.</p> 3360 * 3361 * @param pssSize The size in bytes to set the limit at. 3362 */ 3363 public void setWatchHeapLimit(long pssSize) { 3364 try { 3365 ActivityManagerNative.getDefault().setDumpHeapDebugLimit(null, 0, pssSize, 3366 mContext.getPackageName()); 3367 } catch (RemoteException e) { 3368 } 3369 } 3370 3371 /** 3372 * Action an app can implement to handle reports from {@link #setWatchHeapLimit(long)}. 3373 * If your package has an activity handling this action, it will be launched with the 3374 * heap data provided to it the same way as {@link Intent#ACTION_SEND}. Note that to 3375 * match the activty must support this action and a MIME type of "*/*". 3376 */ 3377 public static final String ACTION_REPORT_HEAP_LIMIT = "android.app.action.REPORT_HEAP_LIMIT"; 3378 3379 /** 3380 * Clear a heap watch limit previously set by {@link #setWatchHeapLimit(long)}. 3381 */ 3382 public void clearWatchHeapLimit() { 3383 try { 3384 ActivityManagerNative.getDefault().setDumpHeapDebugLimit(null, 0, 0, null); 3385 } catch (RemoteException e) { 3386 } 3387 } 3388 3389 /** 3390 * @hide 3391 */ 3392 public void startLockTaskMode(int taskId) { 3393 try { 3394 ActivityManagerNative.getDefault().startLockTaskMode(taskId); 3395 } catch (RemoteException e) { 3396 } 3397 } 3398 3399 /** 3400 * @hide 3401 */ 3402 public void stopLockTaskMode() { 3403 try { 3404 ActivityManagerNative.getDefault().stopLockTaskMode(); 3405 } catch (RemoteException e) { 3406 } 3407 } 3408 3409 /** 3410 * Return whether currently in lock task mode. When in this mode 3411 * no new tasks can be created or switched to. 3412 * 3413 * @see Activity#startLockTask() 3414 * 3415 * @deprecated Use {@link #getLockTaskModeState} instead. 3416 */ 3417 public boolean isInLockTaskMode() { 3418 return getLockTaskModeState() != LOCK_TASK_MODE_NONE; 3419 } 3420 3421 /** 3422 * Return the current state of task locking. The three possible outcomes 3423 * are {@link #LOCK_TASK_MODE_NONE}, {@link #LOCK_TASK_MODE_LOCKED} 3424 * and {@link #LOCK_TASK_MODE_PINNED}. 3425 * 3426 * @see Activity#startLockTask() 3427 */ 3428 public int getLockTaskModeState() { 3429 try { 3430 return ActivityManagerNative.getDefault().getLockTaskModeState(); 3431 } catch (RemoteException e) { 3432 return ActivityManager.LOCK_TASK_MODE_NONE; 3433 } 3434 } 3435 3436 /** 3437 * The AppTask allows you to manage your own application's tasks. 3438 * See {@link android.app.ActivityManager#getAppTasks()} 3439 */ 3440 public static class AppTask { 3441 private IAppTask mAppTaskImpl; 3442 3443 /** @hide */ 3444 public AppTask(IAppTask task) { 3445 mAppTaskImpl = task; 3446 } 3447 3448 /** 3449 * Finishes all activities in this task and removes it from the recent tasks list. 3450 */ 3451 public void finishAndRemoveTask() { 3452 try { 3453 mAppTaskImpl.finishAndRemoveTask(); 3454 } catch (RemoteException e) { 3455 Slog.e(TAG, "Invalid AppTask", e); 3456 } 3457 } 3458 3459 /** 3460 * Get the RecentTaskInfo associated with this task. 3461 * 3462 * @return The RecentTaskInfo for this task, or null if the task no longer exists. 3463 */ 3464 public RecentTaskInfo getTaskInfo() { 3465 try { 3466 return mAppTaskImpl.getTaskInfo(); 3467 } catch (RemoteException e) { 3468 Slog.e(TAG, "Invalid AppTask", e); 3469 return null; 3470 } 3471 } 3472 3473 /** 3474 * Bring this task to the foreground. If it contains activities, they will be 3475 * brought to the foreground with it and their instances re-created if needed. 3476 * If it doesn't contain activities, the root activity of the task will be 3477 * re-launched. 3478 */ 3479 public void moveToFront() { 3480 try { 3481 mAppTaskImpl.moveToFront(); 3482 } catch (RemoteException e) { 3483 Slog.e(TAG, "Invalid AppTask", e); 3484 } 3485 } 3486 3487 /** 3488 * Start an activity in this task. Brings the task to the foreground. If this task 3489 * is not currently active (that is, its id < 0), then a new activity for the given 3490 * Intent will be launched as the root of the task and the task brought to the 3491 * foreground. Otherwise, if this task is currently active and the Intent does not specify 3492 * an activity to launch in a new task, then a new activity for the given Intent will 3493 * be launched on top of the task and the task brought to the foreground. If this 3494 * task is currently active and the Intent specifies {@link Intent#FLAG_ACTIVITY_NEW_TASK} 3495 * or would otherwise be launched in to a new task, then the activity not launched but 3496 * this task be brought to the foreground and a new intent delivered to the top 3497 * activity if appropriate. 3498 * 3499 * <p>In other words, you generally want to use an Intent here that does not specify 3500 * {@link Intent#FLAG_ACTIVITY_NEW_TASK} or {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT}, 3501 * and let the system do the right thing.</p> 3502 * 3503 * @param intent The Intent describing the new activity to be launched on the task. 3504 * @param options Optional launch options. 3505 * 3506 * @see Activity#startActivity(android.content.Intent, android.os.Bundle) 3507 */ 3508 public void startActivity(Context context, Intent intent, Bundle options) { 3509 ActivityThread thread = ActivityThread.currentActivityThread(); 3510 thread.getInstrumentation().execStartActivityFromAppTask(context, 3511 thread.getApplicationThread(), mAppTaskImpl, intent, options); 3512 } 3513 3514 /** 3515 * Modify the {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} flag in the root 3516 * Intent of this AppTask. 3517 * 3518 * @param exclude If true, {@link Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS} will 3519 * be set; otherwise, it will be cleared. 3520 */ 3521 public void setExcludeFromRecents(boolean exclude) { 3522 try { 3523 mAppTaskImpl.setExcludeFromRecents(exclude); 3524 } catch (RemoteException e) { 3525 Slog.e(TAG, "Invalid AppTask", e); 3526 } 3527 } 3528 } 3529} 3530