1 /* 2 * Copyright (C) 2024 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.settings.biometrics.fingerprint2.lib.domain.interactor 18 19 import android.hardware.fingerprint.FingerprintEnrollOptions 20 import com.android.settings.biometrics.fingerprint2.lib.model.EnrollReason 21 import com.android.settings.biometrics.fingerprint2.lib.model.FingerEnrollState 22 import com.android.settings.biometrics.fingerprint2.lib.model.FingerprintAuthAttemptModel 23 import com.android.settings.biometrics.fingerprint2.lib.model.FingerprintData 24 import com.android.systemui.biometrics.shared.model.FingerprintSensor 25 import kotlinx.coroutines.flow.Flow 26 27 /** 28 * Interface to obtain the necessary data for FingerprintEnrollment/Settings 29 * 30 * Note that this interface should not have dependencies on heavyweight libraries such as the 31 * framework, hidl/aidl, etc. This makes it much easier to test and create fakes for. 32 */ 33 interface FingerprintManagerInteractor { 34 /** Returns the list of current fingerprints. */ 35 val enrolledFingerprints: Flow<List<FingerprintData>?> 36 37 /** Returns the max enrollable fingerprints, note during SUW this might be 1 */ 38 val maxEnrollableFingerprints: Flow<Int> 39 40 /** Returns true if a user can enroll a fingerprint false otherwise. */ 41 val canEnrollFingerprints: Flow<Boolean> 42 43 /** Retrieves the sensor properties of a device */ 44 val sensorPropertiesInternal: Flow<FingerprintSensor?> 45 46 /** Runs the authenticate flow */ authenticatenull47 suspend fun authenticate(): FingerprintAuthAttemptModel 48 49 /** 50 * Generates a challenge with the provided [gateKeeperPasswordHandle] and on success returns a 51 * challenge and challenge token. This info can be used for secure operations such as enrollment 52 * 53 * @param gateKeeperPasswordHandle GateKeeper password handle generated by a Confirm 54 * @return A [Pair] of the challenge and challenge token 55 */ 56 suspend fun generateChallenge(gateKeeperPasswordHandle: Long): Pair<Long, ByteArray> 57 58 /** 59 * Runs [FingerprintManager.enroll] with the [hardwareAuthToken] and [EnrollReason] for this 60 * enrollment. If successful data in the [fingerprintEnrollState] should be populated. 61 */ 62 suspend fun enroll( 63 hardwareAuthToken: ByteArray?, 64 enrollReason: EnrollReason, 65 fingerprintEnrollOptions: FingerprintEnrollOptions, 66 ): Flow<FingerEnrollState> 67 68 /** 69 * Removes the given fingerprint, returning true if it was successfully removed and false 70 * otherwise 71 */ 72 suspend fun removeFingerprint(fp: FingerprintData): Boolean 73 74 /** Renames the given fingerprint if one exists */ 75 suspend fun renameFingerprint(fp: FingerprintData, newName: String) 76 77 /** Indicates if the device has side fingerprint */ 78 suspend fun hasSideFps(): Boolean? 79 } 80