Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [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 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
Lucas Dupin | 0df9b7a | 2018-03-15 17:53:17 -0700 | [diff] [blame] | 19 | import static com.android.keyguard.KeyguardHostView.OnDismissAction; |
| 20 | import static com.android.keyguard.KeyguardSecurityModel.SecurityMode; |
| 21 | |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 22 | import android.content.Context; |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 23 | import android.os.Handler; |
Toni Barzic | 657f885 | 2016-02-04 15:14:49 -0800 | [diff] [blame] | 24 | import android.os.UserHandle; |
Toni Barzic | b799d3f | 2016-02-17 15:09:10 -0800 | [diff] [blame] | 25 | import android.os.UserManager; |
Lucas Dupin | 0df9b7a | 2018-03-15 17:53:17 -0700 | [diff] [blame] | 26 | import android.util.Log; |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 27 | import android.util.MathUtils; |
Toni Barzic | 657f885 | 2016-02-04 15:14:49 -0800 | [diff] [blame] | 28 | import android.util.Slog; |
Tej Singh | dd7bd35 | 2018-02-09 19:33:15 -0800 | [diff] [blame] | 29 | import android.util.StatsLog; |
Jorim Jaggi | df99351 | 2014-05-13 23:06:35 +0200 | [diff] [blame] | 30 | import android.view.KeyEvent; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 31 | import android.view.LayoutInflater; |
| 32 | import android.view.View; |
| 33 | import android.view.ViewGroup; |
Adrian Roos | edfa96f | 2016-01-29 12:46:35 -0800 | [diff] [blame] | 34 | import android.view.ViewTreeObserver; |
Lucas Dupin | 6865b71 | 2017-09-11 12:28:03 -0700 | [diff] [blame] | 35 | import android.view.WindowInsets; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 36 | |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 37 | import com.android.internal.widget.LockPatternUtils; |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 38 | import com.android.keyguard.KeyguardHostView; |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 39 | import com.android.keyguard.KeyguardSecurityView; |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 40 | import com.android.keyguard.KeyguardUpdateMonitor; |
| 41 | import com.android.keyguard.KeyguardUpdateMonitorCallback; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 42 | import com.android.keyguard.R; |
| 43 | import com.android.keyguard.ViewMediatorCallback; |
Jorim Jaggi | 86b273f | 2015-07-14 18:08:43 -0700 | [diff] [blame] | 44 | import com.android.systemui.DejankUtils; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 45 | import com.android.systemui.classifier.FalsingManager; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 46 | import com.android.systemui.keyguard.DismissCallbackRegistry; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 47 | |
Lucas Dupin | 15a6b6c | 2018-04-16 14:50:20 +0800 | [diff] [blame] | 48 | import java.io.PrintWriter; |
| 49 | |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 50 | /** |
| 51 | * A class which manages the bouncer on the lockscreen. |
| 52 | */ |
| 53 | public class KeyguardBouncer { |
| 54 | |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 55 | private static final String TAG = "KeyguardBouncer"; |
| 56 | static final float ALPHA_EXPANSION_THRESHOLD = 0.95f; |
Toni Barzic | 657f885 | 2016-02-04 15:14:49 -0800 | [diff] [blame] | 57 | |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 58 | protected final Context mContext; |
| 59 | protected final ViewMediatorCallback mCallback; |
| 60 | protected final LockPatternUtils mLockPatternUtils; |
| 61 | protected final ViewGroup mContainer; |
| 62 | private final FalsingManager mFalsingManager; |
| 63 | private final DismissCallbackRegistry mDismissCallbackRegistry; |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 64 | private final Handler mHandler; |
Lucas Dupin | 15a6b6c | 2018-04-16 14:50:20 +0800 | [diff] [blame] | 65 | private final BouncerExpansionCallback mExpansionCallback; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 66 | private final KeyguardUpdateMonitorCallback mUpdateMonitorCallback = |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 67 | new KeyguardUpdateMonitorCallback() { |
| 68 | @Override |
Adrian Roos | 1de8bcb | 2015-08-19 16:52:52 -0700 | [diff] [blame] | 69 | public void onStrongAuthStateChanged(int userId) { |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 70 | mBouncerPromptReason = mCallback.getBouncerPromptReason(); |
| 71 | } |
| 72 | }; |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 73 | private final Runnable mRemoveViewRunnable = this::removeView; |
Lucas Dupin | 3d565fa | 2018-03-20 15:40:14 -0700 | [diff] [blame] | 74 | |
Selim Cinek | cb3d45a | 2017-09-08 18:00:18 -0700 | [diff] [blame] | 75 | private int mStatusBarHeight; |
Lucas Dupin | 3d565fa | 2018-03-20 15:40:14 -0700 | [diff] [blame] | 76 | private float mExpansion; |
| 77 | protected KeyguardHostView mKeyguardView; |
| 78 | protected ViewGroup mRoot; |
| 79 | private boolean mShowingSoon; |
| 80 | private int mBouncerPromptReason; |
Lucas Dupin | 28dc9d7 | 2018-03-21 15:59:15 -0700 | [diff] [blame] | 81 | private boolean mIsAnimatingAway; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 82 | |
| 83 | public KeyguardBouncer(Context context, ViewMediatorCallback callback, |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 84 | LockPatternUtils lockPatternUtils, ViewGroup container, |
Lucas Dupin | 15a6b6c | 2018-04-16 14:50:20 +0800 | [diff] [blame] | 85 | DismissCallbackRegistry dismissCallbackRegistry, FalsingManager falsingManager, |
| 86 | BouncerExpansionCallback expansionCallback) { |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 87 | mContext = context; |
| 88 | mCallback = callback; |
| 89 | mLockPatternUtils = lockPatternUtils; |
| 90 | mContainer = container; |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 91 | KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback); |
Lucas Dupin | 0df9b7a | 2018-03-15 17:53:17 -0700 | [diff] [blame] | 92 | mFalsingManager = falsingManager; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 93 | mDismissCallbackRegistry = dismissCallbackRegistry; |
Lucas Dupin | 15a6b6c | 2018-04-16 14:50:20 +0800 | [diff] [blame] | 94 | mExpansionCallback = expansionCallback; |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 95 | mHandler = new Handler(); |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 96 | } |
| 97 | |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 98 | public void show(boolean resetSecuritySelection) { |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 99 | show(resetSecuritySelection, true /* notifyFalsing */); |
| 100 | } |
| 101 | |
Lucas Dupin | 0df9b7a | 2018-03-15 17:53:17 -0700 | [diff] [blame] | 102 | /** |
| 103 | * Shows the bouncer. |
| 104 | * |
| 105 | * @param resetSecuritySelection Cleans keyguard view |
| 106 | * @param animated true when the bouncer show show animated, false when the user will be |
| 107 | * dragging it and animation should be deferred. |
| 108 | */ |
| 109 | public void show(boolean resetSecuritySelection, boolean animated) { |
Vadim Tryshev | ec01843 | 2016-02-10 14:11:03 -0800 | [diff] [blame] | 110 | final int keyguardUserId = KeyguardUpdateMonitor.getCurrentUser(); |
| 111 | if (keyguardUserId == UserHandle.USER_SYSTEM && UserManager.isSplitSystemUser()) { |
| 112 | // In split system user mode, we never unlock system user. |
| 113 | return; |
| 114 | } |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 115 | ensureView(); |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 116 | |
| 117 | // On the keyguard, we want to show the bouncer when the user drags up, but it's |
| 118 | // not correct to end the falsing session. We still need to verify if those touches |
| 119 | // are valid. |
| 120 | // Later, at the end of the animation, when the bouncer is at the top of the screen, |
| 121 | // onFullyShown() will be called and FalsingManager will stop recording touches. |
Lucas Dupin | 0df9b7a | 2018-03-15 17:53:17 -0700 | [diff] [blame] | 122 | if (animated) { |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 123 | mFalsingManager.onBouncerShown(); |
Lucas Dupin | 0df9b7a | 2018-03-15 17:53:17 -0700 | [diff] [blame] | 124 | setExpansion(0); |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 125 | } |
Lucas Dupin | 0df9b7a | 2018-03-15 17:53:17 -0700 | [diff] [blame] | 126 | |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 127 | if (resetSecuritySelection) { |
| 128 | // showPrimarySecurityScreen() updates the current security method. This is needed in |
| 129 | // case we are already showing and the current security method changed. |
| 130 | mKeyguardView.showPrimarySecurityScreen(); |
| 131 | } |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 132 | if (mRoot.getVisibility() == View.VISIBLE || mShowingSoon) { |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 133 | return; |
| 134 | } |
Jorim Jaggi | 0bed7f2 | 2014-04-03 16:12:54 +0200 | [diff] [blame] | 135 | |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 136 | final int activeUserId = KeyguardUpdateMonitor.getCurrentUser(); |
Xiaohui Chen | d743cef | 2016-10-03 09:55:53 -0700 | [diff] [blame] | 137 | final boolean isSystemUser = |
| 138 | UserManager.isSplitSystemUser() && activeUserId == UserHandle.USER_SYSTEM; |
| 139 | final boolean allowDismissKeyguard = !isSystemUser && activeUserId == keyguardUserId; |
| 140 | |
Toni Barzic | 657f885 | 2016-02-04 15:14:49 -0800 | [diff] [blame] | 141 | // If allowed, try to dismiss the Keyguard. If no security auth (password/pin/pattern) is |
| 142 | // set, this will dismiss the whole Keyguard. Otherwise, show the bouncer. |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 143 | if (allowDismissKeyguard && mKeyguardView.dismiss(activeUserId)) { |
Toni Barzic | 657f885 | 2016-02-04 15:14:49 -0800 | [diff] [blame] | 144 | return; |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 145 | } |
Toni Barzic | 657f885 | 2016-02-04 15:14:49 -0800 | [diff] [blame] | 146 | |
| 147 | // This condition may indicate an error on Android, so log it. |
| 148 | if (!allowDismissKeyguard) { |
| 149 | Slog.w(TAG, "User can't dismiss keyguard: " + activeUserId + " != " + keyguardUserId); |
| 150 | } |
| 151 | |
| 152 | mShowingSoon = true; |
| 153 | |
| 154 | // Split up the work over multiple frames. |
| 155 | DejankUtils.postAfterTraversal(mShowRunnable); |
Matthew Ng | 66f0b70 | 2017-12-08 12:58:42 -0800 | [diff] [blame] | 156 | |
| 157 | mCallback.onBouncerVisiblityChanged(true /* shown */); |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 158 | } |
| 159 | |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 160 | /** |
| 161 | * This method must be called at the end of the bouncer animation when |
| 162 | * the translation is performed manually by the user, otherwise FalsingManager |
| 163 | * will never be notified and its internal state will be out of sync. |
| 164 | */ |
Lucas Dupin | 15a6b6c | 2018-04-16 14:50:20 +0800 | [diff] [blame] | 165 | private void onFullyShown() { |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 166 | mFalsingManager.onBouncerShown(); |
Lucas Dupin | d2ce46d | 2018-04-04 17:00:29 -0700 | [diff] [blame] | 167 | if (mKeyguardView == null) { |
| 168 | Log.wtf(TAG, "onFullyShown when view was null"); |
| 169 | } else { |
| 170 | mKeyguardView.onResume(); |
| 171 | } |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /** |
Lucas Dupin | 15a6b6c | 2018-04-16 14:50:20 +0800 | [diff] [blame] | 175 | * @see #onFullyShown() |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 176 | */ |
Lucas Dupin | 15a6b6c | 2018-04-16 14:50:20 +0800 | [diff] [blame] | 177 | private void onFullyHidden() { |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 178 | if (!mShowingSoon) { |
| 179 | cancelShowRunnable(); |
Lucas Dupin | 0df9b7a | 2018-03-15 17:53:17 -0700 | [diff] [blame] | 180 | if (mRoot != null) { |
| 181 | mRoot.setVisibility(View.INVISIBLE); |
| 182 | } |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 183 | mFalsingManager.onBouncerHidden(); |
| 184 | } |
| 185 | } |
| 186 | |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 187 | private final Runnable mShowRunnable = new Runnable() { |
| 188 | @Override |
| 189 | public void run() { |
Jorim Jaggi | 0bed7f2 | 2014-04-03 16:12:54 +0200 | [diff] [blame] | 190 | mRoot.setVisibility(View.VISIBLE); |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 191 | showPromptReason(mBouncerPromptReason); |
Lucas Dupin | c80c67e | 2017-12-04 14:29:10 -0800 | [diff] [blame] | 192 | final CharSequence customMessage = mCallback.consumeCustomMessage(); |
| 193 | if (customMessage != null) { |
| 194 | mKeyguardView.showErrorMessage(customMessage); |
| 195 | } |
Selim Cinek | cb3d45a | 2017-09-08 18:00:18 -0700 | [diff] [blame] | 196 | // We might still be collapsed and the view didn't have time to layout yet or still |
| 197 | // be small, let's wait on the predraw to do the animation in that case. |
| 198 | if (mKeyguardView.getHeight() != 0 && mKeyguardView.getHeight() != mStatusBarHeight) { |
Adrian Roos | edfa96f | 2016-01-29 12:46:35 -0800 | [diff] [blame] | 199 | mKeyguardView.startAppearAnimation(); |
| 200 | } else { |
| 201 | mKeyguardView.getViewTreeObserver().addOnPreDrawListener( |
| 202 | new ViewTreeObserver.OnPreDrawListener() { |
| 203 | @Override |
| 204 | public boolean onPreDraw() { |
| 205 | mKeyguardView.getViewTreeObserver().removeOnPreDrawListener(this); |
| 206 | mKeyguardView.startAppearAnimation(); |
| 207 | return true; |
| 208 | } |
| 209 | }); |
| 210 | mKeyguardView.requestLayout(); |
| 211 | } |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 212 | mShowingSoon = false; |
Tej Singh | dd7bd35 | 2018-02-09 19:33:15 -0800 | [diff] [blame] | 213 | StatsLog.write(StatsLog.KEYGUARD_BOUNCER_STATE_CHANGED, |
| 214 | StatsLog.KEYGUARD_BOUNCER_STATE_CHANGED__STATE__SHOWN); |
Jorim Jaggi | 0bed7f2 | 2014-04-03 16:12:54 +0200 | [diff] [blame] | 215 | } |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 216 | }; |
| 217 | |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 218 | /** |
| 219 | * Show a string explaining why the security view needs to be solved. |
| 220 | * |
| 221 | * @param reason a flag indicating which string should be shown, see |
| 222 | * {@link KeyguardSecurityView#PROMPT_REASON_NONE} |
| 223 | * and {@link KeyguardSecurityView#PROMPT_REASON_RESTART} |
| 224 | */ |
| 225 | public void showPromptReason(int reason) { |
Lucas Dupin | 0df9b7a | 2018-03-15 17:53:17 -0700 | [diff] [blame] | 226 | if (mKeyguardView != null) { |
| 227 | mKeyguardView.showPromptReason(reason); |
| 228 | } else { |
| 229 | Log.w(TAG, "Trying to show prompt reason on empty bouncer"); |
| 230 | } |
Selim Cinek | 3122fa8 | 2015-06-18 01:38:59 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 233 | public void showMessage(String message, int color) { |
Lucas Dupin | 0df9b7a | 2018-03-15 17:53:17 -0700 | [diff] [blame] | 234 | if (mKeyguardView != null) { |
| 235 | mKeyguardView.showMessage(message, color); |
| 236 | } else { |
| 237 | Log.w(TAG, "Trying to show message on empty bouncer"); |
| 238 | } |
Selim Cinek | cfafe4e | 2015-08-11 14:58:44 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 241 | private void cancelShowRunnable() { |
Jorim Jaggi | 86b273f | 2015-07-14 18:08:43 -0700 | [diff] [blame] | 242 | DejankUtils.removeCallbacks(mShowRunnable); |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 243 | mShowingSoon = false; |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 244 | } |
| 245 | |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 246 | public void showWithDismissAction(OnDismissAction r, Runnable cancelAction) { |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 247 | ensureView(); |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 248 | mKeyguardView.setOnDismissAction(r, cancelAction); |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 249 | show(false /* resetSecuritySelection */); |
Adrian Roos | 7d7090d | 2014-05-21 13:10:23 +0200 | [diff] [blame] | 250 | } |
| 251 | |
Jorim Jaggi | a0be6d5 | 2014-05-26 03:01:13 +0200 | [diff] [blame] | 252 | public void hide(boolean destroyView) { |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 253 | if (isShowing()) { |
Tej Singh | dd7bd35 | 2018-02-09 19:33:15 -0800 | [diff] [blame] | 254 | StatsLog.write(StatsLog.KEYGUARD_BOUNCER_STATE_CHANGED, |
| 255 | StatsLog.KEYGUARD_BOUNCER_STATE_CHANGED__STATE__HIDDEN); |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 256 | mDismissCallbackRegistry.notifyDismissCancelled(); |
| 257 | } |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 258 | mFalsingManager.onBouncerHidden(); |
Matthew Ng | 66f0b70 | 2017-12-08 12:58:42 -0800 | [diff] [blame] | 259 | mCallback.onBouncerVisiblityChanged(false /* shown */); |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 260 | cancelShowRunnable(); |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 261 | if (mKeyguardView != null) { |
Jorim Jaggi | d944986 | 2015-05-29 14:49:08 -0700 | [diff] [blame] | 262 | mKeyguardView.cancelDismissAction(); |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 263 | mKeyguardView.cleanUp(); |
| 264 | } |
Lucas Dupin | 28dc9d7 | 2018-03-21 15:59:15 -0700 | [diff] [blame] | 265 | mIsAnimatingAway = false; |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 266 | if (mRoot != null) { |
Jorim Jaggi | a0be6d5 | 2014-05-26 03:01:13 +0200 | [diff] [blame] | 267 | mRoot.setVisibility(View.INVISIBLE); |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 268 | if (destroyView) { |
| 269 | |
| 270 | // We have a ViewFlipper that unregisters a broadcast when being detached, which may |
| 271 | // be slow because of AM lock contention during unlocking. We can delay it a bit. |
| 272 | mHandler.postDelayed(mRemoveViewRunnable, 50); |
| 273 | } |
Jorim Jaggi | a0be6d5 | 2014-05-26 03:01:13 +0200 | [diff] [blame] | 274 | } |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 275 | } |
| 276 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 277 | /** |
| 278 | * See {@link StatusBarKeyguardViewManager#startPreHideAnimation}. |
| 279 | */ |
| 280 | public void startPreHideAnimation(Runnable runnable) { |
Lucas Dupin | 28dc9d7 | 2018-03-21 15:59:15 -0700 | [diff] [blame] | 281 | mIsAnimatingAway = true; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 282 | if (mKeyguardView != null) { |
| 283 | mKeyguardView.startDisappearAnimation(runnable); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 284 | } else if (runnable != null) { |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 285 | runnable.run(); |
Jorim Jaggi | e29b2db | 2014-05-30 23:17:03 +0200 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 289 | /** |
| 290 | * Reset the state of the view. |
| 291 | */ |
| 292 | public void reset() { |
Jorim Jaggi | 416493b | 2014-09-13 03:57:32 +0200 | [diff] [blame] | 293 | cancelShowRunnable(); |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 294 | inflateView(); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 295 | mFalsingManager.onBouncerHidden(); |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | public void onScreenTurnedOff() { |
Dan Sandler | 9ee256d | 2014-04-21 12:05:00 -0400 | [diff] [blame] | 299 | if (mKeyguardView != null && mRoot != null && mRoot.getVisibility() == View.VISIBLE) { |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 300 | mKeyguardView.onPause(); |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
Jorim Jaggi | e5c7a89 | 2014-04-10 20:37:32 +0200 | [diff] [blame] | 304 | public boolean isShowing() { |
Lucas Dupin | 3d565fa | 2018-03-20 15:40:14 -0700 | [diff] [blame] | 305 | return (mShowingSoon || (mRoot != null && mRoot.getVisibility() == View.VISIBLE)) |
Lucas Dupin | d2ce46d | 2018-04-04 17:00:29 -0700 | [diff] [blame] | 306 | && mExpansion == 0 && !isAnimatingAway(); |
Jorim Jaggi | e5c7a89 | 2014-04-10 20:37:32 +0200 | [diff] [blame] | 307 | } |
| 308 | |
Lucas Dupin | 28dc9d7 | 2018-03-21 15:59:15 -0700 | [diff] [blame] | 309 | /** |
| 310 | * @return {@code true} when bouncer's pre-hide animation already started but isn't completely |
| 311 | * hidden yet, {@code false} otherwise. |
| 312 | */ |
| 313 | public boolean isAnimatingAway() { |
| 314 | return mIsAnimatingAway; |
| 315 | } |
| 316 | |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 317 | public void prepare() { |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 318 | boolean wasInitialized = mRoot != null; |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 319 | ensureView(); |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 320 | if (wasInitialized) { |
| 321 | mKeyguardView.showPrimarySecurityScreen(); |
| 322 | } |
Jorim Jaggi | 86b273f | 2015-07-14 18:08:43 -0700 | [diff] [blame] | 323 | mBouncerPromptReason = mCallback.getBouncerPromptReason(); |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 324 | } |
| 325 | |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 326 | /** |
| 327 | * Current notification panel expansion |
| 328 | * @param fraction 0 when notification panel is collapsed and 1 when expanded. |
| 329 | * @see StatusBarKeyguardViewManager#onPanelExpansionChanged |
| 330 | */ |
| 331 | public void setExpansion(float fraction) { |
Lucas Dupin | 15a6b6c | 2018-04-16 14:50:20 +0800 | [diff] [blame] | 332 | float oldExpansion = mExpansion; |
Lucas Dupin | 3d565fa | 2018-03-20 15:40:14 -0700 | [diff] [blame] | 333 | mExpansion = fraction; |
Lucas Dupin | 28dc9d7 | 2018-03-21 15:59:15 -0700 | [diff] [blame] | 334 | if (mKeyguardView != null && !mIsAnimatingAway) { |
Lucas Dupin | 0df9b7a | 2018-03-15 17:53:17 -0700 | [diff] [blame] | 335 | float alpha = MathUtils.map(ALPHA_EXPANSION_THRESHOLD, 1, 1, 0, fraction); |
| 336 | mKeyguardView.setAlpha(MathUtils.constrain(alpha, 0f, 1f)); |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 337 | mKeyguardView.setTranslationY(fraction * mKeyguardView.getHeight()); |
| 338 | } |
Lucas Dupin | 15a6b6c | 2018-04-16 14:50:20 +0800 | [diff] [blame] | 339 | |
| 340 | if (fraction == 0 && oldExpansion != 0) { |
| 341 | onFullyShown(); |
| 342 | mExpansionCallback.onFullyShown(); |
| 343 | } else if (fraction == 1 && oldExpansion != 0) { |
| 344 | onFullyHidden(); |
| 345 | mExpansionCallback.onFullyHidden(); |
| 346 | } |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 347 | } |
| 348 | |
Lucas Dupin | 6f0d71f | 2018-03-23 17:26:06 -0700 | [diff] [blame] | 349 | public boolean willDismissWithAction() { |
| 350 | return mKeyguardView != null && mKeyguardView.hasDismissActions(); |
| 351 | } |
| 352 | |
Lucas Dupin | 4c2aa39 | 2018-03-28 18:00:45 -0700 | [diff] [blame] | 353 | public int getTop() { |
| 354 | if (mKeyguardView == null) { |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | int top = mKeyguardView.getTop(); |
| 359 | // The password view has an extra top padding that should be ignored. |
| 360 | if (mKeyguardView.getCurrentSecurityMode() == SecurityMode.Password) { |
| 361 | View messageArea = mKeyguardView.findViewById(R.id.keyguard_message_area); |
| 362 | top += messageArea.getTop(); |
| 363 | } |
| 364 | return top; |
| 365 | } |
| 366 | |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 367 | protected void ensureView() { |
Lucas Dupin | f190a85 | 2017-07-31 17:11:26 -0700 | [diff] [blame] | 368 | // Removal of the view might be deferred to reduce unlock latency, |
| 369 | // in this case we need to force the removal, otherwise we'll |
| 370 | // end up in an unpredictable state. |
| 371 | boolean forceRemoval = mHandler.hasCallbacks(mRemoveViewRunnable); |
| 372 | if (mRoot == null || forceRemoval) { |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 373 | inflateView(); |
| 374 | } |
| 375 | } |
| 376 | |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 377 | protected void inflateView() { |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 378 | removeView(); |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 379 | mHandler.removeCallbacks(mRemoveViewRunnable); |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 380 | mRoot = (ViewGroup) LayoutInflater.from(mContext).inflate(R.layout.keyguard_bouncer, null); |
Lucas Dupin | 6865b71 | 2017-09-11 12:28:03 -0700 | [diff] [blame] | 381 | mKeyguardView = mRoot.findViewById(R.id.keyguard_host_view); |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 382 | mKeyguardView.setLockPatternUtils(mLockPatternUtils); |
| 383 | mKeyguardView.setViewMediatorCallback(mCallback); |
| 384 | mContainer.addView(mRoot, mContainer.getChildCount()); |
Selim Cinek | cb3d45a | 2017-09-08 18:00:18 -0700 | [diff] [blame] | 385 | mStatusBarHeight = mRoot.getResources().getDimensionPixelOffset( |
| 386 | com.android.systemui.R.dimen.status_bar_height); |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 387 | mRoot.setVisibility(View.INVISIBLE); |
Phil Weaver | 7d847b0 | 2018-02-13 16:02:35 -0800 | [diff] [blame] | 388 | mRoot.setAccessibilityPaneTitle(mKeyguardView.getAccessibilityTitleForCurrentMode()); |
Lucas Dupin | 6865b71 | 2017-09-11 12:28:03 -0700 | [diff] [blame] | 389 | |
| 390 | final WindowInsets rootInsets = mRoot.getRootWindowInsets(); |
| 391 | if (rootInsets != null) { |
| 392 | mRoot.dispatchApplyWindowInsets(rootInsets); |
| 393 | } |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 394 | } |
| 395 | |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 396 | protected void removeView() { |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 397 | if (mRoot != null && mRoot.getParent() == mContainer) { |
| 398 | mContainer.removeView(mRoot); |
| 399 | mRoot = null; |
| 400 | } |
| 401 | } |
Jorim Jaggi | e5c7a89 | 2014-04-10 20:37:32 +0200 | [diff] [blame] | 402 | |
| 403 | public boolean onBackPressed() { |
| 404 | return mKeyguardView != null && mKeyguardView.handleBackKey(); |
| 405 | } |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 406 | |
| 407 | /** |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 408 | * @return True if and only if the security method should be shown before showing the |
| 409 | * notifications on Keyguard, like SIM PIN/PUK. |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 410 | */ |
| 411 | public boolean needsFullscreenBouncer() { |
Selim Cinek | edd32b8 | 2015-06-23 22:05:58 -0400 | [diff] [blame] | 412 | ensureView(); |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 413 | if (mKeyguardView != null) { |
| 414 | SecurityMode mode = mKeyguardView.getSecurityMode(); |
Jorim Jaggi | 95e89ca | 2014-11-24 20:12:50 +0100 | [diff] [blame] | 415 | return mode == SecurityMode.SimPin || mode == SecurityMode.SimPuk; |
| 416 | } |
| 417 | return false; |
| 418 | } |
| 419 | |
| 420 | /** |
| 421 | * Like {@link #needsFullscreenBouncer}, but uses the currently visible security method, which |
| 422 | * makes this method much faster. |
| 423 | */ |
| 424 | public boolean isFullscreenBouncer() { |
| 425 | if (mKeyguardView != null) { |
| 426 | SecurityMode mode = mKeyguardView.getCurrentSecurityMode(); |
| 427 | return mode == SecurityMode.SimPin || mode == SecurityMode.SimPuk; |
Jorim Jaggi | a005f1b | 2014-04-16 19:06:10 +0200 | [diff] [blame] | 428 | } |
| 429 | return false; |
| 430 | } |
Jorim Jaggi | 8c8bcc1 | 2014-04-16 21:36:51 +0200 | [diff] [blame] | 431 | |
Christoph Studer | 2231c6e | 2014-12-19 12:40:13 +0100 | [diff] [blame] | 432 | /** |
| 433 | * WARNING: This method might cause Binder calls. |
| 434 | */ |
Jorim Jaggi | 1568250 | 2014-04-23 12:01:36 +0200 | [diff] [blame] | 435 | public boolean isSecure() { |
| 436 | return mKeyguardView == null || mKeyguardView.getSecurityMode() != SecurityMode.None; |
| 437 | } |
| 438 | |
Selim Cinek | 2854019 | 2016-02-19 17:25:08 -0800 | [diff] [blame] | 439 | public boolean shouldDismissOnMenuPressed() { |
| 440 | return mKeyguardView.shouldEnableMenuKey(); |
Jorim Jaggi | 8c8bcc1 | 2014-04-16 21:36:51 +0200 | [diff] [blame] | 441 | } |
Jorim Jaggi | df99351 | 2014-05-13 23:06:35 +0200 | [diff] [blame] | 442 | |
| 443 | public boolean interceptMediaKey(KeyEvent event) { |
| 444 | ensureView(); |
| 445 | return mKeyguardView.interceptMediaKey(event); |
| 446 | } |
Jorim Jaggi | 5cc8659 | 2015-06-08 14:48:28 -0700 | [diff] [blame] | 447 | |
Jorim Jaggi | 25b4d4b | 2015-08-11 15:54:06 -0700 | [diff] [blame] | 448 | public void notifyKeyguardAuthenticated(boolean strongAuth) { |
Jorim Jaggi | 5cc8659 | 2015-06-08 14:48:28 -0700 | [diff] [blame] | 449 | ensureView(); |
Vadim Tryshev | 8702ca7 | 2016-04-22 08:14:12 -0700 | [diff] [blame] | 450 | mKeyguardView.finish(strongAuth, KeyguardUpdateMonitor.getCurrentUser()); |
Jorim Jaggi | 5cc8659 | 2015-06-08 14:48:28 -0700 | [diff] [blame] | 451 | } |
Lucas Dupin | 15a6b6c | 2018-04-16 14:50:20 +0800 | [diff] [blame] | 452 | |
| 453 | public void dump(PrintWriter pw) { |
| 454 | pw.println("KeyguardBouncer"); |
| 455 | pw.println(" isShowing(): " + isShowing()); |
| 456 | pw.println(" mStatusBarHeight: " + mStatusBarHeight); |
| 457 | pw.println(" mExpansion: " + mExpansion); |
| 458 | pw.println(" mKeyguardView; " + mKeyguardView); |
| 459 | pw.println(" mShowingSoon: " + mKeyguardView); |
| 460 | pw.println(" mBouncerPromptReason: " + mBouncerPromptReason); |
| 461 | pw.println(" mIsAnimatingAway: " + mIsAnimatingAway); |
| 462 | } |
| 463 | |
| 464 | public interface BouncerExpansionCallback { |
| 465 | void onFullyShown(); |
| 466 | void onFullyHidden(); |
| 467 | } |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 468 | } |