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

Commit c3d5ea44 authored by William Leshner's avatar William Leshner Committed by Android (Google) Code Review
Browse files

Merge "Fix bug with swiping up on dreams to dismiss." into main

parents deb99b8a 82e63404
Loading
Loading
Loading
Loading
+8 −14
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.systemui.ambient.touch;

import static com.google.common.truth.Truth.assertThat;

import static kotlinx.coroutines.flow.StateFlowKt.MutableStateFlow;

import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -35,15 +37,14 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.internal.logging.UiEventLogger;
import com.android.internal.widget.LockPatternUtils;
import com.android.systemui.Flags;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.ambient.touch.scrim.ScrimController;
import com.android.systemui.ambient.touch.scrim.ScrimManager;
import com.android.systemui.communal.ui.viewmodel.CommunalViewModel;
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor;
import com.android.systemui.kosmos.KosmosJavaAdapter;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.settings.FakeUserTracker;
import com.android.systemui.shared.system.InputChannelCompat;
import com.android.systemui.statusbar.NotificationShadeWindowController;
import com.android.systemui.statusbar.phone.CentralSurfaces;
@@ -57,7 +58,6 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

import java.util.Collections;
import java.util.Optional;

@SmallTest
@@ -105,16 +105,14 @@ public class BouncerFullscreenSwipeTouchHandlerTest extends SysuiTestCase {
    @Mock
    UiEventLogger mUiEventLogger;

    @Mock
    LockPatternUtils mLockPatternUtils;

    @Mock
    ActivityStarter mActivityStarter;

    @Mock
    CommunalViewModel mCommunalViewModel;

    FakeUserTracker mUserTracker;
    @Mock
    KeyguardInteractor mKeyguardInteractor;

    private static final float TOUCH_REGION = .3f;
    private static final float MIN_BOUNCER_HEIGHT = .05f;
@@ -130,7 +128,6 @@ public class BouncerFullscreenSwipeTouchHandlerTest extends SysuiTestCase {
    public void setup() {
        mKosmos = new KosmosJavaAdapter(this);
        MockitoAnnotations.initMocks(this);
        mUserTracker = new FakeUserTracker();
        mTouchHandler = new BouncerSwipeTouchHandler(
                mKosmos.getTestScope(),
                mScrimManager,
@@ -138,24 +135,21 @@ public class BouncerFullscreenSwipeTouchHandlerTest extends SysuiTestCase {
                mNotificationShadeWindowController,
                mValueAnimatorCreator,
                mVelocityTrackerFactory,
                mLockPatternUtils,
                mUserTracker,
                mCommunalViewModel,
                mFlingAnimationUtils,
                mFlingAnimationUtilsClosing,
                TOUCH_REGION,
                MIN_BOUNCER_HEIGHT,
                mUiEventLogger,
                mActivityStarter);
                mActivityStarter,
                mKeyguardInteractor);

        when(mScrimManager.getCurrentController()).thenReturn(mScrimController);
        when(mValueAnimatorCreator.create(anyFloat(), anyFloat())).thenReturn(mValueAnimator);
        when(mVelocityTrackerFactory.obtain()).thenReturn(mVelocityTracker);
        when(mFlingAnimationUtils.getMinVelocityPxPerSecond()).thenReturn(Float.MAX_VALUE);
        when(mTouchSession.getBounds()).thenReturn(SCREEN_BOUNDS);
        when(mLockPatternUtils.isSecure(CURRENT_USER_INFO.id)).thenReturn(true);

        mUserTracker.set(Collections.singletonList(CURRENT_USER_INFO), 0);
        when(mKeyguardInteractor.isKeyguardDismissible()).thenReturn(MutableStateFlow(false));
    }

    /**
+11 −17
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.systemui.ambient.touch;

import static com.google.common.truth.Truth.assertThat;

import static kotlinx.coroutines.flow.StateFlowKt.MutableStateFlow;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.eq;
@@ -44,16 +46,15 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.internal.logging.UiEventLogger;
import com.android.internal.widget.LockPatternUtils;
import com.android.systemui.Flags;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.ambient.touch.scrim.ScrimController;
import com.android.systemui.ambient.touch.scrim.ScrimManager;
import com.android.systemui.bouncer.shared.constants.KeyguardBouncerConstants;
import com.android.systemui.communal.ui.viewmodel.CommunalViewModel;
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor;
import com.android.systemui.kosmos.KosmosJavaAdapter;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.settings.FakeUserTracker;
import com.android.systemui.shade.ShadeExpansionChangeEvent;
import com.android.systemui.shared.system.InputChannelCompat;
import com.android.systemui.statusbar.NotificationShadeWindowController;
@@ -69,7 +70,6 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

import java.util.Collections;
import java.util.Optional;

@SmallTest
@@ -115,9 +115,6 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
    @Mock
    UiEventLogger mUiEventLogger;

    @Mock
    LockPatternUtils mLockPatternUtils;

    @Mock
    ActivityStarter mActivityStarter;

@@ -127,11 +124,12 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
    @Mock
    CommunalViewModel mCommunalViewModel;

    @Mock
    KeyguardInteractor mKeyguardInteractor;

    @Captor
    ArgumentCaptor<Rect> mRectCaptor;

    FakeUserTracker mUserTracker;

    private static final float TOUCH_REGION = .3f;
    private static final int SCREEN_WIDTH_PX = 1024;
    private static final int SCREEN_HEIGHT_PX = 100;
@@ -148,7 +146,6 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
    public void setup() {
        mKosmos = new KosmosJavaAdapter(this);
        MockitoAnnotations.initMocks(this);
        mUserTracker = new FakeUserTracker();
        mTouchHandler = new BouncerSwipeTouchHandler(
                mKosmos.getTestScope(),
                mScrimManager,
@@ -156,24 +153,21 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
                mNotificationShadeWindowController,
                mValueAnimatorCreator,
                mVelocityTrackerFactory,
                mLockPatternUtils,
                mUserTracker,
                mCommunalViewModel,
                mFlingAnimationUtils,
                mFlingAnimationUtilsClosing,
                TOUCH_REGION,
                MIN_BOUNCER_HEIGHT,
                mUiEventLogger,
                mActivityStarter);
                mActivityStarter,
                mKeyguardInteractor);

        when(mScrimManager.getCurrentController()).thenReturn(mScrimController);
        when(mValueAnimatorCreator.create(anyFloat(), anyFloat())).thenReturn(mValueAnimator);
        when(mVelocityTrackerFactory.obtain()).thenReturn(mVelocityTracker);
        when(mFlingAnimationUtils.getMinVelocityPxPerSecond()).thenReturn(Float.MAX_VALUE);
        when(mTouchSession.getBounds()).thenReturn(SCREEN_BOUNDS);
        when(mLockPatternUtils.isSecure(CURRENT_USER_INFO.id)).thenReturn(true);

        mUserTracker.set(Collections.singletonList(CURRENT_USER_INFO), 0);
        when(mKeyguardInteractor.isKeyguardDismissible()).thenReturn(MutableStateFlow(false));
    }

    /**
@@ -391,7 +385,7 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
     */
    @Test
    public void testSwipeUp_keyguardNotSecure_doesNotExpand() {
        when(mLockPatternUtils.isSecure(CURRENT_USER_INFO.id)).thenReturn(false);
        when(mKeyguardInteractor.isKeyguardDismissible()).thenReturn(MutableStateFlow(true));
        mTouchHandler.onSessionStart(mTouchSession);
        ArgumentCaptor<GestureDetector.OnGestureListener> gestureListenerCaptor =
                ArgumentCaptor.forClass(GestureDetector.OnGestureListener.class);
@@ -426,7 +420,7 @@ public class BouncerSwipeTouchHandlerTest extends SysuiTestCase {
     */
    @Test
    public void testSwipeDown_keyguardNotSecure_doesNotExpand() {
        when(mLockPatternUtils.isSecure(CURRENT_USER_INFO.id)).thenReturn(false);
        when(mKeyguardInteractor.isKeyguardDismissible()).thenReturn(MutableStateFlow(true));
        mTouchHandler.onSessionStart(mTouchSession);
        ArgumentCaptor<GestureDetector.OnGestureListener> gestureListenerCaptor =
                ArgumentCaptor.forClass(GestureDetector.OnGestureListener.class);
+6 −8
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.view.VelocityTracker
import androidx.annotation.VisibleForTesting
import com.android.internal.logging.UiEvent
import com.android.internal.logging.UiEventLogger
import com.android.internal.widget.LockPatternUtils
import com.android.systemui.Flags
import com.android.systemui.ambient.touch.TouchHandler.TouchSession
import com.android.systemui.ambient.touch.dagger.BouncerSwipeModule
@@ -37,8 +36,8 @@ import com.android.systemui.ambient.touch.scrim.ScrimController
import com.android.systemui.ambient.touch.scrim.ScrimManager
import com.android.systemui.bouncer.shared.constants.KeyguardBouncerConstants
import com.android.systemui.communal.ui.viewmodel.CommunalViewModel
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.settings.UserTracker
import com.android.systemui.shade.ShadeExpansionChangeEvent
import com.android.systemui.statusbar.NotificationShadeWindowController
import com.android.systemui.statusbar.phone.CentralSurfaces
@@ -63,8 +62,6 @@ constructor(
    private val notificationShadeWindowController: NotificationShadeWindowController,
    private val valueAnimatorCreator: ValueAnimatorCreator,
    private val velocityTrackerFactory: VelocityTrackerFactory,
    private val lockPatternUtils: LockPatternUtils,
    private val userTracker: UserTracker,
    private val communalViewModel: CommunalViewModel,
    @param:Named(BouncerSwipeModule.SWIPE_TO_BOUNCER_FLING_ANIMATION_UTILS_OPENING)
    private val flingAnimationUtils: FlingAnimationUtils,
@@ -75,7 +72,8 @@ constructor(
    @param:Named(BouncerSwipeModule.MIN_BOUNCER_ZONE_SCREEN_PERCENTAGE)
    private val minBouncerZoneScreenPercentage: Float,
    private val uiEventLogger: UiEventLogger,
    private val activityStarter: ActivityStarter
    private val activityStarter: ActivityStarter,
    private val keyguardInteractor: KeyguardInteractor,
) : TouchHandler {
    /** An interface for creating ValueAnimators. */
    interface ValueAnimatorCreator {
@@ -148,7 +146,7 @@ constructor(

                    // If scrolling up and keyguard is not locked, dismiss both keyguard and the
                    // dream since there's no bouncer to show.
                    if (y > e2.y && !lockPatternUtils.isSecure(userTracker.userId)) {
                    if (y > e2.y && keyguardInteractor.isKeyguardDismissible.value) {
                        activityStarter.executeRunnableDismissingKeyguard(
                            { centralSurfaces.get().awakenDreams() },
                            /* cancelAction= */ null,
@@ -331,8 +329,8 @@ constructor(
            return
        }

        // Don't set expansion if the user doesn't have a pin/password set.
        if (!lockPatternUtils.isSecure(userTracker.userId)) {
        // Don't set expansion if keyguard is dismissible (i.e. unlocked).
        if (keyguardInteractor.isKeyguardDismissible.value) {
            return
        }