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.keyguard.shared.model.AuthenticationFlags 22 import kotlinx.coroutines.flow.Flow 23 import kotlinx.coroutines.flow.MutableStateFlow 24 import kotlinx.coroutines.flow.StateFlow 25 import kotlinx.coroutines.flow.map 26 27 class FakeBiometricSettingsRepository : BiometricSettingsRepository { 28 private val _isFingerprintEnrolledAndEnabled = MutableStateFlow(false) 29 override val isFingerprintEnrolledAndEnabled: StateFlow<Boolean> 30 get() = _isFingerprintEnrolledAndEnabled 31 32 private val _isFingerprintAuthCurrentlyAllowed = MutableStateFlow(false) 33 override val isFingerprintAuthCurrentlyAllowed: StateFlow<Boolean> 34 get() = _isFingerprintAuthCurrentlyAllowed 35 36 private val _isFaceAuthEnrolledAndEnabled = MutableStateFlow(false) 37 override val isFaceAuthEnrolledAndEnabled: Flow<Boolean> 38 get() = _isFaceAuthEnrolledAndEnabled 39 40 private val _isFaceAuthCurrentlyAllowed = MutableStateFlow(false) 41 override val isFaceAuthCurrentlyAllowed: Flow<Boolean> 42 get() = _isFaceAuthCurrentlyAllowed 43 44 private val _isFaceAuthSupportedInCurrentPosture = MutableStateFlow(false) 45 override val isFaceAuthSupportedInCurrentPosture: Flow<Boolean> 46 get() = _isFaceAuthSupportedInCurrentPosture 47 48 override val isCurrentUserInLockdown: Flow<Boolean> 49 get() = _authFlags.map { it.isInUserLockdown } 50 51 private val _authFlags = MutableStateFlow(AuthenticationFlags(0, 0)) 52 override val authenticationFlags: Flow<AuthenticationFlags> 53 get() = _authFlags 54 55 fun setAuthenticationFlags(value: AuthenticationFlags) { 56 _authFlags.value = value 57 } 58 59 fun setIsFingerprintAuthEnrolledAndEnabled(value: Boolean) { 60 _isFingerprintEnrolledAndEnabled.value = value 61 _isFingerprintAuthCurrentlyAllowed.value = _isFingerprintAuthCurrentlyAllowed.value && value 62 } 63 64 fun setIsFingerprintAuthCurrentlyAllowed(value: Boolean) { 65 _isFingerprintAuthCurrentlyAllowed.value = value 66 } 67 68 fun setIsFaceAuthEnrolledAndEnabled(value: Boolean) { 69 _isFaceAuthEnrolledAndEnabled.value = value 70 _isFaceAuthCurrentlyAllowed.value = _isFaceAuthCurrentlyAllowed.value && value 71 } 72 73 fun setIsFaceAuthCurrentlyAllowed(value: Boolean) { 74 _isFaceAuthCurrentlyAllowed.value = value 75 } 76 77 fun setIsFaceAuthSupportedInCurrentPosture(value: Boolean) { 78 _isFaceAuthSupportedInCurrentPosture.value = value 79 } 80 81 fun setIsUserInLockdown(value: Boolean) { 82 if (value) { 83 setAuthenticationFlags( 84 AuthenticationFlags( 85 _authFlags.value.userId, 86 _authFlags.value.flag or 87 LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN 88 ) 89 ) 90 } else { 91 setAuthenticationFlags( 92 AuthenticationFlags( 93 _authFlags.value.userId, 94 LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED 95 ) 96 ) 97 } 98 } 99 } 100