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 | |
Jim Miller | af366a3 | 2010-03-25 18:45:22 -0700 | [diff] [blame] | 19 | import android.app.admin.DevicePolicyManager; |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 20 | import android.app.settings.SettingsEnums; |
Andres Morales | 7bdffd8 | 2015-08-04 16:55:00 -0700 | [diff] [blame] | 21 | import android.content.Context; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 22 | import android.content.Intent; |
Andrew Sapperstein | ccbb4cf | 2017-07-06 14:30:28 -0700 | [diff] [blame] | 23 | import android.graphics.Typeface; |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 24 | import android.os.AsyncTask; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 25 | import android.os.Bundle; |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 26 | import android.os.CountDownTimer; |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 27 | import android.os.SystemClock; |
Clara Bayarri | 34ec5f9 | 2016-01-22 14:59:24 +0000 | [diff] [blame] | 28 | import android.os.UserManager; |
Paul Lawrence | d71c31e | 2014-04-03 09:18:45 -0700 | [diff] [blame] | 29 | import android.os.storage.StorageManager; |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 30 | import android.text.Editable; |
Jim Miller | 2e28ace | 2010-12-15 10:07:16 -0800 | [diff] [blame] | 31 | import android.text.InputType; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 32 | import android.text.TextUtils; |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 33 | import android.view.KeyEvent; |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 34 | import android.view.LayoutInflater; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 35 | import android.view.View; |
| 36 | import android.view.View.OnClickListener; |
Jason parks | 3e8b763 | 2011-01-17 09:59:54 -0600 | [diff] [blame] | 37 | import android.view.ViewGroup; |
Jorim Jaggi | ff41a9a | 2015-06-09 15:31:28 -0700 | [diff] [blame] | 38 | import android.view.animation.AnimationUtils; |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 39 | import android.view.inputmethod.EditorInfo; |
Xiyuan Xia | 4a8edaf | 2015-05-20 14:26:15 -0700 | [diff] [blame] | 40 | import android.view.inputmethod.InputMethodManager; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 41 | import android.widget.TextView; |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 42 | import android.widget.TextView.OnEditorActionListener; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 43 | |
Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 44 | import androidx.fragment.app.Fragment; |
| 45 | |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 46 | import com.android.internal.widget.LockPatternChecker; |
| 47 | import com.android.internal.widget.LockPatternUtils; |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 48 | import com.android.internal.widget.LockscreenCredential; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 49 | import com.android.internal.widget.TextViewInputDisabler; |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 50 | import com.android.settings.R; |
Tarandeep Singh | 4803267 | 2017-06-12 15:32:28 -0700 | [diff] [blame] | 51 | import com.android.settings.widget.ImeAwareEditText; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 52 | import com.android.settingslib.animation.AppearAnimationUtils; |
| 53 | import com.android.settingslib.animation.DisappearAnimationUtils; |
| 54 | |
Jorim Jaggi | ff41a9a | 2015-06-09 15:31:28 -0700 | [diff] [blame] | 55 | import java.util.ArrayList; |
| 56 | |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 57 | public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity { |
Svetoslav | 3ea423a | 2014-10-16 14:44:25 -0700 | [diff] [blame] | 58 | |
Alex Johnston | 28c6b57 | 2020-01-28 17:49:33 +0000 | [diff] [blame] | 59 | // The index of the array is isStrongAuth << 2 + isManagedProfile << 1 + isAlpha. |
Tony Mak | 7655be0 | 2016-04-21 10:27:43 +0100 | [diff] [blame] | 60 | private static final int[] DETAIL_TEXTS = new int[] { |
| 61 | R.string.lockpassword_confirm_your_pin_generic, |
| 62 | R.string.lockpassword_confirm_your_password_generic, |
Alex Johnston | 28c6b57 | 2020-01-28 17:49:33 +0000 | [diff] [blame] | 63 | R.string.lockpassword_confirm_your_pin_generic_profile, |
| 64 | R.string.lockpassword_confirm_your_password_generic_profile, |
Charles He | 4c96d9b | 2017-07-04 11:50:03 +0100 | [diff] [blame] | 65 | R.string.lockpassword_strong_auth_required_device_pin, |
Alex Johnston | 28c6b57 | 2020-01-28 17:49:33 +0000 | [diff] [blame] | 66 | R.string.lockpassword_strong_auth_required_device_password, |
| 67 | R.string.lockpassword_strong_auth_required_work_pin, |
| 68 | R.string.lockpassword_strong_auth_required_work_password |
Tony Mak | 7655be0 | 2016-04-21 10:27:43 +0100 | [diff] [blame] | 69 | }; |
| 70 | |
Paul Lawrence | 2044404 | 2014-07-07 13:10:16 -0700 | [diff] [blame] | 71 | public static class InternalActivity extends ConfirmLockPassword { |
| 72 | } |
| 73 | |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 74 | @Override |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 75 | public Intent getIntent() { |
| 76 | Intent modIntent = new Intent(super.getIntent()); |
| 77 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT, ConfirmLockPasswordFragment.class.getName()); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 78 | return modIntent; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 81 | @Override |
Amith Yamasani | a677ee2 | 2013-07-26 13:38:41 -0700 | [diff] [blame] | 82 | protected boolean isValidFragment(String fragmentName) { |
| 83 | if (ConfirmLockPasswordFragment.class.getName().equals(fragmentName)) return true; |
| 84 | return false; |
| 85 | } |
| 86 | |
Xiyuan Xia | 4a8edaf | 2015-05-20 14:26:15 -0700 | [diff] [blame] | 87 | @Override |
| 88 | public void onWindowFocusChanged(boolean hasFocus) { |
| 89 | super.onWindowFocusChanged(hasFocus); |
tmfang | 27c84de | 2018-06-28 11:39:05 +0800 | [diff] [blame] | 90 | Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.main_content); |
Xiyuan Xia | 4a8edaf | 2015-05-20 14:26:15 -0700 | [diff] [blame] | 91 | if (fragment != null && fragment instanceof ConfirmLockPasswordFragment) { |
| 92 | ((ConfirmLockPasswordFragment)fragment).onWindowFocusChanged(hasFocus); |
| 93 | } |
| 94 | } |
| 95 | |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 96 | public static class ConfirmLockPasswordFragment extends ConfirmDeviceCredentialBaseFragment |
Xiyuan Xia | 00b17fa | 2015-08-31 11:59:46 -0700 | [diff] [blame] | 97 | implements OnClickListener, OnEditorActionListener, |
| 98 | CredentialCheckResultTracker.Listener { |
Xiyuan Xia | 00b17fa | 2015-08-31 11:59:46 -0700 | [diff] [blame] | 99 | private static final String FRAGMENT_TAG_CHECK_LOCK_RESULT = "check_lock_result"; |
Tarandeep Singh | 4803267 | 2017-06-12 15:32:28 -0700 | [diff] [blame] | 100 | private ImeAwareEditText mPasswordEntry; |
Xiyuan Xia | f2c2c19 | 2015-05-15 13:37:04 -0700 | [diff] [blame] | 101 | private TextViewInputDisabler mPasswordEntryInputDisabler; |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 102 | private AsyncTask<?, ?, ?> mPendingLockCheck; |
Xiyuan Xia | 00b17fa | 2015-08-31 11:59:46 -0700 | [diff] [blame] | 103 | private CredentialCheckResultTracker mCredentialCheckResultTracker; |
| 104 | private boolean mDisappearing = false; |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 105 | private TextView mHeaderTextView; |
| 106 | private TextView mDetailsTextView; |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 107 | private CountDownTimer mCountdownTimer; |
| 108 | private boolean mIsAlpha; |
Xiyuan Xia | 4a8edaf | 2015-05-20 14:26:15 -0700 | [diff] [blame] | 109 | private InputMethodManager mImm; |
Jorim Jaggi | ff41a9a | 2015-06-09 15:31:28 -0700 | [diff] [blame] | 110 | private AppearAnimationUtils mAppearAnimationUtils; |
| 111 | private DisappearAnimationUtils mDisappearAnimationUtils; |
Alex Johnston | 7868acf | 2019-12-09 12:52:14 +0000 | [diff] [blame] | 112 | private boolean mIsManagedProfile; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 113 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 114 | // required constructor for fragments |
| 115 | public ConfirmLockPasswordFragment() { |
| 116 | |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 117 | } |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 118 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 119 | @Override |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 120 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 121 | Bundle savedInstanceState) { |
Adrian Roos | 5437588 | 2015-04-16 17:11:22 -0700 | [diff] [blame] | 122 | final int storedQuality = mLockPatternUtils.getKeyguardStoredPasswordQuality( |
Andres Morales | 7bdffd8 | 2015-08-04 16:55:00 -0700 | [diff] [blame] | 123 | mEffectiveUserId); |
Maurice Lam | daaf8f8 | 2017-03-10 15:31:30 -0800 | [diff] [blame] | 124 | |
| 125 | ConfirmLockPassword activity = (ConfirmLockPassword) getActivity(); |
| 126 | View view = inflater.inflate( |
Maurice Lam | 3e3b8a9 | 2018-03-21 18:21:04 -0700 | [diff] [blame] | 127 | activity.getConfirmCredentialTheme() == ConfirmCredentialTheme.NORMAL |
| 128 | ? R.layout.confirm_lock_password_normal |
Maurice Lam | daaf8f8 | 2017-03-10 15:31:30 -0800 | [diff] [blame] | 129 | : R.layout.confirm_lock_password, |
| 130 | container, |
| 131 | false); |
Jim Miller | 29c9073 | 2011-04-18 18:16:09 -0700 | [diff] [blame] | 132 | |
Tarandeep Singh | 4803267 | 2017-06-12 15:32:28 -0700 | [diff] [blame] | 133 | mPasswordEntry = (ImeAwareEditText) view.findViewById(R.id.password_entry); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 134 | mPasswordEntry.setOnEditorActionListener(this); |
Tarandeep Singh | 86b8f44 | 2017-06-09 16:24:14 -0700 | [diff] [blame] | 135 | // EditText inside ScrollView doesn't automatically get focus. |
| 136 | mPasswordEntry.requestFocus(); |
Xiyuan Xia | f2c2c19 | 2015-05-15 13:37:04 -0700 | [diff] [blame] | 137 | mPasswordEntryInputDisabler = new TextViewInputDisabler(mPasswordEntry); |
Jim Miller | 29c9073 | 2011-04-18 18:16:09 -0700 | [diff] [blame] | 138 | |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 139 | mHeaderTextView = (TextView) view.findViewById(R.id.headerText); |
Maurice Lam | c41e408 | 2017-04-27 19:04:46 -0700 | [diff] [blame] | 140 | if (mHeaderTextView == null) { |
pastychang | 7961482 | 2019-01-03 10:12:54 +0800 | [diff] [blame] | 141 | mHeaderTextView = view.findViewById(R.id.suc_layout_title); |
Maurice Lam | c41e408 | 2017-04-27 19:04:46 -0700 | [diff] [blame] | 142 | } |
pastychang | fa68ec4 | 2019-04-12 16:22:17 +0800 | [diff] [blame] | 143 | mDetailsTextView = (TextView) view.findViewById(R.id.sud_layout_description); |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 144 | mErrorTextView = (TextView) view.findViewById(R.id.errorText); |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 145 | mIsAlpha = DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC == storedQuality |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 146 | || DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC == storedQuality |
Toni Barzic | e7d6e4d | 2016-03-30 11:43:19 -0700 | [diff] [blame] | 147 | || DevicePolicyManager.PASSWORD_QUALITY_COMPLEX == storedQuality |
| 148 | || DevicePolicyManager.PASSWORD_QUALITY_MANAGED == storedQuality; |
Svetoslav | 3ea423a | 2014-10-16 14:44:25 -0700 | [diff] [blame] | 149 | |
Xiyuan Xia | 4a8edaf | 2015-05-20 14:26:15 -0700 | [diff] [blame] | 150 | mImm = (InputMethodManager) getActivity().getSystemService( |
| 151 | Context.INPUT_METHOD_SERVICE); |
| 152 | |
Alex Johnston | 7868acf | 2019-12-09 12:52:14 +0000 | [diff] [blame] | 153 | mIsManagedProfile = UserManager.get(getActivity()).isManagedProfile(mEffectiveUserId); |
| 154 | |
Svetoslav | 3ea423a | 2014-10-16 14:44:25 -0700 | [diff] [blame] | 155 | Intent intent = getActivity().getIntent(); |
| 156 | if (intent != null) { |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 157 | CharSequence headerMessage = intent.getCharSequenceExtra( |
| 158 | ConfirmDeviceCredentialBaseFragment.HEADER_TEXT); |
| 159 | CharSequence detailsMessage = intent.getCharSequenceExtra( |
| 160 | ConfirmDeviceCredentialBaseFragment.DETAILS_TEXT); |
Svetoslav | 3ea423a | 2014-10-16 14:44:25 -0700 | [diff] [blame] | 161 | if (TextUtils.isEmpty(headerMessage)) { |
| 162 | headerMessage = getString(getDefaultHeader()); |
| 163 | } |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 164 | if (TextUtils.isEmpty(detailsMessage)) { |
| 165 | detailsMessage = getString(getDefaultDetails()); |
| 166 | } |
| 167 | mHeaderTextView.setText(headerMessage); |
| 168 | mDetailsTextView.setText(detailsMessage); |
Svetoslav | 3ea423a | 2014-10-16 14:44:25 -0700 | [diff] [blame] | 169 | } |
Jim Miller | 2e28ace | 2010-12-15 10:07:16 -0800 | [diff] [blame] | 170 | int currentType = mPasswordEntry.getInputType(); |
joshmccloskey | 50aea6e | 2019-09-06 11:32:25 -0700 | [diff] [blame] | 171 | if (mIsAlpha) { |
| 172 | mPasswordEntry.setInputType(currentType); |
| 173 | mPasswordEntry.setContentDescription( |
| 174 | getContext().getString(R.string.unlock_set_unlock_password_title)); |
| 175 | } else { |
| 176 | mPasswordEntry.setInputType( |
| 177 | InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD); |
| 178 | mPasswordEntry.setContentDescription( |
| 179 | getContext().getString(R.string.unlock_set_unlock_pin_title)); |
| 180 | } |
Andrew Sapperstein | ccbb4cf | 2017-07-06 14:30:28 -0700 | [diff] [blame] | 181 | // Can't set via XML since setInputType resets the fontFamily to null |
| 182 | mPasswordEntry.setTypeface(Typeface.create( |
| 183 | getContext().getString(com.android.internal.R.string.config_headlineFontFamily), |
| 184 | Typeface.NORMAL)); |
Jorim Jaggi | ff41a9a | 2015-06-09 15:31:28 -0700 | [diff] [blame] | 185 | mAppearAnimationUtils = new AppearAnimationUtils(getContext(), |
| 186 | 220, 2f /* translationScale */, 1f /* delayScale*/, |
| 187 | AnimationUtils.loadInterpolator(getContext(), |
| 188 | android.R.interpolator.linear_out_slow_in)); |
| 189 | mDisappearAnimationUtils = new DisappearAnimationUtils(getContext(), |
| 190 | 110, 1f /* translationScale */, |
| 191 | 0.5f /* delayScale */, AnimationUtils.loadInterpolator( |
| 192 | getContext(), android.R.interpolator.fast_out_linear_in)); |
Julia Reynolds | ce25af4 | 2015-07-08 16:56:31 -0400 | [diff] [blame] | 193 | setAccessibilityTitle(mHeaderTextView.getText()); |
Xiyuan Xia | 00b17fa | 2015-08-31 11:59:46 -0700 | [diff] [blame] | 194 | |
| 195 | mCredentialCheckResultTracker = (CredentialCheckResultTracker) getFragmentManager() |
| 196 | .findFragmentByTag(FRAGMENT_TAG_CHECK_LOCK_RESULT); |
| 197 | if (mCredentialCheckResultTracker == null) { |
| 198 | mCredentialCheckResultTracker = new CredentialCheckResultTracker(); |
| 199 | getFragmentManager().beginTransaction().add(mCredentialCheckResultTracker, |
| 200 | FRAGMENT_TAG_CHECK_LOCK_RESULT).commit(); |
| 201 | } |
| 202 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 203 | return view; |
| 204 | } |
| 205 | |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 206 | private int getDefaultHeader() { |
Adrian Roos | 6600dde | 2017-07-23 14:18:16 +0200 | [diff] [blame] | 207 | if (mFrp) { |
| 208 | return mIsAlpha ? R.string.lockpassword_confirm_your_password_header_frp |
| 209 | : R.string.lockpassword_confirm_your_pin_header_frp; |
| 210 | } |
Alex Johnston | 7868acf | 2019-12-09 12:52:14 +0000 | [diff] [blame] | 211 | if (mIsManagedProfile) { |
| 212 | return mIsAlpha ? R.string.lockpassword_confirm_your_work_password_header |
| 213 | : R.string.lockpassword_confirm_your_work_pin_header; |
| 214 | } |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 215 | return mIsAlpha ? R.string.lockpassword_confirm_your_password_header |
| 216 | : R.string.lockpassword_confirm_your_pin_header; |
| 217 | } |
| 218 | |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 219 | private int getDefaultDetails() { |
Adrian Roos | 6600dde | 2017-07-23 14:18:16 +0200 | [diff] [blame] | 220 | if (mFrp) { |
| 221 | return mIsAlpha ? R.string.lockpassword_confirm_your_password_details_frp |
| 222 | : R.string.lockpassword_confirm_your_pin_details_frp; |
| 223 | } |
Adrian Roos | 5a9a3cd | 2017-03-30 18:02:25 -0700 | [diff] [blame] | 224 | boolean isStrongAuthRequired = isStrongAuthRequired(); |
Alex Johnston | 28c6b57 | 2020-01-28 17:49:33 +0000 | [diff] [blame] | 225 | // Map boolean flags to an index by isStrongAuth << 2 + isManagedProfile << 1 + isAlpha. |
| 226 | int index = ((isStrongAuthRequired ? 1 : 0) << 2) + ((mIsManagedProfile ? 1 : 0) << 1) |
| 227 | + (mIsAlpha ? 1 : 0); |
Tony Mak | 7655be0 | 2016-04-21 10:27:43 +0100 | [diff] [blame] | 228 | return DETAIL_TEXTS[index]; |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | private int getErrorMessage() { |
| 232 | return mIsAlpha ? R.string.lockpassword_invalid_password |
| 233 | : R.string.lockpassword_invalid_pin; |
| 234 | } |
| 235 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 236 | @Override |
Charles He | 641c9fc | 2017-04-26 18:45:48 +0100 | [diff] [blame] | 237 | protected int getLastTryErrorMessage(int userType) { |
| 238 | switch (userType) { |
| 239 | case USER_TYPE_PRIMARY: |
| 240 | return mIsAlpha ? R.string.lock_last_password_attempt_before_wipe_device |
| 241 | : R.string.lock_last_pin_attempt_before_wipe_device; |
| 242 | case USER_TYPE_MANAGED_PROFILE: |
| 243 | return mIsAlpha ? R.string.lock_last_password_attempt_before_wipe_profile |
| 244 | : R.string.lock_last_pin_attempt_before_wipe_profile; |
| 245 | case USER_TYPE_SECONDARY: |
| 246 | return mIsAlpha ? R.string.lock_last_password_attempt_before_wipe_user |
| 247 | : R.string.lock_last_pin_attempt_before_wipe_user; |
| 248 | default: |
| 249 | throw new IllegalArgumentException("Unrecognized user type:" + userType); |
| 250 | } |
Clara Bayarri | 9d357ea | 2016-01-28 17:50:53 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | @Override |
Jorim Jaggi | ff41a9a | 2015-06-09 15:31:28 -0700 | [diff] [blame] | 254 | public void prepareEnterAnimation() { |
| 255 | super.prepareEnterAnimation(); |
| 256 | mHeaderTextView.setAlpha(0f); |
| 257 | mDetailsTextView.setAlpha(0f); |
| 258 | mCancelButton.setAlpha(0f); |
| 259 | mPasswordEntry.setAlpha(0f); |
Charles He | 170801b | 2017-07-05 15:59:49 +0100 | [diff] [blame] | 260 | mErrorTextView.setAlpha(0f); |
Jorim Jaggi | ff41a9a | 2015-06-09 15:31:28 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | private View[] getActiveViews() { |
| 264 | ArrayList<View> result = new ArrayList<>(); |
| 265 | result.add(mHeaderTextView); |
| 266 | result.add(mDetailsTextView); |
| 267 | if (mCancelButton.getVisibility() == View.VISIBLE) { |
| 268 | result.add(mCancelButton); |
| 269 | } |
| 270 | result.add(mPasswordEntry); |
Charles He | 170801b | 2017-07-05 15:59:49 +0100 | [diff] [blame] | 271 | result.add(mErrorTextView); |
Jorim Jaggi | ff41a9a | 2015-06-09 15:31:28 -0700 | [diff] [blame] | 272 | return result.toArray(new View[] {}); |
| 273 | } |
| 274 | |
| 275 | @Override |
| 276 | public void startEnterAnimation() { |
| 277 | super.startEnterAnimation(); |
Charles He | 170801b | 2017-07-05 15:59:49 +0100 | [diff] [blame] | 278 | mAppearAnimationUtils.startAnimation(getActiveViews(), this::updatePasswordEntry); |
Jorim Jaggi | ff41a9a | 2015-06-09 15:31:28 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | @Override |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 282 | public void onPause() { |
| 283 | super.onPause(); |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 284 | if (mCountdownTimer != null) { |
| 285 | mCountdownTimer.cancel(); |
| 286 | mCountdownTimer = null; |
| 287 | } |
Xiyuan Xia | 00b17fa | 2015-08-31 11:59:46 -0700 | [diff] [blame] | 288 | mCredentialCheckResultTracker.setListener(null); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | @Override |
Fan Zhang | 6507613 | 2016-08-08 10:25:13 -0700 | [diff] [blame] | 292 | public int getMetricsCategory() { |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 293 | return SettingsEnums.CONFIRM_LOCK_PASSWORD; |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | @Override |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 297 | public void onResume() { |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 298 | super.onResume(); |
Andres Morales | 7bdffd8 | 2015-08-04 16:55:00 -0700 | [diff] [blame] | 299 | long deadline = mLockPatternUtils.getLockoutAttemptDeadline(mEffectiveUserId); |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 300 | if (deadline != 0) { |
Xiyuan Xia | 00b17fa | 2015-08-31 11:59:46 -0700 | [diff] [blame] | 301 | mCredentialCheckResultTracker.clearResult(); |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 302 | handleAttemptLockout(deadline); |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 303 | } else { |
Charles He | 170801b | 2017-07-05 15:59:49 +0100 | [diff] [blame] | 304 | updatePasswordEntry(); |
Oleksandr Peletskyi | a6fb466 | 2016-04-14 19:35:04 +0200 | [diff] [blame] | 305 | mErrorTextView.setText(""); |
Charles He | 641c9fc | 2017-04-26 18:45:48 +0100 | [diff] [blame] | 306 | updateErrorMessage( |
| 307 | mLockPatternUtils.getCurrentFailedPasswordAttempts(mEffectiveUserId)); |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 308 | } |
Xiyuan Xia | 00b17fa | 2015-08-31 11:59:46 -0700 | [diff] [blame] | 309 | mCredentialCheckResultTracker.setListener(this); |
Jorim Jaggi | 0cb467a | 2014-09-09 18:25:46 +0200 | [diff] [blame] | 310 | } |
| 311 | |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 312 | @Override |
Andres Morales | 59f5976 | 2015-04-16 16:30:31 -0700 | [diff] [blame] | 313 | protected void authenticationSucceeded() { |
Xiyuan Xia | 00b17fa | 2015-08-31 11:59:46 -0700 | [diff] [blame] | 314 | mCredentialCheckResultTracker.setResult(true, new Intent(), 0, mEffectiveUserId); |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Charles He | 170801b | 2017-07-05 15:59:49 +0100 | [diff] [blame] | 317 | private void updatePasswordEntry() { |
| 318 | final boolean isLockedOut = |
| 319 | mLockPatternUtils.getLockoutAttemptDeadline(mEffectiveUserId) != 0; |
| 320 | mPasswordEntry.setEnabled(!isLockedOut); |
| 321 | mPasswordEntryInputDisabler.setInputEnabled(!isLockedOut); |
Kevin Chyn | e5a016e | 2018-10-03 18:39:22 -0700 | [diff] [blame] | 322 | if (isLockedOut) { |
Charles He | 170801b | 2017-07-05 15:59:49 +0100 | [diff] [blame] | 323 | mImm.hideSoftInputFromWindow(mPasswordEntry.getWindowToken(), 0 /*flags*/); |
| 324 | } else { |
Tarandeep Singh | 4803267 | 2017-06-12 15:32:28 -0700 | [diff] [blame] | 325 | mPasswordEntry.scheduleShowSoftInput(); |
Xiyuan Xia | 4f8102d | 2015-05-21 11:12:19 -0700 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | |
Xiyuan Xia | 4a8edaf | 2015-05-20 14:26:15 -0700 | [diff] [blame] | 329 | public void onWindowFocusChanged(boolean hasFocus) { |
Charles He | 170801b | 2017-07-05 15:59:49 +0100 | [diff] [blame] | 330 | if (!hasFocus) { |
Xiyuan Xia | 4a8edaf | 2015-05-20 14:26:15 -0700 | [diff] [blame] | 331 | return; |
| 332 | } |
| 333 | // Post to let window focus logic to finish to allow soft input show/hide properly. |
Charles He | 170801b | 2017-07-05 15:59:49 +0100 | [diff] [blame] | 334 | mPasswordEntry.post(this::updatePasswordEntry); |
Xiyuan Xia | 4a8edaf | 2015-05-20 14:26:15 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 337 | private void handleNext() { |
Xiyuan Xia | 00b17fa | 2015-08-31 11:59:46 -0700 | [diff] [blame] | 338 | if (mPendingLockCheck != null || mDisappearing) { |
| 339 | return; |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Rich Cannings | b27c430 | 2019-02-19 13:15:30 -0800 | [diff] [blame] | 342 | // 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] | 343 | final Editable passwordText = mPasswordEntry.getText(); |
| 344 | if (TextUtils.isEmpty(passwordText)) { |
Fan Zhang | 774e1d8 | 2016-10-03 09:05:55 -0700 | [diff] [blame] | 345 | return; |
| 346 | } |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 347 | final LockscreenCredential credential = |
| 348 | mIsAlpha ? LockscreenCredential.createPassword(passwordText) |
| 349 | : LockscreenCredential.createPin(passwordText); |
Fan Zhang | 774e1d8 | 2016-10-03 09:05:55 -0700 | [diff] [blame] | 350 | |
| 351 | mPasswordEntryInputDisabler.setInputEnabled(false); |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 352 | final boolean verifyChallenge = getActivity().getIntent().getBooleanExtra( |
| 353 | ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, false); |
Fan Zhang | 774e1d8 | 2016-10-03 09:05:55 -0700 | [diff] [blame] | 354 | |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 355 | Intent intent = new Intent(); |
| 356 | if (verifyChallenge) { |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 357 | if (isInternalActivity()) { |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 358 | startVerifyPassword(credential, intent); |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 359 | return; |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 360 | } |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 361 | } else { |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 362 | startCheckPassword(credential, intent); |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 363 | return; |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Xiyuan Xia | 00b17fa | 2015-08-31 11:59:46 -0700 | [diff] [blame] | 366 | mCredentialCheckResultTracker.setResult(false, intent, 0, mEffectiveUserId); |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | private boolean isInternalActivity() { |
| 370 | return getActivity() instanceof ConfirmLockPassword.InternalActivity; |
| 371 | } |
| 372 | |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 373 | private void startVerifyPassword(LockscreenCredential credential, final Intent intent) { |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 374 | long challenge = getActivity().getIntent().getLongExtra( |
| 375 | ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, 0); |
Andres Morales | 7bdffd8 | 2015-08-04 16:55:00 -0700 | [diff] [blame] | 376 | final int localEffectiveUserId = mEffectiveUserId; |
Ricky Wai | 996d0df | 2016-04-05 16:33:47 +0100 | [diff] [blame] | 377 | final int localUserId = mUserId; |
| 378 | final LockPatternChecker.OnVerifyCallback onVerifyCallback = |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 379 | new LockPatternChecker.OnVerifyCallback() { |
| 380 | @Override |
Andres Morales | 91e6c49 | 2015-05-15 15:20:33 -0700 | [diff] [blame] | 381 | public void onVerified(byte[] token, int timeoutMs) { |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 382 | mPendingLockCheck = null; |
| 383 | boolean matched = false; |
| 384 | if (token != null) { |
| 385 | matched = true; |
Victor Chang | 5e0a46b | 2016-05-13 17:06:59 +0100 | [diff] [blame] | 386 | if (mReturnCredentials) { |
| 387 | intent.putExtra( |
| 388 | ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, |
| 389 | token); |
| 390 | } |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 391 | } |
Xiyuan Xia | 00b17fa | 2015-08-31 11:59:46 -0700 | [diff] [blame] | 392 | mCredentialCheckResultTracker.setResult(matched, intent, timeoutMs, |
Charles He | 170801b | 2017-07-05 15:59:49 +0100 | [diff] [blame] | 393 | localEffectiveUserId); |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 394 | } |
Ricky Wai | 996d0df | 2016-04-05 16:33:47 +0100 | [diff] [blame] | 395 | }; |
| 396 | mPendingLockCheck = (localEffectiveUserId == localUserId) |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 397 | ? LockPatternChecker.verifyCredential( |
| 398 | mLockPatternUtils, credential, challenge, localUserId, onVerifyCallback) |
Ricky Wai | 996d0df | 2016-04-05 16:33:47 +0100 | [diff] [blame] | 399 | : LockPatternChecker.verifyTiedProfileChallenge( |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 400 | mLockPatternUtils, credential, challenge, localUserId, |
Ricky Wai | 996d0df | 2016-04-05 16:33:47 +0100 | [diff] [blame] | 401 | onVerifyCallback); |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 404 | private void startCheckPassword(final LockscreenCredential credential, |
| 405 | final Intent intent) { |
Andres Morales | 7bdffd8 | 2015-08-04 16:55:00 -0700 | [diff] [blame] | 406 | final int localEffectiveUserId = mEffectiveUserId; |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 407 | mPendingLockCheck = LockPatternChecker.checkCredential( |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 408 | mLockPatternUtils, |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 409 | credential, |
Andres Morales | 7bdffd8 | 2015-08-04 16:55:00 -0700 | [diff] [blame] | 410 | localEffectiveUserId, |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 411 | new LockPatternChecker.OnCheckCallback() { |
| 412 | @Override |
Andres Morales | 91e6c49 | 2015-05-15 15:20:33 -0700 | [diff] [blame] | 413 | public void onChecked(boolean matched, int timeoutMs) { |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 414 | mPendingLockCheck = null; |
Victor Chang | 5e0a46b | 2016-05-13 17:06:59 +0100 | [diff] [blame] | 415 | if (matched && isInternalActivity() && mReturnCredentials) { |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 416 | // TODO: get rid of EXTRA_KEY_TYPE, since EXTRA_KEY_PASSWORD already |
| 417 | // distinguishes beteween PIN and password. |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 418 | intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_TYPE, |
| 419 | mIsAlpha ? StorageManager.CRYPT_TYPE_PASSWORD |
| 420 | : StorageManager.CRYPT_TYPE_PIN); |
| 421 | intent.putExtra( |
Rubin Xu | 010116a | 2019-09-11 17:36:37 +0100 | [diff] [blame] | 422 | ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD, credential); |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 423 | } |
Xiyuan Xia | 00b17fa | 2015-08-31 11:59:46 -0700 | [diff] [blame] | 424 | mCredentialCheckResultTracker.setResult(matched, intent, timeoutMs, |
| 425 | localEffectiveUserId); |
Xiyuan Xia | bf9ac6b | 2015-05-05 16:04:00 -0700 | [diff] [blame] | 426 | } |
| 427 | }); |
| 428 | } |
| 429 | |
Jorim Jaggi | ff41a9a | 2015-06-09 15:31:28 -0700 | [diff] [blame] | 430 | private void startDisappearAnimation(final Intent intent) { |
Xiyuan Xia | 00b17fa | 2015-08-31 11:59:46 -0700 | [diff] [blame] | 431 | if (mDisappearing) { |
| 432 | return; |
| 433 | } |
| 434 | mDisappearing = true; |
| 435 | |
Maurice Lam | daaf8f8 | 2017-03-10 15:31:30 -0800 | [diff] [blame] | 436 | final ConfirmLockPassword activity = (ConfirmLockPassword) getActivity(); |
| 437 | // Bail if there is no active activity. |
| 438 | if (activity == null || activity.isFinishing()) { |
| 439 | return; |
| 440 | } |
| 441 | if (activity.getConfirmCredentialTheme() == ConfirmCredentialTheme.DARK) { |
| 442 | mDisappearAnimationUtils.startAnimation(getActiveViews(), () -> { |
| 443 | activity.setResult(RESULT_OK, intent); |
| 444 | activity.finish(); |
| 445 | activity.overridePendingTransition( |
| 446 | R.anim.confirm_credential_close_enter, |
| 447 | R.anim.confirm_credential_close_exit); |
Jorim Jaggi | ff41a9a | 2015-06-09 15:31:28 -0700 | [diff] [blame] | 448 | }); |
| 449 | } else { |
Maurice Lam | daaf8f8 | 2017-03-10 15:31:30 -0800 | [diff] [blame] | 450 | activity.setResult(RESULT_OK, intent); |
| 451 | activity.finish(); |
Jorim Jaggi | ff41a9a | 2015-06-09 15:31:28 -0700 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | |
Andres Morales | 7bdffd8 | 2015-08-04 16:55:00 -0700 | [diff] [blame] | 455 | private void onPasswordChecked(boolean matched, Intent intent, int timeoutMs, |
Clara Bayarri | 9d357ea | 2016-01-28 17:50:53 +0000 | [diff] [blame] | 456 | int effectiveUserId, boolean newResult) { |
Xiyuan Xia | f2c2c19 | 2015-05-15 13:37:04 -0700 | [diff] [blame] | 457 | mPasswordEntryInputDisabler.setInputEnabled(true); |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 458 | if (matched) { |
Clara Bayarri | 9d357ea | 2016-01-28 17:50:53 +0000 | [diff] [blame] | 459 | if (newResult) { |
Kevin Chyn | 127da9c | 2018-11-09 16:13:53 -0800 | [diff] [blame] | 460 | ConfirmDeviceCredentialUtils.reportSuccessfulAttempt(mLockPatternUtils, |
| 461 | mUserManager, mEffectiveUserId); |
Clara Bayarri | 9d357ea | 2016-01-28 17:50:53 +0000 | [diff] [blame] | 462 | } |
Jorim Jaggi | ff41a9a | 2015-06-09 15:31:28 -0700 | [diff] [blame] | 463 | startDisappearAnimation(intent); |
Kevin Chyn | 127da9c | 2018-11-09 16:13:53 -0800 | [diff] [blame] | 464 | ConfirmDeviceCredentialUtils.checkForPendingIntent(getActivity()); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 465 | } else { |
Andres Morales | 91e6c49 | 2015-05-15 15:20:33 -0700 | [diff] [blame] | 466 | if (timeoutMs > 0) { |
Charles He | 991ccc2 | 2017-04-19 19:32:00 +0100 | [diff] [blame] | 467 | refreshLockScreen(); |
Adrian Roos | 5437588 | 2015-04-16 17:11:22 -0700 | [diff] [blame] | 468 | long deadline = mLockPatternUtils.setLockoutAttemptDeadline( |
Andres Morales | 7bdffd8 | 2015-08-04 16:55:00 -0700 | [diff] [blame] | 469 | effectiveUserId, timeoutMs); |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 470 | handleAttemptLockout(deadline); |
| 471 | } else { |
Charles He | caf9510 | 2017-08-18 17:35:27 +0100 | [diff] [blame] | 472 | showError(getErrorMessage(), CLEAR_WRONG_ATTEMPT_TIMEOUT_MS); |
Clara Bayarri | 9d357ea | 2016-01-28 17:50:53 +0000 | [diff] [blame] | 473 | } |
| 474 | if (newResult) { |
| 475 | reportFailedAttempt(); |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 476 | } |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 477 | } |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 478 | } |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 479 | |
Xiyuan Xia | 00b17fa | 2015-08-31 11:59:46 -0700 | [diff] [blame] | 480 | @Override |
| 481 | public void onCredentialChecked(boolean matched, Intent intent, int timeoutMs, |
Clara Bayarri | 9d357ea | 2016-01-28 17:50:53 +0000 | [diff] [blame] | 482 | int effectiveUserId, boolean newResult) { |
| 483 | onPasswordChecked(matched, intent, timeoutMs, effectiveUserId, newResult); |
| 484 | } |
| 485 | |
| 486 | @Override |
| 487 | protected void onShowError() { |
| 488 | mPasswordEntry.setText(null); |
Xiyuan Xia | 00b17fa | 2015-08-31 11:59:46 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 491 | private void handleAttemptLockout(long elapsedRealtimeDeadline) { |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 492 | mCountdownTimer = new CountDownTimer( |
Charles He | 170801b | 2017-07-05 15:59:49 +0100 | [diff] [blame] | 493 | elapsedRealtimeDeadline - SystemClock.elapsedRealtime(), |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 494 | LockPatternUtils.FAILED_ATTEMPT_COUNTDOWN_INTERVAL_MS) { |
| 495 | |
| 496 | @Override |
| 497 | public void onTick(long millisUntilFinished) { |
| 498 | final int secondsCountdown = (int) (millisUntilFinished / 1000); |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 499 | showError(getString( |
| 500 | R.string.lockpattern_too_many_failed_confirmation_attempts, |
| 501 | secondsCountdown), 0); |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | @Override |
| 505 | public void onFinish() { |
Charles He | 170801b | 2017-07-05 15:59:49 +0100 | [diff] [blame] | 506 | updatePasswordEntry(); |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 507 | mErrorTextView.setText(""); |
Charles He | 641c9fc | 2017-04-26 18:45:48 +0100 | [diff] [blame] | 508 | updateErrorMessage( |
| 509 | mLockPatternUtils.getCurrentFailedPasswordAttempts(mEffectiveUserId)); |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 510 | } |
| 511 | }.start(); |
Charles He | 170801b | 2017-07-05 15:59:49 +0100 | [diff] [blame] | 512 | updatePasswordEntry(); |
Adrian Roos | 8184ea5 | 2014-03-31 21:33:35 +0200 | [diff] [blame] | 513 | } |
| 514 | |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 515 | public void onClick(View v) { |
Colin Cross | 807e861 | 2019-05-02 19:56:42 -0700 | [diff] [blame] | 516 | if (v.getId() == R.id.next_button) { |
| 517 | handleNext(); |
| 518 | } else if (v.getId() == R.id.cancel_button) { |
| 519 | getActivity().setResult(RESULT_CANCELED); |
| 520 | getActivity().finish(); |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 521 | } |
| 522 | } |
| 523 | |
Jim Miller | 29c9073 | 2011-04-18 18:16:09 -0700 | [diff] [blame] | 524 | // {@link OnEditorActionListener} methods. |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 525 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
Jim Miller | 74b1e0a | 2011-04-15 18:52:31 -0700 | [diff] [blame] | 526 | // Check if this was the result of hitting the enter or "done" key |
| 527 | if (actionId == EditorInfo.IME_NULL |
| 528 | || actionId == EditorInfo.IME_ACTION_DONE |
| 529 | || actionId == EditorInfo.IME_ACTION_NEXT) { |
Jim Miller | 17e9e19 | 2010-12-07 20:41:41 -0800 | [diff] [blame] | 530 | handleNext(); |
| 531 | return true; |
| 532 | } |
| 533 | return false; |
| 534 | } |
Jim Miller | 122b6c8 | 2010-02-10 19:53:58 -0800 | [diff] [blame] | 535 | } |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 536 | } |