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; 18 19 import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FACE; 20 21 import static com.android.settings.biometrics.BiometricEnrollBase.RESULT_SKIP; 22 23 import android.app.Dialog; 24 import android.app.settings.SettingsEnums; 25 import android.content.DialogInterface; 26 import android.hardware.biometrics.BiometricAuthenticator; 27 import android.os.Bundle; 28 29 import androidx.appcompat.app.AlertDialog; 30 31 import com.android.settings.R; 32 import com.android.settings.core.instrumentation.InstrumentedDialogFragment; 33 34 /** 35 * This alert dialog shows when fingerprint is being added in multi window mode. 36 */ 37 public class BiometricsSplitScreenDialog extends InstrumentedDialogFragment { 38 private static final String KEY_BIOMETRICS_MODALITY = "biometrics_modality"; 39 private static final String KEU_DESTROY_ACTIVITY = "destroy_activity"; 40 41 @BiometricAuthenticator.Modality 42 private int mBiometricsModality; 43 private boolean mDestroyActivity; 44 45 /** 46 * Returns the new instance of the class 47 * @param biometricsModality Biometric modality. 48 * @param destroyActivity Whether to destroy the activity 49 * @return the current {@link BiometricsSplitScreenDialog} 50 */ newInstance( @iometricAuthenticator.Modality int biometricsModality, boolean destroyActivity)51 public static BiometricsSplitScreenDialog newInstance( 52 @BiometricAuthenticator.Modality int biometricsModality, boolean destroyActivity) { 53 final BiometricsSplitScreenDialog dialog = new BiometricsSplitScreenDialog(); 54 final Bundle args = new Bundle(); 55 args.putInt(KEY_BIOMETRICS_MODALITY, biometricsModality); 56 args.putBoolean(KEU_DESTROY_ACTIVITY, destroyActivity); 57 dialog.setArguments(args); 58 dialog.setCancelable(false); 59 return dialog; 60 } 61 62 @Override onCreateDialog(Bundle savedInstanceState)63 public Dialog onCreateDialog(Bundle savedInstanceState) { 64 mBiometricsModality = getArguments().getInt(KEY_BIOMETRICS_MODALITY); 65 mDestroyActivity = getArguments().getBoolean(KEU_DESTROY_ACTIVITY); 66 int titleId; 67 int messageId; 68 switch (mBiometricsModality) { 69 case TYPE_FACE: 70 titleId = R.string.biometric_settings_add_face_in_split_mode_title; 71 messageId = R.string.biometric_settings_add_face_in_split_mode_message; 72 break; 73 default: 74 titleId = R.string.biometric_settings_add_fingerprint_in_split_mode_title; 75 messageId = R.string.biometric_settings_add_fingerprint_in_split_mode_message; 76 } 77 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 78 builder.setTitle(titleId) 79 .setMessage(messageId) 80 .setCancelable(false) 81 .setPositiveButton( 82 R.string.biometric_settings_add_biometrics_in_split_mode_ok, 83 (DialogInterface.OnClickListener) (dialog, which) -> { 84 dialog.dismiss(); 85 if (mDestroyActivity) { 86 getActivity().setResult(RESULT_SKIP); 87 getActivity().finish(); 88 } 89 }); 90 return builder.create(); 91 } 92 93 @Override getMetricsCategory()94 public int getMetricsCategory() { 95 switch (mBiometricsModality) { 96 case TYPE_FACE: 97 return SettingsEnums.DIALOG_ADD_FACE_ERROR_IN_SPLIT_MODE; 98 default: 99 return SettingsEnums.DIALOG_ADD_FINGERPRINT_ERROR_IN_SPLIT_MODE; 100 } 101 } 102 } 103