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

Commit adc55c69 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[flexiglass] Separates isBypassEnabled from DeviceEntryInteractor" into main

parents ffbba997 cf8293c3
Loading
Loading
Loading
Loading
+69 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.deviceentry.data.repository

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runCurrent
import com.android.systemui.kosmos.runTest
import com.android.systemui.statusbar.phone.keyguardBypassController
import com.android.systemui.testKosmos
import com.android.systemui.util.mockito.withArgCaptor
import com.google.common.truth.Truth.assertThat
import kotlin.test.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever

@SmallTest
@RunWith(AndroidJUnit4::class)
class DeviceEntryBypassRepositoryTest : SysuiTestCase() {

    private val kosmos = testKosmos()
    private val underTest = kosmos.deviceEntryBypassRepositoryImpl

    @Test
    fun isBypassEnabled_enabledInController() =
        kosmos.runTest {
            whenever(keyguardBypassController.isBypassEnabled).thenAnswer { true }
            whenever(keyguardBypassController.bypassEnabled).thenAnswer { true }
            val isBypassEnabled by collectLastValue(underTest.isBypassEnabled)
            runCurrent()
            withArgCaptor {
                    verify(keyguardBypassController).registerOnBypassStateChangedListener(capture())
                }
                .onBypassStateChanged(true)
            assertThat(isBypassEnabled).isTrue()
        }

    @Test
    fun isBypassEnabled_disabledInController() =
        kosmos.runTest {
            whenever(keyguardBypassController.isBypassEnabled).thenAnswer { false }
            whenever(keyguardBypassController.bypassEnabled).thenAnswer { false }
            val isBypassEnabled by collectLastValue(underTest.isBypassEnabled)
            runCurrent()
            withArgCaptor {
                    verify(keyguardBypassController).registerOnBypassStateChangedListener(capture())
                }
                .onBypassStateChanged(false)
            runCurrent()
            assertThat(isBypassEnabled).isFalse()
        }
}
+7 −48
Original line number Diff line number Diff line
@@ -5,22 +5,18 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.internal.widget.LockPatternUtils
import com.android.systemui.SysuiTestCase
import com.android.systemui.kosmos.runCurrent
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.kosmos.testScope
import com.android.systemui.statusbar.phone.KeyguardBypassController
import com.android.systemui.testKosmos
import com.android.systemui.user.data.repository.FakeUserRepository
import com.android.systemui.util.mockito.whenever
import com.android.systemui.util.mockito.withArgCaptor
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.runBlocking
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.Mock
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations

@SmallTest
@@ -29,10 +25,8 @@ import org.mockito.MockitoAnnotations
class DeviceEntryRepositoryTest : SysuiTestCase() {

    @Mock private lateinit var lockPatternUtils: LockPatternUtils
    @Mock private lateinit var keyguardBypassController: KeyguardBypassController

    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val userRepository = FakeUserRepository()

    private lateinit var underTest: DeviceEntryRepository
@@ -45,17 +39,16 @@ class DeviceEntryRepositoryTest : SysuiTestCase() {

        underTest =
            DeviceEntryRepositoryImpl(
                applicationScope = testScope.backgroundScope,
                backgroundDispatcher = kosmos.testDispatcher,
                userRepository = userRepository,
                lockPatternUtils = lockPatternUtils,
                keyguardBypassController = keyguardBypassController,
            )
        testScope.runCurrent()
        kosmos.runCurrent()
    }

