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

Commit c3184204 authored by Alejandro Nijamkin's avatar Alejandro Nijamkin
Browse files

[flexiglass] Report userPresent when device entered.

In order to let system server know that authentication occurred since
the device was last booted (which is required to allow non-strong auth
to unlock the device), System UI needs to send a signal to system
server. This CL adds that signal.

Fix: 350542144
Test: unit test added
Test: manually verified that, after the first strong auth unlock of the
device after boot, non-strong auth (fingerprint was tested) is allowed
Flag: com.android.systemui.scene_container

Change-Id: I3a20f40047402d2eb1fec8f527e9b02ab178ba31
parent 4b415605
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -617,6 +617,33 @@ class DeviceEntryInteractorTest : SysuiTestCase() {
                .isEqualTo(DeviceEntryRestrictionReason.DeviceNotUnlockedSinceMainlineUpdate)
        }

    @Test
    fun reportUserPresent_whenDeviceEntered() =
        testScope.runTest {
            val isDeviceEntered by collectLastValue(underTest.isDeviceEntered)
            assertThat(isDeviceEntered).isFalse()
            assertThat(kosmos.fakeDeviceEntryRepository.userPresentCount).isEqualTo(0)

            kosmos.fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus(
                SuccessFingerprintAuthenticationStatus(0, true)
            )
            runCurrent()
            switchToScene(Scenes.Gone)
            assertThat(isDeviceEntered).isTrue()
            assertThat(kosmos.fakeDeviceEntryRepository.userPresentCount).isEqualTo(1)

            switchToScene(Scenes.Lockscreen)
            assertThat(isDeviceEntered).isFalse()
            assertThat(kosmos.fakeDeviceEntryRepository.userPresentCount).isEqualTo(1)

            kosmos.fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus(
                SuccessFingerprintAuthenticationStatus(0, true)
            )
            switchToScene(Scenes.Gone)
            assertThat(isDeviceEntered).isTrue()
            assertThat(kosmos.fakeDeviceEntryRepository.userPresentCount).isEqualTo(2)
        }

    private fun TestScope.verifyRestrictionReasonsForAuthFlags(
        vararg authFlagToDeviceEntryRestriction: Pair<Int, DeviceEntryRestrictionReason?>
    ) {
+13 −0
Original line number Diff line number Diff line
@@ -39,6 +39,12 @@ interface DeviceEntryRepository {
     * the lockscreen.
     */
    val isBypassEnabled: StateFlow<Boolean>

    /**
     * Reports, to system server, that the user is "present" now. This is a signal that system
     * server uses to know that the device has been entered.
     */
    suspend fun reportUserPresent()
}

/** Encapsulates application state for device entry. */
@@ -79,6 +85,13 @@ constructor(
                initialValue = keyguardBypassController.bypassEnabled,
            )

    override suspend fun reportUserPresent() {
        withContext(backgroundDispatcher) {
            val selectedUserId = userRepository.selectedUser.value.userInfo.id
            lockPatternUtils.userPresent(selectedUserId)
        }
    }

    companion object {
        private const val TAG = "DeviceEntryRepositoryImpl"
    }
+6 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch

@@ -108,6 +109,11 @@ constructor(
                    false
                }
            }
            .onEach { isDeviceEntered ->
                if (isDeviceEntered) {
                    repository.reportUserPresent()
                }
            }
            .stateIn(
                scope = applicationScope,
                started = SharingStarted.Eagerly,
+6 −0
Original line number Diff line number Diff line
@@ -30,10 +30,16 @@ class FakeDeviceEntryRepository @Inject constructor() : DeviceEntryRepository {
    private val _isBypassEnabled = MutableStateFlow(false)
    override val isBypassEnabled: StateFlow<Boolean> = _isBypassEnabled

    var userPresentCount = 0

    override suspend fun isLockscreenEnabled(): Boolean {
        return isLockscreenEnabled
    }

    override suspend fun reportUserPresent() {
        userPresentCount++
    }

    fun setLockscreenEnabled(isLockscreenEnabled: Boolean) {
        this.isLockscreenEnabled = isLockscreenEnabled
    }