Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 17 | package com.android.settings.password; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 18 | |
Bernard Chau | 92db5bf | 2018-12-17 18:03:24 +0000 | [diff] [blame] | 19 | import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE; |
Maurice Lam | c41e408 | 2017-04-27 19:04:46 -0700 | [diff] [blame] | 20 | import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_NUMERIC; |
Maurice Lam | c41e408 | 2017-04-27 19:04:46 -0700 | [diff] [blame] | 21 | |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 22 | import static com.android.internal.widget.PasswordValidationError.CONTAINS_INVALID_CHARACTERS; |
| 23 | import static com.android.internal.widget.PasswordValidationError.CONTAINS_SEQUENCE; |
| 24 | import static com.android.internal.widget.PasswordValidationError.NOT_ENOUGH_DIGITS; |
| 25 | import static com.android.internal.widget.PasswordValidationError.NOT_ENOUGH_LETTERS; |
| 26 | import static com.android.internal.widget.PasswordValidationError.NOT_ENOUGH_LOWER_CASE; |
| 27 | import static com.android.internal.widget.PasswordValidationError.NOT_ENOUGH_NON_DIGITS; |
| 28 | import static com.android.internal.widget.PasswordValidationError.NOT_ENOUGH_NON_LETTER; |
| 29 | import static com.android.internal.widget.PasswordValidationError.NOT_ENOUGH_SYMBOLS; |
| 30 | import static com.android.internal.widget.PasswordValidationError.NOT_ENOUGH_UPPER_CASE; |
| 31 | import static com.android.internal.widget.PasswordValidationError.RECENTLY_USED; |
| 32 | import static com.android.internal.widget.PasswordValidationError.TOO_LONG; |
| 33 | import static com.android.internal.widget.PasswordValidationError.TOO_SHORT; |
Bernard Chau | 92db5bf | 2018-12-17 18:03:24 +0000 | [diff] [blame] | 34 | import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_REQUESTED_MIN_COMPLEXITY; |
| 35 | |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 36 | import android.app.Activity; |
Jim Miller | af366a3 | 2010-03-25 18:45:22 -0700 | [diff] [blame] | 37 | import android.app.admin.DevicePolicyManager; |
Bernard Chau | 92db5bf | 2018-12-17 18:03:24 +0000 | [diff] [blame] | 38 | import android.app.admin.DevicePolicyManager.PasswordComplexity; |
Andrew Scull | 27ca263 | 2016-08-02 14:18:58 +0100 | [diff] [blame] | 39 | import android.app.admin.PasswordMetrics; |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 40 | import android.app.settings.SettingsEnums; |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 41 | import android.content.Context; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 42 | import android.content.Intent; |
Maurice Lam | 9990f39 | 2017-06-28 15:06:09 -0700 | [diff] [blame] | 43 | import android.content.res.Resources.Theme; |
Maurice Lam | edb3944 | 2017-04-27 18:54:33 -0700 | [diff] [blame] | 44 | import android.graphics.Insets; |
Andrew Sapperstein | ccbb4cf | 2017-07-06 14:30:28 -0700 | [diff] [blame] | 45 | import android.graphics.Typeface; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 46 | import android.os.Bundle; |
Tony Mak | 9ba765b | 2016-08-02 17:09:53 +0100 | [diff] [blame] | 47 | import android.os.Handler; |
| 48 | import android.os.Message; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 49 | import android.text.Editable; |
Jim Miller | 2e28ace | 2010-12-15 10:07:16 -0800 | [diff] [blame] | 50 | import android.text.InputType; |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 51 | import android.text.Selection; |
| 52 | import android.text.Spannable; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 53 | import android.text.TextUtils; |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 54 | import android.text.TextWatcher; |
Andres Morales | 91e6c49 | 2015-05-15 15:20:33 -0700 | [diff] [blame] | 55 | import android.util.Log; |
Irina Dumitrescu | 4b96dc3 | 2019-02-28 15:35:36 +0000 | [diff] [blame] | 56 | import android.util.Pair; |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 57 | import android.view.KeyEvent; |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 58 | import android.view.LayoutInflater; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 59 | import android.view.View; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 60 | import android.view.ViewGroup; |
Maurice Lam | c41e408 | 2017-04-27 19:04:46 -0700 | [diff] [blame] | 61 | import android.view.inputmethod.EditorInfo; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 62 | import android.widget.TextView; |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 63 | import android.widget.TextView.OnEditorActionListener; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 64 | |
Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 65 | import androidx.annotation.StringRes; |
| 66 | import androidx.fragment.app.Fragment; |
| 67 | import androidx.recyclerview.widget.LinearLayoutManager; |
| 68 | import androidx.recyclerview.widget.RecyclerView; |
| 69 | |
Bernard Chau | 92db5bf | 2018-12-17 18:03:24 +0000 | [diff] [blame] | 70 | import com.android.internal.annotations.VisibleForTesting; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 71 | import com.android.internal.widget.LockPatternUtils; |
| 72 | import com.android.internal.widget.LockPatternUtils.RequestThrottledException; |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 73 | import com.android.internal.widget.LockscreenCredential; |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 74 | import com.android.internal.widget.PasswordValidationError; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 75 | import com.android.internal.widget.TextViewInputDisabler; |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 76 | import com.android.settings.EncryptionInterstitial; |
| 77 | import com.android.settings.R; |
| 78 | import com.android.settings.SettingsActivity; |
Maurice Lam | 9990f39 | 2017-06-28 15:06:09 -0700 | [diff] [blame] | 79 | import com.android.settings.SetupWizardUtils; |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 80 | import com.android.settings.Utils; |
Doris Ling | 7248972 | 2017-11-16 11:03:40 -0800 | [diff] [blame] | 81 | import com.android.settings.core.InstrumentedFragment; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 82 | import com.android.settings.notification.RedactionInterstitial; |
Tarandeep Singh | b0bcbed | 2017-07-14 13:22:07 -0700 | [diff] [blame] | 83 | import com.android.settings.widget.ImeAwareEditText; |
Pasty Chang | c1f8600 | 2018-12-11 02:22:55 +0000 | [diff] [blame] | 84 | |
pastychang | 9bdb59a | 2019-01-21 09:49:15 +0800 | [diff] [blame] | 85 | import com.google.android.setupcompat.template.FooterBarMixin; |
| 86 | import com.google.android.setupcompat.template.FooterButton; |
Pasty Chang | c1f8600 | 2018-12-11 02:22:55 +0000 | [diff] [blame] | 87 | import com.google.android.setupdesign.GlifLayout; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 88 | |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 89 | import java.util.ArrayList; |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 90 | import java.util.Collections; |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 91 | import java.util.List; |
| 92 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 93 | public class ChooseLockPassword extends SettingsActivity { |
Andres Morales | 91e6c49 | 2015-05-15 15:20:33 -0700 | [diff] [blame] | 94 | private static final String TAG = "ChooseLockPassword"; |
| 95 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 96 | @Override |
| 97 | public Intent getIntent() { |
| 98 | Intent modIntent = new Intent(super.getIntent()); |
Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 99 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT, getFragmentClass().getName()); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 100 | return modIntent; |
| 101 | } |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 102 | |
Maurice Lam | 9990f39 | 2017-06-28 15:06:09 -0700 | [diff] [blame] | 103 | @Override |
| 104 | protected void onApplyThemeResource(Theme theme, int resid, boolean first) { |
| 105 | resid = SetupWizardUtils.getTheme(getIntent()); |
| 106 | super.onApplyThemeResource(theme, resid, first); |
| 107 | } |
| 108 | |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 109 | public static class IntentBuilder { |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 110 | |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 111 | private final Intent mIntent; |
Clara Bayarri | fe432e8 | 2015-10-12 12:07:02 +0100 | [diff] [blame] | 112 | |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 113 | public IntentBuilder(Context context) { |
| 114 | mIntent = new Intent(context, ChooseLockPassword.class); |
| 115 | mIntent.putExtra(ChooseLockGeneric.CONFIRM_CREDENTIALS, false); |
| 116 | mIntent.putExtra(EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, false); |
Pavel Grafov | 40e187b | 2017-10-11 22:57:09 +0100 | [diff] [blame] | 117 | mIntent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, false); |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 118 | } |
Andres Morales | a0e1236 | 2015-04-02 09:00:41 -0700 | [diff] [blame] | 119 | |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 120 | public IntentBuilder setPasswordQuality(int quality) { |
| 121 | mIntent.putExtra(LockPatternUtils.PASSWORD_TYPE_KEY, quality); |
| 122 | return this; |
| 123 | } |
Clara Bayarri | fe432e8 | 2015-10-12 12:07:02 +0100 | [diff] [blame] | 124 | |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 125 | public IntentBuilder setUserId(int userId) { |
| 126 | mIntent.putExtra(Intent.EXTRA_USER_ID, userId); |
| 127 | return this; |
| 128 | } |
| 129 | |
| 130 | public IntentBuilder setChallenge(long challenge) { |
| 131 | mIntent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, true); |
| 132 | mIntent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge); |
| 133 | return this; |
| 134 | } |
| 135 | |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 136 | public IntentBuilder setPassword(LockscreenCredential password) { |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 137 | mIntent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD, password); |
| 138 | return this; |
| 139 | } |
| 140 | |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 141 | public IntentBuilder setForFingerprint(boolean forFingerprint) { |
| 142 | mIntent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, forFingerprint); |
| 143 | return this; |
| 144 | } |
| 145 | |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 146 | public IntentBuilder setForFace(boolean forFace) { |
| 147 | mIntent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE, forFace); |
| 148 | return this; |
| 149 | } |
| 150 | |
Bernard Chau | 92db5bf | 2018-12-17 18:03:24 +0000 | [diff] [blame] | 151 | public IntentBuilder setRequestedMinComplexity(@PasswordComplexity int level) { |
| 152 | mIntent.putExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY, level); |
| 153 | return this; |
| 154 | } |
| 155 | |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 156 | public Intent build() { |
| 157 | return mIntent; |
| 158 | } |
Clara Bayarri | fe432e8 | 2015-10-12 12:07:02 +0100 | [diff] [blame] | 159 | } |
| 160 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 161 | @Override |
Amith Yamasani | a677ee2 | 2013-07-26 13:38:41 -0700 | [diff] [blame] | 162 | protected boolean isValidFragment(String fragmentName) { |
| 163 | if (ChooseLockPasswordFragment.class.getName().equals(fragmentName)) return true; |
| 164 | return false; |
| 165 | } |
| 166 | |
Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 167 | /* package */ Class<? extends Fragment> getFragmentClass() { |
| 168 | return ChooseLockPasswordFragment.class; |
| 169 | } |
| 170 | |
Amith Yamasani | a677ee2 | 2013-07-26 13:38:41 -0700 | [diff] [blame] | 171 | @Override |
Udam Saini | 71fde52 | 2016-03-30 13:38:05 -0700 | [diff] [blame] | 172 | protected void onCreate(Bundle savedInstanceState) { |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 173 | super.onCreate(savedInstanceState); |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 174 | final boolean forFingerprint = getIntent() |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 175 | .getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, false); |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 176 | final boolean forFace = getIntent() |
| 177 | .getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE, false); |
| 178 | |
| 179 | CharSequence msg = getText(R.string.lockpassword_choose_your_screen_lock_header); |
| 180 | if (forFingerprint) { |
| 181 | msg = getText(R.string.lockpassword_choose_your_password_header_for_fingerprint); |
| 182 | } else if (forFace) { |
| 183 | msg = getText(R.string.lockpassword_choose_your_password_header_for_face); |
| 184 | } |
| 185 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 186 | setTitle(msg); |
Fan Zhang | 9db66a5 | 2019-05-10 14:18:33 -0700 | [diff] [blame] | 187 | findViewById(R.id.content_parent).setFitsSystemWindows(false); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 188 | } |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 189 | |
Doris Ling | 7248972 | 2017-11-16 11:03:40 -0800 | [diff] [blame] | 190 | public static class ChooseLockPasswordFragment extends InstrumentedFragment |
pastychang | 76ad11c | 2019-01-18 14:28:27 +0800 | [diff] [blame] | 191 | implements OnEditorActionListener, TextWatcher, SaveAndFinishWorker.Listener { |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 192 | private static final String KEY_FIRST_PASSWORD = "first_password"; |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 193 | private static final String KEY_UI_STAGE = "ui_stage"; |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 194 | private static final String KEY_CURRENT_CREDENTIAL = "current_credential"; |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 195 | private static final String FRAGMENT_TAG_SAVE_AND_FINISH = "save_and_finish_worker"; |
Andres Morales | a0e1236 | 2015-04-02 09:00:41 -0700 | [diff] [blame] | 196 | |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 197 | private LockscreenCredential mCurrentCredential; |
| 198 | private LockscreenCredential mChosenPassword; |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 199 | private boolean mHasChallenge; |
| 200 | private long mChallenge; |
Tarandeep Singh | b0bcbed | 2017-07-14 13:22:07 -0700 | [diff] [blame] | 201 | private ImeAwareEditText mPasswordEntry; |
Xiyuan Xia | f2c2c19 | 2015-05-15 13:37:04 -0700 | [diff] [blame] | 202 | private TextViewInputDisabler mPasswordEntryInputDisabler; |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 203 | |
| 204 | // Minimum password metrics enforced by admins. |
| 205 | private PasswordMetrics mMinMetrics; |
| 206 | private List<PasswordValidationError> mValidationErrors; |
| 207 | |
| 208 | @PasswordComplexity private int mMinComplexity = PASSWORD_COMPLEXITY_NONE; |
Maurice Lam | edb3944 | 2017-04-27 18:54:33 -0700 | [diff] [blame] | 209 | protected int mUserId; |
Rubin Xu | c33e2a1 | 2018-03-30 20:51:24 +0100 | [diff] [blame] | 210 | private byte[] mPasswordHistoryHashFactor; |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 211 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 212 | private LockPatternUtils mLockPatternUtils; |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 213 | private SaveAndFinishWorker mSaveAndFinishWorker; |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 214 | private int mRequestedQuality = DevicePolicyManager.PASSWORD_QUALITY_NUMERIC; |
| 215 | private ChooseLockSettingsHelper mChooseLockSettingsHelper; |
Maurice Lam | 62c0c3c | 2017-07-10 18:15:10 -0700 | [diff] [blame] | 216 | protected Stage mUiStage = Stage.Introduction; |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 217 | private PasswordRequirementAdapter mPasswordRequirementAdapter; |
Maurice Lam | 8df7173 | 2017-05-18 20:42:58 -0700 | [diff] [blame] | 218 | private GlifLayout mLayout; |
Maurice Lam | 562e539 | 2017-06-27 17:38:06 -0700 | [diff] [blame] | 219 | protected boolean mForFingerprint; |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 220 | protected boolean mForFace; |
Paul Lawrence | 1f8fb0f | 2015-08-12 13:49:34 -0700 | [diff] [blame] | 221 | |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 222 | private LockscreenCredential mFirstPassword; |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 223 | private RecyclerView mPasswordRestrictionView; |
Maurice Lam | edb3944 | 2017-04-27 18:54:33 -0700 | [diff] [blame] | 224 | protected boolean mIsAlphaMode; |
pastychang | 76ad11c | 2019-01-18 14:28:27 +0800 | [diff] [blame] | 225 | protected FooterButton mSkipOrClearButton; |
| 226 | private FooterButton mNextButton; |
Maurice Lam | 3eb4c83 | 2017-08-02 20:11:28 -0700 | [diff] [blame] | 227 | private TextView mMessage; |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 228 | |
Tony Mak | 9ba765b | 2016-08-02 17:09:53 +0100 | [diff] [blame] | 229 | private TextChangedHandler mTextChangedHandler; |
| 230 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 231 | private static final int CONFIRM_EXISTING_REQUEST = 58; |
| 232 | static final int RESULT_FINISHED = RESULT_FIRST_USER; |
Amith Yamasani | 552bc61 | 2011-10-07 13:58:39 -0700 | [diff] [blame] | 233 | |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 234 | /** |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 235 | * Keep track internally of where the user is in choosing a pattern. |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 236 | */ |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 237 | protected enum Stage { |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 238 | |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 239 | Introduction( |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 240 | R.string.lockpassword_choose_your_screen_lock_header, // password |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 241 | R.string.lockpassword_choose_your_password_header_for_fingerprint, |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 242 | R.string.lockpassword_choose_your_password_header_for_face, |
| 243 | R.string.lockpassword_choose_your_screen_lock_header, // pin |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 244 | R.string.lockpassword_choose_your_pin_header_for_fingerprint, |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 245 | R.string.lockpassword_choose_your_pin_header_for_face, |
| 246 | R.string.lockpassword_choose_your_password_message, // added security message |
| 247 | R.string.lock_settings_picker_biometrics_added_security_message, |
Maurice Lam | 3eb4c83 | 2017-08-02 20:11:28 -0700 | [diff] [blame] | 248 | R.string.lockpassword_choose_your_pin_message, |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 249 | R.string.lock_settings_picker_biometrics_added_security_message, |
Maurice Lam | c57b19d | 2017-06-23 19:15:06 -0700 | [diff] [blame] | 250 | R.string.next_label), |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 251 | |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 252 | NeedToConfirm( |
| 253 | R.string.lockpassword_confirm_your_password_header, |
| 254 | R.string.lockpassword_confirm_your_password_header, |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 255 | R.string.lockpassword_confirm_your_password_header, |
| 256 | R.string.lockpassword_confirm_your_pin_header, |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 257 | R.string.lockpassword_confirm_your_pin_header, |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 258 | R.string.lockpassword_confirm_your_pin_header, |
Maurice Lam | 3eb4c83 | 2017-08-02 20:11:28 -0700 | [diff] [blame] | 259 | 0, |
| 260 | 0, |
| 261 | 0, |
| 262 | 0, |
Maurice Lam | ac8024e | 2017-10-18 16:16:35 -0700 | [diff] [blame] | 263 | R.string.lockpassword_confirm_label), |
Konstantin Lopyrev | 57fbf69 | 2010-05-27 16:01:41 -0700 | [diff] [blame] | 264 | |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 265 | ConfirmWrong( |
| 266 | R.string.lockpassword_confirm_passwords_dont_match, |
| 267 | R.string.lockpassword_confirm_passwords_dont_match, |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 268 | R.string.lockpassword_confirm_passwords_dont_match, |
| 269 | R.string.lockpassword_confirm_pins_dont_match, |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 270 | R.string.lockpassword_confirm_pins_dont_match, |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 271 | R.string.lockpassword_confirm_pins_dont_match, |
Maurice Lam | 3eb4c83 | 2017-08-02 20:11:28 -0700 | [diff] [blame] | 272 | 0, |
| 273 | 0, |
| 274 | 0, |
| 275 | 0, |
Kevin Chyn | d7b4b1b | 2018-02-28 17:28:15 -0800 | [diff] [blame] | 276 | R.string.lockpassword_confirm_label); |
Konstantin Lopyrev | 57fbf69 | 2010-05-27 16:01:41 -0700 | [diff] [blame] | 277 | |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 278 | Stage(int hintInAlpha, int hintInAlphaForFingerprint, int hintInAlphaForFace, |
| 279 | int hintInNumeric, int hintInNumericForFingerprint, int hintInNumericForFace, |
| 280 | int messageInAlpha, int messageInAlphaForBiometrics, |
| 281 | int messageInNumeric, int messageInNumericForBiometrics, |
Maurice Lam | 3eb4c83 | 2017-08-02 20:11:28 -0700 | [diff] [blame] | 282 | int nextButtonText) { |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 283 | this.alphaHint = hintInAlpha; |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 284 | this.alphaHintForFingerprint = hintInAlphaForFingerprint; |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 285 | this.alphaHintForFace = hintInAlphaForFace; |
| 286 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 287 | this.numericHint = hintInNumeric; |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 288 | this.numericHintForFingerprint = hintInNumericForFingerprint; |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 289 | this.numericHintForFace = hintInNumericForFace; |
| 290 | |
Maurice Lam | 3eb4c83 | 2017-08-02 20:11:28 -0700 | [diff] [blame] | 291 | this.alphaMessage = messageInAlpha; |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 292 | this.alphaMessageForBiometrics = messageInAlphaForBiometrics; |
Maurice Lam | 3eb4c83 | 2017-08-02 20:11:28 -0700 | [diff] [blame] | 293 | this.numericMessage = messageInNumeric; |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 294 | this.numericMessageForBiometrics = messageInNumericForBiometrics; |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 295 | this.buttonText = nextButtonText; |
Jim Miller | bbb4afa | 2010-04-08 19:40:19 -0700 | [diff] [blame] | 296 | } |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 297 | |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 298 | public static final int TYPE_NONE = 0; |
| 299 | public static final int TYPE_FINGERPRINT = 1; |
| 300 | public static final int TYPE_FACE = 2; |
| 301 | |
| 302 | // Password |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 303 | public final int alphaHint; |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 304 | public final int alphaHintForFingerprint; |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 305 | public final int alphaHintForFace; |
| 306 | |
| 307 | // PIN |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 308 | public final int numericHint; |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 309 | public final int numericHintForFingerprint; |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 310 | public final int numericHintForFace; |
| 311 | |
Maurice Lam | 3eb4c83 | 2017-08-02 20:11:28 -0700 | [diff] [blame] | 312 | public final int alphaMessage; |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 313 | public final int alphaMessageForBiometrics; |
Maurice Lam | 3eb4c83 | 2017-08-02 20:11:28 -0700 | [diff] [blame] | 314 | public final int numericMessage; |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 315 | public final int numericMessageForBiometrics; |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 316 | public final int buttonText; |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 317 | |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 318 | public @StringRes int getHint(boolean isAlpha, int type) { |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 319 | if (isAlpha) { |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 320 | if (type == TYPE_FINGERPRINT) { |
| 321 | return alphaHintForFingerprint; |
| 322 | } else if (type == TYPE_FACE) { |
| 323 | return alphaHintForFace; |
| 324 | } else { |
| 325 | return alphaHint; |
| 326 | } |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 327 | } else { |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 328 | if (type == TYPE_FINGERPRINT) { |
| 329 | return numericHintForFingerprint; |
| 330 | } else if (type == TYPE_FACE) { |
| 331 | return numericHintForFace; |
| 332 | } else { |
| 333 | return numericHint; |
| 334 | } |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 335 | } |
| 336 | } |
Maurice Lam | 3eb4c83 | 2017-08-02 20:11:28 -0700 | [diff] [blame] | 337 | |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 338 | public @StringRes int getMessage(boolean isAlpha, int type) { |
Maurice Lam | 3eb4c83 | 2017-08-02 20:11:28 -0700 | [diff] [blame] | 339 | if (isAlpha) { |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 340 | return type != TYPE_NONE ? alphaMessageForBiometrics : alphaMessage; |
Maurice Lam | 3eb4c83 | 2017-08-02 20:11:28 -0700 | [diff] [blame] | 341 | } else { |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 342 | return type != TYPE_NONE ? numericMessageForBiometrics : numericMessage; |
Maurice Lam | 3eb4c83 | 2017-08-02 20:11:28 -0700 | [diff] [blame] | 343 | } |
| 344 | } |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 345 | } |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 346 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 347 | // required constructor for fragments |
| 348 | public ChooseLockPasswordFragment() { |
Jim Miller | 2f9dbcb | 2010-02-09 19:08:02 -0800 | [diff] [blame] | 349 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 350 | } |
Jim Miller | 2f9dbcb | 2010-02-09 19:08:02 -0800 | [diff] [blame] | 351 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 352 | @Override |
| 353 | public void onCreate(Bundle savedInstanceState) { |
| 354 | super.onCreate(savedInstanceState); |
| 355 | mLockPatternUtils = new LockPatternUtils(getActivity()); |
| 356 | Intent intent = getActivity().getIntent(); |
Amith Yamasani | 6602677 | 2013-09-25 14:05:33 -0700 | [diff] [blame] | 357 | if (!(getActivity() instanceof ChooseLockPassword)) { |
| 358 | throw new SecurityException("Fragment contained in wrong activity"); |
| 359 | } |
Clara Bayarri | fe432e8 | 2015-10-12 12:07:02 +0100 | [diff] [blame] | 360 | // Only take this argument into account if it belongs to the current profile. |
Benjamin Franz | 194300d | 2016-01-13 12:16:25 +0000 | [diff] [blame] | 361 | mUserId = Utils.getUserIdFromBundle(getActivity(), intent.getExtras()); |
Maurice Lam | b49526e | 2017-05-31 17:55:43 -0700 | [diff] [blame] | 362 | mForFingerprint = intent.getBooleanExtra( |
| 363 | ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, false); |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 364 | mForFace = intent.getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE, false); |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 365 | mMinComplexity = intent.getIntExtra( |
Bernard Chau | 92db5bf | 2018-12-17 18:03:24 +0000 | [diff] [blame] | 366 | EXTRA_KEY_REQUESTED_MIN_COMPLEXITY, PASSWORD_COMPLEXITY_NONE); |
Bernard Chau | 92db5bf | 2018-12-17 18:03:24 +0000 | [diff] [blame] | 367 | |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 368 | mRequestedQuality = intent.getIntExtra( |
| 369 | LockPatternUtils.PASSWORD_TYPE_KEY, PASSWORD_QUALITY_NUMERIC); |
| 370 | |
| 371 | mMinMetrics = mLockPatternUtils.getRequestedPasswordMetrics(mUserId); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 372 | mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity()); |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 373 | |
| 374 | if (intent.getBooleanExtra( |
| 375 | ChooseLockSettingsHelper.EXTRA_KEY_FOR_CHANGE_CRED_REQUIRED_FOR_BOOT, false)) { |
| 376 | SaveAndFinishWorker w = new SaveAndFinishWorker(); |
| 377 | final boolean required = getActivity().getIntent().getBooleanExtra( |
| 378 | EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true); |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 379 | LockscreenCredential currentCredential = intent.getParcelableExtra( |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 380 | ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD); |
Rich Cannings | b27c430 | 2019-02-19 13:15:30 -0800 | [diff] [blame] | 381 | |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 382 | w.setBlocking(true); |
| 383 | w.setListener(this); |
Rich Cannings | b27c430 | 2019-02-19 13:15:30 -0800 | [diff] [blame] | 384 | w.start(mChooseLockSettingsHelper.utils(), required, false, 0, |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 385 | currentCredential, currentCredential, mUserId); |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 386 | } |
Tony Mak | 9ba765b | 2016-08-02 17:09:53 +0100 | [diff] [blame] | 387 | mTextChangedHandler = new TextChangedHandler(); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 388 | } |
Jim Miller | 2f9dbcb | 2010-02-09 19:08:02 -0800 | [diff] [blame] | 389 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 390 | @Override |
| 391 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 392 | Bundle savedInstanceState) { |
Maurice Lam | 44f2736 | 2016-07-08 18:38:48 -0700 | [diff] [blame] | 393 | return inflater.inflate(R.layout.choose_lock_password, container, false); |
Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 394 | } |
Jim Miller | 2f9dbcb | 2010-02-09 19:08:02 -0800 | [diff] [blame] | 395 | |
Maurice Lam | 6b19fa9 | 2014-11-25 19:25:56 -0800 | [diff] [blame] | 396 | @Override |
| 397 | public void onViewCreated(View view, Bundle savedInstanceState) { |
| 398 | super.onViewCreated(view, savedInstanceState); |
Jim Miller | 2f9dbcb | 2010-02-09 19:08:02 -0800 | [diff] [blame] | 399 | |
Maurice Lam | 8df7173 | 2017-05-18 20:42:58 -0700 | [diff] [blame] | 400 | mLayout = (GlifLayout) view; |
| 401 | |
Maurice Lam | edb3944 | 2017-04-27 18:54:33 -0700 | [diff] [blame] | 402 | // Make the password container consume the optical insets so the edit text is aligned |
| 403 | // with the sides of the parent visually. |
| 404 | ViewGroup container = view.findViewById(R.id.password_container); |
| 405 | container.setOpticalInsets(Insets.NONE); |
| 406 | |
pastychang | 9bdb59a | 2019-01-21 09:49:15 +0800 | [diff] [blame] | 407 | final FooterBarMixin mixin = mLayout.getMixin(FooterBarMixin.class); |
pastychang | 76ad11c | 2019-01-18 14:28:27 +0800 | [diff] [blame] | 408 | mixin.setSecondaryButton( |
| 409 | new FooterButton.Builder(getActivity()) |
| 410 | .setText(R.string.lockpassword_clear_label) |
| 411 | .setListener(this::onSkipOrClearButtonClick) |
| 412 | .setButtonType(FooterButton.ButtonType.SKIP) |
| 413 | .setTheme(R.style.SudGlifButton_Secondary) |
| 414 | .build() |
| 415 | ); |
| 416 | mixin.setPrimaryButton( |
| 417 | new FooterButton.Builder(getActivity()) |
| 418 | .setText(R.string.next_label) |
| 419 | .setListener(this::onNextButtonClick) |
| 420 | .setButtonType(FooterButton.ButtonType.NEXT) |
| 421 | .setTheme(R.style.SudGlifButton_Primary) |
| 422 | .build() |
| 423 | ); |
| 424 | mSkipOrClearButton = mixin.getSecondaryButton(); |
| 425 | mNextButton = mixin.getPrimaryButton(); |
Maurice Lam | 3eb4c83 | 2017-08-02 20:11:28 -0700 | [diff] [blame] | 426 | |
pastychang | fa68ec4 | 2019-04-12 16:22:17 +0800 | [diff] [blame] | 427 | mMessage = view.findViewById(R.id.sud_layout_description); |
Maurice Lam | d793590 | 2017-06-21 17:09:33 -0700 | [diff] [blame] | 428 | if (mForFingerprint) { |
Ajay Nadathur | 7af28ec | 2017-07-21 15:11:21 -0700 | [diff] [blame] | 429 | mLayout.setIcon(getActivity().getDrawable(R.drawable.ic_fingerprint_header)); |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 430 | } else if (mForFace) { |
| 431 | mLayout.setIcon(getActivity().getDrawable(R.drawable.ic_face_header)); |
Maurice Lam | d793590 | 2017-06-21 17:09:33 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 434 | mIsAlphaMode = DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC == mRequestedQuality |
| 435 | || DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC == mRequestedQuality |
| 436 | || DevicePolicyManager.PASSWORD_QUALITY_COMPLEX == mRequestedQuality; |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 437 | |
| 438 | setupPasswordRequirementsView(view); |
| 439 | |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 440 | mPasswordRestrictionView.setLayoutManager(new LinearLayoutManager(getActivity())); |
Tarandeep Singh | b0bcbed | 2017-07-14 13:22:07 -0700 | [diff] [blame] | 441 | mPasswordEntry = view.findViewById(R.id.password_entry); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 442 | mPasswordEntry.setOnEditorActionListener(this); |
| 443 | mPasswordEntry.addTextChangedListener(this); |
Tony Mak | 9c26c9d | 2016-07-01 13:55:47 +0100 | [diff] [blame] | 444 | mPasswordEntry.requestFocus(); |
Xiyuan Xia | f2c2c19 | 2015-05-15 13:37:04 -0700 | [diff] [blame] | 445 | mPasswordEntryInputDisabler = new TextViewInputDisabler(mPasswordEntry); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 446 | |
Jim Miller | 9757e30 | 2010-12-17 18:23:23 -0800 | [diff] [blame] | 447 | final Activity activity = getActivity(); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 448 | |
Jim Miller | 2e28ace | 2010-12-15 10:07:16 -0800 | [diff] [blame] | 449 | int currentType = mPasswordEntry.getInputType(); |
| 450 | mPasswordEntry.setInputType(mIsAlphaMode ? currentType |
Jim Miller | 3b46f49 | 2011-01-17 15:50:05 -0800 | [diff] [blame] | 451 | : (InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD)); |
joshmccloskey | fc397f7 | 2019-08-27 12:01:30 -0700 | [diff] [blame] | 452 | if (mIsAlphaMode) { |
| 453 | mPasswordEntry.setContentDescription( |
| 454 | getString(R.string.unlock_set_unlock_password_title)); |
| 455 | } else { |
| 456 | mPasswordEntry.setContentDescription( |
| 457 | getString(R.string.unlock_set_unlock_pin_title)); |
| 458 | } |
Andrew Sapperstein | ccbb4cf | 2017-07-06 14:30:28 -0700 | [diff] [blame] | 459 | // Can't set via XML since setInputType resets the fontFamily to null |
| 460 | mPasswordEntry.setTypeface(Typeface.create( |
| 461 | getContext().getString(com.android.internal.R.string.config_headlineFontFamily), |
| 462 | Typeface.NORMAL)); |
Jim Miller | 2e28ace | 2010-12-15 10:07:16 -0800 | [diff] [blame] | 463 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 464 | Intent intent = getActivity().getIntent(); |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 465 | final boolean confirmCredentials = intent.getBooleanExtra( |
| 466 | ChooseLockGeneric.CONFIRM_CREDENTIALS, true); |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 467 | mCurrentCredential = intent.getParcelableExtra( |
Rich Cannings | b27c430 | 2019-02-19 13:15:30 -0800 | [diff] [blame] | 468 | ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD); |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 469 | mHasChallenge = intent.getBooleanExtra( |
| 470 | ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, false); |
| 471 | mChallenge = intent.getLongExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, 0); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 472 | if (savedInstanceState == null) { |
| 473 | updateStage(Stage.Introduction); |
| 474 | if (confirmCredentials) { |
| 475 | mChooseLockSettingsHelper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST, |
Clara Bayarri | fe432e8 | 2015-10-12 12:07:02 +0100 | [diff] [blame] | 476 | getString(R.string.unlock_set_unlock_launch_picker_title), true, |
| 477 | mUserId); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 478 | } |
| 479 | } else { |
Rich Cannings | b27c430 | 2019-02-19 13:15:30 -0800 | [diff] [blame] | 480 | |
Andres Morales | a0e1236 | 2015-04-02 09:00:41 -0700 | [diff] [blame] | 481 | // restore from previous state |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 482 | mFirstPassword = savedInstanceState.getParcelable(KEY_FIRST_PASSWORD); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 483 | final String state = savedInstanceState.getString(KEY_UI_STAGE); |
| 484 | if (state != null) { |
| 485 | mUiStage = Stage.valueOf(state); |
| 486 | updateStage(mUiStage); |
| 487 | } |
Andres Morales | a0e1236 | 2015-04-02 09:00:41 -0700 | [diff] [blame] | 488 | |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 489 | if (mCurrentCredential == null) { |
| 490 | mCurrentCredential = savedInstanceState.getParcelable(KEY_CURRENT_CREDENTIAL); |
Andres Morales | a0e1236 | 2015-04-02 09:00:41 -0700 | [diff] [blame] | 491 | } |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 492 | |
| 493 | // Re-attach to the exiting worker if there is one. |
| 494 | mSaveAndFinishWorker = (SaveAndFinishWorker) getFragmentManager().findFragmentByTag( |
| 495 | FRAGMENT_TAG_SAVE_AND_FINISH); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 496 | } |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 497 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 498 | if (activity instanceof SettingsActivity) { |
| 499 | final SettingsActivity sa = (SettingsActivity) activity; |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 500 | int title = Stage.Introduction.getHint(mIsAlphaMode, getStageType()); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 501 | sa.setTitle(title); |
Maurice Lam | 8df7173 | 2017-05-18 20:42:58 -0700 | [diff] [blame] | 502 | mLayout.setHeaderText(title); |
Jim Miller | 9757e30 | 2010-12-17 18:23:23 -0800 | [diff] [blame] | 503 | } |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 504 | } |
| 505 | |
pastychang | 7a083f8 | 2019-03-26 16:09:34 +0800 | [diff] [blame] | 506 | protected int getStageType() { |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 507 | return mForFingerprint ? Stage.TYPE_FINGERPRINT : |
| 508 | mForFace ? Stage.TYPE_FACE : |
| 509 | Stage.TYPE_NONE; |
| 510 | } |
| 511 | |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 512 | private void setupPasswordRequirementsView(View view) { |
Pavel Grafov | 5f13910 | 2018-05-04 17:09:28 +0100 | [diff] [blame] | 513 | mPasswordRestrictionView = view.findViewById(R.id.password_requirements_view); |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 514 | mPasswordRestrictionView.setLayoutManager(new LinearLayoutManager(getActivity())); |
| 515 | mPasswordRequirementAdapter = new PasswordRequirementAdapter(); |
| 516 | mPasswordRestrictionView.setAdapter(mPasswordRequirementAdapter); |
| 517 | } |
| 518 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 519 | @Override |
Fan Zhang | 6507613 | 2016-08-08 10:25:13 -0700 | [diff] [blame] | 520 | public int getMetricsCategory() { |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 521 | return SettingsEnums.CHOOSE_LOCK_PASSWORD; |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | @Override |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 525 | public void onResume() { |
| 526 | super.onResume(); |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 527 | updateStage(mUiStage); |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 528 | if (mSaveAndFinishWorker != null) { |
| 529 | mSaveAndFinishWorker.setListener(this); |
| 530 | } else { |
Tony Mak | 9c26c9d | 2016-07-01 13:55:47 +0100 | [diff] [blame] | 531 | mPasswordEntry.requestFocus(); |
Tarandeep Singh | b0bcbed | 2017-07-14 13:22:07 -0700 | [diff] [blame] | 532 | mPasswordEntry.scheduleShowSoftInput(); |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 533 | } |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 534 | } |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 535 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 536 | @Override |
Amith Yamasani | 552bc61 | 2011-10-07 13:58:39 -0700 | [diff] [blame] | 537 | public void onPause() { |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 538 | if (mSaveAndFinishWorker != null) { |
| 539 | mSaveAndFinishWorker.setListener(null); |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 540 | } |
Amith Yamasani | 552bc61 | 2011-10-07 13:58:39 -0700 | [diff] [blame] | 541 | super.onPause(); |
| 542 | } |
| 543 | |
| 544 | @Override |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 545 | public void onSaveInstanceState(Bundle outState) { |
| 546 | super.onSaveInstanceState(outState); |
| 547 | outState.putString(KEY_UI_STAGE, mUiStage.name()); |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 548 | outState.putParcelable(KEY_FIRST_PASSWORD, mFirstPassword); |
| 549 | outState.putParcelable(KEY_CURRENT_CREDENTIAL, mCurrentCredential); |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 550 | } |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 551 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 552 | @Override |
| 553 | public void onActivityResult(int requestCode, int resultCode, |
| 554 | Intent data) { |
| 555 | super.onActivityResult(requestCode, resultCode, data); |
| 556 | switch (requestCode) { |
| 557 | case CONFIRM_EXISTING_REQUEST: |
| 558 | if (resultCode != Activity.RESULT_OK) { |
| 559 | getActivity().setResult(RESULT_FINISHED); |
| 560 | getActivity().finish(); |
Andres Morales | a0e1236 | 2015-04-02 09:00:41 -0700 | [diff] [blame] | 561 | } else { |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 562 | mCurrentCredential = data.getParcelableExtra( |
Andres Morales | a0e1236 | 2015-04-02 09:00:41 -0700 | [diff] [blame] | 563 | ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 564 | } |
| 565 | break; |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 566 | } |
| 567 | } |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 568 | |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 569 | protected Intent getRedactionInterstitialIntent(Context context) { |
Clara Bayarri | f6077f4 | 2016-01-25 17:21:24 +0000 | [diff] [blame] | 570 | return RedactionInterstitial.createStartIntent(context, mUserId); |
Maurice Lam | ecd2b7b | 2014-12-01 10:41:49 -0800 | [diff] [blame] | 571 | } |
| 572 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 573 | protected void updateStage(Stage stage) { |
alanv | eef72c3 | 2012-10-03 17:10:50 -0700 | [diff] [blame] | 574 | final Stage previousStage = mUiStage; |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 575 | mUiStage = stage; |
| 576 | updateUi(); |
alanv | eef72c3 | 2012-10-03 17:10:50 -0700 | [diff] [blame] | 577 | |
| 578 | // If the stage changed, announce the header for accessibility. This |
| 579 | // is a no-op when accessibility is disabled. |
| 580 | if (previousStage != stage) { |
Maurice Lam | 8df7173 | 2017-05-18 20:42:58 -0700 | [diff] [blame] | 581 | mLayout.announceForAccessibility(mLayout.getHeaderText()); |
alanv | eef72c3 | 2012-10-03 17:10:50 -0700 | [diff] [blame] | 582 | } |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 583 | } |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 584 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 585 | /** |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 586 | * Validates PIN/Password and returns the validation result and updates mValidationErrors |
| 587 | * and mPasswordReused to reflect validation results. |
Bernard Chau | 92db5bf | 2018-12-17 18:03:24 +0000 | [diff] [blame] | 588 | * |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 589 | * @param credential credential the user typed in. |
| 590 | * @return whether password satisfies all the requirements. |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 591 | */ |
Bernard Chau | 92db5bf | 2018-12-17 18:03:24 +0000 | [diff] [blame] | 592 | @VisibleForTesting |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 593 | boolean validatePassword(LockscreenCredential credential) { |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 594 | final byte[] password = credential.getCredential(); |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 595 | mValidationErrors = PasswordMetrics.validatePassword( |
| 596 | mMinMetrics, mMinComplexity, !mIsAlphaMode, password); |
| 597 | if (mValidationErrors.isEmpty() && mLockPatternUtils.checkPasswordHistory( |
| 598 | password, getPasswordHistoryHashFactor(), mUserId)) { |
| 599 | mValidationErrors = |
| 600 | Collections.singletonList(new PasswordValidationError(RECENTLY_USED)); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 601 | } |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 602 | return mValidationErrors.isEmpty(); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 603 | } |
| 604 | |
Rubin Xu | c33e2a1 | 2018-03-30 20:51:24 +0100 | [diff] [blame] | 605 | /** |
| 606 | * Lazily compute and return the history hash factor of the current user (mUserId), used for |
| 607 | * password history check. |
| 608 | */ |
| 609 | private byte[] getPasswordHistoryHashFactor() { |
| 610 | if (mPasswordHistoryHashFactor == null) { |
| 611 | mPasswordHistoryHashFactor = mLockPatternUtils.getPasswordHistoryHashFactor( |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 612 | mCurrentCredential != null ? mCurrentCredential |
| 613 | : LockscreenCredential.createNone(), mUserId); |
Rubin Xu | c33e2a1 | 2018-03-30 20:51:24 +0100 | [diff] [blame] | 614 | } |
| 615 | return mPasswordHistoryHashFactor; |
| 616 | } |
| 617 | |
Paul Lawrence | cff37ec | 2015-08-03 09:44:23 -0700 | [diff] [blame] | 618 | public void handleNext() { |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 619 | if (mSaveAndFinishWorker != null) return; |
Rich Cannings | b27c430 | 2019-02-19 13:15:30 -0800 | [diff] [blame] | 620 | // TODO(b/120484642): This is a point of entry for passwords from the UI |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 621 | final Editable passwordText = mPasswordEntry.getText(); |
| 622 | if (TextUtils.isEmpty(passwordText)) { |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 623 | return; |
| 624 | } |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 625 | mChosenPassword = mIsAlphaMode ? LockscreenCredential.createPassword(passwordText) |
| 626 | : LockscreenCredential.createPin(passwordText); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 627 | if (mUiStage == Stage.Introduction) { |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 628 | if (validatePassword(mChosenPassword)) { |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 629 | mFirstPassword = mChosenPassword; |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 630 | mPasswordEntry.setText(""); |
alanv | eef72c3 | 2012-10-03 17:10:50 -0700 | [diff] [blame] | 631 | updateStage(Stage.NeedToConfirm); |
Rich Cannings | b27c430 | 2019-02-19 13:15:30 -0800 | [diff] [blame] | 632 | } else { |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 633 | mChosenPassword.zeroize(); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 634 | } |
| 635 | } else if (mUiStage == Stage.NeedToConfirm) { |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 636 | if (mChosenPassword.equals(mFirstPassword)) { |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 637 | startSaveAndFinish(); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 638 | } else { |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 639 | CharSequence tmp = mPasswordEntry.getText(); |
| 640 | if (tmp != null) { |
| 641 | Selection.setSelection((Spannable) tmp, 0, tmp.length()); |
| 642 | } |
alanv | eef72c3 | 2012-10-03 17:10:50 -0700 | [diff] [blame] | 643 | updateStage(Stage.ConfirmWrong); |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 644 | mChosenPassword.zeroize(); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 645 | } |
| 646 | } |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 647 | } |
| 648 | |
Maurice Lam | af103b4 | 2014-12-03 15:17:46 -0800 | [diff] [blame] | 649 | protected void setNextEnabled(boolean enabled) { |
| 650 | mNextButton.setEnabled(enabled); |
| 651 | } |
| 652 | |
| 653 | protected void setNextText(int text) { |
pastychang | 76ad11c | 2019-01-18 14:28:27 +0800 | [diff] [blame] | 654 | mNextButton.setText(getActivity(), text); |
Maurice Lam | af103b4 | 2014-12-03 15:17:46 -0800 | [diff] [blame] | 655 | } |
| 656 | |
pastychang | 76ad11c | 2019-01-18 14:28:27 +0800 | [diff] [blame] | 657 | protected void onSkipOrClearButtonClick(View view) { |
| 658 | mPasswordEntry.setText(""); |
| 659 | } |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 660 | |
pastychang | 76ad11c | 2019-01-18 14:28:27 +0800 | [diff] [blame] | 661 | protected void onNextButtonClick(View view) { |
| 662 | handleNext(); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 663 | } |
| 664 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 665 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
Jim Miller | 74b1e0a | 2011-04-15 18:52:31 -0700 | [diff] [blame] | 666 | // Check if this was the result of hitting the enter or "done" key |
| 667 | if (actionId == EditorInfo.IME_NULL |
| 668 | || actionId == EditorInfo.IME_ACTION_DONE |
| 669 | || actionId == EditorInfo.IME_ACTION_NEXT) { |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 670 | handleNext(); |
| 671 | return true; |
| 672 | } |
| 673 | return false; |
| 674 | } |
| 675 | |
| 676 | /** |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 677 | * @param errorCode error code returned from password validation. |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 678 | * @return an array of messages describing the error, important messages come first. |
| 679 | */ |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 680 | String[] convertErrorCodeToMessages() { |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 681 | List<String> messages = new ArrayList<>(); |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 682 | for (PasswordValidationError error : mValidationErrors) { |
| 683 | switch (error.errorCode) { |
| 684 | case CONTAINS_INVALID_CHARACTERS: |
| 685 | messages.add(getString(R.string.lockpassword_illegal_character)); |
| 686 | break; |
| 687 | case NOT_ENOUGH_UPPER_CASE: |
| 688 | messages.add(getResources().getQuantityString( |
| 689 | R.plurals.lockpassword_password_requires_uppercase, |
| 690 | error.requirement, error.requirement)); |
| 691 | break; |
| 692 | case NOT_ENOUGH_LOWER_CASE: |
| 693 | messages.add(getResources().getQuantityString( |
| 694 | R.plurals.lockpassword_password_requires_lowercase, |
| 695 | error.requirement, error.requirement)); |
| 696 | break; |
| 697 | case NOT_ENOUGH_LETTERS: |
| 698 | messages.add(getResources().getQuantityString( |
| 699 | R.plurals.lockpassword_password_requires_letters, |
| 700 | error.requirement, error.requirement)); |
| 701 | break; |
| 702 | case NOT_ENOUGH_DIGITS: |
| 703 | messages.add(getResources().getQuantityString( |
| 704 | R.plurals.lockpassword_password_requires_numeric, |
| 705 | error.requirement, error.requirement)); |
| 706 | break; |
| 707 | case NOT_ENOUGH_SYMBOLS: |
| 708 | messages.add(getResources().getQuantityString( |
| 709 | R.plurals.lockpassword_password_requires_symbols, |
| 710 | error.requirement, error.requirement)); |
| 711 | break; |
| 712 | case NOT_ENOUGH_NON_LETTER: |
| 713 | messages.add(getResources().getQuantityString( |
| 714 | R.plurals.lockpassword_password_requires_nonletter, |
| 715 | error.requirement, error.requirement)); |
| 716 | break; |
| 717 | case NOT_ENOUGH_NON_DIGITS: |
| 718 | messages.add(getResources().getQuantityString( |
| 719 | R.plurals.lockpassword_password_requires_nonnumerical, |
| 720 | error.requirement, error.requirement)); |
| 721 | break; |
| 722 | case TOO_SHORT: |
| 723 | messages.add(getResources().getQuantityString( |
| 724 | mIsAlphaMode |
| 725 | ? R.plurals.lockpassword_password_too_short |
| 726 | : R.plurals.lockpassword_pin_too_short, |
| 727 | error.requirement, error.requirement)); |
| 728 | break; |
| 729 | case TOO_LONG: |
| 730 | messages.add(getResources().getQuantityString( |
| 731 | mIsAlphaMode |
| 732 | ? R.plurals.lockpassword_password_too_long |
| 733 | : R.plurals.lockpassword_pin_too_long, |
| 734 | error.requirement + 1, error.requirement + 1)); |
| 735 | break; |
| 736 | case CONTAINS_SEQUENCE: |
| 737 | messages.add(getString(R.string.lockpassword_pin_no_sequential_digits)); |
| 738 | break; |
| 739 | case RECENTLY_USED: |
| 740 | messages.add(getString(mIsAlphaMode |
| 741 | ? R.string.lockpassword_password_recently_used |
| 742 | : R.string.lockpassword_pin_recently_used)); |
| 743 | break; |
| 744 | default: |
| 745 | Log.wtf(TAG, "unknown error validating password: " + error); |
| 746 | } |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 747 | } |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 748 | |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 749 | return messages.toArray(new String[0]); |
Tony Mak | 9ba765b | 2016-08-02 17:09:53 +0100 | [diff] [blame] | 750 | } |
| 751 | |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 752 | /** |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 753 | * Update the hint based on current Stage and length of password entry |
| 754 | */ |
Maurice Lam | 62c0c3c | 2017-07-10 18:15:10 -0700 | [diff] [blame] | 755 | protected void updateUi() { |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 756 | final boolean canInput = mSaveAndFinishWorker == null; |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 757 | |
| 758 | LockscreenCredential password = mIsAlphaMode |
| 759 | ? LockscreenCredential.createPasswordOrNone(mPasswordEntry.getText()) |
| 760 | : LockscreenCredential.createPinOrNone(mPasswordEntry.getText()); |
| 761 | final int length = password.size(); |
Maurice Lam | 163dee9 | 2015-05-19 17:27:12 -0700 | [diff] [blame] | 762 | if (mUiStage == Stage.Introduction) { |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 763 | mPasswordRestrictionView.setVisibility(View.VISIBLE); |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 764 | final boolean passwordCompliant = validatePassword(password); |
| 765 | String[] messages = convertErrorCodeToMessages(); |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 766 | // Update the fulfillment of requirements. |
| 767 | mPasswordRequirementAdapter.setRequirements(messages); |
| 768 | // Enable/Disable the next button accordingly. |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 769 | setNextEnabled(passwordCompliant); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 770 | } else { |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 771 | // Hide password requirement view when we are just asking user to confirm the pw. |
| 772 | mPasswordRestrictionView.setVisibility(View.GONE); |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 773 | setHeaderText(getString(mUiStage.getHint(mIsAlphaMode, getStageType()))); |
Pavel Grafov | 69cac2c | 2019-08-07 13:21:53 +0100 | [diff] [blame] | 774 | setNextEnabled(canInput && length >= LockPatternUtils.MIN_LOCK_PASSWORD_SIZE); |
pastychang | 76ad11c | 2019-01-18 14:28:27 +0800 | [diff] [blame] | 775 | mSkipOrClearButton.setVisibility(toVisibility(canInput && length > 0)); |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 776 | } |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 777 | int message = mUiStage.getMessage(mIsAlphaMode, getStageType()); |
Maurice Lam | 3eb4c83 | 2017-08-02 20:11:28 -0700 | [diff] [blame] | 778 | if (message != 0) { |
| 779 | mMessage.setVisibility(View.VISIBLE); |
| 780 | mMessage.setText(message); |
| 781 | } else { |
| 782 | mMessage.setVisibility(View.INVISIBLE); |
| 783 | } |
Ajay Nadathur | be2246b | 2017-08-02 14:46:26 -0700 | [diff] [blame] | 784 | |
Maurice Lam | af103b4 | 2014-12-03 15:17:46 -0800 | [diff] [blame] | 785 | setNextText(mUiStage.buttonText); |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 786 | mPasswordEntryInputDisabler.setInputEnabled(canInput); |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 787 | password.zeroize(); |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 788 | } |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 789 | |
pastychang | 382d34d | 2018-12-24 17:16:14 +0800 | [diff] [blame] | 790 | protected int toVisibility(boolean visibleOrGone) { |
Ajay Nadathur | be2246b | 2017-08-02 14:46:26 -0700 | [diff] [blame] | 791 | return visibleOrGone ? View.VISIBLE : View.GONE; |
| 792 | } |
| 793 | |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 794 | private void setHeaderText(String text) { |
| 795 | // Only set the text if it is different than the existing one to avoid announcing again. |
Maurice Lam | 8df7173 | 2017-05-18 20:42:58 -0700 | [diff] [blame] | 796 | if (!TextUtils.isEmpty(mLayout.getHeaderText()) |
| 797 | && mLayout.getHeaderText().toString().equals(text)) { |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 798 | return; |
| 799 | } |
Maurice Lam | 8df7173 | 2017-05-18 20:42:58 -0700 | [diff] [blame] | 800 | mLayout.setHeaderText(text); |
Tony Mak | 0bbcdcc | 2016-07-12 11:19:45 +0100 | [diff] [blame] | 801 | } |
| 802 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 803 | public void afterTextChanged(Editable s) { |
| 804 | // Changing the text while error displayed resets to NeedToConfirm state |
| 805 | if (mUiStage == Stage.ConfirmWrong) { |
| 806 | mUiStage = Stage.NeedToConfirm; |
| 807 | } |
Tony Mak | 9ba765b | 2016-08-02 17:09:53 +0100 | [diff] [blame] | 808 | // Schedule the UI update. |
| 809 | mTextChangedHandler.notifyAfterTextChanged(); |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 810 | } |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 811 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 812 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 813 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 814 | } |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 815 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 816 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 817 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 818 | } |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 819 | |
| 820 | private void startSaveAndFinish() { |
| 821 | if (mSaveAndFinishWorker != null) { |
| 822 | Log.w(TAG, "startSaveAndFinish with an existing SaveAndFinishWorker."); |
| 823 | return; |
| 824 | } |
| 825 | |
| 826 | mPasswordEntryInputDisabler.setInputEnabled(false); |
| 827 | setNextEnabled(false); |
| 828 | |
| 829 | mSaveAndFinishWorker = new SaveAndFinishWorker(); |
Robin Lee | 5bb1e4f | 2016-01-27 17:21:00 +0000 | [diff] [blame] | 830 | mSaveAndFinishWorker.setListener(this); |
| 831 | |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 832 | getFragmentManager().beginTransaction().add(mSaveAndFinishWorker, |
| 833 | FRAGMENT_TAG_SAVE_AND_FINISH).commit(); |
Robin Lee | 5bb1e4f | 2016-01-27 17:21:00 +0000 | [diff] [blame] | 834 | getFragmentManager().executePendingTransactions(); |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 835 | |
| 836 | final boolean required = getActivity().getIntent().getBooleanExtra( |
| 837 | EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true); |
| 838 | mSaveAndFinishWorker.start(mLockPatternUtils, required, mHasChallenge, mChallenge, |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 839 | mChosenPassword, mCurrentCredential, mUserId); |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | @Override |
| 843 | public void onChosenLockSaveFinished(boolean wasSecureBefore, Intent resultData) { |
| 844 | getActivity().setResult(RESULT_FINISHED, resultData); |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 845 | |
Rich Cannings | b27c430 | 2019-02-19 13:15:30 -0800 | [diff] [blame] | 846 | if (mChosenPassword != null) { |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 847 | mChosenPassword.zeroize(); |
Rich Cannings | b27c430 | 2019-02-19 13:15:30 -0800 | [diff] [blame] | 848 | } |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 849 | if (mCurrentCredential != null) { |
| 850 | mCurrentCredential.zeroize(); |
Rich Cannings | b27c430 | 2019-02-19 13:15:30 -0800 | [diff] [blame] | 851 | } |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 852 | if (mFirstPassword != null) { |
| 853 | mFirstPassword.zeroize(); |
Rich Cannings | b27c430 | 2019-02-19 13:15:30 -0800 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | mPasswordEntry.setText(""); |
| 857 | |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 858 | if (!wasSecureBefore) { |
| 859 | Intent intent = getRedactionInterstitialIntent(getActivity()); |
| 860 | if (intent != null) { |
| 861 | startActivity(intent); |
| 862 | } |
| 863 | } |
Udam Saini | 686ae49 | 2016-02-02 17:02:29 -0800 | [diff] [blame] | 864 | getActivity().finish(); |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 865 | } |
Tony Mak | 9ba765b | 2016-08-02 17:09:53 +0100 | [diff] [blame] | 866 | |
| 867 | class TextChangedHandler extends Handler { |
| 868 | private static final int ON_TEXT_CHANGED = 1; |
| 869 | private static final int DELAY_IN_MILLISECOND = 100; |
| 870 | |
| 871 | /** |
| 872 | * With the introduction of delay, we batch processing the text changed event to reduce |
| 873 | * unnecessary UI updates. |
| 874 | */ |
| 875 | private void notifyAfterTextChanged() { |
| 876 | removeMessages(ON_TEXT_CHANGED); |
| 877 | sendEmptyMessageDelayed(ON_TEXT_CHANGED, DELAY_IN_MILLISECOND); |
| 878 | } |
| 879 | |
| 880 | @Override |
| 881 | public void handleMessage(Message msg) { |
Doris Ling | f958f2e | 2016-08-24 17:17:52 -0700 | [diff] [blame] | 882 | if (getActivity() == null) { |
| 883 | return; |
| 884 | } |
Tony Mak | 9ba765b | 2016-08-02 17:09:53 +0100 | [diff] [blame] | 885 | if (msg.what == ON_TEXT_CHANGED) { |
| 886 | updateUi(); |
| 887 | } |
| 888 | } |
| 889 | } |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Clara Bayarri | 77c4345 | 2016-06-23 11:11:42 +0100 | [diff] [blame] | 892 | public static class SaveAndFinishWorker extends SaveChosenLockWorkerBase { |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 893 | |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 894 | private LockscreenCredential mChosenPassword; |
| 895 | private LockscreenCredential mCurrentCredential; |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 896 | |
| 897 | public void start(LockPatternUtils utils, boolean required, |
| 898 | boolean hasChallenge, long challenge, |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 899 | LockscreenCredential chosenPassword, LockscreenCredential currentCredential, |
| 900 | int userId) { |
Clara Bayarri | b8a22e4 | 2015-12-18 16:40:18 +0000 | [diff] [blame] | 901 | prepare(utils, required, hasChallenge, challenge, userId); |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 902 | |
| 903 | mChosenPassword = chosenPassword; |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 904 | mCurrentCredential = currentCredential != null ? currentCredential |
| 905 | : LockscreenCredential.createNone(); |
Clara Bayarri | fe432e8 | 2015-10-12 12:07:02 +0100 | [diff] [blame] | 906 | mUserId = userId; |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 907 | |
| 908 | start(); |
| 909 | } |
| 910 | |
| 911 | @Override |
Irina Dumitrescu | 4b96dc3 | 2019-02-28 15:35:36 +0000 | [diff] [blame] | 912 | protected Pair<Boolean, Intent> saveAndVerifyInBackground() { |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 913 | final boolean success = mUtils.setLockCredential( |
| 914 | mChosenPassword, mCurrentCredential, mUserId); |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 915 | Intent result = null; |
Irina Dumitrescu | 4b96dc3 | 2019-02-28 15:35:36 +0000 | [diff] [blame] | 916 | if (success && mHasChallenge) { |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 917 | byte[] token; |
| 918 | try { |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 919 | token = mUtils.verifyCredential(mChosenPassword, mChallenge, mUserId); |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 920 | } catch (RequestThrottledException e) { |
| 921 | token = null; |
| 922 | } |
| 923 | |
| 924 | if (token == null) { |
| 925 | Log.e(TAG, "critical: no token returned for known good password."); |
| 926 | } |
| 927 | |
| 928 | result = new Intent(); |
| 929 | result.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token); |
| 930 | } |
Irina Dumitrescu | 4b96dc3 | 2019-02-28 15:35:36 +0000 | [diff] [blame] | 931 | return Pair.create(success, result); |
Xiyuan Xia | 3e7e3d6 | 2015-08-25 15:04:57 -0700 | [diff] [blame] | 932 | } |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 933 | } |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 934 | } |