Merge "Check okToAnimate for TaskFragment change transition" into sc-v2-dev

This commit is contained in:
Chris Li
2021-11-25 02:54:24 +00:00
committed by Android (Google) Code Review
9 changed files with 51 additions and 39 deletions

View File

@@ -1387,9 +1387,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
/** Whether we should prepare a transition for this {@link ActivityRecord} parent change. */ /** Whether we should prepare a transition for this {@link ActivityRecord} parent change. */
private boolean shouldStartChangeTransition( private boolean shouldStartChangeTransition(
@Nullable TaskFragment newParent, @Nullable TaskFragment oldParent) { @Nullable TaskFragment newParent, @Nullable TaskFragment oldParent) {
if (mWmService.mDisableTransitionAnimation if (newParent == null || oldParent == null || !canStartChangeTransition()) {
|| mDisplayContent == null || newParent == null || oldParent == null
|| getSurfaceControl() == null || !isVisible() || !isVisibleRequested()) {
return false; return false;
} }

View File

@@ -4715,12 +4715,9 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
mWmService.requestTraversal(); mWmService.requestTraversal();
} }
@Override
boolean okToDisplay() { boolean okToDisplay() {
return okToDisplay(false); return okToDisplay(false /* ignoreFrozen */, false /* ignoreScreenOn */);
}
boolean okToDisplay(boolean ignoreFrozen) {
return okToDisplay(ignoreFrozen, false /* ignoreScreenOn */);
} }
boolean okToDisplay(boolean ignoreFrozen, boolean ignoreScreenOn) { boolean okToDisplay(boolean ignoreFrozen, boolean ignoreScreenOn) {
@@ -4732,18 +4729,12 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
return mDisplayInfo.state == Display.STATE_ON; return mDisplayInfo.state == Display.STATE_ON;
} }
boolean okToAnimate() { @Override
return okToAnimate(false);
}
boolean okToAnimate(boolean ignoreFrozen) {
return okToAnimate(ignoreFrozen, false /* ignoreScreenOn */);
}
boolean okToAnimate(boolean ignoreFrozen, boolean ignoreScreenOn) { boolean okToAnimate(boolean ignoreFrozen, boolean ignoreScreenOn) {
return okToDisplay(ignoreFrozen, ignoreScreenOn) return okToDisplay(ignoreFrozen, ignoreScreenOn)
&& (mDisplayId != DEFAULT_DISPLAY && (mDisplayId != DEFAULT_DISPLAY
|| mWmService.mPolicy.okToAnimate(ignoreScreenOn)); || mWmService.mPolicy.okToAnimate(ignoreScreenOn))
&& getDisplayPolicy().isScreenOnFully();
} }
static final class TaskForResizePointSearchResult { static final class TaskForResizePointSearchResult {

View File

@@ -2163,10 +2163,7 @@ class Task extends TaskFragment {
} }
private boolean shouldStartChangeTransition(int prevWinMode, int newWinMode) { private boolean shouldStartChangeTransition(int prevWinMode, int newWinMode) {
if (mWmService.mDisableTransitionAnimation if (!isLeafTask() || !canStartChangeTransition()) {
|| !isVisible()
|| getSurfaceControl() == null
|| !isLeafTask()) {
return false; return false;
} }
// Only do an animation into and out-of freeform mode for now. Other mode // Only do an animation into and out-of freeform mode for now. Other mode

View File

@@ -2125,13 +2125,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {
/** Whether we should prepare a transition for this {@link TaskFragment} bounds change. */ /** Whether we should prepare a transition for this {@link TaskFragment} bounds change. */
private boolean shouldStartChangeTransition(Rect startBounds) { private boolean shouldStartChangeTransition(Rect startBounds) {
if (mWmService.mDisableTransitionAnimation if (mTaskFragmentOrganizer == null || !canStartChangeTransition()) {
|| mDisplayContent == null
|| mTaskFragmentOrganizer == null
|| getSurfaceControl() == null
// The change transition will be covered by display.
|| mDisplayContent.inTransition()
|| !isVisible()) {
return false; return false;
} }

View File

@@ -2600,6 +2600,13 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
mSurfaceFreezer.unfreeze(getPendingTransaction()); mSurfaceFreezer.unfreeze(getPendingTransaction());
} }
/** Whether we can start change transition with this window and current display status. */
boolean canStartChangeTransition() {
return !mWmService.mDisableTransitionAnimation && mDisplayContent != null
&& getSurfaceControl() != null && !mDisplayContent.inTransition()
&& isVisible() && isVisibleRequested() && okToAnimate();
}
/** /**
* Initializes a change transition. See {@link SurfaceFreezer} for more information. * Initializes a change transition. See {@link SurfaceFreezer} for more information.
* *
@@ -2948,12 +2955,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
} }
boolean okToAnimate() { boolean okToAnimate() {
return okToAnimate(false /* ignoreFrozen */); return okToAnimate(false /* ignoreFrozen */, false /* ignoreScreenOn */);
}
boolean okToAnimate(boolean ignoreFrozen) {
final DisplayContent dc = getDisplayContent();
return dc != null && dc.okToAnimate(ignoreFrozen);
} }
boolean okToAnimate(boolean ignoreFrozen, boolean ignoreScreenOn) { boolean okToAnimate(boolean ignoreFrozen, boolean ignoreScreenOn) {

View File

@@ -1779,11 +1779,6 @@ public class ActivityRecordTests extends WindowTestsBase {
anyInt() /* orientation */, anyInt() /* lastRotation */); anyInt() /* orientation */, anyInt() /* lastRotation */);
// Set to visible so the activity can freeze the screen. // Set to visible so the activity can freeze the screen.
activity.setVisibility(true); activity.setVisibility(true);
// Update the display policy to make the screen fully turned on so the freeze is allowed
display.getDisplayPolicy().screenTurnedOn(null);
display.getDisplayPolicy().finishKeyguardDrawn();
display.getDisplayPolicy().finishWindowsDrawn();
display.getDisplayPolicy().finishScreenTurningOn();
display.rotateInDifferentOrientationIfNeeded(activity); display.rotateInDifferentOrientationIfNeeded(activity);
display.setFixedRotationLaunchingAppUnchecked(activity); display.setFixedRotationLaunchingAppUnchecked(activity);

View File

@@ -16,11 +16,14 @@
package com.android.server.wm; package com.android.server.wm;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.any;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.never;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.clearInvocations;
import android.graphics.Rect; import android.graphics.Rect;
@@ -91,6 +94,7 @@ public class TaskFragmentTest extends WindowTestsBase {
final Rect endBounds = new Rect(500, 500, 1000, 1000); final Rect endBounds = new Rect(500, 500, 1000, 1000);
mTaskFragment.setBounds(startBounds); mTaskFragment.setBounds(startBounds);
doReturn(true).when(mTaskFragment).isVisible(); doReturn(true).when(mTaskFragment).isVisible();
doReturn(true).when(mTaskFragment).isVisibleRequested();
clearInvocations(mTransaction); clearInvocations(mTransaction);
mTaskFragment.setBounds(endBounds); mTaskFragment.setBounds(endBounds);
@@ -108,6 +112,25 @@ public class TaskFragmentTest extends WindowTestsBase {
verify(mTransaction).setWindowCrop(mLeash, 500, 500); verify(mTransaction).setWindowCrop(mLeash, 500, 500);
} }
@Test
public void testNotOkToAnimate_doNotStartChangeTransition() {
mockSurfaceFreezerSnapshot(mTaskFragment.mSurfaceFreezer);
final Rect startBounds = new Rect(0, 0, 1000, 1000);
final Rect endBounds = new Rect(500, 500, 1000, 1000);
mTaskFragment.setBounds(startBounds);
doReturn(true).when(mTaskFragment).isVisible();
doReturn(true).when(mTaskFragment).isVisibleRequested();
final DisplayPolicy displayPolicy = mDisplayContent.getDisplayPolicy();
displayPolicy.screenTurnedOff();
assertFalse(mTaskFragment.okToAnimate());
mTaskFragment.setBounds(endBounds);
verify(mTaskFragment, never()).initializeChangeTransition(any());
}
/** /**
* Tests that when a {@link TaskFragmentInfo} is generated from a {@link TaskFragment}, an * Tests that when a {@link TaskFragmentInfo} is generated from a {@link TaskFragment}, an
* activity that has not yet been attached to a process because it is being initialized but * activity that has not yet been attached to a process because it is being initialized but

View File

@@ -165,6 +165,11 @@ class TestDisplayContent extends DisplayContent {
doReturn(false).when(displayPolicy).hasStatusBar(); doReturn(false).when(displayPolicy).hasStatusBar();
doReturn(false).when(newDisplay).supportsSystemDecorations(); doReturn(false).when(newDisplay).supportsSystemDecorations();
} }
// Update the display policy to make the screen fully turned on so animation is allowed
displayPolicy.screenTurnedOn(null /* screenOnListener */);
displayPolicy.finishKeyguardDrawn();
displayPolicy.finishWindowsDrawn();
displayPolicy.finishScreenTurningOn();
if (mStatusBarHeight > 0) { if (mStatusBarHeight > 0) {
doReturn(true).when(displayPolicy).hasStatusBar(); doReturn(true).when(displayPolicy).hasStatusBar();
doAnswer(invocation -> { doAnswer(invocation -> {

View File

@@ -200,6 +200,13 @@ class WindowTestsBase extends SystemServiceTestsBase {
SystemServicesTestRule.checkHoldsLock(mWm.mGlobalLock); SystemServicesTestRule.checkHoldsLock(mWm.mGlobalLock);
mDefaultDisplay = mWm.mRoot.getDefaultDisplay(); mDefaultDisplay = mWm.mRoot.getDefaultDisplay();
// Update the display policy to make the screen fully turned on so animation is allowed
final DisplayPolicy displayPolicy = mDefaultDisplay.getDisplayPolicy();
displayPolicy.screenTurnedOn(null /* screenOnListener */);
displayPolicy.finishKeyguardDrawn();
displayPolicy.finishWindowsDrawn();
displayPolicy.finishScreenTurningOn();
mTransaction = mSystemServicesTestRule.mTransaction; mTransaction = mSystemServicesTestRule.mTransaction;
mMockSession = mock(Session.class); mMockSession = mock(Session.class);