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