summaryrefslogtreecommitdiff
path: root/core/java/android/app/ActivityOptions.java
diff options
context:
space:
mode:
authorJorim Jaggi <jjaggi@google.com>2017-05-12 17:27:46 +0200
committerJorim Jaggi <jjaggi@google.com>2017-05-16 17:28:40 +0200
commit34795e31971b5495fcf91c1063dcb689957e2c9f (patch)
treeaee6b195a3a7db927a458eea6183b78120868df9 /core/java/android/app/ActivityOptions.java
parentdc9385aad49bf2ba24c1221a5d4558a1ac69f97a (diff)
Optimize hot launching recents
Rearrange how we generate the transition specs, which involves creating a thumbnail on the mainthread (about 10ms on large devices): First, we put launching the activity onto a handler thread (with default priority), to free up the main thread. Then, we immediately start generating the thumbnail such that when the future calls us we have the generated spec already handy. For that we need to be able to supply a specs future into ActivityOptions, to avoid race conditions. Furthermore we need to make sure not to call into WM while creating specs, to avoid WM lock contention. Test: App -> Recents -> Same app, inspect app transition logs Test: Double tap recents for quick switching Bug: 32668632 Change-Id: I6001e29145f8e56deb9c4ead46c53c87c9191436 Merged-In: Ic6ec65c2560f67cade3b5ddde9f79ee13e9ba32c
Diffstat (limited to 'core/java/android/app/ActivityOptions.java')
-rw-r--r--core/java/android/app/ActivityOptions.java75
1 files changed, 30 insertions, 45 deletions
diff --git a/core/java/android/app/ActivityOptions.java b/core/java/android/app/ActivityOptions.java
index 3eec596fcb17..53608fbdd4bb 100644
--- a/core/java/android/app/ActivityOptions.java
+++ b/core/java/android/app/ActivityOptions.java
@@ -38,6 +38,7 @@ import android.transition.TransitionManager;
import android.util.Pair;
import android.util.Slog;
import android.view.AppTransitionAnimationSpec;
+import android.view.IAppTransitionAnimationSpecsFuture;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
@@ -213,6 +214,7 @@ public class ActivityOptions {
private static final String KEY_INSTANT_APP_VERIFICATION_BUNDLE
= "android:instantapps.installerbundle";
+ private static final String KEY_SPECS_FUTURE = "android:activity.specsFuture";
/** @hide */
public static final int ANIM_NONE = 0;
@@ -268,6 +270,7 @@ public class ActivityOptions {
private AppTransitionAnimationSpec mAnimSpecs[];
private int mRotationAnimationHint = -1;
private Bundle mAppVerificationBundle;
+ private IAppTransitionAnimationSpecsFuture mSpecsFuture;
/**
* Create an ActivityOptions specifying a custom animation to run when
@@ -492,35 +495,12 @@ public class ActivityOptions {
* is not executed, the callback will happen immediately.
* @return Returns a new ActivityOptions object that you can use to
* supply these options as the options Bundle when starting an activity.
- * @hide
*/
- public static ActivityOptions makeThumbnailScaleUpAnimation(View source,
+ private static ActivityOptions makeThumbnailScaleUpAnimation(View source,
Bitmap thumbnail, int startX, int startY, OnAnimationStartedListener listener) {
return makeThumbnailAnimation(source, thumbnail, startX, startY, listener, true);
}
- /**
- * Create an ActivityOptions specifying an animation where an activity window
- * is scaled from a given position to a thumbnail at a specified location.
- *
- * @param source The View that this thumbnail is animating to. This
- * defines the coordinate space for <var>startX</var> and <var>startY</var>.
- * @param thumbnail The bitmap that will be shown as the final thumbnail
- * of the animation.
- * @param startX The x end location of the bitmap, relative to <var>source</var>.
- * @param startY The y end location of the bitmap, relative to <var>source</var>.
- * @param listener Optional OnAnimationStartedListener to find out when the
- * requested animation has started running. If for some reason the animation
- * is not executed, the callback will happen immediately.
- * @return Returns a new ActivityOptions object that you can use to
- * supply these options as the options Bundle when starting an activity.
- * @hide
- */
- public static ActivityOptions makeThumbnailScaleDownAnimation(View source,
- Bitmap thumbnail, int startX, int startY, OnAnimationStartedListener listener) {
- return makeThumbnailAnimation(source, thumbnail, startX, startY, listener, false);
- }
-
private static ActivityOptions makeThumbnailAnimation(View source,
Bitmap thumbnail, int startX, int startY, OnAnimationStartedListener listener,
boolean scaleUp) {
@@ -537,29 +517,21 @@ public class ActivityOptions {
}
/**
- * Create an ActivityOptions specifying an animation where the new activity
- * window and a thumbnail is aspect-scaled to a new location.
- *
- * @param source The View that this thumbnail is animating from. This
- * defines the coordinate space for <var>startX</var> and <var>startY</var>.
- * @param thumbnail The bitmap that will be shown as the initial thumbnail
- * of the animation.
- * @param startX The x starting location of the bitmap, relative to <var>source</var>.
- * @param startY The y starting location of the bitmap, relative to <var>source</var>.
- * @param handler If <var>listener</var> is non-null this must be a valid
- * Handler on which to dispatch the callback; otherwise it should be null.
- * @param listener Optional OnAnimationStartedListener to find out when the
- * requested animation has started running. If for some reason the animation
- * is not executed, the callback will happen immediately.
- * @return Returns a new ActivityOptions object that you can use to
- * supply these options as the options Bundle when starting an activity.
+ * Create an ActivityOptions specifying an animation where a list of activity windows and
+ * thumbnails are aspect scaled to/from a new location.
* @hide
*/
- public static ActivityOptions makeThumbnailAspectScaleUpAnimation(View source,
- Bitmap thumbnail, int startX, int startY, int targetWidth, int targetHeight,
- Handler handler, OnAnimationStartedListener listener) {
- return makeAspectScaledThumbnailAnimation(source, thumbnail, startX, startY,
- targetWidth, targetHeight, handler, listener, true);
+ public static ActivityOptions makeMultiThumbFutureAspectScaleAnimation(Context context,
+ Handler handler, IAppTransitionAnimationSpecsFuture specsFuture,
+ OnAnimationStartedListener listener, boolean scaleUp) {
+ ActivityOptions opts = new ActivityOptions();
+ opts.mPackageName = context.getPackageName();
+ opts.mAnimationType = scaleUp
+ ? ANIM_THUMBNAIL_ASPECT_SCALE_UP
+ : ANIM_THUMBNAIL_ASPECT_SCALE_DOWN;
+ opts.mSpecsFuture = specsFuture;
+ opts.setOnAnimationStartedListener(handler, listener);
+ return opts;
}
/**
@@ -891,6 +863,10 @@ public class ActivityOptions {
}
mRotationAnimationHint = opts.getInt(KEY_ROTATION_ANIMATION_HINT);
mAppVerificationBundle = opts.getBundle(KEY_INSTANT_APP_VERIFICATION_BUNDLE);
+ if (opts.containsKey(KEY_SPECS_FUTURE)) {
+ mSpecsFuture = IAppTransitionAnimationSpecsFuture.Stub.asInterface(opts.getBinder(
+ KEY_SPECS_FUTURE));
+ }
}
/**
@@ -1029,6 +1005,11 @@ public class ActivityOptions {
public AppTransitionAnimationSpec[] getAnimSpecs() { return mAnimSpecs; }
/** @hide */
+ public IAppTransitionAnimationSpecsFuture getSpecsFuture() {
+ return mSpecsFuture;
+ }
+
+ /** @hide */
public static ActivityOptions fromBundle(Bundle bOptions) {
return bOptions != null ? new ActivityOptions(bOptions) : null;
}
@@ -1205,6 +1186,7 @@ public class ActivityOptions {
}
mAnimSpecs = otherOptions.mAnimSpecs;
mAnimationFinishedListener = otherOptions.mAnimationFinishedListener;
+ mSpecsFuture = otherOptions.mSpecsFuture;
}
/**
@@ -1279,6 +1261,9 @@ public class ActivityOptions {
if (mAnimationFinishedListener != null) {
b.putBinder(KEY_ANIMATION_FINISHED_LISTENER, mAnimationFinishedListener.asBinder());
}
+ if (mSpecsFuture != null) {
+ b.putBinder(KEY_SPECS_FUTURE, mSpecsFuture.asBinder());
+ }
b.putInt(KEY_ROTATION_ANIMATION_HINT, mRotationAnimationHint);
if (mAppVerificationBundle != null) {
b.putBundle(KEY_INSTANT_APP_VERIFICATION_BUNDLE, mAppVerificationBundle);