feat: WM-Shell QPR1 (src and shared)

This commit is contained in:
Pun Butrach committed 2026-01-10 20:48:16 +07:00
1 parent b6ac1c2f3a
commit d89732512d
590 files changed
+79228 -13215

No files matched your search

@@ -18,6 +18,7 @@ package com.android.wm.shell.transition;
import static android.app.ActivityOptions.ANIM_CLIP_REVEAL;
import static android.app.ActivityOptions.ANIM_CUSTOM;
import static android.app.ActivityOptions.ANIM_FROM_STYLE;
import static android.app.ActivityOptions.ANIM_NONE;
import static android.app.ActivityOptions.ANIM_OPEN_CROSS_PROFILE_APPS;
import static android.app.ActivityOptions.ANIM_SCALE_UP;
@@ -38,8 +39,12 @@ import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_ROTATE;
import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS;
import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_UNSPECIFIED;
import static android.view.WindowManager.TRANSIT_CHANGE;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
import static android.view.WindowManager.TRANSIT_OPEN;
import static android.view.WindowManager.TRANSIT_RELAUNCH;
import static android.view.WindowManager.TRANSIT_TO_BACK;
import static android.view.WindowManager.TRANSIT_TO_FRONT;
import static android.window.TransitionInfo.FLAG_CROSS_PROFILE_OWNER_THUMBNAIL;
import static android.window.TransitionInfo.FLAG_CROSS_PROFILE_WORK_THUMBNAIL;
import static android.window.TransitionInfo.FLAG_DISPLAY_HAS_ALERT_WINDOWS;
@@ -53,18 +58,21 @@ import static android.window.TransitionInfo.FLAG_SHOW_WALLPAPER;
import static android.window.TransitionInfo.FLAG_STARTING_WINDOW_TRANSFER_RECIPIENT;
import static android.window.TransitionInfo.FLAG_TRANSLUCENT;
import static com.android.internal.jank.Cuj.CUJ_DEFAULT_TASK_TO_TASK_ANIMATION;
import static com.android.internal.policy.TransitionAnimation.WALLPAPER_TRANSITION_CHANGE;
import static com.android.internal.policy.TransitionAnimation.WALLPAPER_TRANSITION_CLOSE;
import static com.android.internal.policy.TransitionAnimation.WALLPAPER_TRANSITION_INTRA_CLOSE;
import static com.android.internal.policy.TransitionAnimation.WALLPAPER_TRANSITION_INTRA_OPEN;
import static com.android.internal.policy.TransitionAnimation.WALLPAPER_TRANSITION_NONE;
import static com.android.internal.policy.TransitionAnimation.WALLPAPER_TRANSITION_OPEN;
import static com.android.wm.shell.transition.TransitionAnimationHelper.edgeExtendWindow;
import static com.android.wm.shell.Flags.enableDynamicInsetsForAppLaunch;
import static com.android.wm.shell.transition.DefaultSurfaceAnimator.buildSurfaceAnimation;
import static com.android.wm.shell.transition.TransitionAnimationHelper.getTransitionBackgroundColorIfSet;
import static com.android.wm.shell.transition.TransitionAnimationHelper.getTransitionTypeFromInfo;
import static com.android.wm.shell.transition.TransitionAnimationHelper.isCoveredByOpaqueFullscreenChange;
import static com.android.wm.shell.transition.TransitionAnimationHelper.loadAttributeAnimation;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.annotation.ColorInt;
import android.annotation.NonNull;
@@ -77,7 +85,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.graphics.Insets;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
@@ -86,13 +93,9 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.view.Choreographer;
import android.view.SurfaceControl;
import android.view.SurfaceSession;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.window.TransitionInfo;
import android.window.TransitionMetrics;
import android.window.TransitionRequestInfo;
@@ -100,26 +103,29 @@ import android.window.WindowContainerTransaction;
import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.policy.ScreenDecorationsUtils;
import com.android.internal.policy.TransitionAnimation;
import com.android.internal.protolog.common.ProtoLog;
import com.android.internal.protolog.ProtoLog;
import com.android.window.flags.Flags;
import com.android.wm.shell.RootTaskDisplayAreaOrganizer;
import com.android.wm.shell.animation.SizeChangeAnimation;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.DisplayInsetsController;
import com.android.wm.shell.common.DisplayLayout;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.TransactionPool;
import com.android.wm.shell.protolog.ShellProtoLogGroup;
import com.android.wm.shell.shared.TransactionPool;
import com.android.wm.shell.shared.TransitionUtil;
import com.android.wm.shell.shared.animation.Interpolators;
import com.android.wm.shell.sysui.ShellInit;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
/** The default handler that handles anything not already handled. */
public class DefaultTransitionHandler implements Transitions.TransitionHandler {
private static final int MAX_ANIMATION_DURATION = 3000;
private static final int SIZE_CHANGE_ANIMATION_DURATION = 400;
private final TransactionPool mTransactionPool;
private final DisplayController mDisplayController;
@@ -129,8 +135,7 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
private final ShellExecutor mAnimExecutor;
private final TransitionAnimation mTransitionAnimation;
private final DevicePolicyManager mDevicePolicyManager;
private final SurfaceSession mSurfaceSession = new SurfaceSession();
private final TransitionAnimationHelper.RoundedContentTracker mRoundedContentBounds;
/** Keeps track of the currently-running animations associated with each transition. */
private final ArrayMap<IBinder, ArrayList<Animator>> mAnimations = new ArrayMap<>();
@@ -144,6 +149,8 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
private Drawable mEnterpriseThumbnailDrawable;
final InteractionJankMonitor mInteractionJankMonitor;
private BroadcastReceiver mEnterpriseResourceUpdatedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -158,10 +165,12 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
DefaultTransitionHandler(@NonNull Context context,
@NonNull ShellInit shellInit,
@NonNull DisplayController displayController,
@NonNull DisplayInsetsController displayInsetsController,
@NonNull TransactionPool transactionPool,
@NonNull ShellExecutor mainExecutor, @NonNull Handler mainHandler,
@NonNull ShellExecutor animExecutor,
@NonNull RootTaskDisplayAreaOrganizer rootTDAOrganizer) {
@NonNull RootTaskDisplayAreaOrganizer rootTDAOrganizer,
@NonNull InteractionJankMonitor interactionJankMonitor) {
mDisplayController = displayController;
mTransactionPool = transactionPool;
mContext = context;
@@ -173,6 +182,9 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
mDevicePolicyManager = mContext.getSystemService(DevicePolicyManager.class);
shellInit.addInitCallback(this::onInit, this);
mRootTDAOrganizer = rootTDAOrganizer;
mRoundedContentBounds = new TransitionAnimationHelper.RoundedContentTracker(
displayController, displayInsetsController);
mInteractionJankMonitor = interactionJankMonitor;
}
private void onInit() {
@@ -184,6 +196,7 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
mMainHandler);
TransitionAnimation.initAttributeCache(mContext, mMainHandler);
mRoundedContentBounds.init();
}
private void updateEnterpriseThumbnailDrawable() {
@@ -290,6 +303,34 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
return ROTATION_ANIMATION_SEAMLESS;
}
@Nullable
final TransitionAnimationHelper.RoundedContentPerDisplay getRoundedContentBounds(
TransitionInfo.Change change) {
if (!enableDynamicInsetsForAppLaunch()) {
return null;
}
if (change.getTaskInfo() == null && change.getActivityComponent() == null) {
return null;
}
return mRoundedContentBounds.forDisplay(change.getEndDisplayId());
}
@Override
public boolean startAnimation(@NonNull IBinder transition,
@Nullable TransitionInfo info,
@NonNull TransitionDispatchState dispatchState,
@NonNull SurfaceControl.Transaction startTransaction,
@NonNull SurfaceControl.Transaction finishTransaction,
@NonNull Transitions.TransitionFinishCallback finishCallback) {
if (info == null) {
// In data collection mode: there can't be errors - nothing to do
return false;
}
// In animation mode: always play everything
return startAnimation(
transition, info, startTransaction, finishTransaction, finishCallback);
}
@Override
public boolean startAnimation(@NonNull IBinder transition, @NonNull TransitionInfo info,
@NonNull SurfaceControl.Transaction startTransaction,
@@ -306,10 +347,10 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
}
// Early check if the transition doesn't warrant an animation.
if (Transitions.isAllNoAnimation(info) || Transitions.isAllOrderOnly(info)
if (TransitionUtil.isAllNoAnimation(info) || TransitionUtil.isAllOrderOnly(info)
|| (info.getFlags() & WindowManager.TRANSIT_FLAG_INVISIBLE) != 0) {
startTransaction.apply();
finishTransaction.apply();
// As a contract, finishTransaction should only be applied in Transitions#onFinish
finishCallback.onTransitionFinished(null /* wct */);
return true;
}
@@ -321,18 +362,24 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
final ArrayList<Animator> animations = new ArrayList<>();
mAnimations.put(transition, animations);
final boolean isTaskTransition = com.android.window.flags.Flags.transitionHandlerCujTags()
&& isTaskTransition(info);
final Runnable onAnimFinish = () -> {
if (!animations.isEmpty()) return;
if (isTaskTransition) {
mInteractionJankMonitor.end(CUJ_DEFAULT_TASK_TO_TASK_ANIMATION);
}
mAnimations.remove(transition);
if (Flags.releaseSurfaceOnTransitionFinish()) {
info.releaseAllSurfaces();
}
finishCallback.onTransitionFinished(null /* wct */);
};
final List<Consumer<SurfaceControl.Transaction>> postStartTransactionCallbacks =
new ArrayList<>();
@ColorInt int backgroundColorForTransition = 0;
final int wallpaperTransit = getWallpaperTransitType(info);
boolean isDisplayRotationAnimationStarted = false;
int animatingDisplayId = Integer.MIN_VALUE;
final boolean isDreamTransition = isDreamTransition(info);
final boolean isOnlyTranslucent = isOnlyTranslucent(info);
final boolean isActivityLevel = isActivityLevelOnly(info);
@@ -351,17 +398,20 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
continue;
}
final boolean isTask = change.getTaskInfo() != null;
final boolean isFreeform = isTask && change.getTaskInfo().isFreeform();
final int mode = change.getMode();
boolean isSeamlessDisplayChange = false;
if (mode == TRANSIT_CHANGE && change.hasFlags(FLAG_IS_DISPLAY)) {
if (info.getType() == TRANSIT_CHANGE) {
if (info.getType() == TRANSIT_CHANGE || isOnlyTranslucent) {
final int anim = getRotationAnimationHint(change, info, mDisplayController);
isSeamlessDisplayChange = anim == ROTATION_ANIMATION_SEAMLESS;
if (!(isSeamlessDisplayChange || anim == ROTATION_ANIMATION_JUMPCUT)) {
startRotationAnimation(startTransaction, change, info, anim, animations,
onAnimFinish);
isDisplayRotationAnimationStarted = true;
final int flags = wallpaperTransit != WALLPAPER_TRANSITION_NONE
? ScreenRotationAnimation.FLAG_HAS_WALLPAPER : 0;
startRotationAnimation(startTransaction, change, info, anim, flags,
animations, onAnimFinish);
animatingDisplayId = change.getEndDisplayId();
continue;
}
} else {
@@ -395,10 +445,17 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
continue;
}
// No default animation for this, so just update bounds/position.
final int rootIdx = TransitionUtil.rootIndexFor(change, info);
startTransaction.setPosition(change.getLeash(),
change.getEndAbsBounds().left - info.getRoot(rootIdx).getOffset().x,
change.getEndAbsBounds().top - info.getRoot(rootIdx).getOffset().y);
if (change.getParent() == null) {
// For independent change without a parent, we have reparented it to the root
// leash in Transitions#setupAnimHierarchy.
final int rootIdx = TransitionUtil.rootIndexFor(change, info);
startTransaction.setPosition(change.getLeash(),
change.getEndAbsBounds().left - info.getRoot(rootIdx).getOffset().x,
change.getEndAbsBounds().top - info.getRoot(rootIdx).getOffset().y);
} else {
startTransaction.setPosition(change.getLeash(),
change.getEndRelOffset().x, change.getEndRelOffset().y);
}
// Seamless display transition doesn't need to animate.
if (isSeamlessDisplayChange) continue;
if (isTask || (change.hasFlags(FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY)
@@ -412,15 +469,26 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
if (change.getParent() == null && !change.hasFlags(FLAG_IS_DISPLAY)
&& change.getStartRotation() != change.getEndRotation()) {
startRotationAnimation(startTransaction, change, info,
ROTATION_ANIMATION_ROTATE, animations, onAnimFinish);
ROTATION_ANIMATION_ROTATE, 0 /* flags */, animations, onAnimFinish);
continue;
}
if (Flags.portWindowSizeAnimation() && isTask
&& TransitionInfo.isIndependent(change, info)
&& change.getSnapshot() != null) {
startBoundsChangeAnimation(startTransaction, animations, change, onAnimFinish,
mMainExecutor);
continue;
}
}
// Hide the invisible surface directly without animating it if there is a display
// rotation animation playing.
if (isDisplayRotationAnimationStarted && TransitionUtil.isClosingType(mode)) {
startTransaction.hide(change.getLeash());
if (animatingDisplayId == change.getEndDisplayId()) {
if (TransitionUtil.isClosingType(mode)) {
startTransaction.hide(change.getLeash());
}
// Only need to play display level animation.
continue;
}
@@ -430,6 +498,17 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
final int type = getTransitionTypeFromInfo(info);
Animation a = loadAnimation(type, info, change, wallpaperTransit, isDreamTransition);
if (a != null) {
final int displayId = isTask ? change.getTaskInfo().displayId
: info.getRoot(TransitionUtil.rootIndexFor(change, info))
.getDisplayId();
final Context displayContext =
mDisplayController.getDisplayContext(displayId);
if (displayContext != null
&& displayContext.getResources().getConfiguration().isScreenRound()) {
// ensure that any animation on a round display is using rounded corners
a.setHasRoundedCorners(true);
}
if (isTask) {
final boolean isTranslucent = (change.getFlags() & FLAG_TRANSLUCENT) != 0;
if (!isTranslucent && TransitionUtil.isOpenOrCloseMode(mode)
@@ -457,8 +536,18 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
final int layer = zSplitLine + numChanges - i;
startTransaction.setLayer(change.getLeash(), layer);
}
} else if (!isCoveredByOpaqueFullscreenChange(info, change)
&& isFreeform
&& TransitionUtil.isOpeningMode(type)
&& change.getMode() == TRANSIT_TO_BACK) {
// Reparent the minimize-change to the root task so the minimizing Task
// isn't shown in front of other Tasks.
mRootTDAOrganizer.reparentToDisplayArea(
change.getTaskInfo().displayId,
change.getLeash(),
startTransaction);
} else if (isOnlyTranslucent && TransitionUtil.isOpeningType(info.getType())
&& TransitionUtil.isClosingType(mode)) {
&& TransitionUtil.isClosingType(mode)) {
// If there is a closing translucent task in an OPENING transition, we will
// actually select a CLOSING animation, so move the closing task into
// the animating part of the z-order.
@@ -473,32 +562,15 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
final float cornerRadius;
if (a.hasRoundedCorners()) {
final int displayId = isTask ? change.getTaskInfo().displayId
: info.getRoot(TransitionUtil.rootIndexFor(change, info))
.getDisplayId();
final Context displayContext =
mDisplayController.getDisplayContext(displayId);
cornerRadius = displayContext == null ? 0
: ScreenDecorationsUtils.getWindowCornerRadius(displayContext);
} else {
cornerRadius = 0;
}
backgroundColorForTransition = getTransitionBackgroundColorIfSet(info, change, a,
backgroundColorForTransition = getTransitionBackgroundColorIfSet(change, a,
backgroundColorForTransition);
if (!isTask && a.hasExtension()) {
if (!TransitionUtil.isOpeningType(mode)) {
// Can screenshot now (before startTransaction is applied)
edgeExtendWindow(change, a, startTransaction, finishTransaction);
} else {
// Need to screenshot after startTransaction is applied otherwise activity
// may not be visible or ready yet.
postStartTransactionCallbacks
.add(t -> edgeExtendWindow(change, a, t, finishTransaction));
}
}
final Rect clipRect = TransitionUtil.isClosingType(mode)
? new Rect(mRotator.getEndBoundsInStartRotation(change))
: new Rect(change.getEndAbsBounds());
@@ -509,15 +581,24 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
change.getEndAbsBounds().left - animRoot.getOffset().x,
change.getEndAbsBounds().top - animRoot.getOffset().y);
if (change.getActivityComponent() != null) {
final boolean isActivity = change.getActivityComponent() != null;
if (isActivity) {
// For appcompat letterbox: we intentionally report the task-bounds so that we
// can animate as-if letterboxes are "part of" the activity. This means we can't
// always rely solely on endAbsBounds and need to also max with endRelOffset.
animRelOffset.x = Math.max(animRelOffset.x, change.getEndRelOffset().x);
animRelOffset.y = Math.max(animRelOffset.y, change.getEndRelOffset().y);
}
if (!isTask && a.getExtensionEdges() != 0x0
&& (change.hasFlags(FLAG_FILLS_TASK
| FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY))) {
startTransaction.setEdgeExtensionEffect(
change.getLeash(), a.getExtensionEdges());
finishTransaction.setEdgeExtensionEffect(change.getLeash(), /* edge */ 0);
}
if (change.getActivityComponent() != null && !isActivityLevel) {
if (isActivity && !isActivityLevel
&& !mRotator.isRotated(change)) {
// At this point, this is an independent activity change in a non-activity
// transition. This means that an activity transition got erroneously combined
// with another ongoing transition. This then means that the animation root may
@@ -541,18 +622,14 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
}
buildSurfaceAnimation(animations, a, change.getLeash(), onAnimFinish,
mTransactionPool, mMainExecutor, animRelOffset, cornerRadius,
clipRect);
mTransactionPool, mMainExecutor, animRelOffset, cornerRadius, clipRect,
isTask || isActivity
? mRoundedContentBounds.forDisplay(change.getEndDisplayId())
: null);
final TransitionInfo.AnimationOptions options;
if (Flags.moveAnimationOptionsToChange()) {
options = info.getAnimationOptions();
} else {
options = change.getAnimationOptions();
}
final TransitionInfo.AnimationOptions options = change.getAnimationOptions();
if (options != null) {
attachThumbnail(animations, onAnimFinish, change, info.getAnimationOptions(),
cornerRadius);
attachThumbnail(animations, onAnimFinish, change, options, cornerRadius);
}
}
}
@@ -562,30 +639,30 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
finishTransaction);
}
if (postStartTransactionCallbacks.size() > 0) {
// postStartTransactionCallbacks require that the start transaction is already
// applied to run otherwise they may result in flickers and UI inconsistencies.
startTransaction.apply(true /* sync */);
// startTransaction is empty now, so fill it with the edge-extension setup
for (Consumer<SurfaceControl.Transaction> postStartTransactionCallback :
postStartTransactionCallbacks) {
postStartTransactionCallback.accept(startTransaction);
}
}
startTransaction.apply();
// now start animations. they are started on another thread, so we have to post them
// *after* applying the startTransaction
mAnimExecutor.execute(() -> {
for (int i = 0; i < animations.size(); ++i) {
animations.get(i).start();
final boolean hasAnimations = !animations.isEmpty();
if (hasAnimations) {
if (isTaskTransition) {
mInteractionJankMonitor.begin(info.getRoot(0).getLeash(), mContext,
mMainHandler, CUJ_DEFAULT_TASK_TO_TASK_ANIMATION);
}
});
// now start animations. they are started on another thread, so we have to post them
// *after* applying the startTransaction
mAnimExecutor.execute(() -> {
for (int i = 0; i < animations.size(); ++i) {
animations.get(i).start();
}
});
}
mRotator.cleanUp(finishTransaction);
TransitionMetrics.getInstance().reportAnimationStart(transition);
// run finish now in-case there are no animations
onAnimFinish.run();
if (!hasAnimations) {
onAnimFinish.run();
}
return true;
}
@@ -597,10 +674,16 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
for (int i = 0; i < info.getRootCount(); ++i) {
final int displayId = info.getRoot(i).getDisplayId();
final SurfaceControl.Builder colorLayerBuilder = new SurfaceControl.Builder()
.setName("animation-background")
final SurfaceControl backgroundSurface = new SurfaceControl.Builder()
.setName("animation-background for #" + info.getDebugId())
.setCallsite("DefaultTransitionHandler")
.setColorLayer();
.setColorLayer()
.setParent(info.getRoot(i).getLeash())
.build();
startTransaction.setColor(backgroundSurface, colorArray)
.setLayer(backgroundSurface, -1)
.show(backgroundSurface);
// Attaching the background surface to the transition root could unexpectedly make it
// cover one of the split root tasks. To avoid this, put the background surface just
@@ -609,15 +692,10 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
info.getChanges().stream().anyMatch(c-> c.getTaskInfo() != null
&& c.getTaskInfo().getWindowingMode() == WINDOWING_MODE_MULTI_WINDOW);
if (isSplitTaskInvolved) {
mRootTDAOrganizer.attachToDisplayArea(displayId, colorLayerBuilder);
} else {
colorLayerBuilder.setParent(info.getRootLeash());
mRootTDAOrganizer.relZToDisplayArea(displayId, backgroundSurface, startTransaction,
-1);
}
final SurfaceControl backgroundSurface = colorLayerBuilder.build();
startTransaction.setColor(backgroundSurface, colorArray)
.setLayer(backgroundSurface, -1)
.show(backgroundSurface);
finishTransaction.remove(backgroundSurface);
}
}
@@ -634,6 +712,30 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
return false;
}
/**
* A task transition is defined as a transition where there is exaclty one open/to_front task
* and one close/to_back task. Nothing else is allowed to be included in the transition
*/
public static boolean isTaskTransition(@NonNull TransitionInfo info) {
if (info.getChanges().size() != 2) {
return false;
}
boolean hasOpeningTask = false;
boolean hasClosingTask = false;
for (int i = info.getChanges().size() - 1; i >= 0; --i) {
final TransitionInfo.Change change = info.getChanges().get(i);
if (change.getTaskInfo() == null) {
// A non-task is in the transition
return false;
}
int mode = change.getMode();
hasOpeningTask |= mode == TRANSIT_OPEN || mode == TRANSIT_TO_FRONT;
hasClosingTask |= mode == TRANSIT_CLOSE || mode == TRANSIT_TO_BACK;
}
return hasOpeningTask && hasClosingTask;
}
/**
* Does `info` only contain translucent visibility changes (CHANGEs are ignored). We select
* different animations and z-orders for these
@@ -671,7 +773,9 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
@Override
public void mergeAnimation(@NonNull IBinder transition, @NonNull TransitionInfo info,
@NonNull SurfaceControl.Transaction t, @NonNull IBinder mergeTarget,
@NonNull SurfaceControl.Transaction startT,
@NonNull SurfaceControl.Transaction finishT,
@NonNull IBinder mergeTarget,
@NonNull Transitions.TransitionFinishCallback finishCallback) {
ArrayList<Animator> anims = mAnimations.get(mergeTarget);
if (anims == null) return;
@@ -682,12 +786,12 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
}
private void startRotationAnimation(SurfaceControl.Transaction startTransaction,
TransitionInfo.Change change, TransitionInfo info, int animHint,
TransitionInfo.Change change, TransitionInfo info, int animHint, int flags,
ArrayList<Animator> animations, Runnable onAnimFinish) {
final int rootIdx = TransitionUtil.rootIndexFor(change, info);
final ScreenRotationAnimation anim = new ScreenRotationAnimation(mContext, mSurfaceSession,
final ScreenRotationAnimation anim = new ScreenRotationAnimation(mContext,
mTransactionPool, startTransaction, change, info.getRoot(rootIdx).getLeash(),
animHint);
animHint, flags);
// The rotation animation may consist of 3 animations: fade-out screenshot, fade-in real
// content, and background color. The item of "animGroup" will be removed if the sub
// animation is finished. Then if the list becomes empty, the rotation animation is done.
@@ -708,6 +812,22 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
}
}
private void startBoundsChangeAnimation(@NonNull SurfaceControl.Transaction startT,
@NonNull ArrayList<Animator> animations, @NonNull TransitionInfo.Change change,
@NonNull Runnable finishCb, @NonNull ShellExecutor mainExecutor) {
final SizeChangeAnimation sca = new SizeChangeAnimation(change.getStartAbsBounds(),
change.getEndAbsBounds(), /* initialScale= */ 1f, /* scaleFactor= */ 1f);
sca.initialize(change.getLeash(), change.getSnapshot(), startT);
final ValueAnimator va = sca.buildAnimator(change.getLeash(), change.getSnapshot(),
(animator) -> mainExecutor.execute(() -> {
animations.remove(animator);
finishCb.run();
}));
va.setDuration(SIZE_CHANGE_ANIMATION_DURATION);
va.setInterpolator(Interpolators.EMPHASIZED);
animations.add(va);
}
@Nullable
@Override
public WindowContainerTransaction handleRequest(@NonNull IBinder transition,
@@ -732,13 +852,9 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
final boolean isOpeningType = TransitionUtil.isOpeningType(type);
final boolean enter = TransitionUtil.isOpeningType(changeMode);
final boolean isTask = change.getTaskInfo() != null;
final TransitionInfo.AnimationOptions options;
if (Flags.moveAnimationOptionsToChange()) {
options = change.getAnimationOptions();
} else {
options = info.getAnimationOptions();
}
final TransitionInfo.AnimationOptions options = change.getAnimationOptions();
final int overrideType = options != null ? options.getType() : ANIM_NONE;
final int userId = options != null ? options.getUserId() : UserHandle.USER_CURRENT;
final Rect endBounds = TransitionUtil.isClosingType(changeMode)
? mRotator.getEndBoundsInStartRotation(change)
: change.getEndAbsBounds();
@@ -747,25 +863,24 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
a = mTransitionAnimation.loadKeyguardExitAnimation(flags,
(changeFlags & FLAG_SHOW_WALLPAPER) != 0);
} else if (type == TRANSIT_KEYGUARD_UNOCCLUDE) {
a = mTransitionAnimation.loadKeyguardUnoccludeAnimation();
a = mTransitionAnimation.loadKeyguardUnoccludeAnimation(userId);
} else if ((changeFlags & FLAG_IS_VOICE_INTERACTION) != 0) {
if (isOpeningType) {
a = mTransitionAnimation.loadVoiceActivityOpenAnimation(enter);
a = mTransitionAnimation.loadVoiceActivityOpenAnimation(enter, userId);
} else {
a = mTransitionAnimation.loadVoiceActivityExitAnimation(enter);
a = mTransitionAnimation.loadVoiceActivityExitAnimation(enter, userId);
}
} else if (changeMode == TRANSIT_CHANGE) {
// In the absence of a specific adapter, we just want to keep everything stationary.
a = new AlphaAnimation(1.f, 1.f);
a.setDuration(TransitionAnimation.DEFAULT_APP_TRANSITION_DURATION);
// Apply end state directly by default.
return null;
} else if (type == TRANSIT_RELAUNCH) {
a = mTransitionAnimation.createRelaunchAnimation(endBounds, mInsets, endBounds);
} else if (overrideType == ANIM_CUSTOM
&& (!isTask || options.getOverrideTaskTransition())) {
a = mTransitionAnimation.loadAnimationRes(options.getPackageName(), enter
? options.getEnterResId() : options.getExitResId());
? options.getEnterResId() : options.getExitResId(), userId);
} else if (overrideType == ANIM_OPEN_CROSS_PROFILE_APPS && enter) {
a = mTransitionAnimation.loadCrossProfileAppEnterAnimation();
a = mTransitionAnimation.loadCrossProfileAppEnterAnimation(userId);
} else if (overrideType == ANIM_CLIP_REVEAL) {
a = mTransitionAnimation.createClipRevealAnimationLocked(type, wallpaperTransit, enter,
endBounds, endBounds, options.getTransitionBounds());
@@ -802,67 +917,6 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
return a;
}
/** Builds an animator for the surface and adds it to the `animations` list. */
static void buildSurfaceAnimation(@NonNull ArrayList<Animator> animations,
@NonNull Animation anim, @NonNull SurfaceControl leash,
@NonNull Runnable finishCallback, @NonNull TransactionPool pool,
@NonNull ShellExecutor mainExecutor, @Nullable Point position, float cornerRadius,
@Nullable Rect clipRect) {
final SurfaceControl.Transaction transaction = pool.acquire();
final ValueAnimator va = ValueAnimator.ofFloat(0f, 1f);
final Transformation transformation = new Transformation();
final float[] matrix = new float[9];
// Animation length is already expected to be scaled.
va.overrideDurationScale(1.0f);
va.setDuration(anim.computeDurationHint());
final ValueAnimator.AnimatorUpdateListener updateListener = animation -> {
final long currentPlayTime = Math.min(va.getDuration(), va.getCurrentPlayTime());
applyTransformation(currentPlayTime, transaction, leash, anim, transformation, matrix,
position, cornerRadius, clipRect);
};
va.addUpdateListener(updateListener);
final Runnable finisher = () -> {
applyTransformation(va.getDuration(), transaction, leash, anim, transformation, matrix,
position, cornerRadius, clipRect);
pool.release(transaction);
mainExecutor.execute(() -> {
animations.remove(va);
finishCallback.run();
});
};
va.addListener(new AnimatorListenerAdapter() {
// It is possible for the end/cancel to be called more than once, which may cause
// issues if the animating surface has already been released. Track the finished
// state here to skip duplicate callbacks. See b/252872225.
private boolean mFinished = false;
@Override
public void onAnimationEnd(Animator animation) {
onFinish();
}
@Override
public void onAnimationCancel(Animator animation) {
onFinish();
}
private void onFinish() {
if (mFinished) return;
mFinished = true;
finisher.run();
// The update listener can continue to be called after the animation has ended if
// end() is called manually again before the finisher removes the animation.
// Remove it manually here to prevent animating a released surface.
// See b/252872225.
va.removeUpdateListener(updateListener);
}
});
animations.add(va);
}
private void attachThumbnail(@NonNull ArrayList<Animator> animations,
@NonNull Runnable finishCallback, TransitionInfo.Change change,
TransitionInfo.AnimationOptions options, float cornerRadius) {
@@ -885,9 +939,9 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
final Rect bounds = change.getEndAbsBounds();
// Show the right drawable depending on the user we're transitioning to.
final Drawable thumbnailDrawable = change.hasFlags(FLAG_CROSS_PROFILE_OWNER_THUMBNAIL)
? mContext.getDrawable(R.drawable.ic_account_circle)
: change.hasFlags(FLAG_CROSS_PROFILE_WORK_THUMBNAIL)
? mEnterpriseThumbnailDrawable : null;
? mContext.getDrawable(R.drawable.ic_account_circle)
: change.hasFlags(FLAG_CROSS_PROFILE_WORK_THUMBNAIL)
? mEnterpriseThumbnailDrawable : null;
if (thumbnailDrawable == null) {
return;
}
@@ -898,7 +952,7 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
}
final SurfaceControl.Transaction transaction = mTransactionPool.acquire();
final WindowThumbnail wt = WindowThumbnail.createAndAttach(mSurfaceSession,
final WindowThumbnail wt = WindowThumbnail.createAndAttach(
change.getLeash(), thumbnail, transaction);
final Animation a =
mTransitionAnimation.createCrossProfileAppsThumbnailAnimationLocked(bounds);
@@ -915,14 +969,15 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
a.restrictDuration(MAX_ANIMATION_DURATION);
a.scaleCurrentDuration(mTransitionAnimationScaleSetting);
buildSurfaceAnimation(animations, a, wt.getSurface(), finisher, mTransactionPool,
mMainExecutor, change.getEndRelOffset(), cornerRadius, change.getEndAbsBounds());
mMainExecutor, change.getEndRelOffset(), cornerRadius, change.getEndAbsBounds(),
getRoundedContentBounds(change));
}
private void attachThumbnailAnimation(@NonNull ArrayList<Animator> animations,
@NonNull Runnable finishCallback, TransitionInfo.Change change,
TransitionInfo.AnimationOptions options, float cornerRadius) {
final SurfaceControl.Transaction transaction = mTransactionPool.acquire();
final WindowThumbnail wt = WindowThumbnail.createAndAttach(mSurfaceSession,
final WindowThumbnail wt = WindowThumbnail.createAndAttach(
change.getLeash(), options.getThumbnail(), transaction);
final Rect bounds = change.getEndAbsBounds();
final int orientation = mContext.getResources().getConfiguration().orientation;
@@ -939,16 +994,20 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
a.restrictDuration(MAX_ANIMATION_DURATION);
a.scaleCurrentDuration(mTransitionAnimationScaleSetting);
buildSurfaceAnimation(animations, a, wt.getSurface(), finisher, mTransactionPool,
mMainExecutor, change.getEndRelOffset(), cornerRadius, change.getEndAbsBounds());
mMainExecutor, change.getEndRelOffset(), cornerRadius, change.getEndAbsBounds(),
getRoundedContentBounds(change));
}
private static int getWallpaperTransitType(TransitionInfo info) {
boolean hasWallpaper = false;
boolean hasOpenWallpaper = false;
boolean hasCloseWallpaper = false;
for (int i = info.getChanges().size() - 1; i >= 0; --i) {
final TransitionInfo.Change change = info.getChanges().get(i);
if ((change.getFlags() & FLAG_SHOW_WALLPAPER) != 0) {
if ((change.getFlags() & FLAG_SHOW_WALLPAPER) != 0
|| (change.getFlags() & FLAG_IS_WALLPAPER) != 0) {
hasWallpaper = true;
if (TransitionUtil.isOpeningType(change.getMode())) {
hasOpenWallpaper = true;
} else if (TransitionUtil.isClosingType(change.getMode())) {
@@ -964,6 +1023,8 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
return WALLPAPER_TRANSITION_OPEN;
} else if (hasCloseWallpaper) {
return WALLPAPER_TRANSITION_CLOSE;
} else if (hasWallpaper) {
return WALLPAPER_TRANSITION_CHANGE;
} else {
return WALLPAPER_TRANSITION_NONE;
}
@@ -978,35 +1039,13 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
final int animType = options.getType();
return animType == ANIM_CUSTOM || animType == ANIM_SCALE_UP
|| animType == ANIM_THUMBNAIL_SCALE_UP || animType == ANIM_THUMBNAIL_SCALE_DOWN
|| animType == ANIM_CLIP_REVEAL || animType == ANIM_OPEN_CROSS_PROFILE_APPS;
|| animType == ANIM_CLIP_REVEAL || animType == ANIM_OPEN_CROSS_PROFILE_APPS
|| animType == ANIM_FROM_STYLE;
}
private static void applyTransformation(long time, SurfaceControl.Transaction t,
SurfaceControl leash, Animation anim, Transformation tmpTransformation, float[] matrix,
Point position, float cornerRadius, @Nullable Rect immutableClipRect) {
tmpTransformation.clear();
anim.getTransformation(time, tmpTransformation);
if (position != null) {
tmpTransformation.getMatrix().postTranslate(position.x, position.y);
}
t.setMatrix(leash, tmpTransformation.getMatrix(), matrix);
t.setAlpha(leash, tmpTransformation.getAlpha());
final Rect clipRect = immutableClipRect == null ? null : new Rect(immutableClipRect);
Insets extensionInsets = Insets.min(tmpTransformation.getInsets(), Insets.NONE);
if (!extensionInsets.equals(Insets.NONE) && clipRect != null && !clipRect.isEmpty()) {
// Clip out any overflowing edge extension
clipRect.inset(extensionInsets);
t.setCrop(leash, clipRect);
}
if (anim.hasRoundedCorners() && cornerRadius > 0 && clipRect != null) {
// We can only apply rounded corner if a crop is set
t.setCrop(leash, clipRect);
t.setCornerRadius(leash, cornerRadius);
}
t.setFrameTimelineVsync(Choreographer.getInstance().getVsyncId());
t.apply();
@Override
public void onTransitionConsumed(@NonNull IBinder transition, boolean aborted,
@Nullable SurfaceControl.Transaction finishTransaction) {
mInteractionJankMonitor.cancel(CUJ_DEFAULT_TASK_TO_TASK_ANIMATION);
}
}