blob: 2bb9423553d5109cfc137055345dbc671cfe7c02 [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;
Lucas Dupin2508afe2018-09-17 17:17:14 -070023import static com.android.internal.telephony.IccCardConstants.State.PIN_REQUIRED;
24import static com.android.internal.telephony.IccCardConstants.State.PUK_REQUIRED;
25import static com.android.internal.telephony.IccCardConstants.State.READY;
Jorim Jaggid11d1a92016-08-16 16:02:32 -070026import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST;
27import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW;
28import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT;
Michal Karpinskic52f8672016-11-18 11:32:45 +000029import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT;
Jorim Jaggid11d1a92016-08-16 16:02:32 -070030
Adrian Roosb60d47c2014-09-08 19:23:00 +020031import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080032import android.app.AlarmManager;
33import android.app.PendingIntent;
Mike Lockwood5f892c12009-11-19 23:39:13 -050034import android.app.StatusBarManager;
Adrian Roos481a6df2014-11-20 19:48:56 +010035import android.app.trust.TrustManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080036import android.content.BroadcastReceiver;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -050037import android.content.ContentResolver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080038import android.content.Context;
39import android.content.Intent;
40import android.content.IntentFilter;
Adrian Roosbe47b072014-09-03 00:08:56 +020041import android.content.pm.UserInfo;
Daniel Sandleraec967a2010-02-20 01:05:22 -050042import android.media.AudioManager;
Marco Nelissend5545bd2011-09-29 12:49:17 -070043import android.media.SoundPool;
Adam Cohenf7522022012-10-03 20:03:18 -070044import android.os.Bundle;
dooyoung.hwang328472e2015-05-21 16:09:43 +090045import android.os.DeadObjectException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080046import android.os.Handler;
Jeff Brown109025d2012-08-14 20:41:30 -070047import android.os.Looper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080048import android.os.Message;
49import android.os.PowerManager;
Dianne Hackborn4994c662009-09-23 22:21:23 -070050import android.os.RemoteException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080051import android.os.SystemClock;
Jim Miller1b152022009-10-28 16:08:15 -070052import android.os.SystemProperties;
Nick Desaulniers1d396752016-07-25 15:05:33 -070053import android.os.Trace;
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -070054import android.os.UserHandle;
Amith Yamasanib70ff9a2012-09-07 18:28:11 -070055import android.os.UserManager;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -050056import android.provider.Settings;
Jim Miller52a61332014-11-12 19:29:51 -080057import android.telephony.SubscriptionManager;
Karl Rosaenab100082009-03-24 22:35:17 -070058import android.telephony.TelephonyManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080059import android.util.EventLog;
Karl Rosaenab100082009-03-24 22:35:17 -070060import android.util.Log;
Jim Miller25190572013-02-28 17:36:24 -080061import android.util.Slog;
Lucas Dupin2508afe2018-09-17 17:17:14 -070062import android.util.SparseArray;
Jorim Jaggib690f0d2014-07-03 23:25:44 +020063import android.view.ViewGroup;
Adrian Roose99bc052017-11-20 17:55:31 +010064import android.view.WindowManagerPolicyConstants;
Adrian Roos0002a452014-07-03 13:46:07 +020065import android.view.animation.Animation;
66import android.view.animation.AnimationUtils;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -070067
Adrian Roos1cffe3c2016-11-28 15:46:06 -080068import com.android.internal.logging.MetricsLogger;
69import com.android.internal.logging.nano.MetricsProto;
Jorim Jaggi241ae102016-11-02 21:57:33 -070070import com.android.internal.policy.IKeyguardDismissCallback;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -070071import com.android.internal.policy.IKeyguardDrawnCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010072import com.android.internal.policy.IKeyguardExitCallback;
Jim Millerab954542014-10-10 18:21:49 -070073import com.android.internal.policy.IKeyguardStateCallback;
Adam Cohenf7522022012-10-03 20:03:18 -070074import com.android.internal.telephony.IccCardConstants;
Lucas Dupin2508afe2018-09-17 17:17:14 -070075import com.android.internal.util.LatencyTracker;
Adam Cohenf7522022012-10-03 20:03:18 -070076import com.android.internal.widget.LockPatternUtils;
Jim Miller52a61332014-11-12 19:29:51 -080077import com.android.keyguard.KeyguardConstants;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010078import com.android.keyguard.KeyguardDisplayManager;
Selim Cinek3122fa82015-06-18 01:38:59 -070079import com.android.keyguard.KeyguardSecurityView;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010080import com.android.keyguard.KeyguardUpdateMonitor;
81import com.android.keyguard.KeyguardUpdateMonitorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010082import com.android.keyguard.ViewMediatorCallback;
Jorim Jaggie549a8d2017-05-15 02:40:05 +020083import com.android.systemui.Dependency;
Jorim Jaggicff0acb2014-03-31 16:35:15 +020084import com.android.systemui.SystemUI;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080085import com.android.systemui.SystemUIFactory;
Jorim Jaggie549a8d2017-05-15 02:40:05 +020086import com.android.systemui.UiOffloadThread;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070087import com.android.systemui.classifier.FalsingManager;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070088import com.android.systemui.statusbar.phone.FingerprintUnlockController;
Lucas Dupinbc9aac12018-03-04 20:18:15 -080089import com.android.systemui.statusbar.phone.NotificationPanelView;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050090import com.android.systemui.statusbar.phone.StatusBar;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010091import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
Adrian Roos58b58fe2014-01-31 16:00:39 -080092
Jorim Jaggi84dc08a2015-09-11 17:45:22 -070093import java.io.FileDescriptor;
94import java.io.PrintWriter;
Jim Millerab954542014-10-10 18:21:49 -070095import java.util.ArrayList;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010096
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080097/**
98 * Mediates requests related to the keyguard. This includes queries about the
99 * state of the keyguard, power management events that effect whether the keyguard
100 * should be shown or reset, callbacks to the phone window manager to notify
101 * it of when the keyguard is showing, and events from the keyguard view itself
102 * stating that the keyguard was succesfully unlocked.
103 *
104 * Note that the keyguard view is shown when the screen is off (as appropriate)
105 * so that once the screen comes on, it will be ready immediately.
106 *
107 * Example queries about the keyguard:
108 * - is {movement, key} one that should wake the keygaurd?
109 * - is the keyguard showing?
110 * - are input events restricted due to the state of the keyguard?
111 *
112 * Callbacks to the phone window manager:
113 * - the keyguard is showing
114 *
115 * Example external events that translate to keyguard view changes:
116 * - screen turned off -> reset the keyguard, and show it so it will be ready
117 * next time the screen turns on
118 * - keyboard is slid open -> if the keyguard is not secure, hide it
119 *
120 * Events from the keyguard view:
121 * - user succesfully unlocked keyguard -> hide keyguard view, and no longer
122 * restrict input events.
123 *
124 * Note: in addition to normal power managment events that effect the state of
125 * whether the keyguard should be showing, external apps and services may request
126 * that the keyguard be disabled via {@link #setKeyguardEnabled(boolean)}. When
127 * false, this will override all other conditions for turning on the keyguard.
128 *
129 * Threading and synchronization:
Adrian Roose99bc052017-11-20 17:55:31 +0100130 * This class is created by the initialization routine of the {@link WindowManagerPolicyConstants},
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800131 * and runs on its thread. The keyguard UI is created from that thread in the
132 * constructor of this class. The apis may be called from other threads, including the
Jeff Brown4532e612012-04-05 14:27:12 -0700133 * {@link com.android.server.input.InputManagerService}'s and {@link android.view.WindowManager}'s.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800134 * Therefore, methods on this class are synchronized, and any action that is pointed
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100135 * directly to the keyguard UI is posted to a {@link android.os.Handler} to ensure it is taken on the UI
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800136 * thread of the keyguard.
137 */
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200138public class KeyguardViewMediator extends SystemUI {
Jim Millerbc4603b2010-08-30 21:21:34 -0700139 private static final int KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT = 30000;
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100140 private static final long KEYGUARD_DONE_PENDING_TIMEOUT_MS = 3000;
141
Jim Miller52a61332014-11-12 19:29:51 -0800142 private static final boolean DEBUG = KeyguardConstants.DEBUG;
143 private static final boolean DEBUG_SIM_STATES = KeyguardConstants.DEBUG_SIM_STATES;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800144
145 private final static String TAG = "KeyguardViewMediator";
146
Jim Miller9c20d0e2010-01-20 15:00:23 -0800147 private static final String DELAYED_KEYGUARD_ACTION =
Wink Saville37c124c2009-04-02 01:37:02 -0700148 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD";
Clara Bayarri56878a92015-10-29 15:43:55 +0000149 private static final String DELAYED_LOCK_PROFILE_ACTION =
150 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_LOCK";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800151
Kevin Chyn18e91aa2018-04-11 12:55:45 -0700152 private static final String SYSTEMUI_PERMISSION = "com.android.systemui.permission.SELF";
153
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800154 // used for handler messages
Jorim Jaggi8d786932016-10-26 19:08:36 -0700155 private static final int SHOW = 1;
156 private static final int HIDE = 2;
157 private static final int RESET = 3;
158 private static final int VERIFY_UNLOCK = 4;
159 private static final int NOTIFY_FINISHED_GOING_TO_SLEEP = 5;
160 private static final int NOTIFY_SCREEN_TURNING_ON = 6;
161 private static final int KEYGUARD_DONE = 7;
162 private static final int KEYGUARD_DONE_DRAWING = 8;
163 private static final int SET_OCCLUDED = 9;
164 private static final int KEYGUARD_TIMEOUT = 10;
165 private static final int DISMISS = 11;
166 private static final int START_KEYGUARD_EXIT_ANIM = 12;
167 private static final int KEYGUARD_DONE_PENDING_TIMEOUT = 13;
168 private static final int NOTIFY_STARTED_WAKING_UP = 14;
169 private static final int NOTIFY_SCREEN_TURNED_ON = 15;
170 private static final int NOTIFY_SCREEN_TURNED_OFF = 16;
171 private static final int NOTIFY_STARTED_GOING_TO_SLEEP = 17;
Adrian Roos30a2ae62018-04-25 19:09:50 +0200172 private static final int SYSTEM_READY = 18;
Jim Miller9c20d0e2010-01-20 15:00:23 -0800173
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800174 /**
175 * The default amount of time we stay awake (used for all key input)
176 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100177 public static final int AWAKE_INTERVAL_DEFAULT_MS = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800178
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800179 /**
180 * How long to wait after the screen turns off due to timeout before
181 * turning on the keyguard (i.e, the user has this much time to turn
182 * the screen back on without having to face the keyguard).
183 */
Jim Millerbc4603b2010-08-30 21:21:34 -0700184 private static final int KEYGUARD_LOCK_AFTER_DELAY_DEFAULT = 5000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800185
186 /**
Craig Mautnerf1b67412012-09-19 13:18:29 -0700187 * How long we'll wait for the {@link ViewMediatorCallback#keyguardDoneDrawing()}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800188 * callback before unblocking a call to {@link #setKeyguardEnabled(boolean)}
189 * that is reenabling the keyguard.
190 */
191 private static final int KEYGUARD_DONE_DRAWING_TIMEOUT_MS = 2000;
Jim Miller9c20d0e2010-01-20 15:00:23 -0800192
Daniel Sandler74d188c2011-08-10 00:00:31 -0400193 /**
Evan Rosky13a58a92016-07-27 15:51:09 -0700194 * Boolean option for doKeyguardLocked/doKeyguardTimeout which, when set to true, forces the
195 * keyguard to show even if it is disabled for the current user.
196 */
197 public static final String OPTION_FORCE_SHOW = "force_show";
198
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700199 /** The stream type that the lock sounds are tied to. */
John Spurlockee5ad722015-03-03 16:17:21 -0500200 private int mUiSoundsStreamType;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700201
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800202 private AlarmManager mAlarmManager;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700203 private AudioManager mAudioManager;
Mike Lockwood5f892c12009-11-19 23:39:13 -0500204 private StatusBarManager mStatusBarManager;
Jorim Jaggie549a8d2017-05-15 02:40:05 +0200205 private final UiOffloadThread mUiOffloadThread = Dependency.get(UiOffloadThread.class);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800206
207 private boolean mSystemReady;
Jason Monkcf5a9532014-09-17 16:22:19 -0400208 private boolean mBootCompleted;
209 private boolean mBootSendUserPresent;
Adrian Roos1f8025a2016-12-27 10:12:13 -0800210 private boolean mShuttingDown;
Daniel Sandler0060a9b2010-03-15 23:09:57 -0400211
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800212 /** High level access to the power manager for WakeLocks */
213 private PowerManager mPM;
214
Adrian Roos481a6df2014-11-20 19:48:56 +0100215 /** TrustManager for letting it know when we change visibility */
216 private TrustManager mTrustManager;
Amith Yamasanib70ff9a2012-09-07 18:28:11 -0700217
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800218 /**
Mike Lockwood674d3e42009-10-06 09:28:54 -0400219 * Used to keep the device awake while to ensure the keyguard finishes opening before
220 * we sleep.
221 */
222 private PowerManager.WakeLock mShowKeyguardWakeLock;
223
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100224 private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800225
226 // these are protected by synchronized (this)
227
228 /**
Mike Lockwood5d258b62009-12-02 13:50:45 -0500229 * External apps (like the phone app) can tell us to disable the keygaurd.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800230 */
231 private boolean mExternallyEnabled = true;
232
233 /**
234 * Remember if an external call to {@link #setKeyguardEnabled} with value
235 * false caused us to hide the keyguard, so that we need to reshow it once
236 * the keygaurd is reenabled with another call with value true.
237 */
238 private boolean mNeedToReshowWhenReenabled = false;
239
240 // cached value of whether we are showing (need to know this to quickly
241 // answer whether the input should be restricted)
Jim Millere5f17ab2013-11-13 15:40:48 -0800242 private boolean mShowing;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800243
Lucas Dupin47a65c72018-02-15 14:16:18 -0800244 // AOD is enabled and status bar is in AOD state.
245 private boolean mAodShowing;
246
David Stevens53a39ea2017-08-23 18:41:49 -0700247 // display id of the secondary display on which we have put a keyguard window
248 private int mSecondaryDisplayShowing = INVALID_DISPLAY;
249
Jim Millerab954542014-10-10 18:21:49 -0700250 /** Cached value of #isInputRestricted */
251 private boolean mInputRestricted;
252
Mike Lockwood09a40402009-11-08 00:33:23 -0500253 // true if the keyguard is hidden by another window
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100254 private boolean mOccluded = false;
Mike Lockwood09a40402009-11-08 00:33:23 -0500255
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800256 /**
257 * Helps remember whether the screen has turned on since the last time
258 * it turned off due to timeout. see {@link #onScreenTurnedOff(int)}
259 */
260 private int mDelayedShowingSequence;
261
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800262 /**
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000263 * Simiar to {@link #mDelayedProfileShowingSequence}, but it is for profile case.
264 */
265 private int mDelayedProfileShowingSequence;
266
267 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800268 * If the user has disabled the keyguard, then requests to exit, this is
269 * how we'll ultimately let them know whether it was successful. We use this
270 * var being non-null as an indicator that there is an in progress request.
271 */
Jim Miller25190572013-02-28 17:36:24 -0800272 private IKeyguardExitCallback mExitSecureCallback;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700273 private final DismissCallbackRegistry mDismissCallbackRegistry = new DismissCallbackRegistry();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800274
275 // the properties of the keyguard
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800276
277 private KeyguardUpdateMonitor mUpdateMonitor;
278
Lucas Dupin2508afe2018-09-17 17:17:14 -0700279 /**
280 * Last SIM state reported by the telephony system.
281 * Index is the slotId - in case of multiple SIM cards.
282 */
283 private final SparseArray<IccCardConstants.State> mLastSimStates = new SparseArray<>();
284
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700285 private boolean mDeviceInteractive;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700286 private boolean mGoingToSleep;
Karl Rosaenab100082009-03-24 22:35:17 -0700287
Daniel Sandlerf2d8e742010-02-22 13:09:48 -0500288 // last known state of the cellular connection
289 private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE;
290
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800291 /**
Jorim Jaggi53c68a42014-06-17 15:04:47 -0700292 * Whether a hide is pending an we are just waiting for #startKeyguardExitAnimation to be
293 * called.
294 * */
295 private boolean mHiding;
296
297 /**
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700298 * we send this intent when the keyguard is dismissed.
299 */
Jim Miller17f509a2013-02-28 18:36:12 -0800300 private static final Intent USER_PRESENT_INTENT = new Intent(Intent.ACTION_USER_PRESENT)
301 .addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
Chad Brubaker291df4f2017-03-14 10:23:02 -0700302 | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
303 | Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700304
305 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800306 * {@link #setKeyguardEnabled} waits on this condition when it reenables
307 * the keyguard.
308 */
309 private boolean mWaitingUntilKeyguardVisible = false;
Jim Millerbc4603b2010-08-30 21:21:34 -0700310 private LockPatternUtils mLockPatternUtils;
John Spurlock34c4fe52012-11-07 10:12:29 -0500311 private boolean mKeyguardDonePending = false;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200312 private boolean mHideAnimationRun = false;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700313 private boolean mHideAnimationRunning = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800314
Marco Nelissend5545bd2011-09-29 12:49:17 -0700315 private SoundPool mLockSounds;
316 private int mLockSoundId;
317 private int mUnlockSoundId;
Adrian Roos49e057d2014-08-13 17:14:51 +0200318 private int mTrustedSoundId;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700319 private int mLockSoundStreamId;
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700320
321 /**
Adrian Roos0002a452014-07-03 13:46:07 +0200322 * The animation used for hiding keyguard. This is used to fetch the animation timings if
323 * WindowManager is not providing us with them.
324 */
325 private Animation mHideAnimation;
326
327 /**
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700328 * The volume applied to the lock/unlock sounds.
329 */
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200330 private float mLockSoundVolume;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700331
Jim Millerdcb3d842012-08-23 19:18:12 -0700332 /**
Jim Miller31921482013-11-06 20:43:55 -0800333 * For managing external displays
334 */
335 private KeyguardDisplayManager mKeyguardDisplayManager;
336
Jim Millerab954542014-10-10 18:21:49 -0700337 private final ArrayList<IKeyguardStateCallback> mKeyguardStateCallbacks = new ArrayList<>();
338
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700339 /**
340 * When starting going to sleep, we figured out that we need to reset Keyguard state and this
341 * should be committed when finished going to sleep.
342 */
343 private boolean mPendingReset;
344
345 /**
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700346 * 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 -0700347 * committed when finished going to sleep.
348 */
349 private boolean mPendingLock;
350
Robin Leec41f6ec2017-01-10 17:02:34 +0000351 /**
352 * Controller for showing individual "work challenge" lock screen windows inside managed profile
353 * tasks when the current user has been unlocked but the profile is still locked.
354 */
355 private WorkLockActivityController mWorkLockController;
356
Lucas Dupind35502f2018-06-27 13:35:52 -0700357 /**
358 * @see #setPulsing(boolean)
359 */
360 private boolean mPulsing;
361
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000362 private boolean mLockLater;
363
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700364 private boolean mWakeAndUnlocking;
365 private IKeyguardDrawnCallback mDrawnCallback;
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800366 private boolean mLockWhenSimRemoved;
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800367 private CharSequence mCustomMessage;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700368
Jim Millerbbf1a742012-07-17 18:30:30 -0700369 KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {
370
371 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500372 public void onUserSwitching(int userId) {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700373 // Note that the mLockPatternUtils user has already been updated from setCurrentUser.
Adam Cohenf7522022012-10-03 20:03:18 -0700374 // We need to force a reset of the views, since lockNow (called by
375 // ActivityManagerService) will not reconstruct the keyguard if it is already showing.
Jim Millerbbf1a742012-07-17 18:30:30 -0700376 synchronized (KeyguardViewMediator.this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100377 resetKeyguardDonePendingLocked();
Alex Chau77ef9fc2018-04-11 15:41:32 +0100378 if (mLockPatternUtils.isLockScreenDisabled(userId)) {
379 // If we switching to a user that has keyguard disabled, dismiss keyguard.
380 dismiss(null /* callback */, null /* message */);
381 } else {
382 resetStateLocked();
383 }
John Spurlock4e6922d2012-10-04 14:51:51 -0400384 adjustStatusBarLocked();
Dianne Hackborn5dc5a002012-09-15 19:33:48 -0700385 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700386 }
387
388 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500389 public void onUserSwitchComplete(int userId) {
Xiaohui Chen87d0e252015-07-30 15:38:16 -0700390 if (userId != UserHandle.USER_SYSTEM) {
Adrian Roosbe47b072014-09-03 00:08:56 +0200391 UserInfo info = UserManager.get(mContext).getUserInfo(userId);
Kevin Chynf2c0a642017-05-25 11:29:08 -0700392 // Don't try to dismiss if the user has Pin/Patter/Password set
393 if (info == null || mLockPatternUtils.isSecure(userId)) {
394 return;
395 } else if (info.isGuest() || info.isDemo()) {
Adrian Roosbe47b072014-09-03 00:08:56 +0200396 // If we just switched to a guest, try to dismiss keyguard.
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800397 dismiss(null /* callback */, null /* message */);
Adrian Roosbe47b072014-09-03 00:08:56 +0200398 }
399 }
Chris Wrenf41c61b2012-11-29 15:19:54 -0500400 }
401
402 @Override
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -0700403 public void onUserInfoChanged(int userId) {
Jim Millerbbf1a742012-07-17 18:30:30 -0700404 }
405
406 @Override
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100407 public void onPhoneStateChanged(int phoneState) {
Jim Millerbbf1a742012-07-17 18:30:30 -0700408 synchronized (KeyguardViewMediator.this) {
409 if (TelephonyManager.CALL_STATE_IDLE == phoneState // call ending
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700410 && !mDeviceInteractive // screen off
Jim Millerbbf1a742012-07-17 18:30:30 -0700411 && mExternallyEnabled) { // not disabled by any app
412
413 // note: this is a way to gracefully reenable the keyguard when the call
414 // ends and the screen is off without always reenabling the keyguard
415 // each time the screen turns off while in call (and having an occasional ugly
416 // flicker while turning back on the screen and disabling the keyguard again).
417 if (DEBUG) Log.d(TAG, "screen is off and call ended, let's make sure the "
418 + "keyguard is showing");
Jim Miller5ecd8112013-01-09 18:50:26 -0800419 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700420 }
421 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100422 }
Jim Millerb0304762012-03-13 20:01:25 -0700423
424 @Override
425 public void onClockVisibilityChanged() {
426 adjustStatusBarLocked();
427 }
428
429 @Override
430 public void onDeviceProvisioned() {
Jim Miller3fd47af2012-09-21 19:55:27 -0700431 sendUserPresentBroadcast();
Amith Yamasanicb15d662015-11-10 11:11:15 -0800432 synchronized (KeyguardViewMediator.this) {
433 // If system user is provisioned, we might want to lock now to avoid showing launcher
Amith Yamasanieb437d42016-04-29 09:31:25 -0700434 if (mustNotUnlockCurrentUser()) {
Amith Yamasanicb15d662015-11-10 11:11:15 -0800435 doKeyguardLocked(null);
436 }
437 }
Jim Millerb0304762012-03-13 20:01:25 -0700438 }
439
Jim Millerbbf1a742012-07-17 18:30:30 -0700440 @Override
Jim Miller52a61332014-11-12 19:29:51 -0800441 public void onSimStateChanged(int subId, int slotId, IccCardConstants.State simState) {
442
443 if (DEBUG_SIM_STATES) {
444 Log.d(TAG, "onSimStateChanged(subId=" + subId + ", slotId=" + slotId
445 + ",state=" + simState + ")");
446 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700447
dooyoung.hwang328472e2015-05-21 16:09:43 +0900448 int size = mKeyguardStateCallbacks.size();
449 boolean simPinSecure = mUpdateMonitor.isSimPinSecure();
450 for (int i = size - 1; i >= 0; i--) {
451 try {
Jim Millerab954542014-10-10 18:21:49 -0700452 mKeyguardStateCallbacks.get(i).onSimSecureStateChanged(simPinSecure);
dooyoung.hwang328472e2015-05-21 16:09:43 +0900453 } catch (RemoteException e) {
454 Slog.w(TAG, "Failed to call onSimSecureStateChanged", e);
455 if (e instanceof DeadObjectException) {
456 mKeyguardStateCallbacks.remove(i);
457 }
Jim Millerab954542014-10-10 18:21:49 -0700458 }
Jim Millerab954542014-10-10 18:21:49 -0700459 }
460
Lucas Dupin2508afe2018-09-17 17:17:14 -0700461 boolean simWasLocked;
462 synchronized (KeyguardViewMediator.this) {
463 IccCardConstants.State lastState = mLastSimStates.get(slotId);
Brad Ebinger4b2f6e22018-12-20 21:11:44 -0800464 simWasLocked = (lastState == PIN_REQUIRED || lastState == PUK_REQUIRED);
Lucas Dupin2508afe2018-09-17 17:17:14 -0700465 mLastSimStates.append(slotId, simState);
466 }
467
Jim Millerbbf1a742012-07-17 18:30:30 -0700468 switch (simState) {
469 case NOT_READY:
470 case ABSENT:
471 // only force lock screen in case of missing sim if user hasn't
472 // gone through setup wizard
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800473 synchronized (KeyguardViewMediator.this) {
Jim Millerb256e4e22014-10-31 17:27:13 -0700474 if (shouldWaitForProvisioning()) {
Jim Millerab954542014-10-10 18:21:49 -0700475 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800476 if (DEBUG_SIM_STATES) Log.d(TAG, "ICC_ABSENT isn't showing,"
Jim Millerbbf1a742012-07-17 18:30:30 -0700477 + " we need to show the keyguard since the "
478 + "device isn't provisioned yet.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800479 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700480 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100481 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700482 }
483 }
Adrian Roose92de952016-12-13 12:07:09 -0800484 if (simState == ABSENT) {
485 // MVNO SIMs can become transiently NOT_READY when switching networks,
486 // so we should only lock when they are ABSENT.
487 onSimAbsentLocked();
Lucas Dupin0b196c62018-12-05 20:03:53 -0800488 if (simWasLocked) {
Brad Ebinger4b2f6e22018-12-20 21:11:44 -0800489 if (DEBUG_SIM_STATES) Log.d(TAG, "SIM moved to ABSENT when the "
490 + "previous state was locked. Reset the state.");
Lucas Dupin0b196c62018-12-05 20:03:53 -0800491 resetStateLocked();
492 }
Adrian Roose92de952016-12-13 12:07:09 -0800493 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700494 }
495 break;
496 case PIN_REQUIRED:
497 case PUK_REQUIRED:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800498 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700499 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800500 if (DEBUG_SIM_STATES) Log.d(TAG,
501 "INTENT_VALUE_ICC_LOCKED and keygaurd isn't "
Jim Millerbbf1a742012-07-17 18:30:30 -0700502 + "showing; need to show keyguard so user can enter sim pin");
Jim Miller5ecd8112013-01-09 18:50:26 -0800503 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700504 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100505 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700506 }
507 }
508 break;
509 case PERM_DISABLED:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800510 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700511 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800512 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED and "
Jim Millerbbf1a742012-07-17 18:30:30 -0700513 + "keygaurd isn't showing.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800514 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700515 } else {
Jim Miller52a61332014-11-12 19:29:51 -0800516 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED, resetStateLocked to"
Jim Millerbbf1a742012-07-17 18:30:30 -0700517 + "show permanently disabled message in lockscreen.");
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100518 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700519 }
Adrian Roose92de952016-12-13 12:07:09 -0800520 onSimAbsentLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700521 }
522 break;
523 case READY:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800524 synchronized (KeyguardViewMediator.this) {
Lucas Dupin2508afe2018-09-17 17:17:14 -0700525 if (DEBUG_SIM_STATES) Log.d(TAG, "READY, reset state? " + mShowing);
526 if (mShowing && simWasLocked) {
Brad Ebinger4b2f6e22018-12-20 21:11:44 -0800527 if (DEBUG_SIM_STATES) Log.d(TAG, "SIM moved to READY when the "
528 + "previous state was locked. Reset the state.");
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100529 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700530 }
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800531 mLockWhenSimRemoved = true;
Jim Millerbbf1a742012-07-17 18:30:30 -0700532 }
533 break;
Jim Miller52a61332014-11-12 19:29:51 -0800534 default:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800535 if (DEBUG_SIM_STATES) Log.v(TAG, "Unspecific state: " + simState);
Jim Miller52a61332014-11-12 19:29:51 -0800536 break;
Jim Millerbbf1a742012-07-17 18:30:30 -0700537 }
538 }
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000539
Adrian Roose92de952016-12-13 12:07:09 -0800540 private void onSimAbsentLocked() {
Adrian Roos1f8025a2016-12-27 10:12:13 -0800541 if (isSecure() && mLockWhenSimRemoved && !mShuttingDown) {
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800542 mLockWhenSimRemoved = false;
543 MetricsLogger.action(mContext,
544 MetricsProto.MetricsEvent.ACTION_LOCK_BECAUSE_SIM_REMOVED, mShowing);
545 if (!mShowing) {
Adrian Roose92de952016-12-13 12:07:09 -0800546 Log.i(TAG, "SIM removed, showing keyguard");
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800547 doKeyguardLocked(null);
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800548 }
549 }
550 }
551
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000552 @Override
553 public void onFingerprintAuthFailed() {
554 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
555 if (mLockPatternUtils.isSecure(currentUser)) {
556 mLockPatternUtils.getDevicePolicyManager().reportFailedFingerprintAttempt(
557 currentUser);
558 }
559 }
560
561 @Override
562 public void onFingerprintAuthenticated(int userId) {
563 if (mLockPatternUtils.isSecure(userId)) {
564 mLockPatternUtils.getDevicePolicyManager().reportSuccessfulFingerprintAttempt(
565 userId);
566 }
567 }
Adrian Roosd88eb262016-08-04 14:50:48 -0700568
569 @Override
570 public void onTrustChanged(int userId) {
571 if (userId == KeyguardUpdateMonitor.getCurrentUser()) {
572 synchronized (KeyguardViewMediator.this) {
573 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(userId));
574 }
575 }
576 }
577
Jorim Jaggid11d1a92016-08-16 16:02:32 -0700578 @Override
579 public void onHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
580 synchronized (KeyguardViewMediator.this) {
581 notifyHasLockscreenWallpaperChanged(hasLockscreenWallpaper);
582 }
583 }
Jim Millerb0304762012-03-13 20:01:25 -0700584 };
585
Jim Millerdcb3d842012-08-23 19:18:12 -0700586 ViewMediatorCallback mViewMediatorCallback = new ViewMediatorCallback() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100587
Jim Miller2967f482016-01-07 15:05:32 -0800588 @Override
Jeff Brownc7505bc2012-10-05 21:58:15 -0700589 public void userActivity() {
590 KeyguardViewMediator.this.userActivity();
591 }
592
Jim Miller2967f482016-01-07 15:05:32 -0800593 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700594 public void keyguardDone(boolean strongAuth, int targetUserId) {
595 if (targetUserId != ActivityManager.getCurrentUser()) {
596 return;
597 }
598
Jorim Jaggi241ae102016-11-02 21:57:33 -0700599 tryKeyguardDone();
Jim Millerdcb3d842012-08-23 19:18:12 -0700600 }
601
Jim Miller2967f482016-01-07 15:05:32 -0800602 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700603 public void keyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700604 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDoneDrawing");
Jim Millerdcb3d842012-08-23 19:18:12 -0700605 mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700606 Trace.endSection();
Jim Millerdcb3d842012-08-23 19:18:12 -0700607 }
608
609 @Override
610 public void setNeedsInput(boolean needsInput) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100611 mStatusBarKeyguardViewManager.setNeedsInput(needsInput);
Jim Millerdcb3d842012-08-23 19:18:12 -0700612 }
Jeff Brownc7505bc2012-10-05 21:58:15 -0700613
614 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700615 public void keyguardDonePending(boolean strongAuth, int targetUserId) {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700616 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDonePending");
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700617 if (targetUserId != ActivityManager.getCurrentUser()) {
Nick Desaulniersaeb2e1e2016-07-27 15:36:01 -0700618 Trace.endSection();
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700619 return;
620 }
621
John Spurlock34c4fe52012-11-07 10:12:29 -0500622 mKeyguardDonePending = true;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200623 mHideAnimationRun = true;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700624 mHideAnimationRunning = true;
625 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100626 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_PENDING_TIMEOUT,
627 KEYGUARD_DONE_PENDING_TIMEOUT_MS);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700628 Trace.endSection();
John Spurlock34c4fe52012-11-07 10:12:29 -0500629 }
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800630
631 @Override
632 public void keyguardGone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700633 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardGone");
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800634 mKeyguardDisplayManager.hide();
Nick Desaulniers1d396752016-07-25 15:05:33 -0700635 Trace.endSection();
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800636 }
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200637
638 @Override
639 public void readyForKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700640 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#readyForKeyguardDone");
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200641 if (mKeyguardDonePending) {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700642 mKeyguardDonePending = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700643 tryKeyguardDone();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200644 }
Nick Desaulniers1d396752016-07-25 15:05:33 -0700645 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200646 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200647
648 @Override
Andrew Lee72b46d42015-01-30 13:23:21 -0800649 public void resetKeyguard() {
650 resetStateLocked();
651 }
652
653 @Override
Matthew Ng66f0b702017-12-08 12:58:42 -0800654 public void onBouncerVisiblityChanged(boolean shown) {
655 synchronized (KeyguardViewMediator.this) {
656 adjustStatusBarLocked(shown);
657 }
658 }
659
660 @Override
Adrian Roos49e057d2014-08-13 17:14:51 +0200661 public void playTrustedSound() {
662 KeyguardViewMediator.this.playTrustedSound();
663 }
Jim Millerab954542014-10-10 18:21:49 -0700664
665 @Override
Adrian Roos94e15a52015-04-16 12:23:18 -0700666 public boolean isScreenOn() {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700667 return mDeviceInteractive;
Adrian Roos94e15a52015-04-16 12:23:18 -0700668 }
Selim Cinek3122fa82015-06-18 01:38:59 -0700669
670 @Override
671 public int getBouncerPromptReason() {
672 int currentUser = ActivityManager.getCurrentUser();
Adrian Roosc13723f2016-01-12 20:29:03 +0100673 boolean trust = mTrustManager.isTrustUsuallyManaged(currentUser);
674 boolean fingerprint = mUpdateMonitor.isUnlockWithFingerprintPossible(currentUser);
675 boolean any = trust || fingerprint;
676 KeyguardUpdateMonitor.StrongAuthTracker strongAuthTracker =
677 mUpdateMonitor.getStrongAuthTracker();
678 int strongAuth = strongAuthTracker.getStrongAuthForUser(currentUser);
679
680 if (any && !strongAuthTracker.hasUserAuthenticatedSinceBoot()) {
Selim Cinek3122fa82015-06-18 01:38:59 -0700681 return KeyguardSecurityView.PROMPT_REASON_RESTART;
Michal Karpinskic52f8672016-11-18 11:32:45 +0000682 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_TIMEOUT) != 0) {
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700683 return KeyguardSecurityView.PROMPT_REASON_TIMEOUT;
Adrian Roosc13723f2016-01-12 20:29:03 +0100684 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW) != 0) {
685 return KeyguardSecurityView.PROMPT_REASON_DEVICE_ADMIN;
686 } else if (trust && (strongAuth & SOME_AUTH_REQUIRED_AFTER_USER_REQUEST) != 0) {
687 return KeyguardSecurityView.PROMPT_REASON_USER_REQUEST;
688 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_LOCKOUT) != 0) {
689 return KeyguardSecurityView.PROMPT_REASON_AFTER_LOCKOUT;
Selim Cinek3122fa82015-06-18 01:38:59 -0700690 }
691 return KeyguardSecurityView.PROMPT_REASON_NONE;
692 }
David Stevens53a39ea2017-08-23 18:41:49 -0700693
694 @Override
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800695 public CharSequence consumeCustomMessage() {
696 final CharSequence message = mCustomMessage;
697 mCustomMessage = null;
698 return message;
699 }
700
701 @Override
David Stevens53a39ea2017-08-23 18:41:49 -0700702 public void onSecondaryDisplayShowingChanged(int displayId) {
703 synchronized (KeyguardViewMediator.this) {
Lucas Dupin47a65c72018-02-15 14:16:18 -0800704 setShowingLocked(mShowing, mAodShowing, displayId, false);
David Stevens53a39ea2017-08-23 18:41:49 -0700705 }
706 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700707 };
708
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200709 public void userActivity() {
Jeff Brown3dc524b2012-09-30 19:49:11 -0700710 mPM.userActivity(SystemClock.uptimeMillis(), false);
Jim Millerdcb3d842012-08-23 19:18:12 -0700711 }
712
Amith Yamasanieb437d42016-04-29 09:31:25 -0700713 boolean mustNotUnlockCurrentUser() {
Christine Franks338c6ed2017-08-08 09:39:16 -0700714 return UserManager.isSplitSystemUser()
Amith Yamasanieb437d42016-04-29 09:31:25 -0700715 && KeyguardUpdateMonitor.getCurrentUser() == UserHandle.USER_SYSTEM;
716 }
717
Jim Millerab954542014-10-10 18:21:49 -0700718 private void setupLocked() {
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200719 mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
Adrian Roos481a6df2014-11-20 19:48:56 +0100720 mTrustManager = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE);
721
Mike Lockwood674d3e42009-10-06 09:28:54 -0400722 mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
723 mShowKeyguardWakeLock.setReferenceCounted(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800724
Adrian Roos1f8025a2016-12-27 10:12:13 -0800725 IntentFilter filter = new IntentFilter();
Adrian Roos1f8025a2016-12-27 10:12:13 -0800726 filter.addAction(Intent.ACTION_SHUTDOWN);
727 mContext.registerReceiver(mBroadcastReceiver, filter);
Jim Millerbbf1a742012-07-17 18:30:30 -0700728
Kevin Chyn18e91aa2018-04-11 12:55:45 -0700729 final IntentFilter delayedActionFilter = new IntentFilter();
730 delayedActionFilter.addAction(DELAYED_KEYGUARD_ACTION);
731 delayedActionFilter.addAction(DELAYED_LOCK_PROFILE_ACTION);
732 mContext.registerReceiver(mDelayedLockBroadcastReceiver, delayedActionFilter,
733 SYSTEMUI_PERMISSION, null /* scheduler */);
734
David Stevens53a39ea2017-08-23 18:41:49 -0700735 mKeyguardDisplayManager = new KeyguardDisplayManager(mContext, mViewMediatorCallback);
Jim Miller31921482013-11-06 20:43:55 -0800736
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200737 mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800738
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200739 mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800740
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200741 mLockPatternUtils = new LockPatternUtils(mContext);
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700742 KeyguardUpdateMonitor.setCurrentUser(ActivityManager.getCurrentUser());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800743
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200744 // Assume keyguard is showing (unless it's disabled) until we know for sure, unless Keyguard
745 // is disabled.
746 if (mContext.getResources().getBoolean(
747 com.android.keyguard.R.bool.config_enableKeyguardService)) {
748 setShowingLocked(!shouldWaitForProvisioning()
749 && !mLockPatternUtils.isLockScreenDisabled(
David Stevens53a39ea2017-08-23 18:41:49 -0700750 KeyguardUpdateMonitor.getCurrentUser()),
Lucas Dupin47a65c72018-02-15 14:16:18 -0800751 mAodShowing, mSecondaryDisplayShowing, true /* forceCallbacks */);
Leif Hendrik Wildenc6dc1c92018-02-01 10:54:15 -0800752 } else {
753 // The system's keyguard is disabled or missing.
Lucas Dupin47a65c72018-02-15 14:16:18 -0800754 setShowingLocked(false, mAodShowing, mSecondaryDisplayShowing, true);
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200755 }
Jim Millere5f17ab2013-11-13 15:40:48 -0800756
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800757 mStatusBarKeyguardViewManager =
758 SystemUIFactory.getInstance().createStatusBarKeyguardViewManager(mContext,
759 mViewMediatorCallback, mLockPatternUtils);
Daniel Sandler687a3272010-03-13 15:44:47 -0500760 final ContentResolver cr = mContext.getContentResolver();
Marco Nelissend5545bd2011-09-29 12:49:17 -0700761
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700762 mDeviceInteractive = mPM.isInteractive();
Daniel Hansson4b716862012-03-29 11:02:05 +0200763
Marco Nelissend5545bd2011-09-29 12:49:17 -0700764 mLockSounds = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
Jim Millerb14288d2012-09-30 18:25:05 -0700765 String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700766 if (soundPath != null) {
767 mLockSoundId = mLockSounds.load(soundPath, 1);
768 }
769 if (soundPath == null || mLockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700770 Log.w(TAG, "failed to load lock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700771 }
Jim Millerb14288d2012-09-30 18:25:05 -0700772 soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700773 if (soundPath != null) {
774 mUnlockSoundId = mLockSounds.load(soundPath, 1);
775 }
776 if (soundPath == null || mUnlockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700777 Log.w(TAG, "failed to load unlock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700778 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200779 soundPath = Settings.Global.getString(cr, Settings.Global.TRUSTED_SOUND);
780 if (soundPath != null) {
781 mTrustedSoundId = mLockSounds.load(soundPath, 1);
782 }
783 if (soundPath == null || mTrustedSoundId == 0) {
784 Log.w(TAG, "failed to load trusted sound from " + soundPath);
785 }
786
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200787 int lockSoundDefaultAttenuation = mContext.getResources().getInteger(
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700788 com.android.internal.R.integer.config_lockSoundVolumeDb);
Jean-Michel Trivif2b0c112012-07-09 11:59:11 -0700789 mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20);
Adrian Roos0002a452014-07-03 13:46:07 +0200790
791 mHideAnimation = AnimationUtils.loadAnimation(mContext,
792 com.android.internal.R.anim.lock_screen_behind_enter);
Robin Leec41f6ec2017-01-10 17:02:34 +0000793
794 mWorkLockController = new WorkLockActivityController(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800795 }
796
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200797 @Override
798 public void start() {
Jim Millerab954542014-10-10 18:21:49 -0700799 synchronized (this) {
800 setupLocked();
801 }
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200802 putComponent(KeyguardViewMediator.class, this);
803 }
804
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800805 /**
806 * Let us know that the system is ready after startup.
807 */
808 public void onSystemReady() {
Adrian Roos30a2ae62018-04-25 19:09:50 +0200809 mHandler.obtainMessage(SYSTEM_READY).sendToTarget();
810 }
811
812 private void handleSystemReady() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800813 synchronized (this) {
814 if (DEBUG) Log.d(TAG, "onSystemReady");
815 mSystemReady = true;
Jim Miller5ecd8112013-01-09 18:50:26 -0800816 doKeyguardLocked(null);
Selim Cinekedd32b82015-06-23 22:05:58 -0400817 mUpdateMonitor.registerCallback(mUpdateCallback);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800818 }
Jim Miller3fd47af2012-09-21 19:55:27 -0700819 // Most services aren't available until the system reaches the ready state, so we
820 // send it here when the device first boots.
821 maybeSendUserPresentBroadcast();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800822 }
823
824 /**
825 * Called to let us know the screen was turned off.
Adrian Roose99bc052017-11-20 17:55:31 +0100826 * @param why either {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_USER} or
827 * {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_TIMEOUT}.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800828 */
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700829 public void onStartedGoingToSleep(int why) {
830 if (DEBUG) Log.d(TAG, "onStartedGoingToSleep(" + why + ")");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800831 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700832 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700833 mGoingToSleep = true;
John Spurlock14adfe42012-11-08 10:29:26 -0500834
Jim Millera4edd152012-01-06 18:24:04 -0800835 // Lock immediately based on setting if secure (user has a pin/pattern/password).
836 // This also "locks" the device when not secure to provide easy access to the
837 // camera while preventing unwanted input.
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700838 int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jim Millera4edd152012-01-06 18:24:04 -0800839 final boolean lockImmediately =
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700840 mLockPatternUtils.getPowerButtonInstantlyLocks(currentUser)
841 || !mLockPatternUtils.isSecure(currentUser);
Clara Bayarri56878a92015-10-29 15:43:55 +0000842 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000843 mLockLater = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800844 if (mExitSecureCallback != null) {
845 if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled");
Jim Miller5ecd8112013-01-09 18:50:26 -0800846 try {
847 mExitSecureCallback.onKeyguardExitResult(false);
848 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800849 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800850 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800851 mExitSecureCallback = null;
852 if (!mExternallyEnabled) {
Jim Miller9c20d0e2010-01-20 15:00:23 -0800853 hideLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800854 }
855 } else if (mShowing) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700856 mPendingReset = true;
Adrian Roose99bc052017-11-20 17:55:31 +0100857 } else if ((why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_TIMEOUT && timeout > 0)
858 || (why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER && !lockImmediately)) {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700859 doKeyguardLaterLocked(timeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000860 mLockLater = true;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700861 } else if (!mLockPatternUtils.isLockScreenDisabled(currentUser)) {
862 mPendingLock = true;
863 }
864
Jorim Jaggi853cbe32015-06-04 16:31:54 -0700865 if (mPendingLock) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700866 playSounds(true);
867 }
868 }
Jorim Jaggi95e40382015-09-16 15:53:42 -0700869 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedGoingToSleep(why);
Jorim Jaggi18f18ae2015-09-10 15:48:21 -0700870 notifyStartedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700871 }
872
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700873 public void onFinishedGoingToSleep(int why, boolean cameraGestureTriggered) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700874 if (DEBUG) Log.d(TAG, "onFinishedGoingToSleep(" + why + ")");
875 synchronized (this) {
876 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700877 mGoingToSleep = false;
Adrian Roose4cb6c8a2017-07-19 18:08:07 +0200878 mWakeAndUnlocking = false;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700879
880 resetKeyguardDonePendingLocked();
881 mHideAnimationRun = false;
882
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700883 notifyFinishedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700884
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700885 if (cameraGestureTriggered) {
886 Log.i(TAG, "Camera gesture was triggered, preventing Keyguard locking.");
887
888 // Just to make sure, make sure the device is awake.
889 mContext.getSystemService(PowerManager.class).wakeUp(SystemClock.uptimeMillis(),
890 "com.android.systemui:CAMERA_GESTURE_PREVENT_LOCK");
891 mPendingLock = false;
892 mPendingReset = false;
893 }
894
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700895 if (mPendingReset) {
896 resetStateLocked();
897 mPendingReset = false;
898 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000899
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700900 if (mPendingLock) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800901 doKeyguardLocked(null);
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700902 mPendingLock = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800903 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000904
905 // We do not have timeout and power button instant lock setting for profile lock.
906 // So we use the personal setting if there is any. But if there is no device
907 // we need to make sure we lock it immediately when the screen is off.
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700908 if (!mLockLater && !cameraGestureTriggered) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000909 doKeyguardForChildProfilesLocked();
910 }
911
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800912 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700913 KeyguardUpdateMonitor.getInstance(mContext).dispatchFinishedGoingToSleep(why);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800914 }
915
Clara Bayarri56878a92015-10-29 15:43:55 +0000916 private long getLockTimeout(int userId) {
Jeff Brown6aaf2952012-10-05 16:01:08 -0700917 // if the screen turned off because of timeout or the user hit the power button
918 // and we don't need to lock immediately, set an alarm
919 // to enable it a little bit later (i.e, give the user a chance
920 // to turn the screen back on within a certain window without
921 // having to unlock the screen)
922 final ContentResolver cr = mContext.getContentResolver();
923
Jeff Brown6aaf2952012-10-05 16:01:08 -0700924 // From SecuritySettings
925 final long lockAfterTimeout = Settings.Secure.getInt(cr,
926 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT,
927 KEYGUARD_LOCK_AFTER_DELAY_DEFAULT);
928
929 // From DevicePolicyAdmin
930 final long policyTimeout = mLockPatternUtils.getDevicePolicyManager()
Pavel Grafov28939982017-10-03 15:11:52 +0100931 .getMaximumTimeToLock(null, userId);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700932
933 long timeout;
Clara Bayarri56878a92015-10-29 15:43:55 +0000934
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000935 if (policyTimeout <= 0) {
Clara Bayarri56878a92015-10-29 15:43:55 +0000936 timeout = lockAfterTimeout;
937 } else {
938 // From DisplaySettings
939 long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT,
940 KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT);
941
Jeff Brown6aaf2952012-10-05 16:01:08 -0700942 // policy in effect. Make sure we don't go beyond policy limit.
943 displayTimeout = Math.max(displayTimeout, 0); // ignore negative values
944 timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000945 timeout = Math.max(timeout, 0);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700946 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700947 return timeout;
948 }
Jeff Brown6aaf2952012-10-05 16:01:08 -0700949
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700950 private void doKeyguardLaterLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000951 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700952 if (timeout == 0) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800953 doKeyguardLocked(null);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700954 } else {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700955 doKeyguardLaterLocked(timeout);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700956 }
957 }
958
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700959 private void doKeyguardLaterLocked(long timeout) {
960 // Lock in the future
961 long when = SystemClock.elapsedRealtime() + timeout;
962 Intent intent = new Intent(DELAYED_KEYGUARD_ACTION);
963 intent.putExtra("seq", mDelayedShowingSequence);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700964 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700965 PendingIntent sender = PendingIntent.getBroadcast(mContext,
966 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Jim Millera622d3cc2016-03-02 16:02:24 -0800967 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700968 if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = "
969 + mDelayedShowingSequence);
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000970 doKeyguardLaterForChildProfilesLocked();
Clara Bayarri56878a92015-10-29 15:43:55 +0000971 }
Clara Bayarri10ad84a2015-12-01 17:38:05 +0000972
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000973 private void doKeyguardLaterForChildProfilesLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000974 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700975 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
976 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
977 long userTimeout = getLockTimeout(profileId);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000978 if (userTimeout == 0) {
979 doKeyguardForChildProfilesLocked();
980 } else {
981 long userWhen = SystemClock.elapsedRealtime() + userTimeout;
982 Intent lockIntent = new Intent(DELAYED_LOCK_PROFILE_ACTION);
983 lockIntent.putExtra("seq", mDelayedProfileShowingSequence);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700984 lockIntent.putExtra(Intent.EXTRA_USER_ID, profileId);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700985 lockIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000986 PendingIntent lockSender = PendingIntent.getBroadcast(
987 mContext, 0, lockIntent, PendingIntent.FLAG_CANCEL_CURRENT);
988 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
989 userWhen, lockSender);
990 }
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000991 }
992 }
993 }
994
995 private void doKeyguardForChildProfilesLocked() {
996 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700997 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
998 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
999 lockProfile(profileId);
Clara Bayarri56878a92015-10-29 15:43:55 +00001000 }
1001 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -07001002 }
1003
Jeff Brown6aaf2952012-10-05 16:01:08 -07001004 private void cancelDoKeyguardLaterLocked() {
1005 mDelayedShowingSequence++;
1006 }
1007
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001008 private void cancelDoKeyguardForChildProfilesLocked() {
1009 mDelayedProfileShowingSequence++;
1010 }
1011
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001012 /**
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001013 * Let's us know when the device is waking up.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001014 */
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001015 public void onStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001016 Trace.beginSection("KeyguardViewMediator#onStartedWakingUp");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001017
1018 // TODO: Rename all screen off/on references to interactive/sleeping
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001019 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001020 mDeviceInteractive = true;
Jeff Brown6aaf2952012-10-05 16:01:08 -07001021 cancelDoKeyguardLaterLocked();
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001022 cancelDoKeyguardForChildProfilesLocked();
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001023 if (DEBUG) Log.d(TAG, "onStartedWakingUp, seq = " + mDelayedShowingSequence);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001024 notifyStartedWakingUp();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001025 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001026 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedWakingUp();
Jim Miller3fd47af2012-09-21 19:55:27 -07001027 maybeSendUserPresentBroadcast();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001028 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -07001029 }
1030
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001031 public void onScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001032 Trace.beginSection("KeyguardViewMediator#onScreenTurningOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001033 notifyScreenOn(callback);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001034 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001035 }
1036
1037 public void onScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001038 Trace.beginSection("KeyguardViewMediator#onScreenTurnedOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001039 notifyScreenTurnedOn();
1040 mUpdateMonitor.dispatchScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001041 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001042 }
1043
1044 public void onScreenTurnedOff() {
1045 notifyScreenTurnedOff();
1046 mUpdateMonitor.dispatchScreenTurnedOff();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001047 }
1048
Jim Miller3fd47af2012-09-21 19:55:27 -07001049 private void maybeSendUserPresentBroadcast() {
Adrian Roos8150d2a2015-04-16 17:11:20 -07001050 if (mSystemReady && mLockPatternUtils.isLockScreenDisabled(
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001051 KeyguardUpdateMonitor.getCurrentUser())) {
Jim Miller3fd47af2012-09-21 19:55:27 -07001052 // Lock screen is disabled because the user has set the preference to "None".
1053 // In this case, send out ACTION_USER_PRESENT here instead of in
1054 // handleKeyguardDone()
1055 sendUserPresentBroadcast();
Adrian Roosfb95a812016-06-20 14:58:59 -07001056 } else if (mSystemReady && shouldWaitForProvisioning()) {
1057 // Skipping the lockscreen because we're not yet provisioned, but we still need to
1058 // notify the StrongAuthTracker that it's now safe to run trust agents, in case the
1059 // user sets a credential later.
1060 getLockPatternUtils().userPresent(KeyguardUpdateMonitor.getCurrentUser());
Jim Miller3fd47af2012-09-21 19:55:27 -07001061 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001062 }
1063
1064 /**
Jeff Brown6aaf2952012-10-05 16:01:08 -07001065 * A dream started. We should lock after the usual screen-off lock timeout but only
1066 * if there is a secure lock pattern.
1067 */
1068 public void onDreamingStarted() {
Selim Cinek99415392016-09-09 14:58:41 -07001069 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001070 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001071 if (mDeviceInteractive
1072 && mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001073 doKeyguardLaterLocked();
1074 }
1075 }
1076 }
1077
1078 /**
1079 * A dream stopped.
1080 */
1081 public void onDreamingStopped() {
Selim Cinek99415392016-09-09 14:58:41 -07001082 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001083 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001084 if (mDeviceInteractive) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001085 cancelDoKeyguardLaterLocked();
1086 }
1087 }
1088 }
1089
1090 /**
Adrian Roose99bc052017-11-20 17:55:31 +01001091 * Same semantics as {@link WindowManagerPolicyConstants#enableKeyguard}; provide
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001092 * a way for external stuff to override normal keyguard behavior. For instance
1093 * the phone app disables the keyguard when it receives incoming calls.
1094 */
1095 public void setKeyguardEnabled(boolean enabled) {
1096 synchronized (this) {
1097 if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")");
1098
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001099 mExternallyEnabled = enabled;
1100
1101 if (!enabled && mShowing) {
1102 if (mExitSecureCallback != null) {
1103 if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring");
1104 // we're in the process of handling a request to verify the user
1105 // can get past the keyguard. ignore extraneous requests to disable / reenable
1106 return;
1107 }
1108
1109 // hiding keyguard that is showing, remember to reshow later
1110 if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, "
1111 + "disabling status bar expansion");
1112 mNeedToReshowWhenReenabled = true;
Jim Millerab954542014-10-10 18:21:49 -07001113 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001114 hideLocked();
1115 } else if (enabled && mNeedToReshowWhenReenabled) {
1116 // reenabled after previously hidden, reshow
1117 if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling "
1118 + "status bar expansion");
1119 mNeedToReshowWhenReenabled = false;
Jim Millerab954542014-10-10 18:21:49 -07001120 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001121
1122 if (mExitSecureCallback != null) {
1123 if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting");
Jim Miller5ecd8112013-01-09 18:50:26 -08001124 try {
1125 mExitSecureCallback.onKeyguardExitResult(false);
1126 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001127 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001128 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001129 mExitSecureCallback = null;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001130 resetStateLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001131 } else {
Adam Cohenf7522022012-10-03 20:03:18 -07001132 showLocked(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001133
1134 // block until we know the keygaurd is done drawing (and post a message
1135 // to unblock us after a timeout so we don't risk blocking too long
1136 // and causing an ANR).
1137 mWaitingUntilKeyguardVisible = true;
1138 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS);
1139 if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false");
1140 while (mWaitingUntilKeyguardVisible) {
1141 try {
1142 wait();
1143 } catch (InterruptedException e) {
1144 Thread.currentThread().interrupt();
1145 }
1146 }
1147 if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible");
1148 }
1149 }
1150 }
1151 }
1152
1153 /**
1154 * @see android.app.KeyguardManager#exitKeyguardSecurely
1155 */
Jim Miller25190572013-02-28 17:36:24 -08001156 public void verifyUnlock(IKeyguardExitCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001157 Trace.beginSection("KeyguardViewMediator#verifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001158 synchronized (this) {
1159 if (DEBUG) Log.d(TAG, "verifyUnlock");
Jim Millerb256e4e22014-10-31 17:27:13 -07001160 if (shouldWaitForProvisioning()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001161 // don't allow this api when the device isn't provisioned
1162 if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned");
Jim Miller5ecd8112013-01-09 18:50:26 -08001163 try {
Jim Miller25190572013-02-28 17:36:24 -08001164 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001165 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001166 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001167 }
Mike Lockwood5d258b62009-12-02 13:50:45 -05001168 } else if (mExternallyEnabled) {
1169 // this only applies when the user has externally disabled the
1170 // keyguard. this is unexpected and means the user is not
1171 // using the api properly.
1172 Log.w(TAG, "verifyUnlock called when not externally disabled");
Jim Miller5ecd8112013-01-09 18:50:26 -08001173 try {
Jim Miller25190572013-02-28 17:36:24 -08001174 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001175 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001176 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001177 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001178 } else if (mExitSecureCallback != null) {
1179 // already in progress with someone else
Jim Miller5ecd8112013-01-09 18:50:26 -08001180 try {
Jim Miller25190572013-02-28 17:36:24 -08001181 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001182 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001183 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001184 }
Jorim Jaggi302475e2015-09-22 12:44:47 -07001185 } else if (!isSecure()) {
1186
1187 // Keyguard is not secure, no need to do anything, and we don't need to reshow
1188 // the Keyguard after the client releases the Keyguard lock.
1189 mExternallyEnabled = true;
1190 mNeedToReshowWhenReenabled = false;
1191 updateInputRestricted();
1192 try {
1193 callback.onKeyguardExitResult(true);
1194 } catch (RemoteException e) {
1195 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1196 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001197 } else {
Jorim Jaggi302475e2015-09-22 12:44:47 -07001198
1199 // Since we prevent apps from hiding the Keyguard if we are secure, this should be
1200 // a no-op as well.
1201 try {
1202 callback.onKeyguardExitResult(false);
1203 } catch (RemoteException e) {
1204 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1205 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001206 }
1207 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001208 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001209 }
1210
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001211 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001212 * Is the keyguard currently showing and not being force hidden?
Mike Lockwood09a40402009-11-08 00:33:23 -05001213 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001214 public boolean isShowingAndNotOccluded() {
1215 return mShowing && !mOccluded;
1216 }
1217
1218 /**
1219 * Notify us when the keyguard is occluded by another window
1220 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001221 public void setOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001222 Trace.beginSection("KeyguardViewMediator#setOccluded");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001223 if (DEBUG) Log.d(TAG, "setOccluded " + isOccluded);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001224 mHandler.removeMessages(SET_OCCLUDED);
Jorim Jaggi6626f542016-08-22 13:08:44 -07001225 Message msg = mHandler.obtainMessage(SET_OCCLUDED, isOccluded ? 1 : 0, animate ? 1 : 0);
Mike Lockwood9200a392009-11-17 20:25:58 -05001226 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001227 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001228 }
1229
Lucas Dupin2986c152018-04-09 20:49:41 -07001230 public boolean isHiding() {
1231 return mHiding;
1232 }
1233
Mike Lockwood9200a392009-11-17 20:25:58 -05001234 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001235 * Handles SET_OCCLUDED message sent by setOccluded()
Mike Lockwood9200a392009-11-17 20:25:58 -05001236 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001237 private void handleSetOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001238 Trace.beginSection("KeyguardViewMediator#handleSetOccluded");
Mike Lockwood09a40402009-11-08 00:33:23 -05001239 synchronized (KeyguardViewMediator.this) {
Adrian Roosf253eeb2015-04-15 18:03:08 -07001240 if (mHiding && isOccluded) {
1241 // We're in the process of going away but WindowManager wants to show a
1242 // SHOW_WHEN_LOCKED activity instead.
1243 startKeyguardExitAnimation(0, 0);
1244 }
1245
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001246 if (mOccluded != isOccluded) {
1247 mOccluded = isOccluded;
Kevin Chyn2fefd462017-04-28 12:18:19 -07001248 mUpdateMonitor.setKeyguardOccluded(isOccluded);
Selim Cinek2f6272e2017-03-15 16:19:10 -07001249 mStatusBarKeyguardViewManager.setOccluded(isOccluded, animate
1250 && mDeviceInteractive);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001251 adjustStatusBarLocked();
Mike Lockwood9200a392009-11-17 20:25:58 -05001252 }
Mike Lockwood09a40402009-11-08 00:33:23 -05001253 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001254 Trace.endSection();
Mike Lockwood09a40402009-11-08 00:33:23 -05001255 }
1256
1257 /**
Mike Lockwood28569302010-01-28 11:54:40 -05001258 * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout.
1259 * This must be safe to call from any thread and with any window manager locks held.
1260 */
Adam Cohenf7522022012-10-03 20:03:18 -07001261 public void doKeyguardTimeout(Bundle options) {
Mike Lockwood28569302010-01-28 11:54:40 -05001262 mHandler.removeMessages(KEYGUARD_TIMEOUT);
Adam Cohenf7522022012-10-03 20:03:18 -07001263 Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options);
Mike Lockwood28569302010-01-28 11:54:40 -05001264 mHandler.sendMessage(msg);
1265 }
1266
1267 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001268 * Given the state of the keyguard, is the input restricted?
1269 * Input is restricted when the keyguard is showing, or when the keyguard
1270 * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet.
1271 */
1272 public boolean isInputRestricted() {
Adrian Roos9f33d6c2015-06-15 15:58:35 -07001273 return mShowing || mNeedToReshowWhenReenabled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001274 }
1275
Jim Millerab954542014-10-10 18:21:49 -07001276 private void updateInputRestricted() {
1277 synchronized (this) {
1278 updateInputRestrictedLocked();
1279 }
1280 }
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001281
Jim Millerab954542014-10-10 18:21:49 -07001282 private void updateInputRestrictedLocked() {
1283 boolean inputRestricted = isInputRestricted();
1284 if (mInputRestricted != inputRestricted) {
1285 mInputRestricted = inputRestricted;
dooyoung.hwang328472e2015-05-21 16:09:43 +09001286 int size = mKeyguardStateCallbacks.size();
1287 for (int i = size - 1; i >= 0; i--) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001288 final IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001289 try {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001290 callback.onInputRestrictedStateChanged(inputRestricted);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001291 } catch (RemoteException e) {
1292 Slog.w(TAG, "Failed to call onDeviceProvisioned", e);
1293 if (e instanceof DeadObjectException) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001294 mKeyguardStateCallbacks.remove(callback);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001295 }
Jim Millerab954542014-10-10 18:21:49 -07001296 }
Jim Millerab954542014-10-10 18:21:49 -07001297 }
1298 }
1299 }
1300
Dianne Hackbornb446e972009-09-20 15:23:25 -07001301 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001302 * Enable the keyguard if the settings are appropriate.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001303 */
Adam Cohenf7522022012-10-03 20:03:18 -07001304 private void doKeyguardLocked(Bundle options) {
Adrian Roosca8a2162017-08-17 19:00:58 +02001305 if (KeyguardUpdateMonitor.CORE_APPS_ONLY) {
1306 // Don't show keyguard during half-booted cryptkeeper stage.
1307 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because booting to cryptkeeper");
1308 return;
1309 }
1310
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001311 // if another app is disabling us, don't show
1312 if (!mExternallyEnabled) {
1313 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled");
Karl Rosaenab100082009-03-24 22:35:17 -07001314
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001315 // note: we *should* set mNeedToReshowWhenReenabled=true here, but that makes
1316 // for an occasional ugly flicker in this situation:
1317 // 1) receive a call with the screen on (no keyguard) or make a call
1318 // 2) screen times out
1319 // 3) user hits key to turn screen back on
1320 // instead, we reenable the keyguard when we know the screen is off and the call
1321 // ends (see the broadcast receiver below)
1322 // TODO: clean this up when we have better support at the window manager level
1323 // for apps that wish to be on top of the keyguard
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001324 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001325 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001326
1327 // if the keyguard is already showing, don't bother
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001328 if (mStatusBarKeyguardViewManager.isShowing()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001329 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing");
Jorim Jaggi95e89ca2014-11-24 20:12:50 +01001330 resetStateLocked();
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001331 return;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001332 }
1333
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001334 // In split system user mode, we never unlock system user.
Amith Yamasanieb437d42016-04-29 09:31:25 -07001335 if (!mustNotUnlockCurrentUser()
Amith Yamasani27e025b2015-11-06 10:34:41 -08001336 || !mUpdateMonitor.isDeviceProvisioned()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001337
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001338 // if the setup wizard hasn't run yet, don't show
1339 final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", false);
1340 final boolean absent = SubscriptionManager.isValidSubscriptionId(
Adrian Roose92de952016-12-13 12:07:09 -08001341 mUpdateMonitor.getNextSubIdForState(ABSENT));
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001342 final boolean disabled = SubscriptionManager.isValidSubscriptionId(
1343 mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.PERM_DISABLED));
1344 final boolean lockedOrMissing = mUpdateMonitor.isSimPinSecure()
1345 || ((absent || disabled) && requireSim);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001346
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001347 if (!lockedOrMissing && shouldWaitForProvisioning()) {
1348 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned"
1349 + " and the sim is not locked or missing");
1350 return;
1351 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001352
Evan Rosky13a58a92016-07-27 15:51:09 -07001353 boolean forceShow = options != null && options.getBoolean(OPTION_FORCE_SHOW, false);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001354 if (mLockPatternUtils.isLockScreenDisabled(KeyguardUpdateMonitor.getCurrentUser())
Evan Rosky13a58a92016-07-27 15:51:09 -07001355 && !lockedOrMissing && !forceShow) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001356 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off");
1357 return;
1358 }
1359
1360 if (mLockPatternUtils.checkVoldPassword(KeyguardUpdateMonitor.getCurrentUser())) {
1361 if (DEBUG) Log.d(TAG, "Not showing lock screen since just decrypted");
1362 // Without this, settings is not enabled until the lock screen first appears
Lucas Dupin47a65c72018-02-15 14:16:18 -08001363 setShowingLocked(false, mAodShowing);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001364 hideLocked();
1365 return;
1366 }
Paul Lawrence945490c2014-03-27 16:37:28 +00001367 }
1368
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001369 if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");
Adam Cohenf7522022012-10-03 20:03:18 -07001370 showLocked(options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001371 }
1372
Clara Bayarri56878a92015-10-29 15:43:55 +00001373 private void lockProfile(int userId) {
1374 mTrustManager.setDeviceLockedForUser(userId, true);
1375 }
1376
Jim Millerb256e4e22014-10-31 17:27:13 -07001377 private boolean shouldWaitForProvisioning() {
1378 return !mUpdateMonitor.isDeviceProvisioned() && !isSecure();
1379 }
1380
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001381 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001382 * Dismiss the keyguard through the security layers.
Jorim Jaggi241ae102016-11-02 21:57:33 -07001383 * @param callback Callback to be informed about the result
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001384 * @param message Message that should be displayed on the bouncer.
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001385 */
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001386 private void handleDismiss(IKeyguardDismissCallback callback, CharSequence message) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001387 if (mShowing) {
1388 if (callback != null) {
1389 mDismissCallbackRegistry.addCallback(callback);
1390 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001391 mCustomMessage = message;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001392 mStatusBarKeyguardViewManager.dismissAndCollapse();
Jorim Jaggi241ae102016-11-02 21:57:33 -07001393 } else if (callback != null) {
1394 new DismissCallbackWrapper(callback).notifyDismissError();
Jim Miller87d03662012-11-05 20:28:09 -08001395 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001396 }
1397
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001398 public void dismiss(IKeyguardDismissCallback callback, CharSequence message) {
1399 mHandler.obtainMessage(DISMISS, new DismissMessage(callback, message)).sendToTarget();
Jim Miller60013792013-10-03 18:31:34 -07001400 }
1401
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001402 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001403 * Send message to keyguard telling it to reset its state.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001404 * @see #handleReset
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001405 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001406 private void resetStateLocked() {
Jim Miller4894a012013-04-03 15:23:55 -07001407 if (DEBUG) Log.e(TAG, "resetStateLocked");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001408 Message msg = mHandler.obtainMessage(RESET);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001409 mHandler.sendMessage(msg);
1410 }
1411
1412 /**
1413 * Send message to keyguard telling it to verify unlock
1414 * @see #handleVerifyUnlock()
1415 */
1416 private void verifyUnlockLocked() {
1417 if (DEBUG) Log.d(TAG, "verifyUnlockLocked");
1418 mHandler.sendEmptyMessage(VERIFY_UNLOCK);
1419 }
1420
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001421 private void notifyStartedGoingToSleep() {
1422 if (DEBUG) Log.d(TAG, "notifyStartedGoingToSleep");
1423 mHandler.sendEmptyMessage(NOTIFY_STARTED_GOING_TO_SLEEP);
1424 }
1425
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001426 private void notifyFinishedGoingToSleep() {
1427 if (DEBUG) Log.d(TAG, "notifyFinishedGoingToSleep");
1428 mHandler.sendEmptyMessage(NOTIFY_FINISHED_GOING_TO_SLEEP);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001429 }
1430
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001431 private void notifyStartedWakingUp() {
1432 if (DEBUG) Log.d(TAG, "notifyStartedWakingUp");
1433 mHandler.sendEmptyMessage(NOTIFY_STARTED_WAKING_UP);
1434 }
1435
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001436 private void notifyScreenOn(IKeyguardDrawnCallback callback) {
1437 if (DEBUG) Log.d(TAG, "notifyScreenOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001438 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNING_ON, callback);
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001439 mHandler.sendMessage(msg);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001440 }
1441
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001442 private void notifyScreenTurnedOn() {
1443 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOn");
1444 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_ON);
1445 mHandler.sendMessage(msg);
1446 }
1447
1448 private void notifyScreenTurnedOff() {
1449 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOff");
1450 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_OFF);
1451 mHandler.sendMessage(msg);
1452 }
1453
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001454 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001455 * Send message to keyguard telling it to show itself
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001456 * @see #handleShow
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001457 */
Adam Cohenf7522022012-10-03 20:03:18 -07001458 private void showLocked(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001459 Trace.beginSection("KeyguardViewMediator#showLocked aqcuiring mShowKeyguardWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001460 if (DEBUG) Log.d(TAG, "showLocked");
Mike Lockwood674d3e42009-10-06 09:28:54 -04001461 // ensure we stay awake until we are finished displaying the keyguard
1462 mShowKeyguardWakeLock.acquire();
Adam Cohenf7522022012-10-03 20:03:18 -07001463 Message msg = mHandler.obtainMessage(SHOW, options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001464 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001465 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001466 }
1467
1468 /**
1469 * Send message to keyguard telling it to hide itself
Jim Miller9c20d0e2010-01-20 15:00:23 -08001470 * @see #handleHide()
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001471 */
1472 private void hideLocked() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001473 Trace.beginSection("KeyguardViewMediator#hideLocked");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001474 if (DEBUG) Log.d(TAG, "hideLocked");
1475 Message msg = mHandler.obtainMessage(HIDE);
1476 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001477 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001478 }
1479
Dianne Hackbornb446e972009-09-20 15:23:25 -07001480 public boolean isSecure() {
Evan Rosky13a58a92016-07-27 15:51:09 -07001481 return isSecure(KeyguardUpdateMonitor.getCurrentUser());
1482 }
1483
1484 public boolean isSecure(int userId) {
1485 return mLockPatternUtils.isSecure(userId)
1486 || KeyguardUpdateMonitor.getInstance(mContext).isSimPinSecure();
Dianne Hackbornb446e972009-09-20 15:23:25 -07001487 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001488
Evan Rosky18396452016-07-27 15:19:37 -07001489 public void setSwitchingUser(boolean switching) {
Selim Cinekbbe19242017-12-08 15:42:08 -08001490 KeyguardUpdateMonitor.getInstance(mContext).setSwitchingUser(switching);
Evan Rosky18396452016-07-27 15:19:37 -07001491 }
1492
Craig Mautnerf1b67412012-09-19 13:18:29 -07001493 /**
1494 * Update the newUserId. Call while holding WindowManagerService lock.
Jim Milleree82f8f2012-10-01 16:26:18 -07001495 * NOTE: Should only be called by KeyguardViewMediator in response to the user id changing.
1496 *
Craig Mautnerf1b67412012-09-19 13:18:29 -07001497 * @param newUserId The id of the incoming user.
1498 */
1499 public void setCurrentUser(int newUserId) {
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001500 KeyguardUpdateMonitor.setCurrentUser(newUserId);
Adrian Roosd88eb262016-08-04 14:50:48 -07001501 synchronized (this) {
1502 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(newUserId));
1503 }
Craig Mautnerf1b67412012-09-19 13:18:29 -07001504 }
1505
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001506 /**
1507 * This broadcast receiver should be registered with the SystemUI permission.
1508 */
1509 private final BroadcastReceiver mDelayedLockBroadcastReceiver = new BroadcastReceiver() {
Amith Yamasani52c489c2012-03-28 11:42:42 -07001510 @Override
1511 public void onReceive(Context context, Intent intent) {
Jim Millerbbf1a742012-07-17 18:30:30 -07001512 if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
1513 final int sequence = intent.getIntExtra("seq", 0);
Jim Millerf3447352011-08-07 14:00:09 -07001514 if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = "
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001515 + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001516 synchronized (KeyguardViewMediator.this) {
Jim Miller2967f482016-01-07 15:05:32 -08001517 if (mDelayedShowingSequence == sequence) {
1518 doKeyguardLocked(null);
1519 }
Clara Bayarri56878a92015-10-29 15:43:55 +00001520 }
1521 } else if (DELAYED_LOCK_PROFILE_ACTION.equals(intent.getAction())) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001522 final int sequence = intent.getIntExtra("seq", 0);
Clara Bayarri56878a92015-10-29 15:43:55 +00001523 int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, 0);
1524 if (userId != 0) {
1525 synchronized (KeyguardViewMediator.this) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001526 if (mDelayedProfileShowingSequence == sequence) {
1527 lockProfile(userId);
1528 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001529 }
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001530 }
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001531 }
1532 }
1533 };
1534
1535 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1536 @Override
1537 public void onReceive(Context context, Intent intent) {
1538 if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
Adrian Roos1f8025a2016-12-27 10:12:13 -08001539 synchronized (KeyguardViewMediator.this){
1540 mShuttingDown = true;
1541 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001542 }
1543 }
1544 };
1545
Jorim Jaggi241ae102016-11-02 21:57:33 -07001546 public void keyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001547 Trace.beginSection("KeyguardViewMediator#keyguardDone");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001548 if (DEBUG) Log.d(TAG, "keyguardDone()");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001549 userActivity();
Jim Miller60013792013-10-03 18:31:34 -07001550 EventLog.writeEvent(70000, 2);
Jorim Jaggi241ae102016-11-02 21:57:33 -07001551 Message msg = mHandler.obtainMessage(KEYGUARD_DONE);
Jim Miller60013792013-10-03 18:31:34 -07001552 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001553 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001554 }
1555
1556 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001557 * This handler will be associated with the policy thread, which will also
1558 * be the UI thread of the keyguard. Since the apis of the policy, and therefore
1559 * this class, can be called by other threads, any action that directly
1560 * interacts with the keyguard ui should be posted to this handler, rather
1561 * than called directly.
1562 */
Jim Millerdcb3d842012-08-23 19:18:12 -07001563 private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001564 @Override
Wink Saville37c124c2009-04-02 01:37:02 -07001565 public void handleMessage(Message msg) {
1566 switch (msg.what) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001567 case SHOW:
Adam Cohenf7522022012-10-03 20:03:18 -07001568 handleShow((Bundle) msg.obj);
Jim Miller60013792013-10-03 18:31:34 -07001569 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001570 case HIDE:
1571 handleHide();
Jim Miller60013792013-10-03 18:31:34 -07001572 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001573 case RESET:
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001574 handleReset();
Jim Miller60013792013-10-03 18:31:34 -07001575 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001576 case VERIFY_UNLOCK:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001577 Trace.beginSection("KeyguardViewMediator#handleMessage VERIFY_UNLOCK");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001578 handleVerifyUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001579 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001580 break;
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001581 case NOTIFY_STARTED_GOING_TO_SLEEP:
1582 handleNotifyStartedGoingToSleep();
1583 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001584 case NOTIFY_FINISHED_GOING_TO_SLEEP:
1585 handleNotifyFinishedGoingToSleep();
Jim Miller60013792013-10-03 18:31:34 -07001586 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001587 case NOTIFY_SCREEN_TURNING_ON:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001588 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNING_ON");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001589 handleNotifyScreenTurningOn((IKeyguardDrawnCallback) msg.obj);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001590 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001591 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001592 case NOTIFY_SCREEN_TURNED_ON:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001593 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNED_ON");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001594 handleNotifyScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001595 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001596 break;
1597 case NOTIFY_SCREEN_TURNED_OFF:
1598 handleNotifyScreenTurnedOff();
1599 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001600 case NOTIFY_STARTED_WAKING_UP:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001601 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_STARTED_WAKING_UP");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001602 handleNotifyStartedWakingUp();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001603 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001604 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001605 case KEYGUARD_DONE:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001606 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001607 handleKeyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001608 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001609 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001610 case KEYGUARD_DONE_DRAWING:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001611 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_DRAWING");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001612 handleKeyguardDoneDrawing();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001613 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001614 break;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001615 case SET_OCCLUDED:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001616 Trace.beginSection("KeyguardViewMediator#handleMessage SET_OCCLUDED");
Jorim Jaggi6626f542016-08-22 13:08:44 -07001617 handleSetOccluded(msg.arg1 != 0, msg.arg2 != 0);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001618 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001619 break;
Mike Lockwood28569302010-01-28 11:54:40 -05001620 case KEYGUARD_TIMEOUT:
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001621 synchronized (KeyguardViewMediator.this) {
Adam Cohenf7522022012-10-03 20:03:18 -07001622 doKeyguardLocked((Bundle) msg.obj);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001623 }
1624 break;
Jim Miller60013792013-10-03 18:31:34 -07001625 case DISMISS:
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001626 final DismissMessage message = (DismissMessage) msg.obj;
1627 handleDismiss(message.getCallback(), message.getMessage());
Jim Miller60013792013-10-03 18:31:34 -07001628 break;
Jorim Jaggi0d674622014-05-21 01:34:15 +02001629 case START_KEYGUARD_EXIT_ANIM:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001630 Trace.beginSection("KeyguardViewMediator#handleMessage START_KEYGUARD_EXIT_ANIM");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001631 StartKeyguardExitAnimParams params = (StartKeyguardExitAnimParams) msg.obj;
1632 handleStartKeyguardExitAnimation(params.startTime, params.fadeoutDuration);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001633 FalsingManager.getInstance(mContext).onSucccessfulUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001634 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001635 break;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001636 case KEYGUARD_DONE_PENDING_TIMEOUT:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001637 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_PENDING_TIMEOUT");
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001638 Log.w(TAG, "Timeout while waiting for activity drawn!");
Nick Desaulniers1d396752016-07-25 15:05:33 -07001639 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001640 break;
Adrian Roos30a2ae62018-04-25 19:09:50 +02001641 case SYSTEM_READY:
1642 handleSystemReady();
1643 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001644 }
1645 }
1646 };
1647
Jorim Jaggi241ae102016-11-02 21:57:33 -07001648 private void tryKeyguardDone() {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001649 if (!mKeyguardDonePending && mHideAnimationRun && !mHideAnimationRunning) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001650 handleKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001651 } else if (!mHideAnimationRun) {
1652 mHideAnimationRun = true;
1653 mHideAnimationRunning = true;
1654 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
1655 }
1656 }
1657
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001658 /**
1659 * @see #keyguardDone
1660 * @see #KEYGUARD_DONE
1661 */
Jorim Jaggi241ae102016-11-02 21:57:33 -07001662 private void handleKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001663 Trace.beginSection("KeyguardViewMediator#handleKeyguardDone");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001664 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001665 mUiOffloadThread.submit(() -> {
1666 if (mLockPatternUtils.isSecure(currentUser)) {
1667 mLockPatternUtils.getDevicePolicyManager().reportKeyguardDismissed(currentUser);
1668 }
1669 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001670 if (DEBUG) Log.d(TAG, "handleKeyguardDone");
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001671 synchronized (this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001672 resetKeyguardDonePendingLocked();
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001673 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001674
Jim Millerf41fc962014-06-18 16:33:51 -07001675 mUpdateMonitor.clearFingerprintRecognized();
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -07001676
Jorim Jaggi4474f542015-07-09 16:08:02 -07001677 if (mGoingToSleep) {
1678 Log.i(TAG, "Device is going to sleep, aborting keyguardDone");
1679 return;
1680 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001681 if (mExitSecureCallback != null) {
1682 try {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001683 mExitSecureCallback.onKeyguardExitResult(true /* authenciated */);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001684 } catch (RemoteException e) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001685 Slog.w(TAG, "Failed to call onKeyguardExitResult()", e);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001686 }
1687
1688 mExitSecureCallback = null;
1689
Jorim Jaggi241ae102016-11-02 21:57:33 -07001690 // after succesfully exiting securely, no need to reshow
1691 // the keyguard when they've released the lock
1692 mExternallyEnabled = true;
1693 mNeedToReshowWhenReenabled = false;
1694 updateInputRestricted();
Jim Millere51cf7ae2013-06-25 18:31:56 -07001695 }
1696
1697 handleHide();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001698 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -07001699 }
1700
1701 private void sendUserPresentBroadcast() {
Jason Monkcf5a9532014-09-17 16:22:19 -04001702 synchronized (this) {
1703 if (mBootCompleted) {
Adrian Roos4ab7e592016-04-13 15:38:13 -07001704 int currentUserId = KeyguardUpdateMonitor.getCurrentUser();
1705 final UserHandle currentUser = new UserHandle(currentUserId);
Benjamin Franz4b9f8ed2014-12-01 16:51:48 +00001706 final UserManager um = (UserManager) mContext.getSystemService(
1707 Context.USER_SERVICE);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001708 mUiOffloadThread.submit(() -> {
1709 for (int profileId : um.getProfileIdsWithDisabled(currentUser.getIdentifier())) {
1710 mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, UserHandle.of(profileId));
1711 }
1712 getLockPatternUtils().userPresent(currentUserId);
1713 });
Jason Monkcf5a9532014-09-17 16:22:19 -04001714 } else {
1715 mBootSendUserPresent = true;
1716 }
1717 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001718 }
1719
1720 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001721 * @see #keyguardDone
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001722 * @see #KEYGUARD_DONE_DRAWING
1723 */
1724 private void handleKeyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001725 Trace.beginSection("KeyguardViewMediator#handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001726 synchronized(this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001727 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001728 if (mWaitingUntilKeyguardVisible) {
1729 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible");
1730 mWaitingUntilKeyguardVisible = false;
1731 notifyAll();
1732
1733 // there will usually be two of these sent, one as a timeout, and one
1734 // as a result of the callback, so remove any remaining messages from
1735 // the queue
1736 mHandler.removeMessages(KEYGUARD_DONE_DRAWING);
1737 }
1738 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001739 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001740 }
1741
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001742 private void playSounds(boolean locked) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001743 playSound(locked ? mLockSoundId : mUnlockSoundId);
1744 }
1745
1746 private void playSound(int soundId) {
1747 if (soundId == 0) return;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001748 final ContentResolver cr = mContext.getContentResolver();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001749 if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001750
Marco Nelissend5545bd2011-09-29 12:49:17 -07001751 mLockSounds.stop(mLockSoundStreamId);
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001752 // Init mAudioManager
1753 if (mAudioManager == null) {
1754 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
1755 if (mAudioManager == null) return;
John Spurlockee5ad722015-03-03 16:17:21 -05001756 mUiSoundsStreamType = mAudioManager.getUiSoundsStreamType();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001757 }
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001758
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001759 mUiOffloadThread.submit(() -> {
1760 // If the stream is muted, don't play the sound
1761 if (mAudioManager.isStreamMute(mUiSoundsStreamType)) return;
1762
1763 int id = mLockSounds.play(soundId,
1764 mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/);
1765 synchronized (this) {
1766 mLockSoundStreamId = id;
1767 }
1768 });
1769
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001770 }
Jim Miller2a98a4c2010-11-19 18:49:26 -08001771 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001772
Adrian Roos49e057d2014-08-13 17:14:51 +02001773 private void playTrustedSound() {
Adrian Roos49e057d2014-08-13 17:14:51 +02001774 playSound(mTrustedSoundId);
1775 }
1776
Lucas Dupin47a65c72018-02-15 14:16:18 -08001777 private void updateActivityLockScreenState(boolean showing, boolean aodShowing,
1778 int secondaryDisplayShowing) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001779 mUiOffloadThread.submit(() -> {
1780 try {
Lucas Dupin47a65c72018-02-15 14:16:18 -08001781 ActivityManager.getService().setLockScreenShown(showing, aodShowing,
1782 secondaryDisplayShowing);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001783 } catch (RemoteException e) {
1784 }
1785 });
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001786 }
1787
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001788 /**
1789 * Handle message sent by {@link #showLocked}.
1790 * @see #SHOW
1791 */
Adam Cohenf7522022012-10-03 20:03:18 -07001792 private void handleShow(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001793 Trace.beginSection("KeyguardViewMediator#handleShow");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001794 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
1795 if (mLockPatternUtils.isSecure(currentUser)) {
1796 mLockPatternUtils.getDevicePolicyManager().reportKeyguardSecured(currentUser);
Michal Karpinski779aad92016-01-20 11:56:22 +00001797 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001798 synchronized (KeyguardViewMediator.this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001799 if (!mSystemReady) {
1800 if (DEBUG) Log.d(TAG, "ignoring handleShow because system is not ready.");
1801 return;
1802 } else {
1803 if (DEBUG) Log.d(TAG, "handleShow");
1804 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001805
Lucas Dupin47a65c72018-02-15 14:16:18 -08001806 setShowingLocked(true, mAodShowing);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001807 mStatusBarKeyguardViewManager.show(options);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001808 mHiding = false;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001809 mWakeAndUnlocking = false;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001810 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001811 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001812 adjustStatusBarLocked();
Jeff Brown3dc524b2012-09-30 19:49:11 -07001813 userActivity();
Mike Lockwood674d3e42009-10-06 09:28:54 -04001814 mShowKeyguardWakeLock.release();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001815 }
Jim Miller31921482013-11-06 20:43:55 -08001816 mKeyguardDisplayManager.show();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001817 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001818 }
1819
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001820 private final Runnable mKeyguardGoingAwayRunnable = new Runnable() {
1821 @Override
1822 public void run() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001823 Trace.beginSection("KeyguardViewMediator.mKeyGuardGoingAwayRunnable");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001824 if (DEBUG) Log.d(TAG, "keyguardGoingAway");
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001825 try {
Jorim Jaggi33ae80e2015-02-04 16:37:11 +01001826 mStatusBarKeyguardViewManager.keyguardGoingAway();
1827
Adrian Roosd5c2db62016-03-08 16:11:31 -08001828 int flags = 0;
1829 if (mStatusBarKeyguardViewManager.shouldDisableWindowAnimationsForUnlock()
Lucas Dupind35502f2018-06-27 13:35:52 -07001830 || (mWakeAndUnlocking && !mPulsing)) {
1831 flags |= WindowManagerPolicyConstants
1832 .KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001833 }
Lucas Dupind35502f2018-06-27 13:35:52 -07001834 if (mStatusBarKeyguardViewManager.isGoingToNotificationShade()
1835 || (mWakeAndUnlocking && mPulsing)) {
Adrian Roose99bc052017-11-20 17:55:31 +01001836 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001837 }
1838 if (mStatusBarKeyguardViewManager.isUnlockWithWallpaper()) {
Adrian Roose99bc052017-11-20 17:55:31 +01001839 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001840 }
1841
Kevin Chyn6db7d5f2017-05-03 22:24:31 -07001842 mUpdateMonitor.setKeyguardGoingAway(true /* goingAway */);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001843 // Don't actually hide the Keyguard at the moment, wait for window
1844 // manager until it tells us it's safe to do so with
1845 // startKeyguardExitAnimation.
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001846 ActivityManager.getService().keyguardGoingAway(flags);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001847 } catch (RemoteException e) {
1848 Log.e(TAG, "Error while calling WindowManager", e);
1849 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001850 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001851 }
1852 };
1853
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001854 private final Runnable mHideAnimationFinishedRunnable = () -> {
1855 mHideAnimationRunning = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -07001856 tryKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001857 };
1858
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001859 /**
1860 * Handle message sent by {@link #hideLocked()}
1861 * @see #HIDE
1862 */
1863 private void handleHide() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001864 Trace.beginSection("KeyguardViewMediator#handleHide");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001865 synchronized (KeyguardViewMediator.this) {
1866 if (DEBUG) Log.d(TAG, "handleHide");
Jorim Jaggib9d60792014-06-03 22:34:22 +02001867
Amith Yamasanieb437d42016-04-29 09:31:25 -07001868 if (mustNotUnlockCurrentUser()) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001869 // In split system user mode, we never unlock system user. The end user has to
1870 // switch to another user.
1871 // TODO: We should stop it early by disabling the swipe up flow. Right now swipe up
1872 // still completes and makes the screen blank.
1873 if (DEBUG) Log.d(TAG, "Split system user, quit unlocking.");
1874 return;
1875 }
Jorim Jaggi76a16232014-08-08 17:00:47 +02001876 mHiding = true;
Jorim Jaggib9d60792014-06-03 22:34:22 +02001877
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001878 if (mShowing && !mOccluded) {
1879 mKeyguardGoingAwayRunnable.run();
1880 } else {
Jorim Jaggi76a16232014-08-08 17:00:47 +02001881 handleStartKeyguardExitAnimation(
1882 SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(),
1883 mHideAnimation.getDuration());
Jorim Jaggi0d674622014-05-21 01:34:15 +02001884 }
1885 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001886 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001887 }
1888
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001889 private void handleStartKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001890 Trace.beginSection("KeyguardViewMediator#handleStartKeyguardExitAnimation");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001891 if (DEBUG) Log.d(TAG, "handleStartKeyguardExitAnimation startTime=" + startTime
1892 + " fadeoutDuration=" + fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02001893 synchronized (KeyguardViewMediator.this) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001894
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001895 if (!mHiding) {
Adrian Roos6ec76b72018-04-25 14:01:11 +02001896 // Tell ActivityManager that we canceled the keyguardExitAnimation.
1897 setShowingLocked(mShowing, mAodShowing, mSecondaryDisplayShowing, true /* force */);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001898 return;
1899 }
1900 mHiding = false;
1901
Jorim Jaggib774e552015-08-24 14:52:45 -07001902 if (mWakeAndUnlocking && mDrawnCallback != null) {
1903
1904 // Hack level over 9000: To speed up wake-and-unlock sequence, force it to report
1905 // the next draw from here so we don't have to wait for window manager to signal
1906 // this to our ViewRootImpl.
1907 mStatusBarKeyguardViewManager.getViewRootImpl().setReportNextDraw();
1908 notifyDrawn(mDrawnCallback);
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001909 mDrawnCallback = null;
Jorim Jaggib774e552015-08-24 14:52:45 -07001910 }
1911
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001912 // only play "unlock" noises if not on a call (since the incall UI
1913 // disables the keyguard)
1914 if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) {
1915 playSounds(false);
1916 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001917
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001918 mWakeAndUnlocking = false;
Lucas Dupin47a65c72018-02-15 14:16:18 -08001919 setShowingLocked(false, mAodShowing);
Jorim Jaggi5277dea2017-05-18 02:05:29 +02001920 mDismissCallbackRegistry.notifyDismissSucceeded();
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001921 mStatusBarKeyguardViewManager.hide(startTime, fadeoutDuration);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001922 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001923 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001924 adjustStatusBarLocked();
Jim Miller705004b2014-09-04 16:51:20 -07001925 sendUserPresentBroadcast();
Kevin Chyn6db7d5f2017-05-03 22:24:31 -07001926 mUpdateMonitor.setKeyguardGoingAway(false /* goingAway */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001927 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001928 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001929 }
1930
Mike Lockwood5f892c12009-11-19 23:39:13 -05001931 private void adjustStatusBarLocked() {
Matthew Ng66f0b702017-12-08 12:58:42 -08001932 adjustStatusBarLocked(false /* forceHideHomeRecentsButtons */);
1933 }
1934
1935 private void adjustStatusBarLocked(boolean forceHideHomeRecentsButtons) {
Mike Lockwood5f892c12009-11-19 23:39:13 -05001936 if (mStatusBarManager == null) {
1937 mStatusBarManager = (StatusBarManager)
1938 mContext.getSystemService(Context.STATUS_BAR_SERVICE);
1939 }
1940 if (mStatusBarManager == null) {
1941 Log.w(TAG, "Could not get status bar manager");
1942 } else {
Daniel Sandlerdba93562011-10-06 16:39:58 -04001943 // Disable aspects of the system/status/navigation bars that must not be re-enabled by
1944 // windows that appear on top, ever
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001945 int flags = StatusBarManager.DISABLE_NONE;
Matthew Ng66f0b702017-12-08 12:58:42 -08001946 if (forceHideHomeRecentsButtons || isShowingAndNotOccluded()) {
1947 flags |= StatusBarManager.DISABLE_HOME | StatusBarManager.DISABLE_RECENT;
Jorim Jaggia005f1b2014-04-16 19:06:10 +02001948 }
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001949
1950 if (DEBUG) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001951 Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mOccluded=" + mOccluded
Matthew Ng66f0b702017-12-08 12:58:42 -08001952 + " isSecure=" + isSecure() + " force=" + forceHideHomeRecentsButtons
1953 + " --> flags=0x" + Integer.toHexString(flags));
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001954 }
1955
Jorim Jaggie3e0b062017-06-12 12:18:41 -07001956 mStatusBarManager.disable(flags);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001957 }
1958 }
1959
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001960 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001961 * Handle message sent by {@link #resetStateLocked}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001962 * @see #RESET
1963 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001964 private void handleReset() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001965 synchronized (KeyguardViewMediator.this) {
1966 if (DEBUG) Log.d(TAG, "handleReset");
Jorim Jaggife762342016-10-13 14:33:27 +02001967 mStatusBarKeyguardViewManager.reset(true /* hideBouncerWhenShowing */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001968 }
1969 }
1970
1971 /**
1972 * Handle message sent by {@link #verifyUnlock}
Craig Mautner904732c2012-10-17 15:20:24 -07001973 * @see #VERIFY_UNLOCK
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001974 */
1975 private void handleVerifyUnlock() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001976 Trace.beginSection("KeyguardViewMediator#handleVerifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001977 synchronized (KeyguardViewMediator.this) {
1978 if (DEBUG) Log.d(TAG, "handleVerifyUnlock");
Lucas Dupin47a65c72018-02-15 14:16:18 -08001979 setShowingLocked(true, mAodShowing);
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001980 mStatusBarKeyguardViewManager.dismissAndCollapse();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001981 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001982 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001983 }
1984
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001985 private void handleNotifyStartedGoingToSleep() {
1986 synchronized (KeyguardViewMediator.this) {
1987 if (DEBUG) Log.d(TAG, "handleNotifyStartedGoingToSleep");
1988 mStatusBarKeyguardViewManager.onStartedGoingToSleep();
1989 }
1990 }
1991
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001992 /**
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001993 * Handle message sent by {@link #notifyFinishedGoingToSleep()}
1994 * @see #NOTIFY_FINISHED_GOING_TO_SLEEP
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001995 */
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001996 private void handleNotifyFinishedGoingToSleep() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001997 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001998 if (DEBUG) Log.d(TAG, "handleNotifyFinishedGoingToSleep");
1999 mStatusBarKeyguardViewManager.onFinishedGoingToSleep();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002000 }
2001 }
2002
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002003 private void handleNotifyStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002004 Trace.beginSection("KeyguardViewMediator#handleMotifyStartedWakingUp");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002005 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002006 if (DEBUG) Log.d(TAG, "handleNotifyWakingUp");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002007 mStatusBarKeyguardViewManager.onStartedWakingUp();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002008 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002009 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002010 }
2011
2012 private void handleNotifyScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002013 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurningOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002014 synchronized (KeyguardViewMediator.this) {
2015 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurningOn");
Jorim Jaggi93739112015-08-13 15:53:14 -07002016 mStatusBarKeyguardViewManager.onScreenTurningOn();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002017 if (callback != null) {
2018 if (mWakeAndUnlocking) {
2019 mDrawnCallback = callback;
2020 } else {
2021 notifyDrawn(callback);
2022 }
2023 }
2024 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002025 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002026 }
2027
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002028 private void handleNotifyScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002029 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurnedOn");
Jorim Jaggic3fe2042016-10-07 18:52:48 +02002030 if (LatencyTracker.isEnabled(mContext)) {
2031 LatencyTracker.getInstance(mContext).onActionEnd(LatencyTracker.ACTION_TURN_ON_SCREEN);
2032 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002033 synchronized (this) {
2034 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOn");
2035 mStatusBarKeyguardViewManager.onScreenTurnedOn();
2036 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002037 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002038 }
2039
2040 private void handleNotifyScreenTurnedOff() {
2041 synchronized (this) {
2042 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOff");
2043 mStatusBarKeyguardViewManager.onScreenTurnedOff();
Jorim Jaggie93e6f92016-08-04 13:55:39 +02002044 mDrawnCallback = null;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002045 }
2046 }
2047
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002048 private void notifyDrawn(final IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002049 Trace.beginSection("KeyguardViewMediator#notifyDrawn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002050 try {
2051 callback.onDrawn();
2052 } catch (RemoteException e) {
2053 Slog.w(TAG, "Exception calling onDrawn():", e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002054 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002055 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002056 }
Jeff Sharkey054340d2011-09-01 22:28:03 -07002057
Jorim Jaggif8d77da2014-11-11 16:59:12 +01002058 private void resetKeyguardDonePendingLocked() {
2059 mKeyguardDonePending = false;
2060 mHandler.removeMessages(KEYGUARD_DONE_PENDING_TIMEOUT);
2061 }
2062
Jim Miller2967f482016-01-07 15:05:32 -08002063 @Override
Jim Millere5f910a2013-10-16 18:15:46 -07002064 public void onBootCompleted() {
2065 mUpdateMonitor.dispatchBootCompleted();
Jason Monkcf5a9532014-09-17 16:22:19 -04002066 synchronized (this) {
2067 mBootCompleted = true;
2068 if (mBootSendUserPresent) {
2069 sendUserPresentBroadcast();
2070 }
2071 }
Jim Millere5f910a2013-10-16 18:15:46 -07002072 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002073
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002074 public void onWakeAndUnlocking() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002075 Trace.beginSection("KeyguardViewMediator#onWakeAndUnlocking");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002076 mWakeAndUnlocking = true;
Jorim Jaggi241ae102016-11-02 21:57:33 -07002077 keyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07002078 Trace.endSection();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002079 }
2080
Jason Monk2a6ea9c2017-01-26 11:14:51 -05002081 public StatusBarKeyguardViewManager registerStatusBar(StatusBar statusBar,
Lucas Dupinbc9aac12018-03-04 20:18:15 -08002082 ViewGroup container, NotificationPanelView panelView,
2083 FingerprintUnlockController fingerprintUnlockController) {
2084 mStatusBarKeyguardViewManager.registerStatusBar(statusBar, container, panelView,
Lucas Dupin9e3fa102017-11-08 17:16:55 -08002085 fingerprintUnlockController, mDismissCallbackRegistry);
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002086 return mStatusBarKeyguardViewManager;
2087 }
2088
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002089 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002090 Trace.beginSection("KeyguardViewMediator#startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002091 Message msg = mHandler.obtainMessage(START_KEYGUARD_EXIT_ANIM,
2092 new StartKeyguardExitAnimParams(startTime, fadeoutDuration));
Jorim Jaggi0d674622014-05-21 01:34:15 +02002093 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07002094 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02002095 }
2096
Andrew Zengb4045d32017-03-16 17:25:07 -07002097 public void onShortPowerPressedGoHome() {
2098 // do nothing
2099 }
2100
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002101 public ViewMediatorCallback getViewMediatorCallback() {
2102 return mViewMediatorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002103 }
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002104
Xiyuan Xia1b30f792016-01-06 08:50:30 -08002105 public LockPatternUtils getLockPatternUtils() {
2106 return mLockPatternUtils;
2107 }
2108
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002109 @Override
2110 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
2111 pw.print(" mSystemReady: "); pw.println(mSystemReady);
2112 pw.print(" mBootCompleted: "); pw.println(mBootCompleted);
2113 pw.print(" mBootSendUserPresent: "); pw.println(mBootSendUserPresent);
2114 pw.print(" mExternallyEnabled: "); pw.println(mExternallyEnabled);
Adrian Roos1f8025a2016-12-27 10:12:13 -08002115 pw.print(" mShuttingDown: "); pw.println(mShuttingDown);
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002116 pw.print(" mNeedToReshowWhenReenabled: "); pw.println(mNeedToReshowWhenReenabled);
2117 pw.print(" mShowing: "); pw.println(mShowing);
2118 pw.print(" mInputRestricted: "); pw.println(mInputRestricted);
2119 pw.print(" mOccluded: "); pw.println(mOccluded);
2120 pw.print(" mDelayedShowingSequence: "); pw.println(mDelayedShowingSequence);
2121 pw.print(" mExitSecureCallback: "); pw.println(mExitSecureCallback);
2122 pw.print(" mDeviceInteractive: "); pw.println(mDeviceInteractive);
2123 pw.print(" mGoingToSleep: "); pw.println(mGoingToSleep);
2124 pw.print(" mHiding: "); pw.println(mHiding);
2125 pw.print(" mWaitingUntilKeyguardVisible: "); pw.println(mWaitingUntilKeyguardVisible);
2126 pw.print(" mKeyguardDonePending: "); pw.println(mKeyguardDonePending);
2127 pw.print(" mHideAnimationRun: "); pw.println(mHideAnimationRun);
2128 pw.print(" mPendingReset: "); pw.println(mPendingReset);
2129 pw.print(" mPendingLock: "); pw.println(mPendingLock);
2130 pw.print(" mWakeAndUnlocking: "); pw.println(mWakeAndUnlocking);
2131 pw.print(" mDrawnCallback: "); pw.println(mDrawnCallback);
2132 }
2133
Lucas Dupinc29b1462018-07-02 13:15:23 -07002134 /**
2135 * @param aodShowing true when AOD - or ambient mode - is showing.
2136 */
Lucas Dupin47a65c72018-02-15 14:16:18 -08002137 public void setAodShowing(boolean aodShowing) {
2138 setShowingLocked(mShowing, aodShowing);
2139 }
2140
Lucas Dupind35502f2018-06-27 13:35:52 -07002141 /**
2142 * @param pulsing true when device temporarily wakes up to display an incoming notification.
2143 */
2144 public void setPulsing(boolean pulsing) {
2145 mPulsing = pulsing;
2146 }
2147
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002148 private static class StartKeyguardExitAnimParams {
2149
2150 long startTime;
2151 long fadeoutDuration;
2152
2153 private StartKeyguardExitAnimParams(long startTime, long fadeoutDuration) {
2154 this.startTime = startTime;
2155 this.fadeoutDuration = fadeoutDuration;
2156 }
2157 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002158
Lucas Dupin47a65c72018-02-15 14:16:18 -08002159 private void setShowingLocked(boolean showing, boolean aodShowing) {
2160 setShowingLocked(showing, aodShowing, mSecondaryDisplayShowing,
2161 false /* forceCallbacks */);
Jorim Jaggie8f321e2016-11-07 16:48:31 -08002162 }
2163
Lucas Dupin47a65c72018-02-15 14:16:18 -08002164 private void setShowingLocked(boolean showing, boolean aodShowing, int secondaryDisplayShowing,
2165 boolean forceCallbacks) {
2166 final boolean notifyDefaultDisplayCallbacks = showing != mShowing
2167 || aodShowing != mAodShowing || forceCallbacks;
David Stevens53a39ea2017-08-23 18:41:49 -07002168 if (notifyDefaultDisplayCallbacks || secondaryDisplayShowing != mSecondaryDisplayShowing) {
Jim Millerab954542014-10-10 18:21:49 -07002169 mShowing = showing;
Lucas Dupin47a65c72018-02-15 14:16:18 -08002170 mAodShowing = aodShowing;
David Stevens53a39ea2017-08-23 18:41:49 -07002171 mSecondaryDisplayShowing = secondaryDisplayShowing;
2172 if (notifyDefaultDisplayCallbacks) {
2173 notifyDefaultDisplayCallbacks(showing);
2174 }
Lucas Dupin47a65c72018-02-15 14:16:18 -08002175 updateActivityLockScreenState(showing, aodShowing, secondaryDisplayShowing);
David Stevens53a39ea2017-08-23 18:41:49 -07002176 }
2177 }
2178
2179 private void notifyDefaultDisplayCallbacks(boolean showing) {
2180 int size = mKeyguardStateCallbacks.size();
2181 for (int i = size - 1; i >= 0; i--) {
2182 IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
2183 try {
2184 callback.onShowingStateChanged(showing);
2185 } catch (RemoteException e) {
2186 Slog.w(TAG, "Failed to call onShowingStateChanged", e);
2187 if (e instanceof DeadObjectException) {
2188 mKeyguardStateCallbacks.remove(callback);
Jim Millerab954542014-10-10 18:21:49 -07002189 }
Jim Millerab954542014-10-10 18:21:49 -07002190 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002191 }
David Stevens53a39ea2017-08-23 18:41:49 -07002192 updateInputRestrictedLocked();
2193 mUiOffloadThread.submit(() -> {
2194 mTrustManager.reportKeyguardShowingChanged();
2195 });
Adrian Roos481a6df2014-11-20 19:48:56 +01002196 }
Jim Millerab954542014-10-10 18:21:49 -07002197
Adrian Roosd88eb262016-08-04 14:50:48 -07002198 private void notifyTrustedChangedLocked(boolean trusted) {
2199 int size = mKeyguardStateCallbacks.size();
2200 for (int i = size - 1; i >= 0; i--) {
2201 try {
2202 mKeyguardStateCallbacks.get(i).onTrustedChanged(trusted);
2203 } catch (RemoteException e) {
2204 Slog.w(TAG, "Failed to call notifyTrustedChangedLocked", e);
2205 if (e instanceof DeadObjectException) {
2206 mKeyguardStateCallbacks.remove(i);
2207 }
2208 }
2209 }
2210 }
2211
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002212 private void notifyHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
2213 int size = mKeyguardStateCallbacks.size();
2214 for (int i = size - 1; i >= 0; i--) {
2215 try {
2216 mKeyguardStateCallbacks.get(i).onHasLockscreenWallpaperChanged(
2217 hasLockscreenWallpaper);
2218 } catch (RemoteException e) {
2219 Slog.w(TAG, "Failed to call onHasLockscreenWallpaperChanged", e);
2220 if (e instanceof DeadObjectException) {
2221 mKeyguardStateCallbacks.remove(i);
2222 }
2223 }
2224 }
2225 }
2226
Jim Millerab954542014-10-10 18:21:49 -07002227 public void addStateMonitorCallback(IKeyguardStateCallback callback) {
2228 synchronized (this) {
2229 mKeyguardStateCallbacks.add(callback);
2230 try {
2231 callback.onSimSecureStateChanged(mUpdateMonitor.isSimPinSecure());
2232 callback.onShowingStateChanged(mShowing);
Adrian Roos4a963ac2015-04-24 16:04:53 -07002233 callback.onInputRestrictedStateChanged(mInputRestricted);
Adrian Roosd88eb262016-08-04 14:50:48 -07002234 callback.onTrustedChanged(mUpdateMonitor.getUserHasTrust(
2235 KeyguardUpdateMonitor.getCurrentUser()));
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002236 callback.onHasLockscreenWallpaperChanged(mUpdateMonitor.hasLockscreenWallpaper());
Jim Millerab954542014-10-10 18:21:49 -07002237 } catch (RemoteException e) {
Adrian Roosd88eb262016-08-04 14:50:48 -07002238 Slog.w(TAG, "Failed to call to IKeyguardStateCallback", e);
Jim Millerab954542014-10-10 18:21:49 -07002239 }
2240 }
2241 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08002242
2243 private static class DismissMessage {
2244 private final CharSequence mMessage;
2245 private final IKeyguardDismissCallback mCallback;
2246
2247 DismissMessage(IKeyguardDismissCallback callback, CharSequence message) {
2248 mCallback = callback;
2249 mMessage = message;
2250 }
2251
2252 public IKeyguardDismissCallback getCallback() {
2253 return mCallback;
2254 }
2255
2256 public CharSequence getMessage() {
2257 return mMessage;
2258 }
2259 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002260}