1 /* 2 * Copyright 2021 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.fingerprint; 18 19 import android.app.settings.SettingsEnums; 20 import android.hardware.fingerprint.FingerprintManager; 21 import android.os.Bundle; 22 23 import androidx.fragment.app.FragmentManager; 24 25 import com.android.settings.R; 26 import com.android.settings.biometrics.BiometricEnrollBase; 27 import com.android.settings.biometrics.BiometricErrorDialog; 28 29 /** 30 * Fingerprint error dialog, will be shown when an error occurs during fingerprint enrollment. 31 */ 32 public class FingerprintErrorDialog extends BiometricErrorDialog { showErrorDialog(BiometricEnrollBase host, int errMsgId)33 public static void showErrorDialog(BiometricEnrollBase host, int errMsgId) { 34 final CharSequence errMsg = host.getText(getErrorMessage(errMsgId)); 35 final FingerprintErrorDialog dialog = newInstance(errMsg, errMsgId); 36 final FragmentManager fragmentManager = host.getSupportFragmentManager(); 37 if (!fragmentManager.isDestroyed()) { 38 dialog.show(fragmentManager, FingerprintErrorDialog.class.getName()); 39 } 40 } 41 getErrorMessage(int errMsgId)42 private static int getErrorMessage(int errMsgId) { 43 switch (errMsgId) { 44 case FingerprintManager.FINGERPRINT_ERROR_TIMEOUT: 45 // This message happens when the underlying crypto layer decides to revoke the 46 // enrollment auth token. 47 return R.string.security_settings_fingerprint_enroll_error_timeout_dialog_message; 48 case FingerprintManager.FINGERPRINT_ERROR_BAD_CALIBRATION: 49 return R.string.security_settings_fingerprint_bad_calibration; 50 default: 51 // There's nothing specific to tell the user about. Ask them to try again. 52 return R.string.security_settings_fingerprint_enroll_error_generic_dialog_message; 53 } 54 } 55 newInstance(CharSequence msg, int msgId)56 private static FingerprintErrorDialog newInstance(CharSequence msg, int msgId) { 57 FingerprintErrorDialog dialog = new FingerprintErrorDialog(); 58 Bundle args = new Bundle(); 59 args.putCharSequence(KEY_ERROR_MSG, msg); 60 args.putInt(KEY_ERROR_ID, msgId); 61 dialog.setArguments(args); 62 return dialog; 63 } 64 65 @Override getTitleResId()66 public int getTitleResId() { 67 return R.string.security_settings_fingerprint_enroll_error_dialog_title; 68 } 69 70 @Override getOkButtonTextResId()71 public int getOkButtonTextResId() { 72 return R.string.security_settings_fingerprint_enroll_dialog_ok; 73 } 74 75 @Override getMetricsCategory()76 public int getMetricsCategory() { 77 return SettingsEnums.DIALOG_FINGERPINT_ERROR; 78 } 79 } 80