blob: 0be9e25bfc27cbb4680b13224e329b1db31c3472 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002 * Copyright (C) 2014 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
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
Jorim Jaggi5cf17872014-03-26 18:31:48 +010014 * limitations under the License
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080015 */
16
Jorim Jaggi5cf17872014-03-26 18:31:48 +010017package com.android.systemui.keyguard;
Jim Millerbc4603b2010-08-30 21:21:34 -070018
Jorim Jaggid11d1a92016-08-16 16:02:32 -070019import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
Adrian Roose92de952016-12-13 12:07:09 -080020
21import static com.android.internal.telephony.IccCardConstants.State.ABSENT;
Lucas Dupin6d48eab2018-09-17 17:17:14 -070022import static com.android.internal.telephony.IccCardConstants.State.PIN_REQUIRED;
23import static com.android.internal.telephony.IccCardConstants.State.PUK_REQUIRED;
Jorim Jaggid11d1a92016-08-16 16:02:32 -070024import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST;
25import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW;
26import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT;
Michal Karpinskic52f8672016-11-18 11:32:45 +000027import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT;
Jorim Jaggid11d1a92016-08-16 16:02:32 -070028
Adrian Roosb60d47c2014-09-08 19:23:00 +020029import android.app.ActivityManager;
Wale Ogunwale04d9cb52018-04-30 13:55:07 -070030import android.app.ActivityTaskManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080031import android.app.AlarmManager;
32import android.app.PendingIntent;
Mike Lockwood5f892c12009-11-19 23:39:13 -050033import android.app.StatusBarManager;
Adrian Roos481a6df2014-11-20 19:48:56 +010034import android.app.trust.TrustManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080035import android.content.BroadcastReceiver;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -050036import android.content.ContentResolver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080037import android.content.Context;
38import android.content.Intent;
39import android.content.IntentFilter;
Adrian Roosbe47b072014-09-03 00:08:56 +020040import android.content.pm.UserInfo;
Lucas Dupin6d48eab2018-09-17 17:17:14 -070041import android.hardware.biometrics.BiometricSourceType;
Jean-Michel Trivi0616db42019-01-28 10:57:21 -080042import android.media.AudioAttributes;
Daniel Sandleraec967a2010-02-20 01:05:22 -050043import android.media.AudioManager;
Marco Nelissend5545bd2011-09-29 12:49:17 -070044import android.media.SoundPool;
Adam Cohenf7522022012-10-03 20:03:18 -070045import android.os.Bundle;
dooyoung.hwang328472e2015-05-21 16:09:43 +090046import android.os.DeadObjectException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080047import android.os.Handler;
Jeff Brown109025d2012-08-14 20:41:30 -070048import android.os.Looper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080049import android.os.Message;
50import android.os.PowerManager;
Dianne Hackborn4994c662009-09-23 22:21:23 -070051import android.os.RemoteException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080052import android.os.SystemClock;
Jim Miller1b152022009-10-28 16:08:15 -070053import android.os.SystemProperties;
Nick Desaulniers1d396752016-07-25 15:05:33 -070054import android.os.Trace;
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -070055import android.os.UserHandle;
Amith Yamasanib70ff9a2012-09-07 18:28:11 -070056import android.os.UserManager;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -050057import android.provider.Settings;
Jim Miller52a61332014-11-12 19:29:51 -080058import android.telephony.SubscriptionManager;
Karl Rosaenab100082009-03-24 22:35:17 -070059import android.telephony.TelephonyManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080060import android.util.EventLog;
Karl Rosaenab100082009-03-24 22:35:17 -070061import android.util.Log;
Jim Miller25190572013-02-28 17:36:24 -080062import android.util.Slog;
Lucas Dupin6d48eab2018-09-17 17:17:14 -070063import android.util.SparseArray;
Jorim Jaggib690f0d2014-07-03 23:25:44 +020064import android.view.ViewGroup;
Adrian Roose99bc052017-11-20 17:55:31 +010065import android.view.WindowManagerPolicyConstants;
Adrian Roos0002a452014-07-03 13:46:07 +020066import android.view.animation.Animation;
67import android.view.animation.AnimationUtils;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -070068
Adrian Roos1cffe3c2016-11-28 15:46:06 -080069import com.android.internal.logging.MetricsLogger;
70import com.android.internal.logging.nano.MetricsProto;
Jorim Jaggi241ae102016-11-02 21:57:33 -070071import com.android.internal.policy.IKeyguardDismissCallback;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -070072import com.android.internal.policy.IKeyguardDrawnCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010073import com.android.internal.policy.IKeyguardExitCallback;
Jim Millerab954542014-10-10 18:21:49 -070074import com.android.internal.policy.IKeyguardStateCallback;
Adam Cohenf7522022012-10-03 20:03:18 -070075import com.android.internal.telephony.IccCardConstants;
Lucas Dupin6d48eab2018-09-17 17:17:14 -070076import com.android.internal.util.LatencyTracker;
Adam Cohenf7522022012-10-03 20:03:18 -070077import com.android.internal.widget.LockPatternUtils;
Jim Miller52a61332014-11-12 19:29:51 -080078import com.android.keyguard.KeyguardConstants;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010079import com.android.keyguard.KeyguardDisplayManager;
Selim Cinek3122fa82015-06-18 01:38:59 -070080import com.android.keyguard.KeyguardSecurityView;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010081import com.android.keyguard.KeyguardUpdateMonitor;
82import com.android.keyguard.KeyguardUpdateMonitorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010083import com.android.keyguard.ViewMediatorCallback;
Jorim Jaggie549a8d2017-05-15 02:40:05 +020084import com.android.systemui.Dependency;
Jorim Jaggicff0acb2014-03-31 16:35:15 +020085import com.android.systemui.SystemUI;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080086import com.android.systemui.SystemUIFactory;
Jorim Jaggie549a8d2017-05-15 02:40:05 +020087import com.android.systemui.UiOffloadThread;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070088import com.android.systemui.classifier.FalsingManager;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020089import com.android.systemui.statusbar.phone.BiometricUnlockController;
Lucas Dupin6d48eab2018-09-17 17:17:14 -070090import com.android.systemui.statusbar.phone.NotificationPanelView;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050091import com.android.systemui.statusbar.phone.StatusBar;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010092import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
Adrian Roos58b58fe2014-01-31 16:00:39 -080093
Jorim Jaggi84dc08a2015-09-11 17:45:22 -070094import java.io.FileDescriptor;
95import java.io.PrintWriter;
Jim Millerab954542014-10-10 18:21:49 -070096import java.util.ArrayList;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010097
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080098/**
99 * Mediates requests related to the keyguard. This includes queries about the
100 * state of the keyguard, power management events that effect whether the keyguard
101 * should be shown or reset, callbacks to the phone window manager to notify
102 * it of when the keyguard is showing, and events from the keyguard view itself
103 * stating that the keyguard was succesfully unlocked.
104 *
105 * Note that the keyguard view is shown when the screen is off (as appropriate)
106 * so that once the screen comes on, it will be ready immediately.
107 *
108 * Example queries about the keyguard:
109 * - is {movement, key} one that should wake the keygaurd?
110 * - is the keyguard showing?
111 * - are input events restricted due to the state of the keyguard?
112 *
113 * Callbacks to the phone window manager:
114 * - the keyguard is showing
115 *
116 * Example external events that translate to keyguard view changes:
117 * - screen turned off -> reset the keyguard, and show it so it will be ready
118 * next time the screen turns on
119 * - keyboard is slid open -> if the keyguard is not secure, hide it
120 *
121 * Events from the keyguard view:
122 * - user succesfully unlocked keyguard -> hide keyguard view, and no longer
123 * restrict input events.
124 *
125 * Note: in addition to normal power managment events that effect the state of
126 * whether the keyguard should be showing, external apps and services may request
127 * that the keyguard be disabled via {@link #setKeyguardEnabled(boolean)}. When
128 * false, this will override all other conditions for turning on the keyguard.
129 *
130 * Threading and synchronization:
Adrian Roose99bc052017-11-20 17:55:31 +0100131 * This class is created by the initialization routine of the {@link WindowManagerPolicyConstants},
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800132 * and runs on its thread. The keyguard UI is created from that thread in the
133 * constructor of this class. The apis may be called from other threads, including the
Jeff Brown4532e612012-04-05 14:27:12 -0700134 * {@link com.android.server.input.InputManagerService}'s and {@link android.view.WindowManager}'s.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800135 * Therefore, methods on this class are synchronized, and any action that is pointed
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100136 * directly to the keyguard UI is posted to a {@link android.os.Handler} to ensure it is taken on the UI
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800137 * thread of the keyguard.
138 */
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200139public class KeyguardViewMediator extends SystemUI {
Jim Millerbc4603b2010-08-30 21:21:34 -0700140 private static final int KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT = 30000;
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100141 private static final long KEYGUARD_DONE_PENDING_TIMEOUT_MS = 3000;
142
Jim Miller52a61332014-11-12 19:29:51 -0800143 private static final boolean DEBUG = KeyguardConstants.DEBUG;
144 private static final boolean DEBUG_SIM_STATES = KeyguardConstants.DEBUG_SIM_STATES;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800145
146 private final static String TAG = "KeyguardViewMediator";
147
Jim Miller9c20d0e2010-01-20 15:00:23 -0800148 private static final String DELAYED_KEYGUARD_ACTION =
Wink Saville37c124c2009-04-02 01:37:02 -0700149 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD";
Clara Bayarri56878a92015-10-29 15:43:55 +0000150 private static final String DELAYED_LOCK_PROFILE_ACTION =
151 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_LOCK";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800152
Kevin Chyn18e91aa2018-04-11 12:55:45 -0700153 private static final String SYSTEMUI_PERMISSION = "com.android.systemui.permission.SELF";
154
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800155 // used for handler messages
Jorim Jaggi8d786932016-10-26 19:08:36 -0700156 private static final int SHOW = 1;
157 private static final int HIDE = 2;
158 private static final int RESET = 3;
159 private static final int VERIFY_UNLOCK = 4;
160 private static final int NOTIFY_FINISHED_GOING_TO_SLEEP = 5;
161 private static final int NOTIFY_SCREEN_TURNING_ON = 6;
162 private static final int KEYGUARD_DONE = 7;
163 private static final int KEYGUARD_DONE_DRAWING = 8;
164 private static final int SET_OCCLUDED = 9;
165 private static final int KEYGUARD_TIMEOUT = 10;
166 private static final int DISMISS = 11;
167 private static final int START_KEYGUARD_EXIT_ANIM = 12;
168 private static final int KEYGUARD_DONE_PENDING_TIMEOUT = 13;
169 private static final int NOTIFY_STARTED_WAKING_UP = 14;
170 private static final int NOTIFY_SCREEN_TURNED_ON = 15;
171 private static final int NOTIFY_SCREEN_TURNED_OFF = 16;
172 private static final int NOTIFY_STARTED_GOING_TO_SLEEP = 17;
Adrian Roos30a2ae62018-04-25 19:09:50 +0200173 private static final int SYSTEM_READY = 18;
Jim Miller9c20d0e2010-01-20 15:00:23 -0800174
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800175 /**
176 * The default amount of time we stay awake (used for all key input)
177 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100178 public static final int AWAKE_INTERVAL_DEFAULT_MS = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800179
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800180 /**
181 * How long to wait after the screen turns off due to timeout before
182 * turning on the keyguard (i.e, the user has this much time to turn
183 * the screen back on without having to face the keyguard).
184 */
Jim Millerbc4603b2010-08-30 21:21:34 -0700185 private static final int KEYGUARD_LOCK_AFTER_DELAY_DEFAULT = 5000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800186
187 /**
Craig Mautnerf1b67412012-09-19 13:18:29 -0700188 * How long we'll wait for the {@link ViewMediatorCallback#keyguardDoneDrawing()}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800189 * callback before unblocking a call to {@link #setKeyguardEnabled(boolean)}
190 * that is reenabling the keyguard.
191 */
192 private static final int KEYGUARD_DONE_DRAWING_TIMEOUT_MS = 2000;
Jim Miller9c20d0e2010-01-20 15:00:23 -0800193
Daniel Sandler74d188c2011-08-10 00:00:31 -0400194 /**
Evan Rosky13a58a92016-07-27 15:51:09 -0700195 * Boolean option for doKeyguardLocked/doKeyguardTimeout which, when set to true, forces the
196 * keyguard to show even if it is disabled for the current user.
197 */
198 public static final String OPTION_FORCE_SHOW = "force_show";
199
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700200 /** The stream type that the lock sounds are tied to. */
John Spurlockee5ad722015-03-03 16:17:21 -0500201 private int mUiSoundsStreamType;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700202
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800203 private AlarmManager mAlarmManager;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700204 private AudioManager mAudioManager;
Mike Lockwood5f892c12009-11-19 23:39:13 -0500205 private StatusBarManager mStatusBarManager;
Jorim Jaggie549a8d2017-05-15 02:40:05 +0200206 private final UiOffloadThread mUiOffloadThread = Dependency.get(UiOffloadThread.class);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800207
208 private boolean mSystemReady;
Jason Monkcf5a9532014-09-17 16:22:19 -0400209 private boolean mBootCompleted;
210 private boolean mBootSendUserPresent;
Adrian Roos1f8025a2016-12-27 10:12:13 -0800211 private boolean mShuttingDown;
Daniel Sandler0060a9b2010-03-15 23:09:57 -0400212
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800213 /** High level access to the power manager for WakeLocks */
214 private PowerManager mPM;
215
Adrian Roos481a6df2014-11-20 19:48:56 +0100216 /** TrustManager for letting it know when we change visibility */
217 private TrustManager mTrustManager;
Amith Yamasanib70ff9a2012-09-07 18:28:11 -0700218
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800219 /**
Mike Lockwood674d3e42009-10-06 09:28:54 -0400220 * Used to keep the device awake while to ensure the keyguard finishes opening before
221 * we sleep.
222 */
223 private PowerManager.WakeLock mShowKeyguardWakeLock;
224
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100225 private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800226
227 // these are protected by synchronized (this)
228
229 /**
Mike Lockwood5d258b62009-12-02 13:50:45 -0500230 * External apps (like the phone app) can tell us to disable the keygaurd.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800231 */
232 private boolean mExternallyEnabled = true;
233
234 /**
235 * Remember if an external call to {@link #setKeyguardEnabled} with value
236 * false caused us to hide the keyguard, so that we need to reshow it once
237 * the keygaurd is reenabled with another call with value true.
238 */
239 private boolean mNeedToReshowWhenReenabled = false;
240
241 // cached value of whether we are showing (need to know this to quickly
242 // answer whether the input should be restricted)
Jim Millere5f17ab2013-11-13 15:40:48 -0800243 private boolean mShowing;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800244
Lucas Dupin47a65c72018-02-15 14:16:18 -0800245 // AOD is enabled and status bar is in AOD state.
246 private boolean mAodShowing;
247
Jim Millerab954542014-10-10 18:21:49 -0700248 /** Cached value of #isInputRestricted */
249 private boolean mInputRestricted;
250
Mike Lockwood09a40402009-11-08 00:33:23 -0500251 // true if the keyguard is hidden by another window
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100252 private boolean mOccluded = false;
Mike Lockwood09a40402009-11-08 00:33:23 -0500253
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800254 /**
255 * Helps remember whether the screen has turned on since the last time
256 * it turned off due to timeout. see {@link #onScreenTurnedOff(int)}
257 */
258 private int mDelayedShowingSequence;
259
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800260 /**
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000261 * Simiar to {@link #mDelayedProfileShowingSequence}, but it is for profile case.
262 */
263 private int mDelayedProfileShowingSequence;
264
265 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800266 * If the user has disabled the keyguard, then requests to exit, this is
267 * how we'll ultimately let them know whether it was successful. We use this
268 * var being non-null as an indicator that there is an in progress request.
269 */
Jim Miller25190572013-02-28 17:36:24 -0800270 private IKeyguardExitCallback mExitSecureCallback;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700271 private final DismissCallbackRegistry mDismissCallbackRegistry = new DismissCallbackRegistry();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800272
273 // the properties of the keyguard
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800274
275 private KeyguardUpdateMonitor mUpdateMonitor;
276
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700277 /**
278 * Last SIM state reported by the telephony system.
279 * Index is the slotId - in case of multiple SIM cards.
280 */
281 private final SparseArray<IccCardConstants.State> mLastSimStates = new SparseArray<>();
282
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700283 private boolean mDeviceInteractive;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700284 private boolean mGoingToSleep;
Karl Rosaenab100082009-03-24 22:35:17 -0700285
Daniel Sandlerf2d8e742010-02-22 13:09:48 -0500286 // last known state of the cellular connection
287 private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE;
288
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800289 /**
Jorim Jaggi53c68a42014-06-17 15:04:47 -0700290 * Whether a hide is pending an we are just waiting for #startKeyguardExitAnimation to be
291 * called.
292 * */
293 private boolean mHiding;
294
295 /**
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700296 * we send this intent when the keyguard is dismissed.
297 */
Jim Miller17f509a2013-02-28 18:36:12 -0800298 private static final Intent USER_PRESENT_INTENT = new Intent(Intent.ACTION_USER_PRESENT)
299 .addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
Chad Brubaker291df4f2017-03-14 10:23:02 -0700300 | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
301 | Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700302
303 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800304 * {@link #setKeyguardEnabled} waits on this condition when it reenables
305 * the keyguard.
306 */
307 private boolean mWaitingUntilKeyguardVisible = false;
Jim Millerbc4603b2010-08-30 21:21:34 -0700308 private LockPatternUtils mLockPatternUtils;
John Spurlock34c4fe52012-11-07 10:12:29 -0500309 private boolean mKeyguardDonePending = false;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200310 private boolean mHideAnimationRun = false;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700311 private boolean mHideAnimationRunning = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800312
Marco Nelissend5545bd2011-09-29 12:49:17 -0700313 private SoundPool mLockSounds;
314 private int mLockSoundId;
315 private int mUnlockSoundId;
Adrian Roos49e057d2014-08-13 17:14:51 +0200316 private int mTrustedSoundId;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700317 private int mLockSoundStreamId;
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700318
319 /**
Adrian Roos0002a452014-07-03 13:46:07 +0200320 * The animation used for hiding keyguard. This is used to fetch the animation timings if
321 * WindowManager is not providing us with them.
322 */
323 private Animation mHideAnimation;
324
325 /**
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700326 * The volume applied to the lock/unlock sounds.
327 */
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200328 private float mLockSoundVolume;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700329
Jim Millerdcb3d842012-08-23 19:18:12 -0700330 /**
Jim Miller31921482013-11-06 20:43:55 -0800331 * For managing external displays
332 */
333 private KeyguardDisplayManager mKeyguardDisplayManager;
334
Jim Millerab954542014-10-10 18:21:49 -0700335 private final ArrayList<IKeyguardStateCallback> mKeyguardStateCallbacks = new ArrayList<>();
336
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700337 /**
338 * When starting going to sleep, we figured out that we need to reset Keyguard state and this
339 * should be committed when finished going to sleep.
340 */
341 private boolean mPendingReset;
342
343 /**
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700344 * When starting going to sleep, we figured out that we need to lock Keyguard and this should be
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700345 * committed when finished going to sleep.
346 */
347 private boolean mPendingLock;
348
Robin Leec41f6ec2017-01-10 17:02:34 +0000349 /**
350 * Controller for showing individual "work challenge" lock screen windows inside managed profile
351 * tasks when the current user has been unlocked but the profile is still locked.
352 */
353 private WorkLockActivityController mWorkLockController;
354
Lucas Dupind35502f2018-06-27 13:35:52 -0700355 /**
356 * @see #setPulsing(boolean)
357 */
358 private boolean mPulsing;
359
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000360 private boolean mLockLater;
361
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700362 private boolean mWakeAndUnlocking;
363 private IKeyguardDrawnCallback mDrawnCallback;
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800364 private boolean mLockWhenSimRemoved;
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800365 private CharSequence mCustomMessage;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700366
Jim Millerbbf1a742012-07-17 18:30:30 -0700367 KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {
368
369 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500370 public void onUserSwitching(int userId) {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700371 // Note that the mLockPatternUtils user has already been updated from setCurrentUser.
Adam Cohenf7522022012-10-03 20:03:18 -0700372 // We need to force a reset of the views, since lockNow (called by
373 // ActivityManagerService) will not reconstruct the keyguard if it is already showing.
Jim Millerbbf1a742012-07-17 18:30:30 -0700374 synchronized (KeyguardViewMediator.this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100375 resetKeyguardDonePendingLocked();
Alex Chau77ef9fc2018-04-11 15:41:32 +0100376 if (mLockPatternUtils.isLockScreenDisabled(userId)) {
377 // If we switching to a user that has keyguard disabled, dismiss keyguard.
378 dismiss(null /* callback */, null /* message */);
379 } else {
380 resetStateLocked();
381 }
John Spurlock4e6922d2012-10-04 14:51:51 -0400382 adjustStatusBarLocked();
Dianne Hackborn5dc5a002012-09-15 19:33:48 -0700383 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700384 }
385
386 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500387 public void onUserSwitchComplete(int userId) {
Xiaohui Chen87d0e252015-07-30 15:38:16 -0700388 if (userId != UserHandle.USER_SYSTEM) {
Adrian Roosbe47b072014-09-03 00:08:56 +0200389 UserInfo info = UserManager.get(mContext).getUserInfo(userId);
Kevin Chynf2c0a642017-05-25 11:29:08 -0700390 // Don't try to dismiss if the user has Pin/Patter/Password set
391 if (info == null || mLockPatternUtils.isSecure(userId)) {
392 return;
393 } else if (info.isGuest() || info.isDemo()) {
Adrian Roosbe47b072014-09-03 00:08:56 +0200394 // If we just switched to a guest, try to dismiss keyguard.
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800395 dismiss(null /* callback */, null /* message */);
Adrian Roosbe47b072014-09-03 00:08:56 +0200396 }
397 }
Chris Wrenf41c61b2012-11-29 15:19:54 -0500398 }
399
400 @Override
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -0700401 public void onUserInfoChanged(int userId) {
Jim Millerbbf1a742012-07-17 18:30:30 -0700402 }
403
404 @Override
Jim Millerb0304762012-03-13 20:01:25 -0700405 public void onClockVisibilityChanged() {
406 adjustStatusBarLocked();
407 }
408
409 @Override
410 public void onDeviceProvisioned() {
Jim Miller3fd47af2012-09-21 19:55:27 -0700411 sendUserPresentBroadcast();
Amith Yamasanicb15d662015-11-10 11:11:15 -0800412 synchronized (KeyguardViewMediator.this) {
413 // If system user is provisioned, we might want to lock now to avoid showing launcher
Amith Yamasanieb437d42016-04-29 09:31:25 -0700414 if (mustNotUnlockCurrentUser()) {
Amith Yamasanicb15d662015-11-10 11:11:15 -0800415 doKeyguardLocked(null);
416 }
417 }
Jim Millerb0304762012-03-13 20:01:25 -0700418 }
419
Jim Millerbbf1a742012-07-17 18:30:30 -0700420 @Override
Jim Miller52a61332014-11-12 19:29:51 -0800421 public void onSimStateChanged(int subId, int slotId, IccCardConstants.State simState) {
422
423 if (DEBUG_SIM_STATES) {
424 Log.d(TAG, "onSimStateChanged(subId=" + subId + ", slotId=" + slotId
425 + ",state=" + simState + ")");
426 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700427
dooyoung.hwang328472e2015-05-21 16:09:43 +0900428 int size = mKeyguardStateCallbacks.size();
429 boolean simPinSecure = mUpdateMonitor.isSimPinSecure();
430 for (int i = size - 1; i >= 0; i--) {
431 try {
Jim Millerab954542014-10-10 18:21:49 -0700432 mKeyguardStateCallbacks.get(i).onSimSecureStateChanged(simPinSecure);
dooyoung.hwang328472e2015-05-21 16:09:43 +0900433 } catch (RemoteException e) {
434 Slog.w(TAG, "Failed to call onSimSecureStateChanged", e);
435 if (e instanceof DeadObjectException) {
436 mKeyguardStateCallbacks.remove(i);
437 }
Jim Millerab954542014-10-10 18:21:49 -0700438 }
Jim Millerab954542014-10-10 18:21:49 -0700439 }
440
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700441 boolean simWasLocked;
442 synchronized (KeyguardViewMediator.this) {
443 IccCardConstants.State lastState = mLastSimStates.get(slotId);
Brad Ebingere6c6f722018-12-20 21:11:44 -0800444 simWasLocked = (lastState == PIN_REQUIRED || lastState == PUK_REQUIRED);
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700445 mLastSimStates.append(slotId, simState);
446 }
447
Jim Millerbbf1a742012-07-17 18:30:30 -0700448 switch (simState) {
449 case NOT_READY:
450 case ABSENT:
451 // only force lock screen in case of missing sim if user hasn't
452 // gone through setup wizard
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800453 synchronized (KeyguardViewMediator.this) {
Jim Millerb256e4e22014-10-31 17:27:13 -0700454 if (shouldWaitForProvisioning()) {
Jim Millerab954542014-10-10 18:21:49 -0700455 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800456 if (DEBUG_SIM_STATES) Log.d(TAG, "ICC_ABSENT isn't showing,"
Jim Millerbbf1a742012-07-17 18:30:30 -0700457 + " we need to show the keyguard since the "
458 + "device isn't provisioned yet.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800459 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700460 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100461 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700462 }
463 }
Adrian Roose92de952016-12-13 12:07:09 -0800464 if (simState == ABSENT) {
465 // MVNO SIMs can become transiently NOT_READY when switching networks,
466 // so we should only lock when they are ABSENT.
467 onSimAbsentLocked();
Lucas Dupin2e0d4952018-12-05 20:03:53 -0800468 if (simWasLocked) {
Brad Ebingere6c6f722018-12-20 21:11:44 -0800469 if (DEBUG_SIM_STATES) Log.d(TAG, "SIM moved to ABSENT when the "
470 + "previous state was locked. Reset the state.");
Lucas Dupin2e0d4952018-12-05 20:03:53 -0800471 resetStateLocked();
472 }
Adrian Roose92de952016-12-13 12:07:09 -0800473 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700474 }
475 break;
476 case PIN_REQUIRED:
477 case PUK_REQUIRED:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800478 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700479 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800480 if (DEBUG_SIM_STATES) Log.d(TAG,
481 "INTENT_VALUE_ICC_LOCKED and keygaurd isn't "
Jim Millerbbf1a742012-07-17 18:30:30 -0700482 + "showing; need to show keyguard so user can enter sim pin");
Jim Miller5ecd8112013-01-09 18:50:26 -0800483 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700484 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100485 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700486 }
487 }
488 break;
489 case PERM_DISABLED:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800490 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700491 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800492 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED and "
Jim Millerbbf1a742012-07-17 18:30:30 -0700493 + "keygaurd isn't showing.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800494 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700495 } else {
Jim Miller52a61332014-11-12 19:29:51 -0800496 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED, resetStateLocked to"
Jim Millerbbf1a742012-07-17 18:30:30 -0700497 + "show permanently disabled message in lockscreen.");
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100498 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700499 }
Adrian Roose92de952016-12-13 12:07:09 -0800500 onSimAbsentLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700501 }
502 break;
503 case READY:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800504 synchronized (KeyguardViewMediator.this) {
Lucas Dupinab3079d2018-06-07 09:41:18 -0700505 if (DEBUG_SIM_STATES) Log.d(TAG, "READY, reset state? " + mShowing);
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700506 if (mShowing && simWasLocked) {
Brad Ebingere6c6f722018-12-20 21:11:44 -0800507 if (DEBUG_SIM_STATES) Log.d(TAG, "SIM moved to READY when the "
508 + "previous state was locked. Reset the state.");
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700509 resetStateLocked();
510 }
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800511 mLockWhenSimRemoved = true;
Jim Millerbbf1a742012-07-17 18:30:30 -0700512 }
513 break;
Jim Miller52a61332014-11-12 19:29:51 -0800514 default:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800515 if (DEBUG_SIM_STATES) Log.v(TAG, "Unspecific state: " + simState);
Jim Miller52a61332014-11-12 19:29:51 -0800516 break;
Jim Millerbbf1a742012-07-17 18:30:30 -0700517 }
518 }
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000519
Adrian Roose92de952016-12-13 12:07:09 -0800520 private void onSimAbsentLocked() {
Adrian Roos1f8025a2016-12-27 10:12:13 -0800521 if (isSecure() && mLockWhenSimRemoved && !mShuttingDown) {
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800522 mLockWhenSimRemoved = false;
523 MetricsLogger.action(mContext,
524 MetricsProto.MetricsEvent.ACTION_LOCK_BECAUSE_SIM_REMOVED, mShowing);
525 if (!mShowing) {
Adrian Roose92de952016-12-13 12:07:09 -0800526 Log.i(TAG, "SIM removed, showing keyguard");
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800527 doKeyguardLocked(null);
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800528 }
529 }
530 }
531
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000532 @Override
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200533 public void onBiometricAuthFailed(BiometricSourceType biometricSourceType) {
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000534 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
535 if (mLockPatternUtils.isSecure(currentUser)) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200536 mLockPatternUtils.getDevicePolicyManager().reportFailedBiometricAttempt(
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000537 currentUser);
538 }
539 }
540
541 @Override
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200542 public void onBiometricAuthenticated(int userId, BiometricSourceType biometricSourceType) {
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000543 if (mLockPatternUtils.isSecure(userId)) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200544 mLockPatternUtils.getDevicePolicyManager().reportSuccessfulBiometricAttempt(
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000545 userId);
546 }
547 }
Adrian Roosd88eb262016-08-04 14:50:48 -0700548
549 @Override
550 public void onTrustChanged(int userId) {
551 if (userId == KeyguardUpdateMonitor.getCurrentUser()) {
552 synchronized (KeyguardViewMediator.this) {
553 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(userId));
554 }
555 }
556 }
557
Jorim Jaggid11d1a92016-08-16 16:02:32 -0700558 @Override
559 public void onHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
560 synchronized (KeyguardViewMediator.this) {
561 notifyHasLockscreenWallpaperChanged(hasLockscreenWallpaper);
562 }
563 }
Jim Millerb0304762012-03-13 20:01:25 -0700564 };
565
Jim Millerdcb3d842012-08-23 19:18:12 -0700566 ViewMediatorCallback mViewMediatorCallback = new ViewMediatorCallback() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100567
Jim Miller2967f482016-01-07 15:05:32 -0800568 @Override
Jeff Brownc7505bc2012-10-05 21:58:15 -0700569 public void userActivity() {
570 KeyguardViewMediator.this.userActivity();
571 }
572
Jim Miller2967f482016-01-07 15:05:32 -0800573 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700574 public void keyguardDone(boolean strongAuth, int targetUserId) {
575 if (targetUserId != ActivityManager.getCurrentUser()) {
576 return;
577 }
578
Jorim Jaggi241ae102016-11-02 21:57:33 -0700579 tryKeyguardDone();
Jim Millerdcb3d842012-08-23 19:18:12 -0700580 }
581
Jim Miller2967f482016-01-07 15:05:32 -0800582 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700583 public void keyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700584 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDoneDrawing");
Jim Millerdcb3d842012-08-23 19:18:12 -0700585 mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700586 Trace.endSection();
Jim Millerdcb3d842012-08-23 19:18:12 -0700587 }
588
589 @Override
590 public void setNeedsInput(boolean needsInput) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100591 mStatusBarKeyguardViewManager.setNeedsInput(needsInput);
Jim Millerdcb3d842012-08-23 19:18:12 -0700592 }
Jeff Brownc7505bc2012-10-05 21:58:15 -0700593
594 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700595 public void keyguardDonePending(boolean strongAuth, int targetUserId) {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700596 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDonePending");
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700597 if (targetUserId != ActivityManager.getCurrentUser()) {
Nick Desaulniersaeb2e1e2016-07-27 15:36:01 -0700598 Trace.endSection();
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700599 return;
600 }
601
John Spurlock34c4fe52012-11-07 10:12:29 -0500602 mKeyguardDonePending = true;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200603 mHideAnimationRun = true;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700604 mHideAnimationRunning = true;
605 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100606 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_PENDING_TIMEOUT,
607 KEYGUARD_DONE_PENDING_TIMEOUT_MS);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700608 Trace.endSection();
John Spurlock34c4fe52012-11-07 10:12:29 -0500609 }
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800610
611 @Override
612 public void keyguardGone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700613 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardGone");
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800614 mKeyguardDisplayManager.hide();
Nick Desaulniers1d396752016-07-25 15:05:33 -0700615 Trace.endSection();
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800616 }
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200617
618 @Override
619 public void readyForKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700620 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#readyForKeyguardDone");
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200621 if (mKeyguardDonePending) {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700622 mKeyguardDonePending = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700623 tryKeyguardDone();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200624 }
Nick Desaulniers1d396752016-07-25 15:05:33 -0700625 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200626 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200627
628 @Override
Andrew Lee72b46d42015-01-30 13:23:21 -0800629 public void resetKeyguard() {
630 resetStateLocked();
631 }
632
633 @Override
Aarthi Balachander0a427ef2018-07-13 15:00:58 -0700634 public void onCancelClicked() {
635 mStatusBarKeyguardViewManager.onCancelClicked();
636 }
637
638 @Override
Matthew Ng66f0b702017-12-08 12:58:42 -0800639 public void onBouncerVisiblityChanged(boolean shown) {
640 synchronized (KeyguardViewMediator.this) {
641 adjustStatusBarLocked(shown);
642 }
643 }
644
645 @Override
Adrian Roos49e057d2014-08-13 17:14:51 +0200646 public void playTrustedSound() {
647 KeyguardViewMediator.this.playTrustedSound();
648 }
Jim Millerab954542014-10-10 18:21:49 -0700649
650 @Override
Adrian Roos94e15a52015-04-16 12:23:18 -0700651 public boolean isScreenOn() {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700652 return mDeviceInteractive;
Adrian Roos94e15a52015-04-16 12:23:18 -0700653 }
Selim Cinek3122fa82015-06-18 01:38:59 -0700654
655 @Override
656 public int getBouncerPromptReason() {
657 int currentUser = ActivityManager.getCurrentUser();
Adrian Roosc13723f2016-01-12 20:29:03 +0100658 boolean trust = mTrustManager.isTrustUsuallyManaged(currentUser);
659 boolean fingerprint = mUpdateMonitor.isUnlockWithFingerprintPossible(currentUser);
660 boolean any = trust || fingerprint;
661 KeyguardUpdateMonitor.StrongAuthTracker strongAuthTracker =
662 mUpdateMonitor.getStrongAuthTracker();
663 int strongAuth = strongAuthTracker.getStrongAuthForUser(currentUser);
664
665 if (any && !strongAuthTracker.hasUserAuthenticatedSinceBoot()) {
Selim Cinek3122fa82015-06-18 01:38:59 -0700666 return KeyguardSecurityView.PROMPT_REASON_RESTART;
Michal Karpinskic52f8672016-11-18 11:32:45 +0000667 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_TIMEOUT) != 0) {
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700668 return KeyguardSecurityView.PROMPT_REASON_TIMEOUT;
Adrian Roosc13723f2016-01-12 20:29:03 +0100669 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW) != 0) {
670 return KeyguardSecurityView.PROMPT_REASON_DEVICE_ADMIN;
671 } else if (trust && (strongAuth & SOME_AUTH_REQUIRED_AFTER_USER_REQUEST) != 0) {
672 return KeyguardSecurityView.PROMPT_REASON_USER_REQUEST;
673 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_LOCKOUT) != 0) {
674 return KeyguardSecurityView.PROMPT_REASON_AFTER_LOCKOUT;
Selim Cinek3122fa82015-06-18 01:38:59 -0700675 }
676 return KeyguardSecurityView.PROMPT_REASON_NONE;
677 }
David Stevens53a39ea2017-08-23 18:41:49 -0700678
679 @Override
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800680 public CharSequence consumeCustomMessage() {
681 final CharSequence message = mCustomMessage;
682 mCustomMessage = null;
683 return message;
684 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700685 };
686
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200687 public void userActivity() {
Jeff Brown3dc524b2012-09-30 19:49:11 -0700688 mPM.userActivity(SystemClock.uptimeMillis(), false);
Jim Millerdcb3d842012-08-23 19:18:12 -0700689 }
690
Amith Yamasanieb437d42016-04-29 09:31:25 -0700691 boolean mustNotUnlockCurrentUser() {
Christine Franks338c6ed2017-08-08 09:39:16 -0700692 return UserManager.isSplitSystemUser()
Amith Yamasanieb437d42016-04-29 09:31:25 -0700693 && KeyguardUpdateMonitor.getCurrentUser() == UserHandle.USER_SYSTEM;
694 }
695
Jim Millerab954542014-10-10 18:21:49 -0700696 private void setupLocked() {
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200697 mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
Adrian Roos481a6df2014-11-20 19:48:56 +0100698 mTrustManager = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE);
699
Mike Lockwood674d3e42009-10-06 09:28:54 -0400700 mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
701 mShowKeyguardWakeLock.setReferenceCounted(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800702
Adrian Roos1f8025a2016-12-27 10:12:13 -0800703 IntentFilter filter = new IntentFilter();
Adrian Roos1f8025a2016-12-27 10:12:13 -0800704 filter.addAction(Intent.ACTION_SHUTDOWN);
705 mContext.registerReceiver(mBroadcastReceiver, filter);
Jim Millerbbf1a742012-07-17 18:30:30 -0700706
Kevin Chyn18e91aa2018-04-11 12:55:45 -0700707 final IntentFilter delayedActionFilter = new IntentFilter();
708 delayedActionFilter.addAction(DELAYED_KEYGUARD_ACTION);
709 delayedActionFilter.addAction(DELAYED_LOCK_PROFILE_ACTION);
710 mContext.registerReceiver(mDelayedLockBroadcastReceiver, delayedActionFilter,
711 SYSTEMUI_PERMISSION, null /* scheduler */);
712
wilsonshih177261f2019-02-22 12:02:18 +0800713 mKeyguardDisplayManager = new KeyguardDisplayManager(mContext);
Jim Miller31921482013-11-06 20:43:55 -0800714
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200715 mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800716
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200717 mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800718
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200719 mLockPatternUtils = new LockPatternUtils(mContext);
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700720 KeyguardUpdateMonitor.setCurrentUser(ActivityManager.getCurrentUser());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800721
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200722 // Assume keyguard is showing (unless it's disabled) until we know for sure, unless Keyguard
723 // is disabled.
724 if (mContext.getResources().getBoolean(
725 com.android.keyguard.R.bool.config_enableKeyguardService)) {
726 setShowingLocked(!shouldWaitForProvisioning()
727 && !mLockPatternUtils.isLockScreenDisabled(
David Stevens53a39ea2017-08-23 18:41:49 -0700728 KeyguardUpdateMonitor.getCurrentUser()),
wilsonshih177261f2019-02-22 12:02:18 +0800729 mAodShowing, true /* forceCallbacks */);
Leif Hendrik Wildenc6dc1c92018-02-01 10:54:15 -0800730 } else {
731 // The system's keyguard is disabled or missing.
wilsonshih177261f2019-02-22 12:02:18 +0800732 setShowingLocked(false, mAodShowing, true);
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200733 }
Jim Millere5f17ab2013-11-13 15:40:48 -0800734
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800735 mStatusBarKeyguardViewManager =
736 SystemUIFactory.getInstance().createStatusBarKeyguardViewManager(mContext,
737 mViewMediatorCallback, mLockPatternUtils);
Daniel Sandler687a3272010-03-13 15:44:47 -0500738 final ContentResolver cr = mContext.getContentResolver();
Marco Nelissend5545bd2011-09-29 12:49:17 -0700739
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700740 mDeviceInteractive = mPM.isInteractive();
Daniel Hansson4b716862012-03-29 11:02:05 +0200741
Jean-Michel Trivi0616db42019-01-28 10:57:21 -0800742 mLockSounds = new SoundPool.Builder()
743 .setMaxStreams(1)
744 .setAudioAttributes(
745 new AudioAttributes.Builder()
746 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
747 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
748 .build())
749 .build();
Jim Millerb14288d2012-09-30 18:25:05 -0700750 String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700751 if (soundPath != null) {
752 mLockSoundId = mLockSounds.load(soundPath, 1);
753 }
754 if (soundPath == null || mLockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700755 Log.w(TAG, "failed to load lock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700756 }
Jim Millerb14288d2012-09-30 18:25:05 -0700757 soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700758 if (soundPath != null) {
759 mUnlockSoundId = mLockSounds.load(soundPath, 1);
760 }
761 if (soundPath == null || mUnlockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700762 Log.w(TAG, "failed to load unlock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700763 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200764 soundPath = Settings.Global.getString(cr, Settings.Global.TRUSTED_SOUND);
765 if (soundPath != null) {
766 mTrustedSoundId = mLockSounds.load(soundPath, 1);
767 }
768 if (soundPath == null || mTrustedSoundId == 0) {
769 Log.w(TAG, "failed to load trusted sound from " + soundPath);
770 }
771
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200772 int lockSoundDefaultAttenuation = mContext.getResources().getInteger(
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700773 com.android.internal.R.integer.config_lockSoundVolumeDb);
Jean-Michel Trivif2b0c112012-07-09 11:59:11 -0700774 mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20);
Adrian Roos0002a452014-07-03 13:46:07 +0200775
776 mHideAnimation = AnimationUtils.loadAnimation(mContext,
777 com.android.internal.R.anim.lock_screen_behind_enter);
Robin Leec41f6ec2017-01-10 17:02:34 +0000778
779 mWorkLockController = new WorkLockActivityController(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800780 }
781
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200782 @Override
783 public void start() {
Jim Millerab954542014-10-10 18:21:49 -0700784 synchronized (this) {
785 setupLocked();
786 }
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200787 putComponent(KeyguardViewMediator.class, this);
788 }
789
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800790 /**
791 * Let us know that the system is ready after startup.
792 */
793 public void onSystemReady() {
Adrian Roos30a2ae62018-04-25 19:09:50 +0200794 mHandler.obtainMessage(SYSTEM_READY).sendToTarget();
795 }
796
797 private void handleSystemReady() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800798 synchronized (this) {
799 if (DEBUG) Log.d(TAG, "onSystemReady");
800 mSystemReady = true;
Jim Miller5ecd8112013-01-09 18:50:26 -0800801 doKeyguardLocked(null);
Selim Cinekedd32b82015-06-23 22:05:58 -0400802 mUpdateMonitor.registerCallback(mUpdateCallback);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800803 }
Jim Miller3fd47af2012-09-21 19:55:27 -0700804 // Most services aren't available until the system reaches the ready state, so we
805 // send it here when the device first boots.
806 maybeSendUserPresentBroadcast();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800807 }
808
809 /**
810 * Called to let us know the screen was turned off.
Adrian Roose99bc052017-11-20 17:55:31 +0100811 * @param why either {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_USER} or
812 * {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_TIMEOUT}.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800813 */
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700814 public void onStartedGoingToSleep(int why) {
815 if (DEBUG) Log.d(TAG, "onStartedGoingToSleep(" + why + ")");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800816 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700817 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700818 mGoingToSleep = true;
John Spurlock14adfe42012-11-08 10:29:26 -0500819
Jim Millera4edd152012-01-06 18:24:04 -0800820 // Lock immediately based on setting if secure (user has a pin/pattern/password).
821 // This also "locks" the device when not secure to provide easy access to the
822 // camera while preventing unwanted input.
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700823 int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jim Millera4edd152012-01-06 18:24:04 -0800824 final boolean lockImmediately =
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700825 mLockPatternUtils.getPowerButtonInstantlyLocks(currentUser)
826 || !mLockPatternUtils.isSecure(currentUser);
Clara Bayarri56878a92015-10-29 15:43:55 +0000827 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000828 mLockLater = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800829 if (mExitSecureCallback != null) {
830 if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled");
Jim Miller5ecd8112013-01-09 18:50:26 -0800831 try {
832 mExitSecureCallback.onKeyguardExitResult(false);
833 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800834 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800835 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800836 mExitSecureCallback = null;
837 if (!mExternallyEnabled) {
Jim Miller9c20d0e2010-01-20 15:00:23 -0800838 hideLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800839 }
840 } else if (mShowing) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700841 mPendingReset = true;
Adrian Roose99bc052017-11-20 17:55:31 +0100842 } else if ((why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_TIMEOUT && timeout > 0)
843 || (why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER && !lockImmediately)) {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700844 doKeyguardLaterLocked(timeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000845 mLockLater = true;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700846 } else if (!mLockPatternUtils.isLockScreenDisabled(currentUser)) {
847 mPendingLock = true;
848 }
849
Jorim Jaggi853cbe32015-06-04 16:31:54 -0700850 if (mPendingLock) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700851 playSounds(true);
852 }
853 }
Jorim Jaggi95e40382015-09-16 15:53:42 -0700854 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedGoingToSleep(why);
Jorim Jaggi18f18ae2015-09-10 15:48:21 -0700855 notifyStartedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700856 }
857
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700858 public void onFinishedGoingToSleep(int why, boolean cameraGestureTriggered) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700859 if (DEBUG) Log.d(TAG, "onFinishedGoingToSleep(" + why + ")");
860 synchronized (this) {
861 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700862 mGoingToSleep = false;
Adrian Roose4cb6c8a2017-07-19 18:08:07 +0200863 mWakeAndUnlocking = false;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700864
865 resetKeyguardDonePendingLocked();
866 mHideAnimationRun = false;
867
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700868 notifyFinishedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700869
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700870 if (cameraGestureTriggered) {
871 Log.i(TAG, "Camera gesture was triggered, preventing Keyguard locking.");
872
873 // Just to make sure, make sure the device is awake.
874 mContext.getSystemService(PowerManager.class).wakeUp(SystemClock.uptimeMillis(),
Michael Wrighte3001042019-02-05 00:13:14 +0000875 PowerManager.WAKE_REASON_CAMERA_LAUNCH,
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700876 "com.android.systemui:CAMERA_GESTURE_PREVENT_LOCK");
877 mPendingLock = false;
878 mPendingReset = false;
879 }
880
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700881 if (mPendingReset) {
882 resetStateLocked();
883 mPendingReset = false;
884 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000885
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700886 if (mPendingLock) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800887 doKeyguardLocked(null);
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700888 mPendingLock = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800889 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000890
891 // We do not have timeout and power button instant lock setting for profile lock.
892 // So we use the personal setting if there is any. But if there is no device
893 // we need to make sure we lock it immediately when the screen is off.
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700894 if (!mLockLater && !cameraGestureTriggered) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000895 doKeyguardForChildProfilesLocked();
896 }
897
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800898 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700899 KeyguardUpdateMonitor.getInstance(mContext).dispatchFinishedGoingToSleep(why);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800900 }
901
Clara Bayarri56878a92015-10-29 15:43:55 +0000902 private long getLockTimeout(int userId) {
Jeff Brown6aaf2952012-10-05 16:01:08 -0700903 // if the screen turned off because of timeout or the user hit the power button
904 // and we don't need to lock immediately, set an alarm
905 // to enable it a little bit later (i.e, give the user a chance
906 // to turn the screen back on within a certain window without
907 // having to unlock the screen)
908 final ContentResolver cr = mContext.getContentResolver();
909
Jeff Brown6aaf2952012-10-05 16:01:08 -0700910 // From SecuritySettings
911 final long lockAfterTimeout = Settings.Secure.getInt(cr,
912 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT,
913 KEYGUARD_LOCK_AFTER_DELAY_DEFAULT);
914
915 // From DevicePolicyAdmin
916 final long policyTimeout = mLockPatternUtils.getDevicePolicyManager()
Pavel Grafov28939982017-10-03 15:11:52 +0100917 .getMaximumTimeToLock(null, userId);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700918
919 long timeout;
Clara Bayarri56878a92015-10-29 15:43:55 +0000920
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000921 if (policyTimeout <= 0) {
Clara Bayarri56878a92015-10-29 15:43:55 +0000922 timeout = lockAfterTimeout;
923 } else {
924 // From DisplaySettings
925 long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT,
926 KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT);
927
Jeff Brown6aaf2952012-10-05 16:01:08 -0700928 // policy in effect. Make sure we don't go beyond policy limit.
929 displayTimeout = Math.max(displayTimeout, 0); // ignore negative values
930 timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000931 timeout = Math.max(timeout, 0);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700932 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700933 return timeout;
934 }
Jeff Brown6aaf2952012-10-05 16:01:08 -0700935
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700936 private void doKeyguardLaterLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000937 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700938 if (timeout == 0) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800939 doKeyguardLocked(null);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700940 } else {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700941 doKeyguardLaterLocked(timeout);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700942 }
943 }
944
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700945 private void doKeyguardLaterLocked(long timeout) {
946 // Lock in the future
947 long when = SystemClock.elapsedRealtime() + timeout;
948 Intent intent = new Intent(DELAYED_KEYGUARD_ACTION);
949 intent.putExtra("seq", mDelayedShowingSequence);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700950 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700951 PendingIntent sender = PendingIntent.getBroadcast(mContext,
952 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Jim Millera622d3cc2016-03-02 16:02:24 -0800953 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700954 if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = "
955 + mDelayedShowingSequence);
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000956 doKeyguardLaterForChildProfilesLocked();
Clara Bayarri56878a92015-10-29 15:43:55 +0000957 }
Clara Bayarri10ad84a2015-12-01 17:38:05 +0000958
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000959 private void doKeyguardLaterForChildProfilesLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000960 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700961 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
962 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
963 long userTimeout = getLockTimeout(profileId);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000964 if (userTimeout == 0) {
965 doKeyguardForChildProfilesLocked();
966 } else {
967 long userWhen = SystemClock.elapsedRealtime() + userTimeout;
968 Intent lockIntent = new Intent(DELAYED_LOCK_PROFILE_ACTION);
969 lockIntent.putExtra("seq", mDelayedProfileShowingSequence);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700970 lockIntent.putExtra(Intent.EXTRA_USER_ID, profileId);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700971 lockIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000972 PendingIntent lockSender = PendingIntent.getBroadcast(
973 mContext, 0, lockIntent, PendingIntent.FLAG_CANCEL_CURRENT);
974 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
975 userWhen, lockSender);
976 }
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000977 }
978 }
979 }
980
981 private void doKeyguardForChildProfilesLocked() {
982 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700983 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
984 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
985 lockProfile(profileId);
Clara Bayarri56878a92015-10-29 15:43:55 +0000986 }
987 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700988 }
989
Jeff Brown6aaf2952012-10-05 16:01:08 -0700990 private void cancelDoKeyguardLaterLocked() {
991 mDelayedShowingSequence++;
992 }
993
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000994 private void cancelDoKeyguardForChildProfilesLocked() {
995 mDelayedProfileShowingSequence++;
996 }
997
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800998 /**
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700999 * Let's us know when the device is waking up.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001000 */
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001001 public void onStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001002 Trace.beginSection("KeyguardViewMediator#onStartedWakingUp");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001003
1004 // TODO: Rename all screen off/on references to interactive/sleeping
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001005 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001006 mDeviceInteractive = true;
Jeff Brown6aaf2952012-10-05 16:01:08 -07001007 cancelDoKeyguardLaterLocked();
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001008 cancelDoKeyguardForChildProfilesLocked();
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001009 if (DEBUG) Log.d(TAG, "onStartedWakingUp, seq = " + mDelayedShowingSequence);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001010 notifyStartedWakingUp();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001011 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001012 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedWakingUp();
Jim Miller3fd47af2012-09-21 19:55:27 -07001013 maybeSendUserPresentBroadcast();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001014 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -07001015 }
1016
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001017 public void onScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001018 Trace.beginSection("KeyguardViewMediator#onScreenTurningOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001019 notifyScreenOn(callback);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001020 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001021 }
1022
1023 public void onScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001024 Trace.beginSection("KeyguardViewMediator#onScreenTurnedOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001025 notifyScreenTurnedOn();
1026 mUpdateMonitor.dispatchScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001027 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001028 }
1029
1030 public void onScreenTurnedOff() {
1031 notifyScreenTurnedOff();
1032 mUpdateMonitor.dispatchScreenTurnedOff();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001033 }
1034
Jim Miller3fd47af2012-09-21 19:55:27 -07001035 private void maybeSendUserPresentBroadcast() {
Adrian Roos8150d2a2015-04-16 17:11:20 -07001036 if (mSystemReady && mLockPatternUtils.isLockScreenDisabled(
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001037 KeyguardUpdateMonitor.getCurrentUser())) {
Jim Miller3fd47af2012-09-21 19:55:27 -07001038 // Lock screen is disabled because the user has set the preference to "None".
1039 // In this case, send out ACTION_USER_PRESENT here instead of in
1040 // handleKeyguardDone()
1041 sendUserPresentBroadcast();
Adrian Roosfb95a812016-06-20 14:58:59 -07001042 } else if (mSystemReady && shouldWaitForProvisioning()) {
1043 // Skipping the lockscreen because we're not yet provisioned, but we still need to
1044 // notify the StrongAuthTracker that it's now safe to run trust agents, in case the
1045 // user sets a credential later.
1046 getLockPatternUtils().userPresent(KeyguardUpdateMonitor.getCurrentUser());
Jim Miller3fd47af2012-09-21 19:55:27 -07001047 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001048 }
1049
1050 /**
Jeff Brown6aaf2952012-10-05 16:01:08 -07001051 * A dream started. We should lock after the usual screen-off lock timeout but only
1052 * if there is a secure lock pattern.
1053 */
1054 public void onDreamingStarted() {
Selim Cinek99415392016-09-09 14:58:41 -07001055 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001056 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001057 if (mDeviceInteractive
1058 && mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001059 doKeyguardLaterLocked();
1060 }
1061 }
1062 }
1063
1064 /**
1065 * A dream stopped.
1066 */
1067 public void onDreamingStopped() {
Selim Cinek99415392016-09-09 14:58:41 -07001068 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001069 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001070 if (mDeviceInteractive) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001071 cancelDoKeyguardLaterLocked();
1072 }
1073 }
1074 }
1075
1076 /**
Adrian Roose99bc052017-11-20 17:55:31 +01001077 * Same semantics as {@link WindowManagerPolicyConstants#enableKeyguard}; provide
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001078 * a way for external stuff to override normal keyguard behavior. For instance
1079 * the phone app disables the keyguard when it receives incoming calls.
1080 */
1081 public void setKeyguardEnabled(boolean enabled) {
1082 synchronized (this) {
1083 if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")");
1084
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001085 mExternallyEnabled = enabled;
1086
1087 if (!enabled && mShowing) {
1088 if (mExitSecureCallback != null) {
1089 if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring");
1090 // we're in the process of handling a request to verify the user
1091 // can get past the keyguard. ignore extraneous requests to disable / reenable
1092 return;
1093 }
1094
1095 // hiding keyguard that is showing, remember to reshow later
1096 if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, "
1097 + "disabling status bar expansion");
1098 mNeedToReshowWhenReenabled = true;
Jim Millerab954542014-10-10 18:21:49 -07001099 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001100 hideLocked();
1101 } else if (enabled && mNeedToReshowWhenReenabled) {
1102 // reenabled after previously hidden, reshow
1103 if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling "
1104 + "status bar expansion");
1105 mNeedToReshowWhenReenabled = false;
Jim Millerab954542014-10-10 18:21:49 -07001106 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001107
1108 if (mExitSecureCallback != null) {
1109 if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting");
Jim Miller5ecd8112013-01-09 18:50:26 -08001110 try {
1111 mExitSecureCallback.onKeyguardExitResult(false);
1112 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001113 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001114 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001115 mExitSecureCallback = null;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001116 resetStateLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001117 } else {
Adam Cohenf7522022012-10-03 20:03:18 -07001118 showLocked(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001119
1120 // block until we know the keygaurd is done drawing (and post a message
1121 // to unblock us after a timeout so we don't risk blocking too long
1122 // and causing an ANR).
1123 mWaitingUntilKeyguardVisible = true;
1124 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS);
1125 if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false");
1126 while (mWaitingUntilKeyguardVisible) {
1127 try {
1128 wait();
1129 } catch (InterruptedException e) {
1130 Thread.currentThread().interrupt();
1131 }
1132 }
1133 if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible");
1134 }
1135 }
1136 }
1137 }
1138
1139 /**
1140 * @see android.app.KeyguardManager#exitKeyguardSecurely
1141 */
Jim Miller25190572013-02-28 17:36:24 -08001142 public void verifyUnlock(IKeyguardExitCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001143 Trace.beginSection("KeyguardViewMediator#verifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001144 synchronized (this) {
1145 if (DEBUG) Log.d(TAG, "verifyUnlock");
Jim Millerb256e4e22014-10-31 17:27:13 -07001146 if (shouldWaitForProvisioning()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001147 // don't allow this api when the device isn't provisioned
1148 if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned");
Jim Miller5ecd8112013-01-09 18:50:26 -08001149 try {
Jim Miller25190572013-02-28 17:36:24 -08001150 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001151 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001152 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001153 }
Mike Lockwood5d258b62009-12-02 13:50:45 -05001154 } else if (mExternallyEnabled) {
1155 // this only applies when the user has externally disabled the
1156 // keyguard. this is unexpected and means the user is not
1157 // using the api properly.
1158 Log.w(TAG, "verifyUnlock called when not externally disabled");
Jim Miller5ecd8112013-01-09 18:50:26 -08001159 try {
Jim Miller25190572013-02-28 17:36:24 -08001160 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001161 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001162 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001163 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001164 } else if (mExitSecureCallback != null) {
1165 // already in progress with someone else
Jim Miller5ecd8112013-01-09 18:50:26 -08001166 try {
Jim Miller25190572013-02-28 17:36:24 -08001167 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001168 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001169 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001170 }
Jorim Jaggi302475e2015-09-22 12:44:47 -07001171 } else if (!isSecure()) {
1172
1173 // Keyguard is not secure, no need to do anything, and we don't need to reshow
1174 // the Keyguard after the client releases the Keyguard lock.
1175 mExternallyEnabled = true;
1176 mNeedToReshowWhenReenabled = false;
1177 updateInputRestricted();
1178 try {
1179 callback.onKeyguardExitResult(true);
1180 } catch (RemoteException e) {
1181 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1182 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001183 } else {
Jorim Jaggi302475e2015-09-22 12:44:47 -07001184
1185 // Since we prevent apps from hiding the Keyguard if we are secure, this should be
1186 // a no-op as well.
1187 try {
1188 callback.onKeyguardExitResult(false);
1189 } catch (RemoteException e) {
1190 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1191 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001192 }
1193 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001194 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001195 }
1196
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001197 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001198 * Is the keyguard currently showing and not being force hidden?
Mike Lockwood09a40402009-11-08 00:33:23 -05001199 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001200 public boolean isShowingAndNotOccluded() {
1201 return mShowing && !mOccluded;
1202 }
1203
1204 /**
1205 * Notify us when the keyguard is occluded by another window
1206 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001207 public void setOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001208 Trace.beginSection("KeyguardViewMediator#setOccluded");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001209 if (DEBUG) Log.d(TAG, "setOccluded " + isOccluded);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001210 mHandler.removeMessages(SET_OCCLUDED);
Jorim Jaggi6626f542016-08-22 13:08:44 -07001211 Message msg = mHandler.obtainMessage(SET_OCCLUDED, isOccluded ? 1 : 0, animate ? 1 : 0);
Mike Lockwood9200a392009-11-17 20:25:58 -05001212 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001213 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001214 }
1215
Lucas Dupin2986c152018-04-09 20:49:41 -07001216 public boolean isHiding() {
1217 return mHiding;
1218 }
1219
Mike Lockwood9200a392009-11-17 20:25:58 -05001220 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001221 * Handles SET_OCCLUDED message sent by setOccluded()
Mike Lockwood9200a392009-11-17 20:25:58 -05001222 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001223 private void handleSetOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001224 Trace.beginSection("KeyguardViewMediator#handleSetOccluded");
Mike Lockwood09a40402009-11-08 00:33:23 -05001225 synchronized (KeyguardViewMediator.this) {
Adrian Roosf253eeb2015-04-15 18:03:08 -07001226 if (mHiding && isOccluded) {
1227 // We're in the process of going away but WindowManager wants to show a
1228 // SHOW_WHEN_LOCKED activity instead.
1229 startKeyguardExitAnimation(0, 0);
1230 }
1231
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001232 if (mOccluded != isOccluded) {
1233 mOccluded = isOccluded;
Kevin Chyn2fefd462017-04-28 12:18:19 -07001234 mUpdateMonitor.setKeyguardOccluded(isOccluded);
Selim Cinek2f6272e2017-03-15 16:19:10 -07001235 mStatusBarKeyguardViewManager.setOccluded(isOccluded, animate
1236 && mDeviceInteractive);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001237 adjustStatusBarLocked();
Mike Lockwood9200a392009-11-17 20:25:58 -05001238 }
Mike Lockwood09a40402009-11-08 00:33:23 -05001239 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001240 Trace.endSection();
Mike Lockwood09a40402009-11-08 00:33:23 -05001241 }
1242
1243 /**
Mike Lockwood28569302010-01-28 11:54:40 -05001244 * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout.
1245 * This must be safe to call from any thread and with any window manager locks held.
1246 */
Adam Cohenf7522022012-10-03 20:03:18 -07001247 public void doKeyguardTimeout(Bundle options) {
Mike Lockwood28569302010-01-28 11:54:40 -05001248 mHandler.removeMessages(KEYGUARD_TIMEOUT);
Adam Cohenf7522022012-10-03 20:03:18 -07001249 Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options);
Mike Lockwood28569302010-01-28 11:54:40 -05001250 mHandler.sendMessage(msg);
1251 }
1252
1253 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001254 * Given the state of the keyguard, is the input restricted?
1255 * Input is restricted when the keyguard is showing, or when the keyguard
1256 * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet.
1257 */
1258 public boolean isInputRestricted() {
Adrian Roos9f33d6c2015-06-15 15:58:35 -07001259 return mShowing || mNeedToReshowWhenReenabled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001260 }
1261
Jim Millerab954542014-10-10 18:21:49 -07001262 private void updateInputRestricted() {
1263 synchronized (this) {
1264 updateInputRestrictedLocked();
1265 }
1266 }
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001267
Jim Millerab954542014-10-10 18:21:49 -07001268 private void updateInputRestrictedLocked() {
1269 boolean inputRestricted = isInputRestricted();
1270 if (mInputRestricted != inputRestricted) {
1271 mInputRestricted = inputRestricted;
dooyoung.hwang328472e2015-05-21 16:09:43 +09001272 int size = mKeyguardStateCallbacks.size();
1273 for (int i = size - 1; i >= 0; i--) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001274 final IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001275 try {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001276 callback.onInputRestrictedStateChanged(inputRestricted);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001277 } catch (RemoteException e) {
1278 Slog.w(TAG, "Failed to call onDeviceProvisioned", e);
1279 if (e instanceof DeadObjectException) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001280 mKeyguardStateCallbacks.remove(callback);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001281 }
Jim Millerab954542014-10-10 18:21:49 -07001282 }
Jim Millerab954542014-10-10 18:21:49 -07001283 }
1284 }
1285 }
1286
Dianne Hackbornb446e972009-09-20 15:23:25 -07001287 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001288 * Enable the keyguard if the settings are appropriate.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001289 */
Adam Cohenf7522022012-10-03 20:03:18 -07001290 private void doKeyguardLocked(Bundle options) {
Adrian Roosca8a2162017-08-17 19:00:58 +02001291 if (KeyguardUpdateMonitor.CORE_APPS_ONLY) {
1292 // Don't show keyguard during half-booted cryptkeeper stage.
1293 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because booting to cryptkeeper");
1294 return;
1295 }
1296
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001297 // if another app is disabling us, don't show
1298 if (!mExternallyEnabled) {
1299 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled");
Karl Rosaenab100082009-03-24 22:35:17 -07001300
Adrian Roos1c8e3c02018-11-20 20:07:55 +01001301 mNeedToReshowWhenReenabled = true;
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001302 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001303 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001304
1305 // if the keyguard is already showing, don't bother
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001306 if (mStatusBarKeyguardViewManager.isShowing()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001307 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing");
Jorim Jaggi95e89ca2014-11-24 20:12:50 +01001308 resetStateLocked();
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001309 return;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001310 }
1311
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001312 // In split system user mode, we never unlock system user.
Amith Yamasanieb437d42016-04-29 09:31:25 -07001313 if (!mustNotUnlockCurrentUser()
Amith Yamasani27e025b2015-11-06 10:34:41 -08001314 || !mUpdateMonitor.isDeviceProvisioned()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001315
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001316 // if the setup wizard hasn't run yet, don't show
1317 final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", false);
1318 final boolean absent = SubscriptionManager.isValidSubscriptionId(
Adrian Roose92de952016-12-13 12:07:09 -08001319 mUpdateMonitor.getNextSubIdForState(ABSENT));
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001320 final boolean disabled = SubscriptionManager.isValidSubscriptionId(
1321 mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.PERM_DISABLED));
1322 final boolean lockedOrMissing = mUpdateMonitor.isSimPinSecure()
1323 || ((absent || disabled) && requireSim);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001324
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001325 if (!lockedOrMissing && shouldWaitForProvisioning()) {
1326 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned"
1327 + " and the sim is not locked or missing");
1328 return;
1329 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001330
Evan Rosky13a58a92016-07-27 15:51:09 -07001331 boolean forceShow = options != null && options.getBoolean(OPTION_FORCE_SHOW, false);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001332 if (mLockPatternUtils.isLockScreenDisabled(KeyguardUpdateMonitor.getCurrentUser())
Evan Rosky13a58a92016-07-27 15:51:09 -07001333 && !lockedOrMissing && !forceShow) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001334 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off");
1335 return;
1336 }
1337
1338 if (mLockPatternUtils.checkVoldPassword(KeyguardUpdateMonitor.getCurrentUser())) {
1339 if (DEBUG) Log.d(TAG, "Not showing lock screen since just decrypted");
1340 // Without this, settings is not enabled until the lock screen first appears
Lucas Dupin47a65c72018-02-15 14:16:18 -08001341 setShowingLocked(false, mAodShowing);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001342 hideLocked();
1343 return;
1344 }
Paul Lawrence945490c2014-03-27 16:37:28 +00001345 }
1346
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001347 if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");
Adam Cohenf7522022012-10-03 20:03:18 -07001348 showLocked(options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001349 }
1350
Clara Bayarri56878a92015-10-29 15:43:55 +00001351 private void lockProfile(int userId) {
1352 mTrustManager.setDeviceLockedForUser(userId, true);
1353 }
1354
Jim Millerb256e4e22014-10-31 17:27:13 -07001355 private boolean shouldWaitForProvisioning() {
1356 return !mUpdateMonitor.isDeviceProvisioned() && !isSecure();
1357 }
1358
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001359 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001360 * Dismiss the keyguard through the security layers.
Jorim Jaggi241ae102016-11-02 21:57:33 -07001361 * @param callback Callback to be informed about the result
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001362 * @param message Message that should be displayed on the bouncer.
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001363 */
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001364 private void handleDismiss(IKeyguardDismissCallback callback, CharSequence message) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001365 if (mShowing) {
1366 if (callback != null) {
1367 mDismissCallbackRegistry.addCallback(callback);
1368 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001369 mCustomMessage = message;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001370 mStatusBarKeyguardViewManager.dismissAndCollapse();
Jorim Jaggi241ae102016-11-02 21:57:33 -07001371 } else if (callback != null) {
1372 new DismissCallbackWrapper(callback).notifyDismissError();
Jim Miller87d03662012-11-05 20:28:09 -08001373 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001374 }
1375
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001376 public void dismiss(IKeyguardDismissCallback callback, CharSequence message) {
1377 mHandler.obtainMessage(DISMISS, new DismissMessage(callback, message)).sendToTarget();
Jim Miller60013792013-10-03 18:31:34 -07001378 }
1379
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001380 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001381 * Send message to keyguard telling it to reset its state.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001382 * @see #handleReset
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001383 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001384 private void resetStateLocked() {
Jim Miller4894a012013-04-03 15:23:55 -07001385 if (DEBUG) Log.e(TAG, "resetStateLocked");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001386 Message msg = mHandler.obtainMessage(RESET);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001387 mHandler.sendMessage(msg);
1388 }
1389
1390 /**
1391 * Send message to keyguard telling it to verify unlock
1392 * @see #handleVerifyUnlock()
1393 */
1394 private void verifyUnlockLocked() {
1395 if (DEBUG) Log.d(TAG, "verifyUnlockLocked");
1396 mHandler.sendEmptyMessage(VERIFY_UNLOCK);
1397 }
1398
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001399 private void notifyStartedGoingToSleep() {
1400 if (DEBUG) Log.d(TAG, "notifyStartedGoingToSleep");
1401 mHandler.sendEmptyMessage(NOTIFY_STARTED_GOING_TO_SLEEP);
1402 }
1403
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001404 private void notifyFinishedGoingToSleep() {
1405 if (DEBUG) Log.d(TAG, "notifyFinishedGoingToSleep");
1406 mHandler.sendEmptyMessage(NOTIFY_FINISHED_GOING_TO_SLEEP);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001407 }
1408
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001409 private void notifyStartedWakingUp() {
1410 if (DEBUG) Log.d(TAG, "notifyStartedWakingUp");
1411 mHandler.sendEmptyMessage(NOTIFY_STARTED_WAKING_UP);
1412 }
1413
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001414 private void notifyScreenOn(IKeyguardDrawnCallback callback) {
1415 if (DEBUG) Log.d(TAG, "notifyScreenOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001416 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNING_ON, callback);
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001417 mHandler.sendMessage(msg);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001418 }
1419
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001420 private void notifyScreenTurnedOn() {
1421 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOn");
1422 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_ON);
1423 mHandler.sendMessage(msg);
1424 }
1425
1426 private void notifyScreenTurnedOff() {
1427 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOff");
1428 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_OFF);
1429 mHandler.sendMessage(msg);
1430 }
1431
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001432 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001433 * Send message to keyguard telling it to show itself
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001434 * @see #handleShow
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001435 */
Adam Cohenf7522022012-10-03 20:03:18 -07001436 private void showLocked(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001437 Trace.beginSection("KeyguardViewMediator#showLocked aqcuiring mShowKeyguardWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001438 if (DEBUG) Log.d(TAG, "showLocked");
Mike Lockwood674d3e42009-10-06 09:28:54 -04001439 // ensure we stay awake until we are finished displaying the keyguard
1440 mShowKeyguardWakeLock.acquire();
Adam Cohenf7522022012-10-03 20:03:18 -07001441 Message msg = mHandler.obtainMessage(SHOW, options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001442 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001443 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001444 }
1445
1446 /**
1447 * Send message to keyguard telling it to hide itself
Jim Miller9c20d0e2010-01-20 15:00:23 -08001448 * @see #handleHide()
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001449 */
1450 private void hideLocked() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001451 Trace.beginSection("KeyguardViewMediator#hideLocked");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001452 if (DEBUG) Log.d(TAG, "hideLocked");
1453 Message msg = mHandler.obtainMessage(HIDE);
1454 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001455 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001456 }
1457
Dianne Hackbornb446e972009-09-20 15:23:25 -07001458 public boolean isSecure() {
Evan Rosky13a58a92016-07-27 15:51:09 -07001459 return isSecure(KeyguardUpdateMonitor.getCurrentUser());
1460 }
1461
1462 public boolean isSecure(int userId) {
1463 return mLockPatternUtils.isSecure(userId)
1464 || KeyguardUpdateMonitor.getInstance(mContext).isSimPinSecure();
Dianne Hackbornb446e972009-09-20 15:23:25 -07001465 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001466
Evan Rosky18396452016-07-27 15:19:37 -07001467 public void setSwitchingUser(boolean switching) {
Selim Cinekbbe19242017-12-08 15:42:08 -08001468 KeyguardUpdateMonitor.getInstance(mContext).setSwitchingUser(switching);
Evan Rosky18396452016-07-27 15:19:37 -07001469 }
1470
Craig Mautnerf1b67412012-09-19 13:18:29 -07001471 /**
1472 * Update the newUserId. Call while holding WindowManagerService lock.
Jim Milleree82f8f2012-10-01 16:26:18 -07001473 * NOTE: Should only be called by KeyguardViewMediator in response to the user id changing.
1474 *
Craig Mautnerf1b67412012-09-19 13:18:29 -07001475 * @param newUserId The id of the incoming user.
1476 */
1477 public void setCurrentUser(int newUserId) {
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001478 KeyguardUpdateMonitor.setCurrentUser(newUserId);
Adrian Roosd88eb262016-08-04 14:50:48 -07001479 synchronized (this) {
1480 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(newUserId));
1481 }
Craig Mautnerf1b67412012-09-19 13:18:29 -07001482 }
1483
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001484 /**
1485 * This broadcast receiver should be registered with the SystemUI permission.
1486 */
1487 private final BroadcastReceiver mDelayedLockBroadcastReceiver = new BroadcastReceiver() {
Amith Yamasani52c489c2012-03-28 11:42:42 -07001488 @Override
1489 public void onReceive(Context context, Intent intent) {
Jim Millerbbf1a742012-07-17 18:30:30 -07001490 if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
1491 final int sequence = intent.getIntExtra("seq", 0);
Jim Millerf3447352011-08-07 14:00:09 -07001492 if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = "
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001493 + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001494 synchronized (KeyguardViewMediator.this) {
Jim Miller2967f482016-01-07 15:05:32 -08001495 if (mDelayedShowingSequence == sequence) {
1496 doKeyguardLocked(null);
1497 }
Clara Bayarri56878a92015-10-29 15:43:55 +00001498 }
1499 } else if (DELAYED_LOCK_PROFILE_ACTION.equals(intent.getAction())) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001500 final int sequence = intent.getIntExtra("seq", 0);
Clara Bayarri56878a92015-10-29 15:43:55 +00001501 int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, 0);
1502 if (userId != 0) {
1503 synchronized (KeyguardViewMediator.this) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001504 if (mDelayedProfileShowingSequence == sequence) {
1505 lockProfile(userId);
1506 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001507 }
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001508 }
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001509 }
1510 }
1511 };
1512
1513 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1514 @Override
1515 public void onReceive(Context context, Intent intent) {
1516 if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
Adrian Roos1f8025a2016-12-27 10:12:13 -08001517 synchronized (KeyguardViewMediator.this){
1518 mShuttingDown = true;
1519 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001520 }
1521 }
1522 };
1523
Jorim Jaggi241ae102016-11-02 21:57:33 -07001524 public void keyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001525 Trace.beginSection("KeyguardViewMediator#keyguardDone");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001526 if (DEBUG) Log.d(TAG, "keyguardDone()");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001527 userActivity();
Jim Miller60013792013-10-03 18:31:34 -07001528 EventLog.writeEvent(70000, 2);
Jorim Jaggi241ae102016-11-02 21:57:33 -07001529 Message msg = mHandler.obtainMessage(KEYGUARD_DONE);
Jim Miller60013792013-10-03 18:31:34 -07001530 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001531 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001532 }
1533
1534 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001535 * This handler will be associated with the policy thread, which will also
1536 * be the UI thread of the keyguard. Since the apis of the policy, and therefore
1537 * this class, can be called by other threads, any action that directly
1538 * interacts with the keyguard ui should be posted to this handler, rather
1539 * than called directly.
1540 */
Jim Millerdcb3d842012-08-23 19:18:12 -07001541 private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001542 @Override
Wink Saville37c124c2009-04-02 01:37:02 -07001543 public void handleMessage(Message msg) {
1544 switch (msg.what) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001545 case SHOW:
Adam Cohenf7522022012-10-03 20:03:18 -07001546 handleShow((Bundle) msg.obj);
Jim Miller60013792013-10-03 18:31:34 -07001547 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001548 case HIDE:
1549 handleHide();
Jim Miller60013792013-10-03 18:31:34 -07001550 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001551 case RESET:
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001552 handleReset();
Jim Miller60013792013-10-03 18:31:34 -07001553 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001554 case VERIFY_UNLOCK:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001555 Trace.beginSection("KeyguardViewMediator#handleMessage VERIFY_UNLOCK");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001556 handleVerifyUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001557 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001558 break;
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001559 case NOTIFY_STARTED_GOING_TO_SLEEP:
1560 handleNotifyStartedGoingToSleep();
1561 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001562 case NOTIFY_FINISHED_GOING_TO_SLEEP:
1563 handleNotifyFinishedGoingToSleep();
Jim Miller60013792013-10-03 18:31:34 -07001564 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001565 case NOTIFY_SCREEN_TURNING_ON:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001566 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNING_ON");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001567 handleNotifyScreenTurningOn((IKeyguardDrawnCallback) msg.obj);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001568 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001569 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001570 case NOTIFY_SCREEN_TURNED_ON:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001571 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNED_ON");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001572 handleNotifyScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001573 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001574 break;
1575 case NOTIFY_SCREEN_TURNED_OFF:
1576 handleNotifyScreenTurnedOff();
1577 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001578 case NOTIFY_STARTED_WAKING_UP:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001579 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_STARTED_WAKING_UP");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001580 handleNotifyStartedWakingUp();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001581 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001582 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001583 case KEYGUARD_DONE:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001584 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001585 handleKeyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001586 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001587 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001588 case KEYGUARD_DONE_DRAWING:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001589 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_DRAWING");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001590 handleKeyguardDoneDrawing();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001591 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001592 break;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001593 case SET_OCCLUDED:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001594 Trace.beginSection("KeyguardViewMediator#handleMessage SET_OCCLUDED");
Jorim Jaggi6626f542016-08-22 13:08:44 -07001595 handleSetOccluded(msg.arg1 != 0, msg.arg2 != 0);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001596 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001597 break;
Mike Lockwood28569302010-01-28 11:54:40 -05001598 case KEYGUARD_TIMEOUT:
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001599 synchronized (KeyguardViewMediator.this) {
Adam Cohenf7522022012-10-03 20:03:18 -07001600 doKeyguardLocked((Bundle) msg.obj);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001601 }
1602 break;
Jim Miller60013792013-10-03 18:31:34 -07001603 case DISMISS:
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001604 final DismissMessage message = (DismissMessage) msg.obj;
1605 handleDismiss(message.getCallback(), message.getMessage());
Jim Miller60013792013-10-03 18:31:34 -07001606 break;
Jorim Jaggi0d674622014-05-21 01:34:15 +02001607 case START_KEYGUARD_EXIT_ANIM:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001608 Trace.beginSection("KeyguardViewMediator#handleMessage START_KEYGUARD_EXIT_ANIM");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001609 StartKeyguardExitAnimParams params = (StartKeyguardExitAnimParams) msg.obj;
1610 handleStartKeyguardExitAnimation(params.startTime, params.fadeoutDuration);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001611 FalsingManager.getInstance(mContext).onSucccessfulUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001612 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001613 break;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001614 case KEYGUARD_DONE_PENDING_TIMEOUT:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001615 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_PENDING_TIMEOUT");
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001616 Log.w(TAG, "Timeout while waiting for activity drawn!");
Nick Desaulniers1d396752016-07-25 15:05:33 -07001617 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001618 break;
Adrian Roos30a2ae62018-04-25 19:09:50 +02001619 case SYSTEM_READY:
1620 handleSystemReady();
1621 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001622 }
1623 }
1624 };
1625
Jorim Jaggi241ae102016-11-02 21:57:33 -07001626 private void tryKeyguardDone() {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001627 if (!mKeyguardDonePending && mHideAnimationRun && !mHideAnimationRunning) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001628 handleKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001629 } else if (!mHideAnimationRun) {
1630 mHideAnimationRun = true;
1631 mHideAnimationRunning = true;
1632 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
1633 }
1634 }
1635
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001636 /**
1637 * @see #keyguardDone
1638 * @see #KEYGUARD_DONE
1639 */
Jorim Jaggi241ae102016-11-02 21:57:33 -07001640 private void handleKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001641 Trace.beginSection("KeyguardViewMediator#handleKeyguardDone");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001642 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001643 mUiOffloadThread.submit(() -> {
1644 if (mLockPatternUtils.isSecure(currentUser)) {
1645 mLockPatternUtils.getDevicePolicyManager().reportKeyguardDismissed(currentUser);
1646 }
1647 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001648 if (DEBUG) Log.d(TAG, "handleKeyguardDone");
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001649 synchronized (this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001650 resetKeyguardDonePendingLocked();
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001651 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001652
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001653 mUpdateMonitor.clearBiometricRecognized();
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -07001654
Jorim Jaggi4474f542015-07-09 16:08:02 -07001655 if (mGoingToSleep) {
1656 Log.i(TAG, "Device is going to sleep, aborting keyguardDone");
1657 return;
1658 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001659 if (mExitSecureCallback != null) {
1660 try {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001661 mExitSecureCallback.onKeyguardExitResult(true /* authenciated */);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001662 } catch (RemoteException e) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001663 Slog.w(TAG, "Failed to call onKeyguardExitResult()", e);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001664 }
1665
1666 mExitSecureCallback = null;
1667
Jorim Jaggi241ae102016-11-02 21:57:33 -07001668 // after succesfully exiting securely, no need to reshow
1669 // the keyguard when they've released the lock
1670 mExternallyEnabled = true;
1671 mNeedToReshowWhenReenabled = false;
1672 updateInputRestricted();
Jim Millere51cf7ae2013-06-25 18:31:56 -07001673 }
1674
1675 handleHide();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001676 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -07001677 }
1678
1679 private void sendUserPresentBroadcast() {
Jason Monkcf5a9532014-09-17 16:22:19 -04001680 synchronized (this) {
1681 if (mBootCompleted) {
Adrian Roos4ab7e592016-04-13 15:38:13 -07001682 int currentUserId = KeyguardUpdateMonitor.getCurrentUser();
1683 final UserHandle currentUser = new UserHandle(currentUserId);
Benjamin Franz4b9f8ed2014-12-01 16:51:48 +00001684 final UserManager um = (UserManager) mContext.getSystemService(
1685 Context.USER_SERVICE);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001686 mUiOffloadThread.submit(() -> {
1687 for (int profileId : um.getProfileIdsWithDisabled(currentUser.getIdentifier())) {
1688 mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, UserHandle.of(profileId));
1689 }
1690 getLockPatternUtils().userPresent(currentUserId);
1691 });
Jason Monkcf5a9532014-09-17 16:22:19 -04001692 } else {
1693 mBootSendUserPresent = true;
1694 }
1695 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001696 }
1697
1698 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001699 * @see #keyguardDone
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001700 * @see #KEYGUARD_DONE_DRAWING
1701 */
1702 private void handleKeyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001703 Trace.beginSection("KeyguardViewMediator#handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001704 synchronized(this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001705 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001706 if (mWaitingUntilKeyguardVisible) {
1707 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible");
1708 mWaitingUntilKeyguardVisible = false;
1709 notifyAll();
1710
1711 // there will usually be two of these sent, one as a timeout, and one
1712 // as a result of the callback, so remove any remaining messages from
1713 // the queue
1714 mHandler.removeMessages(KEYGUARD_DONE_DRAWING);
1715 }
1716 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001717 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001718 }
1719
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001720 private void playSounds(boolean locked) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001721 playSound(locked ? mLockSoundId : mUnlockSoundId);
1722 }
1723
1724 private void playSound(int soundId) {
1725 if (soundId == 0) return;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001726 final ContentResolver cr = mContext.getContentResolver();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001727 if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001728
Marco Nelissend5545bd2011-09-29 12:49:17 -07001729 mLockSounds.stop(mLockSoundStreamId);
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001730 // Init mAudioManager
1731 if (mAudioManager == null) {
1732 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
1733 if (mAudioManager == null) return;
John Spurlockee5ad722015-03-03 16:17:21 -05001734 mUiSoundsStreamType = mAudioManager.getUiSoundsStreamType();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001735 }
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001736
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001737 mUiOffloadThread.submit(() -> {
1738 // If the stream is muted, don't play the sound
1739 if (mAudioManager.isStreamMute(mUiSoundsStreamType)) return;
1740
1741 int id = mLockSounds.play(soundId,
1742 mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/);
1743 synchronized (this) {
1744 mLockSoundStreamId = id;
1745 }
1746 });
1747
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001748 }
Jim Miller2a98a4c2010-11-19 18:49:26 -08001749 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001750
Adrian Roos49e057d2014-08-13 17:14:51 +02001751 private void playTrustedSound() {
Adrian Roos49e057d2014-08-13 17:14:51 +02001752 playSound(mTrustedSoundId);
1753 }
1754
wilsonshih177261f2019-02-22 12:02:18 +08001755 private void updateActivityLockScreenState(boolean showing, boolean aodShowing) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001756 mUiOffloadThread.submit(() -> {
1757 try {
wilsonshih177261f2019-02-22 12:02:18 +08001758 ActivityTaskManager.getService().setLockScreenShown(showing, aodShowing);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001759 } catch (RemoteException e) {
1760 }
1761 });
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001762 }
1763
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001764 /**
1765 * Handle message sent by {@link #showLocked}.
1766 * @see #SHOW
1767 */
Adam Cohenf7522022012-10-03 20:03:18 -07001768 private void handleShow(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001769 Trace.beginSection("KeyguardViewMediator#handleShow");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001770 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
1771 if (mLockPatternUtils.isSecure(currentUser)) {
1772 mLockPatternUtils.getDevicePolicyManager().reportKeyguardSecured(currentUser);
Michal Karpinski779aad92016-01-20 11:56:22 +00001773 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001774 synchronized (KeyguardViewMediator.this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001775 if (!mSystemReady) {
1776 if (DEBUG) Log.d(TAG, "ignoring handleShow because system is not ready.");
1777 return;
1778 } else {
1779 if (DEBUG) Log.d(TAG, "handleShow");
1780 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001781
Lucas Dupin47a65c72018-02-15 14:16:18 -08001782 setShowingLocked(true, mAodShowing);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001783 mStatusBarKeyguardViewManager.show(options);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001784 mHiding = false;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001785 mWakeAndUnlocking = false;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001786 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001787 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001788 adjustStatusBarLocked();
Jeff Brown3dc524b2012-09-30 19:49:11 -07001789 userActivity();
Kevin Chyn8c7968a2019-03-01 11:25:23 -08001790 mUpdateMonitor.setKeyguardGoingAway(false /* away */);
Mike Lockwood674d3e42009-10-06 09:28:54 -04001791 mShowKeyguardWakeLock.release();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001792 }
Jim Miller31921482013-11-06 20:43:55 -08001793 mKeyguardDisplayManager.show();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001794 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001795 }
1796
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001797 private final Runnable mKeyguardGoingAwayRunnable = new Runnable() {
1798 @Override
1799 public void run() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001800 Trace.beginSection("KeyguardViewMediator.mKeyGuardGoingAwayRunnable");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001801 if (DEBUG) Log.d(TAG, "keyguardGoingAway");
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001802 try {
Jorim Jaggi33ae80e2015-02-04 16:37:11 +01001803 mStatusBarKeyguardViewManager.keyguardGoingAway();
1804
Adrian Roosd5c2db62016-03-08 16:11:31 -08001805 int flags = 0;
1806 if (mStatusBarKeyguardViewManager.shouldDisableWindowAnimationsForUnlock()
Lucas Dupind35502f2018-06-27 13:35:52 -07001807 || (mWakeAndUnlocking && !mPulsing)) {
1808 flags |= WindowManagerPolicyConstants
1809 .KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001810 }
Lucas Dupind35502f2018-06-27 13:35:52 -07001811 if (mStatusBarKeyguardViewManager.isGoingToNotificationShade()
1812 || (mWakeAndUnlocking && mPulsing)) {
Adrian Roose99bc052017-11-20 17:55:31 +01001813 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001814 }
1815 if (mStatusBarKeyguardViewManager.isUnlockWithWallpaper()) {
Adrian Roose99bc052017-11-20 17:55:31 +01001816 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001817 }
1818
Kevin Chyn6db7d5f2017-05-03 22:24:31 -07001819 mUpdateMonitor.setKeyguardGoingAway(true /* goingAway */);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001820 // Don't actually hide the Keyguard at the moment, wait for window
1821 // manager until it tells us it's safe to do so with
1822 // startKeyguardExitAnimation.
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07001823 ActivityTaskManager.getService().keyguardGoingAway(flags);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001824 } catch (RemoteException e) {
1825 Log.e(TAG, "Error while calling WindowManager", e);
1826 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001827 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001828 }
1829 };
1830
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001831 private final Runnable mHideAnimationFinishedRunnable = () -> {
1832 mHideAnimationRunning = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -07001833 tryKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001834 };
1835
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001836 /**
1837 * Handle message sent by {@link #hideLocked()}
1838 * @see #HIDE
1839 */
1840 private void handleHide() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001841 Trace.beginSection("KeyguardViewMediator#handleHide");
Lucas Dupin1c327432019-01-03 13:37:53 -08001842
1843 // It's possible that the device was unlocked in a dream state. It's time to wake up.
1844 if (mAodShowing) {
Michael Wrighte3001042019-02-05 00:13:14 +00001845 PowerManager pm = mContext.getSystemService(PowerManager.class);
1846 pm.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE,
1847 "com.android.systemui:BOUNCER_DOZING");
Lucas Dupin1c327432019-01-03 13:37:53 -08001848 }
1849
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001850 synchronized (KeyguardViewMediator.this) {
1851 if (DEBUG) Log.d(TAG, "handleHide");
Jorim Jaggib9d60792014-06-03 22:34:22 +02001852
Amith Yamasanieb437d42016-04-29 09:31:25 -07001853 if (mustNotUnlockCurrentUser()) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001854 // In split system user mode, we never unlock system user. The end user has to
1855 // switch to another user.
1856 // TODO: We should stop it early by disabling the swipe up flow. Right now swipe up
1857 // still completes and makes the screen blank.
1858 if (DEBUG) Log.d(TAG, "Split system user, quit unlocking.");
1859 return;
1860 }
Jorim Jaggi76a16232014-08-08 17:00:47 +02001861 mHiding = true;
Jorim Jaggib9d60792014-06-03 22:34:22 +02001862
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001863 if (mShowing && !mOccluded) {
1864 mKeyguardGoingAwayRunnable.run();
1865 } else {
Jorim Jaggi76a16232014-08-08 17:00:47 +02001866 handleStartKeyguardExitAnimation(
1867 SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(),
1868 mHideAnimation.getDuration());
Jorim Jaggi0d674622014-05-21 01:34:15 +02001869 }
1870 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001871 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001872 }
1873
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001874 private void handleStartKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001875 Trace.beginSection("KeyguardViewMediator#handleStartKeyguardExitAnimation");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001876 if (DEBUG) Log.d(TAG, "handleStartKeyguardExitAnimation startTime=" + startTime
1877 + " fadeoutDuration=" + fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02001878 synchronized (KeyguardViewMediator.this) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001879
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001880 if (!mHiding) {
Adrian Roos6ec76b72018-04-25 14:01:11 +02001881 // Tell ActivityManager that we canceled the keyguardExitAnimation.
wilsonshih177261f2019-02-22 12:02:18 +08001882 setShowingLocked(mShowing, mAodShowing, true /* force */);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001883 return;
1884 }
1885 mHiding = false;
1886
Jorim Jaggib774e552015-08-24 14:52:45 -07001887 if (mWakeAndUnlocking && mDrawnCallback != null) {
1888
1889 // Hack level over 9000: To speed up wake-and-unlock sequence, force it to report
1890 // the next draw from here so we don't have to wait for window manager to signal
1891 // this to our ViewRootImpl.
1892 mStatusBarKeyguardViewManager.getViewRootImpl().setReportNextDraw();
1893 notifyDrawn(mDrawnCallback);
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001894 mDrawnCallback = null;
Jorim Jaggib774e552015-08-24 14:52:45 -07001895 }
1896
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001897 // only play "unlock" noises if not on a call (since the incall UI
1898 // disables the keyguard)
1899 if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) {
1900 playSounds(false);
1901 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001902
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001903 mWakeAndUnlocking = false;
Lucas Dupin47a65c72018-02-15 14:16:18 -08001904 setShowingLocked(false, mAodShowing);
Jorim Jaggi5277dea2017-05-18 02:05:29 +02001905 mDismissCallbackRegistry.notifyDismissSucceeded();
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001906 mStatusBarKeyguardViewManager.hide(startTime, fadeoutDuration);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001907 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001908 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001909 adjustStatusBarLocked();
Jim Miller705004b2014-09-04 16:51:20 -07001910 sendUserPresentBroadcast();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001911 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001912 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001913 }
1914
Mike Lockwood5f892c12009-11-19 23:39:13 -05001915 private void adjustStatusBarLocked() {
Matthew Ng66f0b702017-12-08 12:58:42 -08001916 adjustStatusBarLocked(false /* forceHideHomeRecentsButtons */);
1917 }
1918
1919 private void adjustStatusBarLocked(boolean forceHideHomeRecentsButtons) {
Mike Lockwood5f892c12009-11-19 23:39:13 -05001920 if (mStatusBarManager == null) {
1921 mStatusBarManager = (StatusBarManager)
1922 mContext.getSystemService(Context.STATUS_BAR_SERVICE);
1923 }
Matthew Ng78ba6e22018-09-24 16:55:36 -07001924
Mike Lockwood5f892c12009-11-19 23:39:13 -05001925 if (mStatusBarManager == null) {
1926 Log.w(TAG, "Could not get status bar manager");
1927 } else {
Daniel Sandlerdba93562011-10-06 16:39:58 -04001928 // Disable aspects of the system/status/navigation bars that must not be re-enabled by
1929 // windows that appear on top, ever
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001930 int flags = StatusBarManager.DISABLE_NONE;
Matthew Ng66f0b702017-12-08 12:58:42 -08001931 if (forceHideHomeRecentsButtons || isShowingAndNotOccluded()) {
1932 flags |= StatusBarManager.DISABLE_HOME | StatusBarManager.DISABLE_RECENT;
Jorim Jaggia005f1b2014-04-16 19:06:10 +02001933 }
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001934
1935 if (DEBUG) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001936 Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mOccluded=" + mOccluded
Matthew Ng66f0b702017-12-08 12:58:42 -08001937 + " isSecure=" + isSecure() + " force=" + forceHideHomeRecentsButtons
1938 + " --> flags=0x" + Integer.toHexString(flags));
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001939 }
1940
Matthew Ng1a814ba2018-11-13 17:50:09 -08001941 // TODO(b/113914868): investigation log for disappearing home button
1942 Log.d(TAG, "adjustStatusBarLocked (b/113914868): flags=" + flags
1943 + "mShowing=" + mShowing + " mStatusBarManager=" + mStatusBarManager
1944 + " mOccluded=" + mOccluded + " isSecure=" + isSecure()
1945 + " force=" + forceHideHomeRecentsButtons);
1946
Jorim Jaggie3e0b062017-06-12 12:18:41 -07001947 mStatusBarManager.disable(flags);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001948 }
1949 }
1950
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001951 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001952 * Handle message sent by {@link #resetStateLocked}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001953 * @see #RESET
1954 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001955 private void handleReset() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001956 synchronized (KeyguardViewMediator.this) {
1957 if (DEBUG) Log.d(TAG, "handleReset");
Jorim Jaggife762342016-10-13 14:33:27 +02001958 mStatusBarKeyguardViewManager.reset(true /* hideBouncerWhenShowing */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001959 }
1960 }
1961
1962 /**
1963 * Handle message sent by {@link #verifyUnlock}
Craig Mautner904732c2012-10-17 15:20:24 -07001964 * @see #VERIFY_UNLOCK
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001965 */
1966 private void handleVerifyUnlock() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001967 Trace.beginSection("KeyguardViewMediator#handleVerifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001968 synchronized (KeyguardViewMediator.this) {
1969 if (DEBUG) Log.d(TAG, "handleVerifyUnlock");
Lucas Dupin47a65c72018-02-15 14:16:18 -08001970 setShowingLocked(true, mAodShowing);
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001971 mStatusBarKeyguardViewManager.dismissAndCollapse();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001972 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001973 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001974 }
1975
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001976 private void handleNotifyStartedGoingToSleep() {
1977 synchronized (KeyguardViewMediator.this) {
1978 if (DEBUG) Log.d(TAG, "handleNotifyStartedGoingToSleep");
1979 mStatusBarKeyguardViewManager.onStartedGoingToSleep();
1980 }
1981 }
1982
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001983 /**
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001984 * Handle message sent by {@link #notifyFinishedGoingToSleep()}
1985 * @see #NOTIFY_FINISHED_GOING_TO_SLEEP
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001986 */
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001987 private void handleNotifyFinishedGoingToSleep() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001988 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001989 if (DEBUG) Log.d(TAG, "handleNotifyFinishedGoingToSleep");
1990 mStatusBarKeyguardViewManager.onFinishedGoingToSleep();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001991 }
1992 }
1993
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001994 private void handleNotifyStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001995 Trace.beginSection("KeyguardViewMediator#handleMotifyStartedWakingUp");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001996 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001997 if (DEBUG) Log.d(TAG, "handleNotifyWakingUp");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001998 mStatusBarKeyguardViewManager.onStartedWakingUp();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001999 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002000 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002001 }
2002
2003 private void handleNotifyScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002004 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurningOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002005 synchronized (KeyguardViewMediator.this) {
2006 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurningOn");
Jorim Jaggi93739112015-08-13 15:53:14 -07002007 mStatusBarKeyguardViewManager.onScreenTurningOn();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002008 if (callback != null) {
2009 if (mWakeAndUnlocking) {
2010 mDrawnCallback = callback;
2011 } else {
2012 notifyDrawn(callback);
2013 }
2014 }
2015 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002016 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002017 }
2018
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002019 private void handleNotifyScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002020 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurnedOn");
Jorim Jaggic3fe2042016-10-07 18:52:48 +02002021 if (LatencyTracker.isEnabled(mContext)) {
2022 LatencyTracker.getInstance(mContext).onActionEnd(LatencyTracker.ACTION_TURN_ON_SCREEN);
2023 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002024 synchronized (this) {
2025 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOn");
2026 mStatusBarKeyguardViewManager.onScreenTurnedOn();
2027 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002028 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002029 }
2030
2031 private void handleNotifyScreenTurnedOff() {
2032 synchronized (this) {
2033 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOff");
2034 mStatusBarKeyguardViewManager.onScreenTurnedOff();
Jorim Jaggie93e6f92016-08-04 13:55:39 +02002035 mDrawnCallback = null;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002036 }
2037 }
2038
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002039 private void notifyDrawn(final IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002040 Trace.beginSection("KeyguardViewMediator#notifyDrawn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002041 try {
2042 callback.onDrawn();
2043 } catch (RemoteException e) {
2044 Slog.w(TAG, "Exception calling onDrawn():", e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002045 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002046 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002047 }
Jeff Sharkey054340d2011-09-01 22:28:03 -07002048
Jorim Jaggif8d77da2014-11-11 16:59:12 +01002049 private void resetKeyguardDonePendingLocked() {
2050 mKeyguardDonePending = false;
2051 mHandler.removeMessages(KEYGUARD_DONE_PENDING_TIMEOUT);
2052 }
2053
Jim Miller2967f482016-01-07 15:05:32 -08002054 @Override
Jim Millere5f910a2013-10-16 18:15:46 -07002055 public void onBootCompleted() {
2056 mUpdateMonitor.dispatchBootCompleted();
Jason Monkcf5a9532014-09-17 16:22:19 -04002057 synchronized (this) {
2058 mBootCompleted = true;
2059 if (mBootSendUserPresent) {
2060 sendUserPresentBroadcast();
2061 }
2062 }
Jim Millere5f910a2013-10-16 18:15:46 -07002063 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002064
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002065 public void onWakeAndUnlocking() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002066 Trace.beginSection("KeyguardViewMediator#onWakeAndUnlocking");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002067 mWakeAndUnlocking = true;
Jorim Jaggi241ae102016-11-02 21:57:33 -07002068 keyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07002069 Trace.endSection();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002070 }
2071
Jason Monk2a6ea9c2017-01-26 11:14:51 -05002072 public StatusBarKeyguardViewManager registerStatusBar(StatusBar statusBar,
Lucas Dupinbc9aac12018-03-04 20:18:15 -08002073 ViewGroup container, NotificationPanelView panelView,
Gilad Brettercb51b8b2018-03-22 17:04:51 +02002074 BiometricUnlockController biometricUnlockController) {
Lucas Dupinbc9aac12018-03-04 20:18:15 -08002075 mStatusBarKeyguardViewManager.registerStatusBar(statusBar, container, panelView,
Gilad Brettercb51b8b2018-03-22 17:04:51 +02002076 biometricUnlockController, mDismissCallbackRegistry);
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002077 return mStatusBarKeyguardViewManager;
2078 }
2079
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002080 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002081 Trace.beginSection("KeyguardViewMediator#startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002082 Message msg = mHandler.obtainMessage(START_KEYGUARD_EXIT_ANIM,
2083 new StartKeyguardExitAnimParams(startTime, fadeoutDuration));
Jorim Jaggi0d674622014-05-21 01:34:15 +02002084 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07002085 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02002086 }
2087
Andrew Zengb4045d32017-03-16 17:25:07 -07002088 public void onShortPowerPressedGoHome() {
2089 // do nothing
2090 }
2091
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002092 public ViewMediatorCallback getViewMediatorCallback() {
2093 return mViewMediatorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002094 }
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002095
Xiyuan Xia1b30f792016-01-06 08:50:30 -08002096 public LockPatternUtils getLockPatternUtils() {
2097 return mLockPatternUtils;
2098 }
2099
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002100 @Override
2101 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
2102 pw.print(" mSystemReady: "); pw.println(mSystemReady);
2103 pw.print(" mBootCompleted: "); pw.println(mBootCompleted);
2104 pw.print(" mBootSendUserPresent: "); pw.println(mBootSendUserPresent);
2105 pw.print(" mExternallyEnabled: "); pw.println(mExternallyEnabled);
Adrian Roos1f8025a2016-12-27 10:12:13 -08002106 pw.print(" mShuttingDown: "); pw.println(mShuttingDown);
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002107 pw.print(" mNeedToReshowWhenReenabled: "); pw.println(mNeedToReshowWhenReenabled);
2108 pw.print(" mShowing: "); pw.println(mShowing);
2109 pw.print(" mInputRestricted: "); pw.println(mInputRestricted);
2110 pw.print(" mOccluded: "); pw.println(mOccluded);
2111 pw.print(" mDelayedShowingSequence: "); pw.println(mDelayedShowingSequence);
2112 pw.print(" mExitSecureCallback: "); pw.println(mExitSecureCallback);
2113 pw.print(" mDeviceInteractive: "); pw.println(mDeviceInteractive);
2114 pw.print(" mGoingToSleep: "); pw.println(mGoingToSleep);
2115 pw.print(" mHiding: "); pw.println(mHiding);
2116 pw.print(" mWaitingUntilKeyguardVisible: "); pw.println(mWaitingUntilKeyguardVisible);
2117 pw.print(" mKeyguardDonePending: "); pw.println(mKeyguardDonePending);
2118 pw.print(" mHideAnimationRun: "); pw.println(mHideAnimationRun);
2119 pw.print(" mPendingReset: "); pw.println(mPendingReset);
2120 pw.print(" mPendingLock: "); pw.println(mPendingLock);
2121 pw.print(" mWakeAndUnlocking: "); pw.println(mWakeAndUnlocking);
2122 pw.print(" mDrawnCallback: "); pw.println(mDrawnCallback);
2123 }
2124
Lucas Dupin5a4f92c2018-07-02 13:15:23 -07002125 /**
2126 * @param aodShowing true when AOD - or ambient mode - is showing.
2127 */
Lucas Dupin47a65c72018-02-15 14:16:18 -08002128 public void setAodShowing(boolean aodShowing) {
2129 setShowingLocked(mShowing, aodShowing);
2130 }
2131
Lucas Dupind35502f2018-06-27 13:35:52 -07002132 /**
2133 * @param pulsing true when device temporarily wakes up to display an incoming notification.
2134 */
2135 public void setPulsing(boolean pulsing) {
2136 mPulsing = pulsing;
2137 }
2138
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002139 private static class StartKeyguardExitAnimParams {
2140
2141 long startTime;
2142 long fadeoutDuration;
2143
2144 private StartKeyguardExitAnimParams(long startTime, long fadeoutDuration) {
2145 this.startTime = startTime;
2146 this.fadeoutDuration = fadeoutDuration;
2147 }
2148 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002149
Lucas Dupin47a65c72018-02-15 14:16:18 -08002150 private void setShowingLocked(boolean showing, boolean aodShowing) {
wilsonshih177261f2019-02-22 12:02:18 +08002151 setShowingLocked(showing, aodShowing, false /* forceCallbacks */);
Jorim Jaggie8f321e2016-11-07 16:48:31 -08002152 }
2153
wilsonshih177261f2019-02-22 12:02:18 +08002154 private void setShowingLocked(boolean showing, boolean aodShowing, boolean forceCallbacks) {
Lucas Dupin47a65c72018-02-15 14:16:18 -08002155 final boolean notifyDefaultDisplayCallbacks = showing != mShowing
2156 || aodShowing != mAodShowing || forceCallbacks;
wilsonshih177261f2019-02-22 12:02:18 +08002157 if (notifyDefaultDisplayCallbacks) {
Jim Millerab954542014-10-10 18:21:49 -07002158 mShowing = showing;
Lucas Dupin47a65c72018-02-15 14:16:18 -08002159 mAodShowing = aodShowing;
David Stevens53a39ea2017-08-23 18:41:49 -07002160 if (notifyDefaultDisplayCallbacks) {
2161 notifyDefaultDisplayCallbacks(showing);
2162 }
wilsonshih177261f2019-02-22 12:02:18 +08002163 updateActivityLockScreenState(showing, aodShowing);
David Stevens53a39ea2017-08-23 18:41:49 -07002164 }
2165 }
2166
2167 private void notifyDefaultDisplayCallbacks(boolean showing) {
2168 int size = mKeyguardStateCallbacks.size();
2169 for (int i = size - 1; i >= 0; i--) {
2170 IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
2171 try {
2172 callback.onShowingStateChanged(showing);
2173 } catch (RemoteException e) {
2174 Slog.w(TAG, "Failed to call onShowingStateChanged", e);
2175 if (e instanceof DeadObjectException) {
2176 mKeyguardStateCallbacks.remove(callback);
Jim Millerab954542014-10-10 18:21:49 -07002177 }
Jim Millerab954542014-10-10 18:21:49 -07002178 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002179 }
David Stevens53a39ea2017-08-23 18:41:49 -07002180 updateInputRestrictedLocked();
2181 mUiOffloadThread.submit(() -> {
2182 mTrustManager.reportKeyguardShowingChanged();
2183 });
Adrian Roos481a6df2014-11-20 19:48:56 +01002184 }
Jim Millerab954542014-10-10 18:21:49 -07002185
Adrian Roosd88eb262016-08-04 14:50:48 -07002186 private void notifyTrustedChangedLocked(boolean trusted) {
2187 int size = mKeyguardStateCallbacks.size();
2188 for (int i = size - 1; i >= 0; i--) {
2189 try {
2190 mKeyguardStateCallbacks.get(i).onTrustedChanged(trusted);
2191 } catch (RemoteException e) {
2192 Slog.w(TAG, "Failed to call notifyTrustedChangedLocked", e);
2193 if (e instanceof DeadObjectException) {
2194 mKeyguardStateCallbacks.remove(i);
2195 }
2196 }
2197 }
2198 }
2199
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002200 private void notifyHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
2201 int size = mKeyguardStateCallbacks.size();
2202 for (int i = size - 1; i >= 0; i--) {
2203 try {
2204 mKeyguardStateCallbacks.get(i).onHasLockscreenWallpaperChanged(
2205 hasLockscreenWallpaper);
2206 } catch (RemoteException e) {
2207 Slog.w(TAG, "Failed to call onHasLockscreenWallpaperChanged", e);
2208 if (e instanceof DeadObjectException) {
2209 mKeyguardStateCallbacks.remove(i);
2210 }
2211 }
2212 }
2213 }
2214
Jim Millerab954542014-10-10 18:21:49 -07002215 public void addStateMonitorCallback(IKeyguardStateCallback callback) {
2216 synchronized (this) {
2217 mKeyguardStateCallbacks.add(callback);
2218 try {
2219 callback.onSimSecureStateChanged(mUpdateMonitor.isSimPinSecure());
2220 callback.onShowingStateChanged(mShowing);
Adrian Roos4a963ac2015-04-24 16:04:53 -07002221 callback.onInputRestrictedStateChanged(mInputRestricted);
Adrian Roosd88eb262016-08-04 14:50:48 -07002222 callback.onTrustedChanged(mUpdateMonitor.getUserHasTrust(
2223 KeyguardUpdateMonitor.getCurrentUser()));
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002224 callback.onHasLockscreenWallpaperChanged(mUpdateMonitor.hasLockscreenWallpaper());
Jim Millerab954542014-10-10 18:21:49 -07002225 } catch (RemoteException e) {
Adrian Roosd88eb262016-08-04 14:50:48 -07002226 Slog.w(TAG, "Failed to call to IKeyguardStateCallback", e);
Jim Millerab954542014-10-10 18:21:49 -07002227 }
2228 }
2229 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08002230
2231 private static class DismissMessage {
2232 private final CharSequence mMessage;
2233 private final IKeyguardDismissCallback mCallback;
2234
2235 DismissMessage(IKeyguardDismissCallback callback, CharSequence message) {
2236 mCallback = callback;
2237 mMessage = message;
2238 }
2239
2240 public IKeyguardDismissCallback getCallback() {
2241 return mCallback;
2242 }
2243
2244 public CharSequence getMessage() {
2245 return mMessage;
2246 }
2247 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002248}