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.core.instrumentation.InstrumentedDialogFragment;
35 import com.android.settings.password.ChooseLockSettingsHelper;
36 
37 public class SetupFingerprintEnrollFindSensor extends FingerprintEnrollFindSensor {
38 
39     @Override
getFingerprintEnrollingIntent()40     protected Intent getFingerprintEnrollingIntent() {
41         Intent intent = new Intent(this, SetupFingerprintEnrollEnrolling.class);
42         intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
43         intent.putExtra(EXTRA_KEY_CHALLENGE, mChallenge);
44         intent.putExtra(EXTRA_KEY_SENSOR_ID, mSensorId);
45         if (mUserId != UserHandle.USER_NULL) {
46             intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
47         }
48         SetupWizardUtils.copySetupExtras(getIntent(), intent);
49         return intent;
50     }
51 
52     @Override
onSkipButtonClick(View view)53     protected void onSkipButtonClick(View view) {
54         new SkipFingerprintDialog().show(getSupportFragmentManager());
55     }
56 
57     @Override
getMetricsCategory()58     public int getMetricsCategory() {
59         return SettingsEnums.FINGERPRINT_FIND_SENSOR_SETUP;
60     }
61 
62     public static class SkipFingerprintDialog extends InstrumentedDialogFragment
63             implements DialogInterface.OnClickListener {
64         private static final String TAG_SKIP_DIALOG = "skip_dialog";
65 
66         @Override
getMetricsCategory()67         public int getMetricsCategory() {
68             return SettingsEnums.DIALOG_FINGERPRINT_SKIP_SETUP;
69         }
70 
71         @Override
onCreateDialog(Bundle savedInstanceState)72         public Dialog onCreateDialog(Bundle savedInstanceState) {
73             return onCreateDialogBuilder().create();
74         }
75 
76         @NonNull
onCreateDialogBuilder()77         public AlertDialog.Builder onCreateDialogBuilder() {
78             return new AlertDialog.Builder(getContext())
79                     .setTitle(R.string.setup_fingerprint_enroll_skip_title)
80                     .setPositiveButton(R.string.skip_anyway_button_label, this)
81                     .setNegativeButton(R.string.go_back_button_label, this)
82                     .setMessage(R.string.setup_fingerprint_enroll_skip_after_adding_lock_text);
83         }
84 
85         @Override
onClick(DialogInterface dialog, int button)86         public void onClick(DialogInterface dialog, int button) {
87             switch (button) {
88                 case DialogInterface.BUTTON_POSITIVE:
89                     Activity activity = getActivity();
90                     if (activity != null) {
91                         activity.setResult(RESULT_SKIP);
92                         activity.finish();
93                     }
94                     break;
95             }
96         }
97 
show(FragmentManager manager)98         public void show(FragmentManager manager) {
99             show(manager, TAG_SKIP_DIALOG);
100         }
101     }
102 }
103