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

Commit dbdc68c5 authored by William Xiao's avatar William Xiao
Browse files

Fix shade jumping back and forth when opening on shade/hub

The bouncer touch handler sets the legacy shade tracking state when a
touch session starts or stops. However, this happens on any touch while
the hub or dream are open, even if the touch handler does not capture
the gesture and start opening the bouncer.

When the state gets erroneously unset as the shade opening starts, the
shade code does not think the user is opening the shade and strange
things happen, causing the shade to jump back and forth between the
expected expansion and 100%.

Bug: 397578827
Fixed: 397578827
Test: atest BouncerSwipeTouchHandlerTest
      manually verified that opening shade looks smooth
Flag: NONE minor fix
Change-Id: I788f8f17826bafa7f353507dd6db3a1cdca9e9e9
parent 4957c9d7
Loading
Loading
Loading
Loading
+25 −3
Original line number Diff line number Diff line
@@ -712,17 +712,39 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
    }

    @Test
    public void testTouchSessionStart_notifiesShadeOfUserInteraction() {
        mTouchHandler.onSessionStart(mTouchSession);

    public void testSwipeUp_notifiesShadeOfUserInteraction() {
        // Start a swipe up gesture that will open the bouncer.
        final float swipeUpPercentage = .3f;
        final float velocityY = -1;
        swipeToPosition(swipeUpPercentage, velocityY);
        mKosmos.getTestScope().getTestScheduler().runCurrent();
        assertThat(mKosmos.getShadeRepository().getLegacyShadeTracking().getValue()).isTrue();

        // End touch session.
        ArgumentCaptor<TouchHandler.TouchSession.Callback> onRemovedCallbackCaptor =
                ArgumentCaptor.forClass(TouchHandler.TouchSession.Callback.class);
        verify(mTouchSession).registerCallback(onRemovedCallbackCaptor.capture());
        onRemovedCallbackCaptor.getValue().onRemoved();
        mKosmos.getTestScope().getTestScheduler().runCurrent();

        // Shade notified that the tracking stops.
        assertThat(mKosmos.getShadeRepository().getLegacyShadeTracking().getValue()).isFalse();
    }

    @Test
    public void testSwipeDown_doesNotNotifYShadeOfUserInteraction() {
        mTouchHandler.onSessionStart(mTouchSession);

        final float percent = .15f;
        final float distanceY = SCREEN_HEIGHT_PX * percent;

        // Swiping down, which will not open the bouncer.
        final MotionEvent event1 = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE,
                0, SCREEN_HEIGHT_PX - distanceY, 0);
        final MotionEvent event2 = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE,
                0, SCREEN_HEIGHT_PX, 0);

        // Shade is not notified since swipe is not captured.
        mKosmos.getTestScope().getTestScheduler().runCurrent();
        assertThat(mKosmos.getShadeRepository().getLegacyShadeTracking().getValue()).isFalse();
    }
+10 −2
Original line number Diff line number Diff line
@@ -142,6 +142,10 @@ constructor(
                            abs(distanceY.toDouble()) > abs(distanceX.toDouble())
                        }
                    if (capture == true) {
                        // Set legacy shade tracking when opening bouncer, same as lock screen does.
                        // This prevents issues with the bouncer swipe getting cancelled/stuck
                        // midway.
                        shadeRepository.setLegacyShadeTracking(true)
                        // reset expanding
                        expanded = false
                        // Since the user is dragging the bouncer up, set scrimmed to false.
@@ -294,8 +298,13 @@ constructor(
        currentScrimController = scrimManager.currentController
        isKeyguardScreenRotationAllowed = keyguardStateController.isKeyguardScreenRotationAllowed()

        shadeRepository.setLegacyShadeTracking(true)
        session.registerCallback {
            if (capture == true) {
                // Only set tracking to false if we started capturing a bouncer swipe gesture.
                // Otherwise this can interfere with opening the shade.
                shadeRepository.setLegacyShadeTracking(false)
            }

            velocityTracker?.apply { recycle() }
            velocityTracker = null

@@ -306,7 +315,6 @@ constructor(
            if (!Flags.communalBouncerDoNotModifyPluginOpen()) {
                notificationShadeWindowController.setForcePluginOpen(false, this)
            }
            shadeRepository.setLegacyShadeTracking(false)
        }
        session.registerGestureListener(onGestureListener)
        session.registerInputListener { ev: InputEvent -> onMotionEvent(ev) }