• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.password;
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.os.Bundle;
24 
25 import androidx.annotation.NonNull;
26 import androidx.appcompat.app.AlertDialog;
27 import androidx.fragment.app.FragmentManager;
28 
29 import com.android.settings.R;
30 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
31 
32 public class SetupSkipDialog extends InstrumentedDialogFragment
33         implements DialogInterface.OnClickListener {
34 
35     public static final String EXTRA_FRP_SUPPORTED = ":settings:frp_supported";
36 
37     private static final String ARG_FRP_SUPPORTED = "frp_supported";
38     // The key indicates type of lock screen is pattern setup.
39     private static final String ARG_LOCK_TYPE_PATTERN = "lock_type_pattern";
40     // The key indicates type of lock screen setup is alphanumeric for password setup.
41     private static final String ARG_LOCK_TYPE_ALPHANUMERIC = "lock_type_alphanumeric";
42     private static final String TAG_SKIP_DIALOG = "skip_dialog";
43     public static final int RESULT_SKIP = Activity.RESULT_FIRST_USER + 10;
44 
newInstance(boolean isFrpSupported, boolean isPatternMode, boolean isAlphanumericMode, boolean isFingerprintSupported, boolean isFaceSupported)45     public static SetupSkipDialog newInstance(boolean isFrpSupported, boolean isPatternMode,
46             boolean isAlphanumericMode, boolean isFingerprintSupported, boolean isFaceSupported) {
47         SetupSkipDialog dialog = new SetupSkipDialog();
48         Bundle args = new Bundle();
49         args.putBoolean(ARG_FRP_SUPPORTED, isFrpSupported);
50         args.putBoolean(ARG_LOCK_TYPE_PATTERN, isPatternMode);
51         args.putBoolean(ARG_LOCK_TYPE_ALPHANUMERIC, isAlphanumericMode);
52         args.putBoolean(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, isFingerprintSupported);
53         args.putBoolean(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE, isFaceSupported);
54         dialog.setArguments(args);
55         return dialog;
56     }
57 
58     @Override
getMetricsCategory()59     public int getMetricsCategory() {
60         return SettingsEnums.DIALOG_FINGERPRINT_SKIP_SETUP;
61     }
62 
63     @Override
onCreateDialog(Bundle savedInstanceState)64     public Dialog onCreateDialog(Bundle savedInstanceState) {
65         return onCreateDialogBuilder().create();
66     }
67 
68     @NonNull
onCreateDialogBuilder()69     public AlertDialog.Builder onCreateDialogBuilder() {
70         Bundle args = getArguments();
71         final boolean isFaceSupported =
72                 args.getBoolean(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE);
73         final boolean isFingerprintSupported =
74                 args.getBoolean(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT);
75         if (isFaceSupported || isFingerprintSupported) {
76             final int titleId;
77 
78             if (args.getBoolean(ARG_LOCK_TYPE_PATTERN)) {
79                 titleId = R.string.lock_screen_pattern_skip_title;
80             } else {
81                 titleId = args.getBoolean(ARG_LOCK_TYPE_ALPHANUMERIC) ?
82                     R.string.lock_screen_password_skip_title : R.string.lock_screen_pin_skip_title;
83             }
84 
85             return new AlertDialog.Builder(getContext())
86                     .setPositiveButton(R.string.skip_lock_screen_dialog_button_label, this)
87                     .setNegativeButton(R.string.cancel_lock_screen_dialog_button_label, this)
88                     .setTitle(titleId)
89                     .setMessage(isFaceSupported ?
90                             R.string.face_lock_screen_setup_skip_dialog_text :
91                             R.string.fingerprint_lock_screen_setup_skip_dialog_text);
92         } else {
93             return new AlertDialog.Builder(getContext())
94                     .setPositiveButton(R.string.skip_anyway_button_label, this)
95                     .setNegativeButton(R.string.go_back_button_label, this)
96                     .setTitle(R.string.lock_screen_intro_skip_title)
97                     .setMessage(args.getBoolean(ARG_FRP_SUPPORTED) ?
98                             R.string.lock_screen_intro_skip_dialog_text_frp :
99                             R.string.lock_screen_intro_skip_dialog_text);
100         }
101     }
102 
103     @Override
onClick(DialogInterface dialog, int button)104     public void onClick(DialogInterface dialog, int button) {
105         switch (button) {
106             case DialogInterface.BUTTON_POSITIVE:
107                 Activity activity = getActivity();
108                 activity.setResult(RESULT_SKIP);
109                 activity.finish();
110                 break;
111         }
112     }
113 
show(FragmentManager manager)114     public void show(FragmentManager manager) {
115         show(manager, TAG_SKIP_DIALOG);
116     }
117 }