blob: 5993c396d0a10aae3beac3db289e2c6c29d7d5c9 [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;
David Stevens53a39ea2017-08-23 18:41:49 -070020import static android.view.Display.INVALID_DISPLAY;
Adrian Roose92de952016-12-13 12:07:09 -080021
22import static com.android.internal.telephony.IccCardConstants.State.ABSENT;
Jorim Jaggid11d1a92016-08-16 16:02:32 -070023import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST;
24import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW;
25import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT;
Michal Karpinskic52f8672016-11-18 11:32:45 +000026import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT;
Jorim Jaggid11d1a92016-08-16 16:02:32 -070027
Adrian Roosb60d47c2014-09-08 19:23:00 +020028import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080029import android.app.AlarmManager;
30import android.app.PendingIntent;
Mike Lockwood5f892c12009-11-19 23:39:13 -050031import android.app.StatusBarManager;
Adrian Roos481a6df2014-11-20 19:48:56 +010032import android.app.trust.TrustManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080033import android.content.BroadcastReceiver;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -050034import android.content.ContentResolver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080035import android.content.Context;
36import android.content.Intent;
37import android.content.IntentFilter;
Adrian Roosbe47b072014-09-03 00:08:56 +020038import android.content.pm.UserInfo;
Daniel Sandleraec967a2010-02-20 01:05:22 -050039import android.media.AudioManager;
Marco Nelissend5545bd2011-09-29 12:49:17 -070040import android.media.SoundPool;
Adam Cohenf7522022012-10-03 20:03:18 -070041import android.os.Bundle;
dooyoung.hwang328472e2015-05-21 16:09:43 +090042import android.os.DeadObjectException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080043import android.os.Handler;
Jeff Brown109025d2012-08-14 20:41:30 -070044import android.os.Looper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080045import android.os.Message;
46import android.os.PowerManager;
Dianne Hackborn4994c662009-09-23 22:21:23 -070047import android.os.RemoteException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080048import android.os.SystemClock;
Jim Miller1b152022009-10-28 16:08:15 -070049import android.os.SystemProperties;
Nick Desaulniers1d396752016-07-25 15:05:33 -070050import android.os.Trace;
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -070051import android.os.UserHandle;
Amith Yamasanib70ff9a2012-09-07 18:28:11 -070052import android.os.UserManager;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -050053import android.provider.Settings;
Jim Miller52a61332014-11-12 19:29:51 -080054import android.telephony.SubscriptionManager;
Karl Rosaenab100082009-03-24 22:35:17 -070055import android.telephony.TelephonyManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080056import android.util.EventLog;
Karl Rosaenab100082009-03-24 22:35:17 -070057import android.util.Log;
Jim Miller25190572013-02-28 17:36:24 -080058import android.util.Slog;
Jorim Jaggib690f0d2014-07-03 23:25:44 +020059import android.view.ViewGroup;
Adrian Roose99bc052017-11-20 17:55:31 +010060import android.view.WindowManagerPolicyConstants;
Adrian Roos0002a452014-07-03 13:46:07 +020061import android.view.animation.Animation;
62import android.view.animation.AnimationUtils;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -070063
Adrian Roos1cffe3c2016-11-28 15:46:06 -080064import com.android.internal.logging.MetricsLogger;
65import com.android.internal.logging.nano.MetricsProto;
Jorim Jaggi241ae102016-11-02 21:57:33 -070066import com.android.internal.policy.IKeyguardDismissCallback;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -070067import com.android.internal.policy.IKeyguardDrawnCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010068import com.android.internal.policy.IKeyguardExitCallback;
Jim Millerab954542014-10-10 18:21:49 -070069import com.android.internal.policy.IKeyguardStateCallback;
Adam Cohenf7522022012-10-03 20:03:18 -070070import com.android.internal.telephony.IccCardConstants;
71import com.android.internal.widget.LockPatternUtils;
Jim Miller52a61332014-11-12 19:29:51 -080072import com.android.keyguard.KeyguardConstants;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010073import com.android.keyguard.KeyguardDisplayManager;
Selim Cinek3122fa82015-06-18 01:38:59 -070074import com.android.keyguard.KeyguardSecurityView;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010075import com.android.keyguard.KeyguardUpdateMonitor;
76import com.android.keyguard.KeyguardUpdateMonitorCallback;
Jason Monkea03be12017-12-04 11:08:41 -050077import com.android.internal.util.LatencyTracker;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010078import com.android.keyguard.ViewMediatorCallback;
Jorim Jaggie549a8d2017-05-15 02:40:05 +020079import com.android.systemui.Dependency;
Jorim Jaggicff0acb2014-03-31 16:35:15 +020080import com.android.systemui.SystemUI;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080081import com.android.systemui.SystemUIFactory;
Jorim Jaggie549a8d2017-05-15 02:40:05 +020082import com.android.systemui.UiOffloadThread;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070083import com.android.systemui.classifier.FalsingManager;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070084import com.android.systemui.statusbar.phone.FingerprintUnlockController;
Lucas Dupinbc9aac12018-03-04 20:18:15 -080085import com.android.systemui.statusbar.phone.NotificationPanelView;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050086import com.android.systemui.statusbar.phone.StatusBar;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010087import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
Adrian Roos58b58fe2014-01-31 16:00:39 -080088
Jorim Jaggi84dc08a2015-09-11 17:45:22 -070089import java.io.FileDescriptor;
90import java.io.PrintWriter;
Jim Millerab954542014-10-10 18:21:49 -070091import java.util.ArrayList;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010092
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080093/**
94 * Mediates requests related to the keyguard. This includes queries about the
95 * state of the keyguard, power management events that effect whether the keyguard
96 * should be shown or reset, callbacks to the phone window manager to notify
97 * it of when the keyguard is showing, and events from the keyguard view itself
98 * stating that the keyguard was succesfully unlocked.
99 *
100 * Note that the keyguard view is shown when the screen is off (as appropriate)
101 * so that once the screen comes on, it will be ready immediately.
102 *
103 * Example queries about the keyguard:
104 * - is {movement, key} one that should wake the keygaurd?
105 * - is the keyguard showing?
106 * - are input events restricted due to the state of the keyguard?
107 *
108 * Callbacks to the phone window manager:
109 * - the keyguard is showing
110 *
111 * Example external events that translate to keyguard view changes:
112 * - screen turned off -> reset the keyguard, and show it so it will be ready
113 * next time the screen turns on
114 * - keyboard is slid open -> if the keyguard is not secure, hide it
115 *
116 * Events from the keyguard view:
117 * - user succesfully unlocked keyguard -> hide keyguard view, and no longer
118 * restrict input events.
119 *
120 * Note: in addition to normal power managment events that effect the state of
121 * whether the keyguard should be showing, external apps and services may request
122 * that the keyguard be disabled via {@link #setKeyguardEnabled(boolean)}. When
123 * false, this will override all other conditions for turning on the keyguard.
124 *
125 * Threading and synchronization:
Adrian Roose99bc052017-11-20 17:55:31 +0100126 * This class is created by the initialization routine of the {@link WindowManagerPolicyConstants},
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800127 * and runs on its thread. The keyguard UI is created from that thread in the
128 * constructor of this class. The apis may be called from other threads, including the
Jeff Brown4532e612012-04-05 14:27:12 -0700129 * {@link com.android.server.input.InputManagerService}'s and {@link android.view.WindowManager}'s.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800130 * Therefore, methods on this class are synchronized, and any action that is pointed
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100131 * 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 -0800132 * thread of the keyguard.
133 */
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200134public class KeyguardViewMediator extends SystemUI {
Jim Millerbc4603b2010-08-30 21:21:34 -0700135 private static final int KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT = 30000;
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100136 private static final long KEYGUARD_DONE_PENDING_TIMEOUT_MS = 3000;
137
Jim Miller52a61332014-11-12 19:29:51 -0800138 private static final boolean DEBUG = KeyguardConstants.DEBUG;
139 private static final boolean DEBUG_SIM_STATES = KeyguardConstants.DEBUG_SIM_STATES;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800140
141 private final static String TAG = "KeyguardViewMediator";
142
Jim Miller9c20d0e2010-01-20 15:00:23 -0800143 private static final String DELAYED_KEYGUARD_ACTION =
Wink Saville37c124c2009-04-02 01:37:02 -0700144 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD";
Clara Bayarri56878a92015-10-29 15:43:55 +0000145 private static final String DELAYED_LOCK_PROFILE_ACTION =
146 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_LOCK";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800147
Kevin Chyn18e91aa2018-04-11 12:55:45 -0700148 private static final String SYSTEMUI_PERMISSION = "com.android.systemui.permission.SELF";
149
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800150 // used for handler messages
Jorim Jaggi8d786932016-10-26 19:08:36 -0700151 private static final int SHOW = 1;
152 private static final int HIDE = 2;
153 private static final int RESET = 3;
154 private static final int VERIFY_UNLOCK = 4;
155 private static final int NOTIFY_FINISHED_GOING_TO_SLEEP = 5;
156 private static final int NOTIFY_SCREEN_TURNING_ON = 6;
157 private static final int KEYGUARD_DONE = 7;
158 private static final int KEYGUARD_DONE_DRAWING = 8;
159 private static final int SET_OCCLUDED = 9;
160 private static final int KEYGUARD_TIMEOUT = 10;
161 private static final int DISMISS = 11;
162 private static final int START_KEYGUARD_EXIT_ANIM = 12;
163 private static final int KEYGUARD_DONE_PENDING_TIMEOUT = 13;
164 private static final int NOTIFY_STARTED_WAKING_UP = 14;
165 private static final int NOTIFY_SCREEN_TURNED_ON = 15;
166 private static final int NOTIFY_SCREEN_TURNED_OFF = 16;
167 private static final int NOTIFY_STARTED_GOING_TO_SLEEP = 17;
Jim Miller9c20d0e2010-01-20 15:00:23 -0800168
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800169 /**
170 * The default amount of time we stay awake (used for all key input)
171 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100172 public static final int AWAKE_INTERVAL_DEFAULT_MS = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800173
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800174 /**
175 * How long to wait after the screen turns off due to timeout before
176 * turning on the keyguard (i.e, the user has this much time to turn
177 * the screen back on without having to face the keyguard).
178 */
Jim Millerbc4603b2010-08-30 21:21:34 -0700179 private static final int KEYGUARD_LOCK_AFTER_DELAY_DEFAULT = 5000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800180
181 /**
Craig Mautnerf1b67412012-09-19 13:18:29 -0700182 * How long we'll wait for the {@link ViewMediatorCallback#keyguardDoneDrawing()}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800183 * callback before unblocking a call to {@link #setKeyguardEnabled(boolean)}
184 * that is reenabling the keyguard.
185 */
186 private static final int KEYGUARD_DONE_DRAWING_TIMEOUT_MS = 2000;
Jim Miller9c20d0e2010-01-20 15:00:23 -0800187
Daniel Sandler74d188c2011-08-10 00:00:31 -0400188 /**
Evan Rosky13a58a92016-07-27 15:51:09 -0700189 * Boolean option for doKeyguardLocked/doKeyguardTimeout which, when set to true, forces the
190 * keyguard to show even if it is disabled for the current user.
191 */
192 public static final String OPTION_FORCE_SHOW = "force_show";
193
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700194 /** The stream type that the lock sounds are tied to. */
John Spurlockee5ad722015-03-03 16:17:21 -0500195 private int mUiSoundsStreamType;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700196
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800197 private AlarmManager mAlarmManager;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700198 private AudioManager mAudioManager;
Mike Lockwood5f892c12009-11-19 23:39:13 -0500199 private StatusBarManager mStatusBarManager;
Jorim Jaggie549a8d2017-05-15 02:40:05 +0200200 private final UiOffloadThread mUiOffloadThread = Dependency.get(UiOffloadThread.class);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800201
202 private boolean mSystemReady;
Jason Monkcf5a9532014-09-17 16:22:19 -0400203 private boolean mBootCompleted;
204 private boolean mBootSendUserPresent;
Adrian Roos1f8025a2016-12-27 10:12:13 -0800205 private boolean mShuttingDown;
Daniel Sandler0060a9b2010-03-15 23:09:57 -0400206
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800207 /** High level access to the power manager for WakeLocks */
208 private PowerManager mPM;
209
Adrian Roos481a6df2014-11-20 19:48:56 +0100210 /** TrustManager for letting it know when we change visibility */
211 private TrustManager mTrustManager;
Amith Yamasanib70ff9a2012-09-07 18:28:11 -0700212
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800213 /**
Mike Lockwood674d3e42009-10-06 09:28:54 -0400214 * Used to keep the device awake while to ensure the keyguard finishes opening before
215 * we sleep.
216 */
217 private PowerManager.WakeLock mShowKeyguardWakeLock;
218
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100219 private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800220
221 // these are protected by synchronized (this)
222
223 /**
Mike Lockwood5d258b62009-12-02 13:50:45 -0500224 * External apps (like the phone app) can tell us to disable the keygaurd.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800225 */
226 private boolean mExternallyEnabled = true;
227
228 /**
229 * Remember if an external call to {@link #setKeyguardEnabled} with value
230 * false caused us to hide the keyguard, so that we need to reshow it once
231 * the keygaurd is reenabled with another call with value true.
232 */
233 private boolean mNeedToReshowWhenReenabled = false;
234
235 // cached value of whether we are showing (need to know this to quickly
236 // answer whether the input should be restricted)
Jim Millere5f17ab2013-11-13 15:40:48 -0800237 private boolean mShowing;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800238
Lucas Dupin47a65c72018-02-15 14:16:18 -0800239 // AOD is enabled and status bar is in AOD state.
240 private boolean mAodShowing;
241
David Stevens53a39ea2017-08-23 18:41:49 -0700242 // display id of the secondary display on which we have put a keyguard window
243 private int mSecondaryDisplayShowing = INVALID_DISPLAY;
244
Jim Millerab954542014-10-10 18:21:49 -0700245 /** Cached value of #isInputRestricted */
246 private boolean mInputRestricted;
247
Mike Lockwood09a40402009-11-08 00:33:23 -0500248 // true if the keyguard is hidden by another window
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100249 private boolean mOccluded = false;
Mike Lockwood09a40402009-11-08 00:33:23 -0500250
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800251 /**
252 * Helps remember whether the screen has turned on since the last time
253 * it turned off due to timeout. see {@link #onScreenTurnedOff(int)}
254 */
255 private int mDelayedShowingSequence;
256
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800257 /**
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000258 * Simiar to {@link #mDelayedProfileShowingSequence}, but it is for profile case.
259 */
260 private int mDelayedProfileShowingSequence;
261
262 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800263 * If the user has disabled the keyguard, then requests to exit, this is
264 * how we'll ultimately let them know whether it was successful. We use this
265 * var being non-null as an indicator that there is an in progress request.
266 */
Jim Miller25190572013-02-28 17:36:24 -0800267 private IKeyguardExitCallback mExitSecureCallback;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700268 private final DismissCallbackRegistry mDismissCallbackRegistry = new DismissCallbackRegistry();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800269
270 // the properties of the keyguard
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800271
272 private KeyguardUpdateMonitor mUpdateMonitor;
273
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700274 private boolean mDeviceInteractive;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700275 private boolean mGoingToSleep;
Karl Rosaenab100082009-03-24 22:35:17 -0700276
Daniel Sandlerf2d8e742010-02-22 13:09:48 -0500277 // last known state of the cellular connection
278 private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE;
279
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800280 /**
Jorim Jaggi53c68a42014-06-17 15:04:47 -0700281 * Whether a hide is pending an we are just waiting for #startKeyguardExitAnimation to be
282 * called.
283 * */
284 private boolean mHiding;
285
286 /**
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700287 * we send this intent when the keyguard is dismissed.
288 */
Jim Miller17f509a2013-02-28 18:36:12 -0800289 private static final Intent USER_PRESENT_INTENT = new Intent(Intent.ACTION_USER_PRESENT)
290 .addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
Chad Brubaker291df4f2017-03-14 10:23:02 -0700291 | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
292 | Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700293
294 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800295 * {@link #setKeyguardEnabled} waits on this condition when it reenables
296 * the keyguard.
297 */
298 private boolean mWaitingUntilKeyguardVisible = false;
Jim Millerbc4603b2010-08-30 21:21:34 -0700299 private LockPatternUtils mLockPatternUtils;
John Spurlock34c4fe52012-11-07 10:12:29 -0500300 private boolean mKeyguardDonePending = false;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200301 private boolean mHideAnimationRun = false;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700302 private boolean mHideAnimationRunning = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800303
Marco Nelissend5545bd2011-09-29 12:49:17 -0700304 private SoundPool mLockSounds;
305 private int mLockSoundId;
306 private int mUnlockSoundId;
Adrian Roos49e057d2014-08-13 17:14:51 +0200307 private int mTrustedSoundId;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700308 private int mLockSoundStreamId;
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700309
310 /**
Adrian Roos0002a452014-07-03 13:46:07 +0200311 * The animation used for hiding keyguard. This is used to fetch the animation timings if
312 * WindowManager is not providing us with them.
313 */
314 private Animation mHideAnimation;
315
316 /**
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700317 * The volume applied to the lock/unlock sounds.
318 */
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200319 private float mLockSoundVolume;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700320
Jim Millerdcb3d842012-08-23 19:18:12 -0700321 /**
Jim Miller31921482013-11-06 20:43:55 -0800322 * For managing external displays
323 */
324 private KeyguardDisplayManager mKeyguardDisplayManager;
325
Jim Millerab954542014-10-10 18:21:49 -0700326 private final ArrayList<IKeyguardStateCallback> mKeyguardStateCallbacks = new ArrayList<>();
327
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700328 /**
329 * When starting going to sleep, we figured out that we need to reset Keyguard state and this
330 * should be committed when finished going to sleep.
331 */
332 private boolean mPendingReset;
333
334 /**
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700335 * 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 -0700336 * committed when finished going to sleep.
337 */
338 private boolean mPendingLock;
339
Robin Leec41f6ec2017-01-10 17:02:34 +0000340 /**
341 * Controller for showing individual "work challenge" lock screen windows inside managed profile
342 * tasks when the current user has been unlocked but the profile is still locked.
343 */
344 private WorkLockActivityController mWorkLockController;
345
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000346 private boolean mLockLater;
347
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700348 private boolean mWakeAndUnlocking;
349 private IKeyguardDrawnCallback mDrawnCallback;
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800350 private boolean mLockWhenSimRemoved;
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800351 private CharSequence mCustomMessage;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700352
Jim Millerbbf1a742012-07-17 18:30:30 -0700353 KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {
354
355 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500356 public void onUserSwitching(int userId) {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700357 // Note that the mLockPatternUtils user has already been updated from setCurrentUser.
Adam Cohenf7522022012-10-03 20:03:18 -0700358 // We need to force a reset of the views, since lockNow (called by
359 // ActivityManagerService) will not reconstruct the keyguard if it is already showing.
Jim Millerbbf1a742012-07-17 18:30:30 -0700360 synchronized (KeyguardViewMediator.this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100361 resetKeyguardDonePendingLocked();
Alex Chau77ef9fc2018-04-11 15:41:32 +0100362 if (mLockPatternUtils.isLockScreenDisabled(userId)) {
363 // If we switching to a user that has keyguard disabled, dismiss keyguard.
364 dismiss(null /* callback */, null /* message */);
365 } else {
366 resetStateLocked();
367 }
John Spurlock4e6922d2012-10-04 14:51:51 -0400368 adjustStatusBarLocked();
Dianne Hackborn5dc5a002012-09-15 19:33:48 -0700369 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700370 }
371
372 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500373 public void onUserSwitchComplete(int userId) {
Xiaohui Chen87d0e252015-07-30 15:38:16 -0700374 if (userId != UserHandle.USER_SYSTEM) {
Adrian Roosbe47b072014-09-03 00:08:56 +0200375 UserInfo info = UserManager.get(mContext).getUserInfo(userId);
Kevin Chynf2c0a642017-05-25 11:29:08 -0700376 // Don't try to dismiss if the user has Pin/Patter/Password set
377 if (info == null || mLockPatternUtils.isSecure(userId)) {
378 return;
379 } else if (info.isGuest() || info.isDemo()) {
Adrian Roosbe47b072014-09-03 00:08:56 +0200380 // If we just switched to a guest, try to dismiss keyguard.
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800381 dismiss(null /* callback */, null /* message */);
Adrian Roosbe47b072014-09-03 00:08:56 +0200382 }
383 }
Chris Wrenf41c61b2012-11-29 15:19:54 -0500384 }
385
386 @Override
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -0700387 public void onUserInfoChanged(int userId) {
Jim Millerbbf1a742012-07-17 18:30:30 -0700388 }
389
390 @Override
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100391 public void onPhoneStateChanged(int phoneState) {
Jim Millerbbf1a742012-07-17 18:30:30 -0700392 synchronized (KeyguardViewMediator.this) {
393 if (TelephonyManager.CALL_STATE_IDLE == phoneState // call ending
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700394 && !mDeviceInteractive // screen off
Jim Millerbbf1a742012-07-17 18:30:30 -0700395 && mExternallyEnabled) { // not disabled by any app
396
397 // note: this is a way to gracefully reenable the keyguard when the call
398 // ends and the screen is off without always reenabling the keyguard
399 // each time the screen turns off while in call (and having an occasional ugly
400 // flicker while turning back on the screen and disabling the keyguard again).
401 if (DEBUG) Log.d(TAG, "screen is off and call ended, let's make sure the "
402 + "keyguard is showing");
Jim Miller5ecd8112013-01-09 18:50:26 -0800403 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700404 }
405 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100406 }
Jim Millerb0304762012-03-13 20:01:25 -0700407
408 @Override
409 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
Jim Millerbbf1a742012-07-17 18:30:30 -0700445 switch (simState) {
446 case NOT_READY:
447 case ABSENT:
448 // only force lock screen in case of missing sim if user hasn't
449 // gone through setup wizard
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800450 synchronized (KeyguardViewMediator.this) {
Jim Millerb256e4e22014-10-31 17:27:13 -0700451 if (shouldWaitForProvisioning()) {
Jim Millerab954542014-10-10 18:21:49 -0700452 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800453 if (DEBUG_SIM_STATES) Log.d(TAG, "ICC_ABSENT isn't showing,"
Jim Millerbbf1a742012-07-17 18:30:30 -0700454 + " we need to show the keyguard since the "
455 + "device isn't provisioned yet.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800456 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700457 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100458 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700459 }
460 }
Adrian Roose92de952016-12-13 12:07:09 -0800461 if (simState == ABSENT) {
462 // MVNO SIMs can become transiently NOT_READY when switching networks,
463 // so we should only lock when they are ABSENT.
464 onSimAbsentLocked();
465 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700466 }
467 break;
468 case PIN_REQUIRED:
469 case PUK_REQUIRED:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800470 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700471 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800472 if (DEBUG_SIM_STATES) Log.d(TAG,
473 "INTENT_VALUE_ICC_LOCKED and keygaurd isn't "
Jim Millerbbf1a742012-07-17 18:30:30 -0700474 + "showing; need to show keyguard so user can enter sim pin");
Jim Miller5ecd8112013-01-09 18:50:26 -0800475 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700476 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100477 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700478 }
479 }
480 break;
481 case PERM_DISABLED:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800482 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700483 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800484 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED and "
Jim Millerbbf1a742012-07-17 18:30:30 -0700485 + "keygaurd isn't showing.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800486 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700487 } else {
Jim Miller52a61332014-11-12 19:29:51 -0800488 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED, resetStateLocked to"
Jim Millerbbf1a742012-07-17 18:30:30 -0700489 + "show permanently disabled message in lockscreen.");
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100490 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700491 }
Adrian Roose92de952016-12-13 12:07:09 -0800492 onSimAbsentLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700493 }
494 break;
495 case READY:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800496 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700497 if (mShowing) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100498 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700499 }
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800500 mLockWhenSimRemoved = true;
Jim Millerbbf1a742012-07-17 18:30:30 -0700501 }
502 break;
Jim Miller52a61332014-11-12 19:29:51 -0800503 default:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800504 if (DEBUG_SIM_STATES) Log.v(TAG, "Unspecific state: " + simState);
505 synchronized (KeyguardViewMediator.this) {
Adrian Roose92de952016-12-13 12:07:09 -0800506 onSimAbsentLocked();
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800507 }
Jim Miller52a61332014-11-12 19:29:51 -0800508 break;
Jim Millerbbf1a742012-07-17 18:30:30 -0700509 }
510 }
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000511
Adrian Roose92de952016-12-13 12:07:09 -0800512 private void onSimAbsentLocked() {
Adrian Roos1f8025a2016-12-27 10:12:13 -0800513 if (isSecure() && mLockWhenSimRemoved && !mShuttingDown) {
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800514 mLockWhenSimRemoved = false;
515 MetricsLogger.action(mContext,
516 MetricsProto.MetricsEvent.ACTION_LOCK_BECAUSE_SIM_REMOVED, mShowing);
517 if (!mShowing) {
Adrian Roose92de952016-12-13 12:07:09 -0800518 Log.i(TAG, "SIM removed, showing keyguard");
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800519 doKeyguardLocked(null);
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800520 }
521 }
522 }
523
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000524 @Override
525 public void onFingerprintAuthFailed() {
526 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
527 if (mLockPatternUtils.isSecure(currentUser)) {
528 mLockPatternUtils.getDevicePolicyManager().reportFailedFingerprintAttempt(
529 currentUser);
530 }
531 }
532
533 @Override
534 public void onFingerprintAuthenticated(int userId) {
535 if (mLockPatternUtils.isSecure(userId)) {
536 mLockPatternUtils.getDevicePolicyManager().reportSuccessfulFingerprintAttempt(
537 userId);
538 }
539 }
Adrian Roosd88eb262016-08-04 14:50:48 -0700540
541 @Override
542 public void onTrustChanged(int userId) {
543 if (userId == KeyguardUpdateMonitor.getCurrentUser()) {
544 synchronized (KeyguardViewMediator.this) {
545 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(userId));
546 }
547 }
548 }
549
Jorim Jaggid11d1a92016-08-16 16:02:32 -0700550 @Override
551 public void onHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
552 synchronized (KeyguardViewMediator.this) {
553 notifyHasLockscreenWallpaperChanged(hasLockscreenWallpaper);
554 }
555 }
Jim Millerb0304762012-03-13 20:01:25 -0700556 };
557
Jim Millerdcb3d842012-08-23 19:18:12 -0700558 ViewMediatorCallback mViewMediatorCallback = new ViewMediatorCallback() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100559
Jim Miller2967f482016-01-07 15:05:32 -0800560 @Override
Jeff Brownc7505bc2012-10-05 21:58:15 -0700561 public void userActivity() {
562 KeyguardViewMediator.this.userActivity();
563 }
564
Jim Miller2967f482016-01-07 15:05:32 -0800565 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700566 public void keyguardDone(boolean strongAuth, int targetUserId) {
567 if (targetUserId != ActivityManager.getCurrentUser()) {
568 return;
569 }
570
Jorim Jaggi241ae102016-11-02 21:57:33 -0700571 tryKeyguardDone();
Jim Millerdcb3d842012-08-23 19:18:12 -0700572 }
573
Jim Miller2967f482016-01-07 15:05:32 -0800574 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700575 public void keyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700576 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDoneDrawing");
Jim Millerdcb3d842012-08-23 19:18:12 -0700577 mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700578 Trace.endSection();
Jim Millerdcb3d842012-08-23 19:18:12 -0700579 }
580
581 @Override
582 public void setNeedsInput(boolean needsInput) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100583 mStatusBarKeyguardViewManager.setNeedsInput(needsInput);
Jim Millerdcb3d842012-08-23 19:18:12 -0700584 }
Jeff Brownc7505bc2012-10-05 21:58:15 -0700585
586 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700587 public void keyguardDonePending(boolean strongAuth, int targetUserId) {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700588 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDonePending");
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700589 if (targetUserId != ActivityManager.getCurrentUser()) {
Nick Desaulniersaeb2e1e2016-07-27 15:36:01 -0700590 Trace.endSection();
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700591 return;
592 }
593
John Spurlock34c4fe52012-11-07 10:12:29 -0500594 mKeyguardDonePending = true;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200595 mHideAnimationRun = true;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700596 mHideAnimationRunning = true;
597 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100598 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_PENDING_TIMEOUT,
599 KEYGUARD_DONE_PENDING_TIMEOUT_MS);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700600 Trace.endSection();
John Spurlock34c4fe52012-11-07 10:12:29 -0500601 }
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800602
603 @Override
604 public void keyguardGone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700605 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardGone");
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800606 mKeyguardDisplayManager.hide();
Nick Desaulniers1d396752016-07-25 15:05:33 -0700607 Trace.endSection();
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800608 }
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200609
610 @Override
611 public void readyForKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700612 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#readyForKeyguardDone");
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200613 if (mKeyguardDonePending) {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700614 mKeyguardDonePending = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700615 tryKeyguardDone();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200616 }
Nick Desaulniers1d396752016-07-25 15:05:33 -0700617 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200618 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200619
620 @Override
Andrew Lee72b46d42015-01-30 13:23:21 -0800621 public void resetKeyguard() {
622 resetStateLocked();
623 }
624
625 @Override
Matthew Ng66f0b702017-12-08 12:58:42 -0800626 public void onBouncerVisiblityChanged(boolean shown) {
627 synchronized (KeyguardViewMediator.this) {
628 adjustStatusBarLocked(shown);
629 }
630 }
631
632 @Override
Adrian Roos49e057d2014-08-13 17:14:51 +0200633 public void playTrustedSound() {
634 KeyguardViewMediator.this.playTrustedSound();
635 }
Jim Millerab954542014-10-10 18:21:49 -0700636
637 @Override
Adrian Roos94e15a52015-04-16 12:23:18 -0700638 public boolean isScreenOn() {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700639 return mDeviceInteractive;
Adrian Roos94e15a52015-04-16 12:23:18 -0700640 }
Selim Cinek3122fa82015-06-18 01:38:59 -0700641
642 @Override
643 public int getBouncerPromptReason() {
644 int currentUser = ActivityManager.getCurrentUser();
Adrian Roosc13723f2016-01-12 20:29:03 +0100645 boolean trust = mTrustManager.isTrustUsuallyManaged(currentUser);
646 boolean fingerprint = mUpdateMonitor.isUnlockWithFingerprintPossible(currentUser);
647 boolean any = trust || fingerprint;
648 KeyguardUpdateMonitor.StrongAuthTracker strongAuthTracker =
649 mUpdateMonitor.getStrongAuthTracker();
650 int strongAuth = strongAuthTracker.getStrongAuthForUser(currentUser);
651
652 if (any && !strongAuthTracker.hasUserAuthenticatedSinceBoot()) {
Selim Cinek3122fa82015-06-18 01:38:59 -0700653 return KeyguardSecurityView.PROMPT_REASON_RESTART;
Michal Karpinskic52f8672016-11-18 11:32:45 +0000654 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_TIMEOUT) != 0) {
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700655 return KeyguardSecurityView.PROMPT_REASON_TIMEOUT;
Adrian Roosc13723f2016-01-12 20:29:03 +0100656 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW) != 0) {
657 return KeyguardSecurityView.PROMPT_REASON_DEVICE_ADMIN;
658 } else if (trust && (strongAuth & SOME_AUTH_REQUIRED_AFTER_USER_REQUEST) != 0) {
659 return KeyguardSecurityView.PROMPT_REASON_USER_REQUEST;
660 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_LOCKOUT) != 0) {
661 return KeyguardSecurityView.PROMPT_REASON_AFTER_LOCKOUT;
Selim Cinek3122fa82015-06-18 01:38:59 -0700662 }
663 return KeyguardSecurityView.PROMPT_REASON_NONE;
664 }
David Stevens53a39ea2017-08-23 18:41:49 -0700665
666 @Override
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800667 public CharSequence consumeCustomMessage() {
668 final CharSequence message = mCustomMessage;
669 mCustomMessage = null;
670 return message;
671 }
672
673 @Override
David Stevens53a39ea2017-08-23 18:41:49 -0700674 public void onSecondaryDisplayShowingChanged(int displayId) {
675 synchronized (KeyguardViewMediator.this) {
Lucas Dupin47a65c72018-02-15 14:16:18 -0800676 setShowingLocked(mShowing, mAodShowing, displayId, false);
David Stevens53a39ea2017-08-23 18:41:49 -0700677 }
678 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700679 };
680
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200681 public void userActivity() {
Jeff Brown3dc524b2012-09-30 19:49:11 -0700682 mPM.userActivity(SystemClock.uptimeMillis(), false);
Jim Millerdcb3d842012-08-23 19:18:12 -0700683 }
684
Amith Yamasanieb437d42016-04-29 09:31:25 -0700685 boolean mustNotUnlockCurrentUser() {
Christine Franks338c6ed2017-08-08 09:39:16 -0700686 return UserManager.isSplitSystemUser()
Amith Yamasanieb437d42016-04-29 09:31:25 -0700687 && KeyguardUpdateMonitor.getCurrentUser() == UserHandle.USER_SYSTEM;
688 }
689
Jim Millerab954542014-10-10 18:21:49 -0700690 private void setupLocked() {
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200691 mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
Adrian Roos481a6df2014-11-20 19:48:56 +0100692 mTrustManager = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE);
693
Mike Lockwood674d3e42009-10-06 09:28:54 -0400694 mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
695 mShowKeyguardWakeLock.setReferenceCounted(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800696
Adrian Roos1f8025a2016-12-27 10:12:13 -0800697 IntentFilter filter = new IntentFilter();
Adrian Roos1f8025a2016-12-27 10:12:13 -0800698 filter.addAction(Intent.ACTION_SHUTDOWN);
699 mContext.registerReceiver(mBroadcastReceiver, filter);
Jim Millerbbf1a742012-07-17 18:30:30 -0700700
Kevin Chyn18e91aa2018-04-11 12:55:45 -0700701 final IntentFilter delayedActionFilter = new IntentFilter();
702 delayedActionFilter.addAction(DELAYED_KEYGUARD_ACTION);
703 delayedActionFilter.addAction(DELAYED_LOCK_PROFILE_ACTION);
704 mContext.registerReceiver(mDelayedLockBroadcastReceiver, delayedActionFilter,
705 SYSTEMUI_PERMISSION, null /* scheduler */);
706
David Stevens53a39ea2017-08-23 18:41:49 -0700707 mKeyguardDisplayManager = new KeyguardDisplayManager(mContext, mViewMediatorCallback);
Jim Miller31921482013-11-06 20:43:55 -0800708
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200709 mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800710
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200711 mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800712
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200713 mLockPatternUtils = new LockPatternUtils(mContext);
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700714 KeyguardUpdateMonitor.setCurrentUser(ActivityManager.getCurrentUser());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800715
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200716 // Assume keyguard is showing (unless it's disabled) until we know for sure, unless Keyguard
717 // is disabled.
718 if (mContext.getResources().getBoolean(
719 com.android.keyguard.R.bool.config_enableKeyguardService)) {
720 setShowingLocked(!shouldWaitForProvisioning()
721 && !mLockPatternUtils.isLockScreenDisabled(
David Stevens53a39ea2017-08-23 18:41:49 -0700722 KeyguardUpdateMonitor.getCurrentUser()),
Lucas Dupin47a65c72018-02-15 14:16:18 -0800723 mAodShowing, mSecondaryDisplayShowing, true /* forceCallbacks */);
Leif Hendrik Wildenc6dc1c92018-02-01 10:54:15 -0800724 } else {
725 // The system's keyguard is disabled or missing.
Lucas Dupin47a65c72018-02-15 14:16:18 -0800726 setShowingLocked(false, mAodShowing, mSecondaryDisplayShowing, true);
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200727 }
Jim Millere5f17ab2013-11-13 15:40:48 -0800728
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800729 mStatusBarKeyguardViewManager =
730 SystemUIFactory.getInstance().createStatusBarKeyguardViewManager(mContext,
731 mViewMediatorCallback, mLockPatternUtils);
Daniel Sandler687a3272010-03-13 15:44:47 -0500732 final ContentResolver cr = mContext.getContentResolver();
Marco Nelissend5545bd2011-09-29 12:49:17 -0700733
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700734 mDeviceInteractive = mPM.isInteractive();
Daniel Hansson4b716862012-03-29 11:02:05 +0200735
Marco Nelissend5545bd2011-09-29 12:49:17 -0700736 mLockSounds = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
Jim Millerb14288d2012-09-30 18:25:05 -0700737 String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700738 if (soundPath != null) {
739 mLockSoundId = mLockSounds.load(soundPath, 1);
740 }
741 if (soundPath == null || mLockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700742 Log.w(TAG, "failed to load lock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700743 }
Jim Millerb14288d2012-09-30 18:25:05 -0700744 soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700745 if (soundPath != null) {
746 mUnlockSoundId = mLockSounds.load(soundPath, 1);
747 }
748 if (soundPath == null || mUnlockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700749 Log.w(TAG, "failed to load unlock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700750 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200751 soundPath = Settings.Global.getString(cr, Settings.Global.TRUSTED_SOUND);
752 if (soundPath != null) {
753 mTrustedSoundId = mLockSounds.load(soundPath, 1);
754 }
755 if (soundPath == null || mTrustedSoundId == 0) {
756 Log.w(TAG, "failed to load trusted sound from " + soundPath);
757 }
758
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200759 int lockSoundDefaultAttenuation = mContext.getResources().getInteger(
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700760 com.android.internal.R.integer.config_lockSoundVolumeDb);
Jean-Michel Trivif2b0c112012-07-09 11:59:11 -0700761 mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20);
Adrian Roos0002a452014-07-03 13:46:07 +0200762
763 mHideAnimation = AnimationUtils.loadAnimation(mContext,
764 com.android.internal.R.anim.lock_screen_behind_enter);
Robin Leec41f6ec2017-01-10 17:02:34 +0000765
766 mWorkLockController = new WorkLockActivityController(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800767 }
768
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200769 @Override
770 public void start() {
Jim Millerab954542014-10-10 18:21:49 -0700771 synchronized (this) {
772 setupLocked();
773 }
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200774 putComponent(KeyguardViewMediator.class, this);
775 }
776
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800777 /**
778 * Let us know that the system is ready after startup.
779 */
780 public void onSystemReady() {
781 synchronized (this) {
782 if (DEBUG) Log.d(TAG, "onSystemReady");
783 mSystemReady = true;
Jim Miller5ecd8112013-01-09 18:50:26 -0800784 doKeyguardLocked(null);
Selim Cinekedd32b82015-06-23 22:05:58 -0400785 mUpdateMonitor.registerCallback(mUpdateCallback);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800786 }
Jim Miller3fd47af2012-09-21 19:55:27 -0700787 // Most services aren't available until the system reaches the ready state, so we
788 // send it here when the device first boots.
789 maybeSendUserPresentBroadcast();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800790 }
791
792 /**
793 * Called to let us know the screen was turned off.
Adrian Roose99bc052017-11-20 17:55:31 +0100794 * @param why either {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_USER} or
795 * {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_TIMEOUT}.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800796 */
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700797 public void onStartedGoingToSleep(int why) {
798 if (DEBUG) Log.d(TAG, "onStartedGoingToSleep(" + why + ")");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800799 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700800 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700801 mGoingToSleep = true;
John Spurlock14adfe42012-11-08 10:29:26 -0500802
Jim Millera4edd152012-01-06 18:24:04 -0800803 // Lock immediately based on setting if secure (user has a pin/pattern/password).
804 // This also "locks" the device when not secure to provide easy access to the
805 // camera while preventing unwanted input.
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700806 int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jim Millera4edd152012-01-06 18:24:04 -0800807 final boolean lockImmediately =
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700808 mLockPatternUtils.getPowerButtonInstantlyLocks(currentUser)
809 || !mLockPatternUtils.isSecure(currentUser);
Clara Bayarri56878a92015-10-29 15:43:55 +0000810 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000811 mLockLater = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800812 if (mExitSecureCallback != null) {
813 if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled");
Jim Miller5ecd8112013-01-09 18:50:26 -0800814 try {
815 mExitSecureCallback.onKeyguardExitResult(false);
816 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800817 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800818 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800819 mExitSecureCallback = null;
820 if (!mExternallyEnabled) {
Jim Miller9c20d0e2010-01-20 15:00:23 -0800821 hideLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800822 }
823 } else if (mShowing) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700824 mPendingReset = true;
Adrian Roose99bc052017-11-20 17:55:31 +0100825 } else if ((why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_TIMEOUT && timeout > 0)
826 || (why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER && !lockImmediately)) {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700827 doKeyguardLaterLocked(timeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000828 mLockLater = true;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700829 } else if (!mLockPatternUtils.isLockScreenDisabled(currentUser)) {
830 mPendingLock = true;
831 }
832
Jorim Jaggi853cbe32015-06-04 16:31:54 -0700833 if (mPendingLock) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700834 playSounds(true);
835 }
836 }
Jorim Jaggi95e40382015-09-16 15:53:42 -0700837 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedGoingToSleep(why);
Jorim Jaggi18f18ae2015-09-10 15:48:21 -0700838 notifyStartedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700839 }
840
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700841 public void onFinishedGoingToSleep(int why, boolean cameraGestureTriggered) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700842 if (DEBUG) Log.d(TAG, "onFinishedGoingToSleep(" + why + ")");
843 synchronized (this) {
844 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700845 mGoingToSleep = false;
Adrian Roose4cb6c8a2017-07-19 18:08:07 +0200846 mWakeAndUnlocking = false;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700847
848 resetKeyguardDonePendingLocked();
849 mHideAnimationRun = false;
850
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700851 notifyFinishedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700852
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700853 if (cameraGestureTriggered) {
854 Log.i(TAG, "Camera gesture was triggered, preventing Keyguard locking.");
855
856 // Just to make sure, make sure the device is awake.
857 mContext.getSystemService(PowerManager.class).wakeUp(SystemClock.uptimeMillis(),
858 "com.android.systemui:CAMERA_GESTURE_PREVENT_LOCK");
859 mPendingLock = false;
860 mPendingReset = false;
861 }
862
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700863 if (mPendingReset) {
864 resetStateLocked();
865 mPendingReset = false;
866 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000867
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700868 if (mPendingLock) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800869 doKeyguardLocked(null);
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700870 mPendingLock = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800871 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000872
873 // We do not have timeout and power button instant lock setting for profile lock.
874 // So we use the personal setting if there is any. But if there is no device
875 // we need to make sure we lock it immediately when the screen is off.
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700876 if (!mLockLater && !cameraGestureTriggered) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000877 doKeyguardForChildProfilesLocked();
878 }
879
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800880 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700881 KeyguardUpdateMonitor.getInstance(mContext).dispatchFinishedGoingToSleep(why);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800882 }
883
Clara Bayarri56878a92015-10-29 15:43:55 +0000884 private long getLockTimeout(int userId) {
Jeff Brown6aaf2952012-10-05 16:01:08 -0700885 // if the screen turned off because of timeout or the user hit the power button
886 // and we don't need to lock immediately, set an alarm
887 // to enable it a little bit later (i.e, give the user a chance
888 // to turn the screen back on within a certain window without
889 // having to unlock the screen)
890 final ContentResolver cr = mContext.getContentResolver();
891
Jeff Brown6aaf2952012-10-05 16:01:08 -0700892 // From SecuritySettings
893 final long lockAfterTimeout = Settings.Secure.getInt(cr,
894 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT,
895 KEYGUARD_LOCK_AFTER_DELAY_DEFAULT);
896
897 // From DevicePolicyAdmin
898 final long policyTimeout = mLockPatternUtils.getDevicePolicyManager()
Pavel Grafov28939982017-10-03 15:11:52 +0100899 .getMaximumTimeToLock(null, userId);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700900
901 long timeout;
Clara Bayarri56878a92015-10-29 15:43:55 +0000902
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000903 if (policyTimeout <= 0) {
Clara Bayarri56878a92015-10-29 15:43:55 +0000904 timeout = lockAfterTimeout;
905 } else {
906 // From DisplaySettings
907 long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT,
908 KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT);
909
Jeff Brown6aaf2952012-10-05 16:01:08 -0700910 // policy in effect. Make sure we don't go beyond policy limit.
911 displayTimeout = Math.max(displayTimeout, 0); // ignore negative values
912 timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000913 timeout = Math.max(timeout, 0);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700914 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700915 return timeout;
916 }
Jeff Brown6aaf2952012-10-05 16:01:08 -0700917
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700918 private void doKeyguardLaterLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000919 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700920 if (timeout == 0) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800921 doKeyguardLocked(null);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700922 } else {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700923 doKeyguardLaterLocked(timeout);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700924 }
925 }
926
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700927 private void doKeyguardLaterLocked(long timeout) {
928 // Lock in the future
929 long when = SystemClock.elapsedRealtime() + timeout;
930 Intent intent = new Intent(DELAYED_KEYGUARD_ACTION);
931 intent.putExtra("seq", mDelayedShowingSequence);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700932 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700933 PendingIntent sender = PendingIntent.getBroadcast(mContext,
934 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Jim Millera622d3cc2016-03-02 16:02:24 -0800935 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700936 if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = "
937 + mDelayedShowingSequence);
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000938 doKeyguardLaterForChildProfilesLocked();
Clara Bayarri56878a92015-10-29 15:43:55 +0000939 }
Clara Bayarri10ad84a2015-12-01 17:38:05 +0000940
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000941 private void doKeyguardLaterForChildProfilesLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000942 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700943 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
944 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
945 long userTimeout = getLockTimeout(profileId);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000946 if (userTimeout == 0) {
947 doKeyguardForChildProfilesLocked();
948 } else {
949 long userWhen = SystemClock.elapsedRealtime() + userTimeout;
950 Intent lockIntent = new Intent(DELAYED_LOCK_PROFILE_ACTION);
951 lockIntent.putExtra("seq", mDelayedProfileShowingSequence);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700952 lockIntent.putExtra(Intent.EXTRA_USER_ID, profileId);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700953 lockIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000954 PendingIntent lockSender = PendingIntent.getBroadcast(
955 mContext, 0, lockIntent, PendingIntent.FLAG_CANCEL_CURRENT);
956 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
957 userWhen, lockSender);
958 }
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000959 }
960 }
961 }
962
963 private void doKeyguardForChildProfilesLocked() {
964 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700965 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
966 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
967 lockProfile(profileId);
Clara Bayarri56878a92015-10-29 15:43:55 +0000968 }
969 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700970 }
971
Jeff Brown6aaf2952012-10-05 16:01:08 -0700972 private void cancelDoKeyguardLaterLocked() {
973 mDelayedShowingSequence++;
974 }
975
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000976 private void cancelDoKeyguardForChildProfilesLocked() {
977 mDelayedProfileShowingSequence++;
978 }
979
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800980 /**
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700981 * Let's us know when the device is waking up.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800982 */
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700983 public void onStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700984 Trace.beginSection("KeyguardViewMediator#onStartedWakingUp");
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700985
986 // TODO: Rename all screen off/on references to interactive/sleeping
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800987 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700988 mDeviceInteractive = true;
Jeff Brown6aaf2952012-10-05 16:01:08 -0700989 cancelDoKeyguardLaterLocked();
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000990 cancelDoKeyguardForChildProfilesLocked();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700991 if (DEBUG) Log.d(TAG, "onStartedWakingUp, seq = " + mDelayedShowingSequence);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700992 notifyStartedWakingUp();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800993 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700994 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedWakingUp();
Jim Miller3fd47af2012-09-21 19:55:27 -0700995 maybeSendUserPresentBroadcast();
Nick Desaulniers1d396752016-07-25 15:05:33 -0700996 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -0700997 }
998
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700999 public void onScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001000 Trace.beginSection("KeyguardViewMediator#onScreenTurningOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001001 notifyScreenOn(callback);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001002 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001003 }
1004
1005 public void onScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001006 Trace.beginSection("KeyguardViewMediator#onScreenTurnedOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001007 notifyScreenTurnedOn();
1008 mUpdateMonitor.dispatchScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001009 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001010 }
1011
1012 public void onScreenTurnedOff() {
1013 notifyScreenTurnedOff();
1014 mUpdateMonitor.dispatchScreenTurnedOff();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001015 }
1016
Jim Miller3fd47af2012-09-21 19:55:27 -07001017 private void maybeSendUserPresentBroadcast() {
Adrian Roos8150d2a2015-04-16 17:11:20 -07001018 if (mSystemReady && mLockPatternUtils.isLockScreenDisabled(
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001019 KeyguardUpdateMonitor.getCurrentUser())) {
Jim Miller3fd47af2012-09-21 19:55:27 -07001020 // Lock screen is disabled because the user has set the preference to "None".
1021 // In this case, send out ACTION_USER_PRESENT here instead of in
1022 // handleKeyguardDone()
1023 sendUserPresentBroadcast();
Adrian Roosfb95a812016-06-20 14:58:59 -07001024 } else if (mSystemReady && shouldWaitForProvisioning()) {
1025 // Skipping the lockscreen because we're not yet provisioned, but we still need to
1026 // notify the StrongAuthTracker that it's now safe to run trust agents, in case the
1027 // user sets a credential later.
1028 getLockPatternUtils().userPresent(KeyguardUpdateMonitor.getCurrentUser());
Jim Miller3fd47af2012-09-21 19:55:27 -07001029 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001030 }
1031
1032 /**
Jeff Brown6aaf2952012-10-05 16:01:08 -07001033 * A dream started. We should lock after the usual screen-off lock timeout but only
1034 * if there is a secure lock pattern.
1035 */
1036 public void onDreamingStarted() {
Selim Cinek99415392016-09-09 14:58:41 -07001037 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001038 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001039 if (mDeviceInteractive
1040 && mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001041 doKeyguardLaterLocked();
1042 }
1043 }
1044 }
1045
1046 /**
1047 * A dream stopped.
1048 */
1049 public void onDreamingStopped() {
Selim Cinek99415392016-09-09 14:58:41 -07001050 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001051 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001052 if (mDeviceInteractive) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001053 cancelDoKeyguardLaterLocked();
1054 }
1055 }
1056 }
1057
1058 /**
Adrian Roose99bc052017-11-20 17:55:31 +01001059 * Same semantics as {@link WindowManagerPolicyConstants#enableKeyguard}; provide
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001060 * a way for external stuff to override normal keyguard behavior. For instance
1061 * the phone app disables the keyguard when it receives incoming calls.
1062 */
1063 public void setKeyguardEnabled(boolean enabled) {
1064 synchronized (this) {
1065 if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")");
1066
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001067 mExternallyEnabled = enabled;
1068
1069 if (!enabled && mShowing) {
1070 if (mExitSecureCallback != null) {
1071 if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring");
1072 // we're in the process of handling a request to verify the user
1073 // can get past the keyguard. ignore extraneous requests to disable / reenable
1074 return;
1075 }
1076
1077 // hiding keyguard that is showing, remember to reshow later
1078 if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, "
1079 + "disabling status bar expansion");
1080 mNeedToReshowWhenReenabled = true;
Jim Millerab954542014-10-10 18:21:49 -07001081 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001082 hideLocked();
1083 } else if (enabled && mNeedToReshowWhenReenabled) {
1084 // reenabled after previously hidden, reshow
1085 if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling "
1086 + "status bar expansion");
1087 mNeedToReshowWhenReenabled = false;
Jim Millerab954542014-10-10 18:21:49 -07001088 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001089
1090 if (mExitSecureCallback != null) {
1091 if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting");
Jim Miller5ecd8112013-01-09 18:50:26 -08001092 try {
1093 mExitSecureCallback.onKeyguardExitResult(false);
1094 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001095 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001096 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001097 mExitSecureCallback = null;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001098 resetStateLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001099 } else {
Adam Cohenf7522022012-10-03 20:03:18 -07001100 showLocked(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001101
1102 // block until we know the keygaurd is done drawing (and post a message
1103 // to unblock us after a timeout so we don't risk blocking too long
1104 // and causing an ANR).
1105 mWaitingUntilKeyguardVisible = true;
1106 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS);
1107 if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false");
1108 while (mWaitingUntilKeyguardVisible) {
1109 try {
1110 wait();
1111 } catch (InterruptedException e) {
1112 Thread.currentThread().interrupt();
1113 }
1114 }
1115 if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible");
1116 }
1117 }
1118 }
1119 }
1120
1121 /**
1122 * @see android.app.KeyguardManager#exitKeyguardSecurely
1123 */
Jim Miller25190572013-02-28 17:36:24 -08001124 public void verifyUnlock(IKeyguardExitCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001125 Trace.beginSection("KeyguardViewMediator#verifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001126 synchronized (this) {
1127 if (DEBUG) Log.d(TAG, "verifyUnlock");
Jim Millerb256e4e22014-10-31 17:27:13 -07001128 if (shouldWaitForProvisioning()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001129 // don't allow this api when the device isn't provisioned
1130 if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned");
Jim Miller5ecd8112013-01-09 18:50:26 -08001131 try {
Jim Miller25190572013-02-28 17:36:24 -08001132 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001133 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001134 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001135 }
Mike Lockwood5d258b62009-12-02 13:50:45 -05001136 } else if (mExternallyEnabled) {
1137 // this only applies when the user has externally disabled the
1138 // keyguard. this is unexpected and means the user is not
1139 // using the api properly.
1140 Log.w(TAG, "verifyUnlock called when not externally disabled");
Jim Miller5ecd8112013-01-09 18:50:26 -08001141 try {
Jim Miller25190572013-02-28 17:36:24 -08001142 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001143 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001144 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001145 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001146 } else if (mExitSecureCallback != null) {
1147 // already in progress with someone else
Jim Miller5ecd8112013-01-09 18:50:26 -08001148 try {
Jim Miller25190572013-02-28 17:36:24 -08001149 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001150 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001151 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001152 }
Jorim Jaggi302475e2015-09-22 12:44:47 -07001153 } else if (!isSecure()) {
1154
1155 // Keyguard is not secure, no need to do anything, and we don't need to reshow
1156 // the Keyguard after the client releases the Keyguard lock.
1157 mExternallyEnabled = true;
1158 mNeedToReshowWhenReenabled = false;
1159 updateInputRestricted();
1160 try {
1161 callback.onKeyguardExitResult(true);
1162 } catch (RemoteException e) {
1163 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1164 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001165 } else {
Jorim Jaggi302475e2015-09-22 12:44:47 -07001166
1167 // Since we prevent apps from hiding the Keyguard if we are secure, this should be
1168 // a no-op as well.
1169 try {
1170 callback.onKeyguardExitResult(false);
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 }
1175 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001176 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001177 }
1178
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001179 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001180 * Is the keyguard currently showing and not being force hidden?
Mike Lockwood09a40402009-11-08 00:33:23 -05001181 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001182 public boolean isShowingAndNotOccluded() {
1183 return mShowing && !mOccluded;
1184 }
1185
1186 /**
1187 * Notify us when the keyguard is occluded by another window
1188 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001189 public void setOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001190 Trace.beginSection("KeyguardViewMediator#setOccluded");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001191 if (DEBUG) Log.d(TAG, "setOccluded " + isOccluded);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001192 mHandler.removeMessages(SET_OCCLUDED);
Jorim Jaggi6626f542016-08-22 13:08:44 -07001193 Message msg = mHandler.obtainMessage(SET_OCCLUDED, isOccluded ? 1 : 0, animate ? 1 : 0);
Mike Lockwood9200a392009-11-17 20:25:58 -05001194 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001195 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001196 }
1197
Lucas Dupin2986c152018-04-09 20:49:41 -07001198 public boolean isHiding() {
1199 return mHiding;
1200 }
1201
Mike Lockwood9200a392009-11-17 20:25:58 -05001202 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001203 * Handles SET_OCCLUDED message sent by setOccluded()
Mike Lockwood9200a392009-11-17 20:25:58 -05001204 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001205 private void handleSetOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001206 Trace.beginSection("KeyguardViewMediator#handleSetOccluded");
Mike Lockwood09a40402009-11-08 00:33:23 -05001207 synchronized (KeyguardViewMediator.this) {
Adrian Roosf253eeb2015-04-15 18:03:08 -07001208 if (mHiding && isOccluded) {
1209 // We're in the process of going away but WindowManager wants to show a
1210 // SHOW_WHEN_LOCKED activity instead.
1211 startKeyguardExitAnimation(0, 0);
1212 }
1213
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001214 if (mOccluded != isOccluded) {
1215 mOccluded = isOccluded;
Kevin Chyn2fefd462017-04-28 12:18:19 -07001216 mUpdateMonitor.setKeyguardOccluded(isOccluded);
Selim Cinek2f6272e2017-03-15 16:19:10 -07001217 mStatusBarKeyguardViewManager.setOccluded(isOccluded, animate
1218 && mDeviceInteractive);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001219 adjustStatusBarLocked();
Mike Lockwood9200a392009-11-17 20:25:58 -05001220 }
Mike Lockwood09a40402009-11-08 00:33:23 -05001221 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001222 Trace.endSection();
Mike Lockwood09a40402009-11-08 00:33:23 -05001223 }
1224
1225 /**
Mike Lockwood28569302010-01-28 11:54:40 -05001226 * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout.
1227 * This must be safe to call from any thread and with any window manager locks held.
1228 */
Adam Cohenf7522022012-10-03 20:03:18 -07001229 public void doKeyguardTimeout(Bundle options) {
Mike Lockwood28569302010-01-28 11:54:40 -05001230 mHandler.removeMessages(KEYGUARD_TIMEOUT);
Adam Cohenf7522022012-10-03 20:03:18 -07001231 Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options);
Mike Lockwood28569302010-01-28 11:54:40 -05001232 mHandler.sendMessage(msg);
1233 }
1234
1235 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001236 * Given the state of the keyguard, is the input restricted?
1237 * Input is restricted when the keyguard is showing, or when the keyguard
1238 * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet.
1239 */
1240 public boolean isInputRestricted() {
Adrian Roos9f33d6c2015-06-15 15:58:35 -07001241 return mShowing || mNeedToReshowWhenReenabled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001242 }
1243
Jim Millerab954542014-10-10 18:21:49 -07001244 private void updateInputRestricted() {
1245 synchronized (this) {
1246 updateInputRestrictedLocked();
1247 }
1248 }
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001249
Jim Millerab954542014-10-10 18:21:49 -07001250 private void updateInputRestrictedLocked() {
1251 boolean inputRestricted = isInputRestricted();
1252 if (mInputRestricted != inputRestricted) {
1253 mInputRestricted = inputRestricted;
dooyoung.hwang328472e2015-05-21 16:09:43 +09001254 int size = mKeyguardStateCallbacks.size();
1255 for (int i = size - 1; i >= 0; i--) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001256 final IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001257 try {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001258 callback.onInputRestrictedStateChanged(inputRestricted);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001259 } catch (RemoteException e) {
1260 Slog.w(TAG, "Failed to call onDeviceProvisioned", e);
1261 if (e instanceof DeadObjectException) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001262 mKeyguardStateCallbacks.remove(callback);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001263 }
Jim Millerab954542014-10-10 18:21:49 -07001264 }
Jim Millerab954542014-10-10 18:21:49 -07001265 }
1266 }
1267 }
1268
Dianne Hackbornb446e972009-09-20 15:23:25 -07001269 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001270 * Enable the keyguard if the settings are appropriate.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001271 */
Adam Cohenf7522022012-10-03 20:03:18 -07001272 private void doKeyguardLocked(Bundle options) {
Adrian Roosca8a2162017-08-17 19:00:58 +02001273 if (KeyguardUpdateMonitor.CORE_APPS_ONLY) {
1274 // Don't show keyguard during half-booted cryptkeeper stage.
1275 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because booting to cryptkeeper");
1276 return;
1277 }
1278
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001279 // if another app is disabling us, don't show
1280 if (!mExternallyEnabled) {
1281 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled");
Karl Rosaenab100082009-03-24 22:35:17 -07001282
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001283 // note: we *should* set mNeedToReshowWhenReenabled=true here, but that makes
1284 // for an occasional ugly flicker in this situation:
1285 // 1) receive a call with the screen on (no keyguard) or make a call
1286 // 2) screen times out
1287 // 3) user hits key to turn screen back on
1288 // instead, we reenable the keyguard when we know the screen is off and the call
1289 // ends (see the broadcast receiver below)
1290 // TODO: clean this up when we have better support at the window manager level
1291 // for apps that wish to be on top of the keyguard
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001292 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001293 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001294
1295 // if the keyguard is already showing, don't bother
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001296 if (mStatusBarKeyguardViewManager.isShowing()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001297 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing");
Jorim Jaggi95e89ca2014-11-24 20:12:50 +01001298 resetStateLocked();
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001299 return;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001300 }
1301
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001302 // In split system user mode, we never unlock system user.
Amith Yamasanieb437d42016-04-29 09:31:25 -07001303 if (!mustNotUnlockCurrentUser()
Amith Yamasani27e025b2015-11-06 10:34:41 -08001304 || !mUpdateMonitor.isDeviceProvisioned()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001305
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001306 // if the setup wizard hasn't run yet, don't show
1307 final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", false);
1308 final boolean absent = SubscriptionManager.isValidSubscriptionId(
Adrian Roose92de952016-12-13 12:07:09 -08001309 mUpdateMonitor.getNextSubIdForState(ABSENT));
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001310 final boolean disabled = SubscriptionManager.isValidSubscriptionId(
1311 mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.PERM_DISABLED));
1312 final boolean lockedOrMissing = mUpdateMonitor.isSimPinSecure()
1313 || ((absent || disabled) && requireSim);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001314
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001315 if (!lockedOrMissing && shouldWaitForProvisioning()) {
1316 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned"
1317 + " and the sim is not locked or missing");
1318 return;
1319 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001320
Evan Rosky13a58a92016-07-27 15:51:09 -07001321 boolean forceShow = options != null && options.getBoolean(OPTION_FORCE_SHOW, false);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001322 if (mLockPatternUtils.isLockScreenDisabled(KeyguardUpdateMonitor.getCurrentUser())
Evan Rosky13a58a92016-07-27 15:51:09 -07001323 && !lockedOrMissing && !forceShow) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001324 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off");
1325 return;
1326 }
1327
1328 if (mLockPatternUtils.checkVoldPassword(KeyguardUpdateMonitor.getCurrentUser())) {
1329 if (DEBUG) Log.d(TAG, "Not showing lock screen since just decrypted");
1330 // Without this, settings is not enabled until the lock screen first appears
Lucas Dupin47a65c72018-02-15 14:16:18 -08001331 setShowingLocked(false, mAodShowing);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001332 hideLocked();
1333 return;
1334 }
Paul Lawrence945490c2014-03-27 16:37:28 +00001335 }
1336
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001337 if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");
Adam Cohenf7522022012-10-03 20:03:18 -07001338 showLocked(options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001339 }
1340
Clara Bayarri56878a92015-10-29 15:43:55 +00001341 private void lockProfile(int userId) {
1342 mTrustManager.setDeviceLockedForUser(userId, true);
1343 }
1344
Jim Millerb256e4e22014-10-31 17:27:13 -07001345 private boolean shouldWaitForProvisioning() {
1346 return !mUpdateMonitor.isDeviceProvisioned() && !isSecure();
1347 }
1348
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001349 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001350 * Dismiss the keyguard through the security layers.
Jorim Jaggi241ae102016-11-02 21:57:33 -07001351 * @param callback Callback to be informed about the result
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001352 * @param message Message that should be displayed on the bouncer.
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001353 */
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001354 private void handleDismiss(IKeyguardDismissCallback callback, CharSequence message) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001355 if (mShowing) {
1356 if (callback != null) {
1357 mDismissCallbackRegistry.addCallback(callback);
1358 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001359 mCustomMessage = message;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001360 mStatusBarKeyguardViewManager.dismissAndCollapse();
Jorim Jaggi241ae102016-11-02 21:57:33 -07001361 } else if (callback != null) {
1362 new DismissCallbackWrapper(callback).notifyDismissError();
Jim Miller87d03662012-11-05 20:28:09 -08001363 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001364 }
1365
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001366 public void dismiss(IKeyguardDismissCallback callback, CharSequence message) {
1367 mHandler.obtainMessage(DISMISS, new DismissMessage(callback, message)).sendToTarget();
Jim Miller60013792013-10-03 18:31:34 -07001368 }
1369
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001370 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001371 * Send message to keyguard telling it to reset its state.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001372 * @see #handleReset
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001373 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001374 private void resetStateLocked() {
Jim Miller4894a012013-04-03 15:23:55 -07001375 if (DEBUG) Log.e(TAG, "resetStateLocked");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001376 Message msg = mHandler.obtainMessage(RESET);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001377 mHandler.sendMessage(msg);
1378 }
1379
1380 /**
1381 * Send message to keyguard telling it to verify unlock
1382 * @see #handleVerifyUnlock()
1383 */
1384 private void verifyUnlockLocked() {
1385 if (DEBUG) Log.d(TAG, "verifyUnlockLocked");
1386 mHandler.sendEmptyMessage(VERIFY_UNLOCK);
1387 }
1388
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001389 private void notifyStartedGoingToSleep() {
1390 if (DEBUG) Log.d(TAG, "notifyStartedGoingToSleep");
1391 mHandler.sendEmptyMessage(NOTIFY_STARTED_GOING_TO_SLEEP);
1392 }
1393
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001394 private void notifyFinishedGoingToSleep() {
1395 if (DEBUG) Log.d(TAG, "notifyFinishedGoingToSleep");
1396 mHandler.sendEmptyMessage(NOTIFY_FINISHED_GOING_TO_SLEEP);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001397 }
1398
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001399 private void notifyStartedWakingUp() {
1400 if (DEBUG) Log.d(TAG, "notifyStartedWakingUp");
1401 mHandler.sendEmptyMessage(NOTIFY_STARTED_WAKING_UP);
1402 }
1403
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001404 private void notifyScreenOn(IKeyguardDrawnCallback callback) {
1405 if (DEBUG) Log.d(TAG, "notifyScreenOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001406 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNING_ON, callback);
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001407 mHandler.sendMessage(msg);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001408 }
1409
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001410 private void notifyScreenTurnedOn() {
1411 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOn");
1412 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_ON);
1413 mHandler.sendMessage(msg);
1414 }
1415
1416 private void notifyScreenTurnedOff() {
1417 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOff");
1418 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_OFF);
1419 mHandler.sendMessage(msg);
1420 }
1421
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001422 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001423 * Send message to keyguard telling it to show itself
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001424 * @see #handleShow
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001425 */
Adam Cohenf7522022012-10-03 20:03:18 -07001426 private void showLocked(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001427 Trace.beginSection("KeyguardViewMediator#showLocked aqcuiring mShowKeyguardWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001428 if (DEBUG) Log.d(TAG, "showLocked");
Mike Lockwood674d3e42009-10-06 09:28:54 -04001429 // ensure we stay awake until we are finished displaying the keyguard
1430 mShowKeyguardWakeLock.acquire();
Adam Cohenf7522022012-10-03 20:03:18 -07001431 Message msg = mHandler.obtainMessage(SHOW, options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001432 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001433 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001434 }
1435
1436 /**
1437 * Send message to keyguard telling it to hide itself
Jim Miller9c20d0e2010-01-20 15:00:23 -08001438 * @see #handleHide()
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001439 */
1440 private void hideLocked() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001441 Trace.beginSection("KeyguardViewMediator#hideLocked");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001442 if (DEBUG) Log.d(TAG, "hideLocked");
1443 Message msg = mHandler.obtainMessage(HIDE);
1444 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001445 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001446 }
1447
Dianne Hackbornb446e972009-09-20 15:23:25 -07001448 public boolean isSecure() {
Evan Rosky13a58a92016-07-27 15:51:09 -07001449 return isSecure(KeyguardUpdateMonitor.getCurrentUser());
1450 }
1451
1452 public boolean isSecure(int userId) {
1453 return mLockPatternUtils.isSecure(userId)
1454 || KeyguardUpdateMonitor.getInstance(mContext).isSimPinSecure();
Dianne Hackbornb446e972009-09-20 15:23:25 -07001455 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001456
Evan Rosky18396452016-07-27 15:19:37 -07001457 public void setSwitchingUser(boolean switching) {
Selim Cinekbbe19242017-12-08 15:42:08 -08001458 KeyguardUpdateMonitor.getInstance(mContext).setSwitchingUser(switching);
Evan Rosky18396452016-07-27 15:19:37 -07001459 }
1460
Craig Mautnerf1b67412012-09-19 13:18:29 -07001461 /**
1462 * Update the newUserId. Call while holding WindowManagerService lock.
Jim Milleree82f8f2012-10-01 16:26:18 -07001463 * NOTE: Should only be called by KeyguardViewMediator in response to the user id changing.
1464 *
Craig Mautnerf1b67412012-09-19 13:18:29 -07001465 * @param newUserId The id of the incoming user.
1466 */
1467 public void setCurrentUser(int newUserId) {
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001468 KeyguardUpdateMonitor.setCurrentUser(newUserId);
Adrian Roosd88eb262016-08-04 14:50:48 -07001469 synchronized (this) {
1470 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(newUserId));
1471 }
Craig Mautnerf1b67412012-09-19 13:18:29 -07001472 }
1473
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001474 /**
1475 * This broadcast receiver should be registered with the SystemUI permission.
1476 */
1477 private final BroadcastReceiver mDelayedLockBroadcastReceiver = new BroadcastReceiver() {
Amith Yamasani52c489c2012-03-28 11:42:42 -07001478 @Override
1479 public void onReceive(Context context, Intent intent) {
Jim Millerbbf1a742012-07-17 18:30:30 -07001480 if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
1481 final int sequence = intent.getIntExtra("seq", 0);
Jim Millerf3447352011-08-07 14:00:09 -07001482 if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = "
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001483 + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001484 synchronized (KeyguardViewMediator.this) {
Jim Miller2967f482016-01-07 15:05:32 -08001485 if (mDelayedShowingSequence == sequence) {
1486 doKeyguardLocked(null);
1487 }
Clara Bayarri56878a92015-10-29 15:43:55 +00001488 }
1489 } else if (DELAYED_LOCK_PROFILE_ACTION.equals(intent.getAction())) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001490 final int sequence = intent.getIntExtra("seq", 0);
Clara Bayarri56878a92015-10-29 15:43:55 +00001491 int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, 0);
1492 if (userId != 0) {
1493 synchronized (KeyguardViewMediator.this) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001494 if (mDelayedProfileShowingSequence == sequence) {
1495 lockProfile(userId);
1496 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001497 }
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001498 }
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001499 }
1500 }
1501 };
1502
1503 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1504 @Override
1505 public void onReceive(Context context, Intent intent) {
1506 if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
Adrian Roos1f8025a2016-12-27 10:12:13 -08001507 synchronized (KeyguardViewMediator.this){
1508 mShuttingDown = true;
1509 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001510 }
1511 }
1512 };
1513
Jorim Jaggi241ae102016-11-02 21:57:33 -07001514 public void keyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001515 Trace.beginSection("KeyguardViewMediator#keyguardDone");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001516 if (DEBUG) Log.d(TAG, "keyguardDone()");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001517 userActivity();
Jim Miller60013792013-10-03 18:31:34 -07001518 EventLog.writeEvent(70000, 2);
Jorim Jaggi241ae102016-11-02 21:57:33 -07001519 Message msg = mHandler.obtainMessage(KEYGUARD_DONE);
Jim Miller60013792013-10-03 18:31:34 -07001520 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001521 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001522 }
1523
1524 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001525 * This handler will be associated with the policy thread, which will also
1526 * be the UI thread of the keyguard. Since the apis of the policy, and therefore
1527 * this class, can be called by other threads, any action that directly
1528 * interacts with the keyguard ui should be posted to this handler, rather
1529 * than called directly.
1530 */
Jim Millerdcb3d842012-08-23 19:18:12 -07001531 private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001532 @Override
Wink Saville37c124c2009-04-02 01:37:02 -07001533 public void handleMessage(Message msg) {
1534 switch (msg.what) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001535 case SHOW:
Adam Cohenf7522022012-10-03 20:03:18 -07001536 handleShow((Bundle) msg.obj);
Jim Miller60013792013-10-03 18:31:34 -07001537 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001538 case HIDE:
1539 handleHide();
Jim Miller60013792013-10-03 18:31:34 -07001540 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001541 case RESET:
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001542 handleReset();
Jim Miller60013792013-10-03 18:31:34 -07001543 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001544 case VERIFY_UNLOCK:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001545 Trace.beginSection("KeyguardViewMediator#handleMessage VERIFY_UNLOCK");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001546 handleVerifyUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001547 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001548 break;
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001549 case NOTIFY_STARTED_GOING_TO_SLEEP:
1550 handleNotifyStartedGoingToSleep();
1551 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001552 case NOTIFY_FINISHED_GOING_TO_SLEEP:
1553 handleNotifyFinishedGoingToSleep();
Jim Miller60013792013-10-03 18:31:34 -07001554 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001555 case NOTIFY_SCREEN_TURNING_ON:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001556 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNING_ON");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001557 handleNotifyScreenTurningOn((IKeyguardDrawnCallback) msg.obj);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001558 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001559 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001560 case NOTIFY_SCREEN_TURNED_ON:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001561 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNED_ON");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001562 handleNotifyScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001563 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001564 break;
1565 case NOTIFY_SCREEN_TURNED_OFF:
1566 handleNotifyScreenTurnedOff();
1567 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001568 case NOTIFY_STARTED_WAKING_UP:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001569 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_STARTED_WAKING_UP");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001570 handleNotifyStartedWakingUp();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001571 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001572 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001573 case KEYGUARD_DONE:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001574 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001575 handleKeyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001576 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001577 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001578 case KEYGUARD_DONE_DRAWING:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001579 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_DRAWING");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001580 handleKeyguardDoneDrawing();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001581 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001582 break;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001583 case SET_OCCLUDED:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001584 Trace.beginSection("KeyguardViewMediator#handleMessage SET_OCCLUDED");
Jorim Jaggi6626f542016-08-22 13:08:44 -07001585 handleSetOccluded(msg.arg1 != 0, msg.arg2 != 0);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001586 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001587 break;
Mike Lockwood28569302010-01-28 11:54:40 -05001588 case KEYGUARD_TIMEOUT:
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001589 synchronized (KeyguardViewMediator.this) {
Adam Cohenf7522022012-10-03 20:03:18 -07001590 doKeyguardLocked((Bundle) msg.obj);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001591 }
1592 break;
Jim Miller60013792013-10-03 18:31:34 -07001593 case DISMISS:
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001594 final DismissMessage message = (DismissMessage) msg.obj;
1595 handleDismiss(message.getCallback(), message.getMessage());
Jim Miller60013792013-10-03 18:31:34 -07001596 break;
Jorim Jaggi0d674622014-05-21 01:34:15 +02001597 case START_KEYGUARD_EXIT_ANIM:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001598 Trace.beginSection("KeyguardViewMediator#handleMessage START_KEYGUARD_EXIT_ANIM");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001599 StartKeyguardExitAnimParams params = (StartKeyguardExitAnimParams) msg.obj;
1600 handleStartKeyguardExitAnimation(params.startTime, params.fadeoutDuration);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001601 FalsingManager.getInstance(mContext).onSucccessfulUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001602 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001603 break;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001604 case KEYGUARD_DONE_PENDING_TIMEOUT:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001605 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_PENDING_TIMEOUT");
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001606 Log.w(TAG, "Timeout while waiting for activity drawn!");
Nick Desaulniers1d396752016-07-25 15:05:33 -07001607 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001608 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001609 }
1610 }
1611 };
1612
Jorim Jaggi241ae102016-11-02 21:57:33 -07001613 private void tryKeyguardDone() {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001614 if (!mKeyguardDonePending && mHideAnimationRun && !mHideAnimationRunning) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001615 handleKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001616 } else if (!mHideAnimationRun) {
1617 mHideAnimationRun = true;
1618 mHideAnimationRunning = true;
1619 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
1620 }
1621 }
1622
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001623 /**
1624 * @see #keyguardDone
1625 * @see #KEYGUARD_DONE
1626 */
Jorim Jaggi241ae102016-11-02 21:57:33 -07001627 private void handleKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001628 Trace.beginSection("KeyguardViewMediator#handleKeyguardDone");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001629 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001630 mUiOffloadThread.submit(() -> {
1631 if (mLockPatternUtils.isSecure(currentUser)) {
1632 mLockPatternUtils.getDevicePolicyManager().reportKeyguardDismissed(currentUser);
1633 }
1634 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001635 if (DEBUG) Log.d(TAG, "handleKeyguardDone");
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001636 synchronized (this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001637 resetKeyguardDonePendingLocked();
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001638 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001639
Jorim Jaggi241ae102016-11-02 21:57:33 -07001640 mUpdateMonitor.clearFailedUnlockAttempts();
Jim Millerf41fc962014-06-18 16:33:51 -07001641 mUpdateMonitor.clearFingerprintRecognized();
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -07001642
Jorim Jaggi4474f542015-07-09 16:08:02 -07001643 if (mGoingToSleep) {
1644 Log.i(TAG, "Device is going to sleep, aborting keyguardDone");
1645 return;
1646 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001647 if (mExitSecureCallback != null) {
1648 try {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001649 mExitSecureCallback.onKeyguardExitResult(true /* authenciated */);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001650 } catch (RemoteException e) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001651 Slog.w(TAG, "Failed to call onKeyguardExitResult()", e);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001652 }
1653
1654 mExitSecureCallback = null;
1655
Jorim Jaggi241ae102016-11-02 21:57:33 -07001656 // after succesfully exiting securely, no need to reshow
1657 // the keyguard when they've released the lock
1658 mExternallyEnabled = true;
1659 mNeedToReshowWhenReenabled = false;
1660 updateInputRestricted();
Jim Millere51cf7ae2013-06-25 18:31:56 -07001661 }
1662
1663 handleHide();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001664 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -07001665 }
1666
1667 private void sendUserPresentBroadcast() {
Jason Monkcf5a9532014-09-17 16:22:19 -04001668 synchronized (this) {
1669 if (mBootCompleted) {
Adrian Roos4ab7e592016-04-13 15:38:13 -07001670 int currentUserId = KeyguardUpdateMonitor.getCurrentUser();
1671 final UserHandle currentUser = new UserHandle(currentUserId);
Benjamin Franz4b9f8ed2014-12-01 16:51:48 +00001672 final UserManager um = (UserManager) mContext.getSystemService(
1673 Context.USER_SERVICE);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001674 mUiOffloadThread.submit(() -> {
1675 for (int profileId : um.getProfileIdsWithDisabled(currentUser.getIdentifier())) {
1676 mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, UserHandle.of(profileId));
1677 }
1678 getLockPatternUtils().userPresent(currentUserId);
1679 });
Jason Monkcf5a9532014-09-17 16:22:19 -04001680 } else {
1681 mBootSendUserPresent = true;
1682 }
1683 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001684 }
1685
1686 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001687 * @see #keyguardDone
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001688 * @see #KEYGUARD_DONE_DRAWING
1689 */
1690 private void handleKeyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001691 Trace.beginSection("KeyguardViewMediator#handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001692 synchronized(this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001693 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001694 if (mWaitingUntilKeyguardVisible) {
1695 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible");
1696 mWaitingUntilKeyguardVisible = false;
1697 notifyAll();
1698
1699 // there will usually be two of these sent, one as a timeout, and one
1700 // as a result of the callback, so remove any remaining messages from
1701 // the queue
1702 mHandler.removeMessages(KEYGUARD_DONE_DRAWING);
1703 }
1704 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001705 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001706 }
1707
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001708 private void playSounds(boolean locked) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001709 playSound(locked ? mLockSoundId : mUnlockSoundId);
1710 }
1711
1712 private void playSound(int soundId) {
1713 if (soundId == 0) return;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001714 final ContentResolver cr = mContext.getContentResolver();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001715 if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001716
Marco Nelissend5545bd2011-09-29 12:49:17 -07001717 mLockSounds.stop(mLockSoundStreamId);
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001718 // Init mAudioManager
1719 if (mAudioManager == null) {
1720 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
1721 if (mAudioManager == null) return;
John Spurlockee5ad722015-03-03 16:17:21 -05001722 mUiSoundsStreamType = mAudioManager.getUiSoundsStreamType();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001723 }
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001724
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001725 mUiOffloadThread.submit(() -> {
1726 // If the stream is muted, don't play the sound
1727 if (mAudioManager.isStreamMute(mUiSoundsStreamType)) return;
1728
1729 int id = mLockSounds.play(soundId,
1730 mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/);
1731 synchronized (this) {
1732 mLockSoundStreamId = id;
1733 }
1734 });
1735
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001736 }
Jim Miller2a98a4c2010-11-19 18:49:26 -08001737 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001738
Adrian Roos49e057d2014-08-13 17:14:51 +02001739 private void playTrustedSound() {
Adrian Roos49e057d2014-08-13 17:14:51 +02001740 playSound(mTrustedSoundId);
1741 }
1742
Lucas Dupin47a65c72018-02-15 14:16:18 -08001743 private void updateActivityLockScreenState(boolean showing, boolean aodShowing,
1744 int secondaryDisplayShowing) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001745 mUiOffloadThread.submit(() -> {
1746 try {
Lucas Dupin47a65c72018-02-15 14:16:18 -08001747 ActivityManager.getService().setLockScreenShown(showing, aodShowing,
1748 secondaryDisplayShowing);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001749 } catch (RemoteException e) {
1750 }
1751 });
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001752 }
1753
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001754 /**
1755 * Handle message sent by {@link #showLocked}.
1756 * @see #SHOW
1757 */
Adam Cohenf7522022012-10-03 20:03:18 -07001758 private void handleShow(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001759 Trace.beginSection("KeyguardViewMediator#handleShow");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001760 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
1761 if (mLockPatternUtils.isSecure(currentUser)) {
1762 mLockPatternUtils.getDevicePolicyManager().reportKeyguardSecured(currentUser);
Michal Karpinski779aad92016-01-20 11:56:22 +00001763 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001764 synchronized (KeyguardViewMediator.this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001765 if (!mSystemReady) {
1766 if (DEBUG) Log.d(TAG, "ignoring handleShow because system is not ready.");
1767 return;
1768 } else {
1769 if (DEBUG) Log.d(TAG, "handleShow");
1770 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001771
Lucas Dupin47a65c72018-02-15 14:16:18 -08001772 setShowingLocked(true, mAodShowing);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001773 mStatusBarKeyguardViewManager.show(options);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001774 mHiding = false;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001775 mWakeAndUnlocking = false;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001776 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001777 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001778 adjustStatusBarLocked();
Jeff Brown3dc524b2012-09-30 19:49:11 -07001779 userActivity();
Mike Lockwood674d3e42009-10-06 09:28:54 -04001780 mShowKeyguardWakeLock.release();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001781 }
Jim Miller31921482013-11-06 20:43:55 -08001782 mKeyguardDisplayManager.show();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001783 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001784 }
1785
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001786 private final Runnable mKeyguardGoingAwayRunnable = new Runnable() {
1787 @Override
1788 public void run() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001789 Trace.beginSection("KeyguardViewMediator.mKeyGuardGoingAwayRunnable");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001790 if (DEBUG) Log.d(TAG, "keyguardGoingAway");
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001791 try {
Jorim Jaggi33ae80e2015-02-04 16:37:11 +01001792 mStatusBarKeyguardViewManager.keyguardGoingAway();
1793
Adrian Roosd5c2db62016-03-08 16:11:31 -08001794 int flags = 0;
1795 if (mStatusBarKeyguardViewManager.shouldDisableWindowAnimationsForUnlock()
1796 || mWakeAndUnlocking) {
Adrian Roose99bc052017-11-20 17:55:31 +01001797 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001798 }
1799 if (mStatusBarKeyguardViewManager.isGoingToNotificationShade()) {
Adrian Roose99bc052017-11-20 17:55:31 +01001800 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001801 }
1802 if (mStatusBarKeyguardViewManager.isUnlockWithWallpaper()) {
Adrian Roose99bc052017-11-20 17:55:31 +01001803 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001804 }
1805
Kevin Chyn6db7d5f2017-05-03 22:24:31 -07001806 mUpdateMonitor.setKeyguardGoingAway(true /* goingAway */);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001807 // Don't actually hide the Keyguard at the moment, wait for window
1808 // manager until it tells us it's safe to do so with
1809 // startKeyguardExitAnimation.
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001810 ActivityManager.getService().keyguardGoingAway(flags);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001811 } catch (RemoteException e) {
1812 Log.e(TAG, "Error while calling WindowManager", e);
1813 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001814 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001815 }
1816 };
1817
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001818 private final Runnable mHideAnimationFinishedRunnable = () -> {
1819 mHideAnimationRunning = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -07001820 tryKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001821 };
1822
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001823 /**
1824 * Handle message sent by {@link #hideLocked()}
1825 * @see #HIDE
1826 */
1827 private void handleHide() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001828 Trace.beginSection("KeyguardViewMediator#handleHide");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001829 synchronized (KeyguardViewMediator.this) {
1830 if (DEBUG) Log.d(TAG, "handleHide");
Jorim Jaggib9d60792014-06-03 22:34:22 +02001831
Amith Yamasanieb437d42016-04-29 09:31:25 -07001832 if (mustNotUnlockCurrentUser()) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001833 // In split system user mode, we never unlock system user. The end user has to
1834 // switch to another user.
1835 // TODO: We should stop it early by disabling the swipe up flow. Right now swipe up
1836 // still completes and makes the screen blank.
1837 if (DEBUG) Log.d(TAG, "Split system user, quit unlocking.");
1838 return;
1839 }
Jorim Jaggi76a16232014-08-08 17:00:47 +02001840 mHiding = true;
Jorim Jaggib9d60792014-06-03 22:34:22 +02001841
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001842 if (mShowing && !mOccluded) {
1843 mKeyguardGoingAwayRunnable.run();
1844 } else {
Jorim Jaggi76a16232014-08-08 17:00:47 +02001845 handleStartKeyguardExitAnimation(
1846 SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(),
1847 mHideAnimation.getDuration());
Jorim Jaggi0d674622014-05-21 01:34:15 +02001848 }
1849 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001850 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001851 }
1852
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001853 private void handleStartKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001854 Trace.beginSection("KeyguardViewMediator#handleStartKeyguardExitAnimation");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001855 if (DEBUG) Log.d(TAG, "handleStartKeyguardExitAnimation startTime=" + startTime
1856 + " fadeoutDuration=" + fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02001857 synchronized (KeyguardViewMediator.this) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001858
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001859 if (!mHiding) {
1860 return;
1861 }
1862 mHiding = false;
1863
Jorim Jaggib774e552015-08-24 14:52:45 -07001864 if (mWakeAndUnlocking && mDrawnCallback != null) {
1865
1866 // Hack level over 9000: To speed up wake-and-unlock sequence, force it to report
1867 // the next draw from here so we don't have to wait for window manager to signal
1868 // this to our ViewRootImpl.
1869 mStatusBarKeyguardViewManager.getViewRootImpl().setReportNextDraw();
1870 notifyDrawn(mDrawnCallback);
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001871 mDrawnCallback = null;
Jorim Jaggib774e552015-08-24 14:52:45 -07001872 }
1873
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001874 // only play "unlock" noises if not on a call (since the incall UI
1875 // disables the keyguard)
1876 if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) {
1877 playSounds(false);
1878 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001879
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001880 mWakeAndUnlocking = false;
Lucas Dupin47a65c72018-02-15 14:16:18 -08001881 setShowingLocked(false, mAodShowing);
Jorim Jaggi5277dea2017-05-18 02:05:29 +02001882 mDismissCallbackRegistry.notifyDismissSucceeded();
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001883 mStatusBarKeyguardViewManager.hide(startTime, fadeoutDuration);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001884 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001885 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001886 adjustStatusBarLocked();
Jim Miller705004b2014-09-04 16:51:20 -07001887 sendUserPresentBroadcast();
Kevin Chyn6db7d5f2017-05-03 22:24:31 -07001888 mUpdateMonitor.setKeyguardGoingAway(false /* goingAway */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001889 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001890 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001891 }
1892
Mike Lockwood5f892c12009-11-19 23:39:13 -05001893 private void adjustStatusBarLocked() {
Matthew Ng66f0b702017-12-08 12:58:42 -08001894 adjustStatusBarLocked(false /* forceHideHomeRecentsButtons */);
1895 }
1896
1897 private void adjustStatusBarLocked(boolean forceHideHomeRecentsButtons) {
Mike Lockwood5f892c12009-11-19 23:39:13 -05001898 if (mStatusBarManager == null) {
1899 mStatusBarManager = (StatusBarManager)
1900 mContext.getSystemService(Context.STATUS_BAR_SERVICE);
1901 }
1902 if (mStatusBarManager == null) {
1903 Log.w(TAG, "Could not get status bar manager");
1904 } else {
Daniel Sandlerdba93562011-10-06 16:39:58 -04001905 // Disable aspects of the system/status/navigation bars that must not be re-enabled by
1906 // windows that appear on top, ever
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001907 int flags = StatusBarManager.DISABLE_NONE;
Matthew Ng66f0b702017-12-08 12:58:42 -08001908 if (forceHideHomeRecentsButtons || isShowingAndNotOccluded()) {
1909 flags |= StatusBarManager.DISABLE_HOME | StatusBarManager.DISABLE_RECENT;
Jorim Jaggia005f1b2014-04-16 19:06:10 +02001910 }
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001911
1912 if (DEBUG) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001913 Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mOccluded=" + mOccluded
Matthew Ng66f0b702017-12-08 12:58:42 -08001914 + " isSecure=" + isSecure() + " force=" + forceHideHomeRecentsButtons
1915 + " --> flags=0x" + Integer.toHexString(flags));
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001916 }
1917
Jorim Jaggie3e0b062017-06-12 12:18:41 -07001918 mStatusBarManager.disable(flags);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001919 }
1920 }
1921
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001922 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001923 * Handle message sent by {@link #resetStateLocked}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001924 * @see #RESET
1925 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001926 private void handleReset() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001927 synchronized (KeyguardViewMediator.this) {
1928 if (DEBUG) Log.d(TAG, "handleReset");
Jorim Jaggife762342016-10-13 14:33:27 +02001929 mStatusBarKeyguardViewManager.reset(true /* hideBouncerWhenShowing */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001930 }
1931 }
1932
1933 /**
1934 * Handle message sent by {@link #verifyUnlock}
Craig Mautner904732c2012-10-17 15:20:24 -07001935 * @see #VERIFY_UNLOCK
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001936 */
1937 private void handleVerifyUnlock() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001938 Trace.beginSection("KeyguardViewMediator#handleVerifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001939 synchronized (KeyguardViewMediator.this) {
1940 if (DEBUG) Log.d(TAG, "handleVerifyUnlock");
Lucas Dupin47a65c72018-02-15 14:16:18 -08001941 setShowingLocked(true, mAodShowing);
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001942 mStatusBarKeyguardViewManager.dismissAndCollapse();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001943 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001944 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001945 }
1946
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001947 private void handleNotifyStartedGoingToSleep() {
1948 synchronized (KeyguardViewMediator.this) {
1949 if (DEBUG) Log.d(TAG, "handleNotifyStartedGoingToSleep");
1950 mStatusBarKeyguardViewManager.onStartedGoingToSleep();
1951 }
1952 }
1953
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001954 /**
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001955 * Handle message sent by {@link #notifyFinishedGoingToSleep()}
1956 * @see #NOTIFY_FINISHED_GOING_TO_SLEEP
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001957 */
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001958 private void handleNotifyFinishedGoingToSleep() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001959 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001960 if (DEBUG) Log.d(TAG, "handleNotifyFinishedGoingToSleep");
1961 mStatusBarKeyguardViewManager.onFinishedGoingToSleep();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001962 }
1963 }
1964
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001965 private void handleNotifyStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001966 Trace.beginSection("KeyguardViewMediator#handleMotifyStartedWakingUp");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001967 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001968 if (DEBUG) Log.d(TAG, "handleNotifyWakingUp");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001969 mStatusBarKeyguardViewManager.onStartedWakingUp();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001970 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001971 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001972 }
1973
1974 private void handleNotifyScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001975 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurningOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001976 synchronized (KeyguardViewMediator.this) {
1977 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurningOn");
Jorim Jaggi93739112015-08-13 15:53:14 -07001978 mStatusBarKeyguardViewManager.onScreenTurningOn();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001979 if (callback != null) {
1980 if (mWakeAndUnlocking) {
1981 mDrawnCallback = callback;
1982 } else {
1983 notifyDrawn(callback);
1984 }
1985 }
1986 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001987 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001988 }
1989
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001990 private void handleNotifyScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001991 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurnedOn");
Jorim Jaggic3fe2042016-10-07 18:52:48 +02001992 if (LatencyTracker.isEnabled(mContext)) {
1993 LatencyTracker.getInstance(mContext).onActionEnd(LatencyTracker.ACTION_TURN_ON_SCREEN);
1994 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001995 synchronized (this) {
1996 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOn");
1997 mStatusBarKeyguardViewManager.onScreenTurnedOn();
1998 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001999 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002000 }
2001
2002 private void handleNotifyScreenTurnedOff() {
2003 synchronized (this) {
2004 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOff");
2005 mStatusBarKeyguardViewManager.onScreenTurnedOff();
Jorim Jaggie93e6f92016-08-04 13:55:39 +02002006 mDrawnCallback = null;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002007 }
2008 }
2009
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002010 private void notifyDrawn(final IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002011 Trace.beginSection("KeyguardViewMediator#notifyDrawn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002012 try {
2013 callback.onDrawn();
2014 } catch (RemoteException e) {
2015 Slog.w(TAG, "Exception calling onDrawn():", e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002016 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002017 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002018 }
Jeff Sharkey054340d2011-09-01 22:28:03 -07002019
Jorim Jaggif8d77da2014-11-11 16:59:12 +01002020 private void resetKeyguardDonePendingLocked() {
2021 mKeyguardDonePending = false;
2022 mHandler.removeMessages(KEYGUARD_DONE_PENDING_TIMEOUT);
2023 }
2024
Jim Miller2967f482016-01-07 15:05:32 -08002025 @Override
Jim Millere5f910a2013-10-16 18:15:46 -07002026 public void onBootCompleted() {
2027 mUpdateMonitor.dispatchBootCompleted();
Jason Monkcf5a9532014-09-17 16:22:19 -04002028 synchronized (this) {
2029 mBootCompleted = true;
2030 if (mBootSendUserPresent) {
2031 sendUserPresentBroadcast();
2032 }
2033 }
Jim Millere5f910a2013-10-16 18:15:46 -07002034 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002035
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002036 public void onWakeAndUnlocking() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002037 Trace.beginSection("KeyguardViewMediator#onWakeAndUnlocking");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002038 mWakeAndUnlocking = true;
Jorim Jaggi241ae102016-11-02 21:57:33 -07002039 keyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07002040 Trace.endSection();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002041 }
2042
Jason Monk2a6ea9c2017-01-26 11:14:51 -05002043 public StatusBarKeyguardViewManager registerStatusBar(StatusBar statusBar,
Lucas Dupinbc9aac12018-03-04 20:18:15 -08002044 ViewGroup container, NotificationPanelView panelView,
2045 FingerprintUnlockController fingerprintUnlockController) {
2046 mStatusBarKeyguardViewManager.registerStatusBar(statusBar, container, panelView,
Lucas Dupin9e3fa102017-11-08 17:16:55 -08002047 fingerprintUnlockController, mDismissCallbackRegistry);
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002048 return mStatusBarKeyguardViewManager;
2049 }
2050
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002051 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002052 Trace.beginSection("KeyguardViewMediator#startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002053 Message msg = mHandler.obtainMessage(START_KEYGUARD_EXIT_ANIM,
2054 new StartKeyguardExitAnimParams(startTime, fadeoutDuration));
Jorim Jaggi0d674622014-05-21 01:34:15 +02002055 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07002056 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02002057 }
2058
Andrew Zengb4045d32017-03-16 17:25:07 -07002059 public void onShortPowerPressedGoHome() {
2060 // do nothing
2061 }
2062
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002063 public ViewMediatorCallback getViewMediatorCallback() {
2064 return mViewMediatorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002065 }
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002066
Xiyuan Xia1b30f792016-01-06 08:50:30 -08002067 public LockPatternUtils getLockPatternUtils() {
2068 return mLockPatternUtils;
2069 }
2070
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002071 @Override
2072 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
2073 pw.print(" mSystemReady: "); pw.println(mSystemReady);
2074 pw.print(" mBootCompleted: "); pw.println(mBootCompleted);
2075 pw.print(" mBootSendUserPresent: "); pw.println(mBootSendUserPresent);
2076 pw.print(" mExternallyEnabled: "); pw.println(mExternallyEnabled);
Adrian Roos1f8025a2016-12-27 10:12:13 -08002077 pw.print(" mShuttingDown: "); pw.println(mShuttingDown);
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002078 pw.print(" mNeedToReshowWhenReenabled: "); pw.println(mNeedToReshowWhenReenabled);
2079 pw.print(" mShowing: "); pw.println(mShowing);
2080 pw.print(" mInputRestricted: "); pw.println(mInputRestricted);
2081 pw.print(" mOccluded: "); pw.println(mOccluded);
2082 pw.print(" mDelayedShowingSequence: "); pw.println(mDelayedShowingSequence);
2083 pw.print(" mExitSecureCallback: "); pw.println(mExitSecureCallback);
2084 pw.print(" mDeviceInteractive: "); pw.println(mDeviceInteractive);
2085 pw.print(" mGoingToSleep: "); pw.println(mGoingToSleep);
2086 pw.print(" mHiding: "); pw.println(mHiding);
2087 pw.print(" mWaitingUntilKeyguardVisible: "); pw.println(mWaitingUntilKeyguardVisible);
2088 pw.print(" mKeyguardDonePending: "); pw.println(mKeyguardDonePending);
2089 pw.print(" mHideAnimationRun: "); pw.println(mHideAnimationRun);
2090 pw.print(" mPendingReset: "); pw.println(mPendingReset);
2091 pw.print(" mPendingLock: "); pw.println(mPendingLock);
2092 pw.print(" mWakeAndUnlocking: "); pw.println(mWakeAndUnlocking);
2093 pw.print(" mDrawnCallback: "); pw.println(mDrawnCallback);
2094 }
2095
Lucas Dupin47a65c72018-02-15 14:16:18 -08002096 public void setAodShowing(boolean aodShowing) {
2097 setShowingLocked(mShowing, aodShowing);
2098 }
2099
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002100 private static class StartKeyguardExitAnimParams {
2101
2102 long startTime;
2103 long fadeoutDuration;
2104
2105 private StartKeyguardExitAnimParams(long startTime, long fadeoutDuration) {
2106 this.startTime = startTime;
2107 this.fadeoutDuration = fadeoutDuration;
2108 }
2109 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002110
Lucas Dupin47a65c72018-02-15 14:16:18 -08002111 private void setShowingLocked(boolean showing, boolean aodShowing) {
2112 setShowingLocked(showing, aodShowing, mSecondaryDisplayShowing,
2113 false /* forceCallbacks */);
Jorim Jaggie8f321e2016-11-07 16:48:31 -08002114 }
2115
Lucas Dupin47a65c72018-02-15 14:16:18 -08002116 private void setShowingLocked(boolean showing, boolean aodShowing, int secondaryDisplayShowing,
2117 boolean forceCallbacks) {
2118 final boolean notifyDefaultDisplayCallbacks = showing != mShowing
2119 || aodShowing != mAodShowing || forceCallbacks;
David Stevens53a39ea2017-08-23 18:41:49 -07002120 if (notifyDefaultDisplayCallbacks || secondaryDisplayShowing != mSecondaryDisplayShowing) {
Jim Millerab954542014-10-10 18:21:49 -07002121 mShowing = showing;
Lucas Dupin47a65c72018-02-15 14:16:18 -08002122 mAodShowing = aodShowing;
David Stevens53a39ea2017-08-23 18:41:49 -07002123 mSecondaryDisplayShowing = secondaryDisplayShowing;
2124 if (notifyDefaultDisplayCallbacks) {
2125 notifyDefaultDisplayCallbacks(showing);
2126 }
Lucas Dupin47a65c72018-02-15 14:16:18 -08002127 updateActivityLockScreenState(showing, aodShowing, secondaryDisplayShowing);
David Stevens53a39ea2017-08-23 18:41:49 -07002128 }
2129 }
2130
2131 private void notifyDefaultDisplayCallbacks(boolean showing) {
2132 int size = mKeyguardStateCallbacks.size();
2133 for (int i = size - 1; i >= 0; i--) {
2134 IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
2135 try {
2136 callback.onShowingStateChanged(showing);
2137 } catch (RemoteException e) {
2138 Slog.w(TAG, "Failed to call onShowingStateChanged", e);
2139 if (e instanceof DeadObjectException) {
2140 mKeyguardStateCallbacks.remove(callback);
Jim Millerab954542014-10-10 18:21:49 -07002141 }
Jim Millerab954542014-10-10 18:21:49 -07002142 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002143 }
David Stevens53a39ea2017-08-23 18:41:49 -07002144 updateInputRestrictedLocked();
2145 mUiOffloadThread.submit(() -> {
2146 mTrustManager.reportKeyguardShowingChanged();
2147 });
Adrian Roos481a6df2014-11-20 19:48:56 +01002148 }
Jim Millerab954542014-10-10 18:21:49 -07002149
Adrian Roosd88eb262016-08-04 14:50:48 -07002150 private void notifyTrustedChangedLocked(boolean trusted) {
2151 int size = mKeyguardStateCallbacks.size();
2152 for (int i = size - 1; i >= 0; i--) {
2153 try {
2154 mKeyguardStateCallbacks.get(i).onTrustedChanged(trusted);
2155 } catch (RemoteException e) {
2156 Slog.w(TAG, "Failed to call notifyTrustedChangedLocked", e);
2157 if (e instanceof DeadObjectException) {
2158 mKeyguardStateCallbacks.remove(i);
2159 }
2160 }
2161 }
2162 }
2163
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002164 private void notifyHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
2165 int size = mKeyguardStateCallbacks.size();
2166 for (int i = size - 1; i >= 0; i--) {
2167 try {
2168 mKeyguardStateCallbacks.get(i).onHasLockscreenWallpaperChanged(
2169 hasLockscreenWallpaper);
2170 } catch (RemoteException e) {
2171 Slog.w(TAG, "Failed to call onHasLockscreenWallpaperChanged", e);
2172 if (e instanceof DeadObjectException) {
2173 mKeyguardStateCallbacks.remove(i);
2174 }
2175 }
2176 }
2177 }
2178
Jim Millerab954542014-10-10 18:21:49 -07002179 public void addStateMonitorCallback(IKeyguardStateCallback callback) {
2180 synchronized (this) {
2181 mKeyguardStateCallbacks.add(callback);
2182 try {
2183 callback.onSimSecureStateChanged(mUpdateMonitor.isSimPinSecure());
2184 callback.onShowingStateChanged(mShowing);
Adrian Roos4a963ac2015-04-24 16:04:53 -07002185 callback.onInputRestrictedStateChanged(mInputRestricted);
Adrian Roosd88eb262016-08-04 14:50:48 -07002186 callback.onTrustedChanged(mUpdateMonitor.getUserHasTrust(
2187 KeyguardUpdateMonitor.getCurrentUser()));
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002188 callback.onHasLockscreenWallpaperChanged(mUpdateMonitor.hasLockscreenWallpaper());
Jim Millerab954542014-10-10 18:21:49 -07002189 } catch (RemoteException e) {
Adrian Roosd88eb262016-08-04 14:50:48 -07002190 Slog.w(TAG, "Failed to call to IKeyguardStateCallback", e);
Jim Millerab954542014-10-10 18:21:49 -07002191 }
2192 }
2193 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08002194
2195 private static class DismissMessage {
2196 private final CharSequence mMessage;
2197 private final IKeyguardDismissCallback mCallback;
2198
2199 DismissMessage(IKeyguardDismissCallback callback, CharSequence message) {
2200 mCallback = callback;
2201 mMessage = message;
2202 }
2203
2204 public IKeyguardDismissCallback getCallback() {
2205 return mCallback;
2206 }
2207
2208 public CharSequence getMessage() {
2209 return mMessage;
2210 }
2211 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002212}