Merge "Fixed the flickering of the nav bar" into sc-dev

This commit is contained in:
Shawn Lin
2021-04-13 06:24:25 +00:00
committed by Android (Google) Code Review
3 changed files with 63 additions and 9 deletions

View File

@@ -39,6 +39,9 @@ public class FadeRotationAnimationController extends FadeAnimationController {
private final Runnable mFrozenTimeoutRunnable;
private final WindowToken mNavBarToken;
/** A runnable which gets called when the {@link #show()} is called. */
private Runnable mOnShowRunnable;
public FadeRotationAnimationController(DisplayContent displayContent) {
super(displayContent);
mService = displayContent.mWmService;
@@ -81,6 +84,10 @@ public class FadeRotationAnimationController extends FadeAnimationController {
if (mFrozenTimeoutRunnable != null) {
mService.mH.removeCallbacks(mFrozenTimeoutRunnable);
}
if (mOnShowRunnable != null) {
mOnShowRunnable.run();
mOnShowRunnable = null;
}
}
/**
@@ -115,6 +122,10 @@ public class FadeRotationAnimationController extends FadeAnimationController {
return token == mNavBarToken || mTargetWindowTokens.contains(token);
}
void setOnShowRunnable(Runnable onShowRunnable) {
mOnShowRunnable = onShowRunnable;
}
@Override
public Animation getFadeInAnimation() {
if (mFrozenTimeoutRunnable != null) {

View File

@@ -669,21 +669,33 @@ public class RecentsAnimationController implements DeathRecipient {
}
navWindow.setSurfaceTranslationY(0);
if (navWindow.mToken == null) {
final WindowToken navToken = navWindow.mToken;
if (navToken == null) {
return;
}
final SurfaceControl.Transaction t = mDisplayContent.getPendingTransaction();
final WindowContainer parent = navWindow.mToken.getParent();
// Reparent the SurfaceControl of nav bar token back.
t.reparent(navWindow.mToken.getSurfaceControl(), parent.getSurfaceControl());
final WindowContainer parent = navToken.getParent();
if (animate) {
// Run fade-in animation to show navigation bar back to bottom of the display.
final NavBarFadeAnimationController controller =
final NavBarFadeAnimationController navBarFadeAnimationController =
mDisplayContent.getDisplayPolicy().getNavBarFadeAnimationController();
if (controller != null) {
controller.fadeWindowToken(true);
final Runnable fadeInAnim = () -> {
// Reparent the SurfaceControl of nav bar token back.
t.reparent(navToken.getSurfaceControl(), parent.getSurfaceControl());
// Run fade-in animation to show navigation bar back to bottom of the display.
if (navBarFadeAnimationController != null) {
navBarFadeAnimationController.fadeWindowToken(true);
}
};
final FadeRotationAnimationController fadeRotationAnimationController =
mDisplayContent.getFadeRotationAnimationController();
if (fadeRotationAnimationController != null) {
fadeRotationAnimationController.setOnShowRunnable(fadeInAnim);
} else {
fadeInAnim.run();
}
} else {
// Reparent the SurfaceControl of nav bar token back.
t.reparent(navToken.getSurfaceControl(), parent.getSurfaceControl());
}
}

View File

@@ -566,6 +566,37 @@ public class RecentsAnimationControllerTest extends WindowTestsBase {
assertFalse(mController.isNavigationBarAttachedToApp());
}
@Test
public void testFadeRotationAfterAttachAndBeforeRestore_notRestoreNavImmediately() {
setupForShouldAttachNavBarDuringTransition();
final ActivityRecord activity = createActivityRecord(mDefaultDisplay);
final ActivityRecord homeActivity = createHomeActivity();
initializeRecentsAnimationController(mController, homeActivity);
final WindowToken navToken = mDefaultDisplay.getDisplayPolicy().getNavigationBar().mToken;
final SurfaceControl.Transaction transaction = navToken.getPendingTransaction();
verify(mController.mStatusBar).setNavigationBarLumaSamplingEnabled(
mDefaultDisplay.mDisplayId, false);
verify(transaction).reparent(navToken.getSurfaceControl(), activity.getSurfaceControl());
final WindowContainer parent = navToken.getParent();
final NavBarFadeAnimationController navBarFadeAnimationController =
mDefaultDisplay.getDisplayPolicy().getNavBarFadeAnimationController();
FadeRotationAnimationController mockController =
mock(FadeRotationAnimationController.class);
doReturn(mockController).when(mDefaultDisplay).getFadeRotationAnimationController();
mController.cleanupAnimation(REORDER_MOVE_TO_TOP);
verify(mController.mStatusBar).setNavigationBarLumaSamplingEnabled(
mDefaultDisplay.mDisplayId, true);
verify(mockController).setOnShowRunnable(any());
verify(transaction, times(0)).reparent(navToken.getSurfaceControl(),
parent.getSurfaceControl());
verify(navBarFadeAnimationController, times(0)).fadeWindowToken(true);
}
@Test
public void testAttachNavBarInSplitScreenMode() {
setupForShouldAttachNavBarDuringTransition();