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