blob: 9616f0a29021630d69c181bce499cc0bc9d251c0 [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
Jorim Jaggi241ae102016-11-02 21:57:33 -070069import com.android.internal.policy.IKeyguardDismissCallback;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -070070import com.android.internal.policy.IKeyguardDrawnCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010071import com.android.internal.policy.IKeyguardExitCallback;
Jim Millerab954542014-10-10 18:21:49 -070072import com.android.internal.policy.IKeyguardStateCallback;
Adam Cohenf7522022012-10-03 20:03:18 -070073import com.android.internal.telephony.IccCardConstants;
Lucas Dupin6d48eab2018-09-17 17:17:14 -070074import com.android.internal.util.LatencyTracker;
Adam Cohenf7522022012-10-03 20:03:18 -070075import com.android.internal.widget.LockPatternUtils;
Jim Miller52a61332014-11-12 19:29:51 -080076import com.android.keyguard.KeyguardConstants;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010077import com.android.keyguard.KeyguardDisplayManager;
Selim Cinek3122fa82015-06-18 01:38:59 -070078import com.android.keyguard.KeyguardSecurityView;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010079import com.android.keyguard.KeyguardUpdateMonitor;
80import com.android.keyguard.KeyguardUpdateMonitorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010081import com.android.keyguard.ViewMediatorCallback;
Jorim Jaggie549a8d2017-05-15 02:40:05 +020082import com.android.systemui.Dependency;
Jorim Jaggicff0acb2014-03-31 16:35:15 +020083import com.android.systemui.SystemUI;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080084import com.android.systemui.SystemUIFactory;
Jorim Jaggie549a8d2017-05-15 02:40:05 +020085import com.android.systemui.UiOffloadThread;
Dave Mankoffdde5ee62019-05-02 17:36:11 -040086import com.android.systemui.classifier.FalsingManagerFactory;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020087import com.android.systemui.statusbar.phone.BiometricUnlockController;
Lucas Dupin6d48eab2018-09-17 17:17:14 -070088import com.android.systemui.statusbar.phone.NotificationPanelView;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050089import com.android.systemui.statusbar.phone.StatusBar;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010090import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
Robert Snoebergerbe35b762019-03-15 14:33:02 -040091import com.android.systemui.util.InjectionInflationController;
Adrian Roos58b58fe2014-01-31 16:00:39 -080092
Jorim Jaggi84dc08a2015-09-11 17:45:22 -070093import java.io.FileDescriptor;
94import java.io.PrintWriter;
Jim Millerab954542014-10-10 18:21:49 -070095import java.util.ArrayList;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010096
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080097/**
98 * Mediates requests related to the keyguard. This includes queries about the
99 * state of the keyguard, power management events that effect whether the keyguard
100 * should be shown or reset, callbacks to the phone window manager to notify
101 * it of when the keyguard is showing, and events from the keyguard view itself
102 * stating that the keyguard was succesfully unlocked.
103 *
104 * Note that the keyguard view is shown when the screen is off (as appropriate)
105 * so that once the screen comes on, it will be ready immediately.
106 *
107 * Example queries about the keyguard:
108 * - is {movement, key} one that should wake the keygaurd?
109 * - is the keyguard showing?
110 * - are input events restricted due to the state of the keyguard?
111 *
112 * Callbacks to the phone window manager:
113 * - the keyguard is showing
114 *
115 * Example external events that translate to keyguard view changes:
116 * - screen turned off -> reset the keyguard, and show it so it will be ready
117 * next time the screen turns on
118 * - keyboard is slid open -> if the keyguard is not secure, hide it
119 *
120 * Events from the keyguard view:
121 * - user succesfully unlocked keyguard -> hide keyguard view, and no longer
122 * restrict input events.
123 *
124 * Note: in addition to normal power managment events that effect the state of
125 * whether the keyguard should be showing, external apps and services may request
126 * that the keyguard be disabled via {@link #setKeyguardEnabled(boolean)}. When
127 * false, this will override all other conditions for turning on the keyguard.
128 *
129 * Threading and synchronization:
Adrian Roose99bc052017-11-20 17:55:31 +0100130 * This class is created by the initialization routine of the {@link WindowManagerPolicyConstants},
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800131 * and runs on its thread. The keyguard UI is created from that thread in the
132 * constructor of this class. The apis may be called from other threads, including the
Jeff Brown4532e612012-04-05 14:27:12 -0700133 * {@link com.android.server.input.InputManagerService}'s and {@link android.view.WindowManager}'s.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800134 * Therefore, methods on this class are synchronized, and any action that is pointed
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100135 * 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 -0800136 * thread of the keyguard.
137 */
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200138public class KeyguardViewMediator extends SystemUI {
Jim Millerbc4603b2010-08-30 21:21:34 -0700139 private static final int KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT = 30000;
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100140 private static final long KEYGUARD_DONE_PENDING_TIMEOUT_MS = 3000;
141
Jim Miller52a61332014-11-12 19:29:51 -0800142 private static final boolean DEBUG = KeyguardConstants.DEBUG;
143 private static final boolean DEBUG_SIM_STATES = KeyguardConstants.DEBUG_SIM_STATES;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800144
145 private final static String TAG = "KeyguardViewMediator";
146
Jim Miller9c20d0e2010-01-20 15:00:23 -0800147 private static final String DELAYED_KEYGUARD_ACTION =
Wink Saville37c124c2009-04-02 01:37:02 -0700148 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD";
Clara Bayarri56878a92015-10-29 15:43:55 +0000149 private static final String DELAYED_LOCK_PROFILE_ACTION =
150 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_LOCK";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800151
Kevin Chyn18e91aa2018-04-11 12:55:45 -0700152 private static final String SYSTEMUI_PERMISSION = "com.android.systemui.permission.SELF";
153
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800154 // used for handler messages
Jorim Jaggi8d786932016-10-26 19:08:36 -0700155 private static final int SHOW = 1;
156 private static final int HIDE = 2;
157 private static final int RESET = 3;
158 private static final int VERIFY_UNLOCK = 4;
159 private static final int NOTIFY_FINISHED_GOING_TO_SLEEP = 5;
160 private static final int NOTIFY_SCREEN_TURNING_ON = 6;
161 private static final int KEYGUARD_DONE = 7;
162 private static final int KEYGUARD_DONE_DRAWING = 8;
163 private static final int SET_OCCLUDED = 9;
164 private static final int KEYGUARD_TIMEOUT = 10;
165 private static final int DISMISS = 11;
166 private static final int START_KEYGUARD_EXIT_ANIM = 12;
167 private static final int KEYGUARD_DONE_PENDING_TIMEOUT = 13;
168 private static final int NOTIFY_STARTED_WAKING_UP = 14;
169 private static final int NOTIFY_SCREEN_TURNED_ON = 15;
170 private static final int NOTIFY_SCREEN_TURNED_OFF = 16;
171 private static final int NOTIFY_STARTED_GOING_TO_SLEEP = 17;
Adrian Roos30a2ae62018-04-25 19:09:50 +0200172 private static final int SYSTEM_READY = 18;
Jim Miller9c20d0e2010-01-20 15:00:23 -0800173
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800174 /**
175 * The default amount of time we stay awake (used for all key input)
176 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100177 public static final int AWAKE_INTERVAL_DEFAULT_MS = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800178
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800179 /**
180 * How long to wait after the screen turns off due to timeout before
181 * turning on the keyguard (i.e, the user has this much time to turn
182 * the screen back on without having to face the keyguard).
183 */
Jim Millerbc4603b2010-08-30 21:21:34 -0700184 private static final int KEYGUARD_LOCK_AFTER_DELAY_DEFAULT = 5000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800185
186 /**
Craig Mautnerf1b67412012-09-19 13:18:29 -0700187 * How long we'll wait for the {@link ViewMediatorCallback#keyguardDoneDrawing()}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800188 * callback before unblocking a call to {@link #setKeyguardEnabled(boolean)}
189 * that is reenabling the keyguard.
190 */
191 private static final int KEYGUARD_DONE_DRAWING_TIMEOUT_MS = 2000;
Jim Miller9c20d0e2010-01-20 15:00:23 -0800192
Daniel Sandler74d188c2011-08-10 00:00:31 -0400193 /**
Evan Rosky13a58a92016-07-27 15:51:09 -0700194 * Boolean option for doKeyguardLocked/doKeyguardTimeout which, when set to true, forces the
195 * keyguard to show even if it is disabled for the current user.
196 */
197 public static final String OPTION_FORCE_SHOW = "force_show";
198
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700199 /** The stream type that the lock sounds are tied to. */
John Spurlockee5ad722015-03-03 16:17:21 -0500200 private int mUiSoundsStreamType;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700201
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800202 private AlarmManager mAlarmManager;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700203 private AudioManager mAudioManager;
Mike Lockwood5f892c12009-11-19 23:39:13 -0500204 private StatusBarManager mStatusBarManager;
Jorim Jaggie549a8d2017-05-15 02:40:05 +0200205 private final UiOffloadThread mUiOffloadThread = Dependency.get(UiOffloadThread.class);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800206
207 private boolean mSystemReady;
Jason Monkcf5a9532014-09-17 16:22:19 -0400208 private boolean mBootCompleted;
209 private boolean mBootSendUserPresent;
Adrian Roos1f8025a2016-12-27 10:12:13 -0800210 private boolean mShuttingDown;
Daniel Sandler0060a9b2010-03-15 23:09:57 -0400211
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800212 /** High level access to the power manager for WakeLocks */
213 private PowerManager mPM;
214
Adrian Roos481a6df2014-11-20 19:48:56 +0100215 /** TrustManager for letting it know when we change visibility */
216 private TrustManager mTrustManager;
Amith Yamasanib70ff9a2012-09-07 18:28:11 -0700217
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800218 /**
Mike Lockwood674d3e42009-10-06 09:28:54 -0400219 * Used to keep the device awake while to ensure the keyguard finishes opening before
220 * we sleep.
221 */
222 private PowerManager.WakeLock mShowKeyguardWakeLock;
223
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100224 private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800225
226 // these are protected by synchronized (this)
227
228 /**
Mike Lockwood5d258b62009-12-02 13:50:45 -0500229 * External apps (like the phone app) can tell us to disable the keygaurd.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800230 */
231 private boolean mExternallyEnabled = true;
232
233 /**
234 * Remember if an external call to {@link #setKeyguardEnabled} with value
235 * false caused us to hide the keyguard, so that we need to reshow it once
236 * the keygaurd is reenabled with another call with value true.
237 */
238 private boolean mNeedToReshowWhenReenabled = false;
239
240 // cached value of whether we are showing (need to know this to quickly
241 // answer whether the input should be restricted)
Jim Millere5f17ab2013-11-13 15:40:48 -0800242 private boolean mShowing;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800243
Lucas Dupin47a65c72018-02-15 14:16:18 -0800244 // AOD is enabled and status bar is in AOD state.
245 private boolean mAodShowing;
246
Jim Millerab954542014-10-10 18:21:49 -0700247 /** Cached value of #isInputRestricted */
248 private boolean mInputRestricted;
249
Mike Lockwood09a40402009-11-08 00:33:23 -0500250 // true if the keyguard is hidden by another window
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100251 private boolean mOccluded = false;
Mike Lockwood09a40402009-11-08 00:33:23 -0500252
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800253 /**
254 * Helps remember whether the screen has turned on since the last time
255 * it turned off due to timeout. see {@link #onScreenTurnedOff(int)}
256 */
257 private int mDelayedShowingSequence;
258
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800259 /**
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000260 * Simiar to {@link #mDelayedProfileShowingSequence}, but it is for profile case.
261 */
262 private int mDelayedProfileShowingSequence;
263
264 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800265 * If the user has disabled the keyguard, then requests to exit, this is
266 * how we'll ultimately let them know whether it was successful. We use this
267 * var being non-null as an indicator that there is an in progress request.
268 */
Jim Miller25190572013-02-28 17:36:24 -0800269 private IKeyguardExitCallback mExitSecureCallback;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700270 private final DismissCallbackRegistry mDismissCallbackRegistry = new DismissCallbackRegistry();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800271
272 // the properties of the keyguard
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800273
274 private KeyguardUpdateMonitor mUpdateMonitor;
275
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700276 /**
277 * Last SIM state reported by the telephony system.
278 * Index is the slotId - in case of multiple SIM cards.
279 */
280 private final SparseArray<IccCardConstants.State> mLastSimStates = new SparseArray<>();
281
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700282 private boolean mDeviceInteractive;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700283 private boolean mGoingToSleep;
Karl Rosaenab100082009-03-24 22:35:17 -0700284
Daniel Sandlerf2d8e742010-02-22 13:09:48 -0500285 // last known state of the cellular connection
286 private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE;
287
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800288 /**
Jorim Jaggi53c68a42014-06-17 15:04:47 -0700289 * Whether a hide is pending an we are just waiting for #startKeyguardExitAnimation to be
290 * called.
291 * */
292 private boolean mHiding;
293
294 /**
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700295 * we send this intent when the keyguard is dismissed.
296 */
Jim Miller17f509a2013-02-28 18:36:12 -0800297 private static final Intent USER_PRESENT_INTENT = new Intent(Intent.ACTION_USER_PRESENT)
298 .addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
Chad Brubaker291df4f2017-03-14 10:23:02 -0700299 | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
300 | Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700301
302 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800303 * {@link #setKeyguardEnabled} waits on this condition when it reenables
304 * the keyguard.
305 */
306 private boolean mWaitingUntilKeyguardVisible = false;
Jim Millerbc4603b2010-08-30 21:21:34 -0700307 private LockPatternUtils mLockPatternUtils;
John Spurlock34c4fe52012-11-07 10:12:29 -0500308 private boolean mKeyguardDonePending = false;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200309 private boolean mHideAnimationRun = false;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700310 private boolean mHideAnimationRunning = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800311
Marco Nelissend5545bd2011-09-29 12:49:17 -0700312 private SoundPool mLockSounds;
313 private int mLockSoundId;
314 private int mUnlockSoundId;
Adrian Roos49e057d2014-08-13 17:14:51 +0200315 private int mTrustedSoundId;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700316 private int mLockSoundStreamId;
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700317
318 /**
Adrian Roos0002a452014-07-03 13:46:07 +0200319 * The animation used for hiding keyguard. This is used to fetch the animation timings if
320 * WindowManager is not providing us with them.
321 */
322 private Animation mHideAnimation;
323
324 /**
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700325 * The volume applied to the lock/unlock sounds.
326 */
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200327 private float mLockSoundVolume;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700328
Jim Millerdcb3d842012-08-23 19:18:12 -0700329 /**
Jim Miller31921482013-11-06 20:43:55 -0800330 * For managing external displays
331 */
332 private KeyguardDisplayManager mKeyguardDisplayManager;
333
Jim Millerab954542014-10-10 18:21:49 -0700334 private final ArrayList<IKeyguardStateCallback> mKeyguardStateCallbacks = new ArrayList<>();
335
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700336 /**
337 * When starting going to sleep, we figured out that we need to reset Keyguard state and this
338 * should be committed when finished going to sleep.
339 */
340 private boolean mPendingReset;
341
342 /**
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700343 * 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 -0700344 * committed when finished going to sleep.
345 */
346 private boolean mPendingLock;
347
Robin Leec41f6ec2017-01-10 17:02:34 +0000348 /**
349 * Controller for showing individual "work challenge" lock screen windows inside managed profile
350 * tasks when the current user has been unlocked but the profile is still locked.
351 */
352 private WorkLockActivityController mWorkLockController;
353
Lucas Dupind35502f2018-06-27 13:35:52 -0700354 /**
355 * @see #setPulsing(boolean)
356 */
357 private boolean mPulsing;
358
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000359 private boolean mLockLater;
360
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700361 private boolean mWakeAndUnlocking;
362 private IKeyguardDrawnCallback mDrawnCallback;
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800363 private CharSequence mCustomMessage;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700364
Jim Millerbbf1a742012-07-17 18:30:30 -0700365 KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {
366
367 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500368 public void onUserSwitching(int userId) {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700369 // Note that the mLockPatternUtils user has already been updated from setCurrentUser.
Adam Cohenf7522022012-10-03 20:03:18 -0700370 // We need to force a reset of the views, since lockNow (called by
371 // ActivityManagerService) will not reconstruct the keyguard if it is already showing.
Jim Millerbbf1a742012-07-17 18:30:30 -0700372 synchronized (KeyguardViewMediator.this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100373 resetKeyguardDonePendingLocked();
Alex Chau77ef9fc2018-04-11 15:41:32 +0100374 if (mLockPatternUtils.isLockScreenDisabled(userId)) {
375 // If we switching to a user that has keyguard disabled, dismiss keyguard.
376 dismiss(null /* callback */, null /* message */);
377 } else {
378 resetStateLocked();
379 }
John Spurlock4e6922d2012-10-04 14:51:51 -0400380 adjustStatusBarLocked();
Dianne Hackborn5dc5a002012-09-15 19:33:48 -0700381 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700382 }
383
384 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500385 public void onUserSwitchComplete(int userId) {
Xiaohui Chen87d0e252015-07-30 15:38:16 -0700386 if (userId != UserHandle.USER_SYSTEM) {
Adrian Roosbe47b072014-09-03 00:08:56 +0200387 UserInfo info = UserManager.get(mContext).getUserInfo(userId);
Kevin Chynf2c0a642017-05-25 11:29:08 -0700388 // Don't try to dismiss if the user has Pin/Patter/Password set
389 if (info == null || mLockPatternUtils.isSecure(userId)) {
390 return;
391 } else if (info.isGuest() || info.isDemo()) {
Adrian Roosbe47b072014-09-03 00:08:56 +0200392 // If we just switched to a guest, try to dismiss keyguard.
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800393 dismiss(null /* callback */, null /* message */);
Adrian Roosbe47b072014-09-03 00:08:56 +0200394 }
395 }
Chris Wrenf41c61b2012-11-29 15:19:54 -0500396 }
397
398 @Override
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -0700399 public void onUserInfoChanged(int userId) {
Jim Millerbbf1a742012-07-17 18:30:30 -0700400 }
401
402 @Override
Jim Millerb0304762012-03-13 20:01:25 -0700403 public void onClockVisibilityChanged() {
404 adjustStatusBarLocked();
405 }
406
407 @Override
408 public void onDeviceProvisioned() {
Jim Miller3fd47af2012-09-21 19:55:27 -0700409 sendUserPresentBroadcast();
Amith Yamasanicb15d662015-11-10 11:11:15 -0800410 synchronized (KeyguardViewMediator.this) {
411 // If system user is provisioned, we might want to lock now to avoid showing launcher
Amith Yamasanieb437d42016-04-29 09:31:25 -0700412 if (mustNotUnlockCurrentUser()) {
Amith Yamasanicb15d662015-11-10 11:11:15 -0800413 doKeyguardLocked(null);
414 }
415 }
Jim Millerb0304762012-03-13 20:01:25 -0700416 }
417
Jim Millerbbf1a742012-07-17 18:30:30 -0700418 @Override
Jim Miller52a61332014-11-12 19:29:51 -0800419 public void onSimStateChanged(int subId, int slotId, IccCardConstants.State simState) {
420
421 if (DEBUG_SIM_STATES) {
422 Log.d(TAG, "onSimStateChanged(subId=" + subId + ", slotId=" + slotId
423 + ",state=" + simState + ")");
424 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700425
dooyoung.hwang328472e2015-05-21 16:09:43 +0900426 int size = mKeyguardStateCallbacks.size();
427 boolean simPinSecure = mUpdateMonitor.isSimPinSecure();
428 for (int i = size - 1; i >= 0; i--) {
429 try {
Jim Millerab954542014-10-10 18:21:49 -0700430 mKeyguardStateCallbacks.get(i).onSimSecureStateChanged(simPinSecure);
dooyoung.hwang328472e2015-05-21 16:09:43 +0900431 } catch (RemoteException e) {
432 Slog.w(TAG, "Failed to call onSimSecureStateChanged", e);
433 if (e instanceof DeadObjectException) {
434 mKeyguardStateCallbacks.remove(i);
435 }
Jim Millerab954542014-10-10 18:21:49 -0700436 }
Jim Millerab954542014-10-10 18:21:49 -0700437 }
438
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700439 boolean simWasLocked;
440 synchronized (KeyguardViewMediator.this) {
441 IccCardConstants.State lastState = mLastSimStates.get(slotId);
Brad Ebingere6c6f722018-12-20 21:11:44 -0800442 simWasLocked = (lastState == PIN_REQUIRED || lastState == PUK_REQUIRED);
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700443 mLastSimStates.append(slotId, simState);
444 }
445
Jim Millerbbf1a742012-07-17 18:30:30 -0700446 switch (simState) {
447 case NOT_READY:
448 case ABSENT:
449 // only force lock screen in case of missing sim if user hasn't
450 // gone through setup wizard
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800451 synchronized (KeyguardViewMediator.this) {
Jim Millerb256e4e22014-10-31 17:27:13 -0700452 if (shouldWaitForProvisioning()) {
Jim Millerab954542014-10-10 18:21:49 -0700453 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800454 if (DEBUG_SIM_STATES) Log.d(TAG, "ICC_ABSENT isn't showing,"
Jim Millerbbf1a742012-07-17 18:30:30 -0700455 + " we need to show the keyguard since the "
456 + "device isn't provisioned yet.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800457 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700458 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100459 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700460 }
461 }
Adrian Roose92de952016-12-13 12:07:09 -0800462 if (simState == ABSENT) {
463 // MVNO SIMs can become transiently NOT_READY when switching networks,
464 // so we should only lock when they are ABSENT.
Lucas Dupin2e0d4952018-12-05 20:03:53 -0800465 if (simWasLocked) {
Brad Ebingere6c6f722018-12-20 21:11:44 -0800466 if (DEBUG_SIM_STATES) Log.d(TAG, "SIM moved to ABSENT when the "
467 + "previous state was locked. Reset the state.");
Lucas Dupin2e0d4952018-12-05 20:03:53 -0800468 resetStateLocked();
469 }
Adrian Roose92de952016-12-13 12:07:09 -0800470 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700471 }
472 break;
473 case PIN_REQUIRED:
474 case PUK_REQUIRED:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800475 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700476 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800477 if (DEBUG_SIM_STATES) Log.d(TAG,
478 "INTENT_VALUE_ICC_LOCKED and keygaurd isn't "
Jim Millerbbf1a742012-07-17 18:30:30 -0700479 + "showing; need to show keyguard so user can enter sim pin");
Jim Miller5ecd8112013-01-09 18:50:26 -0800480 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700481 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100482 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700483 }
484 }
485 break;
486 case PERM_DISABLED:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800487 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700488 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800489 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED and "
Jim Millerbbf1a742012-07-17 18:30:30 -0700490 + "keygaurd isn't showing.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800491 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700492 } else {
Jim Miller52a61332014-11-12 19:29:51 -0800493 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED, resetStateLocked to"
Jim Millerbbf1a742012-07-17 18:30:30 -0700494 + "show permanently disabled message in lockscreen.");
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100495 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700496 }
497 }
498 break;
499 case READY:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800500 synchronized (KeyguardViewMediator.this) {
Lucas Dupinab3079d2018-06-07 09:41:18 -0700501 if (DEBUG_SIM_STATES) Log.d(TAG, "READY, reset state? " + mShowing);
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700502 if (mShowing && simWasLocked) {
Brad Ebingere6c6f722018-12-20 21:11:44 -0800503 if (DEBUG_SIM_STATES) Log.d(TAG, "SIM moved to READY when the "
504 + "previous state was locked. Reset the state.");
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700505 resetStateLocked();
506 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700507 }
508 break;
Jim Miller52a61332014-11-12 19:29:51 -0800509 default:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800510 if (DEBUG_SIM_STATES) Log.v(TAG, "Unspecific state: " + simState);
Jim Miller52a61332014-11-12 19:29:51 -0800511 break;
Jim Millerbbf1a742012-07-17 18:30:30 -0700512 }
513 }
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000514
515 @Override
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200516 public void onBiometricAuthFailed(BiometricSourceType biometricSourceType) {
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000517 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
518 if (mLockPatternUtils.isSecure(currentUser)) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200519 mLockPatternUtils.getDevicePolicyManager().reportFailedBiometricAttempt(
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000520 currentUser);
521 }
522 }
523
524 @Override
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200525 public void onBiometricAuthenticated(int userId, BiometricSourceType biometricSourceType) {
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000526 if (mLockPatternUtils.isSecure(userId)) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200527 mLockPatternUtils.getDevicePolicyManager().reportSuccessfulBiometricAttempt(
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000528 userId);
529 }
530 }
Adrian Roosd88eb262016-08-04 14:50:48 -0700531
532 @Override
533 public void onTrustChanged(int userId) {
534 if (userId == KeyguardUpdateMonitor.getCurrentUser()) {
535 synchronized (KeyguardViewMediator.this) {
536 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(userId));
537 }
538 }
539 }
540
Jorim Jaggid11d1a92016-08-16 16:02:32 -0700541 @Override
542 public void onHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
543 synchronized (KeyguardViewMediator.this) {
544 notifyHasLockscreenWallpaperChanged(hasLockscreenWallpaper);
545 }
546 }
Jim Millerb0304762012-03-13 20:01:25 -0700547 };
548
Jim Millerdcb3d842012-08-23 19:18:12 -0700549 ViewMediatorCallback mViewMediatorCallback = new ViewMediatorCallback() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100550
Jim Miller2967f482016-01-07 15:05:32 -0800551 @Override
Jeff Brownc7505bc2012-10-05 21:58:15 -0700552 public void userActivity() {
553 KeyguardViewMediator.this.userActivity();
554 }
555
Jim Miller2967f482016-01-07 15:05:32 -0800556 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700557 public void keyguardDone(boolean strongAuth, int targetUserId) {
558 if (targetUserId != ActivityManager.getCurrentUser()) {
559 return;
560 }
561
Jorim Jaggi241ae102016-11-02 21:57:33 -0700562 tryKeyguardDone();
Jim Millerdcb3d842012-08-23 19:18:12 -0700563 }
564
Jim Miller2967f482016-01-07 15:05:32 -0800565 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700566 public void keyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700567 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDoneDrawing");
Jim Millerdcb3d842012-08-23 19:18:12 -0700568 mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700569 Trace.endSection();
Jim Millerdcb3d842012-08-23 19:18:12 -0700570 }
571
572 @Override
573 public void setNeedsInput(boolean needsInput) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100574 mStatusBarKeyguardViewManager.setNeedsInput(needsInput);
Jim Millerdcb3d842012-08-23 19:18:12 -0700575 }
Jeff Brownc7505bc2012-10-05 21:58:15 -0700576
577 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700578 public void keyguardDonePending(boolean strongAuth, int targetUserId) {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700579 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDonePending");
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700580 if (targetUserId != ActivityManager.getCurrentUser()) {
Nick Desaulniersaeb2e1e2016-07-27 15:36:01 -0700581 Trace.endSection();
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700582 return;
583 }
584
John Spurlock34c4fe52012-11-07 10:12:29 -0500585 mKeyguardDonePending = true;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200586 mHideAnimationRun = true;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700587 mHideAnimationRunning = true;
588 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100589 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_PENDING_TIMEOUT,
590 KEYGUARD_DONE_PENDING_TIMEOUT_MS);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700591 Trace.endSection();
John Spurlock34c4fe52012-11-07 10:12:29 -0500592 }
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800593
594 @Override
595 public void keyguardGone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700596 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardGone");
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800597 mKeyguardDisplayManager.hide();
Nick Desaulniers1d396752016-07-25 15:05:33 -0700598 Trace.endSection();
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800599 }
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200600
601 @Override
602 public void readyForKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700603 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#readyForKeyguardDone");
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200604 if (mKeyguardDonePending) {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700605 mKeyguardDonePending = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700606 tryKeyguardDone();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200607 }
Nick Desaulniers1d396752016-07-25 15:05:33 -0700608 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200609 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200610
611 @Override
Andrew Lee72b46d42015-01-30 13:23:21 -0800612 public void resetKeyguard() {
613 resetStateLocked();
614 }
615
616 @Override
Aarthi Balachander0a427ef2018-07-13 15:00:58 -0700617 public void onCancelClicked() {
618 mStatusBarKeyguardViewManager.onCancelClicked();
619 }
620
621 @Override
Matthew Ng66f0b702017-12-08 12:58:42 -0800622 public void onBouncerVisiblityChanged(boolean shown) {
623 synchronized (KeyguardViewMediator.this) {
624 adjustStatusBarLocked(shown);
625 }
626 }
627
628 @Override
Adrian Roos49e057d2014-08-13 17:14:51 +0200629 public void playTrustedSound() {
630 KeyguardViewMediator.this.playTrustedSound();
631 }
Jim Millerab954542014-10-10 18:21:49 -0700632
633 @Override
Adrian Roos94e15a52015-04-16 12:23:18 -0700634 public boolean isScreenOn() {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700635 return mDeviceInteractive;
Adrian Roos94e15a52015-04-16 12:23:18 -0700636 }
Selim Cinek3122fa82015-06-18 01:38:59 -0700637
638 @Override
639 public int getBouncerPromptReason() {
640 int currentUser = ActivityManager.getCurrentUser();
Adrian Roosc13723f2016-01-12 20:29:03 +0100641 boolean trust = mTrustManager.isTrustUsuallyManaged(currentUser);
Lucas Dupin8d48fc42019-04-25 14:34:12 -0700642 boolean biometrics = mUpdateMonitor.isUnlockingWithBiometricsPossible(currentUser);
643 boolean any = trust || biometrics;
Adrian Roosc13723f2016-01-12 20:29:03 +0100644 KeyguardUpdateMonitor.StrongAuthTracker strongAuthTracker =
645 mUpdateMonitor.getStrongAuthTracker();
646 int strongAuth = strongAuthTracker.getStrongAuthForUser(currentUser);
647
648 if (any && !strongAuthTracker.hasUserAuthenticatedSinceBoot()) {
Selim Cinek3122fa82015-06-18 01:38:59 -0700649 return KeyguardSecurityView.PROMPT_REASON_RESTART;
Michal Karpinskic52f8672016-11-18 11:32:45 +0000650 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_TIMEOUT) != 0) {
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700651 return KeyguardSecurityView.PROMPT_REASON_TIMEOUT;
Adrian Roosc13723f2016-01-12 20:29:03 +0100652 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW) != 0) {
653 return KeyguardSecurityView.PROMPT_REASON_DEVICE_ADMIN;
654 } else if (trust && (strongAuth & SOME_AUTH_REQUIRED_AFTER_USER_REQUEST) != 0) {
655 return KeyguardSecurityView.PROMPT_REASON_USER_REQUEST;
656 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_LOCKOUT) != 0) {
657 return KeyguardSecurityView.PROMPT_REASON_AFTER_LOCKOUT;
Selim Cinek3122fa82015-06-18 01:38:59 -0700658 }
659 return KeyguardSecurityView.PROMPT_REASON_NONE;
660 }
David Stevens53a39ea2017-08-23 18:41:49 -0700661
662 @Override
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800663 public CharSequence consumeCustomMessage() {
664 final CharSequence message = mCustomMessage;
665 mCustomMessage = null;
666 return message;
667 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700668 };
669
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200670 public void userActivity() {
Jeff Brown3dc524b2012-09-30 19:49:11 -0700671 mPM.userActivity(SystemClock.uptimeMillis(), false);
Jim Millerdcb3d842012-08-23 19:18:12 -0700672 }
673
Amith Yamasanieb437d42016-04-29 09:31:25 -0700674 boolean mustNotUnlockCurrentUser() {
Christine Franks338c6ed2017-08-08 09:39:16 -0700675 return UserManager.isSplitSystemUser()
Amith Yamasanieb437d42016-04-29 09:31:25 -0700676 && KeyguardUpdateMonitor.getCurrentUser() == UserHandle.USER_SYSTEM;
677 }
678
Jim Millerab954542014-10-10 18:21:49 -0700679 private void setupLocked() {
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200680 mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
Adrian Roos481a6df2014-11-20 19:48:56 +0100681 mTrustManager = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE);
682
Mike Lockwood674d3e42009-10-06 09:28:54 -0400683 mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
684 mShowKeyguardWakeLock.setReferenceCounted(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800685
Adrian Roos1f8025a2016-12-27 10:12:13 -0800686 IntentFilter filter = new IntentFilter();
Adrian Roos1f8025a2016-12-27 10:12:13 -0800687 filter.addAction(Intent.ACTION_SHUTDOWN);
688 mContext.registerReceiver(mBroadcastReceiver, filter);
Jim Millerbbf1a742012-07-17 18:30:30 -0700689
Kevin Chyn18e91aa2018-04-11 12:55:45 -0700690 final IntentFilter delayedActionFilter = new IntentFilter();
691 delayedActionFilter.addAction(DELAYED_KEYGUARD_ACTION);
692 delayedActionFilter.addAction(DELAYED_LOCK_PROFILE_ACTION);
693 mContext.registerReceiver(mDelayedLockBroadcastReceiver, delayedActionFilter,
694 SYSTEMUI_PERMISSION, null /* scheduler */);
695
Robert Snoebergerbe35b762019-03-15 14:33:02 -0400696 InjectionInflationController injectionInflationController =
697 new InjectionInflationController(SystemUIFactory.getInstance().getRootComponent());
698 mKeyguardDisplayManager = new KeyguardDisplayManager(mContext,
699 injectionInflationController);
Jim Miller31921482013-11-06 20:43:55 -0800700
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200701 mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800702
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200703 mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800704
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200705 mLockPatternUtils = new LockPatternUtils(mContext);
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700706 KeyguardUpdateMonitor.setCurrentUser(ActivityManager.getCurrentUser());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800707
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200708 // Assume keyguard is showing (unless it's disabled) until we know for sure, unless Keyguard
709 // is disabled.
710 if (mContext.getResources().getBoolean(
711 com.android.keyguard.R.bool.config_enableKeyguardService)) {
712 setShowingLocked(!shouldWaitForProvisioning()
713 && !mLockPatternUtils.isLockScreenDisabled(
David Stevens53a39ea2017-08-23 18:41:49 -0700714 KeyguardUpdateMonitor.getCurrentUser()),
wilsonshih177261f2019-02-22 12:02:18 +0800715 mAodShowing, true /* forceCallbacks */);
Leif Hendrik Wildenc6dc1c92018-02-01 10:54:15 -0800716 } else {
717 // The system's keyguard is disabled or missing.
wilsonshih177261f2019-02-22 12:02:18 +0800718 setShowingLocked(false, mAodShowing, true);
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200719 }
Jim Millere5f17ab2013-11-13 15:40:48 -0800720
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800721 mStatusBarKeyguardViewManager =
722 SystemUIFactory.getInstance().createStatusBarKeyguardViewManager(mContext,
723 mViewMediatorCallback, mLockPatternUtils);
Daniel Sandler687a3272010-03-13 15:44:47 -0500724 final ContentResolver cr = mContext.getContentResolver();
Marco Nelissend5545bd2011-09-29 12:49:17 -0700725
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700726 mDeviceInteractive = mPM.isInteractive();
Daniel Hansson4b716862012-03-29 11:02:05 +0200727
Jean-Michel Trivi0616db42019-01-28 10:57:21 -0800728 mLockSounds = new SoundPool.Builder()
729 .setMaxStreams(1)
730 .setAudioAttributes(
731 new AudioAttributes.Builder()
732 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
733 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
734 .build())
735 .build();
Jim Millerb14288d2012-09-30 18:25:05 -0700736 String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700737 if (soundPath != null) {
738 mLockSoundId = mLockSounds.load(soundPath, 1);
739 }
740 if (soundPath == null || mLockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700741 Log.w(TAG, "failed to load lock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700742 }
Jim Millerb14288d2012-09-30 18:25:05 -0700743 soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700744 if (soundPath != null) {
745 mUnlockSoundId = mLockSounds.load(soundPath, 1);
746 }
747 if (soundPath == null || mUnlockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700748 Log.w(TAG, "failed to load unlock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700749 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200750 soundPath = Settings.Global.getString(cr, Settings.Global.TRUSTED_SOUND);
751 if (soundPath != null) {
752 mTrustedSoundId = mLockSounds.load(soundPath, 1);
753 }
754 if (soundPath == null || mTrustedSoundId == 0) {
755 Log.w(TAG, "failed to load trusted sound from " + soundPath);
756 }
757
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200758 int lockSoundDefaultAttenuation = mContext.getResources().getInteger(
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700759 com.android.internal.R.integer.config_lockSoundVolumeDb);
Jean-Michel Trivif2b0c112012-07-09 11:59:11 -0700760 mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20);
Adrian Roos0002a452014-07-03 13:46:07 +0200761
762 mHideAnimation = AnimationUtils.loadAnimation(mContext,
763 com.android.internal.R.anim.lock_screen_behind_enter);
Robin Leec41f6ec2017-01-10 17:02:34 +0000764
765 mWorkLockController = new WorkLockActivityController(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800766 }
767
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200768 @Override
769 public void start() {
Jim Millerab954542014-10-10 18:21:49 -0700770 synchronized (this) {
771 setupLocked();
772 }
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200773 putComponent(KeyguardViewMediator.class, this);
774 }
775
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800776 /**
777 * Let us know that the system is ready after startup.
778 */
779 public void onSystemReady() {
Adrian Roos30a2ae62018-04-25 19:09:50 +0200780 mHandler.obtainMessage(SYSTEM_READY).sendToTarget();
781 }
782
783 private void handleSystemReady() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800784 synchronized (this) {
785 if (DEBUG) Log.d(TAG, "onSystemReady");
786 mSystemReady = true;
Jim Miller5ecd8112013-01-09 18:50:26 -0800787 doKeyguardLocked(null);
Selim Cinekedd32b82015-06-23 22:05:58 -0400788 mUpdateMonitor.registerCallback(mUpdateCallback);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800789 }
Jim Miller3fd47af2012-09-21 19:55:27 -0700790 // Most services aren't available until the system reaches the ready state, so we
791 // send it here when the device first boots.
792 maybeSendUserPresentBroadcast();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800793 }
794
795 /**
796 * Called to let us know the screen was turned off.
Adrian Roose99bc052017-11-20 17:55:31 +0100797 * @param why either {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_USER} or
798 * {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_TIMEOUT}.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800799 */
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700800 public void onStartedGoingToSleep(int why) {
801 if (DEBUG) Log.d(TAG, "onStartedGoingToSleep(" + why + ")");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800802 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700803 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700804 mGoingToSleep = true;
John Spurlock14adfe42012-11-08 10:29:26 -0500805
Jim Millera4edd152012-01-06 18:24:04 -0800806 // Lock immediately based on setting if secure (user has a pin/pattern/password).
807 // This also "locks" the device when not secure to provide easy access to the
808 // camera while preventing unwanted input.
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700809 int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jim Millera4edd152012-01-06 18:24:04 -0800810 final boolean lockImmediately =
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700811 mLockPatternUtils.getPowerButtonInstantlyLocks(currentUser)
812 || !mLockPatternUtils.isSecure(currentUser);
Clara Bayarri56878a92015-10-29 15:43:55 +0000813 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000814 mLockLater = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800815 if (mExitSecureCallback != null) {
816 if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled");
Jim Miller5ecd8112013-01-09 18:50:26 -0800817 try {
818 mExitSecureCallback.onKeyguardExitResult(false);
819 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800820 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800821 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800822 mExitSecureCallback = null;
823 if (!mExternallyEnabled) {
Jim Miller9c20d0e2010-01-20 15:00:23 -0800824 hideLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800825 }
826 } else if (mShowing) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700827 mPendingReset = true;
Adrian Roose99bc052017-11-20 17:55:31 +0100828 } else if ((why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_TIMEOUT && timeout > 0)
829 || (why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER && !lockImmediately)) {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700830 doKeyguardLaterLocked(timeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000831 mLockLater = true;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700832 } else if (!mLockPatternUtils.isLockScreenDisabled(currentUser)) {
833 mPendingLock = true;
834 }
835
Jorim Jaggi853cbe32015-06-04 16:31:54 -0700836 if (mPendingLock) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700837 playSounds(true);
838 }
839 }
Jorim Jaggi95e40382015-09-16 15:53:42 -0700840 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedGoingToSleep(why);
Jorim Jaggi18f18ae2015-09-10 15:48:21 -0700841 notifyStartedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700842 }
843
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700844 public void onFinishedGoingToSleep(int why, boolean cameraGestureTriggered) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700845 if (DEBUG) Log.d(TAG, "onFinishedGoingToSleep(" + why + ")");
846 synchronized (this) {
847 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700848 mGoingToSleep = false;
Adrian Roose4cb6c8a2017-07-19 18:08:07 +0200849 mWakeAndUnlocking = false;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700850
851 resetKeyguardDonePendingLocked();
852 mHideAnimationRun = false;
853
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700854 notifyFinishedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700855
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700856 if (cameraGestureTriggered) {
857 Log.i(TAG, "Camera gesture was triggered, preventing Keyguard locking.");
858
859 // Just to make sure, make sure the device is awake.
860 mContext.getSystemService(PowerManager.class).wakeUp(SystemClock.uptimeMillis(),
Michael Wrighte3001042019-02-05 00:13:14 +0000861 PowerManager.WAKE_REASON_CAMERA_LAUNCH,
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700862 "com.android.systemui:CAMERA_GESTURE_PREVENT_LOCK");
863 mPendingLock = false;
864 mPendingReset = false;
865 }
866
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700867 if (mPendingReset) {
868 resetStateLocked();
869 mPendingReset = false;
870 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000871
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700872 if (mPendingLock) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800873 doKeyguardLocked(null);
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700874 mPendingLock = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800875 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000876
877 // We do not have timeout and power button instant lock setting for profile lock.
878 // So we use the personal setting if there is any. But if there is no device
879 // we need to make sure we lock it immediately when the screen is off.
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700880 if (!mLockLater && !cameraGestureTriggered) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000881 doKeyguardForChildProfilesLocked();
882 }
883
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800884 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700885 KeyguardUpdateMonitor.getInstance(mContext).dispatchFinishedGoingToSleep(why);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800886 }
887
Clara Bayarri56878a92015-10-29 15:43:55 +0000888 private long getLockTimeout(int userId) {
Jeff Brown6aaf2952012-10-05 16:01:08 -0700889 // if the screen turned off because of timeout or the user hit the power button
890 // and we don't need to lock immediately, set an alarm
891 // to enable it a little bit later (i.e, give the user a chance
892 // to turn the screen back on within a certain window without
893 // having to unlock the screen)
894 final ContentResolver cr = mContext.getContentResolver();
895
Jeff Brown6aaf2952012-10-05 16:01:08 -0700896 // From SecuritySettings
897 final long lockAfterTimeout = Settings.Secure.getInt(cr,
898 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT,
899 KEYGUARD_LOCK_AFTER_DELAY_DEFAULT);
900
901 // From DevicePolicyAdmin
902 final long policyTimeout = mLockPatternUtils.getDevicePolicyManager()
Pavel Grafov28939982017-10-03 15:11:52 +0100903 .getMaximumTimeToLock(null, userId);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700904
905 long timeout;
Clara Bayarri56878a92015-10-29 15:43:55 +0000906
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000907 if (policyTimeout <= 0) {
Clara Bayarri56878a92015-10-29 15:43:55 +0000908 timeout = lockAfterTimeout;
909 } else {
910 // From DisplaySettings
911 long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT,
912 KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT);
913
Jeff Brown6aaf2952012-10-05 16:01:08 -0700914 // policy in effect. Make sure we don't go beyond policy limit.
915 displayTimeout = Math.max(displayTimeout, 0); // ignore negative values
916 timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000917 timeout = Math.max(timeout, 0);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700918 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700919 return timeout;
920 }
Jeff Brown6aaf2952012-10-05 16:01:08 -0700921
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700922 private void doKeyguardLaterLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000923 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700924 if (timeout == 0) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800925 doKeyguardLocked(null);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700926 } else {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700927 doKeyguardLaterLocked(timeout);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700928 }
929 }
930
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700931 private void doKeyguardLaterLocked(long timeout) {
932 // Lock in the future
933 long when = SystemClock.elapsedRealtime() + timeout;
934 Intent intent = new Intent(DELAYED_KEYGUARD_ACTION);
935 intent.putExtra("seq", mDelayedShowingSequence);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700936 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700937 PendingIntent sender = PendingIntent.getBroadcast(mContext,
938 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Jim Millera622d3cc2016-03-02 16:02:24 -0800939 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700940 if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = "
941 + mDelayedShowingSequence);
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000942 doKeyguardLaterForChildProfilesLocked();
Clara Bayarri56878a92015-10-29 15:43:55 +0000943 }
Clara Bayarri10ad84a2015-12-01 17:38:05 +0000944
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000945 private void doKeyguardLaterForChildProfilesLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000946 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700947 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
948 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
949 long userTimeout = getLockTimeout(profileId);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000950 if (userTimeout == 0) {
951 doKeyguardForChildProfilesLocked();
952 } else {
953 long userWhen = SystemClock.elapsedRealtime() + userTimeout;
954 Intent lockIntent = new Intent(DELAYED_LOCK_PROFILE_ACTION);
955 lockIntent.putExtra("seq", mDelayedProfileShowingSequence);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700956 lockIntent.putExtra(Intent.EXTRA_USER_ID, profileId);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700957 lockIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000958 PendingIntent lockSender = PendingIntent.getBroadcast(
959 mContext, 0, lockIntent, PendingIntent.FLAG_CANCEL_CURRENT);
960 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
961 userWhen, lockSender);
962 }
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000963 }
964 }
965 }
966
967 private void doKeyguardForChildProfilesLocked() {
968 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700969 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
970 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
971 lockProfile(profileId);
Clara Bayarri56878a92015-10-29 15:43:55 +0000972 }
973 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700974 }
975
Jeff Brown6aaf2952012-10-05 16:01:08 -0700976 private void cancelDoKeyguardLaterLocked() {
977 mDelayedShowingSequence++;
978 }
979
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000980 private void cancelDoKeyguardForChildProfilesLocked() {
981 mDelayedProfileShowingSequence++;
982 }
983
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800984 /**
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700985 * Let's us know when the device is waking up.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800986 */
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700987 public void onStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700988 Trace.beginSection("KeyguardViewMediator#onStartedWakingUp");
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700989
990 // TODO: Rename all screen off/on references to interactive/sleeping
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800991 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700992 mDeviceInteractive = true;
Jeff Brown6aaf2952012-10-05 16:01:08 -0700993 cancelDoKeyguardLaterLocked();
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000994 cancelDoKeyguardForChildProfilesLocked();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700995 if (DEBUG) Log.d(TAG, "onStartedWakingUp, seq = " + mDelayedShowingSequence);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700996 notifyStartedWakingUp();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800997 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700998 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedWakingUp();
Jim Miller3fd47af2012-09-21 19:55:27 -0700999 maybeSendUserPresentBroadcast();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001000 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -07001001 }
1002
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001003 public void onScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001004 Trace.beginSection("KeyguardViewMediator#onScreenTurningOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001005 notifyScreenOn(callback);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001006 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001007 }
1008
1009 public void onScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001010 Trace.beginSection("KeyguardViewMediator#onScreenTurnedOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001011 notifyScreenTurnedOn();
1012 mUpdateMonitor.dispatchScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001013 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001014 }
1015
1016 public void onScreenTurnedOff() {
1017 notifyScreenTurnedOff();
1018 mUpdateMonitor.dispatchScreenTurnedOff();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001019 }
1020
Jim Miller3fd47af2012-09-21 19:55:27 -07001021 private void maybeSendUserPresentBroadcast() {
Adrian Roos8150d2a2015-04-16 17:11:20 -07001022 if (mSystemReady && mLockPatternUtils.isLockScreenDisabled(
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001023 KeyguardUpdateMonitor.getCurrentUser())) {
Jim Miller3fd47af2012-09-21 19:55:27 -07001024 // Lock screen is disabled because the user has set the preference to "None".
1025 // In this case, send out ACTION_USER_PRESENT here instead of in
1026 // handleKeyguardDone()
1027 sendUserPresentBroadcast();
Adrian Roosfb95a812016-06-20 14:58:59 -07001028 } else if (mSystemReady && shouldWaitForProvisioning()) {
1029 // Skipping the lockscreen because we're not yet provisioned, but we still need to
1030 // notify the StrongAuthTracker that it's now safe to run trust agents, in case the
1031 // user sets a credential later.
1032 getLockPatternUtils().userPresent(KeyguardUpdateMonitor.getCurrentUser());
Jim Miller3fd47af2012-09-21 19:55:27 -07001033 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001034 }
1035
1036 /**
Jeff Brown6aaf2952012-10-05 16:01:08 -07001037 * A dream started. We should lock after the usual screen-off lock timeout but only
1038 * if there is a secure lock pattern.
1039 */
1040 public void onDreamingStarted() {
Selim Cinek99415392016-09-09 14:58:41 -07001041 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001042 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001043 if (mDeviceInteractive
1044 && mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001045 doKeyguardLaterLocked();
1046 }
1047 }
1048 }
1049
1050 /**
1051 * A dream stopped.
1052 */
1053 public void onDreamingStopped() {
Selim Cinek99415392016-09-09 14:58:41 -07001054 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001055 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001056 if (mDeviceInteractive) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001057 cancelDoKeyguardLaterLocked();
1058 }
1059 }
1060 }
1061
1062 /**
Adrian Roose99bc052017-11-20 17:55:31 +01001063 * Same semantics as {@link WindowManagerPolicyConstants#enableKeyguard}; provide
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001064 * a way for external stuff to override normal keyguard behavior. For instance
1065 * the phone app disables the keyguard when it receives incoming calls.
1066 */
1067 public void setKeyguardEnabled(boolean enabled) {
1068 synchronized (this) {
1069 if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")");
1070
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001071 mExternallyEnabled = enabled;
1072
1073 if (!enabled && mShowing) {
1074 if (mExitSecureCallback != null) {
1075 if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring");
1076 // we're in the process of handling a request to verify the user
1077 // can get past the keyguard. ignore extraneous requests to disable / reenable
1078 return;
1079 }
1080
1081 // hiding keyguard that is showing, remember to reshow later
1082 if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, "
1083 + "disabling status bar expansion");
1084 mNeedToReshowWhenReenabled = true;
Jim Millerab954542014-10-10 18:21:49 -07001085 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001086 hideLocked();
1087 } else if (enabled && mNeedToReshowWhenReenabled) {
1088 // reenabled after previously hidden, reshow
1089 if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling "
1090 + "status bar expansion");
1091 mNeedToReshowWhenReenabled = false;
Jim Millerab954542014-10-10 18:21:49 -07001092 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001093
1094 if (mExitSecureCallback != null) {
1095 if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting");
Jim Miller5ecd8112013-01-09 18:50:26 -08001096 try {
1097 mExitSecureCallback.onKeyguardExitResult(false);
1098 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001099 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001100 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001101 mExitSecureCallback = null;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001102 resetStateLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001103 } else {
Adam Cohenf7522022012-10-03 20:03:18 -07001104 showLocked(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001105
1106 // block until we know the keygaurd is done drawing (and post a message
1107 // to unblock us after a timeout so we don't risk blocking too long
1108 // and causing an ANR).
1109 mWaitingUntilKeyguardVisible = true;
1110 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS);
1111 if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false");
1112 while (mWaitingUntilKeyguardVisible) {
1113 try {
1114 wait();
1115 } catch (InterruptedException e) {
1116 Thread.currentThread().interrupt();
1117 }
1118 }
1119 if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible");
1120 }
1121 }
1122 }
1123 }
1124
1125 /**
1126 * @see android.app.KeyguardManager#exitKeyguardSecurely
1127 */
Jim Miller25190572013-02-28 17:36:24 -08001128 public void verifyUnlock(IKeyguardExitCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001129 Trace.beginSection("KeyguardViewMediator#verifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001130 synchronized (this) {
1131 if (DEBUG) Log.d(TAG, "verifyUnlock");
Jim Millerb256e4e22014-10-31 17:27:13 -07001132 if (shouldWaitForProvisioning()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001133 // don't allow this api when the device isn't provisioned
1134 if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned");
Jim Miller5ecd8112013-01-09 18:50:26 -08001135 try {
Jim Miller25190572013-02-28 17:36:24 -08001136 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001137 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001138 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001139 }
Mike Lockwood5d258b62009-12-02 13:50:45 -05001140 } else if (mExternallyEnabled) {
1141 // this only applies when the user has externally disabled the
1142 // keyguard. this is unexpected and means the user is not
1143 // using the api properly.
1144 Log.w(TAG, "verifyUnlock called when not externally disabled");
Jim Miller5ecd8112013-01-09 18:50:26 -08001145 try {
Jim Miller25190572013-02-28 17:36:24 -08001146 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001147 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001148 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001149 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001150 } else if (mExitSecureCallback != null) {
1151 // already in progress with someone else
Jim Miller5ecd8112013-01-09 18:50:26 -08001152 try {
Jim Miller25190572013-02-28 17:36:24 -08001153 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001154 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001155 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001156 }
Jorim Jaggi302475e2015-09-22 12:44:47 -07001157 } else if (!isSecure()) {
1158
1159 // Keyguard is not secure, no need to do anything, and we don't need to reshow
1160 // the Keyguard after the client releases the Keyguard lock.
1161 mExternallyEnabled = true;
1162 mNeedToReshowWhenReenabled = false;
1163 updateInputRestricted();
1164 try {
1165 callback.onKeyguardExitResult(true);
1166 } catch (RemoteException e) {
1167 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1168 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001169 } else {
Jorim Jaggi302475e2015-09-22 12:44:47 -07001170
1171 // Since we prevent apps from hiding the Keyguard if we are secure, this should be
1172 // a no-op as well.
1173 try {
1174 callback.onKeyguardExitResult(false);
1175 } catch (RemoteException e) {
1176 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1177 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001178 }
1179 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001180 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001181 }
1182
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001183 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001184 * Is the keyguard currently showing and not being force hidden?
Mike Lockwood09a40402009-11-08 00:33:23 -05001185 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001186 public boolean isShowingAndNotOccluded() {
1187 return mShowing && !mOccluded;
1188 }
1189
1190 /**
1191 * Notify us when the keyguard is occluded by another window
1192 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001193 public void setOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001194 Trace.beginSection("KeyguardViewMediator#setOccluded");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001195 if (DEBUG) Log.d(TAG, "setOccluded " + isOccluded);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001196 mHandler.removeMessages(SET_OCCLUDED);
Jorim Jaggi6626f542016-08-22 13:08:44 -07001197 Message msg = mHandler.obtainMessage(SET_OCCLUDED, isOccluded ? 1 : 0, animate ? 1 : 0);
Mike Lockwood9200a392009-11-17 20:25:58 -05001198 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001199 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001200 }
1201
Lucas Dupin2986c152018-04-09 20:49:41 -07001202 public boolean isHiding() {
1203 return mHiding;
1204 }
1205
Mike Lockwood9200a392009-11-17 20:25:58 -05001206 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001207 * Handles SET_OCCLUDED message sent by setOccluded()
Mike Lockwood9200a392009-11-17 20:25:58 -05001208 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001209 private void handleSetOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001210 Trace.beginSection("KeyguardViewMediator#handleSetOccluded");
Mike Lockwood09a40402009-11-08 00:33:23 -05001211 synchronized (KeyguardViewMediator.this) {
Adrian Roosf253eeb2015-04-15 18:03:08 -07001212 if (mHiding && isOccluded) {
1213 // We're in the process of going away but WindowManager wants to show a
1214 // SHOW_WHEN_LOCKED activity instead.
1215 startKeyguardExitAnimation(0, 0);
1216 }
1217
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001218 if (mOccluded != isOccluded) {
1219 mOccluded = isOccluded;
Kevin Chyn2fefd462017-04-28 12:18:19 -07001220 mUpdateMonitor.setKeyguardOccluded(isOccluded);
Selim Cinek2f6272e2017-03-15 16:19:10 -07001221 mStatusBarKeyguardViewManager.setOccluded(isOccluded, animate
1222 && mDeviceInteractive);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001223 adjustStatusBarLocked();
Mike Lockwood9200a392009-11-17 20:25:58 -05001224 }
Mike Lockwood09a40402009-11-08 00:33:23 -05001225 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001226 Trace.endSection();
Mike Lockwood09a40402009-11-08 00:33:23 -05001227 }
1228
1229 /**
Mike Lockwood28569302010-01-28 11:54:40 -05001230 * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout.
1231 * This must be safe to call from any thread and with any window manager locks held.
1232 */
Adam Cohenf7522022012-10-03 20:03:18 -07001233 public void doKeyguardTimeout(Bundle options) {
Mike Lockwood28569302010-01-28 11:54:40 -05001234 mHandler.removeMessages(KEYGUARD_TIMEOUT);
Adam Cohenf7522022012-10-03 20:03:18 -07001235 Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options);
Mike Lockwood28569302010-01-28 11:54:40 -05001236 mHandler.sendMessage(msg);
1237 }
1238
1239 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001240 * Given the state of the keyguard, is the input restricted?
1241 * Input is restricted when the keyguard is showing, or when the keyguard
1242 * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet.
1243 */
1244 public boolean isInputRestricted() {
Adrian Roos9f33d6c2015-06-15 15:58:35 -07001245 return mShowing || mNeedToReshowWhenReenabled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001246 }
1247
Jim Millerab954542014-10-10 18:21:49 -07001248 private void updateInputRestricted() {
1249 synchronized (this) {
1250 updateInputRestrictedLocked();
1251 }
1252 }
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001253
Jim Millerab954542014-10-10 18:21:49 -07001254 private void updateInputRestrictedLocked() {
1255 boolean inputRestricted = isInputRestricted();
1256 if (mInputRestricted != inputRestricted) {
1257 mInputRestricted = inputRestricted;
dooyoung.hwang328472e2015-05-21 16:09:43 +09001258 int size = mKeyguardStateCallbacks.size();
1259 for (int i = size - 1; i >= 0; i--) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001260 final IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001261 try {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001262 callback.onInputRestrictedStateChanged(inputRestricted);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001263 } catch (RemoteException e) {
1264 Slog.w(TAG, "Failed to call onDeviceProvisioned", e);
1265 if (e instanceof DeadObjectException) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001266 mKeyguardStateCallbacks.remove(callback);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001267 }
Jim Millerab954542014-10-10 18:21:49 -07001268 }
Jim Millerab954542014-10-10 18:21:49 -07001269 }
1270 }
1271 }
1272
Dianne Hackbornb446e972009-09-20 15:23:25 -07001273 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001274 * Enable the keyguard if the settings are appropriate.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001275 */
Adam Cohenf7522022012-10-03 20:03:18 -07001276 private void doKeyguardLocked(Bundle options) {
Adrian Roosca8a2162017-08-17 19:00:58 +02001277 if (KeyguardUpdateMonitor.CORE_APPS_ONLY) {
1278 // Don't show keyguard during half-booted cryptkeeper stage.
1279 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because booting to cryptkeeper");
1280 return;
1281 }
1282
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001283 // if another app is disabling us, don't show
1284 if (!mExternallyEnabled) {
1285 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled");
Karl Rosaenab100082009-03-24 22:35:17 -07001286
Adrian Roos1c8e3c02018-11-20 20:07:55 +01001287 mNeedToReshowWhenReenabled = true;
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001288 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001289 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001290
1291 // if the keyguard is already showing, don't bother
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001292 if (mStatusBarKeyguardViewManager.isShowing()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001293 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing");
Jorim Jaggi95e89ca2014-11-24 20:12:50 +01001294 resetStateLocked();
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001295 return;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001296 }
1297
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001298 // In split system user mode, we never unlock system user.
Amith Yamasanieb437d42016-04-29 09:31:25 -07001299 if (!mustNotUnlockCurrentUser()
Amith Yamasani27e025b2015-11-06 10:34:41 -08001300 || !mUpdateMonitor.isDeviceProvisioned()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001301
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001302 // if the setup wizard hasn't run yet, don't show
1303 final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", false);
1304 final boolean absent = SubscriptionManager.isValidSubscriptionId(
Adrian Roose92de952016-12-13 12:07:09 -08001305 mUpdateMonitor.getNextSubIdForState(ABSENT));
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001306 final boolean disabled = SubscriptionManager.isValidSubscriptionId(
1307 mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.PERM_DISABLED));
1308 final boolean lockedOrMissing = mUpdateMonitor.isSimPinSecure()
1309 || ((absent || disabled) && requireSim);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001310
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001311 if (!lockedOrMissing && shouldWaitForProvisioning()) {
1312 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned"
1313 + " and the sim is not locked or missing");
1314 return;
1315 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001316
Evan Rosky13a58a92016-07-27 15:51:09 -07001317 boolean forceShow = options != null && options.getBoolean(OPTION_FORCE_SHOW, false);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001318 if (mLockPatternUtils.isLockScreenDisabled(KeyguardUpdateMonitor.getCurrentUser())
Evan Rosky13a58a92016-07-27 15:51:09 -07001319 && !lockedOrMissing && !forceShow) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001320 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off");
1321 return;
1322 }
1323
1324 if (mLockPatternUtils.checkVoldPassword(KeyguardUpdateMonitor.getCurrentUser())) {
1325 if (DEBUG) Log.d(TAG, "Not showing lock screen since just decrypted");
1326 // Without this, settings is not enabled until the lock screen first appears
Lucas Dupin47a65c72018-02-15 14:16:18 -08001327 setShowingLocked(false, mAodShowing);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001328 hideLocked();
1329 return;
1330 }
Paul Lawrence945490c2014-03-27 16:37:28 +00001331 }
1332
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001333 if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");
Adam Cohenf7522022012-10-03 20:03:18 -07001334 showLocked(options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001335 }
1336
Clara Bayarri56878a92015-10-29 15:43:55 +00001337 private void lockProfile(int userId) {
1338 mTrustManager.setDeviceLockedForUser(userId, true);
1339 }
1340
Jim Millerb256e4e22014-10-31 17:27:13 -07001341 private boolean shouldWaitForProvisioning() {
1342 return !mUpdateMonitor.isDeviceProvisioned() && !isSecure();
1343 }
1344
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001345 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001346 * Dismiss the keyguard through the security layers.
Jorim Jaggi241ae102016-11-02 21:57:33 -07001347 * @param callback Callback to be informed about the result
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001348 * @param message Message that should be displayed on the bouncer.
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001349 */
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001350 private void handleDismiss(IKeyguardDismissCallback callback, CharSequence message) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001351 if (mShowing) {
1352 if (callback != null) {
1353 mDismissCallbackRegistry.addCallback(callback);
1354 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001355 mCustomMessage = message;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001356 mStatusBarKeyguardViewManager.dismissAndCollapse();
Jorim Jaggi241ae102016-11-02 21:57:33 -07001357 } else if (callback != null) {
1358 new DismissCallbackWrapper(callback).notifyDismissError();
Jim Miller87d03662012-11-05 20:28:09 -08001359 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001360 }
1361
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001362 public void dismiss(IKeyguardDismissCallback callback, CharSequence message) {
1363 mHandler.obtainMessage(DISMISS, new DismissMessage(callback, message)).sendToTarget();
Jim Miller60013792013-10-03 18:31:34 -07001364 }
1365
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001366 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001367 * Send message to keyguard telling it to reset its state.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001368 * @see #handleReset
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001369 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001370 private void resetStateLocked() {
Jim Miller4894a012013-04-03 15:23:55 -07001371 if (DEBUG) Log.e(TAG, "resetStateLocked");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001372 Message msg = mHandler.obtainMessage(RESET);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001373 mHandler.sendMessage(msg);
1374 }
1375
1376 /**
1377 * Send message to keyguard telling it to verify unlock
1378 * @see #handleVerifyUnlock()
1379 */
1380 private void verifyUnlockLocked() {
1381 if (DEBUG) Log.d(TAG, "verifyUnlockLocked");
1382 mHandler.sendEmptyMessage(VERIFY_UNLOCK);
1383 }
1384
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001385 private void notifyStartedGoingToSleep() {
1386 if (DEBUG) Log.d(TAG, "notifyStartedGoingToSleep");
1387 mHandler.sendEmptyMessage(NOTIFY_STARTED_GOING_TO_SLEEP);
1388 }
1389
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001390 private void notifyFinishedGoingToSleep() {
1391 if (DEBUG) Log.d(TAG, "notifyFinishedGoingToSleep");
1392 mHandler.sendEmptyMessage(NOTIFY_FINISHED_GOING_TO_SLEEP);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001393 }
1394
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001395 private void notifyStartedWakingUp() {
1396 if (DEBUG) Log.d(TAG, "notifyStartedWakingUp");
1397 mHandler.sendEmptyMessage(NOTIFY_STARTED_WAKING_UP);
1398 }
1399
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001400 private void notifyScreenOn(IKeyguardDrawnCallback callback) {
1401 if (DEBUG) Log.d(TAG, "notifyScreenOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001402 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNING_ON, callback);
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001403 mHandler.sendMessage(msg);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001404 }
1405
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001406 private void notifyScreenTurnedOn() {
1407 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOn");
1408 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_ON);
1409 mHandler.sendMessage(msg);
1410 }
1411
1412 private void notifyScreenTurnedOff() {
1413 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOff");
1414 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_OFF);
1415 mHandler.sendMessage(msg);
1416 }
1417
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001418 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001419 * Send message to keyguard telling it to show itself
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001420 * @see #handleShow
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001421 */
Adam Cohenf7522022012-10-03 20:03:18 -07001422 private void showLocked(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001423 Trace.beginSection("KeyguardViewMediator#showLocked aqcuiring mShowKeyguardWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001424 if (DEBUG) Log.d(TAG, "showLocked");
Mike Lockwood674d3e42009-10-06 09:28:54 -04001425 // ensure we stay awake until we are finished displaying the keyguard
1426 mShowKeyguardWakeLock.acquire();
Adam Cohenf7522022012-10-03 20:03:18 -07001427 Message msg = mHandler.obtainMessage(SHOW, options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001428 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001429 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001430 }
1431
1432 /**
1433 * Send message to keyguard telling it to hide itself
Jim Miller9c20d0e2010-01-20 15:00:23 -08001434 * @see #handleHide()
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001435 */
1436 private void hideLocked() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001437 Trace.beginSection("KeyguardViewMediator#hideLocked");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001438 if (DEBUG) Log.d(TAG, "hideLocked");
1439 Message msg = mHandler.obtainMessage(HIDE);
1440 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001441 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001442 }
1443
Dianne Hackbornb446e972009-09-20 15:23:25 -07001444 public boolean isSecure() {
Evan Rosky13a58a92016-07-27 15:51:09 -07001445 return isSecure(KeyguardUpdateMonitor.getCurrentUser());
1446 }
1447
1448 public boolean isSecure(int userId) {
1449 return mLockPatternUtils.isSecure(userId)
1450 || KeyguardUpdateMonitor.getInstance(mContext).isSimPinSecure();
Dianne Hackbornb446e972009-09-20 15:23:25 -07001451 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001452
Evan Rosky18396452016-07-27 15:19:37 -07001453 public void setSwitchingUser(boolean switching) {
Selim Cinekbbe19242017-12-08 15:42:08 -08001454 KeyguardUpdateMonitor.getInstance(mContext).setSwitchingUser(switching);
Evan Rosky18396452016-07-27 15:19:37 -07001455 }
1456
Craig Mautnerf1b67412012-09-19 13:18:29 -07001457 /**
1458 * Update the newUserId. Call while holding WindowManagerService lock.
Jim Milleree82f8f2012-10-01 16:26:18 -07001459 * NOTE: Should only be called by KeyguardViewMediator in response to the user id changing.
1460 *
Craig Mautnerf1b67412012-09-19 13:18:29 -07001461 * @param newUserId The id of the incoming user.
1462 */
1463 public void setCurrentUser(int newUserId) {
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001464 KeyguardUpdateMonitor.setCurrentUser(newUserId);
Adrian Roosd88eb262016-08-04 14:50:48 -07001465 synchronized (this) {
1466 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(newUserId));
1467 }
Craig Mautnerf1b67412012-09-19 13:18:29 -07001468 }
1469
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001470 /**
1471 * This broadcast receiver should be registered with the SystemUI permission.
1472 */
1473 private final BroadcastReceiver mDelayedLockBroadcastReceiver = new BroadcastReceiver() {
Amith Yamasani52c489c2012-03-28 11:42:42 -07001474 @Override
1475 public void onReceive(Context context, Intent intent) {
Jim Millerbbf1a742012-07-17 18:30:30 -07001476 if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
1477 final int sequence = intent.getIntExtra("seq", 0);
Jim Millerf3447352011-08-07 14:00:09 -07001478 if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = "
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001479 + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001480 synchronized (KeyguardViewMediator.this) {
Jim Miller2967f482016-01-07 15:05:32 -08001481 if (mDelayedShowingSequence == sequence) {
1482 doKeyguardLocked(null);
1483 }
Clara Bayarri56878a92015-10-29 15:43:55 +00001484 }
1485 } else if (DELAYED_LOCK_PROFILE_ACTION.equals(intent.getAction())) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001486 final int sequence = intent.getIntExtra("seq", 0);
Clara Bayarri56878a92015-10-29 15:43:55 +00001487 int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, 0);
1488 if (userId != 0) {
1489 synchronized (KeyguardViewMediator.this) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001490 if (mDelayedProfileShowingSequence == sequence) {
1491 lockProfile(userId);
1492 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001493 }
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001494 }
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001495 }
1496 }
1497 };
1498
1499 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1500 @Override
1501 public void onReceive(Context context, Intent intent) {
1502 if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
Adrian Roos1f8025a2016-12-27 10:12:13 -08001503 synchronized (KeyguardViewMediator.this){
1504 mShuttingDown = true;
1505 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001506 }
1507 }
1508 };
1509
Jorim Jaggi241ae102016-11-02 21:57:33 -07001510 public void keyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001511 Trace.beginSection("KeyguardViewMediator#keyguardDone");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001512 if (DEBUG) Log.d(TAG, "keyguardDone()");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001513 userActivity();
Jim Miller60013792013-10-03 18:31:34 -07001514 EventLog.writeEvent(70000, 2);
Jorim Jaggi241ae102016-11-02 21:57:33 -07001515 Message msg = mHandler.obtainMessage(KEYGUARD_DONE);
Jim Miller60013792013-10-03 18:31:34 -07001516 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001517 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001518 }
1519
1520 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001521 * This handler will be associated with the policy thread, which will also
1522 * be the UI thread of the keyguard. Since the apis of the policy, and therefore
1523 * this class, can be called by other threads, any action that directly
1524 * interacts with the keyguard ui should be posted to this handler, rather
1525 * than called directly.
1526 */
Jim Millerdcb3d842012-08-23 19:18:12 -07001527 private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001528 @Override
Wink Saville37c124c2009-04-02 01:37:02 -07001529 public void handleMessage(Message msg) {
1530 switch (msg.what) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001531 case SHOW:
Adam Cohenf7522022012-10-03 20:03:18 -07001532 handleShow((Bundle) msg.obj);
Jim Miller60013792013-10-03 18:31:34 -07001533 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001534 case HIDE:
1535 handleHide();
Jim Miller60013792013-10-03 18:31:34 -07001536 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001537 case RESET:
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001538 handleReset();
Jim Miller60013792013-10-03 18:31:34 -07001539 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001540 case VERIFY_UNLOCK:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001541 Trace.beginSection("KeyguardViewMediator#handleMessage VERIFY_UNLOCK");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001542 handleVerifyUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001543 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001544 break;
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001545 case NOTIFY_STARTED_GOING_TO_SLEEP:
1546 handleNotifyStartedGoingToSleep();
1547 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001548 case NOTIFY_FINISHED_GOING_TO_SLEEP:
1549 handleNotifyFinishedGoingToSleep();
Jim Miller60013792013-10-03 18:31:34 -07001550 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001551 case NOTIFY_SCREEN_TURNING_ON:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001552 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNING_ON");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001553 handleNotifyScreenTurningOn((IKeyguardDrawnCallback) msg.obj);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001554 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001555 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001556 case NOTIFY_SCREEN_TURNED_ON:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001557 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNED_ON");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001558 handleNotifyScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001559 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001560 break;
1561 case NOTIFY_SCREEN_TURNED_OFF:
1562 handleNotifyScreenTurnedOff();
1563 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001564 case NOTIFY_STARTED_WAKING_UP:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001565 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_STARTED_WAKING_UP");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001566 handleNotifyStartedWakingUp();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001567 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001568 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001569 case KEYGUARD_DONE:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001570 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001571 handleKeyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001572 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001573 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001574 case KEYGUARD_DONE_DRAWING:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001575 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_DRAWING");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001576 handleKeyguardDoneDrawing();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001577 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001578 break;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001579 case SET_OCCLUDED:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001580 Trace.beginSection("KeyguardViewMediator#handleMessage SET_OCCLUDED");
Jorim Jaggi6626f542016-08-22 13:08:44 -07001581 handleSetOccluded(msg.arg1 != 0, msg.arg2 != 0);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001582 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001583 break;
Mike Lockwood28569302010-01-28 11:54:40 -05001584 case KEYGUARD_TIMEOUT:
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001585 synchronized (KeyguardViewMediator.this) {
Adam Cohenf7522022012-10-03 20:03:18 -07001586 doKeyguardLocked((Bundle) msg.obj);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001587 }
1588 break;
Jim Miller60013792013-10-03 18:31:34 -07001589 case DISMISS:
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001590 final DismissMessage message = (DismissMessage) msg.obj;
1591 handleDismiss(message.getCallback(), message.getMessage());
Jim Miller60013792013-10-03 18:31:34 -07001592 break;
Jorim Jaggi0d674622014-05-21 01:34:15 +02001593 case START_KEYGUARD_EXIT_ANIM:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001594 Trace.beginSection("KeyguardViewMediator#handleMessage START_KEYGUARD_EXIT_ANIM");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001595 StartKeyguardExitAnimParams params = (StartKeyguardExitAnimParams) msg.obj;
1596 handleStartKeyguardExitAnimation(params.startTime, params.fadeoutDuration);
Dave Mankoffdde5ee62019-05-02 17:36:11 -04001597 FalsingManagerFactory.getInstance(mContext).onSucccessfulUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001598 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001599 break;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001600 case KEYGUARD_DONE_PENDING_TIMEOUT:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001601 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_PENDING_TIMEOUT");
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001602 Log.w(TAG, "Timeout while waiting for activity drawn!");
Nick Desaulniers1d396752016-07-25 15:05:33 -07001603 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001604 break;
Adrian Roos30a2ae62018-04-25 19:09:50 +02001605 case SYSTEM_READY:
1606 handleSystemReady();
1607 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001608 }
1609 }
1610 };
1611
Jorim Jaggi241ae102016-11-02 21:57:33 -07001612 private void tryKeyguardDone() {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001613 if (!mKeyguardDonePending && mHideAnimationRun && !mHideAnimationRunning) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001614 handleKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001615 } else if (!mHideAnimationRun) {
1616 mHideAnimationRun = true;
1617 mHideAnimationRunning = true;
1618 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
1619 }
1620 }
1621
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001622 /**
1623 * @see #keyguardDone
1624 * @see #KEYGUARD_DONE
1625 */
Jorim Jaggi241ae102016-11-02 21:57:33 -07001626 private void handleKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001627 Trace.beginSection("KeyguardViewMediator#handleKeyguardDone");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001628 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001629 mUiOffloadThread.submit(() -> {
1630 if (mLockPatternUtils.isSecure(currentUser)) {
1631 mLockPatternUtils.getDevicePolicyManager().reportKeyguardDismissed(currentUser);
1632 }
1633 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001634 if (DEBUG) Log.d(TAG, "handleKeyguardDone");
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001635 synchronized (this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001636 resetKeyguardDonePendingLocked();
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001637 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001638
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001639 mUpdateMonitor.clearBiometricRecognized();
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -07001640
Jorim Jaggi4474f542015-07-09 16:08:02 -07001641 if (mGoingToSleep) {
1642 Log.i(TAG, "Device is going to sleep, aborting keyguardDone");
1643 return;
1644 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001645 if (mExitSecureCallback != null) {
1646 try {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001647 mExitSecureCallback.onKeyguardExitResult(true /* authenciated */);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001648 } catch (RemoteException e) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001649 Slog.w(TAG, "Failed to call onKeyguardExitResult()", e);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001650 }
1651
1652 mExitSecureCallback = null;
1653
Jorim Jaggi241ae102016-11-02 21:57:33 -07001654 // after succesfully exiting securely, no need to reshow
1655 // the keyguard when they've released the lock
1656 mExternallyEnabled = true;
1657 mNeedToReshowWhenReenabled = false;
1658 updateInputRestricted();
Jim Millere51cf7ae2013-06-25 18:31:56 -07001659 }
1660
1661 handleHide();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001662 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -07001663 }
1664
1665 private void sendUserPresentBroadcast() {
Jason Monkcf5a9532014-09-17 16:22:19 -04001666 synchronized (this) {
1667 if (mBootCompleted) {
Adrian Roos4ab7e592016-04-13 15:38:13 -07001668 int currentUserId = KeyguardUpdateMonitor.getCurrentUser();
1669 final UserHandle currentUser = new UserHandle(currentUserId);
Benjamin Franz4b9f8ed2014-12-01 16:51:48 +00001670 final UserManager um = (UserManager) mContext.getSystemService(
1671 Context.USER_SERVICE);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001672 mUiOffloadThread.submit(() -> {
1673 for (int profileId : um.getProfileIdsWithDisabled(currentUser.getIdentifier())) {
1674 mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, UserHandle.of(profileId));
1675 }
1676 getLockPatternUtils().userPresent(currentUserId);
1677 });
Jason Monkcf5a9532014-09-17 16:22:19 -04001678 } else {
1679 mBootSendUserPresent = true;
1680 }
1681 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001682 }
1683
1684 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001685 * @see #keyguardDone
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001686 * @see #KEYGUARD_DONE_DRAWING
1687 */
1688 private void handleKeyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001689 Trace.beginSection("KeyguardViewMediator#handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001690 synchronized(this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001691 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001692 if (mWaitingUntilKeyguardVisible) {
1693 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible");
1694 mWaitingUntilKeyguardVisible = false;
1695 notifyAll();
1696
1697 // there will usually be two of these sent, one as a timeout, and one
1698 // as a result of the callback, so remove any remaining messages from
1699 // the queue
1700 mHandler.removeMessages(KEYGUARD_DONE_DRAWING);
1701 }
1702 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001703 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001704 }
1705
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001706 private void playSounds(boolean locked) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001707 playSound(locked ? mLockSoundId : mUnlockSoundId);
1708 }
1709
1710 private void playSound(int soundId) {
1711 if (soundId == 0) return;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001712 final ContentResolver cr = mContext.getContentResolver();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001713 if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001714
Marco Nelissend5545bd2011-09-29 12:49:17 -07001715 mLockSounds.stop(mLockSoundStreamId);
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001716 // Init mAudioManager
1717 if (mAudioManager == null) {
1718 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
1719 if (mAudioManager == null) return;
John Spurlockee5ad722015-03-03 16:17:21 -05001720 mUiSoundsStreamType = mAudioManager.getUiSoundsStreamType();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001721 }
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001722
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001723 mUiOffloadThread.submit(() -> {
1724 // If the stream is muted, don't play the sound
1725 if (mAudioManager.isStreamMute(mUiSoundsStreamType)) return;
1726
1727 int id = mLockSounds.play(soundId,
1728 mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/);
1729 synchronized (this) {
1730 mLockSoundStreamId = id;
1731 }
1732 });
1733
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001734 }
Jim Miller2a98a4c2010-11-19 18:49:26 -08001735 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001736
Adrian Roos49e057d2014-08-13 17:14:51 +02001737 private void playTrustedSound() {
Adrian Roos49e057d2014-08-13 17:14:51 +02001738 playSound(mTrustedSoundId);
1739 }
1740
wilsonshih177261f2019-02-22 12:02:18 +08001741 private void updateActivityLockScreenState(boolean showing, boolean aodShowing) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001742 mUiOffloadThread.submit(() -> {
1743 try {
wilsonshih177261f2019-02-22 12:02:18 +08001744 ActivityTaskManager.getService().setLockScreenShown(showing, aodShowing);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001745 } catch (RemoteException e) {
1746 }
1747 });
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001748 }
1749
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001750 /**
1751 * Handle message sent by {@link #showLocked}.
1752 * @see #SHOW
1753 */
Adam Cohenf7522022012-10-03 20:03:18 -07001754 private void handleShow(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001755 Trace.beginSection("KeyguardViewMediator#handleShow");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001756 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
1757 if (mLockPatternUtils.isSecure(currentUser)) {
1758 mLockPatternUtils.getDevicePolicyManager().reportKeyguardSecured(currentUser);
Michal Karpinski779aad92016-01-20 11:56:22 +00001759 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001760 synchronized (KeyguardViewMediator.this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001761 if (!mSystemReady) {
1762 if (DEBUG) Log.d(TAG, "ignoring handleShow because system is not ready.");
1763 return;
1764 } else {
1765 if (DEBUG) Log.d(TAG, "handleShow");
1766 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001767
Lucas Dupin47a65c72018-02-15 14:16:18 -08001768 setShowingLocked(true, mAodShowing);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001769 mStatusBarKeyguardViewManager.show(options);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001770 mHiding = false;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001771 mWakeAndUnlocking = false;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001772 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001773 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001774 adjustStatusBarLocked();
Jeff Brown3dc524b2012-09-30 19:49:11 -07001775 userActivity();
Kevin Chyn8c7968a2019-03-01 11:25:23 -08001776 mUpdateMonitor.setKeyguardGoingAway(false /* away */);
Mike Lockwood674d3e42009-10-06 09:28:54 -04001777 mShowKeyguardWakeLock.release();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001778 }
Jim Miller31921482013-11-06 20:43:55 -08001779 mKeyguardDisplayManager.show();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001780 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001781 }
1782
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001783 private final Runnable mKeyguardGoingAwayRunnable = new Runnable() {
1784 @Override
1785 public void run() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001786 Trace.beginSection("KeyguardViewMediator.mKeyGuardGoingAwayRunnable");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001787 if (DEBUG) Log.d(TAG, "keyguardGoingAway");
wilsonshih2bc846c2019-05-02 14:35:21 +08001788 mStatusBarKeyguardViewManager.keyguardGoingAway();
Jorim Jaggi33ae80e2015-02-04 16:37:11 +01001789
wilsonshih2bc846c2019-05-02 14:35:21 +08001790 int flags = 0;
1791 if (mStatusBarKeyguardViewManager.shouldDisableWindowAnimationsForUnlock()
1792 || (mWakeAndUnlocking && !mPulsing)) {
1793 flags |= WindowManagerPolicyConstants
1794 .KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001795 }
wilsonshih2bc846c2019-05-02 14:35:21 +08001796 if (mStatusBarKeyguardViewManager.isGoingToNotificationShade()
1797 || (mWakeAndUnlocking && mPulsing)) {
1798 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE;
1799 }
1800 if (mStatusBarKeyguardViewManager.isUnlockWithWallpaper()) {
1801 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER;
1802 }
1803
1804 mUpdateMonitor.setKeyguardGoingAway(true /* goingAway */);
1805
1806 // Don't actually hide the Keyguard at the moment, wait for window
1807 // manager until it tells us it's safe to do so with
1808 // startKeyguardExitAnimation.
1809 // Posting to mUiOffloadThread to ensure that calls to ActivityTaskManager will be in
1810 // order.
1811 final int keyguardFlag = flags;
1812 mUiOffloadThread.submit(() -> {
1813 try {
1814 ActivityTaskManager.getService().keyguardGoingAway(keyguardFlag);
1815 } catch (RemoteException e) {
1816 Log.e(TAG, "Error while calling WindowManager", e);
1817 }
1818 });
Nick Desaulniers1d396752016-07-25 15:05:33 -07001819 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001820 }
1821 };
1822
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001823 private final Runnable mHideAnimationFinishedRunnable = () -> {
1824 mHideAnimationRunning = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -07001825 tryKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001826 };
1827
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001828 /**
1829 * Handle message sent by {@link #hideLocked()}
1830 * @see #HIDE
1831 */
1832 private void handleHide() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001833 Trace.beginSection("KeyguardViewMediator#handleHide");
Lucas Dupin1c327432019-01-03 13:37:53 -08001834
1835 // It's possible that the device was unlocked in a dream state. It's time to wake up.
1836 if (mAodShowing) {
Michael Wrighte3001042019-02-05 00:13:14 +00001837 PowerManager pm = mContext.getSystemService(PowerManager.class);
1838 pm.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE,
1839 "com.android.systemui:BOUNCER_DOZING");
Lucas Dupin1c327432019-01-03 13:37:53 -08001840 }
1841
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001842 synchronized (KeyguardViewMediator.this) {
1843 if (DEBUG) Log.d(TAG, "handleHide");
Jorim Jaggib9d60792014-06-03 22:34:22 +02001844
Amith Yamasanieb437d42016-04-29 09:31:25 -07001845 if (mustNotUnlockCurrentUser()) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001846 // In split system user mode, we never unlock system user. The end user has to
1847 // switch to another user.
1848 // TODO: We should stop it early by disabling the swipe up flow. Right now swipe up
1849 // still completes and makes the screen blank.
1850 if (DEBUG) Log.d(TAG, "Split system user, quit unlocking.");
1851 return;
1852 }
Jorim Jaggi76a16232014-08-08 17:00:47 +02001853 mHiding = true;
Jorim Jaggib9d60792014-06-03 22:34:22 +02001854
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001855 if (mShowing && !mOccluded) {
1856 mKeyguardGoingAwayRunnable.run();
1857 } else {
Jorim Jaggi76a16232014-08-08 17:00:47 +02001858 handleStartKeyguardExitAnimation(
1859 SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(),
1860 mHideAnimation.getDuration());
Jorim Jaggi0d674622014-05-21 01:34:15 +02001861 }
1862 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001863 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001864 }
1865
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001866 private void handleStartKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001867 Trace.beginSection("KeyguardViewMediator#handleStartKeyguardExitAnimation");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001868 if (DEBUG) Log.d(TAG, "handleStartKeyguardExitAnimation startTime=" + startTime
1869 + " fadeoutDuration=" + fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02001870 synchronized (KeyguardViewMediator.this) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001871
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001872 if (!mHiding) {
Adrian Roos6ec76b72018-04-25 14:01:11 +02001873 // Tell ActivityManager that we canceled the keyguardExitAnimation.
wilsonshih177261f2019-02-22 12:02:18 +08001874 setShowingLocked(mShowing, mAodShowing, true /* force */);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001875 return;
1876 }
1877 mHiding = false;
1878
Jorim Jaggib774e552015-08-24 14:52:45 -07001879 if (mWakeAndUnlocking && mDrawnCallback != null) {
1880
1881 // Hack level over 9000: To speed up wake-and-unlock sequence, force it to report
1882 // the next draw from here so we don't have to wait for window manager to signal
1883 // this to our ViewRootImpl.
1884 mStatusBarKeyguardViewManager.getViewRootImpl().setReportNextDraw();
1885 notifyDrawn(mDrawnCallback);
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001886 mDrawnCallback = null;
Jorim Jaggib774e552015-08-24 14:52:45 -07001887 }
1888
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001889 // only play "unlock" noises if not on a call (since the incall UI
1890 // disables the keyguard)
1891 if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) {
1892 playSounds(false);
1893 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001894
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001895 mWakeAndUnlocking = false;
Lucas Dupin47a65c72018-02-15 14:16:18 -08001896 setShowingLocked(false, mAodShowing);
Jorim Jaggi5277dea2017-05-18 02:05:29 +02001897 mDismissCallbackRegistry.notifyDismissSucceeded();
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001898 mStatusBarKeyguardViewManager.hide(startTime, fadeoutDuration);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001899 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001900 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001901 adjustStatusBarLocked();
Jim Miller705004b2014-09-04 16:51:20 -07001902 sendUserPresentBroadcast();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001903 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001904 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001905 }
1906
Mike Lockwood5f892c12009-11-19 23:39:13 -05001907 private void adjustStatusBarLocked() {
Matthew Ng66f0b702017-12-08 12:58:42 -08001908 adjustStatusBarLocked(false /* forceHideHomeRecentsButtons */);
1909 }
1910
1911 private void adjustStatusBarLocked(boolean forceHideHomeRecentsButtons) {
Mike Lockwood5f892c12009-11-19 23:39:13 -05001912 if (mStatusBarManager == null) {
1913 mStatusBarManager = (StatusBarManager)
1914 mContext.getSystemService(Context.STATUS_BAR_SERVICE);
1915 }
Matthew Ng78ba6e22018-09-24 16:55:36 -07001916
Mike Lockwood5f892c12009-11-19 23:39:13 -05001917 if (mStatusBarManager == null) {
1918 Log.w(TAG, "Could not get status bar manager");
1919 } else {
Daniel Sandlerdba93562011-10-06 16:39:58 -04001920 // Disable aspects of the system/status/navigation bars that must not be re-enabled by
1921 // windows that appear on top, ever
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001922 int flags = StatusBarManager.DISABLE_NONE;
Matthew Ng66f0b702017-12-08 12:58:42 -08001923 if (forceHideHomeRecentsButtons || isShowingAndNotOccluded()) {
1924 flags |= StatusBarManager.DISABLE_HOME | StatusBarManager.DISABLE_RECENT;
Jorim Jaggia005f1b2014-04-16 19:06:10 +02001925 }
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001926
1927 if (DEBUG) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001928 Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mOccluded=" + mOccluded
Matthew Ng66f0b702017-12-08 12:58:42 -08001929 + " isSecure=" + isSecure() + " force=" + forceHideHomeRecentsButtons
1930 + " --> flags=0x" + Integer.toHexString(flags));
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001931 }
1932
Jorim Jaggie3e0b062017-06-12 12:18:41 -07001933 mStatusBarManager.disable(flags);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001934 }
1935 }
1936
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001937 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001938 * Handle message sent by {@link #resetStateLocked}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001939 * @see #RESET
1940 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001941 private void handleReset() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001942 synchronized (KeyguardViewMediator.this) {
1943 if (DEBUG) Log.d(TAG, "handleReset");
Jorim Jaggife762342016-10-13 14:33:27 +02001944 mStatusBarKeyguardViewManager.reset(true /* hideBouncerWhenShowing */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001945 }
1946 }
1947
1948 /**
1949 * Handle message sent by {@link #verifyUnlock}
Craig Mautner904732c2012-10-17 15:20:24 -07001950 * @see #VERIFY_UNLOCK
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001951 */
1952 private void handleVerifyUnlock() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001953 Trace.beginSection("KeyguardViewMediator#handleVerifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001954 synchronized (KeyguardViewMediator.this) {
1955 if (DEBUG) Log.d(TAG, "handleVerifyUnlock");
Lucas Dupin47a65c72018-02-15 14:16:18 -08001956 setShowingLocked(true, mAodShowing);
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001957 mStatusBarKeyguardViewManager.dismissAndCollapse();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001958 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001959 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001960 }
1961
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001962 private void handleNotifyStartedGoingToSleep() {
1963 synchronized (KeyguardViewMediator.this) {
1964 if (DEBUG) Log.d(TAG, "handleNotifyStartedGoingToSleep");
1965 mStatusBarKeyguardViewManager.onStartedGoingToSleep();
1966 }
1967 }
1968
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001969 /**
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001970 * Handle message sent by {@link #notifyFinishedGoingToSleep()}
1971 * @see #NOTIFY_FINISHED_GOING_TO_SLEEP
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001972 */
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001973 private void handleNotifyFinishedGoingToSleep() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001974 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001975 if (DEBUG) Log.d(TAG, "handleNotifyFinishedGoingToSleep");
1976 mStatusBarKeyguardViewManager.onFinishedGoingToSleep();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001977 }
1978 }
1979
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001980 private void handleNotifyStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001981 Trace.beginSection("KeyguardViewMediator#handleMotifyStartedWakingUp");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001982 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001983 if (DEBUG) Log.d(TAG, "handleNotifyWakingUp");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001984 mStatusBarKeyguardViewManager.onStartedWakingUp();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001985 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001986 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001987 }
1988
1989 private void handleNotifyScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001990 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurningOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001991 synchronized (KeyguardViewMediator.this) {
1992 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurningOn");
Jorim Jaggi93739112015-08-13 15:53:14 -07001993 mStatusBarKeyguardViewManager.onScreenTurningOn();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001994 if (callback != null) {
1995 if (mWakeAndUnlocking) {
1996 mDrawnCallback = callback;
1997 } else {
1998 notifyDrawn(callback);
1999 }
2000 }
2001 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002002 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002003 }
2004
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002005 private void handleNotifyScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002006 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurnedOn");
Jorim Jaggic3fe2042016-10-07 18:52:48 +02002007 if (LatencyTracker.isEnabled(mContext)) {
2008 LatencyTracker.getInstance(mContext).onActionEnd(LatencyTracker.ACTION_TURN_ON_SCREEN);
2009 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002010 synchronized (this) {
2011 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOn");
2012 mStatusBarKeyguardViewManager.onScreenTurnedOn();
2013 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002014 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002015 }
2016
2017 private void handleNotifyScreenTurnedOff() {
2018 synchronized (this) {
2019 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOff");
Jorim Jaggie93e6f92016-08-04 13:55:39 +02002020 mDrawnCallback = null;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002021 }
2022 }
2023
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002024 private void notifyDrawn(final IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002025 Trace.beginSection("KeyguardViewMediator#notifyDrawn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002026 try {
2027 callback.onDrawn();
2028 } catch (RemoteException e) {
2029 Slog.w(TAG, "Exception calling onDrawn():", e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002030 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002031 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002032 }
Jeff Sharkey054340d2011-09-01 22:28:03 -07002033
Jorim Jaggif8d77da2014-11-11 16:59:12 +01002034 private void resetKeyguardDonePendingLocked() {
2035 mKeyguardDonePending = false;
2036 mHandler.removeMessages(KEYGUARD_DONE_PENDING_TIMEOUT);
2037 }
2038
Jim Miller2967f482016-01-07 15:05:32 -08002039 @Override
Jim Millere5f910a2013-10-16 18:15:46 -07002040 public void onBootCompleted() {
2041 mUpdateMonitor.dispatchBootCompleted();
Jason Monkcf5a9532014-09-17 16:22:19 -04002042 synchronized (this) {
2043 mBootCompleted = true;
2044 if (mBootSendUserPresent) {
2045 sendUserPresentBroadcast();
2046 }
2047 }
Jim Millere5f910a2013-10-16 18:15:46 -07002048 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002049
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002050 public void onWakeAndUnlocking() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002051 Trace.beginSection("KeyguardViewMediator#onWakeAndUnlocking");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002052 mWakeAndUnlocking = true;
Jorim Jaggi241ae102016-11-02 21:57:33 -07002053 keyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07002054 Trace.endSection();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002055 }
2056
Jason Monk2a6ea9c2017-01-26 11:14:51 -05002057 public StatusBarKeyguardViewManager registerStatusBar(StatusBar statusBar,
Lucas Dupinbc9aac12018-03-04 20:18:15 -08002058 ViewGroup container, NotificationPanelView panelView,
Lucas Dupin2e838ac2019-04-17 16:50:58 -07002059 BiometricUnlockController biometricUnlockController, ViewGroup lockIconContainer) {
Lucas Dupinbc9aac12018-03-04 20:18:15 -08002060 mStatusBarKeyguardViewManager.registerStatusBar(statusBar, container, panelView,
Lucas Dupin2e838ac2019-04-17 16:50:58 -07002061 biometricUnlockController, mDismissCallbackRegistry, lockIconContainer);
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002062 return mStatusBarKeyguardViewManager;
2063 }
2064
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002065 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002066 Trace.beginSection("KeyguardViewMediator#startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002067 Message msg = mHandler.obtainMessage(START_KEYGUARD_EXIT_ANIM,
2068 new StartKeyguardExitAnimParams(startTime, fadeoutDuration));
Jorim Jaggi0d674622014-05-21 01:34:15 +02002069 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07002070 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02002071 }
2072
Andrew Zengb4045d32017-03-16 17:25:07 -07002073 public void onShortPowerPressedGoHome() {
2074 // do nothing
2075 }
2076
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002077 public ViewMediatorCallback getViewMediatorCallback() {
2078 return mViewMediatorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002079 }
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002080
Xiyuan Xia1b30f792016-01-06 08:50:30 -08002081 public LockPatternUtils getLockPatternUtils() {
2082 return mLockPatternUtils;
2083 }
2084
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002085 @Override
2086 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
2087 pw.print(" mSystemReady: "); pw.println(mSystemReady);
2088 pw.print(" mBootCompleted: "); pw.println(mBootCompleted);
2089 pw.print(" mBootSendUserPresent: "); pw.println(mBootSendUserPresent);
2090 pw.print(" mExternallyEnabled: "); pw.println(mExternallyEnabled);
Adrian Roos1f8025a2016-12-27 10:12:13 -08002091 pw.print(" mShuttingDown: "); pw.println(mShuttingDown);
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002092 pw.print(" mNeedToReshowWhenReenabled: "); pw.println(mNeedToReshowWhenReenabled);
2093 pw.print(" mShowing: "); pw.println(mShowing);
2094 pw.print(" mInputRestricted: "); pw.println(mInputRestricted);
2095 pw.print(" mOccluded: "); pw.println(mOccluded);
2096 pw.print(" mDelayedShowingSequence: "); pw.println(mDelayedShowingSequence);
2097 pw.print(" mExitSecureCallback: "); pw.println(mExitSecureCallback);
2098 pw.print(" mDeviceInteractive: "); pw.println(mDeviceInteractive);
2099 pw.print(" mGoingToSleep: "); pw.println(mGoingToSleep);
2100 pw.print(" mHiding: "); pw.println(mHiding);
2101 pw.print(" mWaitingUntilKeyguardVisible: "); pw.println(mWaitingUntilKeyguardVisible);
2102 pw.print(" mKeyguardDonePending: "); pw.println(mKeyguardDonePending);
2103 pw.print(" mHideAnimationRun: "); pw.println(mHideAnimationRun);
2104 pw.print(" mPendingReset: "); pw.println(mPendingReset);
2105 pw.print(" mPendingLock: "); pw.println(mPendingLock);
2106 pw.print(" mWakeAndUnlocking: "); pw.println(mWakeAndUnlocking);
2107 pw.print(" mDrawnCallback: "); pw.println(mDrawnCallback);
2108 }
2109
Lucas Dupin5a4f92c2018-07-02 13:15:23 -07002110 /**
2111 * @param aodShowing true when AOD - or ambient mode - is showing.
2112 */
Lucas Dupin47a65c72018-02-15 14:16:18 -08002113 public void setAodShowing(boolean aodShowing) {
2114 setShowingLocked(mShowing, aodShowing);
2115 }
2116
Lucas Dupind35502f2018-06-27 13:35:52 -07002117 /**
2118 * @param pulsing true when device temporarily wakes up to display an incoming notification.
2119 */
2120 public void setPulsing(boolean pulsing) {
2121 mPulsing = pulsing;
2122 }
2123
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002124 private static class StartKeyguardExitAnimParams {
2125
2126 long startTime;
2127 long fadeoutDuration;
2128
2129 private StartKeyguardExitAnimParams(long startTime, long fadeoutDuration) {
2130 this.startTime = startTime;
2131 this.fadeoutDuration = fadeoutDuration;
2132 }
2133 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002134
Lucas Dupin47a65c72018-02-15 14:16:18 -08002135 private void setShowingLocked(boolean showing, boolean aodShowing) {
wilsonshih177261f2019-02-22 12:02:18 +08002136 setShowingLocked(showing, aodShowing, false /* forceCallbacks */);
Jorim Jaggie8f321e2016-11-07 16:48:31 -08002137 }
2138
wilsonshih177261f2019-02-22 12:02:18 +08002139 private void setShowingLocked(boolean showing, boolean aodShowing, boolean forceCallbacks) {
Lucas Dupin47a65c72018-02-15 14:16:18 -08002140 final boolean notifyDefaultDisplayCallbacks = showing != mShowing
2141 || aodShowing != mAodShowing || forceCallbacks;
wilsonshih177261f2019-02-22 12:02:18 +08002142 if (notifyDefaultDisplayCallbacks) {
Jim Millerab954542014-10-10 18:21:49 -07002143 mShowing = showing;
Lucas Dupin47a65c72018-02-15 14:16:18 -08002144 mAodShowing = aodShowing;
David Stevens53a39ea2017-08-23 18:41:49 -07002145 if (notifyDefaultDisplayCallbacks) {
2146 notifyDefaultDisplayCallbacks(showing);
2147 }
wilsonshih177261f2019-02-22 12:02:18 +08002148 updateActivityLockScreenState(showing, aodShowing);
David Stevens53a39ea2017-08-23 18:41:49 -07002149 }
2150 }
2151
2152 private void notifyDefaultDisplayCallbacks(boolean showing) {
2153 int size = mKeyguardStateCallbacks.size();
2154 for (int i = size - 1; i >= 0; i--) {
2155 IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
2156 try {
2157 callback.onShowingStateChanged(showing);
2158 } catch (RemoteException e) {
2159 Slog.w(TAG, "Failed to call onShowingStateChanged", e);
2160 if (e instanceof DeadObjectException) {
2161 mKeyguardStateCallbacks.remove(callback);
Jim Millerab954542014-10-10 18:21:49 -07002162 }
Jim Millerab954542014-10-10 18:21:49 -07002163 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002164 }
David Stevens53a39ea2017-08-23 18:41:49 -07002165 updateInputRestrictedLocked();
2166 mUiOffloadThread.submit(() -> {
2167 mTrustManager.reportKeyguardShowingChanged();
2168 });
Adrian Roos481a6df2014-11-20 19:48:56 +01002169 }
Jim Millerab954542014-10-10 18:21:49 -07002170
Adrian Roosd88eb262016-08-04 14:50:48 -07002171 private void notifyTrustedChangedLocked(boolean trusted) {
2172 int size = mKeyguardStateCallbacks.size();
2173 for (int i = size - 1; i >= 0; i--) {
2174 try {
2175 mKeyguardStateCallbacks.get(i).onTrustedChanged(trusted);
2176 } catch (RemoteException e) {
2177 Slog.w(TAG, "Failed to call notifyTrustedChangedLocked", e);
2178 if (e instanceof DeadObjectException) {
2179 mKeyguardStateCallbacks.remove(i);
2180 }
2181 }
2182 }
2183 }
2184
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002185 private void notifyHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
2186 int size = mKeyguardStateCallbacks.size();
2187 for (int i = size - 1; i >= 0; i--) {
2188 try {
2189 mKeyguardStateCallbacks.get(i).onHasLockscreenWallpaperChanged(
2190 hasLockscreenWallpaper);
2191 } catch (RemoteException e) {
2192 Slog.w(TAG, "Failed to call onHasLockscreenWallpaperChanged", e);
2193 if (e instanceof DeadObjectException) {
2194 mKeyguardStateCallbacks.remove(i);
2195 }
2196 }
2197 }
2198 }
2199
Jim Millerab954542014-10-10 18:21:49 -07002200 public void addStateMonitorCallback(IKeyguardStateCallback callback) {
2201 synchronized (this) {
2202 mKeyguardStateCallbacks.add(callback);
2203 try {
2204 callback.onSimSecureStateChanged(mUpdateMonitor.isSimPinSecure());
2205 callback.onShowingStateChanged(mShowing);
Adrian Roos4a963ac2015-04-24 16:04:53 -07002206 callback.onInputRestrictedStateChanged(mInputRestricted);
Adrian Roosd88eb262016-08-04 14:50:48 -07002207 callback.onTrustedChanged(mUpdateMonitor.getUserHasTrust(
2208 KeyguardUpdateMonitor.getCurrentUser()));
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002209 callback.onHasLockscreenWallpaperChanged(mUpdateMonitor.hasLockscreenWallpaper());
Jim Millerab954542014-10-10 18:21:49 -07002210 } catch (RemoteException e) {
Adrian Roosd88eb262016-08-04 14:50:48 -07002211 Slog.w(TAG, "Failed to call to IKeyguardStateCallback", e);
Jim Millerab954542014-10-10 18:21:49 -07002212 }
2213 }
2214 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08002215
2216 private static class DismissMessage {
2217 private final CharSequence mMessage;
2218 private final IKeyguardDismissCallback mCallback;
2219
2220 DismissMessage(IKeyguardDismissCallback callback, CharSequence message) {
2221 mCallback = callback;
2222 mMessage = message;
2223 }
2224
2225 public IKeyguardDismissCallback getCallback() {
2226 return mCallback;
2227 }
2228
2229 public CharSequence getMessage() {
2230 return mMessage;
2231 }
2232 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002233}