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 | 51996bb | 2019-05-16 17:56:43 -0700 | [diff] [blame] | 240 | showMessage(null, null); |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | return true; |
| 244 | } |
| 245 | |
| 246 | private void startSpringAnimation(float startVelocity) { |
| 247 | mSpringAnimation |
| 248 | .setStartVelocity(startVelocity) |
| 249 | .animateToFinalPosition(0); |
| 250 | } |
| 251 | |
Jorim Jaggi | c14f829 | 2014-05-27 02:25:45 +0200 | [diff] [blame] | 252 | public void startAppearAnimation() { |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 253 | if (mCurrentSecuritySelection != SecurityMode.None) { |
| 254 | getSecurityView(mCurrentSecuritySelection).startAppearAnimation(); |
| 255 | } |
Jorim Jaggi | c14f829 | 2014-05-27 02:25:45 +0200 | [diff] [blame] | 256 | } |
| 257 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 258 | public boolean startDisappearAnimation(Runnable onFinishRunnable) { |
| 259 | if (mCurrentSecuritySelection != SecurityMode.None) { |
| 260 | return getSecurityView(mCurrentSecuritySelection).startDisappearAnimation( |
| 261 | onFinishRunnable); |
| 262 | } |
| 263 | return false; |
| 264 | } |
| 265 | |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 266 | /** |
| 267 | * Enables/disables swipe up to retry on the bouncer. |
| 268 | */ |
| 269 | private void updateBiometricRetry() { |
| 270 | SecurityMode securityMode = getSecurityMode(); |
Lucas Dupin | 206fe56 | 2019-05-31 14:36:42 -0700 | [diff] [blame] | 271 | mSwipeUpToRetry = mUnlockMethodCache.isUnlockingWithFacePossible() |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 272 | && securityMode != SecurityMode.SimPin |
| 273 | && securityMode != SecurityMode.SimPuk |
Lucas Dupin | fc8de93 | 2019-06-13 14:20:52 -0700 | [diff] [blame] | 274 | && securityMode != SecurityMode.None; |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Phil Weaver | 7d847b0 | 2018-02-13 16:02:35 -0800 | [diff] [blame] | 277 | public CharSequence getTitle() { |
| 278 | return mSecurityViewFlipper.getTitle(); |
Jorim Jaggi | c1dff8c | 2015-02-02 14:45:39 +0100 | [diff] [blame] | 279 | } |
| 280 | |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 281 | private KeyguardSecurityView getSecurityView(SecurityMode securityMode) { |
| 282 | final int securityViewIdForMode = getSecurityViewIdForMode(securityMode); |
| 283 | KeyguardSecurityView view = null; |
| 284 | final int children = mSecurityViewFlipper.getChildCount(); |
| 285 | for (int child = 0; child < children; child++) { |
| 286 | if (mSecurityViewFlipper.getChildAt(child).getId() == securityViewIdForMode) { |
| 287 | view = ((KeyguardSecurityView)mSecurityViewFlipper.getChildAt(child)); |
| 288 | break; |
| 289 | } |
| 290 | } |
| 291 | int layoutId = getLayoutIdFor(securityMode); |
| 292 | if (view == null && layoutId != 0) { |
| 293 | final LayoutInflater inflater = LayoutInflater.from(mContext); |
| 294 | if (DEBUG) Log.v(TAG, "inflating id = " + layoutId); |
Priyank Singh | 051353e | 2019-04-25 10:14:57 -0700 | [diff] [blame] | 295 | View v = mInjectionInflationController.injectable(inflater) |
| 296 | .inflate(layoutId, mSecurityViewFlipper, false); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 297 | mSecurityViewFlipper.addView(v); |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 298 | updateSecurityView(v); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 299 | view = (KeyguardSecurityView)v; |
Lucas Dupin | f7fd03d | 2018-06-26 15:58:51 -0700 | [diff] [blame] | 300 | view.reset(); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 301 | } |
| 302 | |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 303 | return view; |
| 304 | } |
| 305 | |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 306 | private void updateSecurityView(View view) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 307 | if (view instanceof KeyguardSecurityView) { |
| 308 | KeyguardSecurityView ksv = (KeyguardSecurityView) view; |
| 309 | ksv.setKeyguardCallback(mCallback); |
| 310 | ksv.setLockPatternUtils(mLockPatternUtils); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 311 | } else { |
| 312 | Log.w(TAG, "View " + view + " is not a KeyguardSecurityView"); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | protected void onFinishInflate() { |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 317 | mSecurityViewFlipper = findViewById(R.id.view_flipper); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 318 | mSecurityViewFlipper.setLockPatternUtils(mLockPatternUtils); |
| 319 | } |
| 320 | |
| 321 | public void setLockPatternUtils(LockPatternUtils utils) { |
| 322 | mLockPatternUtils = utils; |
| 323 | mSecurityModel.setLockPatternUtils(utils); |
| 324 | mSecurityViewFlipper.setLockPatternUtils(mLockPatternUtils); |
| 325 | } |
| 326 | |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 327 | @Override |
Lucas Dupin | 3ac28ac | 2019-05-13 16:33:32 -0700 | [diff] [blame] | 328 | protected boolean fitSystemWindows(Rect insets) { |
| 329 | // Consume bottom insets because we're setting the padding locally (for IME and navbar.) |
| 330 | setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), insets.bottom); |
| 331 | insets.bottom = 0; |
| 332 | return false; |
Lucas Dupin | 7156bc7 | 2019-05-03 19:37:39 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 335 | private void showDialog(String title, String message) { |
Lucas Dupin | 7f72982 | 2017-12-13 15:27:10 -0800 | [diff] [blame] | 336 | if (mAlertDialog != null) { |
| 337 | mAlertDialog.dismiss(); |
| 338 | } |
| 339 | |
| 340 | mAlertDialog = new AlertDialog.Builder(mContext) |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 341 | .setTitle(title) |
| 342 | .setMessage(message) |
Edward Savage-Jones | b08a146 | 2016-10-05 10:29:02 +0200 | [diff] [blame] | 343 | .setCancelable(false) |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 344 | .setNeutralButton(R.string.ok, null) |
| 345 | .create(); |
| 346 | if (!(mContext instanceof Activity)) { |
Lucas Dupin | 7f72982 | 2017-12-13 15:27:10 -0800 | [diff] [blame] | 347 | mAlertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 348 | } |
Lucas Dupin | 7f72982 | 2017-12-13 15:27:10 -0800 | [diff] [blame] | 349 | mAlertDialog.show(); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 350 | } |
| 351 | |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 352 | private void showTimeoutDialog(int userId, int timeoutMs) { |
Andres Morales | 2397427 | 2015-05-14 22:42:26 -0700 | [diff] [blame] | 353 | int timeoutInSeconds = (int) timeoutMs / 1000; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 354 | int messageId = 0; |
| 355 | |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 356 | switch (mSecurityModel.getSecurityMode(userId)) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 357 | case Pattern: |
| 358 | messageId = R.string.kg_too_many_failed_pattern_attempts_dialog_message; |
| 359 | break; |
| 360 | case PIN: |
| 361 | messageId = R.string.kg_too_many_failed_pin_attempts_dialog_message; |
| 362 | break; |
| 363 | case Password: |
| 364 | messageId = R.string.kg_too_many_failed_password_attempts_dialog_message; |
| 365 | break; |
| 366 | // These don't have timeout dialogs. |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 367 | case Invalid: |
| 368 | case None: |
| 369 | case SimPin: |
| 370 | case SimPuk: |
| 371 | break; |
| 372 | } |
| 373 | |
| 374 | if (messageId != 0) { |
| 375 | final String message = mContext.getString(messageId, |
Pavel Grafov | b90dc43 | 2018-08-15 20:02:58 +0100 | [diff] [blame] | 376 | mLockPatternUtils.getCurrentFailedPasswordAttempts(userId), |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 377 | timeoutInSeconds); |
| 378 | showDialog(null, message); |
| 379 | } |
| 380 | } |
| 381 | |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 382 | private void showAlmostAtWipeDialog(int attempts, int remaining, int userType) { |
| 383 | String message = null; |
| 384 | switch (userType) { |
| 385 | case USER_TYPE_PRIMARY: |
| 386 | message = mContext.getString(R.string.kg_failed_attempts_almost_at_wipe, |
| 387 | attempts, remaining); |
| 388 | break; |
| 389 | case USER_TYPE_SECONDARY_USER: |
| 390 | message = mContext.getString(R.string.kg_failed_attempts_almost_at_erase_user, |
| 391 | attempts, remaining); |
| 392 | break; |
| 393 | case USER_TYPE_WORK_PROFILE: |
| 394 | message = mContext.getString(R.string.kg_failed_attempts_almost_at_erase_profile, |
| 395 | attempts, remaining); |
| 396 | break; |
| 397 | } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 398 | showDialog(null, message); |
| 399 | } |
| 400 | |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 401 | private void showWipeDialog(int attempts, int userType) { |
| 402 | String message = null; |
| 403 | switch (userType) { |
| 404 | case USER_TYPE_PRIMARY: |
| 405 | message = mContext.getString(R.string.kg_failed_attempts_now_wiping, |
| 406 | attempts); |
| 407 | break; |
| 408 | case USER_TYPE_SECONDARY_USER: |
| 409 | message = mContext.getString(R.string.kg_failed_attempts_now_erasing_user, |
| 410 | attempts); |
| 411 | break; |
| 412 | case USER_TYPE_WORK_PROFILE: |
| 413 | message = mContext.getString(R.string.kg_failed_attempts_now_erasing_profile, |
| 414 | attempts); |
| 415 | break; |
| 416 | } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 417 | showDialog(null, message); |
| 418 | } |
| 419 | |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 420 | private void reportFailedUnlockAttempt(int userId, int timeoutMs) { |
Pavel Grafov | b90dc43 | 2018-08-15 20:02:58 +0100 | [diff] [blame] | 421 | // +1 for this time |
| 422 | final int failedAttempts = mLockPatternUtils.getCurrentFailedPasswordAttempts(userId) + 1; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 423 | |
| 424 | if (DEBUG) Log.d(TAG, "reportFailedPatternAttempt: #" + failedAttempts); |
| 425 | |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 426 | final DevicePolicyManager dpm = mLockPatternUtils.getDevicePolicyManager(); |
| 427 | final int failedAttemptsBeforeWipe = |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 428 | dpm.getMaximumFailedPasswordsForWipe(null, userId); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 429 | |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 430 | final int remainingBeforeWipe = failedAttemptsBeforeWipe > 0 ? |
| 431 | (failedAttemptsBeforeWipe - failedAttempts) |
| 432 | : Integer.MAX_VALUE; // because DPM returns 0 if no restriction |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 433 | if (remainingBeforeWipe < LockPatternUtils.FAILED_ATTEMPTS_BEFORE_WIPE_GRACE) { |
Esteban Talavera | fe0f24c | 2014-08-06 16:20:56 +0100 | [diff] [blame] | 434 | // The user has installed a DevicePolicyManager that requests a user/profile to be wiped |
| 435 | // N attempts. Once we get below the grace period, we post this dialog every time as a |
| 436 | // clear warning until the deletion fires. |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 437 | // Check which profile has the strictest policy for failed password attempts |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 438 | final int expiringUser = dpm.getProfileWithMinimumFailedPasswordsForWipe(userId); |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 439 | int userType = USER_TYPE_PRIMARY; |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 440 | if (expiringUser == userId) { |
Xiaohui Chen | cc791bc | 2015-08-26 14:54:34 -0700 | [diff] [blame] | 441 | // TODO: http://b/23522538 |
| 442 | if (expiringUser != UserHandle.USER_SYSTEM) { |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 443 | userType = USER_TYPE_SECONDARY_USER; |
| 444 | } |
| 445 | } else if (expiringUser != UserHandle.USER_NULL) { |
| 446 | userType = USER_TYPE_WORK_PROFILE; |
| 447 | } // 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] | 448 | if (remainingBeforeWipe > 0) { |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 449 | showAlmostAtWipeDialog(failedAttempts, remainingBeforeWipe, userType); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 450 | } else { |
| 451 | // Too many attempts. The device will be wiped shortly. |
Amith Yamasani | 3a3d212 | 2014-10-29 11:41:31 -0700 | [diff] [blame] | 452 | Slog.i(TAG, "Too many unlock attempts; user " + expiringUser + " will be wiped!"); |
| 453 | showWipeDialog(failedAttempts, userType); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 454 | } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 455 | } |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 456 | mLockPatternUtils.reportFailedPasswordAttempt(userId); |
Andres Morales | 2397427 | 2015-05-14 22:42:26 -0700 | [diff] [blame] | 457 | if (timeoutMs > 0) { |
Zachary Iqbal | 327323d | 2017-01-12 14:41:13 -0800 | [diff] [blame] | 458 | mLockPatternUtils.reportPasswordLockout(timeoutMs, userId); |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 459 | showTimeoutDialog(userId, timeoutMs); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * Shows the primary security screen for the user. This will be either the multi-selector |
| 465 | * or the user's security method. |
| 466 | * @param turningOff true if the device is being turned off |
| 467 | */ |
| 468 | void showPrimarySecurityScreen(boolean turningOff) { |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 469 | SecurityMode securityMode = mSecurityModel.getSecurityMode( |
| 470 | KeyguardUpdateMonitor.getCurrentUser()); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 471 | if (DEBUG) Log.v(TAG, "showPrimarySecurityScreen(turningOff=" + turningOff + ")"); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 472 | showSecurityScreen(securityMode); |
| 473 | } |
| 474 | |
| 475 | /** |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 476 | * Shows the next security screen if there is one. |
| 477 | * @param authenticated true if the user entered the correct authentication |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 478 | * @param targetUserId a user that needs to be the foreground user at the finish (if called) |
| 479 | * completion. |
Jim Miller | ba7d94b | 2014-02-05 17:30:50 -0800 | [diff] [blame] | 480 | * @return true if keyguard is done |
| 481 | */ |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 482 | boolean showNextSecurityScreenOrFinish(boolean authenticated, int targetUserId) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 483 | if (DEBUG) Log.d(TAG, "showNextSecurityScreenOrFinish(" + authenticated + ")"); |
| 484 | boolean finish = false; |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 485 | boolean strongAuth = false; |
Steven Wu | cfe398d | 2019-03-21 11:32:15 -0400 | [diff] [blame] | 486 | int eventSubtype = -1; |
| 487 | if (mUpdateMonitor.getUserHasTrust(targetUserId)) { |
Adrian Roos | 336be7f | 2014-05-19 17:11:18 +0200 | [diff] [blame] | 488 | finish = true; |
Steven Wu | cfe398d | 2019-03-21 11:32:15 -0400 | [diff] [blame] | 489 | eventSubtype = BOUNCER_DISMISS_EXTENDED_ACCESS; |
| 490 | } else if (mUpdateMonitor.getUserUnlockedWithBiometric(targetUserId)) { |
| 491 | finish = true; |
| 492 | eventSubtype = BOUNCER_DISMISS_BIOMETRIC; |
Adrian Roos | 336be7f | 2014-05-19 17:11:18 +0200 | [diff] [blame] | 493 | } else if (SecurityMode.None == mCurrentSecuritySelection) { |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 494 | SecurityMode securityMode = mSecurityModel.getSecurityMode(targetUserId); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 495 | if (SecurityMode.None == securityMode) { |
| 496 | finish = true; // no security required |
Steven Wu | cfe398d | 2019-03-21 11:32:15 -0400 | [diff] [blame] | 497 | eventSubtype = BOUNCER_DISMISS_NONE_SECURITY; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 498 | } else { |
| 499 | showSecurityScreen(securityMode); // switch to the alternate security view |
| 500 | } |
| 501 | } else if (authenticated) { |
| 502 | switch (mCurrentSecuritySelection) { |
| 503 | case Pattern: |
| 504 | case Password: |
| 505 | case PIN: |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 506 | strongAuth = true; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 507 | finish = true; |
Steven Wu | cfe398d | 2019-03-21 11:32:15 -0400 | [diff] [blame] | 508 | eventSubtype = BOUNCER_DISMISS_PASSWORD; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 509 | break; |
| 510 | |
| 511 | case SimPin: |
| 512 | case SimPuk: |
| 513 | // 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] | 514 | SecurityMode securityMode = mSecurityModel.getSecurityMode(targetUserId); |
Jordan Liu | b4299d9 | 2018-09-26 12:49:11 -0700 | [diff] [blame] | 515 | if (securityMode == SecurityMode.None || mLockPatternUtils.isLockScreenDisabled( |
Selim Cinek | 245273e | 2015-06-24 13:17:56 -0400 | [diff] [blame] | 516 | KeyguardUpdateMonitor.getCurrentUser())) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 517 | finish = true; |
Steven Wu | cfe398d | 2019-03-21 11:32:15 -0400 | [diff] [blame] | 518 | eventSubtype = BOUNCER_DISMISS_SIM; |
Jordan Liu | b4299d9 | 2018-09-26 12:49:11 -0700 | [diff] [blame] | 519 | } else { |
| 520 | showSecurityScreen(securityMode); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 521 | } |
| 522 | break; |
| 523 | |
| 524 | default: |
| 525 | Log.v(TAG, "Bad security screen " + mCurrentSecuritySelection + ", fail safe"); |
| 526 | showPrimarySecurityScreen(false); |
| 527 | break; |
| 528 | } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 529 | } |
Steven Wu | cfe398d | 2019-03-21 11:32:15 -0400 | [diff] [blame] | 530 | if (eventSubtype != -1) { |
| 531 | mMetricsLogger.write(new LogMaker(MetricsEvent.BOUNCER) |
| 532 | .setType(MetricsEvent.TYPE_DISMISS).setSubtype(eventSubtype)); |
| 533 | } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 534 | if (finish) { |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 535 | mSecurityCallback.finish(strongAuth, targetUserId); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 536 | } |
| 537 | return finish; |
| 538 | } |
| 539 | |
| 540 | /** |
| 541 | * Switches to the given security view unless it's already being shown, in which case |
| 542 | * this is a no-op. |
| 543 | * |
| 544 | * @param securityMode |
| 545 | */ |
| 546 | private void showSecurityScreen(SecurityMode securityMode) { |
| 547 | if (DEBUG) Log.d(TAG, "showSecurityScreen(" + securityMode + ")"); |
| 548 | |
| 549 | if (securityMode == mCurrentSecuritySelection) return; |
| 550 | |
| 551 | KeyguardSecurityView oldView = getSecurityView(mCurrentSecuritySelection); |
| 552 | KeyguardSecurityView newView = getSecurityView(securityMode); |
| 553 | |
| 554 | // Emulate Activity life cycle |
| 555 | if (oldView != null) { |
| 556 | oldView.onPause(); |
| 557 | oldView.setKeyguardCallback(mNullCallback); // ignore requests from old view |
| 558 | } |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 559 | if (securityMode != SecurityMode.None) { |
| 560 | newView.onResume(KeyguardSecurityView.VIEW_REVEALED); |
| 561 | newView.setKeyguardCallback(mCallback); |
| 562 | } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 563 | |
| 564 | // Find and show this child. |
| 565 | final int childCount = mSecurityViewFlipper.getChildCount(); |
| 566 | |
| 567 | final int securityViewIdForMode = getSecurityViewIdForMode(securityMode); |
| 568 | for (int i = 0; i < childCount; i++) { |
| 569 | if (mSecurityViewFlipper.getChildAt(i).getId() == securityViewIdForMode) { |
| 570 | mSecurityViewFlipper.setDisplayedChild(i); |
| 571 | break; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | mCurrentSecuritySelection = securityMode; |
Lucas Dupin | 27321c4 | 2019-03-20 16:22:24 -0700 | [diff] [blame] | 576 | mCurrentSecurityView = newView; |
Jorim Jaggi | f479792 | 2014-08-04 22:49:41 +0200 | [diff] [blame] | 577 | mSecurityCallback.onSecurityModeChanged(securityMode, |
| 578 | securityMode != SecurityMode.None && newView.needsInput()); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | private KeyguardSecurityViewFlipper getFlipper() { |
Chris Wren | 052999f | 2012-11-02 14:36:56 -0400 | [diff] [blame] | 582 | for (int i = 0; i < getChildCount(); i++) { |
| 583 | View child = getChildAt(i); |
| 584 | if (child instanceof KeyguardSecurityViewFlipper) { |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 585 | return (KeyguardSecurityViewFlipper) child; |
Chris Wren | 052999f | 2012-11-02 14:36:56 -0400 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | return null; |
| 589 | } |
| 590 | |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 591 | private KeyguardSecurityCallback mCallback = new KeyguardSecurityCallback() { |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 592 | public void userActivity() { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 593 | if (mSecurityCallback != null) { |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 594 | mSecurityCallback.userActivity(); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 595 | } |
| 596 | } |
| 597 | |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 598 | public void dismiss(boolean authenticated, int targetId) { |
| 599 | mSecurityCallback.dismiss(authenticated, targetId); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | public boolean isVerifyUnlockOnly() { |
| 603 | return mIsVerifyUnlockOnly; |
| 604 | } |
| 605 | |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 606 | public void reportUnlockAttempt(int userId, boolean success, int timeoutMs) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 607 | if (success) { |
Tej Singh | dd7bd35 | 2018-02-09 19:33:15 -0800 | [diff] [blame] | 608 | StatsLog.write(StatsLog.KEYGUARD_BOUNCER_PASSWORD_ENTERED, |
| 609 | StatsLog.KEYGUARD_BOUNCER_PASSWORD_ENTERED__RESULT__SUCCESS); |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 610 | mLockPatternUtils.reportSuccessfulPasswordAttempt(userId); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 611 | } else { |
Tej Singh | dd7bd35 | 2018-02-09 19:33:15 -0800 | [diff] [blame] | 612 | StatsLog.write(StatsLog.KEYGUARD_BOUNCER_PASSWORD_ENTERED, |
| 613 | StatsLog.KEYGUARD_BOUNCER_PASSWORD_ENTERED__RESULT__FAILURE); |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 614 | KeyguardSecurityContainer.this.reportFailedUnlockAttempt(userId, timeoutMs); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 615 | } |
Steven Wu | 6ef24b2 | 2019-03-11 17:14:11 -0400 | [diff] [blame] | 616 | mMetricsLogger.write(new LogMaker(MetricsEvent.BOUNCER) |
| 617 | .setType(success ? MetricsEvent.TYPE_SUCCESS : MetricsEvent.TYPE_FAILURE)); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 618 | } |
| 619 | |
Andrew Lee | 72b46d4 | 2015-01-30 13:23:21 -0800 | [diff] [blame] | 620 | public void reset() { |
| 621 | mSecurityCallback.reset(); |
| 622 | } |
Aarthi Balachander | 0a427ef | 2018-07-13 15:00:58 -0700 | [diff] [blame] | 623 | |
| 624 | public void onCancelClicked() { |
| 625 | mSecurityCallback.onCancelClicked(); |
| 626 | } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 627 | }; |
| 628 | |
| 629 | // The following is used to ignore callbacks from SecurityViews that are no longer current |
| 630 | // (e.g. face unlock). This avoids unwanted asynchronous events from messing with the |
| 631 | // state for the current security method. |
| 632 | private KeyguardSecurityCallback mNullCallback = new KeyguardSecurityCallback() { |
| 633 | @Override |
Jorim Jaggi | b690f0d | 2014-07-03 23:25:44 +0200 | [diff] [blame] | 634 | public void userActivity() { } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 635 | @Override |
Xiyuan Xia | ce64cea | 2016-01-06 08:51:16 -0800 | [diff] [blame] | 636 | public void reportUnlockAttempt(int userId, boolean success, int timeoutMs) { } |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 637 | @Override |
| 638 | public boolean isVerifyUnlockOnly() { return false; } |
| 639 | @Override |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 640 | public void dismiss(boolean securityVerified, int targetUserId) { } |
Andrew Lee | 72b46d4 | 2015-01-30 13:23:21 -0800 | [diff] [blame] | 641 | @Override |
| 642 | public void reset() {} |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 643 | }; |
| 644 | |
| 645 | private int getSecurityViewIdForMode(SecurityMode securityMode) { |
| 646 | switch (securityMode) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 647 | case Pattern: return R.id.keyguard_pattern_view; |
| 648 | case PIN: return R.id.keyguard_pin_view; |
| 649 | case Password: return R.id.keyguard_password_view; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 650 | case SimPin: return R.id.keyguard_sim_pin_view; |
| 651 | case SimPuk: return R.id.keyguard_sim_puk_view; |
| 652 | } |
| 653 | return 0; |
| 654 | } |
| 655 | |
Lucas Dupin | e17ce52 | 2017-07-17 15:45:06 -0700 | [diff] [blame] | 656 | @VisibleForTesting |
| 657 | public int getLayoutIdFor(SecurityMode securityMode) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 658 | switch (securityMode) { |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 659 | case Pattern: return R.layout.keyguard_pattern_view; |
| 660 | case PIN: return R.layout.keyguard_pin_view; |
| 661 | case Password: return R.layout.keyguard_password_view; |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 662 | case SimPin: return R.layout.keyguard_sim_pin_view; |
| 663 | case SimPuk: return R.layout.keyguard_sim_puk_view; |
| 664 | default: |
| 665 | return 0; |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | public SecurityMode getSecurityMode() { |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 670 | return mSecurityModel.getSecurityMode(KeyguardUpdateMonitor.getCurrentUser()); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 671 | } |
| 672 | |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 673 | public SecurityMode getCurrentSecurityMode() { |
| 674 | return mCurrentSecuritySelection; |
| 675 | } |
| 676 | |
Lucas Dupin | 27321c4 | 2019-03-20 16:22:24 -0700 | [diff] [blame] | 677 | public KeyguardSecurityView getCurrentSecurityView() { |
| 678 | return mCurrentSecurityView; |
| 679 | } |
| 680 | |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 681 | public void verifyUnlock() { |
| 682 | mIsVerifyUnlockOnly = true; |
| 683 | showSecurityScreen(getSecurityMode()); |
| 684 | } |
| 685 | |
| 686 | public SecurityMode getCurrentSecuritySelection() { |
| 687 | return mCurrentSecuritySelection; |
| 688 | } |
| 689 | |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 690 | public void dismiss(boolean authenticated, int targetUserId) { |
| 691 | mCallback.dismiss(authenticated, targetUserId); |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | public boolean needsInput() { |
| 695 | return mSecurityViewFlipper.needsInput(); |
| 696 | } |
| 697 | |
| 698 | @Override |
| 699 | public void setKeyguardCallback(KeyguardSecurityCallback callback) { |
| 700 | mSecurityViewFlipper.setKeyguardCallback(callback); |
| 701 | } |
| 702 | |
| 703 | @Override |
| 704 | public void reset() { |
| 705 | mSecurityViewFlipper.reset(); |
| 706 | } |
| 707 | |
| 708 | @Override |
| 709 | public KeyguardSecurityCallback getCallback() { |
| 710 | return mSecurityViewFlipper.getCallback(); |
| 711 | } |
| 712 | |
| 713 | @Override |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 714 | public void showPromptReason(int reason) { |
| 715 | if (mCurrentSecuritySelection != SecurityMode.None) { |
Adrian Roos | 569edb8 | 2016-03-03 15:39:03 -0800 | [diff] [blame] | 716 | if (reason != PROMPT_REASON_NONE) { |
| 717 | Log.i(TAG, "Strong auth required, reason: " + reason); |
| 718 | } |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 719 | getSecurityView(mCurrentSecuritySelection).showPromptReason(reason); |
| 720 | } |
| 721 | } |
| 722 | |
Jason Chang | 1e4a4bd | 2018-05-22 17:30:19 +0800 | [diff] [blame] | 723 | public void showMessage(CharSequence message, ColorStateList colorState) { |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 724 | if (mCurrentSecuritySelection != SecurityMode.None) { |
Jason Chang | 1e4a4bd | 2018-05-22 17:30:19 +0800 | [diff] [blame] | 725 | getSecurityView(mCurrentSecuritySelection).showMessage(message, colorState); |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 729 | @Override |
Jim Miller | 7751ff6 | 2014-01-14 18:57:03 -0800 | [diff] [blame] | 730 | public void showUsabilityHint() { |
| 731 | mSecurityViewFlipper.showUsabilityHint(); |
| 732 | } |
| 733 | |
Jim Miller | 838906b | 2012-10-19 18:41:25 -0700 | [diff] [blame] | 734 | } |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 735 | |