1 /*
2  * Copyright (C) 2015 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.Activity;
20 import android.app.Dialog;
21 import android.app.settings.SettingsEnums;
22 import android.content.DialogInterface;
23 import android.content.Intent;
24 import android.os.Bundle;
25 import android.os.UserHandle;
26 import android.view.View;
27 
28 import androidx.annotation.NonNull;
29 import androidx.appcompat.app.AlertDialog;
30 import androidx.fragment.app.FragmentManager;
31 
32 import com.android.settings.R;
33 import com.android.settings.SetupWizardUtils;
34 import com.android.settings.biometrics.BiometricUtils;
35 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
36 import com.android.settings.flags.Flags;
37 import com.android.settings.password.ChooseLockSettingsHelper;
38 
39 public class SetupFingerprintEnrollFindSensor extends FingerprintEnrollFindSensor {
40 
41     @Override
getFingerprintEnrollingIntent()42     protected Intent getFingerprintEnrollingIntent() {
43         Intent intent = new Intent(this, SetupFingerprintEnrollEnrolling.class);
44         intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
45         intent.putExtra(EXTRA_KEY_CHALLENGE, mChallenge);
46         intent.putExtra(EXTRA_KEY_SENSOR_ID, mSensorId);
47         if (mUserId != UserHandle.USER_NULL) {
48             intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
49         }
50         BiometricUtils.copyMultiBiometricExtras(getIntent(), intent);
51         SetupWizardUtils.copySetupExtras(getIntent(), intent);
52         if (Flags.udfpsEnrollCalibration()) {
53             if (mCalibrator != null) {
54                 intent.putExtras(mCalibrator.getExtrasForNextIntent());
55             }
56         }
57         return intent;
58     }
59 
60     @Override
onSkipButtonClick(View view)61     protected void onSkipButtonClick(View view) {
62         new SkipFingerprintDialog().show(getSupportFragmentManager());
63     }
64 
65     @Override
getMetricsCategory()66     public int getMetricsCategory() {
67         return SettingsEnums.FINGERPRINT_FIND_SENSOR_SETUP;
68     }
69 
70     public static class SkipFingerprintDialog extends InstrumentedDialogFragment
71             implements DialogInterface.OnClickListener {
72         private static final String TAG_SKIP_DIALOG = "skip_dialog";
73 
74         @Override
getMetricsCategory()75         public int getMetricsCategory() {
76             return SettingsEnums.DIALOG_FINGERPRINT_SKIP_SETUP;
77         }
78 
79         @Override
onCreateDialog(Bundle savedInstanceState)80         public Dialog onCreateDialog(Bundle savedInstanceState) {
81             return onCreateDialogBuilder().create();
82         }
83 
84         @NonNull
onCreateDialogBuilder()85         public AlertDialog.Builder onCreateDialogBuilder() {
86             return new AlertDialog.Builder(getActivity(), R.style.Theme_AlertDialog)
87                     .setTitle(R.string.setup_fingerprint_enroll_skip_title)
88                     .setPositiveButton(R.string.skip_anyway_button_label, this)
89                     .setNegativeButton(R.string.go_back_button_label, this)
90                     .setMessage(R.string.setup_fingerprint_enroll_skip_after_adding_lock_text);
91         }
92 
93         @Override
onClick(DialogInterface dialog, int button)94         public void onClick(DialogInterface dialog, int button) {
95             switch (button) {
96                 case DialogInterface.BUTTON_POSITIVE:
97                     Activity activity = getActivity();
98                     if (activity != null) {
99                         activity.setResult(RESULT_SKIP);
100                         activity.finish();
101                     }
102                     break;
103             }
104         }
105 
show(FragmentManager manager)106         public void show(FragmentManager manager) {
107             show(manager, TAG_SKIP_DIALOG);
108         }
109     }
110 }
111