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

Commit a0d7b87b authored by Lucas Silva's avatar Lucas Silva
Browse files

Dismiss dream when swipe up detected and keyguard unlocked

Previously we were ignoring the gesture and instead letting the dream
handle it. However, for interactive dreams, a swipe-up won't cause the
framework to dismiss the dream. This ensures that dreams are dismissed
if we detect the user is swiping up in the bottom area of the dream.

Fixes: 298716569
Test: atest BouncerSwipeTouchHandlerTest
Flag: NA
Change-Id: Iaa45af8ccd6832736925a2d90f894d672a1d6f6b
parent 6e58412e
Loading
Loading
Loading
Loading
+36 −3
Original line number Diff line number Diff line
@@ -293,8 +293,8 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
    }

    /**
     * Verifies that swiping up when the lock pattern is not secure does not consume the scroll
     * gesture or expand.
     * Verifies that swiping up when the lock pattern is not secure dismissed dream and consumes
     * the gesture.
     */
    @Test
    public void testSwipeUp_keyguardNotSecure_doesNotExpand() {
@@ -314,11 +314,44 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {

        reset(mScrimController);

        // Scroll gesture is consumed.
        assertThat(gestureListener.onScroll(event1, event2, 0, distanceY))
                .isTrue();
        // We should not expand since the keyguard is not secure
        verify(mScrimController, never()).expand(any());
        // Since we are swiping up, we should wake from dreams.
        verify(mCentralSurfaces).awakenDreams();
    }

    /**
     * Verifies that swiping down when the lock pattern is not secure does not dismiss the dream.
     */
    @Test
    public void testSwipeDown_keyguardNotSecure_doesNotExpand() {
        when(mLockPatternUtils.isSecure(CURRENT_USER_INFO.id)).thenReturn(false);
        mTouchHandler.onSessionStart(mTouchSession);
        ArgumentCaptor<GestureDetector.OnGestureListener> gestureListenerCaptor =
                ArgumentCaptor.forClass(GestureDetector.OnGestureListener.class);
        verify(mTouchSession).registerGestureListener(gestureListenerCaptor.capture());

        final OnGestureListener gestureListener = gestureListenerCaptor.getValue();

        final float distanceY = SCREEN_HEIGHT_PX * 0.3f;
        // Swiping down near the bottom of the screen where the touch initiation region is.
        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);

        reset(mScrimController);

        // Scroll gesture is not consumed.
        assertThat(gestureListener.onScroll(event1, event2, 0, distanceY))
                .isFalse();
                .isTrue();
        // We should not expand since the keyguard is not secure
        verify(mScrimController, never()).expand(any());
        // Since we are swiping down, we should not dismiss the dream.
        verify(mCentralSurfaces, never()).awakenDreams();
    }

    private void verifyScroll(float percent, Direction direction,
+6 −6
Original line number Diff line number Diff line
@@ -155,12 +155,12 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
                        return true;
                    }

                    // Don't set expansion if the user doesn't have a pin/password set so that no
                    // animations are played we're not transitioning to the bouncer.
                    if (!mLockPatternUtils.isSecure(mUserTracker.getUserId())) {
                        // Return false so the gesture is not consumed, allowing the dream to wake
                        // if it wants instead of doing nothing.
                        return false;
                    // If scrolling up and keyguard is not locked, dismiss the dream since there's
                    // no bouncer to show.
                    if (e1.getY() > e2.getY()
                            && !mLockPatternUtils.isSecure(mUserTracker.getUserId())) {
                        mCentralSurfaces.get().awakenDreams();
                        return true;
                    }

                    // For consistency, we adopt the expansion definition found in the