Jim Miller | 5a8daad | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 1 | /* |
| 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 Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 16 | package com.android.keyguard; |
Jim Miller | 838906b | 2012-10-19 18:41:25 -0700 | [diff] [blame] | 17 | |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 18 | import android.app.Activity; |
| 19 | import android.app.AlertDialog; |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 20 | import android.app.admin.DevicePolicyManager; |
Jim Miller | 838906b | 2012-10-19 18:41:25 -0700 | [diff] [blame] | 21 | import android.content.Context; |
Jason Chang | 1e4a4bd | 2018-05-22 17:30:19 +0800 | [diff] [blame] | 22 | import android.content.res.ColorStateList; |
Lucas Dupin | 3ac28ac | 2019-05-13 16:33:32 -0700 | [diff] [blame] | 23 | import android.graphics.Rect; |
Steven Wu | 6ef24b2 | 2019-03-11 17:14:11 -0400 | [diff] [blame] | 24 | import android.metrics.LogMaker; |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 25 | import android.os.UserHandle; |
Jim Miller | 838906b | 2012-10-19 18:41:25 -0700 | [diff] [blame] | 26 | import android.util.AttributeSet; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 27 | import android.util.Log; |
| 28 | import android.util.Slog; |
Tej Singh | dd7bd35 | 2018-02-09 19:33:15 -0800 | [diff] [blame] | 29 | import android.util.StatsLog; |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 30 | import android.util.TypedValue; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 31 | import android.view.LayoutInflater; |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 32 | import android.view.MotionEvent; |
| 33 | import android.view.VelocityTracker; |
Chris Wren | 052999f | 2012-11-02 14:36:56 -0400 | [diff] [blame] | 34 | import android.view.View; |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 35 | import android.view.ViewConfiguration; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 36 | import android.view.WindowManager; |
Jim Miller | 838906b | 2012-10-19 18:41:25 -0700 | [diff] [blame] | 37 | import android.widget.FrameLayout; |
| 38 | |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 39 | import androidx.annotation.VisibleForTesting; |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 40 | import androidx.dynamicanimation.animation.DynamicAnimation; |
| 41 | import androidx.dynamicanimation.animation.SpringAnimation; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 42 | |
Steven Wu | 6ef24b2 | 2019-03-11 17:14:11 -0400 | [diff] [blame] | 43 | import com.android.internal.logging.MetricsLogger; |
| 44 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 45 | import com.android.internal.widget.LockPatternUtils; |
| 46 | import com.android.keyguard.KeyguardSecurityModel.SecurityMode; |
Steven Wu | 6ef24b2 | 2019-03-11 17:14:11 -0400 | [diff] [blame] | 47 | import com.android.systemui.Dependency; |
Priyank Singh | 051353e | 2019-04-25 10:14:57 -0700 | [diff] [blame] | 48 | import com.android.systemui.SystemUIFactory; |
Lucas Dupin | 206fe56 | 2019-05-31 14:36:42 -0700 | [diff] [blame] | 49 | import com.android.systemui.statusbar.phone.UnlockMethodCache; |
Priyank Singh | 051353e | 2019-04-25 10:14:57 -0700 | [diff] [blame] | 50 | import com.android.systemui.util.InjectionInflationController; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 51 | |
| 52 | public class KeyguardSecurityContainer extends FrameLayout implements KeyguardSecurityView { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 53 | private static final boolean DEBUG = KeyguardConstants.DEBUG; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 54 | private static final String TAG = "KeyguardSecurityView"; |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 55 | |
| 56 | private static final int USER_TYPE_PRIMARY = 1; |
| 57 | private static final int USER_TYPE_WORK_PROFILE = 2; |
| 58 | private static final int USER_TYPE_SECONDARY_USER = 3; |
| 59 | |
Steven Wu | cfe398d | 2019-03-21 11:32:15 -0400 | [diff] [blame] | 60 | // Bouncer is dismissed due to no security. |
| 61 | private static final int BOUNCER_DISMISS_NONE_SECURITY = 0; |
| 62 | // Bouncer is dismissed due to pin, password or pattern entered. |
| 63 | private static final int BOUNCER_DISMISS_PASSWORD = 1; |
| 64 | // Bouncer is dismissed due to biometric (face, fingerprint or iris) authenticated. |
| 65 | private static final int BOUNCER_DISMISS_BIOMETRIC = 2; |
| 66 | // Bouncer is dismissed due to extended access granted. |
| 67 | private static final int BOUNCER_DISMISS_EXTENDED_ACCESS = 3; |
| 68 | // Bouncer is dismissed due to sim card unlock code entered. |
| 69 | private static final int BOUNCER_DISMISS_SIM = 4; |
| 70 | |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 71 | // Make the view move slower than the finger, as if the spring were applying force. |
| 72 | private static final float TOUCH_Y_MULTIPLIER = 0.25f; |
| 73 | // How much you need to drag the bouncer to trigger an auth retry (in dps.) |
| 74 | private static final float MIN_DRAG_SIZE = 10; |
Lucas Dupin | abb18f4 | 2019-05-20 19:10:22 -0700 | [diff] [blame] | 75 | // How much to scale the default slop by, to avoid accidental drags. |
| 76 | private static final float SLOP_SCALE = 2f; |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 77 | |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 78 | private KeyguardSecurityModel mSecurityModel; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 79 | private LockPatternUtils mLockPatternUtils; |
| 80 | |
| 81 | private KeyguardSecurityViewFlipper mSecurityViewFlipper; |
| 82 | private boolean mIsVerifyUnlockOnly; |
| 83 | private SecurityMode mCurrentSecuritySelection = SecurityMode.Invalid; |
Lucas Dupin | 27321c4 | 2019-03-20 16:22:24 -0700 | [diff] [blame] | 84 | private KeyguardSecurityView mCurrentSecurityView; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 85 | private SecurityCallback mSecurityCallback; |
Lucas Dupin | 7f72982 | 2017-12-13 15:27:10 -0800 | [diff] [blame] | 86 | private AlertDialog mAlertDialog; |
Priyank Singh | 051353e | 2019-04-25 10:14:57 -0700 | [diff] [blame] | 87 | private InjectionInflationController mInjectionInflationController; |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 88 | private boolean mSwipeUpToRetry; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 89 | |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 90 | private final ViewConfiguration mViewConfiguration; |
| 91 | private final SpringAnimation mSpringAnimation; |
| 92 | private final VelocityTracker mVelocityTracker = VelocityTracker.obtain(); |
Adrian Roos | 336be7f | 2014-05-19 17:11:18 +0200 | [diff] [blame] | 93 | private final KeyguardUpdateMonitor mUpdateMonitor; |
Lucas Dupin | 206fe56 | 2019-05-31 14:36:42 -0700 | [diff] [blame] | 94 | private final UnlockMethodCache mUnlockMethodCache; |
Adrian Roos | 336be7f | 2014-05-19 17:11:18 +0200 | [diff] [blame] | 95 | |
Steven Wu | 6ef24b2 | 2019-03-11 17:14:11 -0400 | [diff] [blame] | 96 | private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 97 | private float mLastTouchY = -1; |
| 98 | private int mActivePointerId = -1; |
| 99 | private boolean mIsDragging; |
| 100 | private float mStartTouchY = -1; |
Steven Wu | 6ef24b2 | 2019-03-11 17:14:11 -0400 | [diff] [blame] | 101 | |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 102 | // Used to notify the container when something interesting happens. |
| 103 | public interface SecurityCallback { |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 104 | public boolean dismiss(boolean authenticated, int targetUserId); |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 105 | public void userActivity(); |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 106 | public void onSecurityModeChanged(SecurityMode securityMode, boolean needsInput); |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 107 | |
| 108 | /** |
| 109 | * @param strongAuth wheher the user has authenticated with strong authentication like |
| 110 | * pattern, password or PIN but not by trust agents or fingerprint |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 111 | * @param targetUserId a user that needs to be the foreground user at the finish completion. |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 112 | */ |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 113 | public void finish(boolean strongAuth, int targetUserId); |
Andrew Lee | 72b46d4 | 2015-01-30 13:23:21 -0800 | [diff] [blame] | 114 | public void reset(); |
Aarthi Balachander | 0a427ef | 2018-07-13 15:00:58 -0700 | [diff] [blame] | 115 | public void onCancelClicked(); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Jim Miller | 838906b | 2012-10-19 18:41:25 -0700 | [diff] [blame] | 118 | public KeyguardSecurityContainer(Context context, AttributeSet attrs) { |
| 119 | this(context, attrs, 0); |
| 120 | } |
| 121 | |
| 122 | public KeyguardSecurityContainer(Context context) { |
Esteban Talavera | fe0f24c | 2014-08-06 16:20:56 +0100 | [diff] [blame] | 123 | this(context, null, 0); |
Jim Miller | 838906b | 2012-10-19 18:41:25 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | public KeyguardSecurityContainer(Context context, AttributeSet attrs, int defStyle) { |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 127 | super(context, attrs, defStyle); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 128 | mSecurityModel = new KeyguardSecurityModel(context); |
| 129 | mLockPatternUtils = new LockPatternUtils(context); |
Adrian Roos | 336be7f | 2014-05-19 17:11:18 +0200 | [diff] [blame] | 130 | mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext); |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 131 | mSpringAnimation = new SpringAnimation(this, DynamicAnimation.Y); |
Priyank Singh | 051353e | 2019-04-25 10:14:57 -0700 | [diff] [blame] | 132 | mInjectionInflationController = new InjectionInflationController( |
| 133 | SystemUIFactory.getInstance().getRootComponent()); |
Lucas Dupin | 206fe56 | 2019-05-31 14:36:42 -0700 | [diff] [blame] | 134 | mUnlockMethodCache = UnlockMethodCache.getInstance(context); |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 135 | mViewConfiguration = ViewConfiguration.get(context); |
Chris Wren | c345146 | 2012-10-30 11:22:58 -0400 | [diff] [blame] | 136 | } |
| 137 | |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 138 | public void setSecurityCallback(SecurityCallback callback) { |
| 139 | mSecurityCallback = callback; |
| 140 | } |
| 141 | |
| 142 | @Override |
| 143 | public void onResume(int reason) { |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 144 | if (mCurrentSecuritySelection != SecurityMode.None) { |
| 145 | getSecurityView(mCurrentSecuritySelection).onResume(reason); |
| 146 | } |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 147 | updateBiometricRetry(); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public void onPause() { |
Lucas Dupin | 7f72982 | 2017-12-13 15:27:10 -0800 | [diff] [blame] | 152 | if (mAlertDialog != null) { |
| 153 | mAlertDialog.dismiss(); |
| 154 | mAlertDialog = null; |
| 155 | } |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 156 | if (mCurrentSecuritySelection != SecurityMode.None) { |
| 157 | getSecurityView(mCurrentSecuritySelection).onPause(); |
| 158 | } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 159 | } |
| 160 | |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 161 | @Override |
| 162 | public boolean shouldDelayChildPressedState() { |
| 163 | return true; |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public boolean onInterceptTouchEvent(MotionEvent event) { |
| 168 | switch (event.getActionMasked()) { |
| 169 | case MotionEvent.ACTION_DOWN: |
| 170 | int pointerIndex = event.getActionIndex(); |
| 171 | mStartTouchY = event.getY(pointerIndex); |
| 172 | mActivePointerId = event.getPointerId(pointerIndex); |
| 173 | mVelocityTracker.clear(); |
| 174 | break; |
| 175 | case MotionEvent.ACTION_MOVE: |
| 176 | if (mIsDragging) { |
| 177 | return true; |
| 178 | } |
| 179 | if (!mSwipeUpToRetry) { |
| 180 | return false; |
| 181 | } |
| 182 | // Avoid dragging the pattern view |
| 183 | if (mCurrentSecurityView.disallowInterceptTouch(event)) { |
| 184 | return false; |
| 185 | } |
| 186 | int index = event.findPointerIndex(mActivePointerId); |
Lucas Dupin | abb18f4 | 2019-05-20 19:10:22 -0700 | [diff] [blame] | 187 | float touchSlop = mViewConfiguration.getScaledTouchSlop() * SLOP_SCALE; |
Lucas Dupin | c26ab751 | 2019-05-13 13:49:17 -0700 | [diff] [blame] | 188 | if (mCurrentSecurityView != null && index != -1 |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 189 | && mStartTouchY - event.getY(index) > touchSlop) { |
| 190 | mIsDragging = true; |
| 191 | return true; |
| 192 | } |
| 193 | break; |
| 194 | case MotionEvent.ACTION_CANCEL: |
| 195 | case MotionEvent.ACTION_UP: |
| 196 | mIsDragging = false; |
| 197 | break; |
| 198 | } |
| 199 | return false; |
| 200 | } |
| 201 | |
| 202 | @Override |
| 203 | public boolean onTouchEvent(MotionEvent event) { |
| 204 | final int action = event.getActionMasked(); |
| 205 | switch (action) { |
| 206 | case MotionEvent.ACTION_MOVE: |
| 207 | mVelocityTracker.addMovement(event); |
| 208 | int pointerIndex = event.findPointerIndex(mActivePointerId); |
| 209 | float y = event.getY(pointerIndex); |
| 210 | if (mLastTouchY != -1) { |
| 211 | float dy = y - mLastTouchY; |
| 212 | setTranslationY(getTranslationY() + dy * TOUCH_Y_MULTIPLIER); |
| 213 | } |
| 214 | mLastTouchY = y; |
| 215 | break; |
| 216 | case MotionEvent.ACTION_UP: |
| 217 | case MotionEvent.ACTION_CANCEL: |
| 218 | mActivePointerId = -1; |
| 219 | mLastTouchY = -1; |
| 220 | mIsDragging = false; |
| 221 | startSpringAnimation(mVelocityTracker.getYVelocity()); |
| 222 | break; |
| 223 | case MotionEvent.ACTION_POINTER_UP: |
| 224 | int index = event.getActionIndex(); |
| 225 | int pointerId = event.getPointerId(index); |
| 226 | if (pointerId == mActivePointerId) { |
| 227 | // This was our active pointer going up. Choose a new |
| 228 | // active pointer and adjust accordingly. |
| 229 | final int newPointerIndex = index == 0 ? 1 : 0; |
| 230 | mLastTouchY = event.getY(newPointerIndex); |
| 231 | mActivePointerId = event.getPointerId(newPointerIndex); |
| 232 | } |
| 233 | break; |
| 234 | } |
| 235 | if (action == MotionEvent.ACTION_UP) { |
| 236 | if (-getTranslationY() > TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, |
Lucas Dupin | 51996bb | 2019-05-16 17:56:43 -0700 | [diff] [blame] | 237 | MIN_DRAG_SIZE, getResources().getDisplayMetrics()) |
| 238 | && !mUpdateMonitor.isFaceDetectionRunning()) { |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 239 | mUpdateMonitor.requestFaceAuth(); |
Lucas Dupin | aad9883 | 2019-07-14 13:23:24 +0900 | [diff] [blame] | 240 | mCallback.userActivity(); |
Lucas Dupin | 51996bb | 2019-05-16 17:56:43 -0700 | [diff] [blame] | 241 | showMessage(null, null); |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | return true; |
| 245 | } |
| 246 | |
| 247 | private void startSpringAnimation(float startVelocity) { |
| 248 | mSpringAnimation |
| 249 | .setStartVelocity(startVelocity) |
| 250 | .animateToFinalPosition(0); |
| 251 | } |
| 252 | |
Jorim Jaggi | c14f829 | 2014-05-27 02:25:45 +0200 | [diff] [blame] | 253 | public void startAppearAnimation() { |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 254 | if (mCurrentSecuritySelection != SecurityMode.None) { |
| 255 | getSecurityView(mCurrentSecuritySelection).startAppearAnimation(); |
| 256 | } |
Jorim Jaggi | c14f829 | 2014-05-27 02:25:45 +0200 | [diff] [blame] | 257 | } |
| 258 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 259 | public boolean startDisappearAnimation(Runnable onFinishRunnable) { |
| 260 | if (mCurrentSecuritySelection != SecurityMode.None) { |
| 261 | return getSecurityView(mCurrentSecuritySelection).startDisappearAnimation( |
| 262 | onFinishRunnable); |
| 263 | } |
| 264 | return false; |
| 265 | } |
| 266 | |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 267 | /** |
| 268 | * Enables/disables swipe up to retry on the bouncer. |
| 269 | */ |
| 270 | private void updateBiometricRetry() { |
| 271 | SecurityMode securityMode = getSecurityMode(); |
Lucas Dupin | 4c50704 | 2019-07-22 16:47:34 -0700 | [diff] [blame] | 272 | mSwipeUpToRetry = mUnlockMethodCache.isFaceAuthEnabled() |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 273 | && securityMode != SecurityMode.SimPin |
| 274 | && securityMode != SecurityMode.SimPuk |
Lucas Dupin | fc8de93 | 2019-06-13 14:20:52 -0700 | [diff] [blame] | 275 | && securityMode != SecurityMode.None; |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Phil Weaver | 7d847b0 | 2018-02-13 16:02:35 -0800 | [diff] [blame] | 278 | public CharSequence getTitle() { |
| 279 | return mSecurityViewFlipper.getTitle(); |
Jorim Jaggi | c1dff8c | 2015-02-02 14:45:39 +0100 | [diff] [blame] | 280 | } |
| 281 | |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 282 | private KeyguardSecurityView getSecurityView(SecurityMode securityMode) { |
| 283 | final int securityViewIdForMode = getSecurityViewIdForMode(securityMode); |
| 284 | KeyguardSecurityView view = null; |
| 285 | final int children = mSecurityViewFlipper.getChildCount(); |
| 286 | for (int child = 0; child < children; child++) { |
| 287 | if (mSecurityViewFlipper.getChildAt(child).getId() == securityViewIdForMode) { |
| 288 | view = ((KeyguardSecurityView)mSecurityViewFlipper.getChildAt(child)); |
| 289 | break; |
| 290 | } |
| 291 | } |
| 292 | int layoutId = getLayoutIdFor(securityMode); |
| 293 | if (view == null && layoutId != 0) { |
| 294 | final LayoutInflater inflater = LayoutInflater.from(mContext); |
| 295 | if (DEBUG) Log.v(TAG, "inflating id = " + layoutId); |
Priyank Singh | 051353e | 2019-04-25 10:14:57 -0700 | [diff] [blame] | 296 | View v = mInjectionInflationController.injectable(inflater) |
| 297 | .inflate(layoutId, mSecurityViewFlipper, false); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 298 | mSecurityViewFlipper.addView(v); |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 299 | updateSecurityView(v); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 300 | view = (KeyguardSecurityView)v; |
Lucas Dupin | f7fd03d | 2018-06-26 15:58:51 -0700 | [diff] [blame] | 301 | view.reset(); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 304 | return view; |
| 305 | } |
| 306 | |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 307 | private void updateSecurityView(View view) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 308 | if (view instanceof KeyguardSecurityView) { |
| 309 | KeyguardSecurityView ksv = (KeyguardSecurityView) view; |
| 310 | ksv.setKeyguardCallback(mCallback); |
| 311 | ksv.setLockPatternUtils(mLockPatternUtils); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 312 | } else { |
| 313 | Log.w(TAG, "View " + view + " is not a KeyguardSecurityView"); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | protected void onFinishInflate() { |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 318 | mSecurityViewFlipper = findViewById(R.id.view_flipper); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 319 | mSecurityViewFlipper.setLockPatternUtils(mLockPatternUtils); |
| 320 | } |
| 321 | |
| 322 | public void setLockPatternUtils(LockPatternUtils utils) { |
| 323 | mLockPatternUtils = utils; |
| 324 | mSecurityModel.setLockPatternUtils(utils); |
| 325 | mSecurityViewFlipper.setLockPatternUtils(mLockPatternUtils); |
| 326 | } |
| 327 | |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 328 | @Override |
Lucas Dupin | 3ac28ac | 2019-05-13 16:33:32 -0700 | [diff] [blame] | 329 | protected boolean fitSystemWindows(Rect insets) { |
| 330 | // Consume bottom insets because we're setting the padding locally (for IME and navbar.) |
| 331 | setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), insets.bottom); |
| 332 | insets.bottom = 0; |
| 333 | return false; |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 336 | private void showDialog(String title, String message) { |
Lucas Dupin | 7f72982 | 2017-12-13 15:27:10 -0800 | [diff] [blame] | 337 | if (mAlertDialog != null) { |
| 338 | mAlertDialog.dismiss(); |
| 339 | } |
| 340 | |
| 341 | mAlertDialog = new AlertDialog.Builder(mContext) |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 342 | .setTitle(title) |
| 343 | .setMessage(message) |
Edward Savage-Jones | b08a146 | 2016-10-05 10:29:02 +0200 | [diff] [blame] | 344 | .setCancelable(false) |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 345 | .setNeutralButton(R.string.ok, null) |
| 346 | .create(); |
| 347 | if (!(mContext instanceof Activity)) { |
Lucas Dupin | 7f72982 | 2017-12-13 15:27:10 -0800 | [diff] [blame] | 348 | mAlertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 349 | } |
Lucas Dupin | 7f72982 | 2017-12-13 15:27:10 -0800 | [diff] [blame] | 350 | mAlertDialog.show(); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 351 | } |
| 352 | |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 353 | private void showTimeoutDialog(int userId, int timeoutMs) { |
Andres Morales | 2397427 | 2015-05-14 22:42:26 -0700 | [diff] [blame] | 354 | int timeoutInSeconds = (int) timeoutMs / 1000; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 355 | int messageId = 0; |
| 356 | |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 357 | switch (mSecurityModel.getSecurityMode(userId)) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 358 | case Pattern: |
| 359 | messageId = R.string.kg_too_many_failed_pattern_attempts_dialog_message; |
| 360 | break; |
| 361 | case PIN: |
| 362 | messageId = R.string.kg_too_many_failed_pin_attempts_dialog_message; |
| 363 | break; |
| 364 | case Password: |
| 365 | messageId = R.string.kg_too_many_failed_password_attempts_dialog_message; |
| 366 | break; |
| 367 | // These don't have timeout dialogs. |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 368 | case Invalid: |
| 369 | case None: |
| 370 | case SimPin: |
| 371 | case SimPuk: |
| 372 | break; |
| 373 | } |
| 374 | |
| 375 | if (messageId != 0) { |
| 376 | final String message = mContext.getString(messageId, |
Pavel Grafov | b90dc43 | 2018-08-15 20:02:58 +0100 | [diff] [blame] | 377 | mLockPatternUtils.getCurrentFailedPasswordAttempts(userId), |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 378 | timeoutInSeconds); |
| 379 | showDialog(null, message); |
| 380 | } |
| 381 | } |
| 382 | |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 383 | private void showAlmostAtWipeDialog(int attempts, int remaining, int userType) { |
| 384 | String message = null; |
| 385 | switch (userType) { |
| 386 | case USER_TYPE_PRIMARY: |
| 387 | message = mContext.getString(R.string.kg_failed_attempts_almost_at_wipe, |
| 388 | attempts, remaining); |
| 389 | break; |
| 390 | case USER_TYPE_SECONDARY_USER: |
| 391 | message = mContext.getString(R.string.kg_failed_attempts_almost_at_erase_user, |
| 392 | attempts, remaining); |
| 393 | break; |
| 394 | case USER_TYPE_WORK_PROFILE: |
| 395 | message = mContext.getString(R.string.kg_failed_attempts_almost_at_erase_profile, |
| 396 | attempts, remaining); |
| 397 | break; |
| 398 | } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 399 | showDialog(null, message); |
| 400 | } |
| 401 | |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 402 | private void showWipeDialog(int attempts, int userType) { |
| 403 | String message = null; |
| 404 | switch (userType) { |
| 405 | case USER_TYPE_PRIMARY: |
| 406 | message = mContext.getString(R.string.kg_failed_attempts_now_wiping, |
| 407 | attempts); |
| 408 | break; |
| 409 | case USER_TYPE_SECONDARY_USER: |
| 410 | message = mContext.getString(R.string.kg_failed_attempts_now_erasing_user, |
| 411 | attempts); |
| 412 | break; |
| 413 | case USER_TYPE_WORK_PROFILE: |
| 414 | message = mContext.getString(R.string.kg_failed_attempts_now_erasing_profile, |
| 415 | attempts); |
| 416 | break; |
| 417 | } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 418 | showDialog(null, message); |
| 419 | } |
| 420 | |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 421 | private void reportFailedUnlockAttempt(int userId, int timeoutMs) { |
Pavel Grafov | b90dc43 | 2018-08-15 20:02:58 +0100 | [diff] [blame] | 422 | // +1 for this time |
| 423 | final int failedAttempts = mLockPatternUtils.getCurrentFailedPasswordAttempts(userId) + 1; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 424 | |
| 425 | if (DEBUG) Log.d(TAG, "reportFailedPatternAttempt: #" + failedAttempts); |
| 426 | |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 427 | final DevicePolicyManager dpm = mLockPatternUtils.getDevicePolicyManager(); |
| 428 | final int failedAttemptsBeforeWipe = |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 429 | dpm.getMaximumFailedPasswordsForWipe(null, userId); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 430 | |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 431 | final int remainingBeforeWipe = failedAttemptsBeforeWipe > 0 ? |
| 432 | (failedAttemptsBeforeWipe - failedAttempts) |
| 433 | : Integer.MAX_VALUE; // because DPM returns 0 if no restriction |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 434 | if (remainingBeforeWipe < LockPatternUtils.FAILED_ATTEMPTS_BEFORE_WIPE_GRACE) { |
Esteban Talavera | fe0f24c | 2014-08-06 16:20:56 +0100 | [diff] [blame] | 435 | // The user has installed a DevicePolicyManager that requests a user/profile to be wiped |
| 436 | // N attempts. Once we get below the grace period, we post this dialog every time as a |
| 437 | // clear warning until the deletion fires. |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 438 | // Check which profile has the strictest policy for failed password attempts |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 439 | final int expiringUser = dpm.getProfileWithMinimumFailedPasswordsForWipe(userId); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 440 | int userType = USER_TYPE_PRIMARY; |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 441 | if (expiringUser == userId) { |
Xiaohui Chen | cc791bc | 2015-08-26 14:54:34 -0700 | [diff] [blame] | 442 | // TODO: http://b/23522538 |
| 443 | if (expiringUser != UserHandle.USER_SYSTEM) { |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 444 | userType = USER_TYPE_SECONDARY_USER; |
| 445 | } |
| 446 | } else if (expiringUser != UserHandle.USER_NULL) { |
| 447 | userType = USER_TYPE_WORK_PROFILE; |
| 448 | } // If USER_NULL, which shouldn't happen, leave it as USER_TYPE_PRIMARY |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 449 | if (remainingBeforeWipe > 0) { |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 450 | showAlmostAtWipeDialog(failedAttempts, remainingBeforeWipe, userType); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 451 | } else { |
| 452 | // Too many attempts. The device will be wiped shortly. |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 453 | Slog.i(TAG, "Too many unlock attempts; user " + expiringUser + " will be wiped!"); |
| 454 | showWipeDialog(failedAttempts, userType); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 455 | } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 456 | } |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 457 | mLockPatternUtils.reportFailedPasswordAttempt(userId); |
Andres Morales | 2397427 | 2015-05-14 22:42:26 -0700 | [diff] [blame] | 458 | if (timeoutMs > 0) { |
Zachary Iqbal | 327323d | 2017-01-12 14:41:13 -0800 | [diff] [blame] | 459 | mLockPatternUtils.reportPasswordLockout(timeoutMs, userId); |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 460 | showTimeoutDialog(userId, timeoutMs); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 461 | } |
| 462 | } |
| 463 | |
| 464 | /** |
| 465 | * Shows the primary security screen for the user. This will be either the multi-selector |
| 466 | * or the user's security method. |
| 467 | * @param turningOff true if the device is being turned off |
| 468 | */ |
| 469 | void showPrimarySecurityScreen(boolean turningOff) { |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 470 | SecurityMode securityMode = mSecurityModel.getSecurityMode( |
| 471 | KeyguardUpdateMonitor.getCurrentUser()); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 472 | if (DEBUG) Log.v(TAG, "showPrimarySecurityScreen(turningOff=" + turningOff + ")"); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 473 | showSecurityScreen(securityMode); |
| 474 | } |
| 475 | |
| 476 | /** |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 477 | * Shows the next security screen if there is one. |
| 478 | * @param authenticated true if the user entered the correct authentication |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 479 | * @param targetUserId a user that needs to be the foreground user at the finish (if called) |
| 480 | * completion. |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 481 | * @return true if keyguard is done |
| 482 | */ |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 483 | boolean showNextSecurityScreenOrFinish(boolean authenticated, int targetUserId) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 484 | if (DEBUG) Log.d(TAG, "showNextSecurityScreenOrFinish(" + authenticated + ")"); |
| 485 | boolean finish = false; |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 486 | boolean strongAuth = false; |
Steven Wu | cfe398d | 2019-03-21 11:32:15 -0400 | [diff] [blame] | 487 | int eventSubtype = -1; |
| 488 | if (mUpdateMonitor.getUserHasTrust(targetUserId)) { |
Adrian Roos | 336be7f | 2014-05-19 17:11:18 +0200 | [diff] [blame] | 489 | finish = true; |
Steven Wu | cfe398d | 2019-03-21 11:32:15 -0400 | [diff] [blame] | 490 | eventSubtype = BOUNCER_DISMISS_EXTENDED_ACCESS; |
| 491 | } else if (mUpdateMonitor.getUserUnlockedWithBiometric(targetUserId)) { |
| 492 | finish = true; |
| 493 | eventSubtype = BOUNCER_DISMISS_BIOMETRIC; |
Adrian Roos | 336be7f | 2014-05-19 17:11:18 +0200 | [diff] [blame] | 494 | } else if (SecurityMode.None == mCurrentSecuritySelection) { |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 495 | SecurityMode securityMode = mSecurityModel.getSecurityMode(targetUserId); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 496 | if (SecurityMode.None == securityMode) { |
| 497 | finish = true; // no security required |
Steven Wu | cfe398d | 2019-03-21 11:32:15 -0400 | [diff] [blame] | 498 | eventSubtype = BOUNCER_DISMISS_NONE_SECURITY; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 499 | } else { |
| 500 | showSecurityScreen(securityMode); // switch to the alternate security view |
| 501 | } |
| 502 | } else if (authenticated) { |
| 503 | switch (mCurrentSecuritySelection) { |
| 504 | case Pattern: |
| 505 | case Password: |
| 506 | case PIN: |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 507 | strongAuth = true; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 508 | finish = true; |
Steven Wu | cfe398d | 2019-03-21 11:32:15 -0400 | [diff] [blame] | 509 | eventSubtype = BOUNCER_DISMISS_PASSWORD; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 510 | break; |
| 511 | |
| 512 | case SimPin: |
| 513 | case SimPuk: |
| 514 | // Shortcut for SIM PIN/PUK to go to directly to user's security screen or home |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 515 | SecurityMode securityMode = mSecurityModel.getSecurityMode(targetUserId); |
Jordan Liu | 15be64a | 2019-07-15 17:05:20 -0700 | [diff] [blame] | 516 | if (securityMode == SecurityMode.None && mLockPatternUtils.isLockScreenDisabled( |
Selim Cinek | 245273e | 2015-06-24 13:17:56 -0400 | [diff] [blame] | 517 | KeyguardUpdateMonitor.getCurrentUser())) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 518 | finish = true; |
Steven Wu | cfe398d | 2019-03-21 11:32:15 -0400 | [diff] [blame] | 519 | eventSubtype = BOUNCER_DISMISS_SIM; |
Jordan Liu | b4299d9 | 2018-09-26 12:49:11 -0700 | [diff] [blame] | 520 | } else { |
| 521 | showSecurityScreen(securityMode); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 522 | } |
| 523 | break; |
| 524 | |
| 525 | default: |
| 526 | Log.v(TAG, "Bad security screen " + mCurrentSecuritySelection + ", fail safe"); |
| 527 | showPrimarySecurityScreen(false); |
| 528 | break; |
| 529 | } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 530 | } |
Steven Wu | cfe398d | 2019-03-21 11:32:15 -0400 | [diff] [blame] | 531 | if (eventSubtype != -1) { |
| 532 | mMetricsLogger.write(new LogMaker(MetricsEvent.BOUNCER) |
| 533 | .setType(MetricsEvent.TYPE_DISMISS).setSubtype(eventSubtype)); |
| 534 | } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 535 | if (finish) { |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 536 | mSecurityCallback.finish(strongAuth, targetUserId); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 537 | } |
| 538 | return finish; |
| 539 | } |
| 540 | |
| 541 | /** |
| 542 | * Switches to the given security view unless it's already being shown, in which case |
| 543 | * this is a no-op. |
| 544 | * |
| 545 | * @param securityMode |
| 546 | */ |
| 547 | private void showSecurityScreen(SecurityMode securityMode) { |
| 548 | if (DEBUG) Log.d(TAG, "showSecurityScreen(" + securityMode + ")"); |
| 549 | |
| 550 | if (securityMode == mCurrentSecuritySelection) return; |
| 551 | |
| 552 | KeyguardSecurityView oldView = getSecurityView(mCurrentSecuritySelection); |
| 553 | KeyguardSecurityView newView = getSecurityView(securityMode); |
| 554 | |
| 555 | // Emulate Activity life cycle |
| 556 | if (oldView != null) { |
| 557 | oldView.onPause(); |
| 558 | oldView.setKeyguardCallback(mNullCallback); // ignore requests from old view |
| 559 | } |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 560 | if (securityMode != SecurityMode.None) { |
| 561 | newView.onResume(KeyguardSecurityView.VIEW_REVEALED); |
| 562 | newView.setKeyguardCallback(mCallback); |
| 563 | } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 564 | |
| 565 | // Find and show this child. |
| 566 | final int childCount = mSecurityViewFlipper.getChildCount(); |
| 567 | |
| 568 | final int securityViewIdForMode = getSecurityViewIdForMode(securityMode); |
| 569 | for (int i = 0; i < childCount; i++) { |
| 570 | if (mSecurityViewFlipper.getChildAt(i).getId() == securityViewIdForMode) { |
| 571 | mSecurityViewFlipper.setDisplayedChild(i); |
| 572 | break; |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | mCurrentSecuritySelection = securityMode; |
Lucas Dupin | 27321c4 | 2019-03-20 16:22:24 -0700 | [diff] [blame] | 577 | mCurrentSecurityView = newView; |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 578 | mSecurityCallback.onSecurityModeChanged(securityMode, |
| 579 | securityMode != SecurityMode.None && newView.needsInput()); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | private KeyguardSecurityViewFlipper getFlipper() { |
Chris Wren | 052999f | 2012-11-02 14:36:56 -0400 | [diff] [blame] | 583 | for (int i = 0; i < getChildCount(); i++) { |
| 584 | View child = getChildAt(i); |
| 585 | if (child instanceof KeyguardSecurityViewFlipper) { |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 586 | return (KeyguardSecurityViewFlipper) child; |
Chris Wren | 052999f | 2012-11-02 14:36:56 -0400 | [diff] [blame] | 587 | } |
| 588 | } |
| 589 | return null; |
| 590 | } |
| 591 | |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 592 | private KeyguardSecurityCallback mCallback = new KeyguardSecurityCallback() { |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 593 | public void userActivity() { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 594 | if (mSecurityCallback != null) { |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 595 | mSecurityCallback.userActivity(); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 596 | } |
| 597 | } |
| 598 | |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 599 | public void dismiss(boolean authenticated, int targetId) { |
| 600 | mSecurityCallback.dismiss(authenticated, targetId); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | public boolean isVerifyUnlockOnly() { |
| 604 | return mIsVerifyUnlockOnly; |
| 605 | } |
| 606 | |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 607 | public void reportUnlockAttempt(int userId, boolean success, int timeoutMs) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 608 | if (success) { |
Tej Singh | dd7bd35 | 2018-02-09 19:33:15 -0800 | [diff] [blame] | 609 | StatsLog.write(StatsLog.KEYGUARD_BOUNCER_PASSWORD_ENTERED, |
| 610 | StatsLog.KEYGUARD_BOUNCER_PASSWORD_ENTERED__RESULT__SUCCESS); |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 611 | mLockPatternUtils.reportSuccessfulPasswordAttempt(userId); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 612 | } else { |
Tej Singh | dd7bd35 | 2018-02-09 19:33:15 -0800 | [diff] [blame] | 613 | StatsLog.write(StatsLog.KEYGUARD_BOUNCER_PASSWORD_ENTERED, |
| 614 | StatsLog.KEYGUARD_BOUNCER_PASSWORD_ENTERED__RESULT__FAILURE); |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 615 | KeyguardSecurityContainer.this.reportFailedUnlockAttempt(userId, timeoutMs); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 616 | } |
Steven Wu | 6ef24b2 | 2019-03-11 17:14:11 -0400 | [diff] [blame] | 617 | mMetricsLogger.write(new LogMaker(MetricsEvent.BOUNCER) |
| 618 | .setType(success ? MetricsEvent.TYPE_SUCCESS : MetricsEvent.TYPE_FAILURE)); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 619 | } |
| 620 | |
Andrew Lee | 72b46d4 | 2015-01-30 13:23:21 -0800 | [diff] [blame] | 621 | public void reset() { |
| 622 | mSecurityCallback.reset(); |
| 623 | } |
Aarthi Balachander | 0a427ef | 2018-07-13 15:00:58 -0700 | [diff] [blame] | 624 | |
| 625 | public void onCancelClicked() { |
| 626 | mSecurityCallback.onCancelClicked(); |
| 627 | } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 628 | }; |
| 629 | |
| 630 | // The following is used to ignore callbacks from SecurityViews that are no longer current |
| 631 | // (e.g. face unlock). This avoids unwanted asynchronous events from messing with the |
| 632 | // state for the current security method. |
| 633 | private KeyguardSecurityCallback mNullCallback = new KeyguardSecurityCallback() { |
| 634 | @Override |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 635 | public void userActivity() { } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 636 | @Override |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 637 | public void reportUnlockAttempt(int userId, boolean success, int timeoutMs) { } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 638 | @Override |
| 639 | public boolean isVerifyUnlockOnly() { return false; } |
| 640 | @Override |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 641 | public void dismiss(boolean securityVerified, int targetUserId) { } |
Andrew Lee | 72b46d4 | 2015-01-30 13:23:21 -0800 | [diff] [blame] | 642 | @Override |
| 643 | public void reset() {} |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 644 | }; |
| 645 | |
| 646 | private int getSecurityViewIdForMode(SecurityMode securityMode) { |
| 647 | switch (securityMode) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 648 | case Pattern: return R.id.keyguard_pattern_view; |
| 649 | case PIN: return R.id.keyguard_pin_view; |
| 650 | case Password: return R.id.keyguard_password_view; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 651 | case SimPin: return R.id.keyguard_sim_pin_view; |
| 652 | case SimPuk: return R.id.keyguard_sim_puk_view; |
| 653 | } |
| 654 | return 0; |
| 655 | } |
| 656 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 657 | @VisibleForTesting |
| 658 | public int getLayoutIdFor(SecurityMode securityMode) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 659 | switch (securityMode) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 660 | case Pattern: return R.layout.keyguard_pattern_view; |
| 661 | case PIN: return R.layout.keyguard_pin_view; |
| 662 | case Password: return R.layout.keyguard_password_view; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 663 | case SimPin: return R.layout.keyguard_sim_pin_view; |
| 664 | case SimPuk: return R.layout.keyguard_sim_puk_view; |
| 665 | default: |
| 666 | return 0; |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | public SecurityMode getSecurityMode() { |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 671 | return mSecurityModel.getSecurityMode(KeyguardUpdateMonitor.getCurrentUser()); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 672 | } |
| 673 | |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 674 | public SecurityMode getCurrentSecurityMode() { |
| 675 | return mCurrentSecuritySelection; |
| 676 | } |
| 677 | |
Lucas Dupin | 27321c4 | 2019-03-20 16:22:24 -0700 | [diff] [blame] | 678 | public KeyguardSecurityView getCurrentSecurityView() { |
| 679 | return mCurrentSecurityView; |
| 680 | } |
| 681 | |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 682 | public void verifyUnlock() { |
| 683 | mIsVerifyUnlockOnly = true; |
| 684 | showSecurityScreen(getSecurityMode()); |
| 685 | } |
| 686 | |
| 687 | public SecurityMode getCurrentSecuritySelection() { |
| 688 | return mCurrentSecuritySelection; |
| 689 | } |
| 690 | |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 691 | public void dismiss(boolean authenticated, int targetUserId) { |
| 692 | mCallback.dismiss(authenticated, targetUserId); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | public boolean needsInput() { |
| 696 | return mSecurityViewFlipper.needsInput(); |
| 697 | } |
| 698 | |
| 699 | @Override |
| 700 | public void setKeyguardCallback(KeyguardSecurityCallback callback) { |
| 701 | mSecurityViewFlipper.setKeyguardCallback(callback); |
| 702 | } |
| 703 | |
| 704 | @Override |
| 705 | public void reset() { |
| 706 | mSecurityViewFlipper.reset(); |
| 707 | } |
| 708 | |
| 709 | @Override |
| 710 | public KeyguardSecurityCallback getCallback() { |
| 711 | return mSecurityViewFlipper.getCallback(); |
| 712 | } |
| 713 | |
| 714 | @Override |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 715 | public void showPromptReason(int reason) { |
| 716 | if (mCurrentSecuritySelection != SecurityMode.None) { |
Adrian Roos | 569edb8 | 2016-03-03 15:39:03 -0800 | [diff] [blame] | 717 | if (reason != PROMPT_REASON_NONE) { |
| 718 | Log.i(TAG, "Strong auth required, reason: " + reason); |
| 719 | } |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 720 | getSecurityView(mCurrentSecuritySelection).showPromptReason(reason); |
| 721 | } |
| 722 | } |
| 723 | |
Jason Chang | 1e4a4bd | 2018-05-22 17:30:19 +0800 | [diff] [blame] | 724 | public void showMessage(CharSequence message, ColorStateList colorState) { |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 725 | if (mCurrentSecuritySelection != SecurityMode.None) { |
Jason Chang | 1e4a4bd | 2018-05-22 17:30:19 +0800 | [diff] [blame] | 726 | getSecurityView(mCurrentSecuritySelection).showMessage(message, colorState); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 727 | } |
| 728 | } |
| 729 | |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 730 | @Override |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 731 | public void showUsabilityHint() { |
| 732 | mSecurityViewFlipper.showUsabilityHint(); |
| 733 | } |
| 734 | |
Jim Miller | 838906b | 2012-10-19 18:41:25 -0700 | [diff] [blame] | 735 | } |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 736 | |