• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.deviceentry.domain.interactor
18 
19 import com.android.systemui.dagger.SysUISingleton
20 import com.android.systemui.deviceentry.shared.DeviceEntryBiometricMode
21 import com.android.systemui.deviceentry.shared.model.FailedFaceAuthenticationStatus
22 import com.android.systemui.keyguard.data.repository.BiometricSettingsRepository
23 import javax.inject.Inject
24 import kotlinx.coroutines.flow.Flow
25 import kotlinx.coroutines.flow.combine
26 import kotlinx.coroutines.flow.emptyFlow
27 import kotlinx.coroutines.flow.filterIsInstance
28 import kotlinx.coroutines.flow.flatMapLatest
29 import kotlinx.coroutines.flow.map
30 
31 /** Business logic for device entry biometric states that may differ based on the biometric mode. */
32 @SysUISingleton
33 class DeviceEntryBiometricAuthInteractor
34 @Inject
35 constructor(
36     biometricSettingsRepository: BiometricSettingsRepository,
37     deviceEntryFaceAuthInteractor: DeviceEntryFaceAuthInteractor,
38 ) {
39     private val biometricMode: Flow<DeviceEntryBiometricMode> =
40         combine(
41             biometricSettingsRepository.isFingerprintEnrolledAndEnabled,
42             biometricSettingsRepository.isFaceAuthEnrolledAndEnabled,
43         ) { fingerprintEnrolled, faceEnrolled ->
44             if (fingerprintEnrolled && faceEnrolled) {
45                 DeviceEntryBiometricMode.CO_EXPERIENCE
46             } else if (fingerprintEnrolled) {
47                 DeviceEntryBiometricMode.FINGERPRINT_ONLY
48             } else if (faceEnrolled) {
49                 DeviceEntryBiometricMode.FACE_ONLY
50             } else {
51                 DeviceEntryBiometricMode.NONE
52             }
53         }
54     private val faceOnly: Flow<Boolean> =
55         biometricMode.map { it == DeviceEntryBiometricMode.FACE_ONLY }
56 
57     /**
58      * Triggered if face is the only biometric that can be used for device entry and a face failure
59      * occurs.
60      */
61     val faceOnlyFaceFailure: Flow<FailedFaceAuthenticationStatus> =
62         faceOnly.flatMapLatest { faceOnly ->
63             if (faceOnly) {
64                 deviceEntryFaceAuthInteractor.authenticationStatus.filterIsInstance<
65                     FailedFaceAuthenticationStatus
66                 >()
67             } else {
68                 emptyFlow()
69             }
70         }
71 }
72