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

Commit 2927a36d authored by Ale Nijamkin's avatar Ale Nijamkin Committed by Android (Google) Code Review
Browse files

Merge "[multi-shade] Fixes issue where NSWV was still visible after unlock." into udc-dev

parents 2400e57c 546b4dbf
Loading
Loading
Loading
Loading
+29 −66
Original line number Original line Diff line number Diff line
@@ -22,7 +22,6 @@ import android.view.ViewConfiguration
import com.android.systemui.classifier.Classifier
import com.android.systemui.classifier.Classifier
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerInteractor
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.multishade.shared.math.isZero
import com.android.systemui.multishade.shared.math.isZero
import com.android.systemui.multishade.shared.model.ProxiedInputModel
import com.android.systemui.multishade.shared.model.ProxiedInputModel
@@ -48,7 +47,6 @@ constructor(
    @Application private val applicationScope: CoroutineScope,
    @Application private val applicationScope: CoroutineScope,
    private val multiShadeInteractor: MultiShadeInteractor,
    private val multiShadeInteractor: MultiShadeInteractor,
    keyguardTransitionInteractor: KeyguardTransitionInteractor,
    keyguardTransitionInteractor: KeyguardTransitionInteractor,
    private val bouncerInteractor: PrimaryBouncerInteractor,
    private val falsingManager: FalsingManager,
    private val falsingManager: FalsingManager,
) {
) {


@@ -98,7 +96,7 @@ constructor(
                        currentY = event.y,
                        currentY = event.y,
                        pointerId = event.getPointerId(0),
                        pointerId = event.getPointerId(0),
                        isDraggingHorizontally = false,
                        isDraggingHorizontally = false,
                        draggedVertically = Dragged.NONE,
                        isDraggingShade = false,
                    )
                    )


                false
                false
@@ -108,38 +106,28 @@ constructor(
                    val pointerIndex = event.findPointerIndex(it.pointerId)
                    val pointerIndex = event.findPointerIndex(it.pointerId)
                    val currentX = event.getX(pointerIndex)
                    val currentX = event.getX(pointerIndex)
                    val currentY = event.getY(pointerIndex)
                    val currentY = event.getY(pointerIndex)
                    if (!it.isDraggingHorizontally && it.draggedVertically == Dragged.NONE) {
                    if (!it.isDraggingHorizontally && !it.isDraggingShade) {
                        val xDistanceTravelled = currentX - it.initialX
                        val xDistanceTravelled = currentX - it.initialX
                        val yDistanceTravelled = currentY - it.initialY
                        val yDistanceTravelled = currentY - it.initialY
                        val touchSlop = ViewConfiguration.get(applicationContext).scaledTouchSlop
                        val touchSlop = ViewConfiguration.get(applicationContext).scaledTouchSlop
                        interactionState =
                        interactionState =
                            when {
                            when {
                                abs(yDistanceTravelled) > touchSlop ->
                                yDistanceTravelled > touchSlop -> it.copy(isDraggingShade = true)
                                    it.copy(
                                        draggedVertically =
                                            if (yDistanceTravelled > 0) {
                                                Dragged.SHADE
                                            } else {
                                                Dragged.BOUNCER
                                            }
                                    )
                                abs(xDistanceTravelled) > touchSlop ->
                                abs(xDistanceTravelled) > touchSlop ->
                                    it.copy(
                                    it.copy(isDraggingHorizontally = true)
                                        isDraggingHorizontally = true,
                                    )
                                else -> interactionState
                                else -> interactionState
                            }
                            }
                    }
                    }
                }
                }


                // We want to intercept the rest of the gesture if we're dragging.
                // We want to intercept the rest of the gesture if we're dragging the shade.
                interactionState.isDraggingVertically()
                isDraggingShade()
            }
            }
            MotionEvent.ACTION_UP,
            MotionEvent.ACTION_UP,
            MotionEvent.ACTION_CANCEL ->
            MotionEvent.ACTION_CANCEL ->
                // Make sure that we intercept the up or cancel if we're dragging, to handle drag
                // Make sure that we intercept the up or cancel if we're dragging the shade, to
                // end and cancel.
                // handle drag end or cancel.
                interactionState.isDraggingVertically()
                isDraggingShade()
            else -> false
            else -> false
        }
        }
    }
    }
