1 /* 2 * 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.biometrics.data.repository 18 19 import android.hardware.biometrics.SensorLocationInternal 20 import com.android.systemui.biometrics.shared.model.FingerprintSensorType 21 import com.android.systemui.biometrics.shared.model.SensorStrength 22 import com.android.systemui.dagger.SysUISingleton 23 import dagger.Binds 24 import dagger.Module 25 import javax.inject.Inject 26 import kotlinx.coroutines.flow.MutableStateFlow 27 import kotlinx.coroutines.flow.asStateFlow 28 29 @SysUISingleton 30 class FakeFingerprintPropertyRepository @Inject constructor() : FingerprintPropertyRepository { 31 override val propertiesInitialized: MutableStateFlow<Boolean> = MutableStateFlow(false) 32 33 private val _sensorId: MutableStateFlow<Int> = MutableStateFlow(-1) 34 override val sensorId = _sensorId.asStateFlow() 35 36 private val _strength: MutableStateFlow<SensorStrength> = 37 MutableStateFlow(SensorStrength.CONVENIENCE) 38 override val strength = _strength.asStateFlow() 39 40 private val _sensorType: MutableStateFlow<FingerprintSensorType> = 41 MutableStateFlow(FingerprintSensorType.UNKNOWN) 42 override val sensorType = _sensorType.asStateFlow() 43 44 private val _sensorLocations: MutableStateFlow<Map<String, SensorLocationInternal>> = 45 MutableStateFlow(mapOf("" to SensorLocationInternal.DEFAULT)) 46 override val sensorLocations = _sensorLocations.asStateFlow() 47 setPropertiesnull48 fun setProperties( 49 sensorId: Int, 50 strength: SensorStrength, 51 sensorType: FingerprintSensorType, 52 sensorLocations: Map<String, SensorLocationInternal> 53 ) { 54 _sensorId.value = sensorId 55 _strength.value = strength 56 _sensorType.value = sensorType 57 _sensorLocations.value = sensorLocations 58 propertiesInitialized.value = true 59 } 60 61 /** setProperties as if the device supports UDFPS_OPTICAL. */ supportsUdfpsnull62 fun supportsUdfps() { 63 setProperties( 64 sensorId = 0, 65 strength = SensorStrength.STRONG, 66 sensorType = FingerprintSensorType.UDFPS_OPTICAL, 67 sensorLocations = emptyMap(), 68 ) 69 } 70 71 /** setProperties as if the device supports POWER_BUTTON fingerprint sensor. */ supportsSideFpsnull72 fun supportsSideFps() { 73 setProperties( 74 sensorId = 0, 75 strength = SensorStrength.STRONG, 76 sensorType = FingerprintSensorType.POWER_BUTTON, 77 sensorLocations = emptyMap(), 78 ) 79 } 80 81 /** setProperties as if the device supports the rear fingerprint sensor. */ supportsRearFpsnull82 fun supportsRearFps() { 83 setProperties( 84 sensorId = 0, 85 strength = SensorStrength.STRONG, 86 sensorType = FingerprintSensorType.REAR, 87 sensorLocations = emptyMap(), 88 ) 89 } 90 } 91 92 @Module 93 interface FakeFingerprintPropertyRepositoryModule { bindFakenull94 @Binds fun bindFake(fake: FakeFingerprintPropertyRepository): FingerprintPropertyRepository 95 } 96