1 package com.android.systemui.keyguard.domain.interactor
2 
3 import com.android.systemui.dagger.SysUISingleton
4 import com.android.systemui.keyguard.data.repository.KeyguardRepository
5 import com.android.systemui.keyguard.shared.model.BiometricUnlockMode
6 import com.android.systemui.keyguard.shared.model.BiometricUnlockModel
7 import com.android.systemui.keyguard.shared.model.BiometricUnlockSource
8 import com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_DISMISS_BOUNCER
9 import com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_NONE
10 import com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_ONLY_WAKE
11 import com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_SHOW_BOUNCER
12 import com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_UNLOCK_COLLAPSING
13 import com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_WAKE_AND_UNLOCK
14 import com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_WAKE_AND_UNLOCK_FROM_DREAM
15 import com.android.systemui.statusbar.phone.BiometricUnlockController.MODE_WAKE_AND_UNLOCK_PULSING
16 import com.android.systemui.statusbar.phone.BiometricUnlockController.WakeAndUnlockMode
17 import javax.inject.Inject
18 import kotlinx.coroutines.ExperimentalCoroutinesApi
19 import kotlinx.coroutines.flow.StateFlow
20 
21 @ExperimentalCoroutinesApi
22 @SysUISingleton
23 class BiometricUnlockInteractor
24 @Inject
25 constructor(
26     private val keyguardRepository: KeyguardRepository,
27 ) {
28 
29     val unlockState: StateFlow<BiometricUnlockModel> = keyguardRepository.biometricUnlockState
30 
setBiometricUnlockStatenull31     fun setBiometricUnlockState(
32         @WakeAndUnlockMode unlockStateInt: Int,
33         biometricUnlockSource: BiometricUnlockSource?,
34     ) {
35         val state = biometricModeIntToObject(unlockStateInt)
36         keyguardRepository.setBiometricUnlockState(state, biometricUnlockSource)
37     }
38 
biometricModeIntToObjectnull39     private fun biometricModeIntToObject(@WakeAndUnlockMode value: Int): BiometricUnlockMode {
40         return when (value) {
41             MODE_NONE -> BiometricUnlockMode.NONE
42             MODE_WAKE_AND_UNLOCK -> BiometricUnlockMode.WAKE_AND_UNLOCK
43             MODE_WAKE_AND_UNLOCK_PULSING -> BiometricUnlockMode.WAKE_AND_UNLOCK_PULSING
44             MODE_SHOW_BOUNCER -> BiometricUnlockMode.SHOW_BOUNCER
45             MODE_ONLY_WAKE -> BiometricUnlockMode.ONLY_WAKE
46             MODE_UNLOCK_COLLAPSING -> BiometricUnlockMode.UNLOCK_COLLAPSING
47             MODE_WAKE_AND_UNLOCK_FROM_DREAM -> BiometricUnlockMode.WAKE_AND_UNLOCK_FROM_DREAM
48             MODE_DISMISS_BOUNCER -> BiometricUnlockMode.DISMISS_BOUNCER
49             else -> throw IllegalArgumentException("Invalid BiometricUnlockModel value: $value")
50         }
51     }
52 }
53