    @Test
    fun isLockscreenEnabled() =
        testScope.runTest {
        kosmos.runTest {
            whenever(lockPatternUtils.isLockScreenDisabled(USER_INFOS[0].id)).thenReturn(false)
            whenever(lockPatternUtils.isLockScreenDisabled(USER_INFOS[1].id)).thenReturn(true)

@@ -66,45 +59,11 @@ class DeviceEntryRepositoryTest : SysuiTestCase() {
            assertThat(underTest.isLockscreenEnabled()).isFalse()
        }

    @Test
    fun isBypassEnabled_disabledInController() =
        testScope.runTest {
            whenever(keyguardBypassController.isBypassEnabled).thenAnswer { false }
            whenever(keyguardBypassController.bypassEnabled).thenAnswer { false }
            withArgCaptor {
                    verify(keyguardBypassController).registerOnBypassStateChangedListener(capture())
                }
                .onBypassStateChanged(false)
            runCurrent()
            assertThat(underTest.isBypassEnabled.value).isFalse()
        }

    @Test
    fun isBypassEnabled_enabledInController() =
        testScope.runTest {
            whenever(keyguardBypassController.isBypassEnabled).thenAnswer { true }
            whenever(keyguardBypassController.bypassEnabled).thenAnswer { true }
            withArgCaptor {
                    verify(keyguardBypassController).registerOnBypassStateChangedListener(capture())
                }
                .onBypassStateChanged(true)
            runCurrent()
            assertThat(underTest.isBypassEnabled.value).isTrue()
        }

    companion object {
        private val USER_INFOS =
            listOf(
                UserInfo(
                    /* id= */ 100,
                    /* name= */ "First user",
                    /* flags= */ 0,
                ),
                UserInfo(
                    /* id= */ 101,
                    /* name= */ "Second user",
                    /* flags= */ 0,
                ),
                UserInfo(/* id= */ 100, /* name= */ "First user", /* flags= */ 0),
                UserInfo(/* id= */ 101, /* name= */ "Second user", /* flags= */ 0),
            )
    }
}
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.deviceentry.domain.interactor

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.deviceentry.data.repository.fakeDeviceEntryBypassRepository
import com.android.systemui.kosmos.runTest
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class DeviceEntryBypassInteractorTest : SysuiTestCase() {

    private val kosmos = testKosmos()
    private val underTest = kosmos.deviceEntryBypassInteractor

    @Test
    fun isBypassEnabled_enabledInRepository_true() =
        kosmos.runTest {
            fakeDeviceEntryBypassRepository.setBypassEnabled(true)
            assertThat(underTest.isBypassEnabled.value).isTrue()
        }

    @Test
    fun isBypassEnabled_disabledInRepository_false() =
        kosmos.runTest {
            fakeDeviceEntryBypassRepository.setBypassEnabled(false)
            assertThat(underTest.isBypassEnabled.value).isFalse()
        }
}
+0 −14
Original line number Diff line number Diff line
@@ -310,13 +310,6 @@ class DeviceEntryInteractorTest : SysuiTestCase() {
            assertThat(underTest.isAuthenticationRequired()).isFalse()
        }

    @Test
    fun isBypassEnabled_enabledInRepository_true() =
        testScope.runTest {
            kosmos.fakeDeviceEntryRepository.setBypassEnabled(true)
            assertThat(underTest.isBypassEnabled.value).isTrue()
        }

    @Test
    fun showOrUnlockDevice_notLocked_switchesToGoneScene() =
        testScope.runTest {
@@ -409,13 +402,6 @@ class DeviceEntryInteractorTest : SysuiTestCase() {
            assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
        }

    @Test
    fun isBypassEnabled_disabledInRepository_false() =
        testScope.runTest {
            kosmos.fakeDeviceEntryRepository.setBypassEnabled(false)
            assertThat(underTest.isBypassEnabled.value).isFalse()
        }

    @Test
    fun successfulAuthenticationChallengeAttempt_updatesIsUnlockedState() =
        testScope.runTest {
+3 −3
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.authentication.data.repository.fakeAuthenticationRepository
import com.android.systemui.authentication.shared.model.AuthenticationMethodModel
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.deviceentry.data.repository.fakeDeviceEntryRepository
import com.android.systemui.deviceentry.data.repository.fakeDeviceEntryBypassRepository
import com.android.systemui.deviceentry.shared.model.DeviceEntryRestrictionReason
import com.android.systemui.deviceentry.shared.model.DeviceUnlockSource
import com.android.systemui.flags.fakeSystemPropertiesHelper
@@ -175,7 +175,7 @@ class DeviceUnlockedInteractorTest : SysuiTestCase() {
            kosmos.powerInteractor.setAwakeForTest()

            kosmos.fakeDeviceEntryFaceAuthRepository.isAuthenticated.value = true
            kosmos.fakeDeviceEntryRepository.setBypassEnabled(true)
            kosmos.fakeDeviceEntryBypassRepository.setBypassEnabled(true)
            runCurrent()

            assertThat(deviceUnlockStatus?.isUnlocked).isTrue()
@@ -189,7 +189,7 @@ class DeviceUnlockedInteractorTest : SysuiTestCase() {
            val deviceUnlockStatus by collectLastValue(underTest.deviceUnlockStatus)

            kosmos.fakeDeviceEntryFaceAuthRepository.isAuthenticated.value = true
            kosmos.fakeDeviceEntryRepository.setBypassEnabled(false)
            kosmos.fakeDeviceEntryBypassRepository.setBypassEnabled(false)
            runCurrent()

            assertThat(deviceUnlockStatus?.isUnlocked).isTrue()
Loading