1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.app; 18 19 import static android.Manifest.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS; 20 import static android.Manifest.permission.START_TASKS_FROM_RECENTS; 21 import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; 22 import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; 23 import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK; 24 import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; 25 import static android.content.Intent.FLAG_RECEIVER_FOREGROUND; 26 import static android.view.Display.INVALID_DISPLAY; 27 import static android.window.DisplayAreaOrganizer.FEATURE_UNDEFINED; 28 29 import android.annotation.IntDef; 30 import android.annotation.NonNull; 31 import android.annotation.Nullable; 32 import android.annotation.RequiresPermission; 33 import android.annotation.SuppressLint; 34 import android.annotation.SystemApi; 35 import android.annotation.TestApi; 36 import android.app.ExitTransitionCoordinator.ActivityExitTransitionCallbacks; 37 import android.app.ExitTransitionCoordinator.ExitTransitionCallbacks; 38 import android.compat.annotation.UnsupportedAppUsage; 39 import android.content.ComponentName; 40 import android.content.Context; 41 import android.content.Intent; 42 import android.graphics.Bitmap; 43 import android.graphics.Bitmap.Config; 44 import android.graphics.Rect; 45 import android.hardware.HardwareBuffer; 46 import android.os.Binder; 47 import android.os.Bundle; 48 import android.os.Handler; 49 import android.os.IBinder; 50 import android.os.IRemoteCallback; 51 import android.os.Parcel; 52 import android.os.Parcelable; 53 import android.os.RemoteException; 54 import android.os.ResultReceiver; 55 import android.os.SystemClock; 56 import android.os.UserHandle; 57 import android.transition.TransitionManager; 58 import android.util.Pair; 59 import android.util.Slog; 60 import android.view.AppTransitionAnimationSpec; 61 import android.view.IAppTransitionAnimationSpecsFuture; 62 import android.view.RemoteAnimationAdapter; 63 import android.view.View; 64 import android.view.ViewGroup; 65 import android.view.Window; 66 import android.window.RemoteTransition; 67 import android.window.SplashScreen; 68 import android.window.WindowContainerToken; 69 70 import java.lang.annotation.Retention; 71 import java.lang.annotation.RetentionPolicy; 72 import java.util.ArrayList; 73 74 /** 75 * Helper class for building an options Bundle that can be used with 76 * {@link android.content.Context#startActivity(android.content.Intent, android.os.Bundle) 77 * Context.startActivity(Intent, Bundle)} and related methods. 78 */ 79 @android.ravenwood.annotation.RavenwoodKeepWholeClass 80 public class ActivityOptions extends ComponentOptions { 81 private static final String TAG = "ActivityOptions"; 82 83 /** 84 * A long in the extras delivered by {@link #requestUsageTimeReport} that contains 85 * the total time (in ms) the user spent in the app flow. 86 */ 87 public static final String EXTRA_USAGE_TIME_REPORT = "android.activity.usage_time"; 88 89 /** 90 * A Bundle in the extras delivered by {@link #requestUsageTimeReport} that contains 91 * detailed information about the time spent in each package associated with the app; 92 * each key is a package name, whose value is a long containing the time (in ms). 93 */ 94 public static final String EXTRA_USAGE_TIME_REPORT_PACKAGES = "android.usage_time_packages"; 95 96 /** Enumeration of background activity start modes. 97 * 98 * These define if an app wants to grant it's background activity start privileges to a 99 * {@link PendingIntent}. 100 * @hide 101 */ 102 @Retention(RetentionPolicy.SOURCE) 103 @IntDef(prefix = {"MODE_BACKGROUND_ACTIVITY_START_"}, value = { 104 MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED, 105 MODE_BACKGROUND_ACTIVITY_START_ALLOWED, 106 MODE_BACKGROUND_ACTIVITY_START_DENIED, 107 MODE_BACKGROUND_ACTIVITY_START_COMPAT}) 108 public @interface BackgroundActivityStartMode {} 109 /** 110 * No explicit value chosen. The system will decide whether to grant privileges. 111 */ 112 public static final int MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED = 0; 113 /** 114 * Allow the {@link PendingIntent} to use the background activity start privileges. 115 */ 116 public static final int MODE_BACKGROUND_ACTIVITY_START_ALLOWED = 1; 117 /** 118 * Deny the {@link PendingIntent} to use the background activity start privileges. 119 */ 120 public static final int MODE_BACKGROUND_ACTIVITY_START_DENIED = 2; 121 /** 122 * Special behavior for compatibility. 123 * Similar to {@link #MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED} 124 * 125 * @hide 126 */ 127 public static final int MODE_BACKGROUND_ACTIVITY_START_COMPAT = -1; 128 129 /** 130 * The package name that created the options. 131 * @hide 132 */ 133 public static final String KEY_PACKAGE_NAME = "android:activity.packageName"; 134 135 /** 136 * The bounds (window size) that the activity should be launched in. Set to null explicitly for 137 * full screen. If the key is not found, previous bounds will be preserved. 138 * NOTE: This value is ignored on devices that don't have 139 * {@link android.content.pm.PackageManager#FEATURE_FREEFORM_WINDOW_MANAGEMENT} or 140 * {@link android.content.pm.PackageManager#FEATURE_PICTURE_IN_PICTURE} enabled. 141 * @hide 142 */ 143 public static final String KEY_LAUNCH_BOUNDS = "android:activity.launchBounds"; 144 145 /** 146 * Type of animation that arguments specify. 147 * @hide 148 */ 149 public static final String KEY_ANIM_TYPE = "android:activity.animType"; 150 151 /** 152 * Custom enter animation resource ID. 153 * @hide 154 */ 155 public static final String KEY_ANIM_ENTER_RES_ID = "android:activity.animEnterRes"; 156 157 /** 158 * Custom exit animation resource ID. 159 * @hide 160 */ 161 public static final String KEY_ANIM_EXIT_RES_ID = "android:activity.animExitRes"; 162 163 /** 164 * Custom in-place animation resource ID. 165 * @hide 166 */ 167 public static final String KEY_ANIM_IN_PLACE_RES_ID = "android:activity.animInPlaceRes"; 168 169 /** 170 * Custom background color for animation. 171 * @hide 172 */ 173 public static final String KEY_ANIM_BACKGROUND_COLOR = "android:activity.backgroundColor"; 174 175 /** 176 * Bitmap for thumbnail animation. 177 * @hide 178 */ 179 public static final String KEY_ANIM_THUMBNAIL = "android:activity.animThumbnail"; 180 181 /** 182 * Start X position of thumbnail animation. 183 * @hide 184 */ 185 public static final String KEY_ANIM_START_X = "android:activity.animStartX"; 186 187 /** 188 * Start Y position of thumbnail animation. 189 * @hide 190 */ 191 public static final String KEY_ANIM_START_Y = "android:activity.animStartY"; 192 193 /** 194 * Initial width of the animation. 195 * @hide 196 */ 197 public static final String KEY_ANIM_WIDTH = "android:activity.animWidth"; 198 199 /** 200 * Initial height of the animation. 201 * @hide 202 */ 203 public static final String KEY_ANIM_HEIGHT = "android:activity.animHeight"; 204 205 /** 206 * Callback for when animation is started. 207 * @hide 208 */ 209 public static final String KEY_ANIM_START_LISTENER = "android:activity.animStartListener"; 210 211 /** 212 * Callback for when animation is aborted. 213 * @hide 214 */ 215 private static final String KEY_ANIM_ABORT_LISTENER = "android:activity.animAbortListener"; 216 217 /** 218 * Specific a theme for a splash screen window. 219 * @hide 220 */ 221 public static final String KEY_SPLASH_SCREEN_THEME = "android.activity.splashScreenTheme"; 222 223 /** 224 * Indicates that this activity launch is eligible to show a legacy permission prompt 225 * @hide 226 */ 227 public static final String KEY_LEGACY_PERMISSION_PROMPT_ELIGIBLE = 228 "android:activity.legacyPermissionPromptEligible"; 229 230 /** 231 * Callback for when the last frame of the animation is played. 232 * @hide 233 */ 234 private static final String KEY_ANIMATION_FINISHED_LISTENER = 235 "android:activity.animationFinishedListener"; 236 237 /** 238 * Descriptions of app transition animations to be played during the activity launch. 239 */ 240 private static final String KEY_ANIM_SPECS = "android:activity.animSpecs"; 241 242 /** 243 * Whether the activity should be launched into LockTask mode. 244 * @see #setLockTaskEnabled(boolean) 245 */ 246 private static final String KEY_LOCK_TASK_MODE = "android:activity.lockTaskMode"; 247 248 /** 249 * Whether the launching app's identity should be available to the launched activity. 250 * @see #setShareIdentityEnabled(boolean) 251 */ 252 private static final String KEY_SHARE_IDENTITY = "android:activity.shareIdentity"; 253 254 /** 255 * The display id the activity should be launched into. 256 * @see #setLaunchDisplayId(int) 257 * @hide 258 */ 259 private static final String KEY_LAUNCH_DISPLAY_ID = "android.activity.launchDisplayId"; 260 261 /** 262 * The id of the display where the caller was on. 263 * @see #setCallerDisplayId(int) 264 * @hide 265 */ 266 private static final String KEY_CALLER_DISPLAY_ID = "android.activity.callerDisplayId"; 267 268 /** 269 * The task display area token the activity should be launched into. 270 * @see #setLaunchTaskDisplayArea(WindowContainerToken) 271 * @hide 272 */ 273 private static final String KEY_LAUNCH_TASK_DISPLAY_AREA_TOKEN = 274 "android.activity.launchTaskDisplayAreaToken"; 275 276 /** 277 * The task display area feature id the activity should be launched into. 278 * @see #setLaunchTaskDisplayAreaFeatureId(int) 279 * @hide 280 */ 281 private static final String KEY_LAUNCH_TASK_DISPLAY_AREA_FEATURE_ID = 282 "android.activity.launchTaskDisplayAreaFeatureId"; 283 284 /** 285 * The root task token the activity should be launched into. 286 * @see #setLaunchRootTask(WindowContainerToken) 287 * @hide 288 */ 289 public static final String KEY_LAUNCH_ROOT_TASK_TOKEN = 290 "android.activity.launchRootTaskToken"; 291 292 /** 293 * The {@link com.android.server.wm.TaskFragment} token the activity should be launched into. 294 * @see #setLaunchTaskFragmentToken(IBinder) 295 * @hide 296 */ 297 public static final String KEY_LAUNCH_TASK_FRAGMENT_TOKEN = 298 "android.activity.launchTaskFragmentToken"; 299 300 /** 301 * The windowing mode the activity should be launched into. 302 * @hide 303 */ 304 private static final String KEY_LAUNCH_WINDOWING_MODE = "android.activity.windowingMode"; 305 306 /** 307 * The activity type the activity should be launched as. 308 * @hide 309 */ 310 private static final String KEY_LAUNCH_ACTIVITY_TYPE = "android.activity.activityType"; 311 312 /** 313 * The task id the activity should be launched into. 314 * @hide 315 */ 316 private static final String KEY_LAUNCH_TASK_ID = "android.activity.launchTaskId"; 317 318 /** 319 * See {@link #setDisableStartingWindow}. 320 * @hide 321 */ 322 private static final String KEY_DISABLE_STARTING_WINDOW = "android.activity.disableStarting"; 323 324 /** 325 * See {@link #setPendingIntentLaunchFlags(int)} 326 * @hide 327 */ 328 private static final String KEY_PENDING_INTENT_LAUNCH_FLAGS = 329 "android.activity.pendingIntentLaunchFlags"; 330 331 /** 332 * See {@link #setTaskAlwaysOnTop}. 333 * @hide 334 */ 335 private static final String KEY_TASK_ALWAYS_ON_TOP = "android.activity.alwaysOnTop"; 336 337 /** 338 * See {@link #setTaskOverlay}. 339 * @hide 340 */ 341 private static final String KEY_TASK_OVERLAY = "android.activity.taskOverlay"; 342 343 /** 344 * See {@link #setTaskOverlay}. 345 * @hide 346 */ 347 private static final String KEY_TASK_OVERLAY_CAN_RESUME = 348 "android.activity.taskOverlayCanResume"; 349 350 /** 351 * See {@link #setAvoidMoveToFront()}. 352 * @hide 353 */ 354 private static final String KEY_AVOID_MOVE_TO_FRONT = "android.activity.avoidMoveToFront"; 355 356 /** 357 * See {@link #setFreezeRecentTasksReordering()}. 358 * @hide 359 */ 360 private static final String KEY_FREEZE_RECENT_TASKS_REORDERING = 361 "android.activity.freezeRecentTasksReordering"; 362 363 /** 364 * Determines whether to disallow the outgoing activity from entering picture-in-picture as the 365 * result of a new activity being launched. 366 * @hide 367 */ 368 private static final String KEY_DISALLOW_ENTER_PICTURE_IN_PICTURE_WHILE_LAUNCHING = 369 "android:activity.disallowEnterPictureInPictureWhileLaunching"; 370 371 /** 372 * Indicates flags should be applied to the launching activity such that it will behave 373 * correctly in a bubble. 374 * @hide 375 */ 376 private static final String KEY_APPLY_ACTIVITY_FLAGS_FOR_BUBBLES = 377 "android:activity.applyActivityFlagsForBubbles"; 378 379 /** 380 * Indicates to apply {@link Intent#FLAG_ACTIVITY_MULTIPLE_TASK} to the launching shortcut. 381 * @hide 382 */ 383 private static final String KEY_APPLY_MULTIPLE_TASK_FLAG_FOR_SHORTCUT = 384 "android:activity.applyMultipleTaskFlagForShortcut"; 385 386 /** 387 * Indicates to apply {@link Intent#FLAG_ACTIVITY_NO_USER_ACTION} to the launching shortcut. 388 * @hide 389 */ 390 private static final String KEY_APPLY_NO_USER_ACTION_FLAG_FOR_SHORTCUT = 391 "android:activity.applyNoUserActionFlagForShortcut"; 392 393 private static final String KEY_SCENE_TRANSITION_INFO = "android:activity.sceneTransitionInfo"; 394 395 /** See {@link SourceInfo}. */ 396 private static final String KEY_SOURCE_INFO = "android.activity.sourceInfo"; 397 398 private static final String KEY_USAGE_TIME_REPORT = "android:activity.usageTimeReport"; 399 private static final String KEY_ROTATION_ANIMATION_HINT = "android:activity.rotationAnimationHint"; 400 401 private static final String KEY_INSTANT_APP_VERIFICATION_BUNDLE 402 = "android:instantapps.installerbundle"; 403 private static final String KEY_SPECS_FUTURE = "android:activity.specsFuture"; 404 private static final String KEY_REMOTE_ANIMATION_ADAPTER 405 = "android:activity.remoteAnimationAdapter"; 406 private static final String KEY_REMOTE_TRANSITION = 407 "android:activity.remoteTransition"; 408 409 private static final String KEY_OVERRIDE_TASK_TRANSITION = 410 "android:activity.overrideTaskTransition"; 411 412 /** See {@link #setRemoveWithTaskOrganizer(boolean)}. */ 413 private static final String KEY_REMOVE_WITH_TASK_ORGANIZER = 414 "android.activity.removeWithTaskOrganizer"; 415 /** See {@link #setLaunchedFromBubble(boolean)}. */ 416 private static final String KEY_LAUNCHED_FROM_BUBBLE = 417 "android.activity.launchTypeBubble"; 418 419 /** See {@link #setSplashScreenStyle(int)}. */ 420 private static final String KEY_SPLASH_SCREEN_STYLE = 421 "android.activity.splashScreenStyle"; 422 423 /** 424 * See {@link #setTransientLaunch()}. 425 * @hide 426 */ 427 public static final String KEY_TRANSIENT_LAUNCH = "android.activity.transientLaunch"; 428 429 /** see {@link #makeLaunchIntoPip(PictureInPictureParams)}. */ 430 private static final String KEY_LAUNCH_INTO_PIP_PARAMS = 431 "android.activity.launchIntoPipParams"; 432 433 /** See {@link #setDismissKeyguardIfInsecure()}. */ 434 private static final String KEY_DISMISS_KEYGUARD_IF_INSECURE = 435 "android.activity.dismissKeyguardIfInsecure"; 436 437 private static final String KEY_PENDING_INTENT_CREATOR_BACKGROUND_ACTIVITY_START_MODE = 438 "android.activity.pendingIntentCreatorBackgroundActivityStartMode"; 439 440 /** 441 * @see #setLaunchCookie 442 * @hide 443 */ 444 public static final String KEY_LAUNCH_COOKIE = "android.activity.launchCookie"; 445 446 /** @hide */ 447 public static final int ANIM_UNDEFINED = -1; 448 /** @hide */ 449 public static final int ANIM_NONE = 0; 450 /** @hide */ 451 public static final int ANIM_CUSTOM = 1; 452 /** @hide */ 453 public static final int ANIM_SCALE_UP = 2; 454 /** @hide */ 455 public static final int ANIM_THUMBNAIL_SCALE_UP = 3; 456 /** @hide */ 457 public static final int ANIM_THUMBNAIL_SCALE_DOWN = 4; 458 /** @hide */ 459 public static final int ANIM_SCENE_TRANSITION = 5; 460 /** @hide */ 461 public static final int ANIM_DEFAULT = 6; 462 /** @hide */ 463 public static final int ANIM_LAUNCH_TASK_BEHIND = 7; 464 /** @hide */ 465 public static final int ANIM_THUMBNAIL_ASPECT_SCALE_UP = 8; 466 /** @hide */ 467 public static final int ANIM_THUMBNAIL_ASPECT_SCALE_DOWN = 9; 468 /** @hide */ 469 public static final int ANIM_CUSTOM_IN_PLACE = 10; 470 /** @hide */ 471 public static final int ANIM_CLIP_REVEAL = 11; 472 /** @hide */ 473 public static final int ANIM_OPEN_CROSS_PROFILE_APPS = 12; 474 /** @hide */ 475 public static final int ANIM_REMOTE_ANIMATION = 13; 476 /** @hide */ 477 public static final int ANIM_FROM_STYLE = 14; 478 479 private String mPackageName; 480 private Rect mLaunchBounds; 481 private int mAnimationType = ANIM_UNDEFINED; 482 private int mCustomEnterResId; 483 private int mCustomExitResId; 484 private int mCustomInPlaceResId; 485 private int mCustomBackgroundColor; 486 private Bitmap mThumbnail; 487 private int mStartX; 488 private int mStartY; 489 private int mWidth; 490 private int mHeight; 491 private IRemoteCallback mAnimationStartedListener; 492 private IRemoteCallback mAnimationFinishedListener; 493 private IRemoteCallback mAnimationAbortListener; 494 private SceneTransitionInfo mSceneTransitionInfo; 495 private PendingIntent mUsageTimeReport; 496 private int mLaunchDisplayId = INVALID_DISPLAY; 497 private int mCallerDisplayId = INVALID_DISPLAY; 498 private WindowContainerToken mLaunchTaskDisplayArea; 499 private int mLaunchTaskDisplayAreaFeatureId = FEATURE_UNDEFINED; 500 private WindowContainerToken mLaunchRootTask; 501 private IBinder mLaunchTaskFragmentToken; 502 @WindowConfiguration.WindowingMode 503 private int mLaunchWindowingMode = WINDOWING_MODE_UNDEFINED; 504 @WindowConfiguration.ActivityType 505 private int mLaunchActivityType = ACTIVITY_TYPE_UNDEFINED; 506 private int mLaunchTaskId = -1; 507 private int mPendingIntentLaunchFlags; 508 private boolean mLockTaskMode = false; 509 private boolean mShareIdentity = false; 510 private boolean mDisallowEnterPictureInPictureWhileLaunching; 511 private boolean mApplyActivityFlagsForBubbles; 512 private boolean mApplyMultipleTaskFlagForShortcut; 513 private boolean mApplyNoUserActionFlagForShortcut; 514 private boolean mTaskAlwaysOnTop; 515 private boolean mTaskOverlay; 516 private boolean mTaskOverlayCanResume; 517 private boolean mAvoidMoveToFront; 518 private boolean mFreezeRecentTasksReordering; 519 private AppTransitionAnimationSpec mAnimSpecs[]; 520 private SourceInfo mSourceInfo; 521 private int mRotationAnimationHint = -1; 522 private Bundle mAppVerificationBundle; 523 private IAppTransitionAnimationSpecsFuture mSpecsFuture; 524 private RemoteAnimationAdapter mRemoteAnimationAdapter; 525 private IBinder mLaunchCookie; 526 private RemoteTransition mRemoteTransition; 527 private boolean mOverrideTaskTransition; 528 private String mSplashScreenThemeResName; 529 @SplashScreen.SplashScreenStyle 530 private int mSplashScreenStyle = SplashScreen.SPLASH_SCREEN_STYLE_UNDEFINED; 531 private boolean mIsEligibleForLegacyPermissionPrompt; 532 private boolean mRemoveWithTaskOrganizer; 533 private boolean mLaunchedFromBubble; 534 private boolean mTransientLaunch; 535 private PictureInPictureParams mLaunchIntoPipParams; 536 private boolean mDismissKeyguardIfInsecure; 537 @BackgroundActivityStartMode 538 private int mPendingIntentCreatorBackgroundActivityStartMode = 539 MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED; 540 private boolean mDisableStartingWindow; 541 542 /** 543 * Create an ActivityOptions specifying a custom animation to run when 544 * the activity is displayed. 545 * 546 * @param context Who is defining this. This is the application that the 547 * animation resources will be loaded from. 548 * @param enterResId A resource ID of the animation resource to use for 549 * the incoming activity. Use 0 for no animation. 550 * @param exitResId A resource ID of the animation resource to use for 551 * the outgoing activity. Use 0 for no animation. 552 * @return Returns a new ActivityOptions object that you can use to 553 * supply these options as the options Bundle when starting an activity. 554 */ 555 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = Context.class) makeCustomAnimation(Context context, int enterResId, int exitResId)556 public static ActivityOptions makeCustomAnimation(Context context, 557 int enterResId, int exitResId) { 558 return makeCustomAnimation(context, enterResId, exitResId, 0, null, null); 559 } 560 561 /** 562 * Create an ActivityOptions specifying a custom animation to run when 563 * the activity is displayed. 564 * 565 * @param context Who is defining this. This is the application that the 566 * animation resources will be loaded from. 567 * @param enterResId A resource ID of the animation resource to use for 568 * the incoming activity. Use 0 for no animation. 569 * @param exitResId A resource ID of the animation resource to use for 570 * the outgoing activity. Use 0 for no animation. 571 * @param backgroundColor The background color to use for the background during the animation if 572 * the animation requires a background. Set to 0 to not override the default color. 573 * @return Returns a new ActivityOptions object that you can use to 574 * supply these options as the options Bundle when starting an activity. 575 */ 576 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = Context.class) makeCustomAnimation(@onNull Context context, int enterResId, int exitResId, int backgroundColor)577 public static @NonNull ActivityOptions makeCustomAnimation(@NonNull Context context, 578 int enterResId, int exitResId, int backgroundColor) { 579 return makeCustomAnimation(context, enterResId, exitResId, backgroundColor, null, null); 580 } 581 582 /** 583 * Create an ActivityOptions specifying a custom animation to run when 584 * the activity is displayed. 585 * 586 * @param context Who is defining this. This is the application that the 587 * animation resources will be loaded from. 588 * @param enterResId A resource ID of the animation resource to use for 589 * the incoming activity. Use 0 for no animation. 590 * @param exitResId A resource ID of the animation resource to use for 591 * the outgoing activity. Use 0 for no animation. 592 * @param handler If <var>listener</var> is non-null this must be a valid 593 * Handler on which to dispatch the callback; otherwise it should be null. 594 * @param listener Optional OnAnimationStartedListener to find out when the 595 * requested animation has started running. If for some reason the animation 596 * is not executed, the callback will happen immediately. 597 * @return Returns a new ActivityOptions object that you can use to 598 * supply these options as the options Bundle when starting an activity. 599 * @hide 600 */ 601 @UnsupportedAppUsage 602 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = Context.class) makeCustomAnimation(Context context, int enterResId, int exitResId, int backgroundColor, Handler handler, OnAnimationStartedListener listener)603 public static ActivityOptions makeCustomAnimation(Context context, 604 int enterResId, int exitResId, int backgroundColor, Handler handler, 605 OnAnimationStartedListener listener) { 606 ActivityOptions opts = new ActivityOptions(); 607 opts.mPackageName = context.getPackageName(); 608 opts.mAnimationType = ANIM_CUSTOM; 609 opts.mCustomEnterResId = enterResId; 610 opts.mCustomExitResId = exitResId; 611 opts.mCustomBackgroundColor = backgroundColor; 612 opts.setOnAnimationStartedListener(handler, listener); 613 return opts; 614 } 615 616 /** 617 * Create an ActivityOptions specifying a custom animation to run when 618 * the activity is displayed. 619 * 620 * @param context Who is defining this. This is the application that the 621 * animation resources will be loaded from. 622 * @param enterResId A resource ID of the animation resource to use for 623 * the incoming activity. Use 0 for no animation. 624 * @param exitResId A resource ID of the animation resource to use for 625 * the outgoing activity. Use 0 for no animation. 626 * @param handler If <var>listener</var> is non-null this must be a valid 627 * Handler on which to dispatch the callback; otherwise it should be null. 628 * @param startedListener Optional OnAnimationStartedListener to find out when the 629 * requested animation has started running. If for some reason the animation 630 * is not executed, the callback will happen immediately. 631 * @param finishedListener Optional OnAnimationFinishedListener when the animation 632 * has finished running. 633 * @return Returns a new ActivityOptions object that you can use to 634 * supply these options as the options Bundle when starting an activity. 635 * @hide 636 */ 637 @TestApi 638 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = Context.class) makeCustomAnimation(@onNull Context context, int enterResId, int exitResId, int backgroundColor, @Nullable Handler handler, @Nullable OnAnimationStartedListener startedListener, @Nullable OnAnimationFinishedListener finishedListener)639 public static @NonNull ActivityOptions makeCustomAnimation(@NonNull Context context, 640 int enterResId, int exitResId, int backgroundColor, @Nullable Handler handler, 641 @Nullable OnAnimationStartedListener startedListener, 642 @Nullable OnAnimationFinishedListener finishedListener) { 643 ActivityOptions opts = makeCustomAnimation(context, enterResId, exitResId, backgroundColor, 644 handler, startedListener); 645 opts.setOnAnimationFinishedListener(handler, finishedListener); 646 return opts; 647 } 648 649 /** 650 * Create an ActivityOptions specifying a custom animation to run when the activity in the 651 * different task is displayed. 652 * 653 * @param context Who is defining this. This is the application that the 654 * animation resources will be loaded from. 655 * @param enterResId A resource ID of the animation resource to use for 656 * the incoming activity. Use 0 for no animation. 657 * @param exitResId A resource ID of the animation resource to use for 658 * the outgoing activity. Use 0 for no animation. 659 * @param handler If <var>listener</var> is non-null this must be a valid 660 * Handler on which to dispatch the callback; otherwise it should be null. 661 * @param startedListener Optional OnAnimationStartedListener to find out when the 662 * requested animation has started running. If for some reason the animation 663 * is not executed, the callback will happen immediately. 664 * @param finishedListener Optional OnAnimationFinishedListener when the animation 665 * has finished running. 666 * 667 * @return Returns a new ActivityOptions object that you can use to 668 * supply these options as the options Bundle when starting an activity. 669 * @hide 670 */ 671 @RequiresPermission(START_TASKS_FROM_RECENTS) 672 @TestApi 673 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = Context.class) makeCustomTaskAnimation(@onNull Context context, int enterResId, int exitResId, @Nullable Handler handler, @Nullable OnAnimationStartedListener startedListener, @Nullable OnAnimationFinishedListener finishedListener)674 public static @NonNull ActivityOptions makeCustomTaskAnimation(@NonNull Context context, 675 int enterResId, int exitResId, @Nullable Handler handler, 676 @Nullable OnAnimationStartedListener startedListener, 677 @Nullable OnAnimationFinishedListener finishedListener) { 678 ActivityOptions opts = makeCustomAnimation(context, enterResId, exitResId, 0, 679 handler, startedListener, finishedListener); 680 opts.mOverrideTaskTransition = true; 681 return opts; 682 } 683 684 /** 685 * Creates an ActivityOptions specifying a custom animation to run in place on an existing 686 * activity. 687 * 688 * @param context Who is defining this. This is the application that the 689 * animation resources will be loaded from. 690 * @param animId A resource ID of the animation resource to use for 691 * the incoming activity. 692 * @return Returns a new ActivityOptions object that you can use to 693 * supply these options as the options Bundle when running an in-place animation. 694 * @hide 695 */ 696 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = Context.class) makeCustomInPlaceAnimation(Context context, int animId)697 public static ActivityOptions makeCustomInPlaceAnimation(Context context, int animId) { 698 if (animId == 0) { 699 throw new RuntimeException("You must specify a valid animation."); 700 } 701 702 ActivityOptions opts = new ActivityOptions(); 703 opts.mPackageName = context.getPackageName(); 704 opts.mAnimationType = ANIM_CUSTOM_IN_PLACE; 705 opts.mCustomInPlaceResId = animId; 706 return opts; 707 } 708 setOnAnimationStartedListener(final Handler handler, final OnAnimationStartedListener listener)709 private void setOnAnimationStartedListener(final Handler handler, 710 final OnAnimationStartedListener listener) { 711 if (listener != null) { 712 mAnimationStartedListener = new IRemoteCallback.Stub() { 713 @Override 714 public void sendResult(Bundle data) throws RemoteException { 715 final long elapsedRealtime = SystemClock.elapsedRealtime(); 716 handler.post(new Runnable() { 717 @Override public void run() { 718 listener.onAnimationStarted(elapsedRealtime); 719 } 720 }); 721 } 722 }; 723 } 724 } 725 726 /** 727 * Callback for finding out when the given animation has started running. 728 * @hide 729 */ 730 @TestApi 731 public interface OnAnimationStartedListener { 732 /** 733 * @param elapsedRealTime {@link SystemClock#elapsedRealTime} when animation started. 734 */ onAnimationStarted(long elapsedRealTime)735 void onAnimationStarted(long elapsedRealTime); 736 } 737 setOnAnimationFinishedListener(final Handler handler, final OnAnimationFinishedListener listener)738 private void setOnAnimationFinishedListener(final Handler handler, 739 final OnAnimationFinishedListener listener) { 740 if (listener != null) { 741 mAnimationFinishedListener = new IRemoteCallback.Stub() { 742 @Override 743 public void sendResult(Bundle data) throws RemoteException { 744 final long elapsedRealtime = SystemClock.elapsedRealtime(); 745 handler.post(new Runnable() { 746 @Override 747 public void run() { 748 listener.onAnimationFinished(elapsedRealtime); 749 } 750 }); 751 } 752 }; 753 } 754 } 755 756 /** 757 * Callback for finding out when the given animation is finished 758 * @hide 759 */ setOnAnimationFinishedListener(IRemoteCallback listener)760 public void setOnAnimationFinishedListener(IRemoteCallback listener) { 761 mAnimationFinishedListener = listener; 762 } 763 764 /** 765 * Callback for finding out when the given animation has drawn its last frame. 766 * @hide 767 */ 768 @TestApi 769 public interface OnAnimationFinishedListener { 770 /** 771 * @param elapsedRealTime {@link SystemClock#elapsedRealTime} when animation finished. 772 */ onAnimationFinished(long elapsedRealTime)773 void onAnimationFinished(long elapsedRealTime); 774 } 775 776 /** 777 * Callback for finding out when the given animation is aborted 778 * @hide 779 */ setOnAnimationAbortListener(IRemoteCallback listener)780 public void setOnAnimationAbortListener(IRemoteCallback listener) { 781 mAnimationAbortListener = listener; 782 } 783 784 /** 785 * Create an ActivityOptions specifying an animation where the new 786 * activity is scaled from a small originating area of the screen to 787 * its final full representation. 788 * 789 * <p>If the Intent this is being used with has not set its 790 * {@link android.content.Intent#setSourceBounds Intent.setSourceBounds}, 791 * those bounds will be filled in for you based on the initial 792 * bounds passed in here. 793 * 794 * @param source The View that the new activity is animating from. This 795 * defines the coordinate space for <var>startX</var> and <var>startY</var>. 796 * @param startX The x starting location of the new activity, relative to <var>source</var>. 797 * @param startY The y starting location of the activity, relative to <var>source</var>. 798 * @param width The initial width of the new activity. 799 * @param height The initial height of the new activity. 800 * @return Returns a new ActivityOptions object that you can use to 801 * supply these options as the options Bundle when starting an activity. 802 */ 803 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = View.class) makeScaleUpAnimation(View source, int startX, int startY, int width, int height)804 public static ActivityOptions makeScaleUpAnimation(View source, 805 int startX, int startY, int width, int height) { 806 ActivityOptions opts = new ActivityOptions(); 807 opts.mPackageName = source.getContext().getPackageName(); 808 opts.mAnimationType = ANIM_SCALE_UP; 809 int[] pts = new int[2]; 810 source.getLocationOnScreen(pts); 811 opts.mStartX = pts[0] + startX; 812 opts.mStartY = pts[1] + startY; 813 opts.mWidth = width; 814 opts.mHeight = height; 815 return opts; 816 } 817 818 /** 819 * Create an ActivityOptions specifying an animation where the new 820 * activity is revealed from a small originating area of the screen to 821 * its final full representation. 822 * 823 * @param source The View that the new activity is animating from. This 824 * defines the coordinate space for <var>startX</var> and <var>startY</var>. 825 * @param startX The x starting location of the new activity, relative to <var>source</var>. 826 * @param startY The y starting location of the activity, relative to <var>source</var>. 827 * @param width The initial width of the new activity. 828 * @param height The initial height of the new activity. 829 * @return Returns a new ActivityOptions object that you can use to 830 * supply these options as the options Bundle when starting an activity. 831 */ 832 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = View.class) makeClipRevealAnimation(View source, int startX, int startY, int width, int height)833 public static ActivityOptions makeClipRevealAnimation(View source, 834 int startX, int startY, int width, int height) { 835 ActivityOptions opts = new ActivityOptions(); 836 opts.mAnimationType = ANIM_CLIP_REVEAL; 837 int[] pts = new int[2]; 838 source.getLocationOnScreen(pts); 839 opts.mStartX = pts[0] + startX; 840 opts.mStartY = pts[1] + startY; 841 opts.mWidth = width; 842 opts.mHeight = height; 843 return opts; 844 } 845 846 /** 847 * Creates an {@link ActivityOptions} object specifying an animation where the new activity 848 * is started in another user profile by calling {@link 849 * android.content.pm.crossprofile.CrossProfileApps#startMainActivity(ComponentName, UserHandle) 850 * }. 851 * @hide 852 */ makeOpenCrossProfileAppsAnimation()853 public static ActivityOptions makeOpenCrossProfileAppsAnimation() { 854 ActivityOptions options = new ActivityOptions(); 855 options.mAnimationType = ANIM_OPEN_CROSS_PROFILE_APPS; 856 return options; 857 } 858 859 /** 860 * Create an ActivityOptions specifying an animation where a thumbnail 861 * is scaled from a given position to the new activity window that is 862 * being started. 863 * 864 * <p>If the Intent this is being used with has not set its 865 * {@link android.content.Intent#setSourceBounds Intent.setSourceBounds}, 866 * those bounds will be filled in for you based on the initial 867 * thumbnail location and size provided here. 868 * 869 * @param source The View that this thumbnail is animating from. This 870 * defines the coordinate space for <var>startX</var> and <var>startY</var>. 871 * @param thumbnail The bitmap that will be shown as the initial thumbnail 872 * of the animation. 873 * @param startX The x starting location of the bitmap, relative to <var>source</var>. 874 * @param startY The y starting location of the bitmap, relative to <var>source</var>. 875 * @return Returns a new ActivityOptions object that you can use to 876 * supply these options as the options Bundle when starting an activity. 877 */ 878 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = View.class) makeThumbnailScaleUpAnimation(View source, Bitmap thumbnail, int startX, int startY)879 public static ActivityOptions makeThumbnailScaleUpAnimation(View source, 880 Bitmap thumbnail, int startX, int startY) { 881 return makeThumbnailScaleUpAnimation(source, thumbnail, startX, startY, null); 882 } 883 884 /** 885 * Create an ActivityOptions specifying an animation where a thumbnail 886 * is scaled from a given position to the new activity window that is 887 * being started. 888 * 889 * @param source The View that this thumbnail is animating from. This 890 * defines the coordinate space for <var>startX</var> and <var>startY</var>. 891 * @param thumbnail The bitmap that will be shown as the initial thumbnail 892 * of the animation. 893 * @param startX The x starting location of the bitmap, relative to <var>source</var>. 894 * @param startY The y starting location of the bitmap, relative to <var>source</var>. 895 * @param listener Optional OnAnimationStartedListener to find out when the 896 * requested animation has started running. If for some reason the animation 897 * is not executed, the callback will happen immediately. 898 * @return Returns a new ActivityOptions object that you can use to 899 * supply these options as the options Bundle when starting an activity. 900 */ 901 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = View.class) makeThumbnailScaleUpAnimation(View source, Bitmap thumbnail, int startX, int startY, OnAnimationStartedListener listener)902 private static ActivityOptions makeThumbnailScaleUpAnimation(View source, 903 Bitmap thumbnail, int startX, int startY, OnAnimationStartedListener listener) { 904 return makeThumbnailAnimation(source, thumbnail, startX, startY, listener, true); 905 } 906 907 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = View.class) makeThumbnailAnimation(View source, Bitmap thumbnail, int startX, int startY, OnAnimationStartedListener listener, boolean scaleUp)908 private static ActivityOptions makeThumbnailAnimation(View source, 909 Bitmap thumbnail, int startX, int startY, OnAnimationStartedListener listener, 910 boolean scaleUp) { 911 ActivityOptions opts = new ActivityOptions(); 912 opts.mPackageName = source.getContext().getPackageName(); 913 opts.mAnimationType = scaleUp ? ANIM_THUMBNAIL_SCALE_UP : ANIM_THUMBNAIL_SCALE_DOWN; 914 opts.mThumbnail = thumbnail; 915 int[] pts = new int[2]; 916 source.getLocationOnScreen(pts); 917 opts.mStartX = pts[0] + startX; 918 opts.mStartY = pts[1] + startY; 919 opts.setOnAnimationStartedListener(source.getHandler(), listener); 920 return opts; 921 } 922 923 /** 924 * Create an ActivityOptions specifying an animation where a list of activity windows and 925 * thumbnails are aspect scaled to/from a new location. 926 * @hide 927 */ 928 @UnsupportedAppUsage 929 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = Context.class) makeMultiThumbFutureAspectScaleAnimation(Context context, Handler handler, IAppTransitionAnimationSpecsFuture specsFuture, OnAnimationStartedListener listener, boolean scaleUp)930 public static ActivityOptions makeMultiThumbFutureAspectScaleAnimation(Context context, 931 Handler handler, IAppTransitionAnimationSpecsFuture specsFuture, 932 OnAnimationStartedListener listener, boolean scaleUp) { 933 ActivityOptions opts = new ActivityOptions(); 934 opts.mPackageName = context.getPackageName(); 935 opts.mAnimationType = scaleUp 936 ? ANIM_THUMBNAIL_ASPECT_SCALE_UP 937 : ANIM_THUMBNAIL_ASPECT_SCALE_DOWN; 938 opts.mSpecsFuture = specsFuture; 939 opts.setOnAnimationStartedListener(handler, listener); 940 return opts; 941 } 942 943 /** 944 * Create an ActivityOptions specifying an animation where the new activity 945 * window and a thumbnail is aspect-scaled to a new location. 946 * 947 * @param source The View that this thumbnail is animating to. This 948 * defines the coordinate space for <var>startX</var> and <var>startY</var>. 949 * @param thumbnail The bitmap that will be shown as the final thumbnail 950 * of the animation. 951 * @param startX The x end location of the bitmap, relative to <var>source</var>. 952 * @param startY The y end location of the bitmap, relative to <var>source</var>. 953 * @param handler If <var>listener</var> is non-null this must be a valid 954 * Handler on which to dispatch the callback; otherwise it should be null. 955 * @param listener Optional OnAnimationStartedListener to find out when the 956 * requested animation has started running. If for some reason the animation 957 * is not executed, the callback will happen immediately. 958 * @return Returns a new ActivityOptions object that you can use to 959 * supply these options as the options Bundle when starting an activity. 960 * @hide 961 */ 962 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = View.class) makeThumbnailAspectScaleDownAnimation(View source, Bitmap thumbnail, int startX, int startY, int targetWidth, int targetHeight, Handler handler, OnAnimationStartedListener listener)963 public static ActivityOptions makeThumbnailAspectScaleDownAnimation(View source, 964 Bitmap thumbnail, int startX, int startY, int targetWidth, int targetHeight, 965 Handler handler, OnAnimationStartedListener listener) { 966 return makeAspectScaledThumbnailAnimation(source, thumbnail, startX, startY, 967 targetWidth, targetHeight, handler, listener, false); 968 } 969 970 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = View.class) makeAspectScaledThumbnailAnimation(View source, Bitmap thumbnail, int startX, int startY, int targetWidth, int targetHeight, Handler handler, OnAnimationStartedListener listener, boolean scaleUp)971 private static ActivityOptions makeAspectScaledThumbnailAnimation(View source, Bitmap thumbnail, 972 int startX, int startY, int targetWidth, int targetHeight, 973 Handler handler, OnAnimationStartedListener listener, boolean scaleUp) { 974 ActivityOptions opts = new ActivityOptions(); 975 opts.mPackageName = source.getContext().getPackageName(); 976 opts.mAnimationType = scaleUp ? ANIM_THUMBNAIL_ASPECT_SCALE_UP : 977 ANIM_THUMBNAIL_ASPECT_SCALE_DOWN; 978 opts.mThumbnail = thumbnail; 979 int[] pts = new int[2]; 980 source.getLocationOnScreen(pts); 981 opts.mStartX = pts[0] + startX; 982 opts.mStartY = pts[1] + startY; 983 opts.mWidth = targetWidth; 984 opts.mHeight = targetHeight; 985 opts.setOnAnimationStartedListener(handler, listener); 986 return opts; 987 } 988 989 /** @hide */ 990 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = View.class) makeThumbnailAspectScaleDownAnimation(View source, AppTransitionAnimationSpec[] specs, Handler handler, OnAnimationStartedListener onAnimationStartedListener, OnAnimationFinishedListener onAnimationFinishedListener)991 public static ActivityOptions makeThumbnailAspectScaleDownAnimation(View source, 992 AppTransitionAnimationSpec[] specs, Handler handler, 993 OnAnimationStartedListener onAnimationStartedListener, 994 OnAnimationFinishedListener onAnimationFinishedListener) { 995 ActivityOptions opts = new ActivityOptions(); 996 opts.mPackageName = source.getContext().getPackageName(); 997 opts.mAnimationType = ANIM_THUMBNAIL_ASPECT_SCALE_DOWN; 998 opts.mAnimSpecs = specs; 999 opts.setOnAnimationStartedListener(handler, onAnimationStartedListener); 1000 opts.setOnAnimationFinishedListener(handler, onAnimationFinishedListener); 1001 return opts; 1002 } 1003 1004 /** 1005 * Create an ActivityOptions to transition between Activities using cross-Activity scene 1006 * animations. This method carries the position of one shared element to the started Activity. 1007 * The position of <code>sharedElement</code> will be used as the epicenter for the 1008 * exit Transition. The position of the shared element in the launched Activity will be the 1009 * epicenter of its entering Transition. 1010 * 1011 * <p>This requires {@link android.view.Window#FEATURE_ACTIVITY_TRANSITIONS} to be 1012 * enabled on the calling Activity to cause an exit transition. The same must be in 1013 * the called Activity to get an entering transition.</p> 1014 * @param activity The Activity whose window contains the shared elements. 1015 * @param sharedElement The View to transition to the started Activity. 1016 * @param sharedElementName The shared element name as used in the target Activity. This 1017 * must not be null. 1018 * @return Returns a new ActivityOptions object that you can use to 1019 * supply these options as the options Bundle when starting an activity. 1020 * @see android.transition.Transition#setEpicenterCallback( 1021 * android.transition.Transition.EpicenterCallback) 1022 */ 1023 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = Activity.class) makeSceneTransitionAnimation(Activity activity, View sharedElement, String sharedElementName)1024 public static ActivityOptions makeSceneTransitionAnimation(Activity activity, 1025 View sharedElement, String sharedElementName) { 1026 return makeSceneTransitionAnimation(activity, Pair.create(sharedElement, sharedElementName)); 1027 } 1028 1029 /** 1030 * Create an ActivityOptions to transition between Activities using cross-Activity scene 1031 * animations. This method carries the position of multiple shared elements to the started 1032 * Activity. The position of the first element in sharedElements 1033 * will be used as the epicenter for the exit Transition. The position of the associated 1034 * shared element in the launched Activity will be the epicenter of its entering Transition. 1035 * 1036 * <p>This requires {@link android.view.Window#FEATURE_ACTIVITY_TRANSITIONS} to be 1037 * enabled on the calling Activity to cause an exit transition. The same must be in 1038 * the called Activity to get an entering transition.</p> 1039 * @param activity The Activity whose window contains the shared elements. 1040 * @param sharedElements The names of the shared elements to transfer to the called 1041 * Activity and their associated Views. The Views must each have 1042 * a unique shared element name. 1043 * @return Returns a new ActivityOptions object that you can use to 1044 * supply these options as the options Bundle when starting an activity. 1045 * @see android.transition.Transition#setEpicenterCallback( 1046 * android.transition.Transition.EpicenterCallback) 1047 */ 1048 @SafeVarargs 1049 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = Activity.class) makeSceneTransitionAnimation(Activity activity, Pair<View, String>... sharedElements)1050 public static ActivityOptions makeSceneTransitionAnimation(Activity activity, 1051 Pair<View, String>... sharedElements) { 1052 ActivityOptions opts = new ActivityOptions(); 1053 ExitTransitionCoordinator exit = makeSceneTransitionAnimation( 1054 new ActivityExitTransitionCallbacks(activity), activity.mExitTransitionListener, 1055 activity.getWindow(), opts, sharedElements); 1056 final SceneTransitionInfo info = opts.getSceneTransitionInfo(); 1057 if (info != null) { 1058 info.setExitCoordinatorKey( 1059 activity.mActivityTransitionState.addExitTransitionCoordinator(exit)); 1060 } 1061 return opts; 1062 } 1063 1064 /** 1065 * Call this immediately prior to startActivity to begin a shared element transition 1066 * from a non-Activity. The window must support Window.FEATURE_ACTIVITY_TRANSITIONS. 1067 * The exit transition will start immediately and the shared element transition will 1068 * start once the launched Activity's shared element is ready. 1069 * <p> 1070 * When all transitions have completed and the shared element has been transfered, 1071 * the window's decor View will have its visibility set to View.GONE. 1072 * 1073 * @hide 1074 */ 1075 @SafeVarargs 1076 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = Window.class) startSharedElementAnimation( Window window, ExitTransitionCallbacks exitCallbacks, SharedElementCallback callback, Pair<View, String>... sharedElements)1077 public static Pair<ActivityOptions, ExitTransitionCoordinator> startSharedElementAnimation( 1078 Window window, ExitTransitionCallbacks exitCallbacks, SharedElementCallback callback, 1079 Pair<View, String>... sharedElements) { 1080 ActivityOptions opts = new ActivityOptions(); 1081 ExitTransitionCoordinator exit = makeSceneTransitionAnimation( 1082 exitCallbacks, callback, window, opts, sharedElements); 1083 final SceneTransitionInfo info = opts.getSceneTransitionInfo(); 1084 if (info != null) { 1085 info.setExitCoordinatorKey(-1); 1086 } 1087 return Pair.create(opts, exit); 1088 } 1089 1090 /** 1091 * This method should be called when the {@link #startSharedElementAnimation(Window, 1092 * ExitTransitionCallbacks, SharedElementCallback, Pair[])} 1093 * animation must be stopped and the Views reset. This can happen if there was an error 1094 * from startActivity or a springboard activity and the animation should stop and reset. 1095 * 1096 * @hide 1097 */ 1098 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = Window.class) stopSharedElementAnimation(Window window)1099 public static void stopSharedElementAnimation(Window window) { 1100 final View decorView = window.getDecorView(); 1101 if (decorView == null) { 1102 return; 1103 } 1104 final ExitTransitionCoordinator exit = (ExitTransitionCoordinator) 1105 decorView.getTag(com.android.internal.R.id.cross_task_transition); 1106 if (exit != null) { 1107 exit.cancelPendingTransitions(); 1108 decorView.setTagInternal(com.android.internal.R.id.cross_task_transition, null); 1109 TransitionManager.endTransitions((ViewGroup) decorView); 1110 exit.resetViews(); 1111 exit.clearState(); 1112 decorView.setVisibility(View.VISIBLE); 1113 } 1114 } 1115 1116 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = Window.class) makeSceneTransitionAnimation( ExitTransitionCallbacks exitCallbacks, SharedElementCallback callback, Window window, ActivityOptions opts, Pair<View, String>[] sharedElements)1117 static ExitTransitionCoordinator makeSceneTransitionAnimation( 1118 ExitTransitionCallbacks exitCallbacks, SharedElementCallback callback, Window window, 1119 ActivityOptions opts, Pair<View, String>[] sharedElements) { 1120 if (!window.hasFeature(Window.FEATURE_ACTIVITY_TRANSITIONS)) { 1121 opts.mAnimationType = ANIM_DEFAULT; 1122 return null; 1123 } 1124 opts.mAnimationType = ANIM_SCENE_TRANSITION; 1125 1126 ArrayList<String> names = new ArrayList<String>(); 1127 ArrayList<View> views = new ArrayList<View>(); 1128 1129 if (sharedElements != null) { 1130 for (int i = 0; i < sharedElements.length; i++) { 1131 Pair<View, String> sharedElement = sharedElements[i]; 1132 String sharedElementName = sharedElement.second; 1133 if (sharedElementName == null) { 1134 throw new IllegalArgumentException("Shared element name must not be null"); 1135 } 1136 names.add(sharedElementName); 1137 View view = sharedElement.first; 1138 if (view == null) { 1139 throw new IllegalArgumentException("Shared element must not be null"); 1140 } 1141 views.add(sharedElement.first); 1142 } 1143 } 1144 1145 ExitTransitionCoordinator exit = new ExitTransitionCoordinator(exitCallbacks, window, 1146 callback, names, names, views, false); 1147 final SceneTransitionInfo info = new SceneTransitionInfo(); 1148 info.setResultReceiver(exit); 1149 info.setSharedElementNames(names); 1150 info.setReturning(false); 1151 opts.setSceneTransitionInfo(info); 1152 return exit; 1153 } 1154 1155 /** 1156 * Needed for virtual devices because they can be slow enough that the 1 second timeout 1157 * triggers when it doesn't on normal devices. 1158 * 1159 * @hide 1160 */ 1161 @TestApi setExitTransitionTimeout(long timeoutMillis)1162 public static void setExitTransitionTimeout(long timeoutMillis) { 1163 ExitTransitionCoordinator.sMaxWaitMillis = timeoutMillis; 1164 } 1165 1166 /** @hide */ 1167 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = Activity.class) makeSceneTransitionAnimation(Activity activity, ExitTransitionCoordinator exitCoordinator, ArrayList<String> sharedElementNames, int resultCode, Intent resultData)1168 static ActivityOptions makeSceneTransitionAnimation(Activity activity, 1169 ExitTransitionCoordinator exitCoordinator, ArrayList<String> sharedElementNames, 1170 int resultCode, Intent resultData) { 1171 ActivityOptions opts = new ActivityOptions(); 1172 opts.mAnimationType = ANIM_SCENE_TRANSITION; 1173 final SceneTransitionInfo info = new SceneTransitionInfo(); 1174 info.setSharedElementNames(sharedElementNames); 1175 info.setResultReceiver(exitCoordinator); 1176 info.setReturning(true); 1177 info.setResultCode(resultCode); 1178 info.setResultData(resultData); 1179 if (activity == null) { 1180 info.setExitCoordinatorKey(-1); 1181 } else { 1182 info.setExitCoordinatorKey( 1183 activity.mActivityTransitionState.addExitTransitionCoordinator( 1184 exitCoordinator)); 1185 } 1186 opts.setSceneTransitionInfo(info); 1187 return opts; 1188 } 1189 1190 /** 1191 * If set along with Intent.FLAG_ACTIVITY_NEW_DOCUMENT then the task being launched will not be 1192 * presented to the user but will instead be only available through the recents task list. 1193 * In addition, the new task wil be affiliated with the launching activity's task. 1194 * Affiliated tasks are grouped together in the recents task list. 1195 * 1196 * <p>This behavior is not supported for activities with {@link 1197 * android.R.styleable#AndroidManifestActivity_launchMode launchMode} values of 1198 * <code>singleInstance</code> or <code>singleTask</code>. 1199 */ makeTaskLaunchBehind()1200 public static ActivityOptions makeTaskLaunchBehind() { 1201 final ActivityOptions opts = new ActivityOptions(); 1202 opts.mAnimationType = ANIM_LAUNCH_TASK_BEHIND; 1203 return opts; 1204 } 1205 1206 /** 1207 * Create a basic ActivityOptions that has no special animation associated with it. 1208 * Other options can still be set. 1209 */ makeBasic()1210 public static ActivityOptions makeBasic() { 1211 final ActivityOptions opts = new ActivityOptions(); 1212 return opts; 1213 } 1214 1215 /** 1216 * Create an {@link ActivityOptions} instance that lets the application control the entire 1217 * animation using a {@link RemoteAnimationAdapter}. 1218 * @hide 1219 */ 1220 @RequiresPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS) 1221 @UnsupportedAppUsage 1222 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = RemoteAnimationAdapter.class) makeRemoteAnimation( RemoteAnimationAdapter remoteAnimationAdapter)1223 public static ActivityOptions makeRemoteAnimation( 1224 RemoteAnimationAdapter remoteAnimationAdapter) { 1225 final ActivityOptions opts = new ActivityOptions(); 1226 opts.mRemoteAnimationAdapter = remoteAnimationAdapter; 1227 opts.mAnimationType = ANIM_REMOTE_ANIMATION; 1228 return opts; 1229 } 1230 1231 /** 1232 * Create an {@link ActivityOptions} instance that lets the application control the entire 1233 * animation using a {@link RemoteAnimationAdapter}. 1234 * @hide 1235 */ 1236 @RequiresPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS) 1237 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = RemoteAnimationAdapter.class) makeRemoteAnimation(RemoteAnimationAdapter remoteAnimationAdapter, RemoteTransition remoteTransition)1238 public static ActivityOptions makeRemoteAnimation(RemoteAnimationAdapter remoteAnimationAdapter, 1239 RemoteTransition remoteTransition) { 1240 final ActivityOptions opts = new ActivityOptions(); 1241 opts.mRemoteAnimationAdapter = remoteAnimationAdapter; 1242 opts.mAnimationType = ANIM_REMOTE_ANIMATION; 1243 opts.mRemoteTransition = remoteTransition; 1244 return opts; 1245 } 1246 1247 /** 1248 * Create an {@link ActivityOptions} instance that lets the application control the entire 1249 * transition using a {@link RemoteTransition}. 1250 * @hide 1251 */ 1252 @RequiresPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS) 1253 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = RemoteAnimationAdapter.class) makeRemoteTransition(RemoteTransition remoteTransition)1254 public static ActivityOptions makeRemoteTransition(RemoteTransition remoteTransition) { 1255 final ActivityOptions opts = new ActivityOptions(); 1256 opts.mRemoteTransition = remoteTransition; 1257 return opts; 1258 } 1259 1260 /** 1261 * Creates an {@link ActivityOptions} instance that launch into picture-in-picture. 1262 * This is normally used by a Host activity to start another activity that will directly enter 1263 * picture-in-picture upon its creation. 1264 * @param pictureInPictureParams {@link PictureInPictureParams} for launching the Activity to 1265 * picture-in-picture mode. 1266 */ 1267 @NonNull 1268 @android.ravenwood.annotation.RavenwoodThrow(blockedBy = PictureInPictureParams.class) makeLaunchIntoPip( @onNull PictureInPictureParams pictureInPictureParams)1269 public static ActivityOptions makeLaunchIntoPip( 1270 @NonNull PictureInPictureParams pictureInPictureParams) { 1271 final ActivityOptions opts = new ActivityOptions(); 1272 opts.mLaunchIntoPipParams = new PictureInPictureParams.Builder(pictureInPictureParams) 1273 .setIsLaunchIntoPip(true) 1274 .build(); 1275 return opts; 1276 } 1277 1278 /** @hide */ getLaunchTaskBehind()1279 public boolean getLaunchTaskBehind() { 1280 return mAnimationType == ANIM_LAUNCH_TASK_BEHIND; 1281 } 1282 ActivityOptions()1283 private ActivityOptions() { 1284 super(); 1285 } 1286 1287 /** @hide */ ActivityOptions(Bundle opts)1288 public ActivityOptions(Bundle opts) { 1289 super(opts); 1290 1291 mPackageName = opts.getString(KEY_PACKAGE_NAME); 1292 try { 1293 mUsageTimeReport = opts.getParcelable(KEY_USAGE_TIME_REPORT, PendingIntent.class); 1294 } catch (RuntimeException e) { 1295 Slog.w(TAG, e); 1296 } 1297 mLaunchBounds = opts.getParcelable(KEY_LAUNCH_BOUNDS, android.graphics.Rect.class); 1298 mAnimationType = opts.getInt(KEY_ANIM_TYPE, ANIM_UNDEFINED); 1299 switch (mAnimationType) { 1300 case ANIM_CUSTOM: 1301 mCustomEnterResId = opts.getInt(KEY_ANIM_ENTER_RES_ID, 0); 1302 mCustomExitResId = opts.getInt(KEY_ANIM_EXIT_RES_ID, 0); 1303 mCustomBackgroundColor = opts.getInt(KEY_ANIM_BACKGROUND_COLOR, 0); 1304 mAnimationStartedListener = IRemoteCallback.Stub.asInterface( 1305 opts.getBinder(KEY_ANIM_START_LISTENER)); 1306 break; 1307 1308 case ANIM_CUSTOM_IN_PLACE: 1309 mCustomInPlaceResId = opts.getInt(KEY_ANIM_IN_PLACE_RES_ID, 0); 1310 break; 1311 1312 case ANIM_SCALE_UP: 1313 case ANIM_CLIP_REVEAL: 1314 mStartX = opts.getInt(KEY_ANIM_START_X, 0); 1315 mStartY = opts.getInt(KEY_ANIM_START_Y, 0); 1316 mWidth = opts.getInt(KEY_ANIM_WIDTH, 0); 1317 mHeight = opts.getInt(KEY_ANIM_HEIGHT, 0); 1318 break; 1319 1320 case ANIM_THUMBNAIL_SCALE_UP: 1321 case ANIM_THUMBNAIL_SCALE_DOWN: 1322 case ANIM_THUMBNAIL_ASPECT_SCALE_UP: 1323 case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN: 1324 // Unpackage the HardwareBuffer from the parceled thumbnail 1325 final HardwareBuffer buffer = opts.getParcelable(KEY_ANIM_THUMBNAIL, android.hardware.HardwareBuffer.class); 1326 if (buffer != null) { 1327 mThumbnail = Bitmap.wrapHardwareBuffer(buffer, null); 1328 } 1329 mStartX = opts.getInt(KEY_ANIM_START_X, 0); 1330 mStartY = opts.getInt(KEY_ANIM_START_Y, 0); 1331 mWidth = opts.getInt(KEY_ANIM_WIDTH, 0); 1332 mHeight = opts.getInt(KEY_ANIM_HEIGHT, 0); 1333 mAnimationStartedListener = IRemoteCallback.Stub.asInterface( 1334 opts.getBinder(KEY_ANIM_START_LISTENER)); 1335 break; 1336 1337 case ANIM_SCENE_TRANSITION: 1338 mSceneTransitionInfo = opts.getParcelable(KEY_SCENE_TRANSITION_INFO, 1339 SceneTransitionInfo.class); 1340 break; 1341 } 1342 mLockTaskMode = opts.getBoolean(KEY_LOCK_TASK_MODE, false); 1343 mShareIdentity = opts.getBoolean(KEY_SHARE_IDENTITY, false); 1344 mLaunchDisplayId = opts.getInt(KEY_LAUNCH_DISPLAY_ID, INVALID_DISPLAY); 1345 mCallerDisplayId = opts.getInt(KEY_CALLER_DISPLAY_ID, INVALID_DISPLAY); 1346 mLaunchTaskDisplayArea = opts.getParcelable(KEY_LAUNCH_TASK_DISPLAY_AREA_TOKEN, android.window.WindowContainerToken.class); 1347 mLaunchTaskDisplayAreaFeatureId = opts.getInt(KEY_LAUNCH_TASK_DISPLAY_AREA_FEATURE_ID, 1348 FEATURE_UNDEFINED); 1349 mLaunchRootTask = opts.getParcelable(KEY_LAUNCH_ROOT_TASK_TOKEN, android.window.WindowContainerToken.class); 1350 mLaunchTaskFragmentToken = opts.getBinder(KEY_LAUNCH_TASK_FRAGMENT_TOKEN); 1351 mLaunchWindowingMode = opts.getInt(KEY_LAUNCH_WINDOWING_MODE, WINDOWING_MODE_UNDEFINED); 1352 mLaunchActivityType = opts.getInt(KEY_LAUNCH_ACTIVITY_TYPE, ACTIVITY_TYPE_UNDEFINED); 1353 mLaunchTaskId = opts.getInt(KEY_LAUNCH_TASK_ID, -1); 1354 mPendingIntentLaunchFlags = opts.getInt(KEY_PENDING_INTENT_LAUNCH_FLAGS, 0); 1355 mTaskAlwaysOnTop = opts.getBoolean(KEY_TASK_ALWAYS_ON_TOP, false); 1356 mTaskOverlay = opts.getBoolean(KEY_TASK_OVERLAY, false); 1357 mTaskOverlayCanResume = opts.getBoolean(KEY_TASK_OVERLAY_CAN_RESUME, false); 1358 mAvoidMoveToFront = opts.getBoolean(KEY_AVOID_MOVE_TO_FRONT, false); 1359 mFreezeRecentTasksReordering = opts.getBoolean(KEY_FREEZE_RECENT_TASKS_REORDERING, false); 1360 mDisallowEnterPictureInPictureWhileLaunching = opts.getBoolean( 1361 KEY_DISALLOW_ENTER_PICTURE_IN_PICTURE_WHILE_LAUNCHING, false); 1362 mApplyActivityFlagsForBubbles = opts.getBoolean( 1363 KEY_APPLY_ACTIVITY_FLAGS_FOR_BUBBLES, false); 1364 mApplyMultipleTaskFlagForShortcut = opts.getBoolean( 1365 KEY_APPLY_MULTIPLE_TASK_FLAG_FOR_SHORTCUT, false); 1366 mApplyNoUserActionFlagForShortcut = opts.getBoolean( 1367 KEY_APPLY_NO_USER_ACTION_FLAG_FOR_SHORTCUT, false); 1368 if (opts.containsKey(KEY_ANIM_SPECS)) { 1369 Parcelable[] specs = opts.getParcelableArray(KEY_ANIM_SPECS); 1370 mAnimSpecs = new AppTransitionAnimationSpec[specs.length]; 1371 for (int i = specs.length - 1; i >= 0; i--) { 1372 mAnimSpecs[i] = (AppTransitionAnimationSpec) specs[i]; 1373 } 1374 } 1375 if (opts.containsKey(KEY_ANIMATION_FINISHED_LISTENER)) { 1376 mAnimationFinishedListener = IRemoteCallback.Stub.asInterface( 1377 opts.getBinder(KEY_ANIMATION_FINISHED_LISTENER)); 1378 } 1379 mSourceInfo = opts.getParcelable(KEY_SOURCE_INFO, android.app.ActivityOptions.SourceInfo.class); 1380 mRotationAnimationHint = opts.getInt(KEY_ROTATION_ANIMATION_HINT, -1); 1381 mAppVerificationBundle = opts.getBundle(KEY_INSTANT_APP_VERIFICATION_BUNDLE); 1382 if (opts.containsKey(KEY_SPECS_FUTURE)) { 1383 mSpecsFuture = IAppTransitionAnimationSpecsFuture.Stub.asInterface(opts.getBinder( 1384 KEY_SPECS_FUTURE)); 1385 } 1386 mRemoteAnimationAdapter = opts.getParcelable(KEY_REMOTE_ANIMATION_ADAPTER, android.view.RemoteAnimationAdapter.class); 1387 mLaunchCookie = opts.getBinder(KEY_LAUNCH_COOKIE); 1388 mRemoteTransition = opts.getParcelable(KEY_REMOTE_TRANSITION, android.window.RemoteTransition.class); 1389 mOverrideTaskTransition = opts.getBoolean(KEY_OVERRIDE_TASK_TRANSITION); 1390 mSplashScreenThemeResName = opts.getString(KEY_SPLASH_SCREEN_THEME); 1391 mRemoveWithTaskOrganizer = opts.getBoolean(KEY_REMOVE_WITH_TASK_ORGANIZER); 1392 mLaunchedFromBubble = opts.getBoolean(KEY_LAUNCHED_FROM_BUBBLE); 1393 mTransientLaunch = opts.getBoolean(KEY_TRANSIENT_LAUNCH); 1394 mSplashScreenStyle = opts.getInt(KEY_SPLASH_SCREEN_STYLE); 1395 mLaunchIntoPipParams = opts.getParcelable(KEY_LAUNCH_INTO_PIP_PARAMS, android.app.PictureInPictureParams.class); 1396 mIsEligibleForLegacyPermissionPrompt = 1397 opts.getBoolean(KEY_LEGACY_PERMISSION_PROMPT_ELIGIBLE); 1398 mDismissKeyguardIfInsecure = opts.getBoolean(KEY_DISMISS_KEYGUARD_IF_INSECURE); 1399 mPendingIntentCreatorBackgroundActivityStartMode = opts.getInt( 1400 KEY_PENDING_INTENT_CREATOR_BACKGROUND_ACTIVITY_START_MODE, 1401 MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED); 1402 mDisableStartingWindow = opts.getBoolean(KEY_DISABLE_STARTING_WINDOW); 1403 mAnimationAbortListener = IRemoteCallback.Stub.asInterface( 1404 opts.getBinder(KEY_ANIM_ABORT_LISTENER)); 1405 } 1406 1407 /** 1408 * Sets the bounds (window size and position) that the activity should be launched in. 1409 * Rect position should be provided in pixels and in screen coordinates. 1410 * Set to {@code null} to explicitly launch fullscreen. 1411 * <p> 1412 * <strong>NOTE:</strong> This value is ignored on devices that don't have 1413 * {@link android.content.pm.PackageManager#FEATURE_FREEFORM_WINDOW_MANAGEMENT} or 1414 * {@link android.content.pm.PackageManager#FEATURE_PICTURE_IN_PICTURE} enabled. 1415 * @param screenSpacePixelRect launch bounds or {@code null} for fullscreen 1416 * @return {@code this} {@link ActivityOptions} instance 1417 */ setLaunchBounds(@ullable Rect screenSpacePixelRect)1418 public ActivityOptions setLaunchBounds(@Nullable Rect screenSpacePixelRect) { 1419 mLaunchBounds = screenSpacePixelRect != null ? new Rect(screenSpacePixelRect) : null; 1420 return this; 1421 } 1422 1423 /** @hide */ getPackageName()1424 public String getPackageName() { 1425 return mPackageName; 1426 } 1427 1428 /** 1429 * Returns the bounds that should be used to launch the activity. 1430 * @see #setLaunchBounds(Rect) 1431 * @return Bounds used to launch the activity. 1432 */ 1433 @Nullable getLaunchBounds()1434 public Rect getLaunchBounds() { 1435 return mLaunchBounds; 1436 } 1437 1438 /** @hide */ getAnimationType()1439 public int getAnimationType() { 1440 return mAnimationType; 1441 } 1442 1443 /** @hide */ getCustomEnterResId()1444 public int getCustomEnterResId() { 1445 return mCustomEnterResId; 1446 } 1447 1448 /** @hide */ getCustomExitResId()1449 public int getCustomExitResId() { 1450 return mCustomExitResId; 1451 } 1452 1453 /** @hide */ getCustomInPlaceResId()1454 public int getCustomInPlaceResId() { 1455 return mCustomInPlaceResId; 1456 } 1457 1458 /** @hide */ getCustomBackgroundColor()1459 public int getCustomBackgroundColor() { 1460 return mCustomBackgroundColor; 1461 } 1462 1463 /** 1464 * The thumbnail is copied into a hardware bitmap when it is bundled and sent to the system, so 1465 * it should always be backed by a HardwareBuffer on the other end. 1466 * 1467 * @hide 1468 */ getThumbnail()1469 public HardwareBuffer getThumbnail() { 1470 return mThumbnail != null ? mThumbnail.getHardwareBuffer() : null; 1471 } 1472 1473 /** @hide */ getStartX()1474 public int getStartX() { 1475 return mStartX; 1476 } 1477 1478 /** @hide */ getStartY()1479 public int getStartY() { 1480 return mStartY; 1481 } 1482 1483 /** @hide */ getWidth()1484 public int getWidth() { 1485 return mWidth; 1486 } 1487 1488 /** @hide */ getHeight()1489 public int getHeight() { 1490 return mHeight; 1491 } 1492 1493 /** @hide */ getAnimationStartedListener()1494 public IRemoteCallback getAnimationStartedListener() { 1495 return mAnimationStartedListener; 1496 } 1497 1498 /** @hide */ getAnimationFinishedListener()1499 public IRemoteCallback getAnimationFinishedListener() { 1500 return mAnimationFinishedListener; 1501 } 1502 1503 /** @hide */ abort()1504 public void abort() { 1505 sendResultIgnoreErrors(mAnimationStartedListener, null); 1506 sendResultIgnoreErrors(mAnimationAbortListener, null); 1507 } 1508 sendResultIgnoreErrors(IRemoteCallback callback, Bundle data)1509 private void sendResultIgnoreErrors(IRemoteCallback callback, Bundle data) { 1510 if (callback != null) { 1511 try { 1512 callback.sendResult(data); 1513 } catch (RemoteException e) { } 1514 } 1515 } 1516 1517 /** @hide */ setSceneTransitionInfo(SceneTransitionInfo info)1518 public ActivityOptions setSceneTransitionInfo(SceneTransitionInfo info) { 1519 mSceneTransitionInfo = info; 1520 return this; 1521 } 1522 1523 /** @hide */ getSceneTransitionInfo()1524 public SceneTransitionInfo getSceneTransitionInfo() { 1525 return mSceneTransitionInfo; 1526 } 1527 1528 /** @hide */ getUsageTimeReport()1529 public PendingIntent getUsageTimeReport() { 1530 return mUsageTimeReport; 1531 } 1532 1533 /** @hide */ getAnimSpecs()1534 public AppTransitionAnimationSpec[] getAnimSpecs() { return mAnimSpecs; } 1535 1536 /** @hide */ getSpecsFuture()1537 public IAppTransitionAnimationSpecsFuture getSpecsFuture() { 1538 return mSpecsFuture; 1539 } 1540 1541 /** @hide */ getRemoteAnimationAdapter()1542 public RemoteAnimationAdapter getRemoteAnimationAdapter() { 1543 return mRemoteAnimationAdapter; 1544 } 1545 1546 /** @hide */ setRemoteAnimationAdapter(RemoteAnimationAdapter remoteAnimationAdapter)1547 public void setRemoteAnimationAdapter(RemoteAnimationAdapter remoteAnimationAdapter) { 1548 mRemoteAnimationAdapter = remoteAnimationAdapter; 1549 } 1550 1551 /** @hide */ getRemoteTransition()1552 public RemoteTransition getRemoteTransition() { 1553 return mRemoteTransition; 1554 } 1555 1556 /** @hide */ setRemoteTransition(@ullable RemoteTransition remoteTransition)1557 public ActivityOptions setRemoteTransition(@Nullable RemoteTransition remoteTransition) { 1558 mRemoteTransition = remoteTransition; 1559 return this; 1560 } 1561 1562 /** @hide */ fromBundle(Bundle bOptions)1563 public static ActivityOptions fromBundle(Bundle bOptions) { 1564 return bOptions != null ? new ActivityOptions(bOptions) : null; 1565 } 1566 1567 /** @hide */ abort(ActivityOptions options)1568 public static void abort(ActivityOptions options) { 1569 if (options != null) { 1570 options.abort(); 1571 } 1572 } 1573 1574 /** 1575 * Gets whether the activity is to be launched into LockTask mode. 1576 * @return {@code true} if the activity is to be launched into LockTask mode. 1577 * @see Activity#startLockTask() 1578 * @see android.app.admin.DevicePolicyManager#setLockTaskPackages(ComponentName, String[]) 1579 */ getLockTaskMode()1580 public boolean getLockTaskMode() { 1581 return mLockTaskMode; 1582 } 1583 1584 /** 1585 * Returns whether the launching app has opted-in to sharing its identity with the launched 1586 * activity. 1587 * 1588 * @return {@code true} if the launching app has opted-in to sharing its identity 1589 * 1590 * @see #setShareIdentityEnabled(boolean) 1591 * @see Activity#getLaunchedFromUid() 1592 * @see Activity#getLaunchedFromPackage() 1593 */ isShareIdentityEnabled()1594 public boolean isShareIdentityEnabled() { 1595 return mShareIdentity; 1596 } 1597 1598 /** 1599 * Gets whether the activity want to be launched as other theme for the splash screen. 1600 * @hide 1601 */ 1602 @Nullable getSplashScreenThemeResName()1603 public String getSplashScreenThemeResName() { 1604 return mSplashScreenThemeResName; 1605 } 1606 1607 /** 1608 * Gets the style can be used for cold-launching an activity. 1609 * @see #setSplashScreenStyle(int) 1610 */ getSplashScreenStyle()1611 public @SplashScreen.SplashScreenStyle int getSplashScreenStyle() { 1612 return mSplashScreenStyle; 1613 } 1614 1615 /** 1616 * Sets the preferred splash screen style of the opening activities. This only applies if the 1617 * Activity or Process is not yet created. 1618 * @param style Can be either {@link SplashScreen#SPLASH_SCREEN_STYLE_ICON} or 1619 * {@link SplashScreen#SPLASH_SCREEN_STYLE_SOLID_COLOR} 1620 */ 1621 @NonNull setSplashScreenStyle(@plashScreen.SplashScreenStyle int style)1622 public ActivityOptions setSplashScreenStyle(@SplashScreen.SplashScreenStyle int style) { 1623 if (style == SplashScreen.SPLASH_SCREEN_STYLE_ICON 1624 || style == SplashScreen.SPLASH_SCREEN_STYLE_SOLID_COLOR) { 1625 mSplashScreenStyle = style; 1626 } 1627 return this; 1628 } 1629 1630 /** 1631 * Whether the activity is eligible to show a legacy permission prompt 1632 * @hide 1633 */ 1634 @TestApi isEligibleForLegacyPermissionPrompt()1635 public boolean isEligibleForLegacyPermissionPrompt() { 1636 return mIsEligibleForLegacyPermissionPrompt; 1637 } 1638 1639 /** 1640 * Sets whether the activity is eligible to show a legacy permission prompt 1641 * @hide 1642 */ 1643 @TestApi setEligibleForLegacyPermissionPrompt(boolean eligible)1644 public void setEligibleForLegacyPermissionPrompt(boolean eligible) { 1645 mIsEligibleForLegacyPermissionPrompt = eligible; 1646 } 1647 1648 /** 1649 * Sets whether the activity is to be launched into LockTask mode. 1650 * 1651 * Use this option to start an activity in LockTask mode. Note that only apps permitted by 1652 * {@link android.app.admin.DevicePolicyManager} can run in LockTask mode. Therefore, if 1653 * {@link android.app.admin.DevicePolicyManager#isLockTaskPermitted(String)} returns 1654 * {@code false} for the package of the target activity, a {@link SecurityException} will be 1655 * thrown during {@link Context#startActivity(Intent, Bundle)}. This method doesn't affect 1656 * activities that are already running — relaunch the activity to run in lock task mode. 1657 * 1658 * Defaults to {@code false} if not set. 1659 * 1660 * @param lockTaskMode {@code true} if the activity is to be launched into LockTask mode. 1661 * @return {@code this} {@link ActivityOptions} instance. 1662 * @see Activity#startLockTask() 1663 * @see android.app.admin.DevicePolicyManager#setLockTaskPackages(ComponentName, String[]) 1664 */ setLockTaskEnabled(boolean lockTaskMode)1665 public ActivityOptions setLockTaskEnabled(boolean lockTaskMode) { 1666 mLockTaskMode = lockTaskMode; 1667 return this; 1668 } 1669 1670 /** 1671 * Sets whether the identity of the launching app should be shared with the activity. 1672 * 1673 * <p>Use this option when starting an activity that needs to know the identity of the 1674 * launching app; with this set to {@code true}, the activity will have access to the launching 1675 * app's package name and uid. 1676 * 1677 * <p>Defaults to {@code false} if not set. 1678 * 1679 * <p>Note, even if the launching app does not explicitly enable sharing of its identity, if 1680 * the activity is started with {@code Activity#startActivityForResult}, then {@link 1681 * Activity#getCallingPackage()} will still return the launching app's package name to 1682 * allow validation of the result's recipient. Also, an activity running within a package 1683 * signed by the same key used to sign the platform (some system apps such as Settings will 1684 * be signed with the platform's key) will have access to the launching app's identity. 1685 * 1686 * @param shareIdentity whether the launching app's identity should be shared with the activity 1687 * @return {@code this} {@link ActivityOptions} instance. 1688 * @see Activity#getLaunchedFromPackage() 1689 * @see Activity#getLaunchedFromUid() 1690 */ 1691 @NonNull setShareIdentityEnabled(boolean shareIdentity)1692 public ActivityOptions setShareIdentityEnabled(boolean shareIdentity) { 1693 mShareIdentity = shareIdentity; 1694 return this; 1695 } 1696 1697 /** 1698 * Gets the id of the display where activity should be launched. 1699 * @return The id of the display where activity should be launched, 1700 * {@link android.view.Display#INVALID_DISPLAY} if not set. 1701 * @see #setLaunchDisplayId(int) 1702 */ getLaunchDisplayId()1703 public int getLaunchDisplayId() { 1704 return mLaunchDisplayId; 1705 } 1706 1707 /** 1708 * Sets the id of the display where the activity should be launched. 1709 * An app can launch activities on public displays or displays where the app already has 1710 * activities. Otherwise, trying to launch on a private display or providing an invalid display 1711 * id will result in an exception. 1712 * <p> 1713 * Setting launch display id will be ignored on devices that don't have 1714 * {@link android.content.pm.PackageManager#FEATURE_ACTIVITIES_ON_SECONDARY_DISPLAYS}. 1715 * @param launchDisplayId The id of the display where the activity should be launched. 1716 * @return {@code this} {@link ActivityOptions} instance. 1717 */ setLaunchDisplayId(int launchDisplayId)1718 public ActivityOptions setLaunchDisplayId(int launchDisplayId) { 1719 mLaunchDisplayId = launchDisplayId; 1720 return this; 1721 } 1722 1723 /** @hide */ getCallerDisplayId()1724 public int getCallerDisplayId() { 1725 return mCallerDisplayId; 1726 } 1727 1728 /** @hide */ setCallerDisplayId(int callerDisplayId)1729 public ActivityOptions setCallerDisplayId(int callerDisplayId) { 1730 mCallerDisplayId = callerDisplayId; 1731 return this; 1732 } 1733 1734 /** @hide */ getLaunchTaskDisplayArea()1735 public WindowContainerToken getLaunchTaskDisplayArea() { 1736 return mLaunchTaskDisplayArea; 1737 } 1738 1739 /** @hide */ setLaunchTaskDisplayArea( WindowContainerToken windowContainerToken)1740 public ActivityOptions setLaunchTaskDisplayArea( 1741 WindowContainerToken windowContainerToken) { 1742 mLaunchTaskDisplayArea = windowContainerToken; 1743 return this; 1744 } 1745 1746 /** @hide */ getLaunchTaskDisplayAreaFeatureId()1747 public int getLaunchTaskDisplayAreaFeatureId() { 1748 return mLaunchTaskDisplayAreaFeatureId; 1749 } 1750 1751 /** 1752 * Sets the TaskDisplayArea feature Id the activity should launch into. 1753 * Note: It is possible to have TaskDisplayAreas with the same featureId on multiple displays. 1754 * If launch display id is not specified, the TaskDisplayArea on the default display will be 1755 * used. 1756 * @hide 1757 */ 1758 @TestApi setLaunchTaskDisplayAreaFeatureId(int launchTaskDisplayAreaFeatureId)1759 public void setLaunchTaskDisplayAreaFeatureId(int launchTaskDisplayAreaFeatureId) { 1760 mLaunchTaskDisplayAreaFeatureId = launchTaskDisplayAreaFeatureId; 1761 } 1762 1763 /** @hide */ getLaunchRootTask()1764 public WindowContainerToken getLaunchRootTask() { 1765 return mLaunchRootTask; 1766 } 1767 1768 /** @hide */ setLaunchRootTask(WindowContainerToken windowContainerToken)1769 public ActivityOptions setLaunchRootTask(WindowContainerToken windowContainerToken) { 1770 mLaunchRootTask = windowContainerToken; 1771 return this; 1772 } 1773 1774 /** @hide */ getLaunchTaskFragmentToken()1775 public IBinder getLaunchTaskFragmentToken() { 1776 return mLaunchTaskFragmentToken; 1777 } 1778 1779 /** @hide */ setLaunchTaskFragmentToken(IBinder taskFragmentToken)1780 public ActivityOptions setLaunchTaskFragmentToken(IBinder taskFragmentToken) { 1781 mLaunchTaskFragmentToken = taskFragmentToken; 1782 return this; 1783 } 1784 1785 /** @hide */ getLaunchWindowingMode()1786 public int getLaunchWindowingMode() { 1787 return mLaunchWindowingMode; 1788 } 1789 1790 /** 1791 * Sets the windowing mode the activity should launch into. 1792 * @hide 1793 */ 1794 @TestApi setLaunchWindowingMode(int windowingMode)1795 public void setLaunchWindowingMode(int windowingMode) { 1796 mLaunchWindowingMode = windowingMode; 1797 } 1798 1799 /** 1800 * @return {@link PictureInPictureParams} used to launch into PiP mode. 1801 * @hide 1802 */ getLaunchIntoPipParams()1803 public PictureInPictureParams getLaunchIntoPipParams() { 1804 return mLaunchIntoPipParams; 1805 } 1806 1807 /** 1808 * @return {@code true} if this instance is used to launch into PiP mode. 1809 * @hide 1810 */ isLaunchIntoPip()1811 public boolean isLaunchIntoPip() { 1812 return mLaunchIntoPipParams != null 1813 && mLaunchIntoPipParams.isLaunchIntoPip(); 1814 } 1815 1816 /** @hide */ getLaunchActivityType()1817 public int getLaunchActivityType() { 1818 return mLaunchActivityType; 1819 } 1820 1821 /** @hide */ 1822 @TestApi setLaunchActivityType(int activityType)1823 public void setLaunchActivityType(int activityType) { 1824 mLaunchActivityType = activityType; 1825 } 1826 1827 /** 1828 * Sets the task the activity will be launched in. 1829 * @hide 1830 */ 1831 @RequiresPermission(START_TASKS_FROM_RECENTS) 1832 @SystemApi setLaunchTaskId(int taskId)1833 public void setLaunchTaskId(int taskId) { 1834 mLaunchTaskId = taskId; 1835 } 1836 1837 /** 1838 * @hide 1839 */ 1840 @SystemApi getLaunchTaskId()1841 public int getLaunchTaskId() { 1842 return mLaunchTaskId; 1843 } 1844 1845 /** 1846 * Sets whether recents disable showing starting window when activity launch. 1847 * @hide 1848 */ 1849 @RequiresPermission(START_TASKS_FROM_RECENTS) setDisableStartingWindow(boolean disable)1850 public void setDisableStartingWindow(boolean disable) { 1851 mDisableStartingWindow = disable; 1852 } 1853 1854 /** 1855 * @hide 1856 */ getDisableStartingWindow()1857 public boolean getDisableStartingWindow() { 1858 return mDisableStartingWindow; 1859 } 1860 1861 /** 1862 * Specifies intent flags to be applied for any activity started from a PendingIntent. 1863 * 1864 * @hide 1865 */ setPendingIntentLaunchFlags(@ndroid.content.Intent.Flags int flags)1866 public void setPendingIntentLaunchFlags(@android.content.Intent.Flags int flags) { 1867 mPendingIntentLaunchFlags = flags; 1868 } 1869 1870 /** 1871 * @hide 1872 */ getPendingIntentLaunchFlags()1873 public int getPendingIntentLaunchFlags() { 1874 // b/243794108: Ignore all flags except the new task flag, to be reconsidered in b/254490217 1875 return mPendingIntentLaunchFlags & 1876 (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_MULTIPLE_TASK | FLAG_RECEIVER_FOREGROUND); 1877 } 1878 1879 /** 1880 * Set's whether the task for the activity launched with this option should always be on top. 1881 * @hide 1882 */ 1883 @TestApi setTaskAlwaysOnTop(boolean alwaysOnTop)1884 public void setTaskAlwaysOnTop(boolean alwaysOnTop) { 1885 mTaskAlwaysOnTop = alwaysOnTop; 1886 } 1887 1888 /** 1889 * @hide 1890 */ getTaskAlwaysOnTop()1891 public boolean getTaskAlwaysOnTop() { 1892 return mTaskAlwaysOnTop; 1893 } 1894 1895 /** 1896 * Set's whether the activity launched with this option should be a task overlay. That is the 1897 * activity will always be the top activity of the task. 1898 * @param canResume {@code false} if the task will also not be moved to the front of the stack. 1899 * @hide 1900 */ 1901 @TestApi setTaskOverlay(boolean taskOverlay, boolean canResume)1902 public void setTaskOverlay(boolean taskOverlay, boolean canResume) { 1903 mTaskOverlay = taskOverlay; 1904 mTaskOverlayCanResume = canResume; 1905 } 1906 1907 /** 1908 * @hide 1909 */ getTaskOverlay()1910 public boolean getTaskOverlay() { 1911 return mTaskOverlay; 1912 } 1913 1914 /** 1915 * @hide 1916 */ canTaskOverlayResume()1917 public boolean canTaskOverlayResume() { 1918 return mTaskOverlayCanResume; 1919 } 1920 1921 /** 1922 * Sets whether the activity launched should not cause the activity stack it is contained in to 1923 * be moved to the front as a part of launching. 1924 * 1925 * @hide 1926 */ setAvoidMoveToFront()1927 public void setAvoidMoveToFront() { 1928 mAvoidMoveToFront = true; 1929 } 1930 1931 /** 1932 * @return whether the activity launch should prevent moving the associated activity stack to 1933 * the front. 1934 * @hide 1935 */ getAvoidMoveToFront()1936 public boolean getAvoidMoveToFront() { 1937 return mAvoidMoveToFront; 1938 } 1939 1940 /** 1941 * Sets whether the launch of this activity should freeze the recent task list reordering until 1942 * the next user interaction or timeout. This flag is only applied when starting an activity 1943 * in recents. 1944 * @hide 1945 */ setFreezeRecentTasksReordering()1946 public void setFreezeRecentTasksReordering() { 1947 mFreezeRecentTasksReordering = true; 1948 } 1949 1950 /** 1951 * @return whether the launch of this activity should freeze the recent task list reordering 1952 * @hide 1953 */ freezeRecentTasksReordering()1954 public boolean freezeRecentTasksReordering() { 1955 return mFreezeRecentTasksReordering; 1956 } 1957 1958 /** @hide */ 1959 @UnsupportedAppUsage setSplitScreenCreateMode(int splitScreenCreateMode)1960 public void setSplitScreenCreateMode(int splitScreenCreateMode) { 1961 // Remove this method after @UnsupportedAppUsage can be removed. 1962 } 1963 1964 /** @hide */ setDisallowEnterPictureInPictureWhileLaunching(boolean disallow)1965 public void setDisallowEnterPictureInPictureWhileLaunching(boolean disallow) { 1966 mDisallowEnterPictureInPictureWhileLaunching = disallow; 1967 } 1968 1969 /** @hide */ disallowEnterPictureInPictureWhileLaunching()1970 public boolean disallowEnterPictureInPictureWhileLaunching() { 1971 return mDisallowEnterPictureInPictureWhileLaunching; 1972 } 1973 1974 /** @hide */ setApplyActivityFlagsForBubbles(boolean apply)1975 public void setApplyActivityFlagsForBubbles(boolean apply) { 1976 mApplyActivityFlagsForBubbles = apply; 1977 } 1978 1979 /** @hide */ isApplyActivityFlagsForBubbles()1980 public boolean isApplyActivityFlagsForBubbles() { 1981 return mApplyActivityFlagsForBubbles; 1982 } 1983 1984 /** @hide */ setApplyMultipleTaskFlagForShortcut(boolean apply)1985 public void setApplyMultipleTaskFlagForShortcut(boolean apply) { 1986 mApplyMultipleTaskFlagForShortcut = apply; 1987 } 1988 1989 /** @hide */ isApplyMultipleTaskFlagForShortcut()1990 public boolean isApplyMultipleTaskFlagForShortcut() { 1991 return mApplyMultipleTaskFlagForShortcut; 1992 } 1993 1994 /** @hide */ setApplyNoUserActionFlagForShortcut(boolean apply)1995 public void setApplyNoUserActionFlagForShortcut(boolean apply) { 1996 mApplyNoUserActionFlagForShortcut = apply; 1997 } 1998 1999 /** @hide */ isApplyNoUserActionFlagForShortcut()2000 public boolean isApplyNoUserActionFlagForShortcut() { 2001 return mApplyNoUserActionFlagForShortcut; 2002 } 2003 2004 /** 2005 * An opaque token to use with {@link #setLaunchCookie(LaunchCookie)}. 2006 * 2007 * @hide 2008 */ 2009 @SuppressLint("UnflaggedApi") 2010 @TestApi 2011 public static final class LaunchCookie implements Parcelable { 2012 /** @hide */ 2013 public final IBinder binder; 2014 2015 /** @hide */ 2016 @SuppressLint("UnflaggedApi") 2017 @TestApi LaunchCookie()2018 public LaunchCookie() { 2019 binder = new Binder(); 2020 } 2021 2022 /** @hide */ LaunchCookie(@ullable String descriptor)2023 public LaunchCookie(@Nullable String descriptor) { 2024 binder = new Binder(descriptor); 2025 } 2026 LaunchCookie(IBinder binder)2027 private LaunchCookie(IBinder binder) { 2028 this.binder = binder; 2029 } 2030 2031 /** @hide */ 2032 @SuppressLint("UnflaggedApi") 2033 @TestApi 2034 @Override describeContents()2035 public int describeContents() { 2036 return 0; 2037 } 2038 2039 /** @hide */ 2040 @SuppressLint("UnflaggedApi") 2041 @TestApi 2042 @Override writeToParcel(@onNull Parcel dest, int flags)2043 public void writeToParcel(@NonNull Parcel dest, int flags) { 2044 dest.writeStrongBinder(binder); 2045 } 2046 2047 /** @hide */ readFromParcel(@onNull Parcel in)2048 public static LaunchCookie readFromParcel(@NonNull Parcel in) { 2049 IBinder binder = in.readStrongBinder(); 2050 if (binder == null) { 2051 return null; 2052 } 2053 return new LaunchCookie(binder); 2054 } 2055 2056 /** @hide */ writeToParcel(@ullable LaunchCookie launchCookie, Parcel out)2057 public static void writeToParcel(@Nullable LaunchCookie launchCookie, Parcel out) { 2058 if (launchCookie != null) { 2059 launchCookie.writeToParcel(out, 0); 2060 } else { 2061 out.writeStrongBinder(null); 2062 } 2063 } 2064 2065 /** @hide */ 2066 @SuppressLint("UnflaggedApi") 2067 @TestApi 2068 @NonNull 2069 public static final Parcelable.Creator<LaunchCookie> CREATOR = 2070 new Parcelable.Creator<LaunchCookie>() { 2071 2072 @Override 2073 public LaunchCookie createFromParcel(Parcel source) { 2074 return LaunchCookie.readFromParcel(source); 2075 } 2076 2077 @Override 2078 public LaunchCookie[] newArray(int size) { 2079 return new LaunchCookie[size]; 2080 } 2081 }; 2082 2083 @Override equals(@ullable Object obj)2084 public boolean equals(@Nullable Object obj) { 2085 if (obj instanceof LaunchCookie) { 2086 LaunchCookie other = (LaunchCookie) obj; 2087 return binder == other.binder; 2088 } 2089 return false; 2090 } 2091 2092 @Override hashCode()2093 public int hashCode() { 2094 return binder.hashCode(); 2095 } 2096 } 2097 2098 /** 2099 * Sets a launch cookie that can be used to track the {@link Activity} and task that are 2100 * launched as a result of this option. If the launched activity is a trampoline that starts 2101 * another activity immediately, the cookie will be transferred to the next activity. 2102 * 2103 * @param launchCookie a developer specified identifier for a specific task. 2104 * 2105 * @hide 2106 */ 2107 @SuppressLint("UnflaggedApi") 2108 @TestApi setLaunchCookie(@onNull LaunchCookie launchCookie)2109 public void setLaunchCookie(@NonNull LaunchCookie launchCookie) { 2110 setLaunchCookie(launchCookie.binder); 2111 } 2112 2113 /** 2114 * Sets a launch cookie that can be used to track the activity and task that are launch as a 2115 * result of this option. If the launched activity is a trampoline that starts another activity 2116 * immediately, the cookie will be transferred to the next activity. 2117 * 2118 * @hide 2119 */ setLaunchCookie(IBinder launchCookie)2120 public void setLaunchCookie(IBinder launchCookie) { 2121 mLaunchCookie = launchCookie; 2122 } 2123 2124 /** 2125 * @return The launch tracking cookie if set or {@code null} otherwise. 2126 * 2127 * @hide 2128 */ getLaunchCookie()2129 public IBinder getLaunchCookie() { 2130 return mLaunchCookie; 2131 } 2132 2133 2134 /** @hide */ getOverrideTaskTransition()2135 public boolean getOverrideTaskTransition() { 2136 return mOverrideTaskTransition; 2137 } 2138 2139 /** 2140 * Sets whether to remove the task when TaskOrganizer, which is managing it, is destroyed. 2141 * @hide 2142 */ setRemoveWithTaskOrganizer(boolean remove)2143 public void setRemoveWithTaskOrganizer(boolean remove) { 2144 mRemoveWithTaskOrganizer = remove; 2145 } 2146 2147 /** 2148 * @return whether to remove the task when TaskOrganizer, which is managing it, is destroyed. 2149 * @hide 2150 */ getRemoveWithTaskOranizer()2151 public boolean getRemoveWithTaskOranizer() { 2152 return mRemoveWithTaskOrganizer; 2153 } 2154 2155 /** 2156 * Sets whether this activity is launched from a bubble. 2157 * @hide 2158 */ 2159 @TestApi setLaunchedFromBubble(boolean fromBubble)2160 public void setLaunchedFromBubble(boolean fromBubble) { 2161 mLaunchedFromBubble = fromBubble; 2162 } 2163 2164 /** 2165 * @return whether the activity was launched from a bubble. 2166 * @hide 2167 */ getLaunchedFromBubble()2168 public boolean getLaunchedFromBubble() { 2169 return mLaunchedFromBubble; 2170 } 2171 2172 /** 2173 * Sets whether the activity launch is part of a transient operation. If it is, it will not 2174 * cause lifecycle changes in existing activities even if it were to occlude them (ie. other 2175 * activities occluded by this one will not be paused or stopped until the launch is committed). 2176 * As a consequence, it will start immediately since it doesn't need to wait for other 2177 * lifecycles to evolve. Current user is recents. 2178 * @hide 2179 */ setTransientLaunch()2180 public ActivityOptions setTransientLaunch() { 2181 mTransientLaunch = true; 2182 return this; 2183 } 2184 2185 /** 2186 * @see #setTransientLaunch() 2187 * @return whether the activity launch is part of a transient operation. 2188 * @hide 2189 */ getTransientLaunch()2190 public boolean getTransientLaunch() { 2191 return mTransientLaunch; 2192 } 2193 2194 /** 2195 * Sets whether the insecure keyguard should go away when this activity launches. In case the 2196 * keyguard is secure, this option will be ignored. 2197 * 2198 * @see Activity#setShowWhenLocked(boolean) 2199 * @see android.R.attr#showWhenLocked 2200 * @hide 2201 */ setDismissKeyguardIfInsecure()2202 public void setDismissKeyguardIfInsecure() { 2203 mDismissKeyguardIfInsecure = true; 2204 } 2205 2206 /** 2207 * @see #setDismissKeyguardIfInsecure() 2208 * @return whether the insecure keyguard should go away when the activity launches. 2209 * @hide 2210 */ getDismissKeyguardIfInsecure()2211 public boolean getDismissKeyguardIfInsecure() { 2212 return mDismissKeyguardIfInsecure; 2213 } 2214 2215 /** 2216 * Allow a {@link PendingIntent} to use the privilege of its creator to start background 2217 * activities. 2218 * 2219 * @param mode the mode being set 2220 */ 2221 @NonNull setPendingIntentCreatorBackgroundActivityStartMode( @ackgroundActivityStartMode int mode)2222 public ActivityOptions setPendingIntentCreatorBackgroundActivityStartMode( 2223 @BackgroundActivityStartMode int mode) { 2224 mPendingIntentCreatorBackgroundActivityStartMode = mode; 2225 return this; 2226 } 2227 2228 /** 2229 * Returns the mode to start background activities granted by the creator of the 2230 * {@link PendingIntent}. 2231 * 2232 * @return the mode currently set 2233 */ getPendingIntentCreatorBackgroundActivityStartMode()2234 public @BackgroundActivityStartMode int getPendingIntentCreatorBackgroundActivityStartMode() { 2235 return mPendingIntentCreatorBackgroundActivityStartMode; 2236 } 2237 2238 /** 2239 * Update the current values in this ActivityOptions from those supplied 2240 * in <var>otherOptions</var>. Any values 2241 * defined in <var>otherOptions</var> replace those in the base options. 2242 */ update(ActivityOptions otherOptions)2243 public void update(ActivityOptions otherOptions) { 2244 if (otherOptions.mPackageName != null) { 2245 mPackageName = otherOptions.mPackageName; 2246 } 2247 mUsageTimeReport = otherOptions.mUsageTimeReport; 2248 mSceneTransitionInfo = null; 2249 mAnimationType = otherOptions.mAnimationType; 2250 switch (otherOptions.mAnimationType) { 2251 case ANIM_CUSTOM: 2252 mCustomEnterResId = otherOptions.mCustomEnterResId; 2253 mCustomExitResId = otherOptions.mCustomExitResId; 2254 mCustomBackgroundColor = otherOptions.mCustomBackgroundColor; 2255 mThumbnail = null; 2256 sendResultIgnoreErrors(mAnimationStartedListener, null); 2257 mAnimationStartedListener = otherOptions.mAnimationStartedListener; 2258 break; 2259 case ANIM_CUSTOM_IN_PLACE: 2260 mCustomInPlaceResId = otherOptions.mCustomInPlaceResId; 2261 break; 2262 case ANIM_SCALE_UP: 2263 mStartX = otherOptions.mStartX; 2264 mStartY = otherOptions.mStartY; 2265 mWidth = otherOptions.mWidth; 2266 mHeight = otherOptions.mHeight; 2267 sendResultIgnoreErrors(mAnimationStartedListener, null); 2268 mAnimationStartedListener = null; 2269 break; 2270 case ANIM_THUMBNAIL_SCALE_UP: 2271 case ANIM_THUMBNAIL_SCALE_DOWN: 2272 case ANIM_THUMBNAIL_ASPECT_SCALE_UP: 2273 case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN: 2274 mThumbnail = otherOptions.mThumbnail; 2275 mStartX = otherOptions.mStartX; 2276 mStartY = otherOptions.mStartY; 2277 mWidth = otherOptions.mWidth; 2278 mHeight = otherOptions.mHeight; 2279 sendResultIgnoreErrors(mAnimationStartedListener, null); 2280 mAnimationStartedListener = otherOptions.mAnimationStartedListener; 2281 break; 2282 case ANIM_SCENE_TRANSITION: 2283 mSceneTransitionInfo = otherOptions.mSceneTransitionInfo; 2284 mThumbnail = null; 2285 mAnimationStartedListener = null; 2286 break; 2287 } 2288 mLockTaskMode = otherOptions.mLockTaskMode; 2289 mShareIdentity = otherOptions.mShareIdentity; 2290 mAnimSpecs = otherOptions.mAnimSpecs; 2291 mAnimationFinishedListener = otherOptions.mAnimationFinishedListener; 2292 mSpecsFuture = otherOptions.mSpecsFuture; 2293 mRemoteAnimationAdapter = otherOptions.mRemoteAnimationAdapter; 2294 mLaunchIntoPipParams = otherOptions.mLaunchIntoPipParams; 2295 mIsEligibleForLegacyPermissionPrompt = otherOptions.mIsEligibleForLegacyPermissionPrompt; 2296 2297 sendResultIgnoreErrors(mAnimationAbortListener, null); 2298 mAnimationAbortListener = otherOptions.mAnimationAbortListener; 2299 } 2300 2301 /** 2302 * Returns the created options as a Bundle, which can be passed to 2303 * {@link android.content.Context#startActivity(android.content.Intent, android.os.Bundle) 2304 * Context.startActivity(Intent, Bundle)} and related methods. 2305 * Note that the returned Bundle is still owned by the ActivityOptions 2306 * object; you must not modify it, but can supply it to the startActivity 2307 * methods that take an options Bundle. 2308 */ 2309 @Override toBundle()2310 public Bundle toBundle() { 2311 Bundle b = super.toBundle(); 2312 if (mPackageName != null) { 2313 b.putString(KEY_PACKAGE_NAME, mPackageName); 2314 } 2315 if (mLaunchBounds != null) { 2316 b.putParcelable(KEY_LAUNCH_BOUNDS, mLaunchBounds); 2317 } 2318 if (mAnimationType != ANIM_UNDEFINED) { 2319 b.putInt(KEY_ANIM_TYPE, mAnimationType); 2320 } 2321 if (mUsageTimeReport != null) { 2322 b.putParcelable(KEY_USAGE_TIME_REPORT, mUsageTimeReport); 2323 } 2324 switch (mAnimationType) { 2325 case ANIM_CUSTOM: 2326 b.putInt(KEY_ANIM_ENTER_RES_ID, mCustomEnterResId); 2327 b.putInt(KEY_ANIM_EXIT_RES_ID, mCustomExitResId); 2328 b.putInt(KEY_ANIM_BACKGROUND_COLOR, mCustomBackgroundColor); 2329 b.putBinder(KEY_ANIM_START_LISTENER, mAnimationStartedListener 2330 != null ? mAnimationStartedListener.asBinder() : null); 2331 break; 2332 case ANIM_CUSTOM_IN_PLACE: 2333 b.putInt(KEY_ANIM_IN_PLACE_RES_ID, mCustomInPlaceResId); 2334 break; 2335 case ANIM_SCALE_UP: 2336 case ANIM_CLIP_REVEAL: 2337 b.putInt(KEY_ANIM_START_X, mStartX); 2338 b.putInt(KEY_ANIM_START_Y, mStartY); 2339 b.putInt(KEY_ANIM_WIDTH, mWidth); 2340 b.putInt(KEY_ANIM_HEIGHT, mHeight); 2341 break; 2342 case ANIM_THUMBNAIL_SCALE_UP: 2343 case ANIM_THUMBNAIL_SCALE_DOWN: 2344 case ANIM_THUMBNAIL_ASPECT_SCALE_UP: 2345 case ANIM_THUMBNAIL_ASPECT_SCALE_DOWN: 2346 // Once we parcel the thumbnail for transfering over to the system, create a copy of 2347 // the bitmap to a hardware bitmap and pass through the HardwareBuffer 2348 if (mThumbnail != null) { 2349 final Bitmap hwBitmap = mThumbnail.copy(Config.HARDWARE, false /* isMutable */); 2350 if (hwBitmap != null) { 2351 b.putParcelable(KEY_ANIM_THUMBNAIL, hwBitmap.getHardwareBuffer()); 2352 } else { 2353 Slog.w(TAG, "Failed to copy thumbnail"); 2354 } 2355 } 2356 b.putInt(KEY_ANIM_START_X, mStartX); 2357 b.putInt(KEY_ANIM_START_Y, mStartY); 2358 b.putInt(KEY_ANIM_WIDTH, mWidth); 2359 b.putInt(KEY_ANIM_HEIGHT, mHeight); 2360 b.putBinder(KEY_ANIM_START_LISTENER, mAnimationStartedListener 2361 != null ? mAnimationStartedListener.asBinder() : null); 2362 break; 2363 case ANIM_SCENE_TRANSITION: 2364 if (mSceneTransitionInfo != null) { 2365 b.putParcelable(KEY_SCENE_TRANSITION_INFO, mSceneTransitionInfo); 2366 } 2367 break; 2368 } 2369 if (mLockTaskMode) { 2370 b.putBoolean(KEY_LOCK_TASK_MODE, mLockTaskMode); 2371 } 2372 if (mShareIdentity) { 2373 b.putBoolean(KEY_SHARE_IDENTITY, mShareIdentity); 2374 } 2375 if (mLaunchDisplayId != INVALID_DISPLAY) { 2376 b.putInt(KEY_LAUNCH_DISPLAY_ID, mLaunchDisplayId); 2377 } 2378 if (mCallerDisplayId != INVALID_DISPLAY) { 2379 b.putInt(KEY_CALLER_DISPLAY_ID, mCallerDisplayId); 2380 } 2381 if (mLaunchTaskDisplayArea != null) { 2382 b.putParcelable(KEY_LAUNCH_TASK_DISPLAY_AREA_TOKEN, mLaunchTaskDisplayArea); 2383 } 2384 if (mLaunchTaskDisplayAreaFeatureId != FEATURE_UNDEFINED) { 2385 b.putInt(KEY_LAUNCH_TASK_DISPLAY_AREA_FEATURE_ID, mLaunchTaskDisplayAreaFeatureId); 2386 } 2387 if (mLaunchRootTask != null) { 2388 b.putParcelable(KEY_LAUNCH_ROOT_TASK_TOKEN, mLaunchRootTask); 2389 } 2390 if (mLaunchTaskFragmentToken != null) { 2391 b.putBinder(KEY_LAUNCH_TASK_FRAGMENT_TOKEN, mLaunchTaskFragmentToken); 2392 } 2393 if (mLaunchWindowingMode != WINDOWING_MODE_UNDEFINED) { 2394 b.putInt(KEY_LAUNCH_WINDOWING_MODE, mLaunchWindowingMode); 2395 } 2396 if (mLaunchActivityType != ACTIVITY_TYPE_UNDEFINED) { 2397 b.putInt(KEY_LAUNCH_ACTIVITY_TYPE, mLaunchActivityType); 2398 } 2399 if (mLaunchTaskId != -1) { 2400 b.putInt(KEY_LAUNCH_TASK_ID, mLaunchTaskId); 2401 } 2402 if (mPendingIntentLaunchFlags != 0) { 2403 b.putInt(KEY_PENDING_INTENT_LAUNCH_FLAGS, mPendingIntentLaunchFlags); 2404 } 2405 if (mTaskAlwaysOnTop) { 2406 b.putBoolean(KEY_TASK_ALWAYS_ON_TOP, mTaskAlwaysOnTop); 2407 } 2408 if (mTaskOverlay) { 2409 b.putBoolean(KEY_TASK_OVERLAY, mTaskOverlay); 2410 } 2411 if (mTaskOverlayCanResume) { 2412 b.putBoolean(KEY_TASK_OVERLAY_CAN_RESUME, mTaskOverlayCanResume); 2413 } 2414 if (mAvoidMoveToFront) { 2415 b.putBoolean(KEY_AVOID_MOVE_TO_FRONT, mAvoidMoveToFront); 2416 } 2417 if (mFreezeRecentTasksReordering) { 2418 b.putBoolean(KEY_FREEZE_RECENT_TASKS_REORDERING, mFreezeRecentTasksReordering); 2419 } 2420 if (mDisallowEnterPictureInPictureWhileLaunching) { 2421 b.putBoolean(KEY_DISALLOW_ENTER_PICTURE_IN_PICTURE_WHILE_LAUNCHING, 2422 mDisallowEnterPictureInPictureWhileLaunching); 2423 } 2424 if (mApplyActivityFlagsForBubbles) { 2425 b.putBoolean(KEY_APPLY_ACTIVITY_FLAGS_FOR_BUBBLES, mApplyActivityFlagsForBubbles); 2426 } 2427 if (mApplyMultipleTaskFlagForShortcut) { 2428 b.putBoolean(KEY_APPLY_MULTIPLE_TASK_FLAG_FOR_SHORTCUT, 2429 mApplyMultipleTaskFlagForShortcut); 2430 } 2431 if (mApplyNoUserActionFlagForShortcut) { 2432 b.putBoolean(KEY_APPLY_NO_USER_ACTION_FLAG_FOR_SHORTCUT, true); 2433 } 2434 if (mAnimSpecs != null) { 2435 b.putParcelableArray(KEY_ANIM_SPECS, mAnimSpecs); 2436 } 2437 if (mAnimationFinishedListener != null) { 2438 b.putBinder(KEY_ANIMATION_FINISHED_LISTENER, mAnimationFinishedListener.asBinder()); 2439 } 2440 if (mSpecsFuture != null) { 2441 b.putBinder(KEY_SPECS_FUTURE, mSpecsFuture.asBinder()); 2442 } 2443 if (mSourceInfo != null) { 2444 b.putParcelable(KEY_SOURCE_INFO, mSourceInfo); 2445 } 2446 if (mRotationAnimationHint != -1) { 2447 b.putInt(KEY_ROTATION_ANIMATION_HINT, mRotationAnimationHint); 2448 } 2449 if (mAppVerificationBundle != null) { 2450 b.putBundle(KEY_INSTANT_APP_VERIFICATION_BUNDLE, mAppVerificationBundle); 2451 } 2452 if (mRemoteAnimationAdapter != null) { 2453 b.putParcelable(KEY_REMOTE_ANIMATION_ADAPTER, mRemoteAnimationAdapter); 2454 } 2455 if (mLaunchCookie != null) { 2456 b.putBinder(KEY_LAUNCH_COOKIE, mLaunchCookie); 2457 } 2458 if (mRemoteTransition != null) { 2459 b.putParcelable(KEY_REMOTE_TRANSITION, mRemoteTransition); 2460 } 2461 if (mOverrideTaskTransition) { 2462 b.putBoolean(KEY_OVERRIDE_TASK_TRANSITION, mOverrideTaskTransition); 2463 } 2464 if (mSplashScreenThemeResName != null && !mSplashScreenThemeResName.isEmpty()) { 2465 b.putString(KEY_SPLASH_SCREEN_THEME, mSplashScreenThemeResName); 2466 } 2467 if (mRemoveWithTaskOrganizer) { 2468 b.putBoolean(KEY_REMOVE_WITH_TASK_ORGANIZER, mRemoveWithTaskOrganizer); 2469 } 2470 if (mLaunchedFromBubble) { 2471 b.putBoolean(KEY_LAUNCHED_FROM_BUBBLE, mLaunchedFromBubble); 2472 } 2473 if (mTransientLaunch) { 2474 b.putBoolean(KEY_TRANSIENT_LAUNCH, mTransientLaunch); 2475 } 2476 if (mSplashScreenStyle != 0) { 2477 b.putInt(KEY_SPLASH_SCREEN_STYLE, mSplashScreenStyle); 2478 } 2479 if (mLaunchIntoPipParams != null) { 2480 b.putParcelable(KEY_LAUNCH_INTO_PIP_PARAMS, mLaunchIntoPipParams); 2481 } 2482 if (mIsEligibleForLegacyPermissionPrompt) { 2483 b.putBoolean(KEY_LEGACY_PERMISSION_PROMPT_ELIGIBLE, 2484 mIsEligibleForLegacyPermissionPrompt); 2485 } 2486 if (mDismissKeyguardIfInsecure) { 2487 b.putBoolean(KEY_DISMISS_KEYGUARD_IF_INSECURE, mDismissKeyguardIfInsecure); 2488 } 2489 if (mPendingIntentCreatorBackgroundActivityStartMode 2490 != MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED) { 2491 b.putInt(KEY_PENDING_INTENT_CREATOR_BACKGROUND_ACTIVITY_START_MODE, 2492 mPendingIntentCreatorBackgroundActivityStartMode); 2493 } 2494 if (mDisableStartingWindow) { 2495 b.putBoolean(KEY_DISABLE_STARTING_WINDOW, mDisableStartingWindow); 2496 } 2497 b.putBinder(KEY_ANIM_ABORT_LISTENER, 2498 mAnimationAbortListener != null ? mAnimationAbortListener.asBinder() : null); 2499 return b; 2500 } 2501 2502 /** 2503 * Ask the system track that time the user spends in the app being launched, and 2504 * report it back once done. The report will be sent to the given receiver, with 2505 * the extras {@link #EXTRA_USAGE_TIME_REPORT} and {@link #EXTRA_USAGE_TIME_REPORT_PACKAGES} 2506 * filled in. 2507 * 2508 * <p>The time interval tracked is from launching this activity until the user leaves 2509 * that activity's flow. They are considered to stay in the flow as long as 2510 * new activities are being launched or returned to from the original flow, 2511 * even if this crosses package or task boundaries. For example, if the originator 2512 * starts an activity to view an image, and while there the user selects to share, 2513 * which launches their email app in a new task, and they complete the share, the 2514 * time during that entire operation will be included until they finally hit back from 2515 * the original image viewer activity.</p> 2516 * 2517 * <p>The user is considered to complete a flow once they switch to another 2518 * activity that is not part of the tracked flow. This may happen, for example, by 2519 * using the notification shade, launcher, or recents to launch or switch to another 2520 * app. Simply going in to these navigation elements does not break the flow (although 2521 * the launcher and recents stops time tracking of the session); it is the act of 2522 * going somewhere else that completes the tracking.</p> 2523 * 2524 * @param receiver A broadcast receiver that willl receive the report. 2525 */ requestUsageTimeReport(PendingIntent receiver)2526 public void requestUsageTimeReport(PendingIntent receiver) { 2527 mUsageTimeReport = receiver; 2528 } 2529 2530 /** 2531 * Returns the launch source information set by {@link #setSourceInfo}. 2532 * @hide 2533 */ getSourceInfo()2534 public @Nullable SourceInfo getSourceInfo() { 2535 return mSourceInfo; 2536 } 2537 2538 /** 2539 * Sets the source information of the launch event. 2540 * 2541 * @param type The type of the startup source. 2542 * @param uptimeMillis The event time of startup source in milliseconds since boot, not 2543 * including sleep (e.g. from {@link android.view.MotionEvent#getEventTime} 2544 * or {@link android.os.SystemClock#uptimeMillis}). 2545 * @see SourceInfo 2546 * @hide 2547 */ setSourceInfo(@ourceInfo.SourceType int type, long uptimeMillis)2548 public void setSourceInfo(@SourceInfo.SourceType int type, long uptimeMillis) { 2549 mSourceInfo = new SourceInfo(type, uptimeMillis); 2550 } 2551 2552 /** 2553 * Return the filtered options only meant to be seen by the target activity itself 2554 * @hide 2555 */ forTargetActivity()2556 public ActivityOptions forTargetActivity() { 2557 if (mAnimationType == ANIM_SCENE_TRANSITION) { 2558 final ActivityOptions result = new ActivityOptions(); 2559 result.update(this); 2560 return result; 2561 } 2562 2563 return null; 2564 } 2565 2566 /** 2567 * Returns the rotation animation set by {@link setRotationAnimationHint} or -1 2568 * if unspecified. 2569 * @hide 2570 */ getRotationAnimationHint()2571 public int getRotationAnimationHint() { 2572 return mRotationAnimationHint; 2573 } 2574 2575 2576 /** 2577 * Set a rotation animation to be used if launching the activity 2578 * triggers an orientation change, or -1 to clear. See 2579 * {@link android.view.WindowManager.LayoutParams} for rotation 2580 * animation values. 2581 * @hide 2582 */ setRotationAnimationHint(int hint)2583 public void setRotationAnimationHint(int hint) { 2584 mRotationAnimationHint = hint; 2585 } 2586 2587 /** 2588 * Pop the extra verification bundle for the installer. 2589 * This removes the bundle from the ActivityOptions to make sure the installer bundle 2590 * is only available once. 2591 * @hide 2592 */ popAppVerificationBundle()2593 public Bundle popAppVerificationBundle() { 2594 Bundle out = mAppVerificationBundle; 2595 mAppVerificationBundle = null; 2596 return out; 2597 } 2598 2599 /** 2600 * Set the {@link Bundle} that is provided to the app installer for additional verification 2601 * if the call to {@link Context#startActivity} results in an app being installed. 2602 * 2603 * This Bundle is not provided to any other app besides the installer. 2604 */ setAppVerificationBundle(Bundle bundle)2605 public ActivityOptions setAppVerificationBundle(Bundle bundle) { 2606 mAppVerificationBundle = bundle; 2607 return this; 2608 2609 } 2610 2611 /** 2612 * Sets the mode for allowing or denying the senders privileges to start background activities 2613 * to the PendingIntent. 2614 * 2615 * This is typically used in when executing {@link PendingIntent#send(Context, int, Intent, 2616 * PendingIntent.OnFinished, Handler, String, Bundle)} or similar 2617 * methods. A privileged sender of a PendingIntent should only grant 2618 * {@link #MODE_BACKGROUND_ACTIVITY_START_ALLOWED} if the PendingIntent is from a trusted source 2619 * and/or executed on behalf the user. 2620 */ setPendingIntentBackgroundActivityStartMode( @ackgroundActivityStartMode int state)2621 public @NonNull ActivityOptions setPendingIntentBackgroundActivityStartMode( 2622 @BackgroundActivityStartMode int state) { 2623 super.setPendingIntentBackgroundActivityStartMode(state); 2624 return this; 2625 } 2626 2627 /** 2628 * Get the mode for allowing or denying the senders privileges to start background activities 2629 * to the PendingIntent. 2630 * 2631 * @see #setPendingIntentBackgroundActivityStartMode(int) 2632 */ getPendingIntentBackgroundActivityStartMode()2633 public @BackgroundActivityStartMode int getPendingIntentBackgroundActivityStartMode() { 2634 return super.getPendingIntentBackgroundActivityStartMode(); 2635 } 2636 2637 /** 2638 * Set PendingIntent activity is allowed to be started in the background if the caller 2639 * can start background activities. 2640 * 2641 * @deprecated use #setPendingIntentBackgroundActivityStartMode(int) to set the full range 2642 * of states 2643 */ 2644 @Override setPendingIntentBackgroundActivityLaunchAllowed(boolean allowed)2645 @Deprecated public void setPendingIntentBackgroundActivityLaunchAllowed(boolean allowed) { 2646 super.setPendingIntentBackgroundActivityLaunchAllowed(allowed); 2647 } 2648 2649 /** 2650 * Get PendingIntent activity is allowed to be started in the background if the caller can start 2651 * background activities. 2652 * 2653 * @deprecated use {@link #getPendingIntentBackgroundActivityStartMode()} since for apps 2654 * targeting {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} or higher this value might 2655 * not match the actual behavior if the value was not explicitly set. 2656 */ isPendingIntentBackgroundActivityLaunchAllowed()2657 @Deprecated public boolean isPendingIntentBackgroundActivityLaunchAllowed() { 2658 return super.isPendingIntentBackgroundActivityLaunchAllowed(); 2659 } 2660 2661 /** @hide */ 2662 @Override toString()2663 public String toString() { 2664 return "ActivityOptions(" + hashCode() + "), mPackageName=" + mPackageName 2665 + ", mAnimationType=" + mAnimationType + ", mStartX=" + mStartX + ", mStartY=" 2666 + mStartY + ", mWidth=" + mWidth + ", mHeight=" + mHeight + ", mLaunchDisplayId=" 2667 + mLaunchDisplayId; 2668 } 2669 2670 /** 2671 * The information about the source of activity launch. E.g. describe an activity is launched 2672 * from launcher by receiving a motion event with a timestamp. 2673 * @hide 2674 */ 2675 public static class SourceInfo implements Parcelable { 2676 /** Launched from launcher. */ 2677 public static final int TYPE_LAUNCHER = 1; 2678 /** Launched from notification. */ 2679 public static final int TYPE_NOTIFICATION = 2; 2680 /** Launched from lockscreen, including notification while the device is locked. */ 2681 public static final int TYPE_LOCKSCREEN = 3; 2682 /** Launched from recents gesture handler. */ 2683 public static final int TYPE_RECENTS_ANIMATION = 4; 2684 /** Launched from desktop's transition handler. */ 2685 public static final int TYPE_DESKTOP_ANIMATION = 5; 2686 2687 @IntDef(prefix = { "TYPE_" }, value = { 2688 TYPE_LAUNCHER, 2689 TYPE_NOTIFICATION, 2690 TYPE_LOCKSCREEN, 2691 TYPE_DESKTOP_ANIMATION 2692 }) 2693 @Retention(RetentionPolicy.SOURCE) 2694 public @interface SourceType {} 2695 2696 /** The type of the startup source. */ 2697 public final @SourceType int type; 2698 2699 /** The timestamp (uptime based) of the source to launch activity. */ 2700 public final long eventTimeMs; 2701 SourceInfo(@ourceType int srcType, long uptimeMillis)2702 SourceInfo(@SourceType int srcType, long uptimeMillis) { 2703 type = srcType; 2704 eventTimeMs = uptimeMillis; 2705 } 2706 2707 @Override writeToParcel(Parcel dest, int flags)2708 public void writeToParcel(Parcel dest, int flags) { 2709 dest.writeInt(type); 2710 dest.writeLong(eventTimeMs); 2711 } 2712 2713 @Override describeContents()2714 public int describeContents() { 2715 return 0; 2716 } 2717 2718 public static final Creator<SourceInfo> CREATOR = new Creator<SourceInfo>() { 2719 public SourceInfo createFromParcel(Parcel in) { 2720 return new SourceInfo(in.readInt(), in.readLong()); 2721 } 2722 2723 public SourceInfo[] newArray(int size) { 2724 return new SourceInfo[size]; 2725 } 2726 }; 2727 } 2728 2729 /** 2730 * This class contains necessary information for Activity Scene Transition. 2731 * 2732 * @hide 2733 */ 2734 public static class SceneTransitionInfo implements Parcelable { 2735 private boolean mIsReturning; 2736 private int mResultCode; 2737 @Nullable 2738 private Intent mResultData; 2739 @Nullable 2740 private ArrayList<String> mSharedElementNames; 2741 @Nullable 2742 private ResultReceiver mResultReceiver; 2743 private int mExitCoordinatorIndex; 2744 SceneTransitionInfo()2745 public SceneTransitionInfo() { 2746 } 2747 SceneTransitionInfo(Parcel in)2748 SceneTransitionInfo(Parcel in) { 2749 mIsReturning = in.readBoolean(); 2750 mResultCode = in.readInt(); 2751 mResultData = in.readTypedObject(Intent.CREATOR); 2752 mSharedElementNames = in.createStringArrayList(); 2753 mResultReceiver = in.readTypedObject(ResultReceiver.CREATOR); 2754 mExitCoordinatorIndex = in.readInt(); 2755 } 2756 2757 public static final Creator<SceneTransitionInfo> CREATOR = new Creator<>() { 2758 @Override 2759 public SceneTransitionInfo createFromParcel(Parcel in) { 2760 return new SceneTransitionInfo(in); 2761 } 2762 2763 @Override 2764 public SceneTransitionInfo[] newArray(int size) { 2765 return new SceneTransitionInfo[size]; 2766 } 2767 }; 2768 2769 @Override describeContents()2770 public int describeContents() { 2771 return 0; 2772 } 2773 2774 @Override writeToParcel(Parcel dest, int flags)2775 public void writeToParcel(Parcel dest, int flags) { 2776 dest.writeBoolean(mIsReturning); 2777 dest.writeInt(mResultCode); 2778 dest.writeTypedObject(mResultData, flags); 2779 dest.writeStringList(mSharedElementNames); 2780 dest.writeTypedObject(mResultReceiver, flags); 2781 dest.writeInt(mExitCoordinatorIndex); 2782 } 2783 setReturning(boolean isReturning)2784 public void setReturning(boolean isReturning) { 2785 mIsReturning = isReturning; 2786 } 2787 isReturning()2788 public boolean isReturning() { 2789 return mIsReturning; 2790 } 2791 setResultCode(int resultCode)2792 public void setResultCode(int resultCode) { 2793 mResultCode = resultCode; 2794 } 2795 getResultCode()2796 public int getResultCode() { 2797 return mResultCode; 2798 } 2799 setResultData(Intent resultData)2800 public void setResultData(Intent resultData) { 2801 mResultData = resultData; 2802 } 2803 2804 @Nullable getResultData()2805 public Intent getResultData() { 2806 return mResultData; 2807 } 2808 setSharedElementNames(ArrayList<String> sharedElementNames)2809 public void setSharedElementNames(ArrayList<String> sharedElementNames) { 2810 mSharedElementNames = sharedElementNames; 2811 } 2812 2813 @Nullable getSharedElementNames()2814 public ArrayList<String> getSharedElementNames() { 2815 return mSharedElementNames; 2816 } 2817 setResultReceiver(ResultReceiver resultReceiver)2818 public void setResultReceiver(ResultReceiver resultReceiver) { 2819 mResultReceiver = resultReceiver; 2820 } 2821 2822 @Nullable getResultReceiver()2823 public ResultReceiver getResultReceiver() { 2824 return mResultReceiver; 2825 } 2826 setExitCoordinatorKey(int exitCoordinatorKey)2827 public void setExitCoordinatorKey(int exitCoordinatorKey) { 2828 mExitCoordinatorIndex = exitCoordinatorKey; 2829 } 2830 getExitCoordinatorKey()2831 public int getExitCoordinatorKey() { 2832 return mExitCoordinatorIndex; 2833 } 2834 isCrossTask()2835 boolean isCrossTask() { 2836 return mExitCoordinatorIndex < 0; 2837 } 2838 2839 @Override toString()2840 public String toString() { 2841 return "SceneTransitionInfo, mIsReturning=" + mIsReturning 2842 + ", mResultCode=" + mResultCode + ", mResultData=" + mResultData 2843 + ", mSharedElementNames=" + mSharedElementNames 2844 + ", mTransitionReceiver=" + mResultReceiver 2845 + ", mExitCoordinatorIndex=" + mExitCoordinatorIndex; 2846 } 2847 } 2848 } 2849