Include TaskFragment bounds change in app transition

Bug: 196173550
Test: behave currently with demo app
Change-Id: I9a0f5b7033e5575806d904196594466004458c34
This commit is contained in:
Chris Li
2021-08-13 13:37:09 -07:00
parent 4c7e68f17a
commit 118428b624
7 changed files with 145 additions and 50 deletions

View File

@@ -332,6 +332,12 @@ public interface WindowManager extends ViewManager {
*/
int TRANSIT_OLD_TASK_FRAGMENT_CLOSE = 29;
/**
* A window of task fragment is changing bounds.
* @hide
*/
int TRANSIT_OLD_TASK_FRAGMENT_CHANGE = 30;
/**
* @hide
*/
@@ -359,7 +365,8 @@ public interface WindowManager extends ViewManager {
TRANSIT_OLD_CRASHING_ACTIVITY_CLOSE,
TRANSIT_OLD_TASK_CHANGE_WINDOWING_MODE,
TRANSIT_OLD_TASK_FRAGMENT_OPEN,
TRANSIT_OLD_TASK_FRAGMENT_CLOSE
TRANSIT_OLD_TASK_FRAGMENT_CLOSE,
TRANSIT_OLD_TASK_FRAGMENT_CHANGE
})
@Retention(RetentionPolicy.SOURCE)
@interface TransitionOldType {}

View File

