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