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