@@ -156,17 +144,12 @@ constructor(
        return when (event.actionMasked) {
        return when (event.actionMasked) {
            MotionEvent.ACTION_MOVE -> {
            MotionEvent.ACTION_MOVE -> {
                interactionState?.let {
                interactionState?.let {
                    if (it.draggedVertically != Dragged.NONE) {
                    if (it.isDraggingShade) {
                        val pointerIndex = event.findPointerIndex(it.pointerId)
                        val pointerIndex = event.findPointerIndex(it.pointerId)
                        val previousY = it.currentY
                        val previousY = it.currentY
                        val currentY = event.getY(pointerIndex)
                        val currentY = event.getY(pointerIndex)
                        interactionState =
                        interactionState = it.copy(currentY = currentY)
                            it.copy(
                                currentY = currentY,
                            )


                        when (it.draggedVertically) {
                            Dragged.SHADE -> {
                        val yDragAmountPx = currentY - previousY
                        val yDragAmountPx = currentY - previousY


                        if (yDragAmountPx != 0f) {
                        if (yDragAmountPx != 0f) {
@@ -178,13 +161,6 @@ constructor(
                            )
                            )
                        }
                        }
                        true
                        true
                            }
                            Dragged.BOUNCER -> {
                                bouncerInteractor.show(isScrimmed = true)
                                false
                            }
                            else -> false
                        }
                    } else {
                    } else {
                        false
                        false
                    }
                    }
@@ -192,9 +168,10 @@ constructor(
                    ?: false
                    ?: false
            }
            }
            MotionEvent.ACTION_UP -> {
            MotionEvent.ACTION_UP -> {
                if (interactionState?.draggedVertically == Dragged.SHADE) {
                if (isDraggingShade()) {
                    // We finished dragging. Record that so the multi-shade framework can issue a
                    // We finished dragging the shade. Record that so the multi-shade framework can
                    // fling, if the velocity reached in the drag was high enough, for example.
                    // issue a fling, if the velocity reached in the drag was high enough, for
                    // example.
                    multiShadeInteractor.sendProxiedInput(ProxiedInputModel.OnDragEnd)
                    multiShadeInteractor.sendProxiedInput(ProxiedInputModel.OnDragEnd)


                    if (falsingManager.isFalseTouch(Classifier.SHADE_DRAG)) {
                    if (falsingManager.isFalseTouch(Classifier.SHADE_DRAG)) {
@@ -206,7 +183,7 @@ constructor(
                true
                true
            }
            }
            MotionEvent.ACTION_CANCEL -> {
            MotionEvent.ACTION_CANCEL -> {
                if (interactionState?.draggedVertically == Dragged.SHADE) {
                if (isDraggingShade()) {
                    // Our drag gesture was canceled by the system. This happens primarily in one of
                    // Our drag gesture was canceled by the system. This happens primarily in one of
                    // two occasions: (a) the parent view has decided to intercept the gesture
                    // two occasions: (a) the parent view has decided to intercept the gesture
                    // itself and/or route it to a different child view or (b) the pointer has
                    // itself and/or route it to a different child view or (b) the pointer has
@@ -219,10 +196,6 @@ constructor(
                    if (falsingManager.isFalseTouch(Classifier.SHADE_DRAG)) {
                    if (falsingManager.isFalseTouch(Classifier.SHADE_DRAG)) {
                        multiShadeInteractor.collapseAll()
                        multiShadeInteractor.collapseAll()
                    }
                    }
                } else if (interactionState?.draggedVertically == Dragged.BOUNCER) {
                    if (falsingManager.isFalseTouch(Classifier.BOUNCER_UNLOCK)) {
                        bouncerInteractor.hide()
                    }
                }
                }


                interactionState = null
                interactionState = null
@@ -239,21 +212,11 @@ constructor(
        val pointerId: Int,
        val pointerId: Int,
        /** Whether the current gesture is dragging horizontally. */
        /** Whether the current gesture is dragging horizontally. */
        val isDraggingHorizontally: Boolean,
        val isDraggingHorizontally: Boolean,
        /** The UI component that is being dragged vertically, if any. */
        /** Whether the current gesture is dragging the shade vertically. */
        val draggedVertically: Dragged,
        val isDraggingShade: Boolean,
    )
    )


    /** Enumerates the UI components that can be dragged by the user. */
    private fun isDraggingShade(): Boolean {
    private enum class Dragged {
        return interactionState?.isDraggingShade ?: false
        /** The bouncer is being dragged by the user. */
        BOUNCER,
        /** A shade is being dragged by the user. */
        SHADE,
        /** No UI component is being dragged by the user. */
        NONE,
    }

    private fun InteractionState?.isDraggingVertically(): Boolean {
        return this?.draggedVertically != Dragged.NONE
    }
    }
}
}
+2 −6
Original line number Original line Diff line number Diff line
@@ -389,7 +389,6 @@ public final class NotificationPanelViewController implements Dumpable {
    private KeyguardBottomAreaView mKeyguardBottomArea;
    private KeyguardBottomAreaView mKeyguardBottomArea;
    private boolean mExpanding;
    private boolean mExpanding;
    private boolean mSplitShadeEnabled;
    private boolean mSplitShadeEnabled;
    private final boolean mMultiShadeEnabled;
    /** The bottom padding reserved for elements of the keyguard measuring notifications. */
    /** The bottom padding reserved for elements of the keyguard measuring notifications. */
    private float mKeyguardNotificationBottomPadding;
    private float mKeyguardNotificationBottomPadding;
    /**
    /**
@@ -854,7 +853,6 @@ public final class NotificationPanelViewController implements Dumpable {
        mFeatureFlags = featureFlags;
        mFeatureFlags = featureFlags;
        mAnimateBack = mFeatureFlags.isEnabled(Flags.WM_SHADE_ANIMATE_BACK_GESTURE);
        mAnimateBack = mFeatureFlags.isEnabled(Flags.WM_SHADE_ANIMATE_BACK_GESTURE);
        mTrackpadGestureBack = mFeatureFlags.isEnabled(Flags.TRACKPAD_GESTURE_FEATURES);
        mTrackpadGestureBack = mFeatureFlags.isEnabled(Flags.TRACKPAD_GESTURE_FEATURES);
        mMultiShadeEnabled = mFeatureFlags.isEnabled(Flags.DUAL_SHADE);
        mFalsingCollector = falsingCollector;
        mFalsingCollector = falsingCollector;
        mPowerManager = powerManager;
        mPowerManager = powerManager;
        mWakeUpCoordinator = coordinator;
        mWakeUpCoordinator = coordinator;
@@ -4024,10 +4022,8 @@ public final class NotificationPanelViewController implements Dumpable {
     *   {@link #updateVisibility()}? That would allow us to make this method private.
     *   {@link #updateVisibility()}? That would allow us to make this method private.
     */
     */
    public void updatePanelExpansionAndVisibility() {
    public void updatePanelExpansionAndVisibility() {
        if (!mMultiShadeEnabled) {
        mShadeExpansionStateManager.onPanelExpansionChanged(
        mShadeExpansionStateManager.onPanelExpansionChanged(
                mExpandedFraction, isExpanded(), mTracking, mExpansionDragDownAmountPx);
                mExpandedFraction, isExpanded(), mTracking, mExpansionDragDownAmountPx);
        }


        updateVisibility();
        updateVisibility();
    }
    }
+6 −20
Original line number Original line Diff line number Diff line
@@ -24,7 +24,6 @@ import com.android.systemui.classifier.FalsingManagerFake
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyguard.data.repository.FakeKeyguardTransitionRepository
import com.android.systemui.keyguard.data.repository.FakeKeyguardTransitionRepository
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
import com.android.systemui.keyguard.domain.interactor.PrimaryBouncerInteractor
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.keyguard.shared.model.TransitionStep
@@ -43,18 +42,12 @@ import org.junit.Before
import org.junit.Test
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.runners.JUnit4
import org.mockito.Mock
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations


@OptIn(ExperimentalCoroutinesApi::class)
@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@SmallTest
@RunWith(JUnit4::class)
@RunWith(JUnit4::class)
class MultiShadeMotionEventInteractorTest : SysuiTestCase() {
class MultiShadeMotionEventInteractorTest : SysuiTestCase() {


    @Mock private lateinit var bouncerInteractor: PrimaryBouncerInteractor

    private lateinit var underTest: MultiShadeMotionEventInteractor
    private lateinit var underTest: MultiShadeMotionEventInteractor


    private lateinit var testScope: TestScope
    private lateinit var testScope: TestScope
@@ -67,8 +60,6 @@ class MultiShadeMotionEventInteractorTest : SysuiTestCase() {


    @Before
    @Before
    fun setUp() {
    fun setUp() {
        MockitoAnnotations.initMocks(this)

        testScope = TestScope()
        testScope = TestScope()
        motionEvents = mutableSetOf()
        motionEvents = mutableSetOf()


@@ -95,7 +86,6 @@ class MultiShadeMotionEventInteractorTest : SysuiTestCase() {
                    KeyguardTransitionInteractor(
                    KeyguardTransitionInteractor(
                        repository = keyguardTransitionRepository,
                        repository = keyguardTransitionRepository,
                    ),
                    ),
                bouncerInteractor = bouncerInteractor,
                falsingManager = falsingManager,
                falsingManager = falsingManager,
            )
            )
    }
    }
@@ -400,7 +390,7 @@ class MultiShadeMotionEventInteractorTest : SysuiTestCase() {
        }
        }


    @Test
    @Test
    fun dragBouncerAboveTouchSlopAndUp_showsBouncer() =
    fun dragUp_withUp_doesNotShowShade() =
        testScope.runTest {
        testScope.runTest {
            val leftShadeProxiedInput by collectLastValue(interactor.proxiedInput(ShadeId.LEFT))
            val leftShadeProxiedInput by collectLastValue(interactor.proxiedInput(ShadeId.LEFT))
            val rightShadeProxiedInput by collectLastValue(interactor.proxiedInput(ShadeId.RIGHT))
            val rightShadeProxiedInput by collectLastValue(interactor.proxiedInput(ShadeId.RIGHT))
@@ -423,24 +413,22 @@ class MultiShadeMotionEventInteractorTest : SysuiTestCase() {
                    x = 100f, // left shade
                    x = 100f, // left shade
                    y = yDragAmountPx,
                    y = yDragAmountPx,
                )
                )
            assertThat(underTest.shouldIntercept(moveEvent)).isTrue()
            assertThat(underTest.shouldIntercept(moveEvent)).isFalse()
            underTest.onTouchEvent(moveEvent, viewWidthPx = 1000)
            underTest.onTouchEvent(moveEvent, viewWidthPx = 1000)
            verify(bouncerInteractor).show(isScrimmed = true)
            assertThat(leftShadeProxiedInput).isNull()
            assertThat(leftShadeProxiedInput).isNull()
            assertThat(rightShadeProxiedInput).isNull()
            assertThat(rightShadeProxiedInput).isNull()
            assertThat(singleShadeProxiedInput).isNull()
            assertThat(singleShadeProxiedInput).isNull()


            val upEvent = motionEvent(MotionEvent.ACTION_UP)
            val upEvent = motionEvent(MotionEvent.ACTION_UP)
            assertThat(underTest.shouldIntercept(upEvent)).isTrue()
            assertThat(underTest.shouldIntercept(upEvent)).isFalse()
            underTest.onTouchEvent(upEvent, viewWidthPx = 1000)
            underTest.onTouchEvent(upEvent, viewWidthPx = 1000)
            verify(bouncerInteractor, never()).hide()
            assertThat(leftShadeProxiedInput).isNull()
            assertThat(leftShadeProxiedInput).isNull()
            assertThat(rightShadeProxiedInput).isNull()
            assertThat(rightShadeProxiedInput).isNull()
            assertThat(singleShadeProxiedInput).isNull()
            assertThat(singleShadeProxiedInput).isNull()
        }
        }


    @Test
    @Test
    fun dragBouncerAboveTouchSlopAndCancel_falseTouch_showsThenHidesBouncer() =
    fun dragUp_withCancel_falseTouch_showsThenHidesBouncer() =
        testScope.runTest {
        testScope.runTest {
            val leftShadeProxiedInput by collectLastValue(interactor.proxiedInput(ShadeId.LEFT))
            val leftShadeProxiedInput by collectLastValue(interactor.proxiedInput(ShadeId.LEFT))
            val rightShadeProxiedInput by collectLastValue(interactor.proxiedInput(ShadeId.RIGHT))
            val rightShadeProxiedInput by collectLastValue(interactor.proxiedInput(ShadeId.RIGHT))
@@ -463,18 +451,16 @@ class MultiShadeMotionEventInteractorTest : SysuiTestCase() {
                    x = 900f, // right shade
                    x = 900f, // right shade
                    y = yDragAmountPx,
                    y = yDragAmountPx,
                )
                )
            assertThat(underTest.shouldIntercept(moveEvent)).isTrue()
            assertThat(underTest.shouldIntercept(moveEvent)).isFalse()
            underTest.onTouchEvent(moveEvent, viewWidthPx = 1000)
            underTest.onTouchEvent(moveEvent, viewWidthPx = 1000)
            verify(bouncerInteractor).show(isScrimmed = true)
            assertThat(leftShadeProxiedInput).isNull()
            assertThat(leftShadeProxiedInput).isNull()
            assertThat(rightShadeProxiedInput).isNull()
            assertThat(rightShadeProxiedInput).isNull()
            assertThat(singleShadeProxiedInput).isNull()
            assertThat(singleShadeProxiedInput).isNull()


            falsingManager.setIsFalseTouch(true)
            falsingManager.setIsFalseTouch(true)
            val cancelEvent = motionEvent(MotionEvent.ACTION_CANCEL)
            val cancelEvent = motionEvent(MotionEvent.ACTION_CANCEL)
            assertThat(underTest.shouldIntercept(cancelEvent)).isTrue()
            assertThat(underTest.shouldIntercept(cancelEvent)).isFalse()
            underTest.onTouchEvent(cancelEvent, viewWidthPx = 1000)
            underTest.onTouchEvent(cancelEvent, viewWidthPx = 1000)
            verify(bouncerInteractor).hide()
            assertThat(leftShadeProxiedInput).isNull()
            assertThat(leftShadeProxiedInput).isNull()
            assertThat(rightShadeProxiedInput).isNull()
            assertThat(rightShadeProxiedInput).isNull()
            assertThat(singleShadeProxiedInput).isNull()
            assertThat(singleShadeProxiedInput).isNull()
+0 −1
Original line number Original line Diff line number Diff line
@@ -177,7 +177,6 @@ class NotificationShadeWindowViewControllerTest : SysuiTestCase() {
                            KeyguardTransitionInteractor(
                            KeyguardTransitionInteractor(
                                repository = FakeKeyguardTransitionRepository(),
                                repository = FakeKeyguardTransitionRepository(),
                            ),
                            ),
                        bouncerInteractor = com.android.systemui.util.mockito.mock(),
                        falsingManager = FalsingManagerFake(),
                        falsingManager = FalsingManagerFake(),
                    )
                    )
                },
                },
+0 −1
Original line number Original line Diff line number Diff line
@@ -189,7 +189,6 @@ class NotificationShadeWindowViewTest : SysuiTestCase() {
                            KeyguardTransitionInteractor(
                            KeyguardTransitionInteractor(
                                repository = FakeKeyguardTransitionRepository(),
                                repository = FakeKeyguardTransitionRepository(),
                            ),
                            ),
                        bouncerInteractor = mock(),
                        falsingManager = FalsingManagerFake(),
                        falsingManager = FalsingManagerFake(),
                    )
                    )
                },
                },