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         if (host.isFinishing()) {
35             return;
36         }
37 
38         final FragmentManager fragmentManager = host.getSupportFragmentManager();
39         if (fragmentManager.isDestroyed()) {
40             return;
41         }
42 
43         final CharSequence errMsg = host.getText(getErrorMessage(errMsgId));
44         final FingerprintErrorDialog dialog = newInstance(errMsg, errMsgId);
45         dialog.show(fragmentManager, FingerprintErrorDialog.class.getName());
46     }
47 
getErrorMessage(int errMsgId)48     private static int getErrorMessage(int errMsgId) {
49         switch (errMsgId) {
50             case FingerprintManager.FINGERPRINT_ERROR_TIMEOUT:
51                 // This message happens when the underlying crypto layer decides to revoke the
52                 // enrollment auth token.
53                 return R.string.security_settings_fingerprint_enroll_error_timeout_dialog_message;
54             case FingerprintManager.FINGERPRINT_ERROR_BAD_CALIBRATION:
55                 return R.string.security_settings_fingerprint_bad_calibration;
56             default:
57                 // There's nothing specific to tell the user about. Ask them to try again.
58                 return R.string.security_settings_fingerprint_enroll_error_generic_dialog_message;
59         }
60     }
61 
newInstance(CharSequence msg, int msgId)62     private static FingerprintErrorDialog newInstance(CharSequence msg, int msgId) {
63         FingerprintErrorDialog dialog = new FingerprintErrorDialog();
64         Bundle args = new Bundle();
65         args.putCharSequence(KEY_ERROR_MSG, msg);
66         args.putInt(KEY_ERROR_ID, msgId);
67         dialog.setArguments(args);
68         return dialog;
69     }
70 
71     @Override
getTitleResId()72     public int getTitleResId() {
73         return R.string.security_settings_fingerprint_enroll_error_dialog_title;
74     }
75 
76     @Override
getOkButtonTextResId()77     public int getOkButtonTextResId() {
78         return R.string.security_settings_fingerprint_enroll_dialog_ok;
79     }
80 
81     @Override
getMetricsCategory()82     public int getMetricsCategory() {
83         return SettingsEnums.DIALOG_FINGERPINT_ERROR;
84     }
85 }
86