• 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.biometrics.domain.interactor.FingerprintPropertyInteractor
20 import com.android.systemui.biometrics.shared.model.SensorLocation
21 import com.android.systemui.dagger.SysUISingleton
22 import com.android.systemui.keyguard.data.repository.BiometricSettingsRepository
23 import com.android.systemui.keyguard.data.repository.DeviceEntryFingerprintAuthRepository
24 import javax.inject.Inject
25 import kotlinx.coroutines.ExperimentalCoroutinesApi
26 import kotlinx.coroutines.flow.Flow
27 import kotlinx.coroutines.flow.StateFlow
28 import kotlinx.coroutines.flow.combine
29 import kotlinx.coroutines.flow.flatMapLatest
30 import kotlinx.coroutines.flow.flowOf
31 
32 /** Encapsulates business logic for device entry under-display fingerprint state changes. */
33 @ExperimentalCoroutinesApi
34 @SysUISingleton
35 class DeviceEntryUdfpsInteractor
36 @Inject
37 constructor(
38     fingerprintPropertyInteractor: FingerprintPropertyInteractor,
39     // TODO (b/309655554): create & use interactors for these repositories
40     fingerprintAuthRepository: DeviceEntryFingerprintAuthRepository,
41     biometricSettingsRepository: BiometricSettingsRepository,
42 ) {
43     /** Whether the device supports an under display fingerprint sensor. */
44     val isUdfpsSupported: StateFlow<Boolean> = fingerprintPropertyInteractor.isUdfps
45 
46     /** Whether the under-display fingerprint sensor is enrolled and enabled for device entry. */
47     val isUdfpsEnrolledAndEnabled: Flow<Boolean> =
48         combine(isUdfpsSupported, biometricSettingsRepository.isFingerprintEnrolledAndEnabled) {
49             udfps,
50             fpEnrolledAndEnabled ->
51             udfps && fpEnrolledAndEnabled
52         }
53     /** Whether the under display fingerprint sensor is currently running. */
54     val isListeningForUdfps =
55         isUdfpsSupported.flatMapLatest { isUdfps ->
56             if (isUdfps) {
57                 fingerprintAuthRepository.isRunning
58             } else {
59                 flowOf(false)
60             }
61         }
62 
63     /**
64      * Location of the under-display fingerprint sensor on the display. Null if the device does not
65      * support UDFPS.
66      */
67     val udfpsLocation: Flow<SensorLocation?> =
68         isUdfpsSupported.flatMapLatest {
69             if (it) {
70                 fingerprintPropertyInteractor.sensorLocation
71             } else {
72                 flowOf(null)
73             }
74         }
75 }
76