blob: 60a3474be68430ff1a8ace369c0d4985a103fad0 [file] [log] [blame]
Jorim Jaggi03c701e2014-04-02 12:39:51 +02001/*
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
17package com.android.systemui.statusbar.phone;
18
Lucas Dupin0df9b7a2018-03-15 17:53:17 -070019import static com.android.keyguard.KeyguardHostView.OnDismissAction;
20import static com.android.keyguard.KeyguardSecurityModel.SecurityMode;
21
Jorim Jaggi03c701e2014-04-02 12:39:51 +020022import android.content.Context;
Jorim Jaggifabc7432017-05-15 02:40:05 +020023import android.os.Handler;
Toni Barzic657f8852016-02-04 15:14:49 -080024import android.os.UserHandle;
Toni Barzicb799d3f2016-02-17 15:09:10 -080025import android.os.UserManager;
Lucas Dupin0df9b7a2018-03-15 17:53:17 -070026import android.util.Log;
Lucas Dupinbc9aac12018-03-04 20:18:15 -080027import android.util.MathUtils;
Toni Barzic657f8852016-02-04 15:14:49 -080028import android.util.Slog;
Tej Singhdd7bd352018-02-09 19:33:15 -080029import android.util.StatsLog;
Jorim Jaggidf993512014-05-13 23:06:35 +020030import android.view.KeyEvent;
Jorim Jaggi03c701e2014-04-02 12:39:51 +020031import android.view.LayoutInflater;
32import android.view.View;
33import android.view.ViewGroup;
Adrian Roosedfa96f2016-01-29 12:46:35 -080034import android.view.ViewTreeObserver;
Lucas Dupin6865b712017-09-11 12:28:03 -070035import android.view.WindowInsets;
Jorim Jaggi03c701e2014-04-02 12:39:51 +020036
Jorim Jaggi03c701e2014-04-02 12:39:51 +020037import com.android.internal.widget.LockPatternUtils;
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010038import com.android.keyguard.KeyguardHostView;
Selim Cinek3122fa82015-06-18 01:38:59 -070039import com.android.keyguard.KeyguardSecurityView;
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -070040import com.android.keyguard.KeyguardUpdateMonitor;
41import com.android.keyguard.KeyguardUpdateMonitorCallback;
Jorim Jaggi03c701e2014-04-02 12:39:51 +020042import com.android.keyguard.R;
43import com.android.keyguard.ViewMediatorCallback;
Jorim Jaggi86b273f2015-07-14 18:08:43 -070044import com.android.systemui.DejankUtils;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070045import com.android.systemui.classifier.FalsingManager;
Jorim Jaggi241ae102016-11-02 21:57:33 -070046import com.android.systemui.keyguard.DismissCallbackRegistry;
Jorim Jaggi03c701e2014-04-02 12:39:51 +020047
48/**
49 * A class which manages the bouncer on the lockscreen.
50 */
51public class KeyguardBouncer {
52
Lucas Dupinbc9aac12018-03-04 20:18:15 -080053 private static final String TAG = "KeyguardBouncer";
54 static final float ALPHA_EXPANSION_THRESHOLD = 0.95f;
Toni Barzic657f8852016-02-04 15:14:49 -080055
Jorim Jaggi241ae102016-11-02 21:57:33 -070056 protected final Context mContext;
57 protected final ViewMediatorCallback mCallback;
58 protected final LockPatternUtils mLockPatternUtils;
59 protected final ViewGroup mContainer;
60 private final FalsingManager mFalsingManager;
61 private final DismissCallbackRegistry mDismissCallbackRegistry;
Jorim Jaggifabc7432017-05-15 02:40:05 +020062 private final Handler mHandler;
Jorim Jaggi241ae102016-11-02 21:57:33 -070063 private final KeyguardUpdateMonitorCallback mUpdateMonitorCallback =
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -070064 new KeyguardUpdateMonitorCallback() {
65 @Override
Adrian Roos1de8bcb2015-08-19 16:52:52 -070066 public void onStrongAuthStateChanged(int userId) {
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -070067 mBouncerPromptReason = mCallback.getBouncerPromptReason();
68 }
69 };
Jorim Jaggifabc7432017-05-15 02:40:05 +020070 private final Runnable mRemoveViewRunnable = this::removeView;
Lucas Dupin3d565fa2018-03-20 15:40:14 -070071
Selim Cinekcb3d45a2017-09-08 18:00:18 -070072 private int mStatusBarHeight;
Lucas Dupin3d565fa2018-03-20 15:40:14 -070073 private float mExpansion;
74 protected KeyguardHostView mKeyguardView;
75 protected ViewGroup mRoot;
76 private boolean mShowingSoon;
77 private int mBouncerPromptReason;
Lucas Dupin28dc9d72018-03-21 15:59:15 -070078 private boolean mIsAnimatingAway;
Jorim Jaggi03c701e2014-04-02 12:39:51 +020079
80 public KeyguardBouncer(Context context, ViewMediatorCallback callback,
Jorim Jaggi241ae102016-11-02 21:57:33 -070081 LockPatternUtils lockPatternUtils, ViewGroup container,
Lucas Dupin0df9b7a2018-03-15 17:53:17 -070082 DismissCallbackRegistry dismissCallbackRegistry, FalsingManager falsingManager) {
Jorim Jaggi03c701e2014-04-02 12:39:51 +020083 mContext = context;
84 mCallback = callback;
85 mLockPatternUtils = lockPatternUtils;
86 mContainer = container;
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -070087 KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallback);
Lucas Dupin0df9b7a2018-03-15 17:53:17 -070088 mFalsingManager = falsingManager;
Jorim Jaggi241ae102016-11-02 21:57:33 -070089 mDismissCallbackRegistry = dismissCallbackRegistry;
Jorim Jaggifabc7432017-05-15 02:40:05 +020090 mHandler = new Handler();
Jorim Jaggi03c701e2014-04-02 12:39:51 +020091 }
92
Jorim Jaggi95e89ca2014-11-24 20:12:50 +010093 public void show(boolean resetSecuritySelection) {
Lucas Dupinbc9aac12018-03-04 20:18:15 -080094 show(resetSecuritySelection, true /* notifyFalsing */);
95 }
96
Lucas Dupin0df9b7a2018-03-15 17:53:17 -070097 /**
98 * Shows the bouncer.
99 *
100 * @param resetSecuritySelection Cleans keyguard view
101 * @param animated true when the bouncer show show animated, false when the user will be
102 * dragging it and animation should be deferred.
103 */
104 public void show(boolean resetSecuritySelection, boolean animated) {
Vadim Tryshevec018432016-02-10 14:11:03 -0800105 final int keyguardUserId = KeyguardUpdateMonitor.getCurrentUser();
106 if (keyguardUserId == UserHandle.USER_SYSTEM && UserManager.isSplitSystemUser()) {
107 // In split system user mode, we never unlock system user.
108 return;
109 }
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200110 ensureView();
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800111
112 // On the keyguard, we want to show the bouncer when the user drags up, but it's
113 // not correct to end the falsing session. We still need to verify if those touches
114 // are valid.
115 // Later, at the end of the animation, when the bouncer is at the top of the screen,
116 // onFullyShown() will be called and FalsingManager will stop recording touches.
Lucas Dupin0df9b7a2018-03-15 17:53:17 -0700117 if (animated) {
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800118 mFalsingManager.onBouncerShown();
Lucas Dupin0df9b7a2018-03-15 17:53:17 -0700119 setExpansion(0);
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800120 }
Lucas Dupin0df9b7a2018-03-15 17:53:17 -0700121
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100122 if (resetSecuritySelection) {
123 // showPrimarySecurityScreen() updates the current security method. This is needed in
124 // case we are already showing and the current security method changed.
125 mKeyguardView.showPrimarySecurityScreen();
126 }
Jorim Jaggi416493b2014-09-13 03:57:32 +0200127 if (mRoot.getVisibility() == View.VISIBLE || mShowingSoon) {
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200128 return;
129 }
Jorim Jaggi0bed7f22014-04-03 16:12:54 +0200130
Selim Cinek1a891a92017-12-04 17:41:27 +0100131 final int activeUserId = KeyguardUpdateMonitor.getCurrentUser();
Xiaohui Chend743cef2016-10-03 09:55:53 -0700132 final boolean isSystemUser =
133 UserManager.isSplitSystemUser() && activeUserId == UserHandle.USER_SYSTEM;
134 final boolean allowDismissKeyguard = !isSystemUser && activeUserId == keyguardUserId;
135
Toni Barzic657f8852016-02-04 15:14:49 -0800136 // If allowed, try to dismiss the Keyguard. If no security auth (password/pin/pattern) is
137 // set, this will dismiss the whole Keyguard. Otherwise, show the bouncer.
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700138 if (allowDismissKeyguard && mKeyguardView.dismiss(activeUserId)) {
Toni Barzic657f8852016-02-04 15:14:49 -0800139 return;
Jorim Jaggi416493b2014-09-13 03:57:32 +0200140 }
Toni Barzic657f8852016-02-04 15:14:49 -0800141
142 // This condition may indicate an error on Android, so log it.
143 if (!allowDismissKeyguard) {
144 Slog.w(TAG, "User can't dismiss keyguard: " + activeUserId + " != " + keyguardUserId);
145 }
146
147 mShowingSoon = true;
148
149 // Split up the work over multiple frames.
150 DejankUtils.postAfterTraversal(mShowRunnable);
Matthew Ng66f0b702017-12-08 12:58:42 -0800151
152 mCallback.onBouncerVisiblityChanged(true /* shown */);
Jorim Jaggi416493b2014-09-13 03:57:32 +0200153 }
154
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800155 /**
156 * This method must be called at the end of the bouncer animation when
157 * the translation is performed manually by the user, otherwise FalsingManager
158 * will never be notified and its internal state will be out of sync.
159 */
160 public void onFullyShown() {
161 mFalsingManager.onBouncerShown();
Lucas Dupind2ce46d2018-04-04 17:00:29 -0700162 if (mKeyguardView == null) {
163 Log.wtf(TAG, "onFullyShown when view was null");
164 } else {
165 mKeyguardView.onResume();
166 }
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800167 }
168
169 /**
170 * This method must be called at the end of the bouncer animation when
171 * the translation is performed manually by the user, otherwise FalsingManager
172 * will never be notified and its internal state will be out of sync.
173 */
174 public void onFullyHidden() {
175 if (!mShowingSoon) {
176 cancelShowRunnable();
Lucas Dupin0df9b7a2018-03-15 17:53:17 -0700177 if (mRoot != null) {
178 mRoot.setVisibility(View.INVISIBLE);
179 }
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800180 mFalsingManager.onBouncerHidden();
181 }
182 }
183
Jorim Jaggi416493b2014-09-13 03:57:32 +0200184 private final Runnable mShowRunnable = new Runnable() {
185 @Override
186 public void run() {
Jorim Jaggi0bed7f22014-04-03 16:12:54 +0200187 mRoot.setVisibility(View.VISIBLE);
Selim Cinek3122fa82015-06-18 01:38:59 -0700188 showPromptReason(mBouncerPromptReason);
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800189 final CharSequence customMessage = mCallback.consumeCustomMessage();
190 if (customMessage != null) {
191 mKeyguardView.showErrorMessage(customMessage);
192 }
Selim Cinekcb3d45a2017-09-08 18:00:18 -0700193 // We might still be collapsed and the view didn't have time to layout yet or still
194 // be small, let's wait on the predraw to do the animation in that case.
195 if (mKeyguardView.getHeight() != 0 && mKeyguardView.getHeight() != mStatusBarHeight) {
Adrian Roosedfa96f2016-01-29 12:46:35 -0800196 mKeyguardView.startAppearAnimation();
197 } else {
198 mKeyguardView.getViewTreeObserver().addOnPreDrawListener(
199 new ViewTreeObserver.OnPreDrawListener() {
200 @Override
201 public boolean onPreDraw() {
202 mKeyguardView.getViewTreeObserver().removeOnPreDrawListener(this);
203 mKeyguardView.startAppearAnimation();
204 return true;
205 }
206 });
207 mKeyguardView.requestLayout();
208 }
Jorim Jaggi416493b2014-09-13 03:57:32 +0200209 mShowingSoon = false;
Tej Singhdd7bd352018-02-09 19:33:15 -0800210 StatsLog.write(StatsLog.KEYGUARD_BOUNCER_STATE_CHANGED,
211 StatsLog.KEYGUARD_BOUNCER_STATE_CHANGED__STATE__SHOWN);
Jorim Jaggi0bed7f22014-04-03 16:12:54 +0200212 }
Jorim Jaggi416493b2014-09-13 03:57:32 +0200213 };
214
Selim Cinek3122fa82015-06-18 01:38:59 -0700215 /**
216 * Show a string explaining why the security view needs to be solved.
217 *
218 * @param reason a flag indicating which string should be shown, see
219 * {@link KeyguardSecurityView#PROMPT_REASON_NONE}
220 * and {@link KeyguardSecurityView#PROMPT_REASON_RESTART}
221 */
222 public void showPromptReason(int reason) {
Lucas Dupin0df9b7a2018-03-15 17:53:17 -0700223 if (mKeyguardView != null) {
224 mKeyguardView.showPromptReason(reason);
225 } else {
226 Log.w(TAG, "Trying to show prompt reason on empty bouncer");
227 }
Selim Cinek3122fa82015-06-18 01:38:59 -0700228 }
229
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700230 public void showMessage(String message, int color) {
Lucas Dupin0df9b7a2018-03-15 17:53:17 -0700231 if (mKeyguardView != null) {
232 mKeyguardView.showMessage(message, color);
233 } else {
234 Log.w(TAG, "Trying to show message on empty bouncer");
235 }
Selim Cinekcfafe4e2015-08-11 14:58:44 -0700236 }
237
Jorim Jaggi416493b2014-09-13 03:57:32 +0200238 private void cancelShowRunnable() {
Jorim Jaggi86b273f2015-07-14 18:08:43 -0700239 DejankUtils.removeCallbacks(mShowRunnable);
Jorim Jaggi416493b2014-09-13 03:57:32 +0200240 mShowingSoon = false;
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200241 }
242
Jorim Jaggid9449862015-05-29 14:49:08 -0700243 public void showWithDismissAction(OnDismissAction r, Runnable cancelAction) {
Adrian Roos7d7090d2014-05-21 13:10:23 +0200244 ensureView();
Jorim Jaggid9449862015-05-29 14:49:08 -0700245 mKeyguardView.setOnDismissAction(r, cancelAction);
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100246 show(false /* resetSecuritySelection */);
Adrian Roos7d7090d2014-05-21 13:10:23 +0200247 }
248
Jorim Jaggia0be6d52014-05-26 03:01:13 +0200249 public void hide(boolean destroyView) {
Jorim Jaggi241ae102016-11-02 21:57:33 -0700250 if (isShowing()) {
Tej Singhdd7bd352018-02-09 19:33:15 -0800251 StatsLog.write(StatsLog.KEYGUARD_BOUNCER_STATE_CHANGED,
252 StatsLog.KEYGUARD_BOUNCER_STATE_CHANGED__STATE__HIDDEN);
Jorim Jaggi241ae102016-11-02 21:57:33 -0700253 mDismissCallbackRegistry.notifyDismissCancelled();
254 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700255 mFalsingManager.onBouncerHidden();
Matthew Ng66f0b702017-12-08 12:58:42 -0800256 mCallback.onBouncerVisiblityChanged(false /* shown */);
Jorim Jaggi416493b2014-09-13 03:57:32 +0200257 cancelShowRunnable();
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800258 if (mKeyguardView != null) {
Jorim Jaggid9449862015-05-29 14:49:08 -0700259 mKeyguardView.cancelDismissAction();
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200260 mKeyguardView.cleanUp();
261 }
Lucas Dupin28dc9d72018-03-21 15:59:15 -0700262 mIsAnimatingAway = false;
Jorim Jaggifabc7432017-05-15 02:40:05 +0200263 if (mRoot != null) {
Jorim Jaggia0be6d52014-05-26 03:01:13 +0200264 mRoot.setVisibility(View.INVISIBLE);
Jorim Jaggifabc7432017-05-15 02:40:05 +0200265 if (destroyView) {
266
267 // We have a ViewFlipper that unregisters a broadcast when being detached, which may
268 // be slow because of AM lock contention during unlocking. We can delay it a bit.
269 mHandler.postDelayed(mRemoveViewRunnable, 50);
270 }
Jorim Jaggia0be6d52014-05-26 03:01:13 +0200271 }
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200272 }
273
Jorim Jaggi76a16232014-08-08 17:00:47 +0200274 /**
275 * See {@link StatusBarKeyguardViewManager#startPreHideAnimation}.
276 */
277 public void startPreHideAnimation(Runnable runnable) {
Lucas Dupin28dc9d72018-03-21 15:59:15 -0700278 mIsAnimatingAway = true;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200279 if (mKeyguardView != null) {
280 mKeyguardView.startDisappearAnimation(runnable);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200281 } else if (runnable != null) {
Jorim Jaggi76a16232014-08-08 17:00:47 +0200282 runnable.run();
Jorim Jaggie29b2db2014-05-30 23:17:03 +0200283 }
284 }
285
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200286 /**
287 * Reset the state of the view.
288 */
289 public void reset() {
Jorim Jaggi416493b2014-09-13 03:57:32 +0200290 cancelShowRunnable();
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200291 inflateView();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700292 mFalsingManager.onBouncerHidden();
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200293 }
294
295 public void onScreenTurnedOff() {
Dan Sandler9ee256d2014-04-21 12:05:00 -0400296 if (mKeyguardView != null && mRoot != null && mRoot.getVisibility() == View.VISIBLE) {
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200297 mKeyguardView.onPause();
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200298 }
299 }
300
Jorim Jaggie5c7a892014-04-10 20:37:32 +0200301 public boolean isShowing() {
Lucas Dupin3d565fa2018-03-20 15:40:14 -0700302 return (mShowingSoon || (mRoot != null && mRoot.getVisibility() == View.VISIBLE))
Lucas Dupind2ce46d2018-04-04 17:00:29 -0700303 && mExpansion == 0 && !isAnimatingAway();
Jorim Jaggie5c7a892014-04-10 20:37:32 +0200304 }
305
Lucas Dupin28dc9d72018-03-21 15:59:15 -0700306 /**
307 * @return {@code true} when bouncer's pre-hide animation already started but isn't completely
308 * hidden yet, {@code false} otherwise.
309 */
310 public boolean isAnimatingAway() {
311 return mIsAnimatingAway;
312 }
313
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200314 public void prepare() {
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100315 boolean wasInitialized = mRoot != null;
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200316 ensureView();
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100317 if (wasInitialized) {
318 mKeyguardView.showPrimarySecurityScreen();
319 }
Jorim Jaggi86b273f2015-07-14 18:08:43 -0700320 mBouncerPromptReason = mCallback.getBouncerPromptReason();
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200321 }
322
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800323 /**
324 * Current notification panel expansion
325 * @param fraction 0 when notification panel is collapsed and 1 when expanded.
326 * @see StatusBarKeyguardViewManager#onPanelExpansionChanged
327 */
328 public void setExpansion(float fraction) {
Lucas Dupin3d565fa2018-03-20 15:40:14 -0700329 mExpansion = fraction;
Lucas Dupin28dc9d72018-03-21 15:59:15 -0700330 if (mKeyguardView != null && !mIsAnimatingAway) {
Lucas Dupin0df9b7a2018-03-15 17:53:17 -0700331 float alpha = MathUtils.map(ALPHA_EXPANSION_THRESHOLD, 1, 1, 0, fraction);
332 mKeyguardView.setAlpha(MathUtils.constrain(alpha, 0f, 1f));
Lucas Dupinbc9aac12018-03-04 20:18:15 -0800333 mKeyguardView.setTranslationY(fraction * mKeyguardView.getHeight());
334 }
335 }
336
Lucas Dupin6f0d71f2018-03-23 17:26:06 -0700337 public boolean willDismissWithAction() {
338 return mKeyguardView != null && mKeyguardView.hasDismissActions();
339 }
340
Lucas Dupin4c2aa392018-03-28 18:00:45 -0700341 public int getTop() {
342 if (mKeyguardView == null) {
343 return 0;
344 }
345
346 int top = mKeyguardView.getTop();
347 // The password view has an extra top padding that should be ignored.
348 if (mKeyguardView.getCurrentSecurityMode() == SecurityMode.Password) {
349 View messageArea = mKeyguardView.findViewById(R.id.keyguard_message_area);
350 top += messageArea.getTop();
351 }
352 return top;
353 }
354
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800355 protected void ensureView() {
Lucas Dupinf190a852017-07-31 17:11:26 -0700356 // Removal of the view might be deferred to reduce unlock latency,
357 // in this case we need to force the removal, otherwise we'll
358 // end up in an unpredictable state.
359 boolean forceRemoval = mHandler.hasCallbacks(mRemoveViewRunnable);
360 if (mRoot == null || forceRemoval) {
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200361 inflateView();
362 }
363 }
364
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800365 protected void inflateView() {
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200366 removeView();
Jorim Jaggifabc7432017-05-15 02:40:05 +0200367 mHandler.removeCallbacks(mRemoveViewRunnable);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200368 mRoot = (ViewGroup) LayoutInflater.from(mContext).inflate(R.layout.keyguard_bouncer, null);
Lucas Dupin6865b712017-09-11 12:28:03 -0700369 mKeyguardView = mRoot.findViewById(R.id.keyguard_host_view);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200370 mKeyguardView.setLockPatternUtils(mLockPatternUtils);
371 mKeyguardView.setViewMediatorCallback(mCallback);
372 mContainer.addView(mRoot, mContainer.getChildCount());
Selim Cinekcb3d45a2017-09-08 18:00:18 -0700373 mStatusBarHeight = mRoot.getResources().getDimensionPixelOffset(
374 com.android.systemui.R.dimen.status_bar_height);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200375 mRoot.setVisibility(View.INVISIBLE);
Phil Weaver7d847b02018-02-13 16:02:35 -0800376 mRoot.setAccessibilityPaneTitle(mKeyguardView.getAccessibilityTitleForCurrentMode());
Lucas Dupin6865b712017-09-11 12:28:03 -0700377
378 final WindowInsets rootInsets = mRoot.getRootWindowInsets();
379 if (rootInsets != null) {
380 mRoot.dispatchApplyWindowInsets(rootInsets);
381 }
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200382 }
383
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800384 protected void removeView() {
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200385 if (mRoot != null && mRoot.getParent() == mContainer) {
386 mContainer.removeView(mRoot);
387 mRoot = null;
388 }
389 }
Jorim Jaggie5c7a892014-04-10 20:37:32 +0200390
391 public boolean onBackPressed() {
392 return mKeyguardView != null && mKeyguardView.handleBackKey();
393 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200394
395 /**
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100396 * @return True if and only if the security method should be shown before showing the
397 * notifications on Keyguard, like SIM PIN/PUK.
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200398 */
399 public boolean needsFullscreenBouncer() {
Selim Cinekedd32b82015-06-23 22:05:58 -0400400 ensureView();
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200401 if (mKeyguardView != null) {
402 SecurityMode mode = mKeyguardView.getSecurityMode();
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100403 return mode == SecurityMode.SimPin || mode == SecurityMode.SimPuk;
404 }
405 return false;
406 }
407
408 /**
409 * Like {@link #needsFullscreenBouncer}, but uses the currently visible security method, which
410 * makes this method much faster.
411 */
412 public boolean isFullscreenBouncer() {
413 if (mKeyguardView != null) {
414 SecurityMode mode = mKeyguardView.getCurrentSecurityMode();
415 return mode == SecurityMode.SimPin || mode == SecurityMode.SimPuk;
Jorim Jaggia005f1b2014-04-16 19:06:10 +0200416 }
417 return false;
418 }
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +0200419
Christoph Studer2231c6e2014-12-19 12:40:13 +0100420 /**
421 * WARNING: This method might cause Binder calls.
422 */
Jorim Jaggi15682502014-04-23 12:01:36 +0200423 public boolean isSecure() {
424 return mKeyguardView == null || mKeyguardView.getSecurityMode() != SecurityMode.None;
425 }
426
Selim Cinek28540192016-02-19 17:25:08 -0800427 public boolean shouldDismissOnMenuPressed() {
428 return mKeyguardView.shouldEnableMenuKey();
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +0200429 }
Jorim Jaggidf993512014-05-13 23:06:35 +0200430
431 public boolean interceptMediaKey(KeyEvent event) {
432 ensureView();
433 return mKeyguardView.interceptMediaKey(event);
434 }
Jorim Jaggi5cc86592015-06-08 14:48:28 -0700435
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700436 public void notifyKeyguardAuthenticated(boolean strongAuth) {
Jorim Jaggi5cc86592015-06-08 14:48:28 -0700437 ensureView();
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700438 mKeyguardView.finish(strongAuth, KeyguardUpdateMonitor.getCurrentUser());
Jorim Jaggi5cc86592015-06-08 14:48:28 -0700439 }
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200440}