@@ -40,6 +40,7 @@ import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_UNOCCLUDE;
import static android.view.WindowManager.TRANSIT_OLD_NONE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_CHANGE_WINDOWING_MODE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_CLOSE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_FRAGMENT_CHANGE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_FRAGMENT_CLOSE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_FRAGMENT_OPEN;
import static android.view.WindowManager.TRANSIT_OLD_TASK_OPEN;
@@ -941,7 +942,7 @@ public class AppTransition implements Dump {
"applyAnimation NEXT_TRANSIT_TYPE_OPEN_CROSS_PROFILE_APPS: "
+ "anim=%s transit=%s isEntrance=true Callers=%s",
a, appTransitionOldToString(transit), Debug.getCallers(3));
} else if (transit == TRANSIT_OLD_TASK_CHANGE_WINDOWING_MODE) {
} else if (isChangeTransitOld(transit)) {
// In the absence of a specific adapter, we just want to keep everything stationary.
a = new AlphaAnimation(1.f, 1.f);
a.setDuration(WindowChangeAnimationSpec.ANIMATION_DURATION);
@@ -1338,6 +1339,9 @@ public class AppTransition implements Dump {
case TRANSIT_OLD_TASK_FRAGMENT_CLOSE: {
return "TRANSIT_OLD_TASK_FRAGMENT_CLOSE";
}
case TRANSIT_OLD_TASK_FRAGMENT_CHANGE: {
return "TRANSIT_OLD_TASK_FRAGMENT_CHANGE";
}
default: {
return "<UNKNOWN: " + transition + ">";
}
@@ -1595,7 +1599,8 @@ public class AppTransition implements Dump {
}
static boolean isChangeTransitOld(@TransitionOldType int transit) {
return transit == TRANSIT_OLD_TASK_CHANGE_WINDOWING_MODE;
return transit == TRANSIT_OLD_TASK_CHANGE_WINDOWING_MODE
|| transit == TRANSIT_OLD_TASK_FRAGMENT_CHANGE;
}
static boolean isClosingTransitOld(@TransitionOldType int transit) {

View File

@@ -39,6 +39,7 @@ import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_UNOCCLUDE;
import static android.view.WindowManager.TRANSIT_OLD_NONE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_CHANGE_WINDOWING_MODE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_CLOSE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_FRAGMENT_CHANGE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_FRAGMENT_CLOSE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_FRAGMENT_OPEN;
import static android.view.WindowManager.TRANSIT_OLD_TASK_OPEN;
@@ -204,8 +205,8 @@ public class AppTransitionController {
mDisplayContent.mOpeningApps);
final @TransitionOldType int transit = getTransitCompatType(
mDisplayContent.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
mDisplayContent.mAppTransition, mDisplayContent.mOpeningApps,
mDisplayContent.mClosingApps, mDisplayContent.mChangingContainers,
mWallpaperControllerLocked.getWallpaperTarget(), getOldWallpaper(),
mDisplayContent.mSkipAppTransitionAnimation);
mDisplayContent.mSkipAppTransitionAnimation = false;
@@ -286,6 +287,7 @@ public class AppTransitionController {
* @param appTransition {@link AppTransition} for managing app transition state.
* @param openingApps {@link ActivityRecord}s which are becoming visible.
* @param closingApps {@link ActivityRecord}s which are becoming invisible.
* @param changingContainers {@link WindowContainer}s which are changed in configuration.
* @param wallpaperTarget If non-null, this is the currently visible window that is associated
* with the wallpaper.
* @param oldWallpaper The currently visible window that is associated with the wallpaper in
@@ -294,8 +296,8 @@ public class AppTransitionController {
*/
static @TransitionOldType int getTransitCompatType(AppTransition appTransition,
ArraySet<ActivityRecord> openingApps, ArraySet<ActivityRecord> closingApps,
@Nullable WindowState wallpaperTarget, @Nullable WindowState oldWallpaper,
boolean skipAppTransitionAnimation) {
ArraySet<WindowContainer> changingContainers, @Nullable WindowState wallpaperTarget,
@Nullable WindowState oldWallpaper, boolean skipAppTransitionAnimation) {
// Determine if closing and opening app token sets are wallpaper targets, in which case
// special animations are needed.
@@ -328,8 +330,18 @@ public class AppTransitionController {
// Special transitions
// TODO(new-app-transitions): Revisit if those can be rewritten by using flags.
if (appTransition.containsTransitRequest(TRANSIT_CHANGE)) {
return TRANSIT_OLD_TASK_CHANGE_WINDOWING_MODE;
if (appTransition.containsTransitRequest(TRANSIT_CHANGE) && !changingContainers.isEmpty()) {
@TransitContainerType int changingType =
getTransitContainerType(changingContainers.valueAt(0));
switch (changingType) {
case TYPE_TASK:
return TRANSIT_OLD_TASK_CHANGE_WINDOWING_MODE;
case TYPE_TASK_FRAGMENT:
return TRANSIT_OLD_TASK_FRAGMENT_CHANGE;
default:
throw new IllegalStateException(
"TRANSIT_CHANGE with unrecognized changing type=" + changingType);
}
}
if ((flags & TRANSIT_FLAG_APP_CRASHED) != 0) {
return TRANSIT_OLD_CRASHING_ACTIVITY_CLOSE;

View File

@@ -2166,16 +2166,6 @@ class Task extends TaskFragment {
bounds.offset(horizontalDiff, verticalDiff);
}
/**
* Initializes a change transition. See {@link SurfaceFreezer} for more information.
*/
private void initializeChangeTransition(Rect startBounds) {
mDisplayContent.prepareAppTransition(TRANSIT_CHANGE);
mDisplayContent.mChangingContainers.add(this);
mSurfaceFreezer.freeze(getPendingTransaction(), startBounds);
}
private boolean shouldStartChangeTransition(int prevWinMode, int newWinMode) {
if (mWmService.mDisableTransitionAnimation
|| !isVisible()

View File

@@ -33,6 +33,7 @@ import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.content.res.Configuration.ORIENTATION_UNDEFINED;
import static android.os.UserHandle.USER_NULL;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.WindowManager.TRANSIT_CHANGE;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_FLAG_OPEN_BEHIND;
import static android.view.WindowManager.TRANSIT_NONE;
@@ -1987,10 +1988,48 @@ class TaskFragment extends WindowContainer<WindowContainer> {
@Override
public void onConfigurationChanged(Configuration newParentConfig) {
// Task will animate differently.
if (mTaskFragmentOrganizer != null) {
mTmpPrevBounds.set(getBounds());
}
super.onConfigurationChanged(newParentConfig);
if (shouldStartChangeTransition(mTmpPrevBounds)) {
initializeChangeTransition(mTmpPrevBounds);
}
if (mTaskFragmentOrganizer != null) {
// Update the surface position here instead of in the organizer so that we can make sure
// it can be synced with the surface freezer.
updateSurfacePosition(getSyncTransaction());
}
sendTaskFragmentInfoChanged();
}
/** Whether we should prepare a transition for this {@link TaskFragment} bounds change. */
private boolean shouldStartChangeTransition(Rect startBounds) {
if (mWmService.mDisableTransitionAnimation
|| mDisplayContent == null
|| mTaskFragmentOrganizer == null
|| getSurfaceControl() == null
|| !isVisible()) {
return false;
}
return !startBounds.equals(getBounds());
}
/**
* Initializes a change transition. See {@link SurfaceFreezer} for more information.
*/
void initializeChangeTransition(Rect startBounds) {
mDisplayContent.prepareAppTransition(TRANSIT_CHANGE);
mDisplayContent.mChangingContainers.add(this);
mSurfaceFreezer.freeze(getSyncTransaction(), startBounds);
}
@Override
void setSurfaceControl(SurfaceControl sc) {
super.setSurfaceControl(sc);
@@ -2061,6 +2100,11 @@ class TaskFragment extends WindowContainer<WindowContainer> {
return mTaskFragmentOrganizer;
}
@Override
boolean isOrganized() {
return mTaskFragmentOrganizer != null;
}
/** Clear {@link #mLastPausedActivity} for all {@link TaskFragment} children */
void clearLastPausedActivity() {
forAllTaskFragments(taskFragment -> taskFragment.mLastPausedActivity = null);

View File

@@ -48,7 +48,6 @@ import android.view.RemoteAnimationDefinition;
import android.view.RemoteAnimationTarget;
import android.view.WindowManager;
import androidx.test.filters.FlakyTest;
import androidx.test.filters.SmallTest;
import org.junit.Before;
@@ -94,11 +93,10 @@ public class AppTransitionControllerTest extends WindowTestsBase {
assertEquals(WindowManager.TRANSIT_OLD_UNSET,
AppTransitionController.getTransitCompatType(mDisplayContent.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
null, null, false));
mDisplayContent.mChangingContainers, null, null, false));
}
@Test
@FlakyTest(bugId = 131005232)
public void testTranslucentOpen() {
final ActivityRecord behind = createActivityRecord(mDisplayContent,
WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
@@ -112,12 +110,11 @@ public class AppTransitionControllerTest extends WindowTestsBase {
assertEquals(WindowManager.TRANSIT_OLD_TRANSLUCENT_ACTIVITY_OPEN,
AppTransitionController.getTransitCompatType(mDisplayContent.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
null, null, false));
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
mDisplayContent.mChangingContainers, null, null, false));
}
@Test
@FlakyTest(bugId = 131005232)
public void testTranslucentClose() {
final ActivityRecord behind = createActivityRecord(mDisplayContent,
WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
@@ -129,11 +126,10 @@ public class AppTransitionControllerTest extends WindowTestsBase {
assertEquals(WindowManager.TRANSIT_OLD_TRANSLUCENT_ACTIVITY_CLOSE,
AppTransitionController.getTransitCompatType(mDisplayContent.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
null, null, false));
mDisplayContent.mChangingContainers, null, null, false));
}
@Test
@FlakyTest(bugId = 131005232)
public void testChangeIsNotOverwritten() {
final ActivityRecord behind = createActivityRecord(mDisplayContent,
WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD);
@@ -144,14 +140,14 @@ public class AppTransitionControllerTest extends WindowTestsBase {
mDisplayContent.prepareAppTransition(TRANSIT_CHANGE);
mDisplayContent.mOpeningApps.add(behind);
mDisplayContent.mOpeningApps.add(translucentOpening);
mDisplayContent.mChangingContainers.add(translucentOpening.getTask());
assertEquals(TRANSIT_OLD_TASK_CHANGE_WINDOWING_MODE,
AppTransitionController.getTransitCompatType(mDisplayContent.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
null, null, false));
mDisplayContent.mChangingContainers, null, null, false));
}
@Test
@FlakyTest(bugId = 131005232)
public void testTransitWithinTask() {
final ActivityRecord opening = createActivityRecord(mDisplayContent,
WINDOWING_MODE_FREEFORM, ACTIVITY_TYPE_STANDARD);
@@ -198,7 +194,7 @@ public class AppTransitionControllerTest extends WindowTestsBase {
assertEquals(WindowManager.TRANSIT_OLD_WALLPAPER_INTRA_OPEN,
AppTransitionController.getTransitCompatType(mDisplayContent.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
appWindowClosing, null, false));
mDisplayContent.mChangingContainers, appWindowClosing, null, false));
}
@Test
@@ -229,7 +225,7 @@ public class AppTransitionControllerTest extends WindowTestsBase {
assertEquals(WindowManager.TRANSIT_OLD_WALLPAPER_INTRA_OPEN,
AppTransitionController.getTransitCompatType(mDisplayContent.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
appWindowClosing, null, false));
mDisplayContent.mChangingContainers, appWindowClosing, null, false));
}
@Test

View File

@@ -18,11 +18,14 @@ package com.android.server.wm;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static android.view.WindowManager.TRANSIT_CHANGE;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_FLAG_APP_CRASHED;
import static android.view.WindowManager.TRANSIT_KEYGUARD_GOING_AWAY;
import static android.view.WindowManager.TRANSIT_OLD_CRASHING_ACTIVITY_CLOSE;
import static android.view.WindowManager.TRANSIT_OLD_KEYGUARD_GOING_AWAY;
import static android.view.WindowManager.TRANSIT_OLD_TASK_CHANGE_WINDOWING_MODE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_FRAGMENT_CHANGE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_FRAGMENT_CLOSE;
import static android.view.WindowManager.TRANSIT_OLD_TASK_FRAGMENT_OPEN;
import static android.view.WindowManager.TRANSIT_OLD_UNSET;
@@ -32,6 +35,7 @@ import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentat
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doNothing;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.server.wm.WindowContainer.POSITION_TOP;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -39,6 +43,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
import android.platform.test.annotations.Presubmit;
@@ -85,8 +90,8 @@ public class AppTransitionTests extends WindowTestsBase {
assertEquals(TRANSIT_OLD_KEYGUARD_GOING_AWAY,
AppTransitionController.getTransitCompatType(mDc.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
null /* wallpaperTarget */, null /* oldWallpaper */,
false /*skipAppTransitionAnimation*/));
mDisplayContent.mChangingContainers, null /* wallpaperTarget */,
null /* oldWallpaper */, false /*skipAppTransitionAnimation*/));
}
@Test
@@ -100,8 +105,8 @@ public class AppTransitionTests extends WindowTestsBase {
assertEquals(TRANSIT_OLD_KEYGUARD_GOING_AWAY,
AppTransitionController.getTransitCompatType(mDc.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
null /* wallpaperTarget */, null /* oldWallpaper */,
false /*skipAppTransitionAnimation*/));
mDisplayContent.mChangingContainers, null /* wallpaperTarget */,
null /* oldWallpaper */, false /*skipAppTransitionAnimation*/));
}
@Test
@@ -115,8 +120,8 @@ public class AppTransitionTests extends WindowTestsBase {
assertEquals(TRANSIT_OLD_CRASHING_ACTIVITY_CLOSE,
AppTransitionController.getTransitCompatType(mDc.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
null /* wallpaperTarget */, null /* oldWallpaper */,
false /*skipAppTransitionAnimation*/));
mDisplayContent.mChangingContainers, null /* wallpaperTarget */,
null /* oldWallpaper */, false /*skipAppTransitionAnimation*/));
}
@Test
@@ -130,8 +135,8 @@ public class AppTransitionTests extends WindowTestsBase {
assertEquals(TRANSIT_OLD_KEYGUARD_GOING_AWAY,
AppTransitionController.getTransitCompatType(mDc.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
null /* wallpaperTarget */, null /* oldWallpaper */,
false /*skipAppTransitionAnimation*/));
mDisplayContent.mChangingContainers, null /* wallpaperTarget */,
null /* oldWallpaper */, false /*skipAppTransitionAnimation*/));
}
@Test
@@ -145,8 +150,44 @@ public class AppTransitionTests extends WindowTestsBase {
assertEquals(TRANSIT_OLD_UNSET,
AppTransitionController.getTransitCompatType(mDc.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
null /* wallpaperTarget */, null /* oldWallpaper */,
true /*skipAppTransitionAnimation*/));
mDisplayContent.mChangingContainers, null /* wallpaperTarget */,
null /* oldWallpaper */, true /*skipAppTransitionAnimation*/));
}
@Test
public void testTaskChangeWindowingMode() {
final ActivityRecord activity = createActivityRecord(mDc);
mDc.prepareAppTransition(TRANSIT_OPEN);
mDc.prepareAppTransition(TRANSIT_CHANGE);
mDc.mOpeningApps.add(activity); // Make sure TRANSIT_CHANGE has the priority
mDc.mChangingContainers.add(activity.getTask());
assertEquals(TRANSIT_OLD_TASK_CHANGE_WINDOWING_MODE,
AppTransitionController.getTransitCompatType(mDc.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
mDisplayContent.mChangingContainers, null /* wallpaperTarget */,
null /* oldWallpaper */, false /*skipAppTransitionAnimation*/));
}
@Test
public void testTaskFragmentChange() {
final ActivityRecord activity = createActivityRecord(mDc);
final TaskFragment taskFragment = new TaskFragment(mAtm, new Binder(),
true /* createdByOrganizer */, true /* isEmbedded */);
activity.getTask().addChild(taskFragment, POSITION_TOP);
activity.reparent(taskFragment, POSITION_TOP);
mDc.prepareAppTransition(TRANSIT_OPEN);
mDc.prepareAppTransition(TRANSIT_CHANGE);
mDc.mOpeningApps.add(activity); // Make sure TRANSIT_CHANGE has the priority
mDc.mChangingContainers.add(taskFragment);
assertEquals(TRANSIT_OLD_TASK_FRAGMENT_CHANGE,
AppTransitionController.getTransitCompatType(mDc.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
mDisplayContent.mChangingContainers, null /* wallpaperTarget */,
null /* oldWallpaper */, false /*skipAppTransitionAnimation*/));
}
@Test
@@ -159,9 +200,9 @@ public class AppTransitionTests extends WindowTestsBase {
mDisplayContent.mOpeningApps.add(activity);
assertEquals(TRANSIT_OLD_TASK_FRAGMENT_OPEN,
AppTransitionController.getTransitCompatType(mDisplayContent.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
null /* wallpaperTarget */, null /* oldWallpaper */,
false /* skipAppTransitionAnimation */));
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
mDisplayContent.mChangingContainers, null /* wallpaperTarget */,
null /* oldWallpaper */, false /* skipAppTransitionAnimation */));
}
@Test
@@ -175,8 +216,8 @@ public class AppTransitionTests extends WindowTestsBase {
assertEquals(TRANSIT_OLD_TASK_FRAGMENT_OPEN,
AppTransitionController.getTransitCompatType(mDisplayContent.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
null /* wallpaperTarget */, null /* oldWallpaper */,
false /* skipAppTransitionAnimation */));
mDisplayContent.mChangingContainers, null /* wallpaperTarget */,
null /* oldWallpaper */, false /* skipAppTransitionAnimation */));
}
@Test
@@ -190,8 +231,8 @@ public class AppTransitionTests extends WindowTestsBase {
assertEquals(TRANSIT_OLD_TASK_FRAGMENT_CLOSE,
AppTransitionController.getTransitCompatType(mDisplayContent.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
null /* wallpaperTarget */, null /* oldWallpaper */,
false /* skipAppTransitionAnimation */));
mDisplayContent.mChangingContainers, null /* wallpaperTarget */,
null /* oldWallpaper */, false /* skipAppTransitionAnimation */));
}
@Test
@@ -205,8 +246,8 @@ public class AppTransitionTests extends WindowTestsBase {
assertEquals(TRANSIT_OLD_TASK_FRAGMENT_CLOSE,
AppTransitionController.getTransitCompatType(mDisplayContent.mAppTransition,
mDisplayContent.mOpeningApps, mDisplayContent.mClosingApps,
null /* wallpaperTarget */, null /* oldWallpaper */,
false /* skipAppTransitionAnimation */));
mDisplayContent.mChangingContainers, null /* wallpaperTarget */,
null /* oldWallpaper */, false /* skipAppTransitionAnimation */));
}
/**