Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 17 | package com.android.keyguard; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 18 | |
Jason Monk | ea03be1 | 2017-12-04 11:08:41 -0500 | [diff] [blame] | 19 | import static com.android.internal.util.LatencyTracker.ACTION_CHECK_CREDENTIAL; |
| 20 | import static com.android.internal.util.LatencyTracker.ACTION_CHECK_CREDENTIAL_UNLOCKED; |
Jorim Jaggi | d056517 | 2016-09-15 16:31:14 -0700 | [diff] [blame] | 21 | |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 22 | import android.content.Context; |
Jason Chang | 1e4a4bd | 2018-05-22 17:30:19 +0800 | [diff] [blame] | 23 | import android.content.res.ColorStateList; |
Xiyuan Xia | 6e38058 | 2015-05-05 15:16:08 -0700 | [diff] [blame] | 24 | import android.os.AsyncTask; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 25 | import android.os.CountDownTimer; |
| 26 | import android.os.SystemClock; |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 27 | import android.util.AttributeSet; |
| 28 | import android.view.HapticFeedbackConstants; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 29 | import android.view.KeyEvent; |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 30 | import android.view.View; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 31 | import android.widget.LinearLayout; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 32 | |
Jason Monk | ea03be1 | 2017-12-04 11:08:41 -0500 | [diff] [blame] | 33 | import com.android.internal.util.LatencyTracker; |
Xiyuan Xia | 6e38058 | 2015-05-05 15:16:08 -0700 | [diff] [blame] | 34 | import com.android.internal.widget.LockPatternChecker; |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 35 | import com.android.internal.widget.LockPatternUtils; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 36 | |
Rich Cannings | f64ec63 | 2019-02-21 12:40:36 -0800 | [diff] [blame] | 37 | import java.util.Arrays; |
| 38 | |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 39 | /** |
| 40 | * Base class for PIN and password unlock screens. |
| 41 | */ |
| 42 | public abstract class KeyguardAbsKeyInputView extends LinearLayout |
Andrew Lee | 72b46d4 | 2015-01-30 13:23:21 -0800 | [diff] [blame] | 43 | implements KeyguardSecurityView, EmergencyButton.EmergencyButtonCallback { |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 44 | protected KeyguardSecurityCallback mCallback; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 45 | protected LockPatternUtils mLockPatternUtils; |
Xiyuan Xia | 6e38058 | 2015-05-05 15:16:08 -0700 | [diff] [blame] | 46 | protected AsyncTask<?, ?, ?> mPendingLockCheck; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 47 | protected SecurityMessageDisplay mSecurityMessageDisplay; |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 48 | protected View mEcaView; |
Daniel Sandler | acb60fb | 2012-10-25 10:46:37 -0400 | [diff] [blame] | 49 | protected boolean mEnableHaptics; |
Jim Miller | ed7dcc2 | 2015-08-25 19:36:22 -0700 | [diff] [blame] | 50 | private boolean mDismissing; |
lumark | d62bfd2 | 2019-01-10 15:29:11 +0800 | [diff] [blame] | 51 | protected boolean mResumed; |
Hidenari Koshimae | 5be868c | 2014-08-21 11:27:33 +0200 | [diff] [blame] | 52 | private CountDownTimer mCountdownTimer = null; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 53 | |
| 54 | // To avoid accidental lockout due to events while the device in in the pocket, ignore |
| 55 | // any passwords with length less than or equal to this length. |
| 56 | protected static final int MINIMUM_PASSWORD_LENGTH_BEFORE_REPORT = 3; |
| 57 | |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 58 | public KeyguardAbsKeyInputView(Context context) { |
| 59 | this(context, null); |
| 60 | } |
| 61 | |
| 62 | public KeyguardAbsKeyInputView(Context context, AttributeSet attrs) { |
| 63 | super(context, attrs); |
| 64 | } |
| 65 | |
Jim Miller | 51e3a67 | 2015-07-31 18:42:53 -0700 | [diff] [blame] | 66 | @Override |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 67 | public void setKeyguardCallback(KeyguardSecurityCallback callback) { |
| 68 | mCallback = callback; |
| 69 | } |
| 70 | |
Jim Miller | 51e3a67 | 2015-07-31 18:42:53 -0700 | [diff] [blame] | 71 | @Override |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 72 | public void setLockPatternUtils(LockPatternUtils utils) { |
| 73 | mLockPatternUtils = utils; |
Daniel Sandler | acb60fb | 2012-10-25 10:46:37 -0400 | [diff] [blame] | 74 | mEnableHaptics = mLockPatternUtils.isTactileFeedbackEnabled(); |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 75 | } |
| 76 | |
Jim Miller | 51e3a67 | 2015-07-31 18:42:53 -0700 | [diff] [blame] | 77 | @Override |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 78 | public void reset() { |
| 79 | // start fresh |
Jim Miller | ed7dcc2 | 2015-08-25 19:36:22 -0700 | [diff] [blame] | 80 | mDismissing = false; |
Jim Miller | 4db942c | 2016-05-16 18:06:50 -0700 | [diff] [blame] | 81 | resetPasswordText(false /* animate */, false /* announce */); |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 82 | // if the user is currently locked out, enforce it. |
Adrian Roos | 8150d2a | 2015-04-16 17:11:20 -0700 | [diff] [blame] | 83 | long deadline = mLockPatternUtils.getLockoutAttemptDeadline( |
Adrian Roos | d6aa6cb | 2015-04-16 19:31:29 -0700 | [diff] [blame] | 84 | KeyguardUpdateMonitor.getCurrentUser()); |
Jim Miller | 7d5e00a | 2013-10-11 22:45:57 -0700 | [diff] [blame] | 85 | if (shouldLockout(deadline)) { |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 86 | handleAttemptLockout(deadline); |
| 87 | } else { |
| 88 | resetState(); |
| 89 | } |
| 90 | } |
| 91 | |
Jim Miller | 7d5e00a | 2013-10-11 22:45:57 -0700 | [diff] [blame] | 92 | // Allow subclasses to override this behavior |
| 93 | protected boolean shouldLockout(long deadline) { |
| 94 | return deadline != 0; |
| 95 | } |
| 96 | |
Daniel Sandler | 8a26bf5 | 2012-10-30 13:29:50 -0400 | [diff] [blame] | 97 | protected abstract int getPasswordTextViewId(); |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 98 | protected abstract void resetState(); |
| 99 | |
| 100 | @Override |
| 101 | protected void onFinishInflate() { |
Daniel Sandler | acb60fb | 2012-10-25 10:46:37 -0400 | [diff] [blame] | 102 | mLockPatternUtils = new LockPatternUtils(mContext); |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 103 | mEcaView = findViewById(R.id.keyguard_selector_fade_container); |
Andrew Lee | 72b46d4 | 2015-01-30 13:23:21 -0800 | [diff] [blame] | 104 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 105 | EmergencyButton button = findViewById(R.id.emergency_call_button); |
Andrew Lee | f98f7b9 | 2015-02-02 15:50:29 -0800 | [diff] [blame] | 106 | if (button != null) { |
| 107 | button.setCallback(this); |
| 108 | } |
Andrew Lee | 72b46d4 | 2015-01-30 13:23:21 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Jim Miller | 51e3a67 | 2015-07-31 18:42:53 -0700 | [diff] [blame] | 111 | @Override |
Lucas Dupin | 2e838ac | 2019-04-17 16:50:58 -0700 | [diff] [blame] | 112 | protected void onAttachedToWindow() { |
| 113 | super.onAttachedToWindow(); |
| 114 | mSecurityMessageDisplay = KeyguardMessageArea.findSecurityMessageDisplay(this); |
| 115 | } |
| 116 | |
| 117 | @Override |
Andrew Lee | 72b46d4 | 2015-01-30 13:23:21 -0800 | [diff] [blame] | 118 | public void onEmergencyButtonClickedWhenInCall() { |
| 119 | mCallback.reset(); |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 120 | } |
| 121 | |
Daniel Sandler | 261b18a | 2012-11-01 23:54:03 -0400 | [diff] [blame] | 122 | /* |
| 123 | * Override this if you have a different string for "wrong password" |
| 124 | * |
| 125 | * Note that PIN/PUK have their own implementation of verifyPasswordAndUnlock and so don't need this |
| 126 | */ |
| 127 | protected int getWrongPasswordStringId() { |
| 128 | return R.string.kg_wrong_password; |
| 129 | } |
| 130 | |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 131 | protected void verifyPasswordAndUnlock() { |
Jim Miller | ed7dcc2 | 2015-08-25 19:36:22 -0700 | [diff] [blame] | 132 | if (mDismissing) return; // already verified but haven't been dismissed; don't do it again. |
| 133 | |
Rich Cannings | f64ec63 | 2019-02-21 12:40:36 -0800 | [diff] [blame] | 134 | final byte[] entry = getPasswordText(); |
Xiyuan Xia | de26ea6 | 2015-05-19 15:00:41 -0700 | [diff] [blame] | 135 | setPasswordEntryInputEnabled(false); |
Xiyuan Xia | 6e38058 | 2015-05-05 15:16:08 -0700 | [diff] [blame] | 136 | if (mPendingLockCheck != null) { |
| 137 | mPendingLockCheck.cancel(false); |
| 138 | } |
Andres Morales | 2397427 | 2015-05-14 22:42:26 -0700 | [diff] [blame] | 139 | |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 140 | final int userId = KeyguardUpdateMonitor.getCurrentUser(); |
Rich Cannings | f64ec63 | 2019-02-21 12:40:36 -0800 | [diff] [blame] | 141 | if (entry.length <= MINIMUM_PASSWORD_LENGTH_BEFORE_REPORT) { |
Andres Morales | 2397427 | 2015-05-14 22:42:26 -0700 | [diff] [blame] | 142 | // to avoid accidental lockout, only count attempts that are long enough to be a |
| 143 | // real password. This may require some tweaking. |
| 144 | setPasswordEntryInputEnabled(true); |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 145 | onPasswordChecked(userId, false /* matched */, 0, false /* not valid - too short */); |
Rich Cannings | f64ec63 | 2019-02-21 12:40:36 -0800 | [diff] [blame] | 146 | Arrays.fill(entry, (byte) 0); |
Andres Morales | 2397427 | 2015-05-14 22:42:26 -0700 | [diff] [blame] | 147 | return; |
| 148 | } |
| 149 | |
Jorim Jaggi | d056517 | 2016-09-15 16:31:14 -0700 | [diff] [blame] | 150 | if (LatencyTracker.isEnabled(mContext)) { |
| 151 | LatencyTracker.getInstance(mContext).onActionStart(ACTION_CHECK_CREDENTIAL); |
| 152 | LatencyTracker.getInstance(mContext).onActionStart(ACTION_CHECK_CREDENTIAL_UNLOCKED); |
| 153 | } |
Xiyuan Xia | 6e38058 | 2015-05-05 15:16:08 -0700 | [diff] [blame] | 154 | mPendingLockCheck = LockPatternChecker.checkPassword( |
| 155 | mLockPatternUtils, |
| 156 | entry, |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 157 | userId, |
Xiyuan Xia | 6e38058 | 2015-05-05 15:16:08 -0700 | [diff] [blame] | 158 | new LockPatternChecker.OnCheckCallback() { |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 159 | |
| 160 | @Override |
| 161 | public void onEarlyMatched() { |
Jorim Jaggi | d056517 | 2016-09-15 16:31:14 -0700 | [diff] [blame] | 162 | if (LatencyTracker.isEnabled(mContext)) { |
| 163 | LatencyTracker.getInstance(mContext).onActionEnd( |
| 164 | ACTION_CHECK_CREDENTIAL); |
| 165 | } |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 166 | onPasswordChecked(userId, true /* matched */, 0 /* timeoutMs */, |
| 167 | true /* isValidPassword */); |
Rich Cannings | f64ec63 | 2019-02-21 12:40:36 -0800 | [diff] [blame] | 168 | Arrays.fill(entry, (byte) 0); |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Xiyuan Xia | 6e38058 | 2015-05-05 15:16:08 -0700 | [diff] [blame] | 171 | @Override |
Andres Morales | 2397427 | 2015-05-14 22:42:26 -0700 | [diff] [blame] | 172 | public void onChecked(boolean matched, int timeoutMs) { |
Jorim Jaggi | d056517 | 2016-09-15 16:31:14 -0700 | [diff] [blame] | 173 | if (LatencyTracker.isEnabled(mContext)) { |
| 174 | LatencyTracker.getInstance(mContext).onActionEnd( |
| 175 | ACTION_CHECK_CREDENTIAL_UNLOCKED); |
| 176 | } |
Xiyuan Xia | de26ea6 | 2015-05-19 15:00:41 -0700 | [diff] [blame] | 177 | setPasswordEntryInputEnabled(true); |
Xiyuan Xia | 6e38058 | 2015-05-05 15:16:08 -0700 | [diff] [blame] | 178 | mPendingLockCheck = null; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 179 | if (!matched) { |
| 180 | onPasswordChecked(userId, false /* matched */, timeoutMs, |
| 181 | true /* isValidPassword */); |
| 182 | } |
Rich Cannings | f64ec63 | 2019-02-21 12:40:36 -0800 | [diff] [blame] | 183 | Arrays.fill(entry, (byte) 0); |
Xiyuan Xia | 6e38058 | 2015-05-05 15:16:08 -0700 | [diff] [blame] | 184 | } |
Jorim Jaggi | ed3032b | 2016-10-07 16:49:34 +0200 | [diff] [blame] | 185 | |
| 186 | @Override |
| 187 | public void onCancelled() { |
| 188 | // We already got dismissed with the early matched callback, so we cancelled |
| 189 | // the check. However, we still need to note down the latency. |
| 190 | if (LatencyTracker.isEnabled(mContext)) { |
| 191 | LatencyTracker.getInstance(mContext).onActionEnd( |
| 192 | ACTION_CHECK_CREDENTIAL_UNLOCKED); |
| 193 | } |
Rich Cannings | f64ec63 | 2019-02-21 12:40:36 -0800 | [diff] [blame] | 194 | Arrays.fill(entry, (byte) 0); |
Jorim Jaggi | ed3032b | 2016-10-07 16:49:34 +0200 | [diff] [blame] | 195 | } |
Xiyuan Xia | 6e38058 | 2015-05-05 15:16:08 -0700 | [diff] [blame] | 196 | }); |
| 197 | } |
| 198 | |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 199 | private void onPasswordChecked(int userId, boolean matched, int timeoutMs, |
| 200 | boolean isValidPassword) { |
| 201 | boolean dismissKeyguard = KeyguardUpdateMonitor.getCurrentUser() == userId; |
Xiyuan Xia | 6e38058 | 2015-05-05 15:16:08 -0700 | [diff] [blame] | 202 | if (matched) { |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 203 | mCallback.reportUnlockAttempt(userId, true, 0); |
| 204 | if (dismissKeyguard) { |
| 205 | mDismissing = true; |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 206 | mCallback.dismiss(true, userId); |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 207 | } |
Jim Miller | 526ed2d | 2014-05-19 11:28:32 -0700 | [diff] [blame] | 208 | } else { |
Jim Miller | 51e3a67 | 2015-07-31 18:42:53 -0700 | [diff] [blame] | 209 | if (isValidPassword) { |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 210 | mCallback.reportUnlockAttempt(userId, false, timeoutMs); |
Jim Miller | 51e3a67 | 2015-07-31 18:42:53 -0700 | [diff] [blame] | 211 | if (timeoutMs > 0) { |
| 212 | long deadline = mLockPatternUtils.setLockoutAttemptDeadline( |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 213 | userId, timeoutMs); |
Jim Miller | 51e3a67 | 2015-07-31 18:42:53 -0700 | [diff] [blame] | 214 | handleAttemptLockout(deadline); |
| 215 | } |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 216 | } |
Jim Miller | 51e3a67 | 2015-07-31 18:42:53 -0700 | [diff] [blame] | 217 | if (timeoutMs == 0) { |
Adrian Roos | db327e9 | 2016-10-12 16:41:28 -0700 | [diff] [blame] | 218 | mSecurityMessageDisplay.setMessage(getWrongPasswordStringId()); |
Jim Miller | 51e3a67 | 2015-07-31 18:42:53 -0700 | [diff] [blame] | 219 | } |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 220 | } |
Jim Miller | 4db942c | 2016-05-16 18:06:50 -0700 | [diff] [blame] | 221 | resetPasswordText(true /* animate */, !matched /* announce deletion if no match */); |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 222 | } |
| 223 | |
Jim Miller | 4db942c | 2016-05-16 18:06:50 -0700 | [diff] [blame] | 224 | protected abstract void resetPasswordText(boolean animate, boolean announce); |
Rich Cannings | f64ec63 | 2019-02-21 12:40:36 -0800 | [diff] [blame] | 225 | protected abstract byte[] getPasswordText(); |
Selim Cinek | 4e8b9ed | 2014-06-20 16:37:04 -0700 | [diff] [blame] | 226 | protected abstract void setPasswordEntryEnabled(boolean enabled); |
Xiyuan Xia | de26ea6 | 2015-05-19 15:00:41 -0700 | [diff] [blame] | 227 | protected abstract void setPasswordEntryInputEnabled(boolean enabled); |
Selim Cinek | 4e8b9ed | 2014-06-20 16:37:04 -0700 | [diff] [blame] | 228 | |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 229 | // Prevent user from using the PIN/Password entry until scheduled deadline. |
| 230 | protected void handleAttemptLockout(long elapsedRealtimeDeadline) { |
Selim Cinek | 4e8b9ed | 2014-06-20 16:37:04 -0700 | [diff] [blame] | 231 | setPasswordEntryEnabled(false); |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 232 | long elapsedRealtime = SystemClock.elapsedRealtime(); |
Hidenari Koshimae | 5be868c | 2014-08-21 11:27:33 +0200 | [diff] [blame] | 233 | long secondsInFuture = (long) Math.ceil( |
| 234 | (elapsedRealtimeDeadline - elapsedRealtime) / 1000.0); |
| 235 | mCountdownTimer = new CountDownTimer(secondsInFuture * 1000, 1000) { |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 236 | |
| 237 | @Override |
| 238 | public void onTick(long millisUntilFinished) { |
Hidenari Koshimae | 5be868c | 2014-08-21 11:27:33 +0200 | [diff] [blame] | 239 | int secondsRemaining = (int) Math.round(millisUntilFinished / 1000.0); |
Kevin Chyn | e01c5e1 | 2017-08-29 19:04:25 -0700 | [diff] [blame] | 240 | mSecurityMessageDisplay.setMessage(mContext.getResources().getQuantityString( |
| 241 | R.plurals.kg_too_many_failed_attempts_countdown, |
| 242 | secondsRemaining, secondsRemaining)); |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | @Override |
| 246 | public void onFinish() { |
Adrian Roos | db327e9 | 2016-10-12 16:41:28 -0700 | [diff] [blame] | 247 | mSecurityMessageDisplay.setMessage(""); |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 248 | resetState(); |
| 249 | } |
| 250 | }.start(); |
| 251 | } |
| 252 | |
Xiyuan Xia | 09eb033 | 2015-05-13 15:29:42 -0700 | [diff] [blame] | 253 | protected void onUserInput() { |
| 254 | if (mCallback != null) { |
| 255 | mCallback.userActivity(); |
| 256 | } |
Adrian Roos | db327e9 | 2016-10-12 16:41:28 -0700 | [diff] [blame] | 257 | mSecurityMessageDisplay.setMessage(""); |
Xiyuan Xia | 09eb033 | 2015-05-13 15:29:42 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 260 | @Override |
| 261 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Lucas Dupin | 29e796d | 2018-05-10 15:31:20 -0700 | [diff] [blame] | 262 | // Fingerprint sensor sends a KeyEvent.KEYCODE_UNKNOWN. |
| 263 | // We don't want to consider it valid user input because the UI |
| 264 | // will already respond to the event. |
| 265 | if (keyCode != KeyEvent.KEYCODE_UNKNOWN) { |
| 266 | onUserInput(); |
| 267 | } |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 268 | return false; |
| 269 | } |
| 270 | |
| 271 | @Override |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 272 | public boolean needsInput() { |
| 273 | return false; |
| 274 | } |
| 275 | |
| 276 | @Override |
| 277 | public void onPause() { |
lumark | d62bfd2 | 2019-01-10 15:29:11 +0800 | [diff] [blame] | 278 | mResumed = false; |
| 279 | |
Hidenari Koshimae | 5be868c | 2014-08-21 11:27:33 +0200 | [diff] [blame] | 280 | if (mCountdownTimer != null) { |
| 281 | mCountdownTimer.cancel(); |
| 282 | mCountdownTimer = null; |
| 283 | } |
Xiyuan Xia | 6e38058 | 2015-05-05 15:16:08 -0700 | [diff] [blame] | 284 | if (mPendingLockCheck != null) { |
| 285 | mPendingLockCheck.cancel(false); |
| 286 | mPendingLockCheck = null; |
| 287 | } |
Lucas Dupin | 2986c15 | 2018-04-09 20:49:41 -0700 | [diff] [blame] | 288 | reset(); |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | @Override |
Chris Wren | a042ac9 | 2012-11-07 11:37:06 -0500 | [diff] [blame] | 292 | public void onResume(int reason) { |
lumark | d62bfd2 | 2019-01-10 15:29:11 +0800 | [diff] [blame] | 293 | mResumed = true; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | @Override |
| 297 | public KeyguardSecurityCallback getCallback() { |
| 298 | return mCallback; |
| 299 | } |
| 300 | |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 301 | @Override |
| 302 | public void showPromptReason(int reason) { |
| 303 | if (reason != PROMPT_REASON_NONE) { |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 304 | int promtReasonStringRes = getPromptReasonStringRes(reason); |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 305 | if (promtReasonStringRes != 0) { |
Adrian Roos | db327e9 | 2016-10-12 16:41:28 -0700 | [diff] [blame] | 306 | mSecurityMessageDisplay.setMessage(promtReasonStringRes); |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 311 | @Override |
Jason Chang | 1e4a4bd | 2018-05-22 17:30:19 +0800 | [diff] [blame] | 312 | public void showMessage(CharSequence message, ColorStateList colorState) { |
| 313 | mSecurityMessageDisplay.setNextMessageColor(colorState); |
Adrian Roos | db327e9 | 2016-10-12 16:41:28 -0700 | [diff] [blame] | 314 | mSecurityMessageDisplay.setMessage(message); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 317 | protected abstract int getPromptReasonStringRes(int reason); |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 318 | |
Daniel Sandler | acb60fb | 2012-10-25 10:46:37 -0400 | [diff] [blame] | 319 | // Cause a VIRTUAL_KEY vibration |
| 320 | public void doHapticKeyClick() { |
| 321 | if (mEnableHaptics) { |
| 322 | performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, |
| 323 | HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING |
| 324 | | HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); |
| 325 | } |
| 326 | } |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 327 | |
| 328 | @Override |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 329 | public boolean startDisappearAnimation(Runnable finishRunnable) { |
| 330 | return false; |
| 331 | } |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 332 | } |
| 333 | |