Debian Codegraph @

core/java/android/app/ActivityOptions.java

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