blob: e9f99acd8d468872536897c87ca3d1af6773a139 [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;
Selim Cinek06c12d62019-07-01 19:44:18 -070064import android.view.View;
Jorim Jaggib690f0d2014-07-03 23:25:44 +020065import android.view.ViewGroup;
Adrian Roose99bc052017-11-20 17:55:31 +010066import android.view.WindowManagerPolicyConstants;
Adrian Roos0002a452014-07-03 13:46:07 +020067import android.view.animation.Animation;
68import android.view.animation.AnimationUtils;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -070069
Jorim Jaggi241ae102016-11-02 21:57:33 -070070import com.android.internal.policy.IKeyguardDismissCallback;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -070071import com.android.internal.policy.IKeyguardDrawnCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010072import com.android.internal.policy.IKeyguardExitCallback;
Jim Millerab954542014-10-10 18:21:49 -070073import com.android.internal.policy.IKeyguardStateCallback;
Adam Cohenf7522022012-10-03 20:03:18 -070074import com.android.internal.telephony.IccCardConstants;
Lucas Dupin6d48eab2018-09-17 17:17:14 -070075import com.android.internal.util.LatencyTracker;
Adam Cohenf7522022012-10-03 20:03:18 -070076import com.android.internal.widget.LockPatternUtils;
Jim Miller52a61332014-11-12 19:29:51 -080077import com.android.keyguard.KeyguardConstants;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010078import com.android.keyguard.KeyguardDisplayManager;
Selim Cinek3122fa82015-06-18 01:38:59 -070079import com.android.keyguard.KeyguardSecurityView;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010080import com.android.keyguard.KeyguardUpdateMonitor;
81import com.android.keyguard.KeyguardUpdateMonitorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010082import com.android.keyguard.ViewMediatorCallback;
Jorim Jaggie549a8d2017-05-15 02:40:05 +020083import com.android.systemui.Dependency;
Jorim Jaggicff0acb2014-03-31 16:35:15 +020084import com.android.systemui.SystemUI;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080085import com.android.systemui.SystemUIFactory;
Jorim Jaggie549a8d2017-05-15 02:40:05 +020086import com.android.systemui.UiOffloadThread;
Dave Mankoffdde5ee62019-05-02 17:36:11 -040087import com.android.systemui.classifier.FalsingManagerFactory;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020088import com.android.systemui.statusbar.phone.BiometricUnlockController;
Selim Cinek06c12d62019-07-01 19:44:18 -070089import com.android.systemui.statusbar.phone.KeyguardBypassController;
Lucas Dupin6d48eab2018-09-17 17:17:14 -070090import com.android.systemui.statusbar.phone.NotificationPanelView;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050091import com.android.systemui.statusbar.phone.StatusBar;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010092import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
Lucas Dupine25c4872019-07-29 13:51:35 -070093import com.android.systemui.statusbar.phone.StatusBarWindowController;
Robert Snoebergerbe35b762019-03-15 14:33:02 -040094import com.android.systemui.util.InjectionInflationController;
Adrian Roos58b58fe2014-01-31 16:00:39 -080095
Jorim Jaggi84dc08a2015-09-11 17:45:22 -070096import java.io.FileDescriptor;
97import java.io.PrintWriter;
Jim Millerab954542014-10-10 18:21:49 -070098import java.util.ArrayList;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010099
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800100/**
101 * Mediates requests related to the keyguard. This includes queries about the
102 * state of the keyguard, power management events that effect whether the keyguard
103 * should be shown or reset, callbacks to the phone window manager to notify
104 * it of when the keyguard is showing, and events from the keyguard view itself
105 * stating that the keyguard was succesfully unlocked.
106 *
107 * Note that the keyguard view is shown when the screen is off (as appropriate)
108 * so that once the screen comes on, it will be ready immediately.
109 *
110 * Example queries about the keyguard:
111 * - is {movement, key} one that should wake the keygaurd?
112 * - is the keyguard showing?
113 * - are input events restricted due to the state of the keyguard?
114 *
115 * Callbacks to the phone window manager:
116 * - the keyguard is showing
117 *
118 * Example external events that translate to keyguard view changes:
119 * - screen turned off -> reset the keyguard, and show it so it will be ready
120 * next time the screen turns on
121 * - keyboard is slid open -> if the keyguard is not secure, hide it
122 *
123 * Events from the keyguard view:
124 * - user succesfully unlocked keyguard -> hide keyguard view, and no longer
125 * restrict input events.
126 *
127 * Note: in addition to normal power managment events that effect the state of
128 * whether the keyguard should be showing, external apps and services may request
129 * that the keyguard be disabled via {@link #setKeyguardEnabled(boolean)}. When
130 * false, this will override all other conditions for turning on the keyguard.
131 *
132 * Threading and synchronization:
Adrian Roose99bc052017-11-20 17:55:31 +0100133 * This class is created by the initialization routine of the {@link WindowManagerPolicyConstants},
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800134 * and runs on its thread. The keyguard UI is created from that thread in the
135 * constructor of this class. The apis may be called from other threads, including the
Jeff Brown4532e612012-04-05 14:27:12 -0700136 * {@link com.android.server.input.InputManagerService}'s and {@link android.view.WindowManager}'s.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800137 * Therefore, methods on this class are synchronized, and any action that is pointed
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100138 * 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 -0800139 * thread of the keyguard.
140 */
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200141public class KeyguardViewMediator extends SystemUI {
Jim Millerbc4603b2010-08-30 21:21:34 -0700142 private static final int KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT = 30000;
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100143 private static final long KEYGUARD_DONE_PENDING_TIMEOUT_MS = 3000;
144
Jim Miller52a61332014-11-12 19:29:51 -0800145 private static final boolean DEBUG = KeyguardConstants.DEBUG;
146 private static final boolean DEBUG_SIM_STATES = KeyguardConstants.DEBUG_SIM_STATES;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800147
148 private final static String TAG = "KeyguardViewMediator";
149
Jim Miller9c20d0e2010-01-20 15:00:23 -0800150 private static final String DELAYED_KEYGUARD_ACTION =
Wink Saville37c124c2009-04-02 01:37:02 -0700151 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD";
Clara Bayarri56878a92015-10-29 15:43:55 +0000152 private static final String DELAYED_LOCK_PROFILE_ACTION =
153 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_LOCK";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800154
Kevin Chyn18e91aa2018-04-11 12:55:45 -0700155 private static final String SYSTEMUI_PERMISSION = "com.android.systemui.permission.SELF";
156
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800157 // used for handler messages
Jorim Jaggi8d786932016-10-26 19:08:36 -0700158 private static final int SHOW = 1;
159 private static final int HIDE = 2;
160 private static final int RESET = 3;
161 private static final int VERIFY_UNLOCK = 4;
162 private static final int NOTIFY_FINISHED_GOING_TO_SLEEP = 5;
163 private static final int NOTIFY_SCREEN_TURNING_ON = 6;
164 private static final int KEYGUARD_DONE = 7;
165 private static final int KEYGUARD_DONE_DRAWING = 8;
166 private static final int SET_OCCLUDED = 9;
167 private static final int KEYGUARD_TIMEOUT = 10;
168 private static final int DISMISS = 11;
169 private static final int START_KEYGUARD_EXIT_ANIM = 12;
170 private static final int KEYGUARD_DONE_PENDING_TIMEOUT = 13;
171 private static final int NOTIFY_STARTED_WAKING_UP = 14;
172 private static final int NOTIFY_SCREEN_TURNED_ON = 15;
173 private static final int NOTIFY_SCREEN_TURNED_OFF = 16;
174 private static final int NOTIFY_STARTED_GOING_TO_SLEEP = 17;
Adrian Roos30a2ae62018-04-25 19:09:50 +0200175 private static final int SYSTEM_READY = 18;
Jim Miller9c20d0e2010-01-20 15:00:23 -0800176
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800177 /**
178 * The default amount of time we stay awake (used for all key input)
179 */
Lucas Dupine90fead2019-06-12 16:22:41 -0700180 public static final int AWAKE_INTERVAL_BOUNCER_MS = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800181
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800182 /**
183 * How long to wait after the screen turns off due to timeout before
184 * turning on the keyguard (i.e, the user has this much time to turn
185 * the screen back on without having to face the keyguard).
186 */
Jim Millerbc4603b2010-08-30 21:21:34 -0700187 private static final int KEYGUARD_LOCK_AFTER_DELAY_DEFAULT = 5000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800188
189 /**
Craig Mautnerf1b67412012-09-19 13:18:29 -0700190 * How long we'll wait for the {@link ViewMediatorCallback#keyguardDoneDrawing()}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800191 * callback before unblocking a call to {@link #setKeyguardEnabled(boolean)}
192 * that is reenabling the keyguard.
193 */
194 private static final int KEYGUARD_DONE_DRAWING_TIMEOUT_MS = 2000;
Jim Miller9c20d0e2010-01-20 15:00:23 -0800195
Daniel Sandler74d188c2011-08-10 00:00:31 -0400196 /**
Evan Rosky13a58a92016-07-27 15:51:09 -0700197 * Boolean option for doKeyguardLocked/doKeyguardTimeout which, when set to true, forces the
198 * keyguard to show even if it is disabled for the current user.
199 */
200 public static final String OPTION_FORCE_SHOW = "force_show";
201
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700202 /** The stream type that the lock sounds are tied to. */
John Spurlockee5ad722015-03-03 16:17:21 -0500203 private int mUiSoundsStreamType;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700204
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800205 private AlarmManager mAlarmManager;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700206 private AudioManager mAudioManager;
Mike Lockwood5f892c12009-11-19 23:39:13 -0500207 private StatusBarManager mStatusBarManager;
Lucas Dupine25c4872019-07-29 13:51:35 -0700208 private final StatusBarWindowController mStatusBarWindowController =
209 Dependency.get(StatusBarWindowController.class);
Jorim Jaggie549a8d2017-05-15 02:40:05 +0200210 private final UiOffloadThread mUiOffloadThread = Dependency.get(UiOffloadThread.class);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800211
212 private boolean mSystemReady;
Jason Monkcf5a9532014-09-17 16:22:19 -0400213 private boolean mBootCompleted;
214 private boolean mBootSendUserPresent;
Adrian Roos1f8025a2016-12-27 10:12:13 -0800215 private boolean mShuttingDown;
Lucas Dupinb3455e62019-07-11 11:47:13 +0900216 private boolean mDozing;
Daniel Sandler0060a9b2010-03-15 23:09:57 -0400217
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800218 /** High level access to the power manager for WakeLocks */
219 private PowerManager mPM;
220
Adrian Roos481a6df2014-11-20 19:48:56 +0100221 /** TrustManager for letting it know when we change visibility */
222 private TrustManager mTrustManager;
Amith Yamasanib70ff9a2012-09-07 18:28:11 -0700223
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800224 /**
Mike Lockwood674d3e42009-10-06 09:28:54 -0400225 * Used to keep the device awake while to ensure the keyguard finishes opening before
226 * we sleep.
227 */
228 private PowerManager.WakeLock mShowKeyguardWakeLock;
229
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100230 private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800231
232 // these are protected by synchronized (this)
233
234 /**
Mike Lockwood5d258b62009-12-02 13:50:45 -0500235 * External apps (like the phone app) can tell us to disable the keygaurd.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800236 */
237 private boolean mExternallyEnabled = true;
238
239 /**
240 * Remember if an external call to {@link #setKeyguardEnabled} with value
241 * false caused us to hide the keyguard, so that we need to reshow it once
242 * the keygaurd is reenabled with another call with value true.
243 */
244 private boolean mNeedToReshowWhenReenabled = false;
245
246 // cached value of whether we are showing (need to know this to quickly
247 // answer whether the input should be restricted)
Jim Millere5f17ab2013-11-13 15:40:48 -0800248 private boolean mShowing;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800249
Lucas Dupin47a65c72018-02-15 14:16:18 -0800250 // AOD is enabled and status bar is in AOD state.
251 private boolean mAodShowing;
252
Jim Millerab954542014-10-10 18:21:49 -0700253 /** Cached value of #isInputRestricted */
254 private boolean mInputRestricted;
255
Mike Lockwood09a40402009-11-08 00:33:23 -0500256 // true if the keyguard is hidden by another window
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100257 private boolean mOccluded = false;
Mike Lockwood09a40402009-11-08 00:33:23 -0500258
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800259 /**
260 * Helps remember whether the screen has turned on since the last time
261 * it turned off due to timeout. see {@link #onScreenTurnedOff(int)}
262 */
263 private int mDelayedShowingSequence;
264
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800265 /**
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000266 * Simiar to {@link #mDelayedProfileShowingSequence}, but it is for profile case.
267 */
268 private int mDelayedProfileShowingSequence;
269
270 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800271 * If the user has disabled the keyguard, then requests to exit, this is
272 * how we'll ultimately let them know whether it was successful. We use this
273 * var being non-null as an indicator that there is an in progress request.
274 */
Jim Miller25190572013-02-28 17:36:24 -0800275 private IKeyguardExitCallback mExitSecureCallback;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700276 private final DismissCallbackRegistry mDismissCallbackRegistry = new DismissCallbackRegistry();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800277
278 // the properties of the keyguard
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800279
280 private KeyguardUpdateMonitor mUpdateMonitor;
281
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700282 /**
283 * Last SIM state reported by the telephony system.
284 * Index is the slotId - in case of multiple SIM cards.
285 */
286 private final SparseArray<IccCardConstants.State> mLastSimStates = new SparseArray<>();
287
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700288 private boolean mDeviceInteractive;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700289 private boolean mGoingToSleep;
Karl Rosaenab100082009-03-24 22:35:17 -0700290
Daniel Sandlerf2d8e742010-02-22 13:09:48 -0500291 // last known state of the cellular connection
292 private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE;
293
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800294 /**
Jorim Jaggi53c68a42014-06-17 15:04:47 -0700295 * Whether a hide is pending an we are just waiting for #startKeyguardExitAnimation to be
296 * called.
297 * */
298 private boolean mHiding;
299
300 /**
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700301 * we send this intent when the keyguard is dismissed.
302 */
Jim Miller17f509a2013-02-28 18:36:12 -0800303 private static final Intent USER_PRESENT_INTENT = new Intent(Intent.ACTION_USER_PRESENT)
304 .addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
Chad Brubaker291df4f2017-03-14 10:23:02 -0700305 | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
306 | Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700307
308 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800309 * {@link #setKeyguardEnabled} waits on this condition when it reenables
310 * the keyguard.
311 */
312 private boolean mWaitingUntilKeyguardVisible = false;
Jim Millerbc4603b2010-08-30 21:21:34 -0700313 private LockPatternUtils mLockPatternUtils;
John Spurlock34c4fe52012-11-07 10:12:29 -0500314 private boolean mKeyguardDonePending = false;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200315 private boolean mHideAnimationRun = false;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700316 private boolean mHideAnimationRunning = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800317
Marco Nelissend5545bd2011-09-29 12:49:17 -0700318 private SoundPool mLockSounds;
319 private int mLockSoundId;
320 private int mUnlockSoundId;
Adrian Roos49e057d2014-08-13 17:14:51 +0200321 private int mTrustedSoundId;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700322 private int mLockSoundStreamId;
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700323
324 /**
Adrian Roos0002a452014-07-03 13:46:07 +0200325 * The animation used for hiding keyguard. This is used to fetch the animation timings if
326 * WindowManager is not providing us with them.
327 */
328 private Animation mHideAnimation;
329
330 /**
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700331 * The volume applied to the lock/unlock sounds.
332 */
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200333 private float mLockSoundVolume;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700334
Jim Millerdcb3d842012-08-23 19:18:12 -0700335 /**
Jim Miller31921482013-11-06 20:43:55 -0800336 * For managing external displays
337 */
338 private KeyguardDisplayManager mKeyguardDisplayManager;
339
Jim Millerab954542014-10-10 18:21:49 -0700340 private final ArrayList<IKeyguardStateCallback> mKeyguardStateCallbacks = new ArrayList<>();
341
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700342 /**
343 * When starting going to sleep, we figured out that we need to reset Keyguard state and this
344 * should be committed when finished going to sleep.
345 */
346 private boolean mPendingReset;
347
348 /**
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700349 * 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 -0700350 * committed when finished going to sleep.
351 */
352 private boolean mPendingLock;
353
Robin Leec41f6ec2017-01-10 17:02:34 +0000354 /**
355 * Controller for showing individual "work challenge" lock screen windows inside managed profile
356 * tasks when the current user has been unlocked but the profile is still locked.
357 */
358 private WorkLockActivityController mWorkLockController;
359
Lucas Dupind35502f2018-06-27 13:35:52 -0700360 /**
361 * @see #setPulsing(boolean)
362 */
363 private boolean mPulsing;
364
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000365 private boolean mLockLater;
366
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700367 private boolean mWakeAndUnlocking;
368 private IKeyguardDrawnCallback mDrawnCallback;
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800369 private CharSequence mCustomMessage;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700370
Jim Millerbbf1a742012-07-17 18:30:30 -0700371 KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {
372
373 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500374 public void onUserSwitching(int userId) {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700375 // Note that the mLockPatternUtils user has already been updated from setCurrentUser.
Adam Cohenf7522022012-10-03 20:03:18 -0700376 // We need to force a reset of the views, since lockNow (called by
377 // ActivityManagerService) will not reconstruct the keyguard if it is already showing.
Jim Millerbbf1a742012-07-17 18:30:30 -0700378 synchronized (KeyguardViewMediator.this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100379 resetKeyguardDonePendingLocked();
Alex Chau77ef9fc2018-04-11 15:41:32 +0100380 if (mLockPatternUtils.isLockScreenDisabled(userId)) {
381 // If we switching to a user that has keyguard disabled, dismiss keyguard.
382 dismiss(null /* callback */, null /* message */);
383 } else {
384 resetStateLocked();
385 }
John Spurlock4e6922d2012-10-04 14:51:51 -0400386 adjustStatusBarLocked();
Dianne Hackborn5dc5a002012-09-15 19:33:48 -0700387 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700388 }
389
390 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500391 public void onUserSwitchComplete(int userId) {
Xiaohui Chen87d0e252015-07-30 15:38:16 -0700392 if (userId != UserHandle.USER_SYSTEM) {
Adrian Roosbe47b072014-09-03 00:08:56 +0200393 UserInfo info = UserManager.get(mContext).getUserInfo(userId);
Kevin Chynf2c0a642017-05-25 11:29:08 -0700394 // Don't try to dismiss if the user has Pin/Patter/Password set
395 if (info == null || mLockPatternUtils.isSecure(userId)) {
396 return;
397 } else if (info.isGuest() || info.isDemo()) {
Adrian Roosbe47b072014-09-03 00:08:56 +0200398 // If we just switched to a guest, try to dismiss keyguard.
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800399 dismiss(null /* callback */, null /* message */);
Adrian Roosbe47b072014-09-03 00:08:56 +0200400 }
401 }
Chris Wrenf41c61b2012-11-29 15:19:54 -0500402 }
403
404 @Override
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -0700405 public void onUserInfoChanged(int userId) {
Jim Millerbbf1a742012-07-17 18:30:30 -0700406 }
407
408 @Override
Jim Millerb0304762012-03-13 20:01:25 -0700409 public void onClockVisibilityChanged() {
410 adjustStatusBarLocked();
411 }
412
413 @Override
414 public void onDeviceProvisioned() {
Jim Miller3fd47af2012-09-21 19:55:27 -0700415 sendUserPresentBroadcast();
Amith Yamasanicb15d662015-11-10 11:11:15 -0800416 synchronized (KeyguardViewMediator.this) {
417 // If system user is provisioned, we might want to lock now to avoid showing launcher
Amith Yamasanieb437d42016-04-29 09:31:25 -0700418 if (mustNotUnlockCurrentUser()) {
Amith Yamasanicb15d662015-11-10 11:11:15 -0800419 doKeyguardLocked(null);
420 }
421 }
Jim Millerb0304762012-03-13 20:01:25 -0700422 }
423
Jim Millerbbf1a742012-07-17 18:30:30 -0700424 @Override
Jim Miller52a61332014-11-12 19:29:51 -0800425 public void onSimStateChanged(int subId, int slotId, IccCardConstants.State simState) {
426
427 if (DEBUG_SIM_STATES) {
428 Log.d(TAG, "onSimStateChanged(subId=" + subId + ", slotId=" + slotId
429 + ",state=" + simState + ")");
430 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700431
dooyoung.hwang328472e2015-05-21 16:09:43 +0900432 int size = mKeyguardStateCallbacks.size();
433 boolean simPinSecure = mUpdateMonitor.isSimPinSecure();
434 for (int i = size - 1; i >= 0; i--) {
435 try {
Jim Millerab954542014-10-10 18:21:49 -0700436 mKeyguardStateCallbacks.get(i).onSimSecureStateChanged(simPinSecure);
dooyoung.hwang328472e2015-05-21 16:09:43 +0900437 } catch (RemoteException e) {
438 Slog.w(TAG, "Failed to call onSimSecureStateChanged", e);
439 if (e instanceof DeadObjectException) {
440 mKeyguardStateCallbacks.remove(i);
441 }
Jim Millerab954542014-10-10 18:21:49 -0700442 }
Jim Millerab954542014-10-10 18:21:49 -0700443 }
444
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700445 boolean simWasLocked;
446 synchronized (KeyguardViewMediator.this) {
447 IccCardConstants.State lastState = mLastSimStates.get(slotId);
Brad Ebingere6c6f722018-12-20 21:11:44 -0800448 simWasLocked = (lastState == PIN_REQUIRED || lastState == PUK_REQUIRED);
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700449 mLastSimStates.append(slotId, simState);
450 }
451
Jim Millerbbf1a742012-07-17 18:30:30 -0700452 switch (simState) {
453 case NOT_READY:
454 case ABSENT:
455 // only force lock screen in case of missing sim if user hasn't
456 // gone through setup wizard
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800457 synchronized (KeyguardViewMediator.this) {
Jim Millerb256e4e22014-10-31 17:27:13 -0700458 if (shouldWaitForProvisioning()) {
Jim Millerab954542014-10-10 18:21:49 -0700459 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800460 if (DEBUG_SIM_STATES) Log.d(TAG, "ICC_ABSENT isn't showing,"
Jim Millerbbf1a742012-07-17 18:30:30 -0700461 + " we need to show the keyguard since the "
462 + "device isn't provisioned yet.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800463 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700464 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100465 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700466 }
467 }
Adrian Roose92de952016-12-13 12:07:09 -0800468 if (simState == ABSENT) {
469 // MVNO SIMs can become transiently NOT_READY when switching networks,
470 // so we should only lock when they are ABSENT.
Lucas Dupin2e0d4952018-12-05 20:03:53 -0800471 if (simWasLocked) {
Brad Ebingere6c6f722018-12-20 21:11:44 -0800472 if (DEBUG_SIM_STATES) Log.d(TAG, "SIM moved to ABSENT when the "
473 + "previous state was locked. Reset the state.");
Lucas Dupin2e0d4952018-12-05 20:03:53 -0800474 resetStateLocked();
475 }
Adrian Roose92de952016-12-13 12:07:09 -0800476 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700477 }
478 break;
479 case PIN_REQUIRED:
480 case PUK_REQUIRED:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800481 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700482 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800483 if (DEBUG_SIM_STATES) Log.d(TAG,
484 "INTENT_VALUE_ICC_LOCKED and keygaurd isn't "
Jim Millerbbf1a742012-07-17 18:30:30 -0700485 + "showing; need to show keyguard so user can enter sim pin");
Jim Miller5ecd8112013-01-09 18:50:26 -0800486 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700487 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100488 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700489 }
490 }
491 break;
492 case PERM_DISABLED:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800493 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700494 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800495 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED and "
Jim Millerbbf1a742012-07-17 18:30:30 -0700496 + "keygaurd isn't showing.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800497 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700498 } else {
Jim Miller52a61332014-11-12 19:29:51 -0800499 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED, resetStateLocked to"
Jim Millerbbf1a742012-07-17 18:30:30 -0700500 + "show permanently disabled message in lockscreen.");
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100501 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700502 }
503 }
504 break;
505 case READY:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800506 synchronized (KeyguardViewMediator.this) {
Lucas Dupinab3079d2018-06-07 09:41:18 -0700507 if (DEBUG_SIM_STATES) Log.d(TAG, "READY, reset state? " + mShowing);
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700508 if (mShowing && simWasLocked) {
Brad Ebingere6c6f722018-12-20 21:11:44 -0800509 if (DEBUG_SIM_STATES) Log.d(TAG, "SIM moved to READY when the "
510 + "previous state was locked. Reset the state.");
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700511 resetStateLocked();
512 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700513 }
514 break;
Jim Miller52a61332014-11-12 19:29:51 -0800515 default:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800516 if (DEBUG_SIM_STATES) Log.v(TAG, "Unspecific state: " + simState);
Jim Miller52a61332014-11-12 19:29:51 -0800517 break;
Jim Millerbbf1a742012-07-17 18:30:30 -0700518 }
519 }
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000520
521 @Override
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200522 public void onBiometricAuthFailed(BiometricSourceType biometricSourceType) {
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000523 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
524 if (mLockPatternUtils.isSecure(currentUser)) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200525 mLockPatternUtils.getDevicePolicyManager().reportFailedBiometricAttempt(
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000526 currentUser);
527 }
528 }
529
530 @Override
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200531 public void onBiometricAuthenticated(int userId, BiometricSourceType biometricSourceType) {
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000532 if (mLockPatternUtils.isSecure(userId)) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200533 mLockPatternUtils.getDevicePolicyManager().reportSuccessfulBiometricAttempt(
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000534 userId);
535 }
536 }
Adrian Roosd88eb262016-08-04 14:50:48 -0700537
538 @Override
539 public void onTrustChanged(int userId) {
540 if (userId == KeyguardUpdateMonitor.getCurrentUser()) {
541 synchronized (KeyguardViewMediator.this) {
542 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(userId));
543 }
544 }
545 }
546
Jorim Jaggid11d1a92016-08-16 16:02:32 -0700547 @Override
548 public void onHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
549 synchronized (KeyguardViewMediator.this) {
550 notifyHasLockscreenWallpaperChanged(hasLockscreenWallpaper);
551 }
552 }
Jim Millerb0304762012-03-13 20:01:25 -0700553 };
554
Jim Millerdcb3d842012-08-23 19:18:12 -0700555 ViewMediatorCallback mViewMediatorCallback = new ViewMediatorCallback() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100556
Jim Miller2967f482016-01-07 15:05:32 -0800557 @Override
Jeff Brownc7505bc2012-10-05 21:58:15 -0700558 public void userActivity() {
559 KeyguardViewMediator.this.userActivity();
560 }
561
Jim Miller2967f482016-01-07 15:05:32 -0800562 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700563 public void keyguardDone(boolean strongAuth, int targetUserId) {
564 if (targetUserId != ActivityManager.getCurrentUser()) {
565 return;
566 }
567
Jorim Jaggi241ae102016-11-02 21:57:33 -0700568 tryKeyguardDone();
Jim Millerdcb3d842012-08-23 19:18:12 -0700569 }
570
Jim Miller2967f482016-01-07 15:05:32 -0800571 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700572 public void keyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700573 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDoneDrawing");
Jim Millerdcb3d842012-08-23 19:18:12 -0700574 mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700575 Trace.endSection();
Jim Millerdcb3d842012-08-23 19:18:12 -0700576 }
577
578 @Override
579 public void setNeedsInput(boolean needsInput) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100580 mStatusBarKeyguardViewManager.setNeedsInput(needsInput);
Jim Millerdcb3d842012-08-23 19:18:12 -0700581 }
Jeff Brownc7505bc2012-10-05 21:58:15 -0700582
583 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700584 public void keyguardDonePending(boolean strongAuth, int targetUserId) {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700585 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDonePending");
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700586 if (targetUserId != ActivityManager.getCurrentUser()) {
Nick Desaulniersaeb2e1e2016-07-27 15:36:01 -0700587 Trace.endSection();
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700588 return;
589 }
590
John Spurlock34c4fe52012-11-07 10:12:29 -0500591 mKeyguardDonePending = true;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200592 mHideAnimationRun = true;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700593 mHideAnimationRunning = true;
594 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100595 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_PENDING_TIMEOUT,
596 KEYGUARD_DONE_PENDING_TIMEOUT_MS);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700597 Trace.endSection();
John Spurlock34c4fe52012-11-07 10:12:29 -0500598 }
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800599
600 @Override
601 public void keyguardGone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700602 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardGone");
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800603 mKeyguardDisplayManager.hide();
Nick Desaulniers1d396752016-07-25 15:05:33 -0700604 Trace.endSection();
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800605 }
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200606
607 @Override
608 public void readyForKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700609 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#readyForKeyguardDone");
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200610 if (mKeyguardDonePending) {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700611 mKeyguardDonePending = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700612 tryKeyguardDone();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200613 }
Nick Desaulniers1d396752016-07-25 15:05:33 -0700614 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200615 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200616
617 @Override
Andrew Lee72b46d42015-01-30 13:23:21 -0800618 public void resetKeyguard() {
619 resetStateLocked();
620 }
621
622 @Override
Aarthi Balachander0a427ef2018-07-13 15:00:58 -0700623 public void onCancelClicked() {
624 mStatusBarKeyguardViewManager.onCancelClicked();
625 }
626
627 @Override
Matthew Ng66f0b702017-12-08 12:58:42 -0800628 public void onBouncerVisiblityChanged(boolean shown) {
629 synchronized (KeyguardViewMediator.this) {
630 adjustStatusBarLocked(shown);
631 }
632 }
633
634 @Override
Adrian Roos49e057d2014-08-13 17:14:51 +0200635 public void playTrustedSound() {
636 KeyguardViewMediator.this.playTrustedSound();
637 }
Jim Millerab954542014-10-10 18:21:49 -0700638
639 @Override
Adrian Roos94e15a52015-04-16 12:23:18 -0700640 public boolean isScreenOn() {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700641 return mDeviceInteractive;
Adrian Roos94e15a52015-04-16 12:23:18 -0700642 }
Selim Cinek3122fa82015-06-18 01:38:59 -0700643
644 @Override
645 public int getBouncerPromptReason() {
646 int currentUser = ActivityManager.getCurrentUser();
Adrian Roosc13723f2016-01-12 20:29:03 +0100647 boolean trust = mTrustManager.isTrustUsuallyManaged(currentUser);
Lucas Dupin8d48fc42019-04-25 14:34:12 -0700648 boolean biometrics = mUpdateMonitor.isUnlockingWithBiometricsPossible(currentUser);
649 boolean any = trust || biometrics;
Adrian Roosc13723f2016-01-12 20:29:03 +0100650 KeyguardUpdateMonitor.StrongAuthTracker strongAuthTracker =
651 mUpdateMonitor.getStrongAuthTracker();
652 int strongAuth = strongAuthTracker.getStrongAuthForUser(currentUser);
653
654 if (any && !strongAuthTracker.hasUserAuthenticatedSinceBoot()) {
Selim Cinek3122fa82015-06-18 01:38:59 -0700655 return KeyguardSecurityView.PROMPT_REASON_RESTART;
Michal Karpinskic52f8672016-11-18 11:32:45 +0000656 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_TIMEOUT) != 0) {
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700657 return KeyguardSecurityView.PROMPT_REASON_TIMEOUT;
Adrian Roosc13723f2016-01-12 20:29:03 +0100658 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW) != 0) {
659 return KeyguardSecurityView.PROMPT_REASON_DEVICE_ADMIN;
660 } else if (trust && (strongAuth & SOME_AUTH_REQUIRED_AFTER_USER_REQUEST) != 0) {
661 return KeyguardSecurityView.PROMPT_REASON_USER_REQUEST;
662 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_LOCKOUT) != 0) {
663 return KeyguardSecurityView.PROMPT_REASON_AFTER_LOCKOUT;
Selim Cinek3122fa82015-06-18 01:38:59 -0700664 }
665 return KeyguardSecurityView.PROMPT_REASON_NONE;
666 }
David Stevens53a39ea2017-08-23 18:41:49 -0700667
668 @Override
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800669 public CharSequence consumeCustomMessage() {
670 final CharSequence message = mCustomMessage;
671 mCustomMessage = null;
672 return message;
673 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700674 };
675
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200676 public void userActivity() {
Jeff Brown3dc524b2012-09-30 19:49:11 -0700677 mPM.userActivity(SystemClock.uptimeMillis(), false);
Jim Millerdcb3d842012-08-23 19:18:12 -0700678 }
679
Amith Yamasanieb437d42016-04-29 09:31:25 -0700680 boolean mustNotUnlockCurrentUser() {
Christine Franks338c6ed2017-08-08 09:39:16 -0700681 return UserManager.isSplitSystemUser()
Amith Yamasanieb437d42016-04-29 09:31:25 -0700682 && KeyguardUpdateMonitor.getCurrentUser() == UserHandle.USER_SYSTEM;
683 }
684
Jim Millerab954542014-10-10 18:21:49 -0700685 private void setupLocked() {
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200686 mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
Adrian Roos481a6df2014-11-20 19:48:56 +0100687 mTrustManager = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE);
688
Mike Lockwood674d3e42009-10-06 09:28:54 -0400689 mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
690 mShowKeyguardWakeLock.setReferenceCounted(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800691
Adrian Roos1f8025a2016-12-27 10:12:13 -0800692 IntentFilter filter = new IntentFilter();
Adrian Roos1f8025a2016-12-27 10:12:13 -0800693 filter.addAction(Intent.ACTION_SHUTDOWN);
694 mContext.registerReceiver(mBroadcastReceiver, filter);
Jim Millerbbf1a742012-07-17 18:30:30 -0700695
Kevin Chyn18e91aa2018-04-11 12:55:45 -0700696 final IntentFilter delayedActionFilter = new IntentFilter();
697 delayedActionFilter.addAction(DELAYED_KEYGUARD_ACTION);
698 delayedActionFilter.addAction(DELAYED_LOCK_PROFILE_ACTION);
699 mContext.registerReceiver(mDelayedLockBroadcastReceiver, delayedActionFilter,
700 SYSTEMUI_PERMISSION, null /* scheduler */);
701
Robert Snoebergerbe35b762019-03-15 14:33:02 -0400702 InjectionInflationController injectionInflationController =
703 new InjectionInflationController(SystemUIFactory.getInstance().getRootComponent());
704 mKeyguardDisplayManager = new KeyguardDisplayManager(mContext,
705 injectionInflationController);
Jim Miller31921482013-11-06 20:43:55 -0800706
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200707 mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800708
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200709 mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800710
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200711 mLockPatternUtils = new LockPatternUtils(mContext);
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700712 KeyguardUpdateMonitor.setCurrentUser(ActivityManager.getCurrentUser());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800713
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200714 // Assume keyguard is showing (unless it's disabled) until we know for sure, unless Keyguard
715 // is disabled.
716 if (mContext.getResources().getBoolean(
717 com.android.keyguard.R.bool.config_enableKeyguardService)) {
718 setShowingLocked(!shouldWaitForProvisioning()
719 && !mLockPatternUtils.isLockScreenDisabled(
Lucas Dupinb3455e62019-07-11 11:47:13 +0900720 KeyguardUpdateMonitor.getCurrentUser()), true /* forceCallbacks */);
Leif Hendrik Wildenc6dc1c92018-02-01 10:54:15 -0800721 } else {
722 // The system's keyguard is disabled or missing.
Lucas Dupinb3455e62019-07-11 11:47:13 +0900723 setShowingLocked(false /* showing */, true /* forceCallbacks */);
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200724 }
Jim Millere5f17ab2013-11-13 15:40:48 -0800725
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800726 mStatusBarKeyguardViewManager =
727 SystemUIFactory.getInstance().createStatusBarKeyguardViewManager(mContext,
728 mViewMediatorCallback, mLockPatternUtils);
Daniel Sandler687a3272010-03-13 15:44:47 -0500729 final ContentResolver cr = mContext.getContentResolver();
Marco Nelissend5545bd2011-09-29 12:49:17 -0700730
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700731 mDeviceInteractive = mPM.isInteractive();
Daniel Hansson4b716862012-03-29 11:02:05 +0200732
Jean-Michel Trivi0616db42019-01-28 10:57:21 -0800733 mLockSounds = new SoundPool.Builder()
734 .setMaxStreams(1)
735 .setAudioAttributes(
736 new AudioAttributes.Builder()
737 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
738 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
739 .build())
740 .build();
Jim Millerb14288d2012-09-30 18:25:05 -0700741 String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700742 if (soundPath != null) {
743 mLockSoundId = mLockSounds.load(soundPath, 1);
744 }
745 if (soundPath == null || mLockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700746 Log.w(TAG, "failed to load lock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700747 }
Jim Millerb14288d2012-09-30 18:25:05 -0700748 soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700749 if (soundPath != null) {
750 mUnlockSoundId = mLockSounds.load(soundPath, 1);
751 }
752 if (soundPath == null || mUnlockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700753 Log.w(TAG, "failed to load unlock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700754 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200755 soundPath = Settings.Global.getString(cr, Settings.Global.TRUSTED_SOUND);
756 if (soundPath != null) {
757 mTrustedSoundId = mLockSounds.load(soundPath, 1);
758 }
759 if (soundPath == null || mTrustedSoundId == 0) {
760 Log.w(TAG, "failed to load trusted sound from " + soundPath);
761 }
762
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200763 int lockSoundDefaultAttenuation = mContext.getResources().getInteger(
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700764 com.android.internal.R.integer.config_lockSoundVolumeDb);
Jean-Michel Trivif2b0c112012-07-09 11:59:11 -0700765 mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20);
Adrian Roos0002a452014-07-03 13:46:07 +0200766
767 mHideAnimation = AnimationUtils.loadAnimation(mContext,
768 com.android.internal.R.anim.lock_screen_behind_enter);
Robin Leec41f6ec2017-01-10 17:02:34 +0000769
770 mWorkLockController = new WorkLockActivityController(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800771 }
772
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200773 @Override
774 public void start() {
Jim Millerab954542014-10-10 18:21:49 -0700775 synchronized (this) {
776 setupLocked();
777 }
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200778 putComponent(KeyguardViewMediator.class, this);
779 }
780
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800781 /**
782 * Let us know that the system is ready after startup.
783 */
784 public void onSystemReady() {
Adrian Roos30a2ae62018-04-25 19:09:50 +0200785 mHandler.obtainMessage(SYSTEM_READY).sendToTarget();
786 }
787
788 private void handleSystemReady() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800789 synchronized (this) {
790 if (DEBUG) Log.d(TAG, "onSystemReady");
791 mSystemReady = true;
Jim Miller5ecd8112013-01-09 18:50:26 -0800792 doKeyguardLocked(null);
Selim Cinekedd32b82015-06-23 22:05:58 -0400793 mUpdateMonitor.registerCallback(mUpdateCallback);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800794 }
Jim Miller3fd47af2012-09-21 19:55:27 -0700795 // Most services aren't available until the system reaches the ready state, so we
796 // send it here when the device first boots.
797 maybeSendUserPresentBroadcast();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800798 }
799
800 /**
801 * Called to let us know the screen was turned off.
Adrian Roose99bc052017-11-20 17:55:31 +0100802 * @param why either {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_USER} or
803 * {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_TIMEOUT}.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800804 */
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700805 public void onStartedGoingToSleep(int why) {
806 if (DEBUG) Log.d(TAG, "onStartedGoingToSleep(" + why + ")");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800807 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700808 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700809 mGoingToSleep = true;
John Spurlock14adfe42012-11-08 10:29:26 -0500810
Jim Millera4edd152012-01-06 18:24:04 -0800811 // Lock immediately based on setting if secure (user has a pin/pattern/password).
812 // This also "locks" the device when not secure to provide easy access to the
813 // camera while preventing unwanted input.
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700814 int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jim Millera4edd152012-01-06 18:24:04 -0800815 final boolean lockImmediately =
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700816 mLockPatternUtils.getPowerButtonInstantlyLocks(currentUser)
817 || !mLockPatternUtils.isSecure(currentUser);
Clara Bayarri56878a92015-10-29 15:43:55 +0000818 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000819 mLockLater = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800820 if (mExitSecureCallback != null) {
821 if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled");
Jim Miller5ecd8112013-01-09 18:50:26 -0800822 try {
823 mExitSecureCallback.onKeyguardExitResult(false);
824 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800825 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800826 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800827 mExitSecureCallback = null;
828 if (!mExternallyEnabled) {
Jim Miller9c20d0e2010-01-20 15:00:23 -0800829 hideLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800830 }
831 } else if (mShowing) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700832 mPendingReset = true;
Adrian Roose99bc052017-11-20 17:55:31 +0100833 } else if ((why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_TIMEOUT && timeout > 0)
834 || (why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER && !lockImmediately)) {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700835 doKeyguardLaterLocked(timeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000836 mLockLater = true;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700837 } else if (!mLockPatternUtils.isLockScreenDisabled(currentUser)) {
838 mPendingLock = true;
839 }
840
Jorim Jaggi853cbe32015-06-04 16:31:54 -0700841 if (mPendingLock) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700842 playSounds(true);
843 }
844 }
Jorim Jaggi95e40382015-09-16 15:53:42 -0700845 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedGoingToSleep(why);
Jorim Jaggi18f18ae2015-09-10 15:48:21 -0700846 notifyStartedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700847 }
848
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700849 public void onFinishedGoingToSleep(int why, boolean cameraGestureTriggered) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700850 if (DEBUG) Log.d(TAG, "onFinishedGoingToSleep(" + why + ")");
851 synchronized (this) {
852 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700853 mGoingToSleep = false;
Adrian Roose4cb6c8a2017-07-19 18:08:07 +0200854 mWakeAndUnlocking = false;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700855
856 resetKeyguardDonePendingLocked();
857 mHideAnimationRun = false;
858
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700859 notifyFinishedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700860
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700861 if (cameraGestureTriggered) {
862 Log.i(TAG, "Camera gesture was triggered, preventing Keyguard locking.");
863
864 // Just to make sure, make sure the device is awake.
865 mContext.getSystemService(PowerManager.class).wakeUp(SystemClock.uptimeMillis(),
Michael Wrighte3001042019-02-05 00:13:14 +0000866 PowerManager.WAKE_REASON_CAMERA_LAUNCH,
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700867 "com.android.systemui:CAMERA_GESTURE_PREVENT_LOCK");
868 mPendingLock = false;
869 mPendingReset = false;
870 }
871
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700872 if (mPendingReset) {
873 resetStateLocked();
874 mPendingReset = false;
875 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000876
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700877 if (mPendingLock) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800878 doKeyguardLocked(null);
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700879 mPendingLock = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800880 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000881
882 // We do not have timeout and power button instant lock setting for profile lock.
883 // So we use the personal setting if there is any. But if there is no device
884 // we need to make sure we lock it immediately when the screen is off.
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700885 if (!mLockLater && !cameraGestureTriggered) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000886 doKeyguardForChildProfilesLocked();
887 }
888
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800889 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700890 KeyguardUpdateMonitor.getInstance(mContext).dispatchFinishedGoingToSleep(why);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800891 }
892
Clara Bayarri56878a92015-10-29 15:43:55 +0000893 private long getLockTimeout(int userId) {
Jeff Brown6aaf2952012-10-05 16:01:08 -0700894 // if the screen turned off because of timeout or the user hit the power button
895 // and we don't need to lock immediately, set an alarm
896 // to enable it a little bit later (i.e, give the user a chance
897 // to turn the screen back on within a certain window without
898 // having to unlock the screen)
899 final ContentResolver cr = mContext.getContentResolver();
900
Jeff Brown6aaf2952012-10-05 16:01:08 -0700901 // From SecuritySettings
902 final long lockAfterTimeout = Settings.Secure.getInt(cr,
903 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT,
904 KEYGUARD_LOCK_AFTER_DELAY_DEFAULT);
905
906 // From DevicePolicyAdmin
907 final long policyTimeout = mLockPatternUtils.getDevicePolicyManager()
Pavel Grafov28939982017-10-03 15:11:52 +0100908 .getMaximumTimeToLock(null, userId);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700909
910 long timeout;
Clara Bayarri56878a92015-10-29 15:43:55 +0000911
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000912 if (policyTimeout <= 0) {
Clara Bayarri56878a92015-10-29 15:43:55 +0000913 timeout = lockAfterTimeout;
914 } else {
915 // From DisplaySettings
916 long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT,
917 KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT);
918
Jeff Brown6aaf2952012-10-05 16:01:08 -0700919 // policy in effect. Make sure we don't go beyond policy limit.
920 displayTimeout = Math.max(displayTimeout, 0); // ignore negative values
921 timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000922 timeout = Math.max(timeout, 0);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700923 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700924 return timeout;
925 }
Jeff Brown6aaf2952012-10-05 16:01:08 -0700926
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700927 private void doKeyguardLaterLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000928 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700929 if (timeout == 0) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800930 doKeyguardLocked(null);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700931 } else {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700932 doKeyguardLaterLocked(timeout);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700933 }
934 }
935
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700936 private void doKeyguardLaterLocked(long timeout) {
937 // Lock in the future
938 long when = SystemClock.elapsedRealtime() + timeout;
939 Intent intent = new Intent(DELAYED_KEYGUARD_ACTION);
940 intent.putExtra("seq", mDelayedShowingSequence);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700941 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700942 PendingIntent sender = PendingIntent.getBroadcast(mContext,
943 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Jim Millera622d3cc2016-03-02 16:02:24 -0800944 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700945 if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = "
946 + mDelayedShowingSequence);
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000947 doKeyguardLaterForChildProfilesLocked();
Clara Bayarri56878a92015-10-29 15:43:55 +0000948 }
Clara Bayarri10ad84a2015-12-01 17:38:05 +0000949
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000950 private void doKeyguardLaterForChildProfilesLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000951 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700952 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
953 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
954 long userTimeout = getLockTimeout(profileId);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000955 if (userTimeout == 0) {
956 doKeyguardForChildProfilesLocked();
957 } else {
958 long userWhen = SystemClock.elapsedRealtime() + userTimeout;
959 Intent lockIntent = new Intent(DELAYED_LOCK_PROFILE_ACTION);
960 lockIntent.putExtra("seq", mDelayedProfileShowingSequence);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700961 lockIntent.putExtra(Intent.EXTRA_USER_ID, profileId);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700962 lockIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000963 PendingIntent lockSender = PendingIntent.getBroadcast(
964 mContext, 0, lockIntent, PendingIntent.FLAG_CANCEL_CURRENT);
965 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
966 userWhen, lockSender);
967 }
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000968 }
969 }
970 }
971
972 private void doKeyguardForChildProfilesLocked() {
973 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700974 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
975 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
976 lockProfile(profileId);
Clara Bayarri56878a92015-10-29 15:43:55 +0000977 }
978 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700979 }
980
Jeff Brown6aaf2952012-10-05 16:01:08 -0700981 private void cancelDoKeyguardLaterLocked() {
982 mDelayedShowingSequence++;
983 }
984
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000985 private void cancelDoKeyguardForChildProfilesLocked() {
986 mDelayedProfileShowingSequence++;
987 }
988
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800989 /**
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700990 * Let's us know when the device is waking up.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800991 */
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700992 public void onStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700993 Trace.beginSection("KeyguardViewMediator#onStartedWakingUp");
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700994
995 // TODO: Rename all screen off/on references to interactive/sleeping
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800996 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700997 mDeviceInteractive = true;
Jeff Brown6aaf2952012-10-05 16:01:08 -0700998 cancelDoKeyguardLaterLocked();
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000999 cancelDoKeyguardForChildProfilesLocked();
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001000 if (DEBUG) Log.d(TAG, "onStartedWakingUp, seq = " + mDelayedShowingSequence);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001001 notifyStartedWakingUp();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001002 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001003 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedWakingUp();
Jim Miller3fd47af2012-09-21 19:55:27 -07001004 maybeSendUserPresentBroadcast();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001005 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -07001006 }
1007
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001008 public void onScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001009 Trace.beginSection("KeyguardViewMediator#onScreenTurningOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001010 notifyScreenOn(callback);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001011 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001012 }
1013
1014 public void onScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001015 Trace.beginSection("KeyguardViewMediator#onScreenTurnedOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001016 notifyScreenTurnedOn();
1017 mUpdateMonitor.dispatchScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001018 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001019 }
1020
1021 public void onScreenTurnedOff() {
1022 notifyScreenTurnedOff();
1023 mUpdateMonitor.dispatchScreenTurnedOff();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001024 }
1025
Jim Miller3fd47af2012-09-21 19:55:27 -07001026 private void maybeSendUserPresentBroadcast() {
Adrian Roos8150d2a2015-04-16 17:11:20 -07001027 if (mSystemReady && mLockPatternUtils.isLockScreenDisabled(
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001028 KeyguardUpdateMonitor.getCurrentUser())) {
Jim Miller3fd47af2012-09-21 19:55:27 -07001029 // Lock screen is disabled because the user has set the preference to "None".
1030 // In this case, send out ACTION_USER_PRESENT here instead of in
1031 // handleKeyguardDone()
1032 sendUserPresentBroadcast();
Adrian Roosfb95a812016-06-20 14:58:59 -07001033 } else if (mSystemReady && shouldWaitForProvisioning()) {
1034 // Skipping the lockscreen because we're not yet provisioned, but we still need to
1035 // notify the StrongAuthTracker that it's now safe to run trust agents, in case the
1036 // user sets a credential later.
1037 getLockPatternUtils().userPresent(KeyguardUpdateMonitor.getCurrentUser());
Jim Miller3fd47af2012-09-21 19:55:27 -07001038 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001039 }
1040
1041 /**
Jeff Brown6aaf2952012-10-05 16:01:08 -07001042 * A dream started. We should lock after the usual screen-off lock timeout but only
1043 * if there is a secure lock pattern.
1044 */
1045 public void onDreamingStarted() {
Selim Cinek99415392016-09-09 14:58:41 -07001046 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001047 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001048 if (mDeviceInteractive
1049 && mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001050 doKeyguardLaterLocked();
1051 }
1052 }
1053 }
1054
1055 /**
1056 * A dream stopped.
1057 */
1058 public void onDreamingStopped() {
Selim Cinek99415392016-09-09 14:58:41 -07001059 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001060 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001061 if (mDeviceInteractive) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001062 cancelDoKeyguardLaterLocked();
1063 }
1064 }
1065 }
1066
1067 /**
Adrian Roose99bc052017-11-20 17:55:31 +01001068 * Same semantics as {@link WindowManagerPolicyConstants#enableKeyguard}; provide
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001069 * a way for external stuff to override normal keyguard behavior. For instance
1070 * the phone app disables the keyguard when it receives incoming calls.
1071 */
1072 public void setKeyguardEnabled(boolean enabled) {
1073 synchronized (this) {
1074 if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")");
1075
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001076 mExternallyEnabled = enabled;
1077
1078 if (!enabled && mShowing) {
1079 if (mExitSecureCallback != null) {
1080 if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring");
1081 // we're in the process of handling a request to verify the user
1082 // can get past the keyguard. ignore extraneous requests to disable / reenable
1083 return;
1084 }
1085
1086 // hiding keyguard that is showing, remember to reshow later
1087 if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, "
1088 + "disabling status bar expansion");
1089 mNeedToReshowWhenReenabled = true;
Jim Millerab954542014-10-10 18:21:49 -07001090 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001091 hideLocked();
1092 } else if (enabled && mNeedToReshowWhenReenabled) {
1093 // reenabled after previously hidden, reshow
1094 if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling "
1095 + "status bar expansion");
1096 mNeedToReshowWhenReenabled = false;
Jim Millerab954542014-10-10 18:21:49 -07001097 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001098
1099 if (mExitSecureCallback != null) {
1100 if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting");
Jim Miller5ecd8112013-01-09 18:50:26 -08001101 try {
1102 mExitSecureCallback.onKeyguardExitResult(false);
1103 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001104 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001105 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001106 mExitSecureCallback = null;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001107 resetStateLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001108 } else {
Adam Cohenf7522022012-10-03 20:03:18 -07001109 showLocked(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001110
1111 // block until we know the keygaurd is done drawing (and post a message
1112 // to unblock us after a timeout so we don't risk blocking too long
1113 // and causing an ANR).
1114 mWaitingUntilKeyguardVisible = true;
1115 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS);
1116 if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false");
1117 while (mWaitingUntilKeyguardVisible) {
1118 try {
1119 wait();
1120 } catch (InterruptedException e) {
1121 Thread.currentThread().interrupt();
1122 }
1123 }
1124 if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible");
1125 }
1126 }
1127 }
1128 }
1129
1130 /**
1131 * @see android.app.KeyguardManager#exitKeyguardSecurely
1132 */
Jim Miller25190572013-02-28 17:36:24 -08001133 public void verifyUnlock(IKeyguardExitCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001134 Trace.beginSection("KeyguardViewMediator#verifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001135 synchronized (this) {
1136 if (DEBUG) Log.d(TAG, "verifyUnlock");
Jim Millerb256e4e22014-10-31 17:27:13 -07001137 if (shouldWaitForProvisioning()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001138 // don't allow this api when the device isn't provisioned
1139 if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned");
Jim Miller5ecd8112013-01-09 18:50:26 -08001140 try {
Jim Miller25190572013-02-28 17:36:24 -08001141 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001142 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001143 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001144 }
Mike Lockwood5d258b62009-12-02 13:50:45 -05001145 } else if (mExternallyEnabled) {
1146 // this only applies when the user has externally disabled the
1147 // keyguard. this is unexpected and means the user is not
1148 // using the api properly.
1149 Log.w(TAG, "verifyUnlock called when not externally disabled");
Jim Miller5ecd8112013-01-09 18:50:26 -08001150 try {
Jim Miller25190572013-02-28 17:36:24 -08001151 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001152 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001153 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001154 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001155 } else if (mExitSecureCallback != null) {
1156 // already in progress with someone else
Jim Miller5ecd8112013-01-09 18:50:26 -08001157 try {
Jim Miller25190572013-02-28 17:36:24 -08001158 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001159 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001160 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001161 }
Jorim Jaggi302475e2015-09-22 12:44:47 -07001162 } else if (!isSecure()) {
1163
1164 // Keyguard is not secure, no need to do anything, and we don't need to reshow
1165 // the Keyguard after the client releases the Keyguard lock.
1166 mExternallyEnabled = true;
1167 mNeedToReshowWhenReenabled = false;
1168 updateInputRestricted();
1169 try {
1170 callback.onKeyguardExitResult(true);
1171 } catch (RemoteException e) {
1172 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1173 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001174 } else {
Jorim Jaggi302475e2015-09-22 12:44:47 -07001175
1176 // Since we prevent apps from hiding the Keyguard if we are secure, this should be
1177 // a no-op as well.
1178 try {
1179 callback.onKeyguardExitResult(false);
1180 } catch (RemoteException e) {
1181 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1182 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001183 }
1184 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001185 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001186 }
1187
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001188 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001189 * Is the keyguard currently showing and not being force hidden?
Mike Lockwood09a40402009-11-08 00:33:23 -05001190 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001191 public boolean isShowingAndNotOccluded() {
1192 return mShowing && !mOccluded;
1193 }
1194
1195 /**
1196 * Notify us when the keyguard is occluded by another window
1197 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001198 public void setOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001199 Trace.beginSection("KeyguardViewMediator#setOccluded");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001200 if (DEBUG) Log.d(TAG, "setOccluded " + isOccluded);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001201 mHandler.removeMessages(SET_OCCLUDED);
Jorim Jaggi6626f542016-08-22 13:08:44 -07001202 Message msg = mHandler.obtainMessage(SET_OCCLUDED, isOccluded ? 1 : 0, animate ? 1 : 0);
Mike Lockwood9200a392009-11-17 20:25:58 -05001203 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001204 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001205 }
1206
Lucas Dupin2986c152018-04-09 20:49:41 -07001207 public boolean isHiding() {
1208 return mHiding;
1209 }
1210
Mike Lockwood9200a392009-11-17 20:25:58 -05001211 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001212 * Handles SET_OCCLUDED message sent by setOccluded()
Mike Lockwood9200a392009-11-17 20:25:58 -05001213 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001214 private void handleSetOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001215 Trace.beginSection("KeyguardViewMediator#handleSetOccluded");
Mike Lockwood09a40402009-11-08 00:33:23 -05001216 synchronized (KeyguardViewMediator.this) {
Adrian Roosf253eeb2015-04-15 18:03:08 -07001217 if (mHiding && isOccluded) {
1218 // We're in the process of going away but WindowManager wants to show a
1219 // SHOW_WHEN_LOCKED activity instead.
1220 startKeyguardExitAnimation(0, 0);
1221 }
1222
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001223 if (mOccluded != isOccluded) {
1224 mOccluded = isOccluded;
Kevin Chyn2fefd462017-04-28 12:18:19 -07001225 mUpdateMonitor.setKeyguardOccluded(isOccluded);
Selim Cinek2f6272e2017-03-15 16:19:10 -07001226 mStatusBarKeyguardViewManager.setOccluded(isOccluded, animate
1227 && mDeviceInteractive);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001228 adjustStatusBarLocked();
Mike Lockwood9200a392009-11-17 20:25:58 -05001229 }
Mike Lockwood09a40402009-11-08 00:33:23 -05001230 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001231 Trace.endSection();
Mike Lockwood09a40402009-11-08 00:33:23 -05001232 }
1233
1234 /**
Mike Lockwood28569302010-01-28 11:54:40 -05001235 * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout.
1236 * This must be safe to call from any thread and with any window manager locks held.
1237 */
Adam Cohenf7522022012-10-03 20:03:18 -07001238 public void doKeyguardTimeout(Bundle options) {
Mike Lockwood28569302010-01-28 11:54:40 -05001239 mHandler.removeMessages(KEYGUARD_TIMEOUT);
Adam Cohenf7522022012-10-03 20:03:18 -07001240 Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options);
Mike Lockwood28569302010-01-28 11:54:40 -05001241 mHandler.sendMessage(msg);
1242 }
1243
1244 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001245 * Given the state of the keyguard, is the input restricted?
1246 * Input is restricted when the keyguard is showing, or when the keyguard
1247 * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet.
1248 */
1249 public boolean isInputRestricted() {
Adrian Roos9f33d6c2015-06-15 15:58:35 -07001250 return mShowing || mNeedToReshowWhenReenabled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001251 }
1252
Jim Millerab954542014-10-10 18:21:49 -07001253 private void updateInputRestricted() {
1254 synchronized (this) {
1255 updateInputRestrictedLocked();
1256 }
1257 }
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001258
Jim Millerab954542014-10-10 18:21:49 -07001259 private void updateInputRestrictedLocked() {
1260 boolean inputRestricted = isInputRestricted();
1261 if (mInputRestricted != inputRestricted) {
1262 mInputRestricted = inputRestricted;
dooyoung.hwang328472e2015-05-21 16:09:43 +09001263 int size = mKeyguardStateCallbacks.size();
1264 for (int i = size - 1; i >= 0; i--) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001265 final IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001266 try {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001267 callback.onInputRestrictedStateChanged(inputRestricted);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001268 } catch (RemoteException e) {
1269 Slog.w(TAG, "Failed to call onDeviceProvisioned", e);
1270 if (e instanceof DeadObjectException) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001271 mKeyguardStateCallbacks.remove(callback);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001272 }
Jim Millerab954542014-10-10 18:21:49 -07001273 }
Jim Millerab954542014-10-10 18:21:49 -07001274 }
1275 }
1276 }
1277
Dianne Hackbornb446e972009-09-20 15:23:25 -07001278 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001279 * Enable the keyguard if the settings are appropriate.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001280 */
Adam Cohenf7522022012-10-03 20:03:18 -07001281 private void doKeyguardLocked(Bundle options) {
Adrian Roosca8a2162017-08-17 19:00:58 +02001282 if (KeyguardUpdateMonitor.CORE_APPS_ONLY) {
1283 // Don't show keyguard during half-booted cryptkeeper stage.
1284 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because booting to cryptkeeper");
1285 return;
1286 }
1287
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001288 // if another app is disabling us, don't show
1289 if (!mExternallyEnabled) {
1290 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled");
Karl Rosaenab100082009-03-24 22:35:17 -07001291
Adrian Roos1c8e3c02018-11-20 20:07:55 +01001292 mNeedToReshowWhenReenabled = true;
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001293 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001294 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001295
1296 // if the keyguard is already showing, don't bother
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001297 if (mStatusBarKeyguardViewManager.isShowing()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001298 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing");
Jorim Jaggi95e89ca2014-11-24 20:12:50 +01001299 resetStateLocked();
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001300 return;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001301 }
1302
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001303 // In split system user mode, we never unlock system user.
Amith Yamasanieb437d42016-04-29 09:31:25 -07001304 if (!mustNotUnlockCurrentUser()
Amith Yamasani27e025b2015-11-06 10:34:41 -08001305 || !mUpdateMonitor.isDeviceProvisioned()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001306
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001307 // if the setup wizard hasn't run yet, don't show
1308 final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", false);
1309 final boolean absent = SubscriptionManager.isValidSubscriptionId(
Adrian Roose92de952016-12-13 12:07:09 -08001310 mUpdateMonitor.getNextSubIdForState(ABSENT));
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001311 final boolean disabled = SubscriptionManager.isValidSubscriptionId(
1312 mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.PERM_DISABLED));
1313 final boolean lockedOrMissing = mUpdateMonitor.isSimPinSecure()
1314 || ((absent || disabled) && requireSim);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001315
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001316 if (!lockedOrMissing && shouldWaitForProvisioning()) {
1317 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned"
1318 + " and the sim is not locked or missing");
1319 return;
1320 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001321
Evan Rosky13a58a92016-07-27 15:51:09 -07001322 boolean forceShow = options != null && options.getBoolean(OPTION_FORCE_SHOW, false);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001323 if (mLockPatternUtils.isLockScreenDisabled(KeyguardUpdateMonitor.getCurrentUser())
Evan Rosky13a58a92016-07-27 15:51:09 -07001324 && !lockedOrMissing && !forceShow) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001325 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off");
1326 return;
1327 }
1328
1329 if (mLockPatternUtils.checkVoldPassword(KeyguardUpdateMonitor.getCurrentUser())) {
1330 if (DEBUG) Log.d(TAG, "Not showing lock screen since just decrypted");
1331 // Without this, settings is not enabled until the lock screen first appears
Lucas Dupinb3455e62019-07-11 11:47:13 +09001332 setShowingLocked(false);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001333 hideLocked();
1334 return;
1335 }
Paul Lawrence945490c2014-03-27 16:37:28 +00001336 }
1337
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001338 if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");
Adam Cohenf7522022012-10-03 20:03:18 -07001339 showLocked(options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001340 }
1341
Clara Bayarri56878a92015-10-29 15:43:55 +00001342 private void lockProfile(int userId) {
1343 mTrustManager.setDeviceLockedForUser(userId, true);
1344 }
1345
Jim Millerb256e4e22014-10-31 17:27:13 -07001346 private boolean shouldWaitForProvisioning() {
1347 return !mUpdateMonitor.isDeviceProvisioned() && !isSecure();
1348 }
1349
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001350 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001351 * Dismiss the keyguard through the security layers.
Jorim Jaggi241ae102016-11-02 21:57:33 -07001352 * @param callback Callback to be informed about the result
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001353 * @param message Message that should be displayed on the bouncer.
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001354 */
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001355 private void handleDismiss(IKeyguardDismissCallback callback, CharSequence message) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001356 if (mShowing) {
1357 if (callback != null) {
1358 mDismissCallbackRegistry.addCallback(callback);
1359 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001360 mCustomMessage = message;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001361 mStatusBarKeyguardViewManager.dismissAndCollapse();
Jorim Jaggi241ae102016-11-02 21:57:33 -07001362 } else if (callback != null) {
1363 new DismissCallbackWrapper(callback).notifyDismissError();
Jim Miller87d03662012-11-05 20:28:09 -08001364 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001365 }
1366
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001367 public void dismiss(IKeyguardDismissCallback callback, CharSequence message) {
1368 mHandler.obtainMessage(DISMISS, new DismissMessage(callback, message)).sendToTarget();
Jim Miller60013792013-10-03 18:31:34 -07001369 }
1370
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001371 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001372 * Send message to keyguard telling it to reset its state.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001373 * @see #handleReset
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001374 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001375 private void resetStateLocked() {
Jim Miller4894a012013-04-03 15:23:55 -07001376 if (DEBUG) Log.e(TAG, "resetStateLocked");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001377 Message msg = mHandler.obtainMessage(RESET);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001378 mHandler.sendMessage(msg);
1379 }
1380
1381 /**
1382 * Send message to keyguard telling it to verify unlock
1383 * @see #handleVerifyUnlock()
1384 */
1385 private void verifyUnlockLocked() {
1386 if (DEBUG) Log.d(TAG, "verifyUnlockLocked");
1387 mHandler.sendEmptyMessage(VERIFY_UNLOCK);
1388 }
1389
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001390 private void notifyStartedGoingToSleep() {
1391 if (DEBUG) Log.d(TAG, "notifyStartedGoingToSleep");
1392 mHandler.sendEmptyMessage(NOTIFY_STARTED_GOING_TO_SLEEP);
1393 }
1394
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001395 private void notifyFinishedGoingToSleep() {
1396 if (DEBUG) Log.d(TAG, "notifyFinishedGoingToSleep");
1397 mHandler.sendEmptyMessage(NOTIFY_FINISHED_GOING_TO_SLEEP);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001398 }
1399
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001400 private void notifyStartedWakingUp() {
1401 if (DEBUG) Log.d(TAG, "notifyStartedWakingUp");
1402 mHandler.sendEmptyMessage(NOTIFY_STARTED_WAKING_UP);
1403 }
1404
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001405 private void notifyScreenOn(IKeyguardDrawnCallback callback) {
1406 if (DEBUG) Log.d(TAG, "notifyScreenOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001407 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNING_ON, callback);
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001408 mHandler.sendMessage(msg);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001409 }
1410
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001411 private void notifyScreenTurnedOn() {
1412 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOn");
1413 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_ON);
1414 mHandler.sendMessage(msg);
1415 }
1416
1417 private void notifyScreenTurnedOff() {
1418 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOff");
1419 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_OFF);
1420 mHandler.sendMessage(msg);
1421 }
1422
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001423 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001424 * Send message to keyguard telling it to show itself
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001425 * @see #handleShow
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001426 */
Adam Cohenf7522022012-10-03 20:03:18 -07001427 private void showLocked(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001428 Trace.beginSection("KeyguardViewMediator#showLocked aqcuiring mShowKeyguardWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001429 if (DEBUG) Log.d(TAG, "showLocked");
Mike Lockwood674d3e42009-10-06 09:28:54 -04001430 // ensure we stay awake until we are finished displaying the keyguard
1431 mShowKeyguardWakeLock.acquire();
Adam Cohenf7522022012-10-03 20:03:18 -07001432 Message msg = mHandler.obtainMessage(SHOW, options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001433 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001434 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001435 }
1436
1437 /**
1438 * Send message to keyguard telling it to hide itself
Jim Miller9c20d0e2010-01-20 15:00:23 -08001439 * @see #handleHide()
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001440 */
1441 private void hideLocked() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001442 Trace.beginSection("KeyguardViewMediator#hideLocked");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001443 if (DEBUG) Log.d(TAG, "hideLocked");
1444 Message msg = mHandler.obtainMessage(HIDE);
1445 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001446 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001447 }
1448
Dianne Hackbornb446e972009-09-20 15:23:25 -07001449 public boolean isSecure() {
Evan Rosky13a58a92016-07-27 15:51:09 -07001450 return isSecure(KeyguardUpdateMonitor.getCurrentUser());
1451 }
1452
1453 public boolean isSecure(int userId) {
1454 return mLockPatternUtils.isSecure(userId)
1455 || KeyguardUpdateMonitor.getInstance(mContext).isSimPinSecure();
Dianne Hackbornb446e972009-09-20 15:23:25 -07001456 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001457
Evan Rosky18396452016-07-27 15:19:37 -07001458 public void setSwitchingUser(boolean switching) {
Selim Cinekbbe19242017-12-08 15:42:08 -08001459 KeyguardUpdateMonitor.getInstance(mContext).setSwitchingUser(switching);
Evan Rosky18396452016-07-27 15:19:37 -07001460 }
1461
Craig Mautnerf1b67412012-09-19 13:18:29 -07001462 /**
1463 * Update the newUserId. Call while holding WindowManagerService lock.
Jim Milleree82f8f2012-10-01 16:26:18 -07001464 * NOTE: Should only be called by KeyguardViewMediator in response to the user id changing.
1465 *
Craig Mautnerf1b67412012-09-19 13:18:29 -07001466 * @param newUserId The id of the incoming user.
1467 */
1468 public void setCurrentUser(int newUserId) {
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001469 KeyguardUpdateMonitor.setCurrentUser(newUserId);
Adrian Roosd88eb262016-08-04 14:50:48 -07001470 synchronized (this) {
1471 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(newUserId));
1472 }
Craig Mautnerf1b67412012-09-19 13:18:29 -07001473 }
1474
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001475 /**
1476 * This broadcast receiver should be registered with the SystemUI permission.
1477 */
1478 private final BroadcastReceiver mDelayedLockBroadcastReceiver = new BroadcastReceiver() {
Amith Yamasani52c489c2012-03-28 11:42:42 -07001479 @Override
1480 public void onReceive(Context context, Intent intent) {
Jim Millerbbf1a742012-07-17 18:30:30 -07001481 if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
1482 final int sequence = intent.getIntExtra("seq", 0);
Jim Millerf3447352011-08-07 14:00:09 -07001483 if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = "
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001484 + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001485 synchronized (KeyguardViewMediator.this) {
Jim Miller2967f482016-01-07 15:05:32 -08001486 if (mDelayedShowingSequence == sequence) {
1487 doKeyguardLocked(null);
1488 }
Clara Bayarri56878a92015-10-29 15:43:55 +00001489 }
1490 } else if (DELAYED_LOCK_PROFILE_ACTION.equals(intent.getAction())) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001491 final int sequence = intent.getIntExtra("seq", 0);
Clara Bayarri56878a92015-10-29 15:43:55 +00001492 int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, 0);
1493 if (userId != 0) {
1494 synchronized (KeyguardViewMediator.this) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001495 if (mDelayedProfileShowingSequence == sequence) {
1496 lockProfile(userId);
1497 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001498 }
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001499 }
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001500 }
1501 }
1502 };
1503
1504 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1505 @Override
1506 public void onReceive(Context context, Intent intent) {
1507 if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
Adrian Roos1f8025a2016-12-27 10:12:13 -08001508 synchronized (KeyguardViewMediator.this){
1509 mShuttingDown = true;
1510 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001511 }
1512 }
1513 };
1514
Jorim Jaggi241ae102016-11-02 21:57:33 -07001515 public void keyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001516 Trace.beginSection("KeyguardViewMediator#keyguardDone");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001517 if (DEBUG) Log.d(TAG, "keyguardDone()");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001518 userActivity();
Jim Miller60013792013-10-03 18:31:34 -07001519 EventLog.writeEvent(70000, 2);
Jorim Jaggi241ae102016-11-02 21:57:33 -07001520 Message msg = mHandler.obtainMessage(KEYGUARD_DONE);
Jim Miller60013792013-10-03 18:31:34 -07001521 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001522 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001523 }
1524
1525 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001526 * This handler will be associated with the policy thread, which will also
1527 * be the UI thread of the keyguard. Since the apis of the policy, and therefore
1528 * this class, can be called by other threads, any action that directly
1529 * interacts with the keyguard ui should be posted to this handler, rather
1530 * than called directly.
1531 */
Jim Millerdcb3d842012-08-23 19:18:12 -07001532 private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001533 @Override
Wink Saville37c124c2009-04-02 01:37:02 -07001534 public void handleMessage(Message msg) {
1535 switch (msg.what) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001536 case SHOW:
Adam Cohenf7522022012-10-03 20:03:18 -07001537 handleShow((Bundle) msg.obj);
Jim Miller60013792013-10-03 18:31:34 -07001538 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001539 case HIDE:
1540 handleHide();
Jim Miller60013792013-10-03 18:31:34 -07001541 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001542 case RESET:
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001543 handleReset();
Jim Miller60013792013-10-03 18:31:34 -07001544 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001545 case VERIFY_UNLOCK:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001546 Trace.beginSection("KeyguardViewMediator#handleMessage VERIFY_UNLOCK");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001547 handleVerifyUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001548 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001549 break;
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001550 case NOTIFY_STARTED_GOING_TO_SLEEP:
1551 handleNotifyStartedGoingToSleep();
1552 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001553 case NOTIFY_FINISHED_GOING_TO_SLEEP:
1554 handleNotifyFinishedGoingToSleep();
Jim Miller60013792013-10-03 18:31:34 -07001555 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001556 case NOTIFY_SCREEN_TURNING_ON:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001557 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNING_ON");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001558 handleNotifyScreenTurningOn((IKeyguardDrawnCallback) msg.obj);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001559 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001560 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001561 case NOTIFY_SCREEN_TURNED_ON:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001562 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNED_ON");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001563 handleNotifyScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001564 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001565 break;
1566 case NOTIFY_SCREEN_TURNED_OFF:
1567 handleNotifyScreenTurnedOff();
1568 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001569 case NOTIFY_STARTED_WAKING_UP:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001570 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_STARTED_WAKING_UP");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001571 handleNotifyStartedWakingUp();
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:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001575 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001576 handleKeyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001577 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001578 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001579 case KEYGUARD_DONE_DRAWING:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001580 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_DRAWING");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001581 handleKeyguardDoneDrawing();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001582 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001583 break;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001584 case SET_OCCLUDED:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001585 Trace.beginSection("KeyguardViewMediator#handleMessage SET_OCCLUDED");
Jorim Jaggi6626f542016-08-22 13:08:44 -07001586 handleSetOccluded(msg.arg1 != 0, msg.arg2 != 0);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001587 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001588 break;
Mike Lockwood28569302010-01-28 11:54:40 -05001589 case KEYGUARD_TIMEOUT:
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001590 synchronized (KeyguardViewMediator.this) {
Adam Cohenf7522022012-10-03 20:03:18 -07001591 doKeyguardLocked((Bundle) msg.obj);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001592 }
1593 break;
Jim Miller60013792013-10-03 18:31:34 -07001594 case DISMISS:
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001595 final DismissMessage message = (DismissMessage) msg.obj;
1596 handleDismiss(message.getCallback(), message.getMessage());
Jim Miller60013792013-10-03 18:31:34 -07001597 break;
Jorim Jaggi0d674622014-05-21 01:34:15 +02001598 case START_KEYGUARD_EXIT_ANIM:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001599 Trace.beginSection("KeyguardViewMediator#handleMessage START_KEYGUARD_EXIT_ANIM");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001600 StartKeyguardExitAnimParams params = (StartKeyguardExitAnimParams) msg.obj;
1601 handleStartKeyguardExitAnimation(params.startTime, params.fadeoutDuration);
Dave Mankoffdde5ee62019-05-02 17:36:11 -04001602 FalsingManagerFactory.getInstance(mContext).onSucccessfulUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001603 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001604 break;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001605 case KEYGUARD_DONE_PENDING_TIMEOUT:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001606 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_PENDING_TIMEOUT");
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001607 Log.w(TAG, "Timeout while waiting for activity drawn!");
Nick Desaulniers1d396752016-07-25 15:05:33 -07001608 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001609 break;
Adrian Roos30a2ae62018-04-25 19:09:50 +02001610 case SYSTEM_READY:
1611 handleSystemReady();
1612 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001613 }
1614 }
1615 };
1616
Jorim Jaggi241ae102016-11-02 21:57:33 -07001617 private void tryKeyguardDone() {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001618 if (!mKeyguardDonePending && mHideAnimationRun && !mHideAnimationRunning) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001619 handleKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001620 } else if (!mHideAnimationRun) {
1621 mHideAnimationRun = true;
1622 mHideAnimationRunning = true;
1623 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
1624 }
1625 }
1626
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001627 /**
1628 * @see #keyguardDone
1629 * @see #KEYGUARD_DONE
1630 */
Jorim Jaggi241ae102016-11-02 21:57:33 -07001631 private void handleKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001632 Trace.beginSection("KeyguardViewMediator#handleKeyguardDone");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001633 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001634 mUiOffloadThread.submit(() -> {
1635 if (mLockPatternUtils.isSecure(currentUser)) {
1636 mLockPatternUtils.getDevicePolicyManager().reportKeyguardDismissed(currentUser);
1637 }
1638 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001639 if (DEBUG) Log.d(TAG, "handleKeyguardDone");
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001640 synchronized (this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001641 resetKeyguardDonePendingLocked();
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001642 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001643
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001644 mUpdateMonitor.clearBiometricRecognized();
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -07001645
Jorim Jaggi4474f542015-07-09 16:08:02 -07001646 if (mGoingToSleep) {
1647 Log.i(TAG, "Device is going to sleep, aborting keyguardDone");
1648 return;
1649 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001650 if (mExitSecureCallback != null) {
1651 try {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001652 mExitSecureCallback.onKeyguardExitResult(true /* authenciated */);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001653 } catch (RemoteException e) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001654 Slog.w(TAG, "Failed to call onKeyguardExitResult()", e);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001655 }
1656
1657 mExitSecureCallback = null;
1658
Jorim Jaggi241ae102016-11-02 21:57:33 -07001659 // after succesfully exiting securely, no need to reshow
1660 // the keyguard when they've released the lock
1661 mExternallyEnabled = true;
1662 mNeedToReshowWhenReenabled = false;
1663 updateInputRestricted();
Jim Millere51cf7ae2013-06-25 18:31:56 -07001664 }
1665
1666 handleHide();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001667 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -07001668 }
1669
1670 private void sendUserPresentBroadcast() {
Jason Monkcf5a9532014-09-17 16:22:19 -04001671 synchronized (this) {
1672 if (mBootCompleted) {
Adrian Roos4ab7e592016-04-13 15:38:13 -07001673 int currentUserId = KeyguardUpdateMonitor.getCurrentUser();
1674 final UserHandle currentUser = new UserHandle(currentUserId);
Benjamin Franz4b9f8ed2014-12-01 16:51:48 +00001675 final UserManager um = (UserManager) mContext.getSystemService(
1676 Context.USER_SERVICE);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001677 mUiOffloadThread.submit(() -> {
1678 for (int profileId : um.getProfileIdsWithDisabled(currentUser.getIdentifier())) {
1679 mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, UserHandle.of(profileId));
1680 }
1681 getLockPatternUtils().userPresent(currentUserId);
1682 });
Jason Monkcf5a9532014-09-17 16:22:19 -04001683 } else {
1684 mBootSendUserPresent = true;
1685 }
1686 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001687 }
1688
1689 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001690 * @see #keyguardDone
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001691 * @see #KEYGUARD_DONE_DRAWING
1692 */
1693 private void handleKeyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001694 Trace.beginSection("KeyguardViewMediator#handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001695 synchronized(this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001696 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001697 if (mWaitingUntilKeyguardVisible) {
1698 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible");
1699 mWaitingUntilKeyguardVisible = false;
1700 notifyAll();
1701
1702 // there will usually be two of these sent, one as a timeout, and one
1703 // as a result of the callback, so remove any remaining messages from
1704 // the queue
1705 mHandler.removeMessages(KEYGUARD_DONE_DRAWING);
1706 }
1707 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001708 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001709 }
1710
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001711 private void playSounds(boolean locked) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001712 playSound(locked ? mLockSoundId : mUnlockSoundId);
1713 }
1714
1715 private void playSound(int soundId) {
1716 if (soundId == 0) return;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001717 final ContentResolver cr = mContext.getContentResolver();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001718 if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001719
Marco Nelissend5545bd2011-09-29 12:49:17 -07001720 mLockSounds.stop(mLockSoundStreamId);
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001721 // Init mAudioManager
1722 if (mAudioManager == null) {
1723 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
1724 if (mAudioManager == null) return;
John Spurlockee5ad722015-03-03 16:17:21 -05001725 mUiSoundsStreamType = mAudioManager.getUiSoundsStreamType();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001726 }
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001727
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001728 mUiOffloadThread.submit(() -> {
1729 // If the stream is muted, don't play the sound
1730 if (mAudioManager.isStreamMute(mUiSoundsStreamType)) return;
1731
1732 int id = mLockSounds.play(soundId,
1733 mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/);
1734 synchronized (this) {
1735 mLockSoundStreamId = id;
1736 }
1737 });
1738
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001739 }
Jim Miller2a98a4c2010-11-19 18:49:26 -08001740 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001741
Adrian Roos49e057d2014-08-13 17:14:51 +02001742 private void playTrustedSound() {
Adrian Roos49e057d2014-08-13 17:14:51 +02001743 playSound(mTrustedSoundId);
1744 }
1745
wilsonshih177261f2019-02-22 12:02:18 +08001746 private void updateActivityLockScreenState(boolean showing, boolean aodShowing) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001747 mUiOffloadThread.submit(() -> {
Lucas Dupinb3455e62019-07-11 11:47:13 +09001748 if (DEBUG) {
1749 Log.d(TAG, "updateActivityLockScreenState(" + showing + ", " + aodShowing + ")");
1750 }
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001751 try {
wilsonshih177261f2019-02-22 12:02:18 +08001752 ActivityTaskManager.getService().setLockScreenShown(showing, aodShowing);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001753 } catch (RemoteException e) {
1754 }
1755 });
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001756 }
1757
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001758 /**
1759 * Handle message sent by {@link #showLocked}.
1760 * @see #SHOW
1761 */
Adam Cohenf7522022012-10-03 20:03:18 -07001762 private void handleShow(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001763 Trace.beginSection("KeyguardViewMediator#handleShow");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001764 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
1765 if (mLockPatternUtils.isSecure(currentUser)) {
1766 mLockPatternUtils.getDevicePolicyManager().reportKeyguardSecured(currentUser);
Michal Karpinski779aad92016-01-20 11:56:22 +00001767 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001768 synchronized (KeyguardViewMediator.this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001769 if (!mSystemReady) {
1770 if (DEBUG) Log.d(TAG, "ignoring handleShow because system is not ready.");
1771 return;
1772 } else {
1773 if (DEBUG) Log.d(TAG, "handleShow");
1774 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001775
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001776 mHiding = false;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001777 mWakeAndUnlocking = false;
Lucas Dupinb3455e62019-07-11 11:47:13 +09001778 setShowingLocked(true);
1779 mStatusBarKeyguardViewManager.show(options);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001780 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001781 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001782 adjustStatusBarLocked();
Jeff Brown3dc524b2012-09-30 19:49:11 -07001783 userActivity();
Kevin Chyn8c7968a2019-03-01 11:25:23 -08001784 mUpdateMonitor.setKeyguardGoingAway(false /* away */);
Lucas Dupine25c4872019-07-29 13:51:35 -07001785 mStatusBarWindowController.setKeyguardGoingAway(false /* goingAway */);
Mike Lockwood674d3e42009-10-06 09:28:54 -04001786 mShowKeyguardWakeLock.release();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001787 }
Jim Miller31921482013-11-06 20:43:55 -08001788 mKeyguardDisplayManager.show();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001789 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001790 }
1791
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001792 private final Runnable mKeyguardGoingAwayRunnable = new Runnable() {
1793 @Override
1794 public void run() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001795 Trace.beginSection("KeyguardViewMediator.mKeyGuardGoingAwayRunnable");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001796 if (DEBUG) Log.d(TAG, "keyguardGoingAway");
wilsonshih2bc846c2019-05-02 14:35:21 +08001797 mStatusBarKeyguardViewManager.keyguardGoingAway();
Jorim Jaggi33ae80e2015-02-04 16:37:11 +01001798
wilsonshih2bc846c2019-05-02 14:35:21 +08001799 int flags = 0;
1800 if (mStatusBarKeyguardViewManager.shouldDisableWindowAnimationsForUnlock()
1801 || (mWakeAndUnlocking && !mPulsing)) {
1802 flags |= WindowManagerPolicyConstants
1803 .KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001804 }
wilsonshih2bc846c2019-05-02 14:35:21 +08001805 if (mStatusBarKeyguardViewManager.isGoingToNotificationShade()
1806 || (mWakeAndUnlocking && mPulsing)) {
1807 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE;
1808 }
1809 if (mStatusBarKeyguardViewManager.isUnlockWithWallpaper()) {
1810 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER;
1811 }
Issei Suzuki5609ccb2019-06-13 15:04:08 +02001812 if (mStatusBarKeyguardViewManager.shouldSubtleWindowAnimationsForUnlock()) {
1813 flags |= WindowManagerPolicyConstants
1814 .KEYGUARD_GOING_AWAY_FLAG_SUBTLE_WINDOW_ANIMATIONS;
1815 }
wilsonshih2bc846c2019-05-02 14:35:21 +08001816
1817 mUpdateMonitor.setKeyguardGoingAway(true /* goingAway */);
Lucas Dupine25c4872019-07-29 13:51:35 -07001818 mStatusBarWindowController.setKeyguardGoingAway(true /* goingAway */);
wilsonshih2bc846c2019-05-02 14:35:21 +08001819
1820 // Don't actually hide the Keyguard at the moment, wait for window
1821 // manager until it tells us it's safe to do so with
1822 // startKeyguardExitAnimation.
1823 // Posting to mUiOffloadThread to ensure that calls to ActivityTaskManager will be in
1824 // order.
1825 final int keyguardFlag = flags;
1826 mUiOffloadThread.submit(() -> {
1827 try {
1828 ActivityTaskManager.getService().keyguardGoingAway(keyguardFlag);
1829 } catch (RemoteException e) {
1830 Log.e(TAG, "Error while calling WindowManager", e);
1831 }
1832 });
Nick Desaulniers1d396752016-07-25 15:05:33 -07001833 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001834 }
1835 };
1836
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001837 private final Runnable mHideAnimationFinishedRunnable = () -> {
1838 mHideAnimationRunning = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -07001839 tryKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001840 };
1841
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001842 /**
1843 * Handle message sent by {@link #hideLocked()}
1844 * @see #HIDE
1845 */
1846 private void handleHide() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001847 Trace.beginSection("KeyguardViewMediator#handleHide");
Lucas Dupin1c327432019-01-03 13:37:53 -08001848
1849 // It's possible that the device was unlocked in a dream state. It's time to wake up.
1850 if (mAodShowing) {
Michael Wrighte3001042019-02-05 00:13:14 +00001851 PowerManager pm = mContext.getSystemService(PowerManager.class);
1852 pm.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE,
1853 "com.android.systemui:BOUNCER_DOZING");
Lucas Dupin1c327432019-01-03 13:37:53 -08001854 }
1855
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001856 synchronized (KeyguardViewMediator.this) {
1857 if (DEBUG) Log.d(TAG, "handleHide");
Jorim Jaggib9d60792014-06-03 22:34:22 +02001858
Amith Yamasanieb437d42016-04-29 09:31:25 -07001859 if (mustNotUnlockCurrentUser()) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001860 // In split system user mode, we never unlock system user. The end user has to
1861 // switch to another user.
1862 // TODO: We should stop it early by disabling the swipe up flow. Right now swipe up
1863 // still completes and makes the screen blank.
1864 if (DEBUG) Log.d(TAG, "Split system user, quit unlocking.");
1865 return;
1866 }
Jorim Jaggi76a16232014-08-08 17:00:47 +02001867 mHiding = true;
Jorim Jaggib9d60792014-06-03 22:34:22 +02001868
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001869 if (mShowing && !mOccluded) {
1870 mKeyguardGoingAwayRunnable.run();
1871 } else {
Jorim Jaggi76a16232014-08-08 17:00:47 +02001872 handleStartKeyguardExitAnimation(
1873 SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(),
1874 mHideAnimation.getDuration());
Jorim Jaggi0d674622014-05-21 01:34:15 +02001875 }
1876 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001877 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001878 }
1879
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001880 private void handleStartKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001881 Trace.beginSection("KeyguardViewMediator#handleStartKeyguardExitAnimation");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001882 if (DEBUG) Log.d(TAG, "handleStartKeyguardExitAnimation startTime=" + startTime
1883 + " fadeoutDuration=" + fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02001884 synchronized (KeyguardViewMediator.this) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001885
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001886 if (!mHiding) {
Adrian Roos6ec76b72018-04-25 14:01:11 +02001887 // Tell ActivityManager that we canceled the keyguardExitAnimation.
Lucas Dupinb3455e62019-07-11 11:47:13 +09001888 setShowingLocked(mShowing, true /* force */);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001889 return;
1890 }
1891 mHiding = false;
1892
Jorim Jaggib774e552015-08-24 14:52:45 -07001893 if (mWakeAndUnlocking && mDrawnCallback != null) {
1894
1895 // Hack level over 9000: To speed up wake-and-unlock sequence, force it to report
1896 // the next draw from here so we don't have to wait for window manager to signal
1897 // this to our ViewRootImpl.
1898 mStatusBarKeyguardViewManager.getViewRootImpl().setReportNextDraw();
1899 notifyDrawn(mDrawnCallback);
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001900 mDrawnCallback = null;
Jorim Jaggib774e552015-08-24 14:52:45 -07001901 }
1902
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001903 // only play "unlock" noises if not on a call (since the incall UI
1904 // disables the keyguard)
1905 if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) {
1906 playSounds(false);
1907 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001908
Lucas Dupinb3455e62019-07-11 11:47:13 +09001909 setShowingLocked(false);
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001910 mWakeAndUnlocking = false;
Jorim Jaggi5277dea2017-05-18 02:05:29 +02001911 mDismissCallbackRegistry.notifyDismissSucceeded();
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001912 mStatusBarKeyguardViewManager.hide(startTime, fadeoutDuration);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001913 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001914 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001915 adjustStatusBarLocked();
Jim Miller705004b2014-09-04 16:51:20 -07001916 sendUserPresentBroadcast();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001917 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001918 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001919 }
1920
Mike Lockwood5f892c12009-11-19 23:39:13 -05001921 private void adjustStatusBarLocked() {
Matthew Ng66f0b702017-12-08 12:58:42 -08001922 adjustStatusBarLocked(false /* forceHideHomeRecentsButtons */);
1923 }
1924
1925 private void adjustStatusBarLocked(boolean forceHideHomeRecentsButtons) {
Mike Lockwood5f892c12009-11-19 23:39:13 -05001926 if (mStatusBarManager == null) {
1927 mStatusBarManager = (StatusBarManager)
1928 mContext.getSystemService(Context.STATUS_BAR_SERVICE);
1929 }
Matthew Ng78ba6e22018-09-24 16:55:36 -07001930
Mike Lockwood5f892c12009-11-19 23:39:13 -05001931 if (mStatusBarManager == null) {
1932 Log.w(TAG, "Could not get status bar manager");
1933 } else {
Daniel Sandlerdba93562011-10-06 16:39:58 -04001934 // Disable aspects of the system/status/navigation bars that must not be re-enabled by
1935 // windows that appear on top, ever
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001936 int flags = StatusBarManager.DISABLE_NONE;
Matthew Ng66f0b702017-12-08 12:58:42 -08001937 if (forceHideHomeRecentsButtons || isShowingAndNotOccluded()) {
1938 flags |= StatusBarManager.DISABLE_HOME | StatusBarManager.DISABLE_RECENT;
Jorim Jaggia005f1b2014-04-16 19:06:10 +02001939 }
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001940
1941 if (DEBUG) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001942 Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mOccluded=" + mOccluded
Matthew Ng66f0b702017-12-08 12:58:42 -08001943 + " isSecure=" + isSecure() + " force=" + forceHideHomeRecentsButtons
1944 + " --> flags=0x" + Integer.toHexString(flags));
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001945 }
1946
Jorim Jaggie3e0b062017-06-12 12:18:41 -07001947 mStatusBarManager.disable(flags);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001948 }
1949 }
1950
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001951 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001952 * Handle message sent by {@link #resetStateLocked}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001953 * @see #RESET
1954 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001955 private void handleReset() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001956 synchronized (KeyguardViewMediator.this) {
1957 if (DEBUG) Log.d(TAG, "handleReset");
Jorim Jaggife762342016-10-13 14:33:27 +02001958 mStatusBarKeyguardViewManager.reset(true /* hideBouncerWhenShowing */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001959 }
1960 }
1961
1962 /**
1963 * Handle message sent by {@link #verifyUnlock}
Craig Mautner904732c2012-10-17 15:20:24 -07001964 * @see #VERIFY_UNLOCK
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001965 */
1966 private void handleVerifyUnlock() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001967 Trace.beginSection("KeyguardViewMediator#handleVerifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001968 synchronized (KeyguardViewMediator.this) {
1969 if (DEBUG) Log.d(TAG, "handleVerifyUnlock");
Lucas Dupinb3455e62019-07-11 11:47:13 +09001970 setShowingLocked(true);
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001971 mStatusBarKeyguardViewManager.dismissAndCollapse();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001972 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001973 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001974 }
1975
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001976 private void handleNotifyStartedGoingToSleep() {
1977 synchronized (KeyguardViewMediator.this) {
1978 if (DEBUG) Log.d(TAG, "handleNotifyStartedGoingToSleep");
1979 mStatusBarKeyguardViewManager.onStartedGoingToSleep();
1980 }
1981 }
1982
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001983 /**
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001984 * Handle message sent by {@link #notifyFinishedGoingToSleep()}
1985 * @see #NOTIFY_FINISHED_GOING_TO_SLEEP
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001986 */
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001987 private void handleNotifyFinishedGoingToSleep() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001988 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001989 if (DEBUG) Log.d(TAG, "handleNotifyFinishedGoingToSleep");
1990 mStatusBarKeyguardViewManager.onFinishedGoingToSleep();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001991 }
1992 }
1993
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001994 private void handleNotifyStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001995 Trace.beginSection("KeyguardViewMediator#handleMotifyStartedWakingUp");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001996 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001997 if (DEBUG) Log.d(TAG, "handleNotifyWakingUp");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001998 mStatusBarKeyguardViewManager.onStartedWakingUp();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001999 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002000 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002001 }
2002
2003 private void handleNotifyScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002004 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurningOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002005 synchronized (KeyguardViewMediator.this) {
2006 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurningOn");
Jorim Jaggi93739112015-08-13 15:53:14 -07002007 mStatusBarKeyguardViewManager.onScreenTurningOn();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002008 if (callback != null) {
2009 if (mWakeAndUnlocking) {
2010 mDrawnCallback = callback;
2011 } else {
2012 notifyDrawn(callback);
2013 }
2014 }
2015 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002016 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002017 }
2018
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002019 private void handleNotifyScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002020 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurnedOn");
Jorim Jaggic3fe2042016-10-07 18:52:48 +02002021 if (LatencyTracker.isEnabled(mContext)) {
2022 LatencyTracker.getInstance(mContext).onActionEnd(LatencyTracker.ACTION_TURN_ON_SCREEN);
2023 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002024 synchronized (this) {
2025 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOn");
2026 mStatusBarKeyguardViewManager.onScreenTurnedOn();
2027 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002028 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002029 }
2030
2031 private void handleNotifyScreenTurnedOff() {
2032 synchronized (this) {
2033 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOff");
Jorim Jaggie93e6f92016-08-04 13:55:39 +02002034 mDrawnCallback = null;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002035 }
2036 }
2037
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002038 private void notifyDrawn(final IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002039 Trace.beginSection("KeyguardViewMediator#notifyDrawn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002040 try {
2041 callback.onDrawn();
2042 } catch (RemoteException e) {
2043 Slog.w(TAG, "Exception calling onDrawn():", e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002044 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002045 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002046 }
Jeff Sharkey054340d2011-09-01 22:28:03 -07002047
Jorim Jaggif8d77da2014-11-11 16:59:12 +01002048 private void resetKeyguardDonePendingLocked() {
2049 mKeyguardDonePending = false;
2050 mHandler.removeMessages(KEYGUARD_DONE_PENDING_TIMEOUT);
2051 }
2052
Jim Miller2967f482016-01-07 15:05:32 -08002053 @Override
Jim Millere5f910a2013-10-16 18:15:46 -07002054 public void onBootCompleted() {
2055 mUpdateMonitor.dispatchBootCompleted();
Jason Monkcf5a9532014-09-17 16:22:19 -04002056 synchronized (this) {
2057 mBootCompleted = true;
2058 if (mBootSendUserPresent) {
2059 sendUserPresentBroadcast();
2060 }
2061 }
Jim Millere5f910a2013-10-16 18:15:46 -07002062 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002063
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002064 public void onWakeAndUnlocking() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002065 Trace.beginSection("KeyguardViewMediator#onWakeAndUnlocking");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002066 mWakeAndUnlocking = true;
Jorim Jaggi241ae102016-11-02 21:57:33 -07002067 keyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07002068 Trace.endSection();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002069 }
2070
Jason Monk2a6ea9c2017-01-26 11:14:51 -05002071 public StatusBarKeyguardViewManager registerStatusBar(StatusBar statusBar,
Lucas Dupinbc9aac12018-03-04 20:18:15 -08002072 ViewGroup container, NotificationPanelView panelView,
Selim Cinek06c12d62019-07-01 19:44:18 -07002073 BiometricUnlockController biometricUnlockController, ViewGroup lockIconContainer,
2074 View notificationContainer, KeyguardBypassController bypassController) {
Lucas Dupinbc9aac12018-03-04 20:18:15 -08002075 mStatusBarKeyguardViewManager.registerStatusBar(statusBar, container, panelView,
Selim Cinek06c12d62019-07-01 19:44:18 -07002076 biometricUnlockController, mDismissCallbackRegistry, lockIconContainer,
2077 notificationContainer, bypassController);
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002078 return mStatusBarKeyguardViewManager;
2079 }
2080
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002081 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002082 Trace.beginSection("KeyguardViewMediator#startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002083 Message msg = mHandler.obtainMessage(START_KEYGUARD_EXIT_ANIM,
2084 new StartKeyguardExitAnimParams(startTime, fadeoutDuration));
Jorim Jaggi0d674622014-05-21 01:34:15 +02002085 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07002086 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02002087 }
2088
Andrew Zengb4045d32017-03-16 17:25:07 -07002089 public void onShortPowerPressedGoHome() {
2090 // do nothing
2091 }
2092
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002093 public ViewMediatorCallback getViewMediatorCallback() {
2094 return mViewMediatorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002095 }
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002096
Xiyuan Xia1b30f792016-01-06 08:50:30 -08002097 public LockPatternUtils getLockPatternUtils() {
2098 return mLockPatternUtils;
2099 }
2100
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002101 @Override
2102 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
2103 pw.print(" mSystemReady: "); pw.println(mSystemReady);
2104 pw.print(" mBootCompleted: "); pw.println(mBootCompleted);
2105 pw.print(" mBootSendUserPresent: "); pw.println(mBootSendUserPresent);
2106 pw.print(" mExternallyEnabled: "); pw.println(mExternallyEnabled);
Adrian Roos1f8025a2016-12-27 10:12:13 -08002107 pw.print(" mShuttingDown: "); pw.println(mShuttingDown);
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002108 pw.print(" mNeedToReshowWhenReenabled: "); pw.println(mNeedToReshowWhenReenabled);
2109 pw.print(" mShowing: "); pw.println(mShowing);
2110 pw.print(" mInputRestricted: "); pw.println(mInputRestricted);
2111 pw.print(" mOccluded: "); pw.println(mOccluded);
2112 pw.print(" mDelayedShowingSequence: "); pw.println(mDelayedShowingSequence);
2113 pw.print(" mExitSecureCallback: "); pw.println(mExitSecureCallback);
2114 pw.print(" mDeviceInteractive: "); pw.println(mDeviceInteractive);
2115 pw.print(" mGoingToSleep: "); pw.println(mGoingToSleep);
2116 pw.print(" mHiding: "); pw.println(mHiding);
Lucas Dupinb3455e62019-07-11 11:47:13 +09002117 pw.print(" mDozing: "); pw.println(mDozing);
2118 pw.print(" mAodShowing: "); pw.println(mAodShowing);
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002119 pw.print(" mWaitingUntilKeyguardVisible: "); pw.println(mWaitingUntilKeyguardVisible);
2120 pw.print(" mKeyguardDonePending: "); pw.println(mKeyguardDonePending);
2121 pw.print(" mHideAnimationRun: "); pw.println(mHideAnimationRun);
2122 pw.print(" mPendingReset: "); pw.println(mPendingReset);
2123 pw.print(" mPendingLock: "); pw.println(mPendingLock);
2124 pw.print(" mWakeAndUnlocking: "); pw.println(mWakeAndUnlocking);
2125 pw.print(" mDrawnCallback: "); pw.println(mDrawnCallback);
2126 }
2127
Lucas Dupin5a4f92c2018-07-02 13:15:23 -07002128 /**
Lucas Dupinb3455e62019-07-11 11:47:13 +09002129 * @param dozing true when AOD - or ambient mode - is showing.
Lucas Dupin5a4f92c2018-07-02 13:15:23 -07002130 */
Lucas Dupinb3455e62019-07-11 11:47:13 +09002131 public void setDozing(boolean dozing) {
2132 if (dozing == mDozing) {
2133 return;
2134 }
2135 mDozing = dozing;
2136 setShowingLocked(mShowing);
Lucas Dupin47a65c72018-02-15 14:16:18 -08002137 }
2138
Lucas Dupind35502f2018-06-27 13:35:52 -07002139 /**
2140 * @param pulsing true when device temporarily wakes up to display an incoming notification.
2141 */
2142 public void setPulsing(boolean pulsing) {
2143 mPulsing = pulsing;
2144 }
2145
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002146 private static class StartKeyguardExitAnimParams {
2147
2148 long startTime;
2149 long fadeoutDuration;
2150
2151 private StartKeyguardExitAnimParams(long startTime, long fadeoutDuration) {
2152 this.startTime = startTime;
2153 this.fadeoutDuration = fadeoutDuration;
2154 }
2155 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002156
Lucas Dupinb3455e62019-07-11 11:47:13 +09002157 private void setShowingLocked(boolean showing) {
2158 setShowingLocked(showing, false /* forceCallbacks */);
Jorim Jaggie8f321e2016-11-07 16:48:31 -08002159 }
2160
Lucas Dupinb3455e62019-07-11 11:47:13 +09002161 private void setShowingLocked(boolean showing, boolean forceCallbacks) {
2162 final boolean aodShowing = mDozing && !mWakeAndUnlocking;
Lucas Dupin47a65c72018-02-15 14:16:18 -08002163 final boolean notifyDefaultDisplayCallbacks = showing != mShowing
2164 || aodShowing != mAodShowing || forceCallbacks;
Lucas Dupinb3455e62019-07-11 11:47:13 +09002165 mShowing = showing;
2166 mAodShowing = aodShowing;
wilsonshih177261f2019-02-22 12:02:18 +08002167 if (notifyDefaultDisplayCallbacks) {
Lucas Dupinb3455e62019-07-11 11:47:13 +09002168 notifyDefaultDisplayCallbacks(showing);
wilsonshih177261f2019-02-22 12:02:18 +08002169 updateActivityLockScreenState(showing, aodShowing);
David Stevens53a39ea2017-08-23 18:41:49 -07002170 }
2171 }
2172
2173 private void notifyDefaultDisplayCallbacks(boolean showing) {
2174 int size = mKeyguardStateCallbacks.size();
2175 for (int i = size - 1; i >= 0; i--) {
2176 IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
2177 try {
2178 callback.onShowingStateChanged(showing);
2179 } catch (RemoteException e) {
2180 Slog.w(TAG, "Failed to call onShowingStateChanged", e);
2181 if (e instanceof DeadObjectException) {
2182 mKeyguardStateCallbacks.remove(callback);
Jim Millerab954542014-10-10 18:21:49 -07002183 }
Jim Millerab954542014-10-10 18:21:49 -07002184 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002185 }
David Stevens53a39ea2017-08-23 18:41:49 -07002186 updateInputRestrictedLocked();
2187 mUiOffloadThread.submit(() -> {
2188 mTrustManager.reportKeyguardShowingChanged();
2189 });
Adrian Roos481a6df2014-11-20 19:48:56 +01002190 }
Jim Millerab954542014-10-10 18:21:49 -07002191
Adrian Roosd88eb262016-08-04 14:50:48 -07002192 private void notifyTrustedChangedLocked(boolean trusted) {
2193 int size = mKeyguardStateCallbacks.size();
2194 for (int i = size - 1; i >= 0; i--) {
2195 try {
2196 mKeyguardStateCallbacks.get(i).onTrustedChanged(trusted);
2197 } catch (RemoteException e) {
2198 Slog.w(TAG, "Failed to call notifyTrustedChangedLocked", e);
2199 if (e instanceof DeadObjectException) {
2200 mKeyguardStateCallbacks.remove(i);
2201 }
2202 }
2203 }
2204 }
2205
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002206 private void notifyHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
2207 int size = mKeyguardStateCallbacks.size();
2208 for (int i = size - 1; i >= 0; i--) {
2209 try {
2210 mKeyguardStateCallbacks.get(i).onHasLockscreenWallpaperChanged(
2211 hasLockscreenWallpaper);
2212 } catch (RemoteException e) {
2213 Slog.w(TAG, "Failed to call onHasLockscreenWallpaperChanged", e);
2214 if (e instanceof DeadObjectException) {
2215 mKeyguardStateCallbacks.remove(i);
2216 }
2217 }
2218 }
2219 }
2220
Jim Millerab954542014-10-10 18:21:49 -07002221 public void addStateMonitorCallback(IKeyguardStateCallback callback) {
2222 synchronized (this) {
2223 mKeyguardStateCallbacks.add(callback);
2224 try {
2225 callback.onSimSecureStateChanged(mUpdateMonitor.isSimPinSecure());
2226 callback.onShowingStateChanged(mShowing);
Adrian Roos4a963ac2015-04-24 16:04:53 -07002227 callback.onInputRestrictedStateChanged(mInputRestricted);
Adrian Roosd88eb262016-08-04 14:50:48 -07002228 callback.onTrustedChanged(mUpdateMonitor.getUserHasTrust(
2229 KeyguardUpdateMonitor.getCurrentUser()));
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002230 callback.onHasLockscreenWallpaperChanged(mUpdateMonitor.hasLockscreenWallpaper());
Jim Millerab954542014-10-10 18:21:49 -07002231 } catch (RemoteException e) {
Adrian Roosd88eb262016-08-04 14:50:48 -07002232 Slog.w(TAG, "Failed to call to IKeyguardStateCallback", e);
Jim Millerab954542014-10-10 18:21:49 -07002233 }
2234 }
2235 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08002236
2237 private static class DismissMessage {
2238 private final CharSequence mMessage;
2239 private final IKeyguardDismissCallback mCallback;
2240
2241 DismissMessage(IKeyguardDismissCallback callback, CharSequence message) {
2242 mCallback = callback;
2243 mMessage = message;
2244 }
2245
2246 public IKeyguardDismissCallback getCallback() {
2247 return mCallback;
2248 }
2249
2250 public CharSequence getMessage() {
2251 return mMessage;
2252 }
2253 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002254}