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

Commit 0b56bd3d authored by Matt Pietal's avatar Matt Pietal Committed by Android (Google) Code Review
Browse files

Merge "Remove dreaming hosted lockscreen - Part #4 (end)" into main

parents 1ce6b9ea 87bd231d
Loading
Loading
Loading
Loading
+9 −24
Original line number Diff line number Diff line
@@ -313,16 +313,6 @@ class KeyguardRepositoryImplTest : SysuiTestCase() {
            verify(statusBarStateController).removeCallback(any())
        }

    @Test
    fun isActiveDreamLockscreenHosted() =
        testScope.runTest {
            underTest.setIsActiveDreamLockscreenHosted(true)
            assertThat(underTest.isActiveDreamLockscreenHosted.value).isEqualTo(true)

            underTest.setIsActiveDreamLockscreenHosted(false)
            assertThat(underTest.isActiveDreamLockscreenHosted.value).isEqualTo(false)
        }

    @Test
    fun isUdfpsSupported() =
        testScope.runTest {
@@ -423,17 +413,17 @@ class KeyguardRepositoryImplTest : SysuiTestCase() {
            runCurrent()
            listener.onDozeTransition(
                DozeMachine.State.DOZE_REQUEST_PULSE,
                DozeMachine.State.DOZE_PULSING
                DozeMachine.State.DOZE_PULSING,
            )
            runCurrent()
            listener.onDozeTransition(
                DozeMachine.State.DOZE_SUSPEND_TRIGGERS,
                DozeMachine.State.DOZE_PULSE_DONE
                DozeMachine.State.DOZE_PULSE_DONE,
            )
            runCurrent()
            listener.onDozeTransition(
                DozeMachine.State.DOZE_AOD_PAUSING,
                DozeMachine.State.DOZE_AOD_PAUSED
                DozeMachine.State.DOZE_AOD_PAUSED,
            )
            runCurrent()

@@ -443,22 +433,22 @@ class KeyguardRepositoryImplTest : SysuiTestCase() {
                        // Initial value will be UNINITIALIZED
                        DozeTransitionModel(
                            DozeStateModel.UNINITIALIZED,
                            DozeStateModel.UNINITIALIZED
                            DozeStateModel.UNINITIALIZED,
                        ),
                        DozeTransitionModel(DozeStateModel.INITIALIZED, DozeStateModel.DOZE),
                        DozeTransitionModel(DozeStateModel.DOZE, DozeStateModel.DOZE_AOD),
                        DozeTransitionModel(DozeStateModel.DOZE_AOD_DOCKED, DozeStateModel.FINISH),
                        DozeTransitionModel(
                            DozeStateModel.DOZE_REQUEST_PULSE,
                            DozeStateModel.DOZE_PULSING
                            DozeStateModel.DOZE_PULSING,
                        ),
                        DozeTransitionModel(
                            DozeStateModel.DOZE_SUSPEND_TRIGGERS,
                            DozeStateModel.DOZE_PULSE_DONE
                            DozeStateModel.DOZE_PULSE_DONE,
                        ),
                        DozeTransitionModel(
                            DozeStateModel.DOZE_AOD_PAUSING,
                            DozeStateModel.DOZE_AOD_PAUSED
                            DozeStateModel.DOZE_AOD_PAUSED,
                        ),
                    )
                )
@@ -510,12 +500,7 @@ class KeyguardRepositoryImplTest : SysuiTestCase() {
            // consuming it should handle that properly.
            assertThat(values).isEqualTo(listOf(null))

            listOf(
                    Point(500, 500),
                    Point(0, 0),
                    null,
                    Point(250, 250),
                )
            listOf(Point(500, 500), Point(0, 0), null, Point(250, 250))
                .onEach {
                    facePropertyRepository.setSensorLocation(it)
                    runCurrent()
@@ -551,7 +536,7 @@ class KeyguardRepositoryImplTest : SysuiTestCase() {
                .onEach { biometricSourceType ->
                    underTest.setBiometricUnlockState(
                        BiometricUnlockMode.NONE,
                        BiometricUnlockSource.Companion.fromBiometricSourceType(biometricSourceType)
                        BiometricUnlockSource.Companion.fromBiometricSourceType(biometricSourceType),
                    )
                    runCurrent()
                }
+0 −11
Original line number Diff line number Diff line
@@ -171,17 +171,6 @@ class KeyguardClockInteractorTest : SysuiTestCase() {
            assertThat(value).isTrue()
        }

    @Test
    @EnableSceneContainer
    fun clockShouldBeCentered_sceneContainerFlagOn_splitMode_isActiveDreamLockscreenHosted_true() =
        testScope.runTest {
            val value by collectLastValue(underTest.clockShouldBeCentered)
            kosmos.shadeRepository.setShadeLayoutWide(true)
            kosmos.activeNotificationListRepository.setActiveNotifs(1)
            kosmos.keyguardRepository.setIsActiveDreamLockscreenHosted(true)
            assertThat(value).isTrue()
        }

    @Test
    @EnableSceneContainer
    fun clockShouldBeCentered_sceneContainerFlagOn_splitMode_hasPulsingNotifications_false() =
+0 −185
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.shade

import android.os.PowerManager
import android.view.MotionEvent
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.bouncer.domain.interactor.PrimaryBouncerInteractor
import com.android.systemui.classifier.FalsingCollector
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
import com.android.systemui.plugins.FalsingManager
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.power.data.repository.FakePowerRepository
import com.android.systemui.power.domain.interactor.PowerInteractorFactory
import com.android.systemui.statusbar.StatusBarState
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers
import org.mockito.Mock
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations

@SmallTest
@OptIn(ExperimentalCoroutinesApi::class)
@RunWith(AndroidJUnit4::class)
class LockscreenHostedDreamGestureListenerTest : SysuiTestCase() {
    @Mock private lateinit var falsingManager: FalsingManager
    @Mock private lateinit var falsingCollector: FalsingCollector
    @Mock private lateinit var statusBarStateController: StatusBarStateController
    @Mock private lateinit var shadeLogger: ShadeLogger
    @Mock private lateinit var primaryBouncerInteractor: PrimaryBouncerInteractor

    private val testDispatcher = UnconfinedTestDispatcher()
    private val testScope = TestScope(testDispatcher)

    private lateinit var powerRepository: FakePowerRepository
    private lateinit var keyguardRepository: FakeKeyguardRepository
    private lateinit var underTest: LockscreenHostedDreamGestureListener

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

        powerRepository = FakePowerRepository()
        keyguardRepository = FakeKeyguardRepository()

        underTest =
            LockscreenHostedDreamGestureListener(
                falsingManager,
                PowerInteractorFactory.create(
                        repository = powerRepository,
                        statusBarStateController = statusBarStateController,
                    )
                    .powerInteractor,
                statusBarStateController,
                primaryBouncerInteractor,
                keyguardRepository,
                shadeLogger,
            )
        whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD)
        whenever(primaryBouncerInteractor.isBouncerShowing()).thenReturn(false)
    }

    @Test
    fun testGestureDetector_onSingleTap_whileDreaming() =
        testScope.runTest {
            // GIVEN device dreaming and the dream is hosted in lockscreen
            whenever(statusBarStateController.isDreaming).thenReturn(true)
            keyguardRepository.setIsActiveDreamLockscreenHosted(true)
            testScope.runCurrent()

            // GIVEN the falsing manager does NOT think the tap is a false tap
            whenever(falsingManager.isFalseTap(ArgumentMatchers.anyInt())).thenReturn(false)

            // WHEN there's a tap
            underTest.onSingleTapUp(upEv)

            // THEN wake up device if dreaming
            Truth.assertThat(powerRepository.lastWakeWhy).isNotNull()
            Truth.assertThat(powerRepository.lastWakeReason).isEqualTo(PowerManager.WAKE_REASON_TAP)
        }

    @Test
    fun testGestureDetector_onSingleTap_notOnKeyguard() =
        testScope.runTest {
            // GIVEN device dreaming and the dream is hosted in lockscreen
            whenever(statusBarStateController.isDreaming).thenReturn(true)
            keyguardRepository.setIsActiveDreamLockscreenHosted(true)
            testScope.runCurrent()

            // GIVEN shade is open
            whenever(statusBarStateController.state).thenReturn(StatusBarState.SHADE)

            // GIVEN the falsing manager does NOT think the tap is a false tap
            whenever(falsingManager.isFalseTap(ArgumentMatchers.anyInt())).thenReturn(false)

            // WHEN there's a tap
            underTest.onSingleTapUp(upEv)

            // THEN the falsing manager never gets a call
            verify(falsingManager, never()).isFalseTap(ArgumentMatchers.anyInt())
        }

    @Test
    fun testGestureDetector_onSingleTap_bouncerShown() =
        testScope.runTest {
            // GIVEN device dreaming and the dream is hosted in lockscreen
            whenever(statusBarStateController.isDreaming).thenReturn(true)
            keyguardRepository.setIsActiveDreamLockscreenHosted(true)
            testScope.runCurrent()

            // GIVEN bouncer is expanded
            whenever(primaryBouncerInteractor.isBouncerShowing()).thenReturn(true)

            // GIVEN the falsing manager does NOT think the tap is a false tap
            whenever(falsingManager.isFalseTap(ArgumentMatchers.anyInt())).thenReturn(false)

            // WHEN there's a tap
            underTest.onSingleTapUp(upEv)

            // THEN the falsing manager never gets a call
            verify(falsingManager, never()).isFalseTap(ArgumentMatchers.anyInt())
        }

    @Test
    fun testGestureDetector_onSingleTap_falsing() =
        testScope.runTest {
            // GIVEN device dreaming and the dream is hosted in lockscreen
            whenever(statusBarStateController.isDreaming).thenReturn(true)
            keyguardRepository.setIsActiveDreamLockscreenHosted(true)
            testScope.runCurrent()

            // GIVEN the falsing manager thinks the tap is a false tap
            whenever(falsingManager.isFalseTap(ArgumentMatchers.anyInt())).thenReturn(true)

            // WHEN there's a tap
            underTest.onSingleTapUp(upEv)

            // THEN the device doesn't wake up
            Truth.assertThat(powerRepository.lastWakeWhy).isNull()
            Truth.assertThat(powerRepository.lastWakeReason).isNull()
        }

    @Test
    fun testSingleTap_notDreaming_noFalsingCheck() =
        testScope.runTest {
            // GIVEN device not dreaming with lockscreen hosted dream
            whenever(statusBarStateController.isDreaming).thenReturn(false)
            keyguardRepository.setIsActiveDreamLockscreenHosted(false)
            testScope.runCurrent()

            // WHEN there's a tap
            underTest.onSingleTapUp(upEv)

            // THEN the falsing manager never gets a call
            verify(falsingManager, never()).isFalseTap(ArgumentMatchers.anyInt())
        }
}

private val upEv = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_UP, 0f, 0f, 0)
+1 −6
Original line number Diff line number Diff line
@@ -165,7 +165,7 @@ object Flags {
    val QS_USER_DETAIL_SHORTCUT =
        resourceBooleanFlag(
            R.bool.flag_lockscreen_qs_user_detail_shortcut,
            "qs_user_detail_shortcut"
            "qs_user_detail_shortcut",
        )

    // TODO(b/254512383): Tracking Bug
@@ -365,11 +365,6 @@ object Flags {
    val ZJ_285570694_LOCKSCREEN_TRANSITION_FROM_AOD =
        releasedFlag("zj_285570694_lockscreen_transition_from_aod")

    // 3000 - dream
    // TODO(b/285059790) : Tracking Bug
    @JvmField
    val LOCKSCREEN_WALLPAPER_DREAM_ENABLED = unreleasedFlag("enable_lockscreen_wallpaper_dream")

    // TODO(b/283447257): Tracking bug
    @JvmField
    val BIGPICTURE_NOTIFICATION_LAZY_LOADING =
+0 −12
Original line number Diff line number Diff line
@@ -184,9 +184,6 @@ interface KeyguardRepository {
    /** Observable for whether the device is dreaming with an overlay, see [DreamOverlayService] */
    val isDreamingWithOverlay: Flow<Boolean>

    /** Observable for device dreaming state and the active dream is hosted in lockscreen */
    val isActiveDreamLockscreenHosted: StateFlow<Boolean>

    /**
     * Observable for the amount of doze we are currently in.
     *
@@ -308,8 +305,6 @@ interface KeyguardRepository {

    fun setIsDozing(isDozing: Boolean)

    fun setIsActiveDreamLockscreenHosted(isLockscreenHosted: Boolean)

    fun dozeTimeTick()

    fun showDismissibleKeyguard()
@@ -637,9 +632,6 @@ constructor(
    private val _isQuickSettingsVisible = MutableStateFlow(false)
    override val isQuickSettingsVisible: Flow<Boolean> = _isQuickSettingsVisible.asStateFlow()

    private val _isActiveDreamLockscreenHosted = MutableStateFlow(false)
    override val isActiveDreamLockscreenHosted = _isActiveDreamLockscreenHosted.asStateFlow()

    private val _shortcutAbsoluteTop = MutableStateFlow(0F)
    override val shortcutAbsoluteTop = _shortcutAbsoluteTop.asStateFlow()

@@ -698,10 +690,6 @@ constructor(
        _isQuickSettingsVisible.value = isVisible
    }

    override fun setIsActiveDreamLockscreenHosted(isLockscreenHosted: Boolean) {
        _isActiveDreamLockscreenHosted.value = isLockscreenHosted
    }

    override fun setClockShouldBeCentered(shouldBeCentered: Boolean) {
        _clockShouldBeCentered.value = shouldBeCentered
    }
Loading