Restrict change mode to apply transition background

Previously it only checks the transition type. It will incorrectly
add the background color for a CHANGE mode window.

An example:
 CLOSE type {
   CLOSE mode: translucent
   CHANGE mode: opaque
 }

Bug: 281010752
Test: Launch a translucent activity and it calls
      Activity#finishAndRemoveTask(). A fullscreen background
      color should not show.
Change-Id: Iff51289467c448b422f4011e14b9fd61de881b45
This commit is contained in:
Riddle Hsu
2023-05-05 22:26:57 +08:00
parent 35f2750e30
commit a4b15ed033
2 changed files with 14 additions and 17 deletions

View File

@@ -36,12 +36,8 @@ 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_BACK_GESTURE_ANIMATED;
import static android.window.TransitionInfo.FLAG_CROSS_PROFILE_OWNER_THUMBNAIL;
import static android.window.TransitionInfo.FLAG_CROSS_PROFILE_WORK_THUMBNAIL;
@@ -92,7 +88,6 @@ import android.view.Choreographer;
import android.view.SurfaceControl;
import android.view.SurfaceSession;
import android.view.WindowManager;
import android.view.WindowManager.TransitionType;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Transformation;
@@ -343,9 +338,10 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
continue;
}
final boolean isTask = change.getTaskInfo() != null;
final int mode = change.getMode();
boolean isSeamlessDisplayChange = false;
if (change.getMode() == TRANSIT_CHANGE && (change.getFlags() & FLAG_IS_DISPLAY) != 0) {
if (mode == TRANSIT_CHANGE && change.hasFlags(FLAG_IS_DISPLAY)) {
if (info.getType() == TRANSIT_CHANGE) {
final int anim = getRotationAnimationHint(change, info, mDisplayController);
isSeamlessDisplayChange = anim == ROTATION_ANIMATION_SEAMLESS;
@@ -361,7 +357,7 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
}
}
if (change.getMode() == TRANSIT_CHANGE) {
if (mode == TRANSIT_CHANGE) {
// If task is child task, only set position in parent and update crop when needed.
if (isTask && change.getParent() != null
&& info.getChange(change.getParent()).getTaskInfo() != null) {
@@ -410,8 +406,7 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
// Hide the invisible surface directly without animating it if there is a display
// rotation animation playing.
if (isDisplayRotationAnimationStarted && TransitionUtil.isClosingType(
change.getMode())) {
if (isDisplayRotationAnimationStarted && TransitionUtil.isClosingType(mode)) {
startTransaction.hide(change.getLeash());
continue;
}
@@ -427,13 +422,9 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
Animation a = loadAnimation(info, change, wallpaperTransit);
if (a != null) {
if (isTask) {
final @TransitionType int type = info.getType();
final boolean isOpenOrCloseTransition = type == TRANSIT_OPEN
|| type == TRANSIT_CLOSE
|| type == TRANSIT_TO_FRONT
|| type == TRANSIT_TO_BACK;
final boolean isTranslucent = (change.getFlags() & FLAG_TRANSLUCENT) != 0;
if (isOpenOrCloseTransition && !isTranslucent
if (!isTranslucent && TransitionUtil.isOpenOrCloseMode(mode)
&& TransitionUtil.isOpenOrCloseMode(info.getType())
&& wallpaperTransit == WALLPAPER_TRANSITION_NONE) {
// Use the overview background as the background for the animation
final Context uiContext = ActivityThread.currentActivityThread()
@@ -458,7 +449,7 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
backgroundColorForTransition);
if (!isTask && a.hasExtension()) {
if (!TransitionUtil.isOpeningType(change.getMode())) {
if (!TransitionUtil.isOpeningType(mode)) {
// Can screenshot now (before startTransaction is applied)
edgeExtendWindow(change, a, startTransaction, finishTransaction);
} else {
@@ -469,7 +460,7 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler {
}
}
final Rect clipRect = TransitionUtil.isClosingType(change.getMode())
final Rect clipRect = TransitionUtil.isClosingType(mode)
? new Rect(mRotator.getEndBoundsInStartRotation(change))
: new Rect(change.getEndAbsBounds());
clipRect.offsetTo(0, 0);

View File

@@ -68,6 +68,12 @@ public class TransitionUtil {
return type == TRANSIT_CLOSE || type == TRANSIT_TO_BACK;
}
/** Returns {@code true} if the transition is opening or closing mode. */
public static boolean isOpenOrCloseMode(@TransitionInfo.TransitionMode int mode) {
return mode == TRANSIT_OPEN || mode == TRANSIT_CLOSE
|| mode == TRANSIT_TO_FRONT || mode == TRANSIT_TO_BACK;
}
/** Returns {@code true} if the transition has a display change. */
public static boolean hasDisplayChange(@NonNull TransitionInfo info) {
for (int i = info.getChanges().size() - 1; i >= 0; --i) {