Udam Saini | 8ef4c62 | 2016-02-03 17:31:11 -0800 | [diff] [blame] | 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 | |
Maurice Lam | 0f897d7 | 2017-06-02 19:22:53 -0700 | [diff] [blame] | 17 | package com.android.settings.password; |
Udam Saini | 8ef4c62 | 2016-02-03 17:31:11 -0800 | [diff] [blame] | 18 | |
| 19 | import android.app.Activity; |
Udam Saini | 8ef4c62 | 2016-02-03 17:31:11 -0800 | [diff] [blame] | 20 | import android.app.Dialog; |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 21 | import android.app.settings.SettingsEnums; |
Udam Saini | 8ef4c62 | 2016-02-03 17:31:11 -0800 | [diff] [blame] | 22 | import android.content.DialogInterface; |
Udam Saini | 8ef4c62 | 2016-02-03 17:31:11 -0800 | [diff] [blame] | 23 | import android.os.Bundle; |
Udam Saini | 8ef4c62 | 2016-02-03 17:31:11 -0800 | [diff] [blame] | 24 | |
Fan Zhang | c7162cd | 2018-06-18 15:21:41 -0700 | [diff] [blame] | 25 | import androidx.annotation.NonNull; |
tmfang | 41ab6b4 | 2018-07-17 13:53:04 +0800 | [diff] [blame] | 26 | import androidx.appcompat.app.AlertDialog; |
tmfang | 99cc23d | 2018-06-26 19:01:57 +0800 | [diff] [blame] | 27 | import androidx.fragment.app.FragmentManager; |
Fan Zhang | c7162cd | 2018-06-18 15:21:41 -0700 | [diff] [blame] | 28 | |
Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 29 | import com.android.settings.R; |
| 30 | import com.android.settings.core.instrumentation.InstrumentedDialogFragment; |
| 31 | |
Fan Zhang | 1e51628 | 2016-09-16 12:45:07 -0700 | [diff] [blame] | 32 | public class SetupSkipDialog extends InstrumentedDialogFragment |
| 33 | implements DialogInterface.OnClickListener { |
Udam Saini | 8ef4c62 | 2016-02-03 17:31:11 -0800 | [diff] [blame] | 34 | |
| 35 | public static final String EXTRA_FRP_SUPPORTED = ":settings:frp_supported"; |
| 36 | |
| 37 | private static final String ARG_FRP_SUPPORTED = "frp_supported"; |
pastychang | 5145dc1 | 2019-03-18 20:10:32 +0800 | [diff] [blame] | 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"; |
Udam Saini | 8ef4c62 | 2016-02-03 17:31:11 -0800 | [diff] [blame] | 42 | private static final String TAG_SKIP_DIALOG = "skip_dialog"; |
Maurice Lam | 0f897d7 | 2017-06-02 19:22:53 -0700 | [diff] [blame] | 43 | public static final int RESULT_SKIP = Activity.RESULT_FIRST_USER + 10; |
Udam Saini | 8ef4c62 | 2016-02-03 17:31:11 -0800 | [diff] [blame] | 44 | |
pastychang | 5145dc1 | 2019-03-18 20:10:32 +0800 | [diff] [blame] | 45 | public static SetupSkipDialog newInstance(boolean isFrpSupported, boolean isPatternMode, |
| 46 | boolean isAlphanumericMode, boolean isFingerprintSupported, boolean isFaceSupported) { |
Udam Saini | 8ef4c62 | 2016-02-03 17:31:11 -0800 | [diff] [blame] | 47 | SetupSkipDialog dialog = new SetupSkipDialog(); |
| 48 | Bundle args = new Bundle(); |
| 49 | args.putBoolean(ARG_FRP_SUPPORTED, isFrpSupported); |
pastychang | 5145dc1 | 2019-03-18 20:10:32 +0800 | [diff] [blame] | 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); |
Udam Saini | 8ef4c62 | 2016-02-03 17:31:11 -0800 | [diff] [blame] | 54 | dialog.setArguments(args); |
| 55 | return dialog; |
| 56 | } |
| 57 | |
| 58 | @Override |
Fan Zhang | 1e51628 | 2016-09-16 12:45:07 -0700 | [diff] [blame] | 59 | public int getMetricsCategory() { |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 60 | return SettingsEnums.DIALOG_FINGERPRINT_SKIP_SETUP; |
Fan Zhang | 1e51628 | 2016-09-16 12:45:07 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | @Override |
Udam Saini | 8ef4c62 | 2016-02-03 17:31:11 -0800 | [diff] [blame] | 64 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
Maurice Lam | 190ec1c | 2016-04-22 16:41:18 -0700 | [diff] [blame] | 65 | return onCreateDialogBuilder().create(); |
Udam Saini | 8ef4c62 | 2016-02-03 17:31:11 -0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @NonNull |
| 69 | public AlertDialog.Builder onCreateDialogBuilder() { |
| 70 | Bundle args = getArguments(); |
pastychang | 5145dc1 | 2019-03-18 20:10:32 +0800 | [diff] [blame] | 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 | } |
Udam Saini | 8ef4c62 | 2016-02-03 17:31:11 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | @Override |
| 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 | |
| 114 | public void show(FragmentManager manager) { |
| 115 | show(manager, TAG_SKIP_DIALOG); |
| 116 | } |
| 117 | } |