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.settings.biometrics.fingerprint2.conversion 18 19 import android.hardware.biometrics.BiometricFingerprintConstants.FINGERPRINT_ERROR_CANCELED 20 import android.hardware.biometrics.BiometricFingerprintConstants.FINGERPRINT_ERROR_UNABLE_TO_PROCESS 21 import android.hardware.fingerprint.FingerprintManager 22 import com.android.settings.R 23 import com.android.settings.biometrics.fingerprint2.lib.model.EnrollReason 24 import com.android.settings.biometrics.fingerprint2.lib.model.FingerEnrollState 25 26 object Util { EnrollReasonnull27 fun EnrollReason.toOriginalReason(): Int { 28 return when (this) { 29 EnrollReason.EnrollEnrolling -> FingerprintManager.ENROLL_ENROLL 30 EnrollReason.FindSensor -> FingerprintManager.ENROLL_FIND_SENSOR 31 } 32 } 33 toEnrollErrornull34 fun Int.toEnrollError(isSetupWizard: Boolean): FingerEnrollState.EnrollError { 35 val errTitle = 36 when (this) { 37 FingerprintManager.FINGERPRINT_ERROR_TIMEOUT -> 38 R.string.security_settings_fingerprint_enroll_error_dialog_title 39 FingerprintManager.FINGERPRINT_ERROR_BAD_CALIBRATION -> 40 R.string.security_settings_fingerprint_bad_calibration_title 41 else -> R.string.security_settings_fingerprint_enroll_error_unable_to_process_dialog_title 42 } 43 val errString = 44 if (isSetupWizard) { 45 when (this) { 46 FingerprintManager.FINGERPRINT_ERROR_TIMEOUT -> 47 R.string.security_settings_fingerprint_enroll_error_dialog_title 48 FingerprintManager.FINGERPRINT_ERROR_BAD_CALIBRATION -> 49 R.string.security_settings_fingerprint_bad_calibration_title 50 else -> R.string.security_settings_fingerprint_enroll_error_unable_to_process_dialog_title 51 } 52 } else { 53 when (this) { 54 // This message happens when the underlying crypto layer 55 // decides to revoke the enrollment auth token 56 FingerprintManager.FINGERPRINT_ERROR_TIMEOUT -> 57 R.string.security_settings_fingerprint_enroll_error_timeout_dialog_message 58 FingerprintManager.FINGERPRINT_ERROR_BAD_CALIBRATION -> 59 R.string.security_settings_fingerprint_bad_calibration 60 FingerprintManager.FINGERPRINT_ERROR_UNABLE_TO_PROCESS -> 61 R.string.security_settings_fingerprint_enroll_error_unable_to_process_message 62 // There's nothing specific to tell the user about. Ask them to try again. 63 else -> R.string.security_settings_fingerprint_enroll_error_generic_dialog_message 64 } 65 } 66 67 return FingerEnrollState.EnrollError( 68 errTitle, 69 errString, 70 this == FINGERPRINT_ERROR_UNABLE_TO_PROCESS, 71 this == FINGERPRINT_ERROR_CANCELED, 72 ) 73 } 74 } 75