blob: ca92d3570ff7a328de0bb0d11a3ecaab40633eab [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);
Jim Miller52a61332014-11-12 19:29:51 -0800505 break;
Jim Millerbbf1a742012-07-17 18:30:30 -0700506 }
507 }
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000508
Adrian Roose92de952016-12-13 12:07:09 -0800509 private void onSimAbsentLocked() {
Adrian Roos1f8025a2016-12-27 10:12:13 -0800510 if (isSecure() && mLockWhenSimRemoved && !mShuttingDown) {
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800511 mLockWhenSimRemoved = false;
512 MetricsLogger.action(mContext,
513 MetricsProto.MetricsEvent.ACTION_LOCK_BECAUSE_SIM_REMOVED, mShowing);
514 if (!mShowing) {
Adrian Roose92de952016-12-13 12:07:09 -0800515 Log.i(TAG, "SIM removed, showing keyguard");
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800516 doKeyguardLocked(null);
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800517 }
518 }
519 }
520
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000521 @Override
522 public void onFingerprintAuthFailed() {
523 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
524 if (mLockPatternUtils.isSecure(currentUser)) {
525 mLockPatternUtils.getDevicePolicyManager().reportFailedFingerprintAttempt(
526 currentUser);
527 }
528 }
529
530 @Override
531 public void onFingerprintAuthenticated(int userId) {
532 if (mLockPatternUtils.isSecure(userId)) {
533 mLockPatternUtils.getDevicePolicyManager().reportSuccessfulFingerprintAttempt(
534 userId);
535 }
536 }
Adrian Roosd88eb262016-08-04 14:50:48 -0700537
538 @Override
539 public void onTrustChanged(int userId) {
540 if (userId == KeyguardUpdateMonitor.getCurrentUser()) {
541 synchronized (KeyguardViewMediator.this) {
542 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(userId));
543 }
544 }
545 }
546
Jorim Jaggid11d1a92016-08-16 16:02:32 -0700547 @Override
548 public void onHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
549 synchronized (KeyguardViewMediator.this) {
550 notifyHasLockscreenWallpaperChanged(hasLockscreenWallpaper);
551 }
552 }
Jim Millerb0304762012-03-13 20:01:25 -0700553 };
554
Jim Millerdcb3d842012-08-23 19:18:12 -0700555 ViewMediatorCallback mViewMediatorCallback = new ViewMediatorCallback() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100556
Jim Miller2967f482016-01-07 15:05:32 -0800557 @Override
Jeff Brownc7505bc2012-10-05 21:58:15 -0700558 public void userActivity() {
559 KeyguardViewMediator.this.userActivity();
560 }
561
Jim Miller2967f482016-01-07 15:05:32 -0800562 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700563 public void keyguardDone(boolean strongAuth, int targetUserId) {
564 if (targetUserId != ActivityManager.getCurrentUser()) {
565 return;
566 }
567
Jorim Jaggi241ae102016-11-02 21:57:33 -0700568 tryKeyguardDone();
Jim Millerdcb3d842012-08-23 19:18:12 -0700569 }
570
Jim Miller2967f482016-01-07 15:05:32 -0800571 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700572 public void keyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700573 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDoneDrawing");
Jim Millerdcb3d842012-08-23 19:18:12 -0700574 mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700575 Trace.endSection();
Jim Millerdcb3d842012-08-23 19:18:12 -0700576 }
577
578 @Override
579 public void setNeedsInput(boolean needsInput) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100580 mStatusBarKeyguardViewManager.setNeedsInput(needsInput);
Jim Millerdcb3d842012-08-23 19:18:12 -0700581 }
Jeff Brownc7505bc2012-10-05 21:58:15 -0700582
583 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700584 public void keyguardDonePending(boolean strongAuth, int targetUserId) {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700585 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDonePending");
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700586 if (targetUserId != ActivityManager.getCurrentUser()) {
Nick Desaulniersaeb2e1e2016-07-27 15:36:01 -0700587 Trace.endSection();
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700588 return;
589 }
590
John Spurlock34c4fe52012-11-07 10:12:29 -0500591 mKeyguardDonePending = true;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200592 mHideAnimationRun = true;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700593 mHideAnimationRunning = true;
594 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100595 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_PENDING_TIMEOUT,
596 KEYGUARD_DONE_PENDING_TIMEOUT_MS);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700597 Trace.endSection();
John Spurlock34c4fe52012-11-07 10:12:29 -0500598 }
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800599
600 @Override
601 public void keyguardGone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700602 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardGone");
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800603 mKeyguardDisplayManager.hide();
Nick Desaulniers1d396752016-07-25 15:05:33 -0700604 Trace.endSection();
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800605 }
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200606
607 @Override
608 public void readyForKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700609 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#readyForKeyguardDone");
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200610 if (mKeyguardDonePending) {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700611 mKeyguardDonePending = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700612 tryKeyguardDone();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200613 }
Nick Desaulniers1d396752016-07-25 15:05:33 -0700614 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200615 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200616
617 @Override
Andrew Lee72b46d42015-01-30 13:23:21 -0800618 public void resetKeyguard() {
619 resetStateLocked();
620 }
621
622 @Override
Matthew Ng66f0b702017-12-08 12:58:42 -0800623 public void onBouncerVisiblityChanged(boolean shown) {
624 synchronized (KeyguardViewMediator.this) {
625 adjustStatusBarLocked(shown);
626 }
627 }
628
629 @Override
Adrian Roos49e057d2014-08-13 17:14:51 +0200630 public void playTrustedSound() {
631 KeyguardViewMediator.this.playTrustedSound();
632 }
Jim Millerab954542014-10-10 18:21:49 -0700633
634 @Override
Adrian Roos94e15a52015-04-16 12:23:18 -0700635 public boolean isScreenOn() {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700636 return mDeviceInteractive;
Adrian Roos94e15a52015-04-16 12:23:18 -0700637 }
Selim Cinek3122fa82015-06-18 01:38:59 -0700638
639 @Override
640 public int getBouncerPromptReason() {
641 int currentUser = ActivityManager.getCurrentUser();
Adrian Roosc13723f2016-01-12 20:29:03 +0100642 boolean trust = mTrustManager.isTrustUsuallyManaged(currentUser);
643 boolean fingerprint = mUpdateMonitor.isUnlockWithFingerprintPossible(currentUser);
644 boolean any = trust || fingerprint;
645 KeyguardUpdateMonitor.StrongAuthTracker strongAuthTracker =
646 mUpdateMonitor.getStrongAuthTracker();
647 int strongAuth = strongAuthTracker.getStrongAuthForUser(currentUser);
648
649 if (any && !strongAuthTracker.hasUserAuthenticatedSinceBoot()) {
Selim Cinek3122fa82015-06-18 01:38:59 -0700650 return KeyguardSecurityView.PROMPT_REASON_RESTART;
Michal Karpinskic52f8672016-11-18 11:32:45 +0000651 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_TIMEOUT) != 0) {
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700652 return KeyguardSecurityView.PROMPT_REASON_TIMEOUT;
Adrian Roosc13723f2016-01-12 20:29:03 +0100653 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW) != 0) {
654 return KeyguardSecurityView.PROMPT_REASON_DEVICE_ADMIN;
655 } else if (trust && (strongAuth & SOME_AUTH_REQUIRED_AFTER_USER_REQUEST) != 0) {
656 return KeyguardSecurityView.PROMPT_REASON_USER_REQUEST;
657 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_LOCKOUT) != 0) {
658 return KeyguardSecurityView.PROMPT_REASON_AFTER_LOCKOUT;
Selim Cinek3122fa82015-06-18 01:38:59 -0700659 }
660 return KeyguardSecurityView.PROMPT_REASON_NONE;
661 }
David Stevens53a39ea2017-08-23 18:41:49 -0700662
663 @Override
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800664 public CharSequence consumeCustomMessage() {
665 final CharSequence message = mCustomMessage;
666 mCustomMessage = null;
667 return message;
668 }
669
670 @Override
David Stevens53a39ea2017-08-23 18:41:49 -0700671 public void onSecondaryDisplayShowingChanged(int displayId) {
672 synchronized (KeyguardViewMediator.this) {
Lucas Dupin47a65c72018-02-15 14:16:18 -0800673 setShowingLocked(mShowing, mAodShowing, displayId, false);
David Stevens53a39ea2017-08-23 18:41:49 -0700674 }
675 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700676 };
677
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200678 public void userActivity() {
Jeff Brown3dc524b2012-09-30 19:49:11 -0700679 mPM.userActivity(SystemClock.uptimeMillis(), false);
Jim Millerdcb3d842012-08-23 19:18:12 -0700680 }
681
Amith Yamasanieb437d42016-04-29 09:31:25 -0700682 boolean mustNotUnlockCurrentUser() {
Christine Franks338c6ed2017-08-08 09:39:16 -0700683 return UserManager.isSplitSystemUser()
Amith Yamasanieb437d42016-04-29 09:31:25 -0700684 && KeyguardUpdateMonitor.getCurrentUser() == UserHandle.USER_SYSTEM;
685 }
686
Jim Millerab954542014-10-10 18:21:49 -0700687 private void setupLocked() {
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200688 mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
Adrian Roos481a6df2014-11-20 19:48:56 +0100689 mTrustManager = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE);
690
Mike Lockwood674d3e42009-10-06 09:28:54 -0400691 mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
692 mShowKeyguardWakeLock.setReferenceCounted(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800693
Adrian Roos1f8025a2016-12-27 10:12:13 -0800694 IntentFilter filter = new IntentFilter();
Adrian Roos1f8025a2016-12-27 10:12:13 -0800695 filter.addAction(Intent.ACTION_SHUTDOWN);
696 mContext.registerReceiver(mBroadcastReceiver, filter);
Jim Millerbbf1a742012-07-17 18:30:30 -0700697
Kevin Chyn18e91aa2018-04-11 12:55:45 -0700698 final IntentFilter delayedActionFilter = new IntentFilter();
699 delayedActionFilter.addAction(DELAYED_KEYGUARD_ACTION);
700 delayedActionFilter.addAction(DELAYED_LOCK_PROFILE_ACTION);
701 mContext.registerReceiver(mDelayedLockBroadcastReceiver, delayedActionFilter,
702 SYSTEMUI_PERMISSION, null /* scheduler */);
703
David Stevens53a39ea2017-08-23 18:41:49 -0700704 mKeyguardDisplayManager = new KeyguardDisplayManager(mContext, mViewMediatorCallback);
Jim Miller31921482013-11-06 20:43:55 -0800705
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200706 mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800707
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200708 mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800709
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200710 mLockPatternUtils = new LockPatternUtils(mContext);
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700711 KeyguardUpdateMonitor.setCurrentUser(ActivityManager.getCurrentUser());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800712
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200713 // Assume keyguard is showing (unless it's disabled) until we know for sure, unless Keyguard
714 // is disabled.
715 if (mContext.getResources().getBoolean(
716 com.android.keyguard.R.bool.config_enableKeyguardService)) {
717 setShowingLocked(!shouldWaitForProvisioning()
718 && !mLockPatternUtils.isLockScreenDisabled(
David Stevens53a39ea2017-08-23 18:41:49 -0700719 KeyguardUpdateMonitor.getCurrentUser()),
Lucas Dupin47a65c72018-02-15 14:16:18 -0800720 mAodShowing, mSecondaryDisplayShowing, true /* forceCallbacks */);
Leif Hendrik Wildenc6dc1c92018-02-01 10:54:15 -0800721 } else {
722 // The system's keyguard is disabled or missing.
Lucas Dupin47a65c72018-02-15 14:16:18 -0800723 setShowingLocked(false, mAodShowing, mSecondaryDisplayShowing, true);
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200724 }
Jim Millere5f17ab2013-11-13 15:40:48 -0800725
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800726 mStatusBarKeyguardViewManager =
727 SystemUIFactory.getInstance().createStatusBarKeyguardViewManager(mContext,
728 mViewMediatorCallback, mLockPatternUtils);
Daniel Sandler687a3272010-03-13 15:44:47 -0500729 final ContentResolver cr = mContext.getContentResolver();
Marco Nelissend5545bd2011-09-29 12:49:17 -0700730
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700731 mDeviceInteractive = mPM.isInteractive();
Daniel Hansson4b716862012-03-29 11:02:05 +0200732
Marco Nelissend5545bd2011-09-29 12:49:17 -0700733 mLockSounds = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
Jim Millerb14288d2012-09-30 18:25:05 -0700734 String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700735 if (soundPath != null) {
736 mLockSoundId = mLockSounds.load(soundPath, 1);
737 }
738 if (soundPath == null || mLockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700739 Log.w(TAG, "failed to load lock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700740 }
Jim Millerb14288d2012-09-30 18:25:05 -0700741 soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700742 if (soundPath != null) {
743 mUnlockSoundId = mLockSounds.load(soundPath, 1);
744 }
745 if (soundPath == null || mUnlockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700746 Log.w(TAG, "failed to load unlock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700747 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200748 soundPath = Settings.Global.getString(cr, Settings.Global.TRUSTED_SOUND);
749 if (soundPath != null) {
750 mTrustedSoundId = mLockSounds.load(soundPath, 1);
751 }
752 if (soundPath == null || mTrustedSoundId == 0) {
753 Log.w(TAG, "failed to load trusted sound from " + soundPath);
754 }
755
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200756 int lockSoundDefaultAttenuation = mContext.getResources().getInteger(
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700757 com.android.internal.R.integer.config_lockSoundVolumeDb);
Jean-Michel Trivif2b0c112012-07-09 11:59:11 -0700758 mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20);
Adrian Roos0002a452014-07-03 13:46:07 +0200759
760 mHideAnimation = AnimationUtils.loadAnimation(mContext,
761 com.android.internal.R.anim.lock_screen_behind_enter);
Robin Leec41f6ec2017-01-10 17:02:34 +0000762
763 mWorkLockController = new WorkLockActivityController(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800764 }
765
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200766 @Override
767 public void start() {
Jim Millerab954542014-10-10 18:21:49 -0700768 synchronized (this) {
769 setupLocked();
770 }
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200771 putComponent(KeyguardViewMediator.class, this);
772 }
773
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800774 /**
775 * Let us know that the system is ready after startup.
776 */
777 public void onSystemReady() {
778 synchronized (this) {
779 if (DEBUG) Log.d(TAG, "onSystemReady");
780 mSystemReady = true;
Jim Miller5ecd8112013-01-09 18:50:26 -0800781 doKeyguardLocked(null);
Selim Cinekedd32b82015-06-23 22:05:58 -0400782 mUpdateMonitor.registerCallback(mUpdateCallback);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800783 }
Jim Miller3fd47af2012-09-21 19:55:27 -0700784 // Most services aren't available until the system reaches the ready state, so we
785 // send it here when the device first boots.
786 maybeSendUserPresentBroadcast();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800787 }
788
789 /**
790 * Called to let us know the screen was turned off.
Adrian Roose99bc052017-11-20 17:55:31 +0100791 * @param why either {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_USER} or
792 * {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_TIMEOUT}.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800793 */
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700794 public void onStartedGoingToSleep(int why) {
795 if (DEBUG) Log.d(TAG, "onStartedGoingToSleep(" + why + ")");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800796 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700797 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700798 mGoingToSleep = true;
John Spurlock14adfe42012-11-08 10:29:26 -0500799
Jim Millera4edd152012-01-06 18:24:04 -0800800 // Lock immediately based on setting if secure (user has a pin/pattern/password).
801 // This also "locks" the device when not secure to provide easy access to the
802 // camera while preventing unwanted input.
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700803 int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jim Millera4edd152012-01-06 18:24:04 -0800804 final boolean lockImmediately =
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700805 mLockPatternUtils.getPowerButtonInstantlyLocks(currentUser)
806 || !mLockPatternUtils.isSecure(currentUser);
Clara Bayarri56878a92015-10-29 15:43:55 +0000807 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000808 mLockLater = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800809 if (mExitSecureCallback != null) {
810 if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled");
Jim Miller5ecd8112013-01-09 18:50:26 -0800811 try {
812 mExitSecureCallback.onKeyguardExitResult(false);
813 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800814 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800815 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800816 mExitSecureCallback = null;
817 if (!mExternallyEnabled) {
Jim Miller9c20d0e2010-01-20 15:00:23 -0800818 hideLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800819 }
820 } else if (mShowing) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700821 mPendingReset = true;
Adrian Roose99bc052017-11-20 17:55:31 +0100822 } else if ((why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_TIMEOUT && timeout > 0)
823 || (why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER && !lockImmediately)) {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700824 doKeyguardLaterLocked(timeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000825 mLockLater = true;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700826 } else if (!mLockPatternUtils.isLockScreenDisabled(currentUser)) {
827 mPendingLock = true;
828 }
829
Jorim Jaggi853cbe32015-06-04 16:31:54 -0700830 if (mPendingLock) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700831 playSounds(true);
832 }
833 }
Jorim Jaggi95e40382015-09-16 15:53:42 -0700834 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedGoingToSleep(why);
Jorim Jaggi18f18ae2015-09-10 15:48:21 -0700835 notifyStartedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700836 }
837
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700838 public void onFinishedGoingToSleep(int why, boolean cameraGestureTriggered) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700839 if (DEBUG) Log.d(TAG, "onFinishedGoingToSleep(" + why + ")");
840 synchronized (this) {
841 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700842 mGoingToSleep = false;
Adrian Roose4cb6c8a2017-07-19 18:08:07 +0200843 mWakeAndUnlocking = false;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700844
845 resetKeyguardDonePendingLocked();
846 mHideAnimationRun = false;
847
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700848 notifyFinishedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700849
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700850 if (cameraGestureTriggered) {
851 Log.i(TAG, "Camera gesture was triggered, preventing Keyguard locking.");
852
853 // Just to make sure, make sure the device is awake.
854 mContext.getSystemService(PowerManager.class).wakeUp(SystemClock.uptimeMillis(),
855 "com.android.systemui:CAMERA_GESTURE_PREVENT_LOCK");
856 mPendingLock = false;
857 mPendingReset = false;
858 }
859
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700860 if (mPendingReset) {
861 resetStateLocked();
862 mPendingReset = false;
863 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000864
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700865 if (mPendingLock) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800866 doKeyguardLocked(null);
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700867 mPendingLock = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800868 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000869
870 // We do not have timeout and power button instant lock setting for profile lock.
871 // So we use the personal setting if there is any. But if there is no device
872 // we need to make sure we lock it immediately when the screen is off.
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700873 if (!mLockLater && !cameraGestureTriggered) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000874 doKeyguardForChildProfilesLocked();
875 }
876
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800877 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700878 KeyguardUpdateMonitor.getInstance(mContext).dispatchFinishedGoingToSleep(why);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800879 }
880
Clara Bayarri56878a92015-10-29 15:43:55 +0000881 private long getLockTimeout(int userId) {
Jeff Brown6aaf2952012-10-05 16:01:08 -0700882 // if the screen turned off because of timeout or the user hit the power button
883 // and we don't need to lock immediately, set an alarm
884 // to enable it a little bit later (i.e, give the user a chance
885 // to turn the screen back on within a certain window without
886 // having to unlock the screen)
887 final ContentResolver cr = mContext.getContentResolver();
888
Jeff Brown6aaf2952012-10-05 16:01:08 -0700889 // From SecuritySettings
890 final long lockAfterTimeout = Settings.Secure.getInt(cr,
891 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT,
892 KEYGUARD_LOCK_AFTER_DELAY_DEFAULT);
893
894 // From DevicePolicyAdmin
895 final long policyTimeout = mLockPatternUtils.getDevicePolicyManager()
Pavel Grafov28939982017-10-03 15:11:52 +0100896 .getMaximumTimeToLock(null, userId);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700897
898 long timeout;
Clara Bayarri56878a92015-10-29 15:43:55 +0000899
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000900 if (policyTimeout <= 0) {
Clara Bayarri56878a92015-10-29 15:43:55 +0000901 timeout = lockAfterTimeout;
902 } else {
903 // From DisplaySettings
904 long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT,
905 KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT);
906
Jeff Brown6aaf2952012-10-05 16:01:08 -0700907 // policy in effect. Make sure we don't go beyond policy limit.
908 displayTimeout = Math.max(displayTimeout, 0); // ignore negative values
909 timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000910 timeout = Math.max(timeout, 0);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700911 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700912 return timeout;
913 }
Jeff Brown6aaf2952012-10-05 16:01:08 -0700914
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700915 private void doKeyguardLaterLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000916 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700917 if (timeout == 0) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800918 doKeyguardLocked(null);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700919 } else {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700920 doKeyguardLaterLocked(timeout);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700921 }
922 }
923
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700924 private void doKeyguardLaterLocked(long timeout) {
925 // Lock in the future
926 long when = SystemClock.elapsedRealtime() + timeout;
927 Intent intent = new Intent(DELAYED_KEYGUARD_ACTION);
928 intent.putExtra("seq", mDelayedShowingSequence);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700929 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700930 PendingIntent sender = PendingIntent.getBroadcast(mContext,
931 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Jim Millera622d3cc2016-03-02 16:02:24 -0800932 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700933 if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = "
934 + mDelayedShowingSequence);
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000935 doKeyguardLaterForChildProfilesLocked();
Clara Bayarri56878a92015-10-29 15:43:55 +0000936 }
Clara Bayarri10ad84a2015-12-01 17:38:05 +0000937
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000938 private void doKeyguardLaterForChildProfilesLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000939 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700940 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
941 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
942 long userTimeout = getLockTimeout(profileId);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000943 if (userTimeout == 0) {
944 doKeyguardForChildProfilesLocked();
945 } else {
946 long userWhen = SystemClock.elapsedRealtime() + userTimeout;
947 Intent lockIntent = new Intent(DELAYED_LOCK_PROFILE_ACTION);
948 lockIntent.putExtra("seq", mDelayedProfileShowingSequence);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700949 lockIntent.putExtra(Intent.EXTRA_USER_ID, profileId);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700950 lockIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000951 PendingIntent lockSender = PendingIntent.getBroadcast(
952 mContext, 0, lockIntent, PendingIntent.FLAG_CANCEL_CURRENT);
953 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
954 userWhen, lockSender);
955 }
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000956 }
957 }
958 }
959
960 private void doKeyguardForChildProfilesLocked() {
961 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700962 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
963 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
964 lockProfile(profileId);
Clara Bayarri56878a92015-10-29 15:43:55 +0000965 }
966 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700967 }
968
Jeff Brown6aaf2952012-10-05 16:01:08 -0700969 private void cancelDoKeyguardLaterLocked() {
970 mDelayedShowingSequence++;
971 }
972
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000973 private void cancelDoKeyguardForChildProfilesLocked() {
974 mDelayedProfileShowingSequence++;
975 }
976
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800977 /**
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700978 * Let's us know when the device is waking up.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800979 */
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700980 public void onStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700981 Trace.beginSection("KeyguardViewMediator#onStartedWakingUp");
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700982
983 // TODO: Rename all screen off/on references to interactive/sleeping
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800984 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700985 mDeviceInteractive = true;
Jeff Brown6aaf2952012-10-05 16:01:08 -0700986 cancelDoKeyguardLaterLocked();
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000987 cancelDoKeyguardForChildProfilesLocked();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700988 if (DEBUG) Log.d(TAG, "onStartedWakingUp, seq = " + mDelayedShowingSequence);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700989 notifyStartedWakingUp();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800990 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700991 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedWakingUp();
Jim Miller3fd47af2012-09-21 19:55:27 -0700992 maybeSendUserPresentBroadcast();
Nick Desaulniers1d396752016-07-25 15:05:33 -0700993 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -0700994 }
995
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700996 public void onScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700997 Trace.beginSection("KeyguardViewMediator#onScreenTurningOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700998 notifyScreenOn(callback);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700999 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001000 }
1001
1002 public void onScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001003 Trace.beginSection("KeyguardViewMediator#onScreenTurnedOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001004 notifyScreenTurnedOn();
1005 mUpdateMonitor.dispatchScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001006 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001007 }
1008
1009 public void onScreenTurnedOff() {
1010 notifyScreenTurnedOff();
1011 mUpdateMonitor.dispatchScreenTurnedOff();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001012 }
1013
Jim Miller3fd47af2012-09-21 19:55:27 -07001014 private void maybeSendUserPresentBroadcast() {
Adrian Roos8150d2a2015-04-16 17:11:20 -07001015 if (mSystemReady && mLockPatternUtils.isLockScreenDisabled(
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001016 KeyguardUpdateMonitor.getCurrentUser())) {
Jim Miller3fd47af2012-09-21 19:55:27 -07001017 // Lock screen is disabled because the user has set the preference to "None".
1018 // In this case, send out ACTION_USER_PRESENT here instead of in
1019 // handleKeyguardDone()
1020 sendUserPresentBroadcast();
Adrian Roosfb95a812016-06-20 14:58:59 -07001021 } else if (mSystemReady && shouldWaitForProvisioning()) {
1022 // Skipping the lockscreen because we're not yet provisioned, but we still need to
1023 // notify the StrongAuthTracker that it's now safe to run trust agents, in case the
1024 // user sets a credential later.
1025 getLockPatternUtils().userPresent(KeyguardUpdateMonitor.getCurrentUser());
Jim Miller3fd47af2012-09-21 19:55:27 -07001026 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001027 }
1028
1029 /**
Jeff Brown6aaf2952012-10-05 16:01:08 -07001030 * A dream started. We should lock after the usual screen-off lock timeout but only
1031 * if there is a secure lock pattern.
1032 */
1033 public void onDreamingStarted() {
Selim Cinek99415392016-09-09 14:58:41 -07001034 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001035 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001036 if (mDeviceInteractive
1037 && mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001038 doKeyguardLaterLocked();
1039 }
1040 }
1041 }
1042
1043 /**
1044 * A dream stopped.
1045 */
1046 public void onDreamingStopped() {
Selim Cinek99415392016-09-09 14:58:41 -07001047 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001048 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001049 if (mDeviceInteractive) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001050 cancelDoKeyguardLaterLocked();
1051 }
1052 }
1053 }
1054
1055 /**
Adrian Roose99bc052017-11-20 17:55:31 +01001056 * Same semantics as {@link WindowManagerPolicyConstants#enableKeyguard}; provide
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001057 * a way for external stuff to override normal keyguard behavior. For instance
1058 * the phone app disables the keyguard when it receives incoming calls.
1059 */
1060 public void setKeyguardEnabled(boolean enabled) {
1061 synchronized (this) {
1062 if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")");
1063
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001064 mExternallyEnabled = enabled;
1065
1066 if (!enabled && mShowing) {
1067 if (mExitSecureCallback != null) {
1068 if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring");
1069 // we're in the process of handling a request to verify the user
1070 // can get past the keyguard. ignore extraneous requests to disable / reenable
1071 return;
1072 }
1073
1074 // hiding keyguard that is showing, remember to reshow later
1075 if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, "
1076 + "disabling status bar expansion");
1077 mNeedToReshowWhenReenabled = true;
Jim Millerab954542014-10-10 18:21:49 -07001078 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001079 hideLocked();
1080 } else if (enabled && mNeedToReshowWhenReenabled) {
1081 // reenabled after previously hidden, reshow
1082 if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling "
1083 + "status bar expansion");
1084 mNeedToReshowWhenReenabled = false;
Jim Millerab954542014-10-10 18:21:49 -07001085 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001086
1087 if (mExitSecureCallback != null) {
1088 if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting");
Jim Miller5ecd8112013-01-09 18:50:26 -08001089 try {
1090 mExitSecureCallback.onKeyguardExitResult(false);
1091 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001092 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001093 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001094 mExitSecureCallback = null;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001095 resetStateLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001096 } else {
Adam Cohenf7522022012-10-03 20:03:18 -07001097 showLocked(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001098
1099 // block until we know the keygaurd is done drawing (and post a message
1100 // to unblock us after a timeout so we don't risk blocking too long
1101 // and causing an ANR).
1102 mWaitingUntilKeyguardVisible = true;
1103 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS);
1104 if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false");
1105 while (mWaitingUntilKeyguardVisible) {
1106 try {
1107 wait();
1108 } catch (InterruptedException e) {
1109 Thread.currentThread().interrupt();
1110 }
1111 }
1112 if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible");
1113 }
1114 }
1115 }
1116 }
1117
1118 /**
1119 * @see android.app.KeyguardManager#exitKeyguardSecurely
1120 */
Jim Miller25190572013-02-28 17:36:24 -08001121 public void verifyUnlock(IKeyguardExitCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001122 Trace.beginSection("KeyguardViewMediator#verifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001123 synchronized (this) {
1124 if (DEBUG) Log.d(TAG, "verifyUnlock");
Jim Millerb256e4e22014-10-31 17:27:13 -07001125 if (shouldWaitForProvisioning()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001126 // don't allow this api when the device isn't provisioned
1127 if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned");
Jim Miller5ecd8112013-01-09 18:50:26 -08001128 try {
Jim Miller25190572013-02-28 17:36:24 -08001129 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001130 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001131 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001132 }
Mike Lockwood5d258b62009-12-02 13:50:45 -05001133 } else if (mExternallyEnabled) {
1134 // this only applies when the user has externally disabled the
1135 // keyguard. this is unexpected and means the user is not
1136 // using the api properly.
1137 Log.w(TAG, "verifyUnlock called when not externally disabled");
Jim Miller5ecd8112013-01-09 18:50:26 -08001138 try {
Jim Miller25190572013-02-28 17:36:24 -08001139 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001140 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001141 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001142 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001143 } else if (mExitSecureCallback != null) {
1144 // already in progress with someone else
Jim Miller5ecd8112013-01-09 18:50:26 -08001145 try {
Jim Miller25190572013-02-28 17:36:24 -08001146 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001147 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001148 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001149 }
Jorim Jaggi302475e2015-09-22 12:44:47 -07001150 } else if (!isSecure()) {
1151
1152 // Keyguard is not secure, no need to do anything, and we don't need to reshow
1153 // the Keyguard after the client releases the Keyguard lock.
1154 mExternallyEnabled = true;
1155 mNeedToReshowWhenReenabled = false;
1156 updateInputRestricted();
1157 try {
1158 callback.onKeyguardExitResult(true);
1159 } catch (RemoteException e) {
1160 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1161 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001162 } else {
Jorim Jaggi302475e2015-09-22 12:44:47 -07001163
1164 // Since we prevent apps from hiding the Keyguard if we are secure, this should be
1165 // a no-op as well.
1166 try {
1167 callback.onKeyguardExitResult(false);
1168 } catch (RemoteException e) {
1169 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1170 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001171 }
1172 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001173 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001174 }
1175
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001176 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001177 * Is the keyguard currently showing and not being force hidden?
Mike Lockwood09a40402009-11-08 00:33:23 -05001178 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001179 public boolean isShowingAndNotOccluded() {
1180 return mShowing && !mOccluded;
1181 }
1182
1183 /**
1184 * Notify us when the keyguard is occluded by another window
1185 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001186 public void setOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001187 Trace.beginSection("KeyguardViewMediator#setOccluded");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001188 if (DEBUG) Log.d(TAG, "setOccluded " + isOccluded);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001189 mHandler.removeMessages(SET_OCCLUDED);
Jorim Jaggi6626f542016-08-22 13:08:44 -07001190 Message msg = mHandler.obtainMessage(SET_OCCLUDED, isOccluded ? 1 : 0, animate ? 1 : 0);
Mike Lockwood9200a392009-11-17 20:25:58 -05001191 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001192 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001193 }
1194
Lucas Dupin2986c152018-04-09 20:49:41 -07001195 public boolean isHiding() {
1196 return mHiding;
1197 }
1198
Mike Lockwood9200a392009-11-17 20:25:58 -05001199 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001200 * Handles SET_OCCLUDED message sent by setOccluded()
Mike Lockwood9200a392009-11-17 20:25:58 -05001201 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001202 private void handleSetOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001203 Trace.beginSection("KeyguardViewMediator#handleSetOccluded");
Mike Lockwood09a40402009-11-08 00:33:23 -05001204 synchronized (KeyguardViewMediator.this) {
Adrian Roosf253eeb2015-04-15 18:03:08 -07001205 if (mHiding && isOccluded) {
1206 // We're in the process of going away but WindowManager wants to show a
1207 // SHOW_WHEN_LOCKED activity instead.
1208 startKeyguardExitAnimation(0, 0);
1209 }
1210
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001211 if (mOccluded != isOccluded) {
1212 mOccluded = isOccluded;
Kevin Chyn2fefd462017-04-28 12:18:19 -07001213 mUpdateMonitor.setKeyguardOccluded(isOccluded);
Selim Cinek2f6272e2017-03-15 16:19:10 -07001214 mStatusBarKeyguardViewManager.setOccluded(isOccluded, animate
1215 && mDeviceInteractive);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001216 adjustStatusBarLocked();
Mike Lockwood9200a392009-11-17 20:25:58 -05001217 }
Mike Lockwood09a40402009-11-08 00:33:23 -05001218 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001219 Trace.endSection();
Mike Lockwood09a40402009-11-08 00:33:23 -05001220 }
1221
1222 /**
Mike Lockwood28569302010-01-28 11:54:40 -05001223 * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout.
1224 * This must be safe to call from any thread and with any window manager locks held.
1225 */
Adam Cohenf7522022012-10-03 20:03:18 -07001226 public void doKeyguardTimeout(Bundle options) {
Mike Lockwood28569302010-01-28 11:54:40 -05001227 mHandler.removeMessages(KEYGUARD_TIMEOUT);
Adam Cohenf7522022012-10-03 20:03:18 -07001228 Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options);
Mike Lockwood28569302010-01-28 11:54:40 -05001229 mHandler.sendMessage(msg);
1230 }
1231
1232 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001233 * Given the state of the keyguard, is the input restricted?
1234 * Input is restricted when the keyguard is showing, or when the keyguard
1235 * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet.
1236 */
1237 public boolean isInputRestricted() {
Adrian Roos9f33d6c2015-06-15 15:58:35 -07001238 return mShowing || mNeedToReshowWhenReenabled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001239 }
1240
Jim Millerab954542014-10-10 18:21:49 -07001241 private void updateInputRestricted() {
1242 synchronized (this) {
1243 updateInputRestrictedLocked();
1244 }
1245 }
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001246
Jim Millerab954542014-10-10 18:21:49 -07001247 private void updateInputRestrictedLocked() {
1248 boolean inputRestricted = isInputRestricted();
1249 if (mInputRestricted != inputRestricted) {
1250 mInputRestricted = inputRestricted;
dooyoung.hwang328472e2015-05-21 16:09:43 +09001251 int size = mKeyguardStateCallbacks.size();
1252 for (int i = size - 1; i >= 0; i--) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001253 final IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001254 try {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001255 callback.onInputRestrictedStateChanged(inputRestricted);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001256 } catch (RemoteException e) {
1257 Slog.w(TAG, "Failed to call onDeviceProvisioned", e);
1258 if (e instanceof DeadObjectException) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001259 mKeyguardStateCallbacks.remove(callback);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001260 }
Jim Millerab954542014-10-10 18:21:49 -07001261 }
Jim Millerab954542014-10-10 18:21:49 -07001262 }
1263 }
1264 }
1265
Dianne Hackbornb446e972009-09-20 15:23:25 -07001266 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001267 * Enable the keyguard if the settings are appropriate.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001268 */
Adam Cohenf7522022012-10-03 20:03:18 -07001269 private void doKeyguardLocked(Bundle options) {
Adrian Roosca8a2162017-08-17 19:00:58 +02001270 if (KeyguardUpdateMonitor.CORE_APPS_ONLY) {
1271 // Don't show keyguard during half-booted cryptkeeper stage.
1272 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because booting to cryptkeeper");
1273 return;
1274 }
1275
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001276 // if another app is disabling us, don't show
1277 if (!mExternallyEnabled) {
1278 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled");
Karl Rosaenab100082009-03-24 22:35:17 -07001279
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001280 // note: we *should* set mNeedToReshowWhenReenabled=true here, but that makes
1281 // for an occasional ugly flicker in this situation:
1282 // 1) receive a call with the screen on (no keyguard) or make a call
1283 // 2) screen times out
1284 // 3) user hits key to turn screen back on
1285 // instead, we reenable the keyguard when we know the screen is off and the call
1286 // ends (see the broadcast receiver below)
1287 // TODO: clean this up when we have better support at the window manager level
1288 // for apps that wish to be on top of the keyguard
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001289 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001290 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001291
1292 // if the keyguard is already showing, don't bother
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001293 if (mStatusBarKeyguardViewManager.isShowing()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001294 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing");
Jorim Jaggi95e89ca2014-11-24 20:12:50 +01001295 resetStateLocked();
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001296 return;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001297 }
1298
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001299 // In split system user mode, we never unlock system user.
Amith Yamasanieb437d42016-04-29 09:31:25 -07001300 if (!mustNotUnlockCurrentUser()
Amith Yamasani27e025b2015-11-06 10:34:41 -08001301 || !mUpdateMonitor.isDeviceProvisioned()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001302
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001303 // if the setup wizard hasn't run yet, don't show
1304 final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", false);
1305 final boolean absent = SubscriptionManager.isValidSubscriptionId(
Adrian Roose92de952016-12-13 12:07:09 -08001306 mUpdateMonitor.getNextSubIdForState(ABSENT));
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001307 final boolean disabled = SubscriptionManager.isValidSubscriptionId(
1308 mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.PERM_DISABLED));
1309 final boolean lockedOrMissing = mUpdateMonitor.isSimPinSecure()
1310 || ((absent || disabled) && requireSim);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001311
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001312 if (!lockedOrMissing && shouldWaitForProvisioning()) {
1313 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned"
1314 + " and the sim is not locked or missing");
1315 return;
1316 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001317
Evan Rosky13a58a92016-07-27 15:51:09 -07001318 boolean forceShow = options != null && options.getBoolean(OPTION_FORCE_SHOW, false);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001319 if (mLockPatternUtils.isLockScreenDisabled(KeyguardUpdateMonitor.getCurrentUser())
Evan Rosky13a58a92016-07-27 15:51:09 -07001320 && !lockedOrMissing && !forceShow) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001321 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off");
1322 return;
1323 }
1324
1325 if (mLockPatternUtils.checkVoldPassword(KeyguardUpdateMonitor.getCurrentUser())) {
1326 if (DEBUG) Log.d(TAG, "Not showing lock screen since just decrypted");
1327 // Without this, settings is not enabled until the lock screen first appears
Lucas Dupin47a65c72018-02-15 14:16:18 -08001328 setShowingLocked(false, mAodShowing);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001329 hideLocked();
1330 return;
1331 }
Paul Lawrence945490c2014-03-27 16:37:28 +00001332 }
1333
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001334 if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");
Adam Cohenf7522022012-10-03 20:03:18 -07001335 showLocked(options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001336 }
1337
Clara Bayarri56878a92015-10-29 15:43:55 +00001338 private void lockProfile(int userId) {
1339 mTrustManager.setDeviceLockedForUser(userId, true);
1340 }
1341
Jim Millerb256e4e22014-10-31 17:27:13 -07001342 private boolean shouldWaitForProvisioning() {
1343 return !mUpdateMonitor.isDeviceProvisioned() && !isSecure();
1344 }
1345
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001346 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001347 * Dismiss the keyguard through the security layers.
Jorim Jaggi241ae102016-11-02 21:57:33 -07001348 * @param callback Callback to be informed about the result
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001349 * @param message Message that should be displayed on the bouncer.
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001350 */
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001351 private void handleDismiss(IKeyguardDismissCallback callback, CharSequence message) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001352 if (mShowing) {
1353 if (callback != null) {
1354 mDismissCallbackRegistry.addCallback(callback);
1355 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001356 mCustomMessage = message;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001357 mStatusBarKeyguardViewManager.dismissAndCollapse();
Jorim Jaggi241ae102016-11-02 21:57:33 -07001358 } else if (callback != null) {
1359 new DismissCallbackWrapper(callback).notifyDismissError();
Jim Miller87d03662012-11-05 20:28:09 -08001360 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001361 }
1362
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001363 public void dismiss(IKeyguardDismissCallback callback, CharSequence message) {
1364 mHandler.obtainMessage(DISMISS, new DismissMessage(callback, message)).sendToTarget();
Jim Miller60013792013-10-03 18:31:34 -07001365 }
1366
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001367 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001368 * Send message to keyguard telling it to reset its state.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001369 * @see #handleReset
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001370 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001371 private void resetStateLocked() {
Jim Miller4894a012013-04-03 15:23:55 -07001372 if (DEBUG) Log.e(TAG, "resetStateLocked");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001373 Message msg = mHandler.obtainMessage(RESET);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001374 mHandler.sendMessage(msg);
1375 }
1376
1377 /**
1378 * Send message to keyguard telling it to verify unlock
1379 * @see #handleVerifyUnlock()
1380 */
1381 private void verifyUnlockLocked() {
1382 if (DEBUG) Log.d(TAG, "verifyUnlockLocked");
1383 mHandler.sendEmptyMessage(VERIFY_UNLOCK);
1384 }
1385
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001386 private void notifyStartedGoingToSleep() {
1387 if (DEBUG) Log.d(TAG, "notifyStartedGoingToSleep");
1388 mHandler.sendEmptyMessage(NOTIFY_STARTED_GOING_TO_SLEEP);
1389 }
1390
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001391 private void notifyFinishedGoingToSleep() {
1392 if (DEBUG) Log.d(TAG, "notifyFinishedGoingToSleep");
1393 mHandler.sendEmptyMessage(NOTIFY_FINISHED_GOING_TO_SLEEP);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001394 }
1395
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001396 private void notifyStartedWakingUp() {
1397 if (DEBUG) Log.d(TAG, "notifyStartedWakingUp");
1398 mHandler.sendEmptyMessage(NOTIFY_STARTED_WAKING_UP);
1399 }
1400
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001401 private void notifyScreenOn(IKeyguardDrawnCallback callback) {
1402 if (DEBUG) Log.d(TAG, "notifyScreenOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001403 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNING_ON, callback);
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001404 mHandler.sendMessage(msg);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001405 }
1406
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001407 private void notifyScreenTurnedOn() {
1408 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOn");
1409 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_ON);
1410 mHandler.sendMessage(msg);
1411 }
1412
1413 private void notifyScreenTurnedOff() {
1414 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOff");
1415 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_OFF);
1416 mHandler.sendMessage(msg);
1417 }
1418
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001419 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001420 * Send message to keyguard telling it to show itself
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001421 * @see #handleShow
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001422 */
Adam Cohenf7522022012-10-03 20:03:18 -07001423 private void showLocked(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001424 Trace.beginSection("KeyguardViewMediator#showLocked aqcuiring mShowKeyguardWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001425 if (DEBUG) Log.d(TAG, "showLocked");
Mike Lockwood674d3e42009-10-06 09:28:54 -04001426 // ensure we stay awake until we are finished displaying the keyguard
1427 mShowKeyguardWakeLock.acquire();
Adam Cohenf7522022012-10-03 20:03:18 -07001428 Message msg = mHandler.obtainMessage(SHOW, options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001429 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001430 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001431 }
1432
1433 /**
1434 * Send message to keyguard telling it to hide itself
Jim Miller9c20d0e2010-01-20 15:00:23 -08001435 * @see #handleHide()
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001436 */
1437 private void hideLocked() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001438 Trace.beginSection("KeyguardViewMediator#hideLocked");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001439 if (DEBUG) Log.d(TAG, "hideLocked");
1440 Message msg = mHandler.obtainMessage(HIDE);
1441 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001442 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001443 }
1444
Dianne Hackbornb446e972009-09-20 15:23:25 -07001445 public boolean isSecure() {
Evan Rosky13a58a92016-07-27 15:51:09 -07001446 return isSecure(KeyguardUpdateMonitor.getCurrentUser());
1447 }
1448
1449 public boolean isSecure(int userId) {
1450 return mLockPatternUtils.isSecure(userId)
1451 || KeyguardUpdateMonitor.getInstance(mContext).isSimPinSecure();
Dianne Hackbornb446e972009-09-20 15:23:25 -07001452 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001453
Evan Rosky18396452016-07-27 15:19:37 -07001454 public void setSwitchingUser(boolean switching) {
Selim Cinekbbe19242017-12-08 15:42:08 -08001455 KeyguardUpdateMonitor.getInstance(mContext).setSwitchingUser(switching);
Evan Rosky18396452016-07-27 15:19:37 -07001456 }
1457
Craig Mautnerf1b67412012-09-19 13:18:29 -07001458 /**
1459 * Update the newUserId. Call while holding WindowManagerService lock.
Jim Milleree82f8f2012-10-01 16:26:18 -07001460 * NOTE: Should only be called by KeyguardViewMediator in response to the user id changing.
1461 *
Craig Mautnerf1b67412012-09-19 13:18:29 -07001462 * @param newUserId The id of the incoming user.
1463 */
1464 public void setCurrentUser(int newUserId) {
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001465 KeyguardUpdateMonitor.setCurrentUser(newUserId);
Adrian Roosd88eb262016-08-04 14:50:48 -07001466 synchronized (this) {
1467 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(newUserId));
1468 }
Craig Mautnerf1b67412012-09-19 13:18:29 -07001469 }
1470
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001471 /**
1472 * This broadcast receiver should be registered with the SystemUI permission.
1473 */
1474 private final BroadcastReceiver mDelayedLockBroadcastReceiver = new BroadcastReceiver() {
Amith Yamasani52c489c2012-03-28 11:42:42 -07001475 @Override
1476 public void onReceive(Context context, Intent intent) {
Jim Millerbbf1a742012-07-17 18:30:30 -07001477 if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
1478 final int sequence = intent.getIntExtra("seq", 0);
Jim Millerf3447352011-08-07 14:00:09 -07001479 if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = "
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001480 + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001481 synchronized (KeyguardViewMediator.this) {
Jim Miller2967f482016-01-07 15:05:32 -08001482 if (mDelayedShowingSequence == sequence) {
1483 doKeyguardLocked(null);
1484 }
Clara Bayarri56878a92015-10-29 15:43:55 +00001485 }
1486 } else if (DELAYED_LOCK_PROFILE_ACTION.equals(intent.getAction())) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001487 final int sequence = intent.getIntExtra("seq", 0);
Clara Bayarri56878a92015-10-29 15:43:55 +00001488 int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, 0);
1489 if (userId != 0) {
1490 synchronized (KeyguardViewMediator.this) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001491 if (mDelayedProfileShowingSequence == sequence) {
1492 lockProfile(userId);
1493 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001494 }
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001495 }
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001496 }
1497 }
1498 };
1499
1500 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1501 @Override
1502 public void onReceive(Context context, Intent intent) {
1503 if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
Adrian Roos1f8025a2016-12-27 10:12:13 -08001504 synchronized (KeyguardViewMediator.this){
1505 mShuttingDown = true;
1506 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001507 }
1508 }
1509 };
1510
Jorim Jaggi241ae102016-11-02 21:57:33 -07001511 public void keyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001512 Trace.beginSection("KeyguardViewMediator#keyguardDone");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001513 if (DEBUG) Log.d(TAG, "keyguardDone()");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001514 userActivity();
Jim Miller60013792013-10-03 18:31:34 -07001515 EventLog.writeEvent(70000, 2);
Jorim Jaggi241ae102016-11-02 21:57:33 -07001516 Message msg = mHandler.obtainMessage(KEYGUARD_DONE);
Jim Miller60013792013-10-03 18:31:34 -07001517 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001518 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001519 }
1520
1521 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001522 * This handler will be associated with the policy thread, which will also
1523 * be the UI thread of the keyguard. Since the apis of the policy, and therefore
1524 * this class, can be called by other threads, any action that directly
1525 * interacts with the keyguard ui should be posted to this handler, rather
1526 * than called directly.
1527 */
Jim Millerdcb3d842012-08-23 19:18:12 -07001528 private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001529 @Override
Wink Saville37c124c2009-04-02 01:37:02 -07001530 public void handleMessage(Message msg) {
1531 switch (msg.what) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001532 case SHOW:
Adam Cohenf7522022012-10-03 20:03:18 -07001533 handleShow((Bundle) msg.obj);
Jim Miller60013792013-10-03 18:31:34 -07001534 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001535 case HIDE:
1536 handleHide();
Jim Miller60013792013-10-03 18:31:34 -07001537 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001538 case RESET:
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001539 handleReset();
Jim Miller60013792013-10-03 18:31:34 -07001540 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001541 case VERIFY_UNLOCK:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001542 Trace.beginSection("KeyguardViewMediator#handleMessage VERIFY_UNLOCK");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001543 handleVerifyUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001544 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001545 break;
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001546 case NOTIFY_STARTED_GOING_TO_SLEEP:
1547 handleNotifyStartedGoingToSleep();
1548 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001549 case NOTIFY_FINISHED_GOING_TO_SLEEP:
1550 handleNotifyFinishedGoingToSleep();
Jim Miller60013792013-10-03 18:31:34 -07001551 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001552 case NOTIFY_SCREEN_TURNING_ON:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001553 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNING_ON");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001554 handleNotifyScreenTurningOn((IKeyguardDrawnCallback) msg.obj);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001555 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001556 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001557 case NOTIFY_SCREEN_TURNED_ON:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001558 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNED_ON");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001559 handleNotifyScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001560 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001561 break;
1562 case NOTIFY_SCREEN_TURNED_OFF:
1563 handleNotifyScreenTurnedOff();
1564 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001565 case NOTIFY_STARTED_WAKING_UP:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001566 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_STARTED_WAKING_UP");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001567 handleNotifyStartedWakingUp();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001568 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001569 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001570 case KEYGUARD_DONE:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001571 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001572 handleKeyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001573 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001574 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001575 case KEYGUARD_DONE_DRAWING:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001576 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_DRAWING");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001577 handleKeyguardDoneDrawing();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001578 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001579 break;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001580 case SET_OCCLUDED:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001581 Trace.beginSection("KeyguardViewMediator#handleMessage SET_OCCLUDED");
Jorim Jaggi6626f542016-08-22 13:08:44 -07001582 handleSetOccluded(msg.arg1 != 0, msg.arg2 != 0);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001583 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001584 break;
Mike Lockwood28569302010-01-28 11:54:40 -05001585 case KEYGUARD_TIMEOUT:
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001586 synchronized (KeyguardViewMediator.this) {
Adam Cohenf7522022012-10-03 20:03:18 -07001587 doKeyguardLocked((Bundle) msg.obj);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001588 }
1589 break;
Jim Miller60013792013-10-03 18:31:34 -07001590 case DISMISS:
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001591 final DismissMessage message = (DismissMessage) msg.obj;
1592 handleDismiss(message.getCallback(), message.getMessage());
Jim Miller60013792013-10-03 18:31:34 -07001593 break;
Jorim Jaggi0d674622014-05-21 01:34:15 +02001594 case START_KEYGUARD_EXIT_ANIM:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001595 Trace.beginSection("KeyguardViewMediator#handleMessage START_KEYGUARD_EXIT_ANIM");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001596 StartKeyguardExitAnimParams params = (StartKeyguardExitAnimParams) msg.obj;
1597 handleStartKeyguardExitAnimation(params.startTime, params.fadeoutDuration);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001598 FalsingManager.getInstance(mContext).onSucccessfulUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001599 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001600 break;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001601 case KEYGUARD_DONE_PENDING_TIMEOUT:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001602 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_PENDING_TIMEOUT");
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001603 Log.w(TAG, "Timeout while waiting for activity drawn!");
Nick Desaulniers1d396752016-07-25 15:05:33 -07001604 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001605 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001606 }
1607 }
1608 };
1609
Jorim Jaggi241ae102016-11-02 21:57:33 -07001610 private void tryKeyguardDone() {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001611 if (!mKeyguardDonePending && mHideAnimationRun && !mHideAnimationRunning) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001612 handleKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001613 } else if (!mHideAnimationRun) {
1614 mHideAnimationRun = true;
1615 mHideAnimationRunning = true;
1616 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
1617 }
1618 }
1619
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001620 /**
1621 * @see #keyguardDone
1622 * @see #KEYGUARD_DONE
1623 */
Jorim Jaggi241ae102016-11-02 21:57:33 -07001624 private void handleKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001625 Trace.beginSection("KeyguardViewMediator#handleKeyguardDone");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001626 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001627 mUiOffloadThread.submit(() -> {
1628 if (mLockPatternUtils.isSecure(currentUser)) {
1629 mLockPatternUtils.getDevicePolicyManager().reportKeyguardDismissed(currentUser);
1630 }
1631 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001632 if (DEBUG) Log.d(TAG, "handleKeyguardDone");
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001633 synchronized (this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001634 resetKeyguardDonePendingLocked();
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001635 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001636
Jorim Jaggi241ae102016-11-02 21:57:33 -07001637 mUpdateMonitor.clearFailedUnlockAttempts();
Jim Millerf41fc962014-06-18 16:33:51 -07001638 mUpdateMonitor.clearFingerprintRecognized();
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -07001639
Jorim Jaggi4474f542015-07-09 16:08:02 -07001640 if (mGoingToSleep) {
1641 Log.i(TAG, "Device is going to sleep, aborting keyguardDone");
1642 return;
1643 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001644 if (mExitSecureCallback != null) {
1645 try {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001646 mExitSecureCallback.onKeyguardExitResult(true /* authenciated */);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001647 } catch (RemoteException e) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001648 Slog.w(TAG, "Failed to call onKeyguardExitResult()", e);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001649 }
1650
1651 mExitSecureCallback = null;
1652
Jorim Jaggi241ae102016-11-02 21:57:33 -07001653 // after succesfully exiting securely, no need to reshow
1654 // the keyguard when they've released the lock
1655 mExternallyEnabled = true;
1656 mNeedToReshowWhenReenabled = false;
1657 updateInputRestricted();
Jim Millere51cf7ae2013-06-25 18:31:56 -07001658 }
1659
1660 handleHide();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001661 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -07001662 }
1663
1664 private void sendUserPresentBroadcast() {
Jason Monkcf5a9532014-09-17 16:22:19 -04001665 synchronized (this) {
1666 if (mBootCompleted) {
Adrian Roos4ab7e592016-04-13 15:38:13 -07001667 int currentUserId = KeyguardUpdateMonitor.getCurrentUser();
1668 final UserHandle currentUser = new UserHandle(currentUserId);
Benjamin Franz4b9f8ed2014-12-01 16:51:48 +00001669 final UserManager um = (UserManager) mContext.getSystemService(
1670 Context.USER_SERVICE);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001671 mUiOffloadThread.submit(() -> {
1672 for (int profileId : um.getProfileIdsWithDisabled(currentUser.getIdentifier())) {
1673 mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, UserHandle.of(profileId));
1674 }
1675 getLockPatternUtils().userPresent(currentUserId);
1676 });
Jason Monkcf5a9532014-09-17 16:22:19 -04001677 } else {
1678 mBootSendUserPresent = true;
1679 }
1680 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001681 }
1682
1683 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001684 * @see #keyguardDone
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001685 * @see #KEYGUARD_DONE_DRAWING
1686 */
1687 private void handleKeyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001688 Trace.beginSection("KeyguardViewMediator#handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001689 synchronized(this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001690 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001691 if (mWaitingUntilKeyguardVisible) {
1692 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible");
1693 mWaitingUntilKeyguardVisible = false;
1694 notifyAll();
1695
1696 // there will usually be two of these sent, one as a timeout, and one
1697 // as a result of the callback, so remove any remaining messages from
1698 // the queue
1699 mHandler.removeMessages(KEYGUARD_DONE_DRAWING);
1700 }
1701 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001702 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001703 }
1704
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001705 private void playSounds(boolean locked) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001706 playSound(locked ? mLockSoundId : mUnlockSoundId);
1707 }
1708
1709 private void playSound(int soundId) {
1710 if (soundId == 0) return;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001711 final ContentResolver cr = mContext.getContentResolver();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001712 if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001713
Marco Nelissend5545bd2011-09-29 12:49:17 -07001714 mLockSounds.stop(mLockSoundStreamId);
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001715 // Init mAudioManager
1716 if (mAudioManager == null) {
1717 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
1718 if (mAudioManager == null) return;
John Spurlockee5ad722015-03-03 16:17:21 -05001719 mUiSoundsStreamType = mAudioManager.getUiSoundsStreamType();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001720 }
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001721
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001722 mUiOffloadThread.submit(() -> {
1723 // If the stream is muted, don't play the sound
1724 if (mAudioManager.isStreamMute(mUiSoundsStreamType)) return;
1725
1726 int id = mLockSounds.play(soundId,
1727 mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/);
1728 synchronized (this) {
1729 mLockSoundStreamId = id;
1730 }
1731 });
1732
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001733 }
Jim Miller2a98a4c2010-11-19 18:49:26 -08001734 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001735
Adrian Roos49e057d2014-08-13 17:14:51 +02001736 private void playTrustedSound() {
Adrian Roos49e057d2014-08-13 17:14:51 +02001737 playSound(mTrustedSoundId);
1738 }
1739
Lucas Dupin47a65c72018-02-15 14:16:18 -08001740 private void updateActivityLockScreenState(boolean showing, boolean aodShowing,
1741 int secondaryDisplayShowing) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001742 mUiOffloadThread.submit(() -> {
1743 try {
Lucas Dupin47a65c72018-02-15 14:16:18 -08001744 ActivityManager.getService().setLockScreenShown(showing, aodShowing,
1745 secondaryDisplayShowing);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001746 } catch (RemoteException e) {
1747 }
1748 });
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001749 }
1750
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001751 /**
1752 * Handle message sent by {@link #showLocked}.
1753 * @see #SHOW
1754 */
Adam Cohenf7522022012-10-03 20:03:18 -07001755 private void handleShow(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001756 Trace.beginSection("KeyguardViewMediator#handleShow");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001757 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
1758 if (mLockPatternUtils.isSecure(currentUser)) {
1759 mLockPatternUtils.getDevicePolicyManager().reportKeyguardSecured(currentUser);
Michal Karpinski779aad92016-01-20 11:56:22 +00001760 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001761 synchronized (KeyguardViewMediator.this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001762 if (!mSystemReady) {
1763 if (DEBUG) Log.d(TAG, "ignoring handleShow because system is not ready.");
1764 return;
1765 } else {
1766 if (DEBUG) Log.d(TAG, "handleShow");
1767 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001768
Lucas Dupin47a65c72018-02-15 14:16:18 -08001769 setShowingLocked(true, mAodShowing);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001770 mStatusBarKeyguardViewManager.show(options);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001771 mHiding = false;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001772 mWakeAndUnlocking = false;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001773 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001774 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001775 adjustStatusBarLocked();
Jeff Brown3dc524b2012-09-30 19:49:11 -07001776 userActivity();
Mike Lockwood674d3e42009-10-06 09:28:54 -04001777 mShowKeyguardWakeLock.release();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001778 }
Jim Miller31921482013-11-06 20:43:55 -08001779 mKeyguardDisplayManager.show();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001780 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001781 }
1782
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001783 private final Runnable mKeyguardGoingAwayRunnable = new Runnable() {
1784 @Override
1785 public void run() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001786 Trace.beginSection("KeyguardViewMediator.mKeyGuardGoingAwayRunnable");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001787 if (DEBUG) Log.d(TAG, "keyguardGoingAway");
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001788 try {
Jorim Jaggi33ae80e2015-02-04 16:37:11 +01001789 mStatusBarKeyguardViewManager.keyguardGoingAway();
1790
Adrian Roosd5c2db62016-03-08 16:11:31 -08001791 int flags = 0;
1792 if (mStatusBarKeyguardViewManager.shouldDisableWindowAnimationsForUnlock()
1793 || mWakeAndUnlocking) {
Adrian Roose99bc052017-11-20 17:55:31 +01001794 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001795 }
1796 if (mStatusBarKeyguardViewManager.isGoingToNotificationShade()) {
Adrian Roose99bc052017-11-20 17:55:31 +01001797 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001798 }
1799 if (mStatusBarKeyguardViewManager.isUnlockWithWallpaper()) {
Adrian Roose99bc052017-11-20 17:55:31 +01001800 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001801 }
1802
Kevin Chyn6db7d5f2017-05-03 22:24:31 -07001803 mUpdateMonitor.setKeyguardGoingAway(true /* goingAway */);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001804 // Don't actually hide the Keyguard at the moment, wait for window
1805 // manager until it tells us it's safe to do so with
1806 // startKeyguardExitAnimation.
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001807 ActivityManager.getService().keyguardGoingAway(flags);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001808 } catch (RemoteException e) {
1809 Log.e(TAG, "Error while calling WindowManager", e);
1810 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001811 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001812 }
1813 };
1814
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001815 private final Runnable mHideAnimationFinishedRunnable = () -> {
1816 mHideAnimationRunning = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -07001817 tryKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001818 };
1819
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001820 /**
1821 * Handle message sent by {@link #hideLocked()}
1822 * @see #HIDE
1823 */
1824 private void handleHide() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001825 Trace.beginSection("KeyguardViewMediator#handleHide");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001826 synchronized (KeyguardViewMediator.this) {
1827 if (DEBUG) Log.d(TAG, "handleHide");
Jorim Jaggib9d60792014-06-03 22:34:22 +02001828
Amith Yamasanieb437d42016-04-29 09:31:25 -07001829 if (mustNotUnlockCurrentUser()) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001830 // In split system user mode, we never unlock system user. The end user has to
1831 // switch to another user.
1832 // TODO: We should stop it early by disabling the swipe up flow. Right now swipe up
1833 // still completes and makes the screen blank.
1834 if (DEBUG) Log.d(TAG, "Split system user, quit unlocking.");
1835 return;
1836 }
Jorim Jaggi76a16232014-08-08 17:00:47 +02001837 mHiding = true;
Jorim Jaggib9d60792014-06-03 22:34:22 +02001838
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001839 if (mShowing && !mOccluded) {
1840 mKeyguardGoingAwayRunnable.run();
1841 } else {
Jorim Jaggi76a16232014-08-08 17:00:47 +02001842 handleStartKeyguardExitAnimation(
1843 SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(),
1844 mHideAnimation.getDuration());
Jorim Jaggi0d674622014-05-21 01:34:15 +02001845 }
1846 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001847 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001848 }
1849
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001850 private void handleStartKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001851 Trace.beginSection("KeyguardViewMediator#handleStartKeyguardExitAnimation");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001852 if (DEBUG) Log.d(TAG, "handleStartKeyguardExitAnimation startTime=" + startTime
1853 + " fadeoutDuration=" + fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02001854 synchronized (KeyguardViewMediator.this) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001855
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001856 if (!mHiding) {
Adrian Roos6ec76b72018-04-25 14:01:11 +02001857 // Tell ActivityManager that we canceled the keyguardExitAnimation.
1858 setShowingLocked(mShowing, mAodShowing, mSecondaryDisplayShowing, true /* force */);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001859 return;
1860 }
1861 mHiding = false;
1862
Jorim Jaggib774e552015-08-24 14:52:45 -07001863 if (mWakeAndUnlocking && mDrawnCallback != null) {
1864
1865 // Hack level over 9000: To speed up wake-and-unlock sequence, force it to report
1866 // the next draw from here so we don't have to wait for window manager to signal
1867 // this to our ViewRootImpl.
1868 mStatusBarKeyguardViewManager.getViewRootImpl().setReportNextDraw();
1869 notifyDrawn(mDrawnCallback);
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001870 mDrawnCallback = null;
Jorim Jaggib774e552015-08-24 14:52:45 -07001871 }
1872
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001873 // only play "unlock" noises if not on a call (since the incall UI
1874 // disables the keyguard)
1875 if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) {
1876 playSounds(false);
1877 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001878
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001879 mWakeAndUnlocking = false;
Lucas Dupin47a65c72018-02-15 14:16:18 -08001880 setShowingLocked(false, mAodShowing);
Jorim Jaggi5277dea2017-05-18 02:05:29 +02001881 mDismissCallbackRegistry.notifyDismissSucceeded();
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001882 mStatusBarKeyguardViewManager.hide(startTime, fadeoutDuration);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001883 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001884 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001885 adjustStatusBarLocked();
Jim Miller705004b2014-09-04 16:51:20 -07001886 sendUserPresentBroadcast();
Kevin Chyn6db7d5f2017-05-03 22:24:31 -07001887 mUpdateMonitor.setKeyguardGoingAway(false /* goingAway */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001888 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001889 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001890 }
1891
Mike Lockwood5f892c12009-11-19 23:39:13 -05001892 private void adjustStatusBarLocked() {
Matthew Ng66f0b702017-12-08 12:58:42 -08001893 adjustStatusBarLocked(false /* forceHideHomeRecentsButtons */);
1894 }
1895
1896 private void adjustStatusBarLocked(boolean forceHideHomeRecentsButtons) {
Mike Lockwood5f892c12009-11-19 23:39:13 -05001897 if (mStatusBarManager == null) {
1898 mStatusBarManager = (StatusBarManager)
1899 mContext.getSystemService(Context.STATUS_BAR_SERVICE);
1900 }
1901 if (mStatusBarManager == null) {
1902 Log.w(TAG, "Could not get status bar manager");
1903 } else {
Daniel Sandlerdba93562011-10-06 16:39:58 -04001904 // Disable aspects of the system/status/navigation bars that must not be re-enabled by
1905 // windows that appear on top, ever
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001906 int flags = StatusBarManager.DISABLE_NONE;
Matthew Ng66f0b702017-12-08 12:58:42 -08001907 if (forceHideHomeRecentsButtons || isShowingAndNotOccluded()) {
1908 flags |= StatusBarManager.DISABLE_HOME | StatusBarManager.DISABLE_RECENT;
Jorim Jaggia005f1b2014-04-16 19:06:10 +02001909 }
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001910
1911 if (DEBUG) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001912 Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mOccluded=" + mOccluded
Matthew Ng66f0b702017-12-08 12:58:42 -08001913 + " isSecure=" + isSecure() + " force=" + forceHideHomeRecentsButtons
1914 + " --> flags=0x" + Integer.toHexString(flags));
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001915 }
1916
Jorim Jaggie3e0b062017-06-12 12:18:41 -07001917 mStatusBarManager.disable(flags);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001918 }
1919 }
1920
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001921 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001922 * Handle message sent by {@link #resetStateLocked}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001923 * @see #RESET
1924 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001925 private void handleReset() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001926 synchronized (KeyguardViewMediator.this) {
1927 if (DEBUG) Log.d(TAG, "handleReset");
Jorim Jaggife762342016-10-13 14:33:27 +02001928 mStatusBarKeyguardViewManager.reset(true /* hideBouncerWhenShowing */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001929 }
1930 }
1931
1932 /**
1933 * Handle message sent by {@link #verifyUnlock}
Craig Mautner904732c2012-10-17 15:20:24 -07001934 * @see #VERIFY_UNLOCK
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001935 */
1936 private void handleVerifyUnlock() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001937 Trace.beginSection("KeyguardViewMediator#handleVerifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001938 synchronized (KeyguardViewMediator.this) {
1939 if (DEBUG) Log.d(TAG, "handleVerifyUnlock");
Lucas Dupin47a65c72018-02-15 14:16:18 -08001940 setShowingLocked(true, mAodShowing);
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001941 mStatusBarKeyguardViewManager.dismissAndCollapse();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001942 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001943 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001944 }
1945
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001946 private void handleNotifyStartedGoingToSleep() {
1947 synchronized (KeyguardViewMediator.this) {
1948 if (DEBUG) Log.d(TAG, "handleNotifyStartedGoingToSleep");
1949 mStatusBarKeyguardViewManager.onStartedGoingToSleep();
1950 }
1951 }
1952
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001953 /**
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001954 * Handle message sent by {@link #notifyFinishedGoingToSleep()}
1955 * @see #NOTIFY_FINISHED_GOING_TO_SLEEP
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001956 */
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001957 private void handleNotifyFinishedGoingToSleep() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001958 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001959 if (DEBUG) Log.d(TAG, "handleNotifyFinishedGoingToSleep");
1960 mStatusBarKeyguardViewManager.onFinishedGoingToSleep();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001961 }
1962 }
1963
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001964 private void handleNotifyStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001965 Trace.beginSection("KeyguardViewMediator#handleMotifyStartedWakingUp");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001966 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001967 if (DEBUG) Log.d(TAG, "handleNotifyWakingUp");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001968 mStatusBarKeyguardViewManager.onStartedWakingUp();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001969 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001970 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001971 }
1972
1973 private void handleNotifyScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001974 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurningOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001975 synchronized (KeyguardViewMediator.this) {
1976 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurningOn");
Jorim Jaggi93739112015-08-13 15:53:14 -07001977 mStatusBarKeyguardViewManager.onScreenTurningOn();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001978 if (callback != null) {
1979 if (mWakeAndUnlocking) {
1980 mDrawnCallback = callback;
1981 } else {
1982 notifyDrawn(callback);
1983 }
1984 }
1985 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001986 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001987 }
1988
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001989 private void handleNotifyScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001990 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurnedOn");
Jorim Jaggic3fe2042016-10-07 18:52:48 +02001991 if (LatencyTracker.isEnabled(mContext)) {
1992 LatencyTracker.getInstance(mContext).onActionEnd(LatencyTracker.ACTION_TURN_ON_SCREEN);
1993 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001994 synchronized (this) {
1995 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOn");
1996 mStatusBarKeyguardViewManager.onScreenTurnedOn();
1997 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001998 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001999 }
2000
2001 private void handleNotifyScreenTurnedOff() {
2002 synchronized (this) {
2003 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOff");
2004 mStatusBarKeyguardViewManager.onScreenTurnedOff();
Jorim Jaggie93e6f92016-08-04 13:55:39 +02002005 mDrawnCallback = null;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002006 }
2007 }
2008
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002009 private void notifyDrawn(final IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002010 Trace.beginSection("KeyguardViewMediator#notifyDrawn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002011 try {
2012 callback.onDrawn();
2013 } catch (RemoteException e) {
2014 Slog.w(TAG, "Exception calling onDrawn():", e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002015 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002016 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002017 }
Jeff Sharkey054340d2011-09-01 22:28:03 -07002018
Jorim Jaggif8d77da2014-11-11 16:59:12 +01002019 private void resetKeyguardDonePendingLocked() {
2020 mKeyguardDonePending = false;
2021 mHandler.removeMessages(KEYGUARD_DONE_PENDING_TIMEOUT);
2022 }
2023
Jim Miller2967f482016-01-07 15:05:32 -08002024 @Override
Jim Millere5f910a2013-10-16 18:15:46 -07002025 public void onBootCompleted() {
2026 mUpdateMonitor.dispatchBootCompleted();
Jason Monkcf5a9532014-09-17 16:22:19 -04002027 synchronized (this) {
2028 mBootCompleted = true;
2029 if (mBootSendUserPresent) {
2030 sendUserPresentBroadcast();
2031 }
2032 }
Jim Millere5f910a2013-10-16 18:15:46 -07002033 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002034
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002035 public void onWakeAndUnlocking() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002036 Trace.beginSection("KeyguardViewMediator#onWakeAndUnlocking");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002037 mWakeAndUnlocking = true;
Jorim Jaggi241ae102016-11-02 21:57:33 -07002038 keyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07002039 Trace.endSection();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002040 }
2041
Jason Monk2a6ea9c2017-01-26 11:14:51 -05002042 public StatusBarKeyguardViewManager registerStatusBar(StatusBar statusBar,
Lucas Dupinbc9aac12018-03-04 20:18:15 -08002043 ViewGroup container, NotificationPanelView panelView,
2044 FingerprintUnlockController fingerprintUnlockController) {
2045 mStatusBarKeyguardViewManager.registerStatusBar(statusBar, container, panelView,
Lucas Dupin9e3fa102017-11-08 17:16:55 -08002046 fingerprintUnlockController, mDismissCallbackRegistry);
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002047 return mStatusBarKeyguardViewManager;
2048 }
2049
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002050 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002051 Trace.beginSection("KeyguardViewMediator#startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002052 Message msg = mHandler.obtainMessage(START_KEYGUARD_EXIT_ANIM,
2053 new StartKeyguardExitAnimParams(startTime, fadeoutDuration));
Jorim Jaggi0d674622014-05-21 01:34:15 +02002054 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07002055 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02002056 }
2057
Andrew Zengb4045d32017-03-16 17:25:07 -07002058 public void onShortPowerPressedGoHome() {
2059 // do nothing
2060 }
2061
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002062 public ViewMediatorCallback getViewMediatorCallback() {
2063 return mViewMediatorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002064 }
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002065
Xiyuan Xia1b30f792016-01-06 08:50:30 -08002066 public LockPatternUtils getLockPatternUtils() {
2067 return mLockPatternUtils;
2068 }
2069
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002070 @Override
2071 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
2072 pw.print(" mSystemReady: "); pw.println(mSystemReady);
2073 pw.print(" mBootCompleted: "); pw.println(mBootCompleted);
2074 pw.print(" mBootSendUserPresent: "); pw.println(mBootSendUserPresent);
2075 pw.print(" mExternallyEnabled: "); pw.println(mExternallyEnabled);
Adrian Roos1f8025a2016-12-27 10:12:13 -08002076 pw.print(" mShuttingDown: "); pw.println(mShuttingDown);
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002077 pw.print(" mNeedToReshowWhenReenabled: "); pw.println(mNeedToReshowWhenReenabled);
2078 pw.print(" mShowing: "); pw.println(mShowing);
2079 pw.print(" mInputRestricted: "); pw.println(mInputRestricted);
2080 pw.print(" mOccluded: "); pw.println(mOccluded);
2081 pw.print(" mDelayedShowingSequence: "); pw.println(mDelayedShowingSequence);
2082 pw.print(" mExitSecureCallback: "); pw.println(mExitSecureCallback);
2083 pw.print(" mDeviceInteractive: "); pw.println(mDeviceInteractive);
2084 pw.print(" mGoingToSleep: "); pw.println(mGoingToSleep);
2085 pw.print(" mHiding: "); pw.println(mHiding);
2086 pw.print(" mWaitingUntilKeyguardVisible: "); pw.println(mWaitingUntilKeyguardVisible);
2087 pw.print(" mKeyguardDonePending: "); pw.println(mKeyguardDonePending);
2088 pw.print(" mHideAnimationRun: "); pw.println(mHideAnimationRun);
2089 pw.print(" mPendingReset: "); pw.println(mPendingReset);
2090 pw.print(" mPendingLock: "); pw.println(mPendingLock);
2091 pw.print(" mWakeAndUnlocking: "); pw.println(mWakeAndUnlocking);
2092 pw.print(" mDrawnCallback: "); pw.println(mDrawnCallback);
2093 }
2094
Lucas Dupin47a65c72018-02-15 14:16:18 -08002095 public void setAodShowing(boolean aodShowing) {
2096 setShowingLocked(mShowing, aodShowing);
2097 }
2098
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002099 private static class StartKeyguardExitAnimParams {
2100
2101 long startTime;
2102 long fadeoutDuration;
2103
2104 private StartKeyguardExitAnimParams(long startTime, long fadeoutDuration) {
2105 this.startTime = startTime;
2106 this.fadeoutDuration = fadeoutDuration;
2107 }
2108 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002109
Lucas Dupin47a65c72018-02-15 14:16:18 -08002110 private void setShowingLocked(boolean showing, boolean aodShowing) {
2111 setShowingLocked(showing, aodShowing, mSecondaryDisplayShowing,
2112 false /* forceCallbacks */);
Jorim Jaggie8f321e2016-11-07 16:48:31 -08002113 }
2114
Lucas Dupin47a65c72018-02-15 14:16:18 -08002115 private void setShowingLocked(boolean showing, boolean aodShowing, int secondaryDisplayShowing,
2116 boolean forceCallbacks) {
2117 final boolean notifyDefaultDisplayCallbacks = showing != mShowing
2118 || aodShowing != mAodShowing || forceCallbacks;
David Stevens53a39ea2017-08-23 18:41:49 -07002119 if (notifyDefaultDisplayCallbacks || secondaryDisplayShowing != mSecondaryDisplayShowing) {
Jim Millerab954542014-10-10 18:21:49 -07002120 mShowing = showing;
Lucas Dupin47a65c72018-02-15 14:16:18 -08002121 mAodShowing = aodShowing;
David Stevens53a39ea2017-08-23 18:41:49 -07002122 mSecondaryDisplayShowing = secondaryDisplayShowing;
2123 if (notifyDefaultDisplayCallbacks) {
2124 notifyDefaultDisplayCallbacks(showing);
2125 }
Lucas Dupin47a65c72018-02-15 14:16:18 -08002126 updateActivityLockScreenState(showing, aodShowing, secondaryDisplayShowing);
David Stevens53a39ea2017-08-23 18:41:49 -07002127 }
2128 }
2129
2130 private void notifyDefaultDisplayCallbacks(boolean showing) {
2131 int size = mKeyguardStateCallbacks.size();
2132 for (int i = size - 1; i >= 0; i--) {
2133 IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
2134 try {
2135 callback.onShowingStateChanged(showing);
2136 } catch (RemoteException e) {
2137 Slog.w(TAG, "Failed to call onShowingStateChanged", e);
2138 if (e instanceof DeadObjectException) {
2139 mKeyguardStateCallbacks.remove(callback);
Jim Millerab954542014-10-10 18:21:49 -07002140 }
Jim Millerab954542014-10-10 18:21:49 -07002141 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002142 }
David Stevens53a39ea2017-08-23 18:41:49 -07002143 updateInputRestrictedLocked();
2144 mUiOffloadThread.submit(() -> {
2145 mTrustManager.reportKeyguardShowingChanged();
2146 });
Adrian Roos481a6df2014-11-20 19:48:56 +01002147 }
Jim Millerab954542014-10-10 18:21:49 -07002148
Adrian Roosd88eb262016-08-04 14:50:48 -07002149 private void notifyTrustedChangedLocked(boolean trusted) {
2150 int size = mKeyguardStateCallbacks.size();
2151 for (int i = size - 1; i >= 0; i--) {
2152 try {
2153 mKeyguardStateCallbacks.get(i).onTrustedChanged(trusted);
2154 } catch (RemoteException e) {
2155 Slog.w(TAG, "Failed to call notifyTrustedChangedLocked", e);
2156 if (e instanceof DeadObjectException) {
2157 mKeyguardStateCallbacks.remove(i);
2158 }
2159 }
2160 }
2161 }
2162
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002163 private void notifyHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
2164 int size = mKeyguardStateCallbacks.size();
2165 for (int i = size - 1; i >= 0; i--) {
2166 try {
2167 mKeyguardStateCallbacks.get(i).onHasLockscreenWallpaperChanged(
2168 hasLockscreenWallpaper);
2169 } catch (RemoteException e) {
2170 Slog.w(TAG, "Failed to call onHasLockscreenWallpaperChanged", e);
2171 if (e instanceof DeadObjectException) {
2172 mKeyguardStateCallbacks.remove(i);
2173 }
2174 }
2175 }
2176 }
2177
Jim Millerab954542014-10-10 18:21:49 -07002178 public void addStateMonitorCallback(IKeyguardStateCallback callback) {
2179 synchronized (this) {
2180 mKeyguardStateCallbacks.add(callback);
2181 try {
2182 callback.onSimSecureStateChanged(mUpdateMonitor.isSimPinSecure());
2183 callback.onShowingStateChanged(mShowing);
Adrian Roos4a963ac2015-04-24 16:04:53 -07002184 callback.onInputRestrictedStateChanged(mInputRestricted);
Adrian Roosd88eb262016-08-04 14:50:48 -07002185 callback.onTrustedChanged(mUpdateMonitor.getUserHasTrust(
2186 KeyguardUpdateMonitor.getCurrentUser()));
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002187 callback.onHasLockscreenWallpaperChanged(mUpdateMonitor.hasLockscreenWallpaper());
Jim Millerab954542014-10-10 18:21:49 -07002188 } catch (RemoteException e) {
Adrian Roosd88eb262016-08-04 14:50:48 -07002189 Slog.w(TAG, "Failed to call to IKeyguardStateCallback", e);
Jim Millerab954542014-10-10 18:21:49 -07002190 }
2191 }
2192 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08002193
2194 private static class DismissMessage {
2195 private final CharSequence mMessage;
2196 private final IKeyguardDismissCallback mCallback;
2197
2198 DismissMessage(IKeyguardDismissCallback callback, CharSequence message) {
2199 mCallback = callback;
2200 mMessage = message;
2201 }
2202
2203 public IKeyguardDismissCallback getCallback() {
2204 return mCallback;
2205 }
2206
2207 public CharSequence getMessage() {
2208 return mMessage;
2209 }
2210 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002211}