blob: f45b9bd70f61b91fda0da97f3e38d0cd0e663246 [file] [log] [blame]
Jim Miller5a8daad2014-01-14 18:57:03 -08001/*
2 * Copyright (C) 2014 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 */
Jim Miller5ecd8112013-01-09 18:50:26 -080016package com.android.keyguard;
Jim Miller838906b2012-10-19 18:41:25 -070017
Jim Miller7751ff62014-01-14 18:57:03 -080018import android.app.Activity;
19import android.app.AlertDialog;
Amith Yamasani3a3d2122014-10-29 11:41:31 -070020import android.app.admin.DevicePolicyManager;
Jim Miller838906b2012-10-19 18:41:25 -070021import android.content.Context;
Amith Yamasani3a3d2122014-10-29 11:41:31 -070022import android.os.UserHandle;
Jim Miller838906b2012-10-19 18:41:25 -070023import android.util.AttributeSet;
Jim Miller7751ff62014-01-14 18:57:03 -080024import android.util.Log;
25import android.util.Slog;
26import android.view.LayoutInflater;
Chris Wren052999f2012-11-02 14:36:56 -040027import android.view.View;
Jim Miller7751ff62014-01-14 18:57:03 -080028import android.view.WindowManager;
Jim Miller838906b2012-10-19 18:41:25 -070029import android.widget.FrameLayout;
30
Jim Miller7751ff62014-01-14 18:57:03 -080031import com.android.internal.widget.LockPatternUtils;
32import com.android.keyguard.KeyguardSecurityModel.SecurityMode;
33
34public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSecurityView {
Jorim Jaggi5cf17872014-03-26 18:31:48 +010035 private static final boolean DEBUG = KeyguardConstants.DEBUG;
Jim Miller7751ff62014-01-14 18:57:03 -080036 private static final String TAG = "KeyguardSecurityView";
Amith Yamasani3a3d2122014-10-29 11:41:31 -070037
38 private static final int USER_TYPE_PRIMARY = 1;
39 private static final int USER_TYPE_WORK_PROFILE = 2;
40 private static final int USER_TYPE_SECONDARY_USER = 3;
41
Jim Miller7751ff62014-01-14 18:57:03 -080042 private KeyguardSecurityModel mSecurityModel;
Jim Miller7751ff62014-01-14 18:57:03 -080043 private LockPatternUtils mLockPatternUtils;
44
45 private KeyguardSecurityViewFlipper mSecurityViewFlipper;
46 private boolean mIsVerifyUnlockOnly;
47 private SecurityMode mCurrentSecuritySelection = SecurityMode.Invalid;
Jim Miller7751ff62014-01-14 18:57:03 -080048 private SecurityCallback mSecurityCallback;
49
Adrian Roos336be7f2014-05-19 17:11:18 +020050 private final KeyguardUpdateMonitor mUpdateMonitor;
51
Jim Miller7751ff62014-01-14 18:57:03 -080052 // Used to notify the container when something interesting happens.
53 public interface SecurityCallback {
Jim Millerba7d94b2014-02-05 17:30:50 -080054 public boolean dismiss(boolean authenticated);
Jorim Jaggib690f0d2014-07-03 23:25:44 +020055 public void userActivity();
Jim Millerba7d94b2014-02-05 17:30:50 -080056 public void onSecurityModeChanged(SecurityMode securityMode, boolean needsInput);
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -070057
58 /**
59 * @param strongAuth wheher the user has authenticated with strong authentication like
60 * pattern, password or PIN but not by trust agents or fingerprint
61 */
62 public void finish(boolean strongAuth);
Andrew Lee72b46d42015-01-30 13:23:21 -080063 public void reset();
Jim Miller7751ff62014-01-14 18:57:03 -080064 }
65
Jim Miller838906b2012-10-19 18:41:25 -070066 public KeyguardSecurityContainer(Context context, AttributeSet attrs) {
67 this(context, attrs, 0);
68 }
69
70 public KeyguardSecurityContainer(Context context) {
Esteban Talaverafe0f24c2014-08-06 16:20:56 +010071 this(context, null, 0);
Jim Miller838906b2012-10-19 18:41:25 -070072 }
73
74 public KeyguardSecurityContainer(Context context, AttributeSet attrs, int defStyle) {
75 super(context, attrs, defStyle);
Jim Miller7751ff62014-01-14 18:57:03 -080076 mSecurityModel = new KeyguardSecurityModel(context);
77 mLockPatternUtils = new LockPatternUtils(context);
Adrian Roos336be7f2014-05-19 17:11:18 +020078 mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
Chris Wrenc3451462012-10-30 11:22:58 -040079 }
80
Jim Miller7751ff62014-01-14 18:57:03 -080081 public void setSecurityCallback(SecurityCallback callback) {
82 mSecurityCallback = callback;
83 }
84
85 @Override
86 public void onResume(int reason) {
Jorim Jaggif4797922014-08-04 22:49:41 +020087 if (mCurrentSecuritySelection != SecurityMode.None) {
88 getSecurityView(mCurrentSecuritySelection).onResume(reason);
89 }
Jim Miller7751ff62014-01-14 18:57:03 -080090 }
91
92 @Override
93 public void onPause() {
Jorim Jaggif4797922014-08-04 22:49:41 +020094 if (mCurrentSecuritySelection != SecurityMode.None) {
95 getSecurityView(mCurrentSecuritySelection).onPause();
96 }
Jim Miller7751ff62014-01-14 18:57:03 -080097 }
98
Jorim Jaggic14f8292014-05-27 02:25:45 +020099 public void startAppearAnimation() {
Jorim Jaggif4797922014-08-04 22:49:41 +0200100 if (mCurrentSecuritySelection != SecurityMode.None) {
101 getSecurityView(mCurrentSecuritySelection).startAppearAnimation();
102 }
Jorim Jaggic14f8292014-05-27 02:25:45 +0200103 }
104
Jorim Jaggi76a16232014-08-08 17:00:47 +0200105 public boolean startDisappearAnimation(Runnable onFinishRunnable) {
106 if (mCurrentSecuritySelection != SecurityMode.None) {
107 return getSecurityView(mCurrentSecuritySelection).startDisappearAnimation(
108 onFinishRunnable);
109 }
110 return false;
111 }
112
Jim Miller7751ff62014-01-14 18:57:03 -0800113 public void announceCurrentSecurityMethod() {
114 View v = (View) getSecurityView(mCurrentSecuritySelection);
115 if (v != null) {
116 v.announceForAccessibility(v.getContentDescription());
117 }
118 }
119
Jorim Jaggic1dff8c2015-02-02 14:45:39 +0100120 public CharSequence getCurrentSecurityModeContentDescription() {
121 View v = (View) getSecurityView(mCurrentSecuritySelection);
122 if (v != null) {
123 return v.getContentDescription();
124 }
125 return "";
126 }
127
Jim Miller7751ff62014-01-14 18:57:03 -0800128 private KeyguardSecurityView getSecurityView(SecurityMode securityMode) {
129 final int securityViewIdForMode = getSecurityViewIdForMode(securityMode);
130 KeyguardSecurityView view = null;
131 final int children = mSecurityViewFlipper.getChildCount();
132 for (int child = 0; child < children; child++) {
133 if (mSecurityViewFlipper.getChildAt(child).getId() == securityViewIdForMode) {
134 view = ((KeyguardSecurityView)mSecurityViewFlipper.getChildAt(child));
135 break;
136 }
137 }
138 int layoutId = getLayoutIdFor(securityMode);
139 if (view == null && layoutId != 0) {
140 final LayoutInflater inflater = LayoutInflater.from(mContext);
141 if (DEBUG) Log.v(TAG, "inflating id = " + layoutId);
142 View v = inflater.inflate(layoutId, mSecurityViewFlipper, false);
143 mSecurityViewFlipper.addView(v);
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100144 updateSecurityView(v);
Jim Miller7751ff62014-01-14 18:57:03 -0800145 view = (KeyguardSecurityView)v;
146 }
147
Jim Miller7751ff62014-01-14 18:57:03 -0800148 return view;
149 }
150
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100151 private void updateSecurityView(View view) {
Jim Miller7751ff62014-01-14 18:57:03 -0800152 if (view instanceof KeyguardSecurityView) {
153 KeyguardSecurityView ksv = (KeyguardSecurityView) view;
154 ksv.setKeyguardCallback(mCallback);
155 ksv.setLockPatternUtils(mLockPatternUtils);
Jim Miller7751ff62014-01-14 18:57:03 -0800156 } else {
157 Log.w(TAG, "View " + view + " is not a KeyguardSecurityView");
158 }
159 }
160
161 protected void onFinishInflate() {
162 mSecurityViewFlipper = (KeyguardSecurityViewFlipper) findViewById(R.id.view_flipper);
163 mSecurityViewFlipper.setLockPatternUtils(mLockPatternUtils);
164 }
165
166 public void setLockPatternUtils(LockPatternUtils utils) {
167 mLockPatternUtils = utils;
168 mSecurityModel.setLockPatternUtils(utils);
169 mSecurityViewFlipper.setLockPatternUtils(mLockPatternUtils);
170 }
171
172 private void showDialog(String title, String message) {
173 final AlertDialog dialog = new AlertDialog.Builder(mContext)
174 .setTitle(title)
175 .setMessage(message)
176 .setNeutralButton(R.string.ok, null)
177 .create();
178 if (!(mContext instanceof Activity)) {
179 dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
180 }
181 dialog.show();
182 }
183
Andres Morales23974272015-05-14 22:42:26 -0700184 private void showTimeoutDialog(int timeoutMs) {
185 int timeoutInSeconds = (int) timeoutMs / 1000;
Jim Miller7751ff62014-01-14 18:57:03 -0800186 int messageId = 0;
187
188 switch (mSecurityModel.getSecurityMode()) {
189 case Pattern:
190 messageId = R.string.kg_too_many_failed_pattern_attempts_dialog_message;
191 break;
192 case PIN:
193 messageId = R.string.kg_too_many_failed_pin_attempts_dialog_message;
194 break;
195 case Password:
196 messageId = R.string.kg_too_many_failed_password_attempts_dialog_message;
197 break;
198 // These don't have timeout dialogs.
Jim Miller7751ff62014-01-14 18:57:03 -0800199 case Invalid:
200 case None:
201 case SimPin:
202 case SimPuk:
203 break;
204 }
205
206 if (messageId != 0) {
207 final String message = mContext.getString(messageId,
208 KeyguardUpdateMonitor.getInstance(mContext).getFailedUnlockAttempts(),
209 timeoutInSeconds);
210 showDialog(null, message);
211 }
212 }
213
Amith Yamasani3a3d2122014-10-29 11:41:31 -0700214 private void showAlmostAtWipeDialog(int attempts, int remaining, int userType) {
215 String message = null;
216 switch (userType) {
217 case USER_TYPE_PRIMARY:
218 message = mContext.getString(R.string.kg_failed_attempts_almost_at_wipe,
219 attempts, remaining);
220 break;
221 case USER_TYPE_SECONDARY_USER:
222 message = mContext.getString(R.string.kg_failed_attempts_almost_at_erase_user,
223 attempts, remaining);
224 break;
225 case USER_TYPE_WORK_PROFILE:
226 message = mContext.getString(R.string.kg_failed_attempts_almost_at_erase_profile,
227 attempts, remaining);
228 break;
229 }
Jim Miller7751ff62014-01-14 18:57:03 -0800230 showDialog(null, message);
231 }
232
Amith Yamasani3a3d2122014-10-29 11:41:31 -0700233 private void showWipeDialog(int attempts, int userType) {
234 String message = null;
235 switch (userType) {
236 case USER_TYPE_PRIMARY:
237 message = mContext.getString(R.string.kg_failed_attempts_now_wiping,
238 attempts);
239 break;
240 case USER_TYPE_SECONDARY_USER:
241 message = mContext.getString(R.string.kg_failed_attempts_now_erasing_user,
242 attempts);
243 break;
244 case USER_TYPE_WORK_PROFILE:
245 message = mContext.getString(R.string.kg_failed_attempts_now_erasing_profile,
246 attempts);
247 break;
248 }
Jim Miller7751ff62014-01-14 18:57:03 -0800249 showDialog(null, message);
250 }
251
Andres Morales23974272015-05-14 22:42:26 -0700252 private void reportFailedUnlockAttempt(int timeoutMs) {
Jim Miller7751ff62014-01-14 18:57:03 -0800253 final KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
254 final int failedAttempts = monitor.getFailedUnlockAttempts() + 1; // +1 for this time
255
256 if (DEBUG) Log.d(TAG, "reportFailedPatternAttempt: #" + failedAttempts);
257
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700258 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Amith Yamasani3a3d2122014-10-29 11:41:31 -0700259 final DevicePolicyManager dpm = mLockPatternUtils.getDevicePolicyManager();
260 final int failedAttemptsBeforeWipe =
261 dpm.getMaximumFailedPasswordsForWipe(null, currentUser);
Jim Miller7751ff62014-01-14 18:57:03 -0800262
Jim Miller7751ff62014-01-14 18:57:03 -0800263 final int remainingBeforeWipe = failedAttemptsBeforeWipe > 0 ?
264 (failedAttemptsBeforeWipe - failedAttempts)
265 : Integer.MAX_VALUE; // because DPM returns 0 if no restriction
Jim Miller7751ff62014-01-14 18:57:03 -0800266 if (remainingBeforeWipe < LockPatternUtils.FAILED_ATTEMPTS_BEFORE_WIPE_GRACE) {
Esteban Talaverafe0f24c2014-08-06 16:20:56 +0100267 // The user has installed a DevicePolicyManager that requests a user/profile to be wiped
268 // N attempts. Once we get below the grace period, we post this dialog every time as a
269 // clear warning until the deletion fires.
Amith Yamasani3a3d2122014-10-29 11:41:31 -0700270 // Check which profile has the strictest policy for failed password attempts
271 final int expiringUser = dpm.getProfileWithMinimumFailedPasswordsForWipe(currentUser);
272 int userType = USER_TYPE_PRIMARY;
273 if (expiringUser == currentUser) {
Xiaohui Chencc791bc2015-08-26 14:54:34 -0700274 // TODO: http://b/23522538
275 if (expiringUser != UserHandle.USER_SYSTEM) {
Amith Yamasani3a3d2122014-10-29 11:41:31 -0700276 userType = USER_TYPE_SECONDARY_USER;
277 }
278 } else if (expiringUser != UserHandle.USER_NULL) {
279 userType = USER_TYPE_WORK_PROFILE;
280 } // If USER_NULL, which shouldn't happen, leave it as USER_TYPE_PRIMARY
Jim Miller7751ff62014-01-14 18:57:03 -0800281 if (remainingBeforeWipe > 0) {
Amith Yamasani3a3d2122014-10-29 11:41:31 -0700282 showAlmostAtWipeDialog(failedAttempts, remainingBeforeWipe, userType);
Jim Miller7751ff62014-01-14 18:57:03 -0800283 } else {
284 // Too many attempts. The device will be wiped shortly.
Amith Yamasani3a3d2122014-10-29 11:41:31 -0700285 Slog.i(TAG, "Too many unlock attempts; user " + expiringUser + " will be wiped!");
286 showWipeDialog(failedAttempts, userType);
Jim Miller7751ff62014-01-14 18:57:03 -0800287 }
Jim Miller7751ff62014-01-14 18:57:03 -0800288 }
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700289 monitor.reportFailedStrongAuthUnlockAttempt();
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700290 mLockPatternUtils.reportFailedPasswordAttempt(KeyguardUpdateMonitor.getCurrentUser());
Andres Morales23974272015-05-14 22:42:26 -0700291 if (timeoutMs > 0) {
292 showTimeoutDialog(timeoutMs);
Jim Miller7751ff62014-01-14 18:57:03 -0800293 }
294 }
295
296 /**
297 * Shows the primary security screen for the user. This will be either the multi-selector
298 * or the user's security method.
299 * @param turningOff true if the device is being turned off
300 */
301 void showPrimarySecurityScreen(boolean turningOff) {
302 SecurityMode securityMode = mSecurityModel.getSecurityMode();
303 if (DEBUG) Log.v(TAG, "showPrimarySecurityScreen(turningOff=" + turningOff + ")");
Jim Miller7751ff62014-01-14 18:57:03 -0800304 showSecurityScreen(securityMode);
305 }
306
307 /**
Jim Millerba7d94b2014-02-05 17:30:50 -0800308 * Shows the next security screen if there is one.
309 * @param authenticated true if the user entered the correct authentication
Jim Millerba7d94b2014-02-05 17:30:50 -0800310 * @return true if keyguard is done
311 */
Jim Miller7751ff62014-01-14 18:57:03 -0800312 boolean showNextSecurityScreenOrFinish(boolean authenticated) {
313 if (DEBUG) Log.d(TAG, "showNextSecurityScreenOrFinish(" + authenticated + ")");
314 boolean finish = false;
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700315 boolean strongAuth = false;
Selim Cineke8bae622015-07-15 13:24:06 -0700316 if (mUpdateMonitor.getUserCanSkipBouncer(
317 KeyguardUpdateMonitor.getCurrentUser())) {
Adrian Roos336be7f2014-05-19 17:11:18 +0200318 finish = true;
319 } else if (SecurityMode.None == mCurrentSecuritySelection) {
Jim Miller7751ff62014-01-14 18:57:03 -0800320 SecurityMode securityMode = mSecurityModel.getSecurityMode();
Jim Miller7751ff62014-01-14 18:57:03 -0800321 if (SecurityMode.None == securityMode) {
322 finish = true; // no security required
323 } else {
324 showSecurityScreen(securityMode); // switch to the alternate security view
325 }
326 } else if (authenticated) {
327 switch (mCurrentSecuritySelection) {
328 case Pattern:
329 case Password:
330 case PIN:
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700331 strongAuth = true;
Jim Miller7751ff62014-01-14 18:57:03 -0800332 finish = true;
333 break;
334
335 case SimPin:
336 case SimPuk:
337 // Shortcut for SIM PIN/PUK to go to directly to user's security screen or home
338 SecurityMode securityMode = mSecurityModel.getSecurityMode();
Selim Cinek245273e2015-06-24 13:17:56 -0400339 if (securityMode != SecurityMode.None
340 || !mLockPatternUtils.isLockScreenDisabled(
341 KeyguardUpdateMonitor.getCurrentUser())) {
Jim Miller7751ff62014-01-14 18:57:03 -0800342 showSecurityScreen(securityMode);
343 } else {
344 finish = true;
345 }
346 break;
347
348 default:
349 Log.v(TAG, "Bad security screen " + mCurrentSecuritySelection + ", fail safe");
350 showPrimarySecurityScreen(false);
351 break;
352 }
Jim Miller7751ff62014-01-14 18:57:03 -0800353 }
354 if (finish) {
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700355 mSecurityCallback.finish(strongAuth);
Jim Miller7751ff62014-01-14 18:57:03 -0800356 }
357 return finish;
358 }
359
360 /**
361 * Switches to the given security view unless it's already being shown, in which case
362 * this is a no-op.
363 *
364 * @param securityMode
365 */
366 private void showSecurityScreen(SecurityMode securityMode) {
367 if (DEBUG) Log.d(TAG, "showSecurityScreen(" + securityMode + ")");
368
369 if (securityMode == mCurrentSecuritySelection) return;
370
371 KeyguardSecurityView oldView = getSecurityView(mCurrentSecuritySelection);
372 KeyguardSecurityView newView = getSecurityView(securityMode);
373
374 // Emulate Activity life cycle
375 if (oldView != null) {
376 oldView.onPause();
377 oldView.setKeyguardCallback(mNullCallback); // ignore requests from old view
378 }
Jorim Jaggif4797922014-08-04 22:49:41 +0200379 if (securityMode != SecurityMode.None) {
380 newView.onResume(KeyguardSecurityView.VIEW_REVEALED);
381 newView.setKeyguardCallback(mCallback);
382 }
Jim Miller7751ff62014-01-14 18:57:03 -0800383
384 // Find and show this child.
385 final int childCount = mSecurityViewFlipper.getChildCount();
386
387 final int securityViewIdForMode = getSecurityViewIdForMode(securityMode);
388 for (int i = 0; i < childCount; i++) {
389 if (mSecurityViewFlipper.getChildAt(i).getId() == securityViewIdForMode) {
390 mSecurityViewFlipper.setDisplayedChild(i);
391 break;
392 }
393 }
394
395 mCurrentSecuritySelection = securityMode;
Jorim Jaggif4797922014-08-04 22:49:41 +0200396 mSecurityCallback.onSecurityModeChanged(securityMode,
397 securityMode != SecurityMode.None && newView.needsInput());
Jim Miller7751ff62014-01-14 18:57:03 -0800398 }
399
400 private KeyguardSecurityViewFlipper getFlipper() {
Chris Wren052999f2012-11-02 14:36:56 -0400401 for (int i = 0; i < getChildCount(); i++) {
402 View child = getChildAt(i);
403 if (child instanceof KeyguardSecurityViewFlipper) {
Chris Wrenc0ae9e62012-11-05 13:16:31 -0500404 return (KeyguardSecurityViewFlipper) child;
Chris Wren052999f2012-11-02 14:36:56 -0400405 }
406 }
407 return null;
408 }
409
Jim Miller7751ff62014-01-14 18:57:03 -0800410 private KeyguardSecurityCallback mCallback = new KeyguardSecurityCallback() {
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200411 public void userActivity() {
Jim Miller7751ff62014-01-14 18:57:03 -0800412 if (mSecurityCallback != null) {
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200413 mSecurityCallback.userActivity();
Jim Miller7751ff62014-01-14 18:57:03 -0800414 }
415 }
416
417 public void dismiss(boolean authenticated) {
418 mSecurityCallback.dismiss(authenticated);
419 }
420
421 public boolean isVerifyUnlockOnly() {
422 return mIsVerifyUnlockOnly;
423 }
424
Andres Morales23974272015-05-14 22:42:26 -0700425 public void reportUnlockAttempt(boolean success, int timeoutMs) {
Jim Miller7751ff62014-01-14 18:57:03 -0800426 KeyguardUpdateMonitor monitor = KeyguardUpdateMonitor.getInstance(mContext);
427 if (success) {
428 monitor.clearFailedUnlockAttempts();
Adrian Roos8150d2a2015-04-16 17:11:20 -0700429 mLockPatternUtils.reportSuccessfulPasswordAttempt(
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700430 KeyguardUpdateMonitor.getCurrentUser());
Jim Miller7751ff62014-01-14 18:57:03 -0800431 } else {
Andres Morales23974272015-05-14 22:42:26 -0700432 KeyguardSecurityContainer.this.reportFailedUnlockAttempt(timeoutMs);
Jim Miller7751ff62014-01-14 18:57:03 -0800433 }
434 }
435
Andrew Lee72b46d42015-01-30 13:23:21 -0800436 public void reset() {
437 mSecurityCallback.reset();
438 }
Jim Miller7751ff62014-01-14 18:57:03 -0800439 };
440
441 // The following is used to ignore callbacks from SecurityViews that are no longer current
442 // (e.g. face unlock). This avoids unwanted asynchronous events from messing with the
443 // state for the current security method.
444 private KeyguardSecurityCallback mNullCallback = new KeyguardSecurityCallback() {
445 @Override
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200446 public void userActivity() { }
Jim Miller7751ff62014-01-14 18:57:03 -0800447 @Override
Andres Morales23974272015-05-14 22:42:26 -0700448 public void reportUnlockAttempt(boolean success, int timeoutMs) { }
Jim Miller7751ff62014-01-14 18:57:03 -0800449 @Override
450 public boolean isVerifyUnlockOnly() { return false; }
451 @Override
452 public void dismiss(boolean securityVerified) { }
Andrew Lee72b46d42015-01-30 13:23:21 -0800453 @Override
454 public void reset() {}
Jim Miller7751ff62014-01-14 18:57:03 -0800455 };
456
457 private int getSecurityViewIdForMode(SecurityMode securityMode) {
458 switch (securityMode) {
Jim Miller7751ff62014-01-14 18:57:03 -0800459 case Pattern: return R.id.keyguard_pattern_view;
460 case PIN: return R.id.keyguard_pin_view;
461 case Password: return R.id.keyguard_password_view;
Jim Miller7751ff62014-01-14 18:57:03 -0800462 case SimPin: return R.id.keyguard_sim_pin_view;
463 case SimPuk: return R.id.keyguard_sim_puk_view;
464 }
465 return 0;
466 }
467
468 private int getLayoutIdFor(SecurityMode securityMode) {
469 switch (securityMode) {
Jim Miller7751ff62014-01-14 18:57:03 -0800470 case Pattern: return R.layout.keyguard_pattern_view;
471 case PIN: return R.layout.keyguard_pin_view;
472 case Password: return R.layout.keyguard_password_view;
Jim Miller7751ff62014-01-14 18:57:03 -0800473 case SimPin: return R.layout.keyguard_sim_pin_view;
474 case SimPuk: return R.layout.keyguard_sim_puk_view;
475 default:
476 return 0;
477 }
478 }
479
480 public SecurityMode getSecurityMode() {
481 return mSecurityModel.getSecurityMode();
482 }
483
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100484 public SecurityMode getCurrentSecurityMode() {
485 return mCurrentSecuritySelection;
486 }
487
Jim Miller7751ff62014-01-14 18:57:03 -0800488 public void verifyUnlock() {
489 mIsVerifyUnlockOnly = true;
490 showSecurityScreen(getSecurityMode());
491 }
492
493 public SecurityMode getCurrentSecuritySelection() {
494 return mCurrentSecuritySelection;
495 }
496
497 public void dismiss(boolean authenticated) {
498 mCallback.dismiss(authenticated);
499 }
500
501 public boolean needsInput() {
502 return mSecurityViewFlipper.needsInput();
503 }
504
505 @Override
506 public void setKeyguardCallback(KeyguardSecurityCallback callback) {
507 mSecurityViewFlipper.setKeyguardCallback(callback);
508 }
509
510 @Override
511 public void reset() {
512 mSecurityViewFlipper.reset();
513 }
514
515 @Override
516 public KeyguardSecurityCallback getCallback() {
517 return mSecurityViewFlipper.getCallback();
518 }
519
520 @Override
Selim Cinek3122fa82015-06-18 01:38:59 -0700521 public void showPromptReason(int reason) {
522 if (mCurrentSecuritySelection != SecurityMode.None) {
523 getSecurityView(mCurrentSecuritySelection).showPromptReason(reason);
524 }
525 }
526
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700527
528 public void showMessage(String message, int color) {
529 if (mCurrentSecuritySelection != SecurityMode.None) {
530 getSecurityView(mCurrentSecuritySelection).showMessage(message, color);
531 }
532 }
533
Selim Cinek3122fa82015-06-18 01:38:59 -0700534 @Override
Jim Miller7751ff62014-01-14 18:57:03 -0800535 public void showUsabilityHint() {
536 mSecurityViewFlipper.showUsabilityHint();
537 }
538
Jim Miller838906b2012-10-19 18:41:25 -0700539}
Chris Wrenc0ae9e62012-11-05 13:16:31 -0500540