1 /* 2 * Copyright (C) 2022 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 18 package com.android.systemui.keyguard.data.repository 19 20 import com.android.internal.widget.LockPatternUtils 21 import com.android.systemui.dagger.SysUISingleton 22 import com.android.systemui.keyguard.shared.model.AuthenticationFlags 23 import dagger.Binds 24 import dagger.Module 25 import javax.inject.Inject 26 import kotlinx.coroutines.flow.Flow 27 import kotlinx.coroutines.flow.MutableStateFlow 28 import kotlinx.coroutines.flow.StateFlow 29 import kotlinx.coroutines.flow.map 30 31 @SysUISingleton 32 class FakeBiometricSettingsRepository @Inject constructor() : BiometricSettingsRepository { 33 private val _isFingerprintEnrolledAndEnabled = MutableStateFlow(false) 34 override val isFingerprintEnrolledAndEnabled: StateFlow<Boolean> 35 get() = _isFingerprintEnrolledAndEnabled 36 37 private val _isFingerprintAuthCurrentlyAllowed = MutableStateFlow(false) 38 override val isFingerprintAuthCurrentlyAllowed: StateFlow<Boolean> 39 get() = _isFingerprintAuthCurrentlyAllowed 40 41 private val _isFaceAuthEnrolledAndEnabled = MutableStateFlow(false) 42 override val isFaceAuthEnrolledAndEnabled: StateFlow<Boolean> 43 get() = _isFaceAuthEnrolledAndEnabled 44 45 private val _isFaceAuthCurrentlyAllowed = MutableStateFlow(false) 46 override val isFaceAuthCurrentlyAllowed: Flow<Boolean> 47 get() = _isFaceAuthCurrentlyAllowed 48 49 private val _isFaceAuthSupportedInCurrentPosture = MutableStateFlow(false) 50 override val isFaceAuthSupportedInCurrentPosture: StateFlow<Boolean> 51 get() = _isFaceAuthSupportedInCurrentPosture 52 53 override val isCurrentUserInLockdown: Flow<Boolean> <lambda>null54 get() = _authFlags.map { it.isInUserLockdown } 55 56 private val _authFlags = MutableStateFlow(AuthenticationFlags(0, 0)) 57 override val authenticationFlags: Flow<AuthenticationFlags> 58 get() = _authFlags 59 setAuthenticationFlagsnull60 fun setAuthenticationFlags(value: AuthenticationFlags) { 61 _authFlags.value = value 62 } 63 setIsFingerprintAuthEnrolledAndEnablednull64 fun setIsFingerprintAuthEnrolledAndEnabled(value: Boolean) { 65 _isFingerprintEnrolledAndEnabled.value = value 66 _isFingerprintAuthCurrentlyAllowed.value = _isFingerprintAuthCurrentlyAllowed.value && value 67 } 68 setIsFingerprintAuthCurrentlyAllowednull69 fun setIsFingerprintAuthCurrentlyAllowed(value: Boolean) { 70 _isFingerprintAuthCurrentlyAllowed.value = value 71 } 72 setIsFaceAuthEnrolledAndEnablednull73 fun setIsFaceAuthEnrolledAndEnabled(value: Boolean) { 74 _isFaceAuthEnrolledAndEnabled.value = value 75 _isFaceAuthCurrentlyAllowed.value = _isFaceAuthCurrentlyAllowed.value && value 76 } 77 setIsFaceAuthCurrentlyAllowednull78 fun setIsFaceAuthCurrentlyAllowed(value: Boolean) { 79 _isFaceAuthCurrentlyAllowed.value = value 80 } 81 setIsFaceAuthSupportedInCurrentPosturenull82 fun setIsFaceAuthSupportedInCurrentPosture(value: Boolean) { 83 _isFaceAuthSupportedInCurrentPosture.value = value 84 } 85 setIsUserInLockdownnull86 fun setIsUserInLockdown(value: Boolean) { 87 if (value) { 88 setAuthenticationFlags( 89 AuthenticationFlags( 90 _authFlags.value.userId, 91 _authFlags.value.flag or 92 LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN 93 ) 94 ) 95 } else { 96 setAuthenticationFlags( 97 AuthenticationFlags( 98 _authFlags.value.userId, 99 LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED 100 ) 101 ) 102 } 103 } 104 } 105 106 @Module 107 interface FakeBiometricSettingsRepositoryModule { bindFakenull108 @Binds fun bindFake(fake: FakeBiometricSettingsRepository): BiometricSettingsRepository 109 } 110