Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f8979c28 authored by shawnlin's avatar shawnlin
Browse files

Fixed the flickering of the nav bar

The nav bar flickers when swiping up from an app in landscape to
launcher.

Should run the fade-in animation of the nav after the fade rotation finishes.

Bug: 184800262
Test: atest RecentsAnimationControllerTest
Change-Id: If2c25baaf8d0405129af9b36330f13779f76f67a
parent cf150a40
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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) {
+21 −9
Original line number Diff line number Diff line
@@ -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());
        }
    }

+31 −0
Original line number Diff line number Diff line
@@ -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();