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

Commit 9e87c396 authored by Sherry Zhou's avatar Sherry Zhou
Browse files

Pass tap event from keyguard to magic portrait

Test: atest WallpaperFocalAreaInteractorTest
Bug: 370556290
Flag: com.android.systemui.shared.extended_wallpaper_effects

Change-Id: If520415129ea48e7cf7f943a29dfbfdc6d99a17f
parent 45d73de7
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -296,6 +296,16 @@ public class WallpaperManager {
    public static final String COMMAND_LOCKSCREEN_LAYOUT_CHANGED =
            "android.wallpaper.lockscreen_layout_changed";

    /**
     * Command for {@link #sendWallpaperCommand}:  Include the tap position within the wallpaper
     * focal area.The x and y arguments are the absolute tap coordinates, already scaled to match
     * the wallpaper's dimensions.
     *
     * @hide
     */
    public static final String COMMAND_LOCKSCREEN_TAP =
            "android.wallpaper.lockscreen_tap";

    /**
     * Extra passed back from setWallpaper() giving the new wallpaper's assigned ID.
     * @hide
+14 −39
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ class LongPressHandlingViewInteractionHandlerTest : SysuiTestCase() {

    @Mock private lateinit var postDelayed: (Runnable, Long) -> DisposableHandle
    @Mock private lateinit var onLongPressDetected: (Int, Int) -> Unit
    @Mock private lateinit var onSingleTapDetected: () -> Unit
    @Mock private lateinit var onSingleTapDetected: (Int, Int) -> Unit

    private lateinit var underTest: LongPressHandlingViewInteractionHandler

@@ -76,74 +76,51 @@ class LongPressHandlingViewInteractionHandlerTest : SysuiTestCase() {
        val downX = 123
        val downY = 456
        dispatchTouchEvents(
            Down(
                x = downX,
                y = downY,
            ),
            Move(
                distanceMoved = ViewConfiguration.getTouchSlop() - 0.1f,
            ),
            Down(x = downX, y = downY),
            Move(distanceMoved = ViewConfiguration.getTouchSlop() - 0.1f),
        )
        delayedRunnable?.run()

        verify(onLongPressDetected).invoke(downX, downY)
        verify(onSingleTapDetected, never()).invoke()
        verify(onSingleTapDetected, never()).invoke(any(), any())
    }

    @Test
    fun longPressButFeatureNotEnabled() = runTest {
        underTest.isLongPressHandlingEnabled = false
        dispatchTouchEvents(
            Down(
                x = 123,
                y = 456,
            ),
        )
        dispatchTouchEvents(Down(x = 123, y = 456))

        assertThat(delayedRunnable).isNull()
        verify(onLongPressDetected, never()).invoke(any(), any())
        verify(onSingleTapDetected, never()).invoke()
        verify(onSingleTapDetected, never()).invoke(any(), any())
    }

    @Test
    fun longPressButViewNotAttached() = runTest {
        isAttachedToWindow = false
        dispatchTouchEvents(
            Down(
                x = 123,
                y = 456,
            ),
        )
        dispatchTouchEvents(Down(x = 123, y = 456))
        delayedRunnable?.run()

        verify(onLongPressDetected, never()).invoke(any(), any())
        verify(onSingleTapDetected, never()).invoke()
        verify(onSingleTapDetected, never()).invoke(any(), any())
    }

    @Test
    fun draggedTooFarToBeConsideredAlongPress() = runTest {
        dispatchTouchEvents(
            Down(
                x = 123,
                y = 456,
            ),
            Move(
                distanceMoved = ViewConfiguration.getTouchSlop() + 0.1f,
            ),
            Down(x = 123, y = 456),
            Move(distanceMoved = ViewConfiguration.getTouchSlop() + 0.1f),
        )

        assertThat(delayedRunnable).isNull()
        verify(onLongPressDetected, never()).invoke(any(), any())
        verify(onSingleTapDetected, never()).invoke()
        verify(onSingleTapDetected, never()).invoke(any(), any())
    }

    @Test
    fun heldDownTooBrieflyToBeConsideredAlongPress() = runTest {
        dispatchTouchEvents(
            Down(
                x = 123,
                y = 456,
            ),
            Down(x = 123, y = 456),
            Up(
                distanceMoved = ViewConfiguration.getTouchSlop().toFloat(),
                gestureDuration = ViewConfiguration.getLongPressTimeout() - 1L,
@@ -152,12 +129,10 @@ class LongPressHandlingViewInteractionHandlerTest : SysuiTestCase() {

        assertThat(delayedRunnable).isNull()
        verify(onLongPressDetected, never()).invoke(any(), any())
        verify(onSingleTapDetected).invoke()
        verify(onSingleTapDetected).invoke(123, 456)
    }

    private fun dispatchTouchEvents(
        vararg models: MotionEventModel,
    ) {
    private fun dispatchTouchEvents(vararg models: MotionEventModel) {
        models.forEach { model -> underTest.onTouchEvent(model) }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -167,6 +167,7 @@ import com.android.systemui.user.domain.interactor.UserSwitcherInteractor;
import com.android.systemui.util.kotlin.JavaAdapter;
import com.android.systemui.util.time.FakeSystemClock;
import com.android.systemui.util.time.SystemClock;
import com.android.systemui.wallpapers.ui.viewmodel.WallpaperFocalAreaViewModel;
import com.android.wm.shell.animation.FlingAnimationUtils;

import dagger.Lazy;
@@ -270,6 +271,7 @@ public class NotificationPanelViewControllerBaseTest extends SysuiTestCase {
            mDreamingToLockscreenTransitionViewModel;
    @Mock protected KeyguardTransitionInteractor mKeyguardTransitionInteractor;
    @Mock protected KeyguardTouchHandlingViewModel mKeyuardTouchHandlingViewModel;
    @Mock protected WallpaperFocalAreaViewModel mWallpaperFocalAreaViewModel;
    @Mock protected AlternateBouncerInteractor mAlternateBouncerInteractor;
    @Mock protected MotionEvent mDownMotionEvent;
    @Mock protected CoroutineDispatcher mMainDispatcher;
@@ -574,6 +576,7 @@ public class NotificationPanelViewControllerBaseTest extends SysuiTestCase {
                mKeyguardTransitionInteractor,
                mDumpManager,
                mKeyuardTouchHandlingViewModel,
                mWallpaperFocalAreaViewModel,
                mKeyguardInteractor,
                mActivityStarter,
                mSharedNotificationContainerInteractor,
+1 −1
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ class WallpaperControllerTest : SysuiTestCase() {

    @Test
    fun setUnfoldTransitionZoom_defaultUnfoldTransitionIsDisabled_doesNotUpdateWallpaperZoom() {
        wallpaperRepository.wallpaperInfo.value = createWallpaperInfo(useDefaultTransition = false)
        wallpaperRepository.setWallpaperInfo(createWallpaperInfo(useDefaultTransition = false))

        wallaperController.setUnfoldTransitionZoom(0.5f)

+2 −5
Original line number Diff line number Diff line
@@ -27,8 +27,6 @@ import androidx.test.filters.SmallTest
import com.android.internal.R
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyguard.data.repository.FakeKeyguardClockRepository
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
import com.android.systemui.res.R as SysUIR
import com.android.systemui.shared.Flags as SharedFlags
import com.android.systemui.user.data.model.SelectedUserModel
@@ -53,8 +51,7 @@ class WallpaperRepositoryImplTest : SysuiTestCase() {
    private val testDispatcher = StandardTestDispatcher()
    private val testScope = TestScope(testDispatcher)
    private val userRepository = FakeUserRepository()
    private val keyguardClockRepository = FakeKeyguardClockRepository()
    private val keyguardRepository = FakeKeyguardRepository()
    private val wallpaperFocalAreaRepository = FakeWallpaperFocalAreaRepository()
    private val wallpaperManager: WallpaperManager = mock()

    private val underTest: WallpaperRepositoryImpl by lazy {
@@ -63,7 +60,7 @@ class WallpaperRepositoryImplTest : SysuiTestCase() {
            testDispatcher,
            fakeBroadcastDispatcher,
            userRepository,
            keyguardRepository,
            wallpaperFocalAreaRepository,
            wallpaperManager,
            context,
        )
Loading