blob: 411bf9a80dca982b6696b8396343c1b831a80c05 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002 * Copyright (C) 2014 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
Jorim Jaggi5cf17872014-03-26 18:31:48 +010014 * limitations under the License
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080015 */
16
Jorim Jaggi5cf17872014-03-26 18:31:48 +010017package com.android.systemui.keyguard;
Jim Millerbc4603b2010-08-30 21:21:34 -070018
Jorim Jaggid11d1a92016-08-16 16:02:32 -070019import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
Adrian Roose92de952016-12-13 12:07:09 -080020
21import static com.android.internal.telephony.IccCardConstants.State.ABSENT;
Lucas Dupin6d48eab2018-09-17 17:17:14 -070022import static com.android.internal.telephony.IccCardConstants.State.PIN_REQUIRED;
23import static com.android.internal.telephony.IccCardConstants.State.PUK_REQUIRED;
Jorim Jaggid11d1a92016-08-16 16:02:32 -070024import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST;
25import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW;
26import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT;
Michal Karpinskic52f8672016-11-18 11:32:45 +000027import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT;
Lucas Dupin8968f6a2019-08-09 17:41:15 -070028import static com.android.systemui.DejankUtils.whitelistIpcs;
Jorim Jaggid11d1a92016-08-16 16:02:32 -070029
Adrian Roosb60d47c2014-09-08 19:23:00 +020030import android.app.ActivityManager;
Wale Ogunwale04d9cb52018-04-30 13:55:07 -070031import android.app.ActivityTaskManager;
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;
Lucas Dupin6d48eab2018-09-17 17:17:14 -070042import android.hardware.biometrics.BiometricSourceType;
Jean-Michel Trivi0616db42019-01-28 10:57:21 -080043import android.media.AudioAttributes;
Daniel Sandleraec967a2010-02-20 01:05:22 -050044import android.media.AudioManager;
Marco Nelissend5545bd2011-09-29 12:49:17 -070045import android.media.SoundPool;
Adam Cohenf7522022012-10-03 20:03:18 -070046import android.os.Bundle;
dooyoung.hwang328472e2015-05-21 16:09:43 +090047import android.os.DeadObjectException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080048import android.os.Handler;
Jeff Brown109025d2012-08-14 20:41:30 -070049import android.os.Looper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080050import android.os.Message;
51import android.os.PowerManager;
Dianne Hackborn4994c662009-09-23 22:21:23 -070052import android.os.RemoteException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080053import android.os.SystemClock;
Jim Miller1b152022009-10-28 16:08:15 -070054import android.os.SystemProperties;
Nick Desaulniers1d396752016-07-25 15:05:33 -070055import android.os.Trace;
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -070056import android.os.UserHandle;
Amith Yamasanib70ff9a2012-09-07 18:28:11 -070057import android.os.UserManager;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -050058import android.provider.Settings;
Jim Miller52a61332014-11-12 19:29:51 -080059import android.telephony.SubscriptionManager;
Karl Rosaenab100082009-03-24 22:35:17 -070060import android.telephony.TelephonyManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080061import android.util.EventLog;
Karl Rosaenab100082009-03-24 22:35:17 -070062import android.util.Log;
Jim Miller25190572013-02-28 17:36:24 -080063import android.util.Slog;
Lucas Dupin6d48eab2018-09-17 17:17:14 -070064import android.util.SparseArray;
Selim Cinek06c12d62019-07-01 19:44:18 -070065import android.view.View;
Jorim Jaggib690f0d2014-07-03 23:25:44 +020066import android.view.ViewGroup;
Adrian Roose99bc052017-11-20 17:55:31 +010067import android.view.WindowManagerPolicyConstants;
Adrian Roos0002a452014-07-03 13:46:07 +020068import android.view.animation.Animation;
69import android.view.animation.AnimationUtils;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -070070
Curtis Belmonte5cece532019-10-15 09:44:28 -070071import com.android.internal.annotations.VisibleForTesting;
Jorim Jaggi241ae102016-11-02 21:57:33 -070072import com.android.internal.policy.IKeyguardDismissCallback;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -070073import com.android.internal.policy.IKeyguardDrawnCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010074import com.android.internal.policy.IKeyguardExitCallback;
Jim Millerab954542014-10-10 18:21:49 -070075import com.android.internal.policy.IKeyguardStateCallback;
Adam Cohenf7522022012-10-03 20:03:18 -070076import com.android.internal.telephony.IccCardConstants;
Lucas Dupin6d48eab2018-09-17 17:17:14 -070077import com.android.internal.util.LatencyTracker;
Adam Cohenf7522022012-10-03 20:03:18 -070078import com.android.internal.widget.LockPatternUtils;
Jim Miller52a61332014-11-12 19:29:51 -080079import com.android.keyguard.KeyguardConstants;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010080import com.android.keyguard.KeyguardDisplayManager;
Selim Cinek3122fa82015-06-18 01:38:59 -070081import com.android.keyguard.KeyguardSecurityView;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010082import com.android.keyguard.KeyguardUpdateMonitor;
83import com.android.keyguard.KeyguardUpdateMonitorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010084import com.android.keyguard.ViewMediatorCallback;
Jorim Jaggie549a8d2017-05-15 02:40:05 +020085import com.android.systemui.Dependency;
Hyunyoung Song8f9d34c2019-08-30 14:47:43 -070086import com.android.systemui.R;
Jorim Jaggicff0acb2014-03-31 16:35:15 +020087import com.android.systemui.SystemUI;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080088import com.android.systemui.SystemUIFactory;
Jorim Jaggie549a8d2017-05-15 02:40:05 +020089import com.android.systemui.UiOffloadThread;
Dave Mankoffc195ea82019-06-28 16:33:25 -040090import com.android.systemui.plugins.FalsingManager;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020091import com.android.systemui.statusbar.phone.BiometricUnlockController;
Selim Cinek06c12d62019-07-01 19:44:18 -070092import com.android.systemui.statusbar.phone.KeyguardBypassController;
Lucas Dupin6d48eab2018-09-17 17:17:14 -070093import com.android.systemui.statusbar.phone.NotificationPanelView;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050094import com.android.systemui.statusbar.phone.StatusBar;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010095import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
Lucas Dupine25c4872019-07-29 13:51:35 -070096import com.android.systemui.statusbar.phone.StatusBarWindowController;
Robert Snoebergerbe35b762019-03-15 14:33:02 -040097import com.android.systemui.util.InjectionInflationController;
Adrian Roos58b58fe2014-01-31 16:00:39 -080098
Jorim Jaggi84dc08a2015-09-11 17:45:22 -070099import java.io.FileDescriptor;
100import java.io.PrintWriter;
Jim Millerab954542014-10-10 18:21:49 -0700101import java.util.ArrayList;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100102
Dave Mankoffaa8b7ae2019-09-04 18:03:21 -0400103import javax.inject.Inject;
Dave Mankoffbeef8f12019-10-03 19:06:55 +0000104import javax.inject.Singleton;
Dave Mankoffaa8b7ae2019-09-04 18:03:21 -0400105
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800106/**
107 * Mediates requests related to the keyguard. This includes queries about the
108 * state of the keyguard, power management events that effect whether the keyguard
109 * should be shown or reset, callbacks to the phone window manager to notify
110 * it of when the keyguard is showing, and events from the keyguard view itself
111 * stating that the keyguard was succesfully unlocked.
112 *
113 * Note that the keyguard view is shown when the screen is off (as appropriate)
114 * so that once the screen comes on, it will be ready immediately.
115 *
116 * Example queries about the keyguard:
117 * - is {movement, key} one that should wake the keygaurd?
118 * - is the keyguard showing?
119 * - are input events restricted due to the state of the keyguard?
120 *
121 * Callbacks to the phone window manager:
122 * - the keyguard is showing
123 *
124 * Example external events that translate to keyguard view changes:
125 * - screen turned off -> reset the keyguard, and show it so it will be ready
126 * next time the screen turns on
127 * - keyboard is slid open -> if the keyguard is not secure, hide it
128 *
129 * Events from the keyguard view:
130 * - user succesfully unlocked keyguard -> hide keyguard view, and no longer
131 * restrict input events.
132 *
133 * Note: in addition to normal power managment events that effect the state of
134 * whether the keyguard should be showing, external apps and services may request
135 * that the keyguard be disabled via {@link #setKeyguardEnabled(boolean)}. When
136 * false, this will override all other conditions for turning on the keyguard.
137 *
138 * Threading and synchronization:
Adrian Roose99bc052017-11-20 17:55:31 +0100139 * This class is created by the initialization routine of the {@link WindowManagerPolicyConstants},
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800140 * and runs on its thread. The keyguard UI is created from that thread in the
141 * constructor of this class. The apis may be called from other threads, including the
Jeff Brown4532e612012-04-05 14:27:12 -0700142 * {@link com.android.server.input.InputManagerService}'s and {@link android.view.WindowManager}'s.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800143 * Therefore, methods on this class are synchronized, and any action that is pointed
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100144 * 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 -0800145 * thread of the keyguard.
146 */
Dave Mankoffbeef8f12019-10-03 19:06:55 +0000147@Singleton
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200148public class KeyguardViewMediator extends SystemUI {
Jim Millerbc4603b2010-08-30 21:21:34 -0700149 private static final int KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT = 30000;
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100150 private static final long KEYGUARD_DONE_PENDING_TIMEOUT_MS = 3000;
151
Jim Miller52a61332014-11-12 19:29:51 -0800152 private static final boolean DEBUG = KeyguardConstants.DEBUG;
153 private static final boolean DEBUG_SIM_STATES = KeyguardConstants.DEBUG_SIM_STATES;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800154
155 private final static String TAG = "KeyguardViewMediator";
156
Jim Miller9c20d0e2010-01-20 15:00:23 -0800157 private static final String DELAYED_KEYGUARD_ACTION =
Wink Saville37c124c2009-04-02 01:37:02 -0700158 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD";
Clara Bayarri56878a92015-10-29 15:43:55 +0000159 private static final String DELAYED_LOCK_PROFILE_ACTION =
160 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_LOCK";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800161
Kevin Chyn18e91aa2018-04-11 12:55:45 -0700162 private static final String SYSTEMUI_PERMISSION = "com.android.systemui.permission.SELF";
163
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800164 // used for handler messages
Jorim Jaggi8d786932016-10-26 19:08:36 -0700165 private static final int SHOW = 1;
166 private static final int HIDE = 2;
167 private static final int RESET = 3;
168 private static final int VERIFY_UNLOCK = 4;
169 private static final int NOTIFY_FINISHED_GOING_TO_SLEEP = 5;
170 private static final int NOTIFY_SCREEN_TURNING_ON = 6;
171 private static final int KEYGUARD_DONE = 7;
172 private static final int KEYGUARD_DONE_DRAWING = 8;
173 private static final int SET_OCCLUDED = 9;
174 private static final int KEYGUARD_TIMEOUT = 10;
175 private static final int DISMISS = 11;
176 private static final int START_KEYGUARD_EXIT_ANIM = 12;
177 private static final int KEYGUARD_DONE_PENDING_TIMEOUT = 13;
178 private static final int NOTIFY_STARTED_WAKING_UP = 14;
179 private static final int NOTIFY_SCREEN_TURNED_ON = 15;
180 private static final int NOTIFY_SCREEN_TURNED_OFF = 16;
181 private static final int NOTIFY_STARTED_GOING_TO_SLEEP = 17;
Adrian Roos30a2ae62018-04-25 19:09:50 +0200182 private static final int SYSTEM_READY = 18;
Jim Miller9c20d0e2010-01-20 15:00:23 -0800183
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800184 /**
185 * The default amount of time we stay awake (used for all key input)
186 */
Lucas Dupine90fead2019-06-12 16:22:41 -0700187 public static final int AWAKE_INTERVAL_BOUNCER_MS = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800188
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800189 /**
190 * How long to wait after the screen turns off due to timeout before
191 * turning on the keyguard (i.e, the user has this much time to turn
192 * the screen back on without having to face the keyguard).
193 */
Jim Millerbc4603b2010-08-30 21:21:34 -0700194 private static final int KEYGUARD_LOCK_AFTER_DELAY_DEFAULT = 5000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800195
196 /**
Craig Mautnerf1b67412012-09-19 13:18:29 -0700197 * How long we'll wait for the {@link ViewMediatorCallback#keyguardDoneDrawing()}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800198 * callback before unblocking a call to {@link #setKeyguardEnabled(boolean)}
199 * that is reenabling the keyguard.
200 */
201 private static final int KEYGUARD_DONE_DRAWING_TIMEOUT_MS = 2000;
Jim Miller9c20d0e2010-01-20 15:00:23 -0800202
Daniel Sandler74d188c2011-08-10 00:00:31 -0400203 /**
Evan Rosky13a58a92016-07-27 15:51:09 -0700204 * Boolean option for doKeyguardLocked/doKeyguardTimeout which, when set to true, forces the
205 * keyguard to show even if it is disabled for the current user.
206 */
207 public static final String OPTION_FORCE_SHOW = "force_show";
208
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700209 /** The stream type that the lock sounds are tied to. */
John Spurlockee5ad722015-03-03 16:17:21 -0500210 private int mUiSoundsStreamType;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700211
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800212 private AlarmManager mAlarmManager;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700213 private AudioManager mAudioManager;
Mike Lockwood5f892c12009-11-19 23:39:13 -0500214 private StatusBarManager mStatusBarManager;
Lucas Dupine25c4872019-07-29 13:51:35 -0700215 private final StatusBarWindowController mStatusBarWindowController =
216 Dependency.get(StatusBarWindowController.class);
Jorim Jaggie549a8d2017-05-15 02:40:05 +0200217 private final UiOffloadThread mUiOffloadThread = Dependency.get(UiOffloadThread.class);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800218
219 private boolean mSystemReady;
Jason Monkcf5a9532014-09-17 16:22:19 -0400220 private boolean mBootCompleted;
221 private boolean mBootSendUserPresent;
Adrian Roos1f8025a2016-12-27 10:12:13 -0800222 private boolean mShuttingDown;
Lucas Dupinb3455e62019-07-11 11:47:13 +0900223 private boolean mDozing;
Dave Mankoffaa8b7ae2019-09-04 18:03:21 -0400224 private final FalsingManager mFalsingManager;
Daniel Sandler0060a9b2010-03-15 23:09:57 -0400225
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800226 /** High level access to the power manager for WakeLocks */
227 private PowerManager mPM;
228
Adrian Roos481a6df2014-11-20 19:48:56 +0100229 /** TrustManager for letting it know when we change visibility */
230 private TrustManager mTrustManager;
Amith Yamasanib70ff9a2012-09-07 18:28:11 -0700231
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800232 /**
Mike Lockwood674d3e42009-10-06 09:28:54 -0400233 * Used to keep the device awake while to ensure the keyguard finishes opening before
234 * we sleep.
235 */
236 private PowerManager.WakeLock mShowKeyguardWakeLock;
237
Dave Mankoffbb9575f2019-10-02 12:23:49 -0400238 private final StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800239
240 // these are protected by synchronized (this)
241
242 /**
Mike Lockwood5d258b62009-12-02 13:50:45 -0500243 * External apps (like the phone app) can tell us to disable the keygaurd.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800244 */
245 private boolean mExternallyEnabled = true;
246
247 /**
248 * Remember if an external call to {@link #setKeyguardEnabled} with value
249 * false caused us to hide the keyguard, so that we need to reshow it once
250 * the keygaurd is reenabled with another call with value true.
251 */
252 private boolean mNeedToReshowWhenReenabled = false;
253
254 // cached value of whether we are showing (need to know this to quickly
255 // answer whether the input should be restricted)
Jim Millere5f17ab2013-11-13 15:40:48 -0800256 private boolean mShowing;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800257
Lucas Dupin47a65c72018-02-15 14:16:18 -0800258 // AOD is enabled and status bar is in AOD state.
259 private boolean mAodShowing;
260
Jim Millerab954542014-10-10 18:21:49 -0700261 /** Cached value of #isInputRestricted */
262 private boolean mInputRestricted;
263
Mike Lockwood09a40402009-11-08 00:33:23 -0500264 // true if the keyguard is hidden by another window
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100265 private boolean mOccluded = false;
Mike Lockwood09a40402009-11-08 00:33:23 -0500266
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800267 /**
268 * Helps remember whether the screen has turned on since the last time
269 * it turned off due to timeout. see {@link #onScreenTurnedOff(int)}
270 */
271 private int mDelayedShowingSequence;
272
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800273 /**
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000274 * Simiar to {@link #mDelayedProfileShowingSequence}, but it is for profile case.
275 */
276 private int mDelayedProfileShowingSequence;
277
278 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800279 * If the user has disabled the keyguard, then requests to exit, this is
280 * how we'll ultimately let them know whether it was successful. We use this
281 * var being non-null as an indicator that there is an in progress request.
282 */
Jim Miller25190572013-02-28 17:36:24 -0800283 private IKeyguardExitCallback mExitSecureCallback;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700284 private final DismissCallbackRegistry mDismissCallbackRegistry = new DismissCallbackRegistry();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800285
286 // the properties of the keyguard
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800287
288 private KeyguardUpdateMonitor mUpdateMonitor;
289
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700290 /**
291 * Last SIM state reported by the telephony system.
292 * Index is the slotId - in case of multiple SIM cards.
293 */
294 private final SparseArray<IccCardConstants.State> mLastSimStates = new SparseArray<>();
295
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700296 private boolean mDeviceInteractive;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700297 private boolean mGoingToSleep;
Karl Rosaenab100082009-03-24 22:35:17 -0700298
Daniel Sandlerf2d8e742010-02-22 13:09:48 -0500299 // last known state of the cellular connection
300 private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE;
301
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800302 /**
Jorim Jaggi53c68a42014-06-17 15:04:47 -0700303 * Whether a hide is pending an we are just waiting for #startKeyguardExitAnimation to be
304 * called.
305 * */
306 private boolean mHiding;
307
308 /**
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700309 * we send this intent when the keyguard is dismissed.
310 */
Jim Miller17f509a2013-02-28 18:36:12 -0800311 private static final Intent USER_PRESENT_INTENT = new Intent(Intent.ACTION_USER_PRESENT)
312 .addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
Chad Brubaker291df4f2017-03-14 10:23:02 -0700313 | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
314 | Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700315
316 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800317 * {@link #setKeyguardEnabled} waits on this condition when it reenables
318 * the keyguard.
319 */
320 private boolean mWaitingUntilKeyguardVisible = false;
Dave Mankoffbb9575f2019-10-02 12:23:49 -0400321 private final LockPatternUtils mLockPatternUtils;
John Spurlock34c4fe52012-11-07 10:12:29 -0500322 private boolean mKeyguardDonePending = false;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200323 private boolean mHideAnimationRun = false;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700324 private boolean mHideAnimationRunning = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800325
Marco Nelissend5545bd2011-09-29 12:49:17 -0700326 private SoundPool mLockSounds;
327 private int mLockSoundId;
328 private int mUnlockSoundId;
Adrian Roos49e057d2014-08-13 17:14:51 +0200329 private int mTrustedSoundId;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700330 private int mLockSoundStreamId;
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700331
332 /**
Adrian Roos0002a452014-07-03 13:46:07 +0200333 * The animation used for hiding keyguard. This is used to fetch the animation timings if
334 * WindowManager is not providing us with them.
335 */
336 private Animation mHideAnimation;
337
338 /**
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700339 * The volume applied to the lock/unlock sounds.
340 */
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200341 private float mLockSoundVolume;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700342
Jim Millerdcb3d842012-08-23 19:18:12 -0700343 /**
Jim Miller31921482013-11-06 20:43:55 -0800344 * For managing external displays
345 */
346 private KeyguardDisplayManager mKeyguardDisplayManager;
347
Jim Millerab954542014-10-10 18:21:49 -0700348 private final ArrayList<IKeyguardStateCallback> mKeyguardStateCallbacks = new ArrayList<>();
349
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700350 /**
351 * When starting going to sleep, we figured out that we need to reset Keyguard state and this
352 * should be committed when finished going to sleep.
353 */
354 private boolean mPendingReset;
355
356 /**
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700357 * 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 -0700358 * committed when finished going to sleep.
359 */
360 private boolean mPendingLock;
361
Robin Leec41f6ec2017-01-10 17:02:34 +0000362 /**
363 * Controller for showing individual "work challenge" lock screen windows inside managed profile
364 * tasks when the current user has been unlocked but the profile is still locked.
365 */
366 private WorkLockActivityController mWorkLockController;
367
Lucas Dupind35502f2018-06-27 13:35:52 -0700368 /**
369 * @see #setPulsing(boolean)
370 */
371 private boolean mPulsing;
372
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000373 private boolean mLockLater;
374
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700375 private boolean mWakeAndUnlocking;
376 private IKeyguardDrawnCallback mDrawnCallback;
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800377 private CharSequence mCustomMessage;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700378
Jim Millerbbf1a742012-07-17 18:30:30 -0700379 KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {
380
381 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500382 public void onUserSwitching(int userId) {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700383 // Note that the mLockPatternUtils user has already been updated from setCurrentUser.
Adam Cohenf7522022012-10-03 20:03:18 -0700384 // We need to force a reset of the views, since lockNow (called by
385 // ActivityManagerService) will not reconstruct the keyguard if it is already showing.
Jim Millerbbf1a742012-07-17 18:30:30 -0700386 synchronized (KeyguardViewMediator.this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100387 resetKeyguardDonePendingLocked();
Alex Chau77ef9fc2018-04-11 15:41:32 +0100388 if (mLockPatternUtils.isLockScreenDisabled(userId)) {
389 // If we switching to a user that has keyguard disabled, dismiss keyguard.
390 dismiss(null /* callback */, null /* message */);
391 } else {
392 resetStateLocked();
393 }
John Spurlock4e6922d2012-10-04 14:51:51 -0400394 adjustStatusBarLocked();
Dianne Hackborn5dc5a002012-09-15 19:33:48 -0700395 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700396 }
397
398 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500399 public void onUserSwitchComplete(int userId) {
Xiaohui Chen87d0e252015-07-30 15:38:16 -0700400 if (userId != UserHandle.USER_SYSTEM) {
Adrian Roosbe47b072014-09-03 00:08:56 +0200401 UserInfo info = UserManager.get(mContext).getUserInfo(userId);
Kevin Chynf2c0a642017-05-25 11:29:08 -0700402 // Don't try to dismiss if the user has Pin/Patter/Password set
403 if (info == null || mLockPatternUtils.isSecure(userId)) {
404 return;
405 } else if (info.isGuest() || info.isDemo()) {
Adrian Roosbe47b072014-09-03 00:08:56 +0200406 // If we just switched to a guest, try to dismiss keyguard.
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800407 dismiss(null /* callback */, null /* message */);
Adrian Roosbe47b072014-09-03 00:08:56 +0200408 }
409 }
Chris Wrenf41c61b2012-11-29 15:19:54 -0500410 }
411
412 @Override
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -0700413 public void onUserInfoChanged(int userId) {
Jim Millerbbf1a742012-07-17 18:30:30 -0700414 }
415
416 @Override
Jim Millerb0304762012-03-13 20:01:25 -0700417 public void onClockVisibilityChanged() {
418 adjustStatusBarLocked();
419 }
420
421 @Override
422 public void onDeviceProvisioned() {
Jim Miller3fd47af2012-09-21 19:55:27 -0700423 sendUserPresentBroadcast();
Amith Yamasanicb15d662015-11-10 11:11:15 -0800424 synchronized (KeyguardViewMediator.this) {
425 // If system user is provisioned, we might want to lock now to avoid showing launcher
Amith Yamasanieb437d42016-04-29 09:31:25 -0700426 if (mustNotUnlockCurrentUser()) {
Amith Yamasanicb15d662015-11-10 11:11:15 -0800427 doKeyguardLocked(null);
428 }
429 }
Jim Millerb0304762012-03-13 20:01:25 -0700430 }
431
Jim Millerbbf1a742012-07-17 18:30:30 -0700432 @Override
Jim Miller52a61332014-11-12 19:29:51 -0800433 public void onSimStateChanged(int subId, int slotId, IccCardConstants.State simState) {
434
435 if (DEBUG_SIM_STATES) {
436 Log.d(TAG, "onSimStateChanged(subId=" + subId + ", slotId=" + slotId
437 + ",state=" + simState + ")");
438 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700439
dooyoung.hwang328472e2015-05-21 16:09:43 +0900440 int size = mKeyguardStateCallbacks.size();
441 boolean simPinSecure = mUpdateMonitor.isSimPinSecure();
442 for (int i = size - 1; i >= 0; i--) {
443 try {
Jim Millerab954542014-10-10 18:21:49 -0700444 mKeyguardStateCallbacks.get(i).onSimSecureStateChanged(simPinSecure);
dooyoung.hwang328472e2015-05-21 16:09:43 +0900445 } catch (RemoteException e) {
446 Slog.w(TAG, "Failed to call onSimSecureStateChanged", e);
447 if (e instanceof DeadObjectException) {
448 mKeyguardStateCallbacks.remove(i);
449 }
Jim Millerab954542014-10-10 18:21:49 -0700450 }
Jim Millerab954542014-10-10 18:21:49 -0700451 }
452
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700453 boolean simWasLocked;
454 synchronized (KeyguardViewMediator.this) {
455 IccCardConstants.State lastState = mLastSimStates.get(slotId);
Brad Ebingere6c6f722018-12-20 21:11:44 -0800456 simWasLocked = (lastState == PIN_REQUIRED || lastState == PUK_REQUIRED);
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700457 mLastSimStates.append(slotId, simState);
458 }
459
Jim Millerbbf1a742012-07-17 18:30:30 -0700460 switch (simState) {
461 case NOT_READY:
462 case ABSENT:
463 // only force lock screen in case of missing sim if user hasn't
464 // gone through setup wizard
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800465 synchronized (KeyguardViewMediator.this) {
Jim Millerb256e4e22014-10-31 17:27:13 -0700466 if (shouldWaitForProvisioning()) {
Jim Millerab954542014-10-10 18:21:49 -0700467 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800468 if (DEBUG_SIM_STATES) Log.d(TAG, "ICC_ABSENT isn't showing,"
Jim Millerbbf1a742012-07-17 18:30:30 -0700469 + " we need to show the keyguard since the "
470 + "device isn't provisioned yet.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800471 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700472 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100473 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700474 }
475 }
Adrian Roose92de952016-12-13 12:07:09 -0800476 if (simState == ABSENT) {
477 // MVNO SIMs can become transiently NOT_READY when switching networks,
478 // so we should only lock when they are ABSENT.
Lucas Dupin2e0d4952018-12-05 20:03:53 -0800479 if (simWasLocked) {
Brad Ebingere6c6f722018-12-20 21:11:44 -0800480 if (DEBUG_SIM_STATES) Log.d(TAG, "SIM moved to ABSENT when the "
481 + "previous state was locked. Reset the state.");
Lucas Dupin2e0d4952018-12-05 20:03:53 -0800482 resetStateLocked();
483 }
Adrian Roose92de952016-12-13 12:07:09 -0800484 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700485 }
486 break;
487 case PIN_REQUIRED:
488 case PUK_REQUIRED:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800489 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700490 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800491 if (DEBUG_SIM_STATES) Log.d(TAG,
492 "INTENT_VALUE_ICC_LOCKED and keygaurd isn't "
Jim Millerbbf1a742012-07-17 18:30:30 -0700493 + "showing; need to show keyguard so user can enter sim pin");
Jim Miller5ecd8112013-01-09 18:50:26 -0800494 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700495 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100496 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700497 }
498 }
499 break;
500 case PERM_DISABLED:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800501 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700502 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800503 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED and "
Jim Millerbbf1a742012-07-17 18:30:30 -0700504 + "keygaurd isn't showing.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800505 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700506 } else {
Jim Miller52a61332014-11-12 19:29:51 -0800507 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED, resetStateLocked to"
Jim Millerbbf1a742012-07-17 18:30:30 -0700508 + "show permanently disabled message in lockscreen.");
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100509 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700510 }
511 }
512 break;
513 case READY:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800514 synchronized (KeyguardViewMediator.this) {
Lucas Dupinab3079d2018-06-07 09:41:18 -0700515 if (DEBUG_SIM_STATES) Log.d(TAG, "READY, reset state? " + mShowing);
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700516 if (mShowing && simWasLocked) {
Brad Ebingere6c6f722018-12-20 21:11:44 -0800517 if (DEBUG_SIM_STATES) Log.d(TAG, "SIM moved to READY when the "
518 + "previous state was locked. Reset the state.");
Lucas Dupin6d48eab2018-09-17 17:17:14 -0700519 resetStateLocked();
520 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700521 }
522 break;
Jim Miller52a61332014-11-12 19:29:51 -0800523 default:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800524 if (DEBUG_SIM_STATES) Log.v(TAG, "Unspecific state: " + simState);
Jim Miller52a61332014-11-12 19:29:51 -0800525 break;
Jim Millerbbf1a742012-07-17 18:30:30 -0700526 }
527 }
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000528
529 @Override
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200530 public void onBiometricAuthFailed(BiometricSourceType biometricSourceType) {
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000531 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
532 if (mLockPatternUtils.isSecure(currentUser)) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200533 mLockPatternUtils.getDevicePolicyManager().reportFailedBiometricAttempt(
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000534 currentUser);
535 }
536 }
537
538 @Override
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200539 public void onBiometricAuthenticated(int userId, BiometricSourceType biometricSourceType) {
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000540 if (mLockPatternUtils.isSecure(userId)) {
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200541 mLockPatternUtils.getDevicePolicyManager().reportSuccessfulBiometricAttempt(
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000542 userId);
543 }
544 }
Adrian Roosd88eb262016-08-04 14:50:48 -0700545
546 @Override
547 public void onTrustChanged(int userId) {
548 if (userId == KeyguardUpdateMonitor.getCurrentUser()) {
549 synchronized (KeyguardViewMediator.this) {
550 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(userId));
551 }
552 }
553 }
554
Jorim Jaggid11d1a92016-08-16 16:02:32 -0700555 @Override
556 public void onHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
557 synchronized (KeyguardViewMediator.this) {
558 notifyHasLockscreenWallpaperChanged(hasLockscreenWallpaper);
559 }
560 }
Jim Millerb0304762012-03-13 20:01:25 -0700561 };
562
Jim Millerdcb3d842012-08-23 19:18:12 -0700563 ViewMediatorCallback mViewMediatorCallback = new ViewMediatorCallback() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100564
Jim Miller2967f482016-01-07 15:05:32 -0800565 @Override
Jeff Brownc7505bc2012-10-05 21:58:15 -0700566 public void userActivity() {
567 KeyguardViewMediator.this.userActivity();
568 }
569
Jim Miller2967f482016-01-07 15:05:32 -0800570 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700571 public void keyguardDone(boolean strongAuth, int targetUserId) {
572 if (targetUserId != ActivityManager.getCurrentUser()) {
573 return;
574 }
575
Jorim Jaggi241ae102016-11-02 21:57:33 -0700576 tryKeyguardDone();
Jim Millerdcb3d842012-08-23 19:18:12 -0700577 }
578
Jim Miller2967f482016-01-07 15:05:32 -0800579 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700580 public void keyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700581 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDoneDrawing");
Jim Millerdcb3d842012-08-23 19:18:12 -0700582 mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700583 Trace.endSection();
Jim Millerdcb3d842012-08-23 19:18:12 -0700584 }
585
586 @Override
587 public void setNeedsInput(boolean needsInput) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100588 mStatusBarKeyguardViewManager.setNeedsInput(needsInput);
Jim Millerdcb3d842012-08-23 19:18:12 -0700589 }
Jeff Brownc7505bc2012-10-05 21:58:15 -0700590
591 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700592 public void keyguardDonePending(boolean strongAuth, int targetUserId) {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700593 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDonePending");
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700594 if (targetUserId != ActivityManager.getCurrentUser()) {
Nick Desaulniersaeb2e1e2016-07-27 15:36:01 -0700595 Trace.endSection();
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700596 return;
597 }
598
John Spurlock34c4fe52012-11-07 10:12:29 -0500599 mKeyguardDonePending = true;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200600 mHideAnimationRun = true;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700601 mHideAnimationRunning = true;
602 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100603 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_PENDING_TIMEOUT,
604 KEYGUARD_DONE_PENDING_TIMEOUT_MS);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700605 Trace.endSection();
John Spurlock34c4fe52012-11-07 10:12:29 -0500606 }
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800607
608 @Override
609 public void keyguardGone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700610 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardGone");
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800611 mKeyguardDisplayManager.hide();
Nick Desaulniers1d396752016-07-25 15:05:33 -0700612 Trace.endSection();
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800613 }
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200614
615 @Override
616 public void readyForKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700617 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#readyForKeyguardDone");
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200618 if (mKeyguardDonePending) {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700619 mKeyguardDonePending = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700620 tryKeyguardDone();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200621 }
Nick Desaulniers1d396752016-07-25 15:05:33 -0700622 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200623 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200624
625 @Override
Andrew Lee72b46d42015-01-30 13:23:21 -0800626 public void resetKeyguard() {
627 resetStateLocked();
628 }
629
630 @Override
Aarthi Balachander0a427ef2018-07-13 15:00:58 -0700631 public void onCancelClicked() {
632 mStatusBarKeyguardViewManager.onCancelClicked();
633 }
634
635 @Override
Matthew Ng66f0b702017-12-08 12:58:42 -0800636 public void onBouncerVisiblityChanged(boolean shown) {
637 synchronized (KeyguardViewMediator.this) {
638 adjustStatusBarLocked(shown);
639 }
640 }
641
642 @Override
Adrian Roos49e057d2014-08-13 17:14:51 +0200643 public void playTrustedSound() {
644 KeyguardViewMediator.this.playTrustedSound();
645 }
Jim Millerab954542014-10-10 18:21:49 -0700646
647 @Override
Adrian Roos94e15a52015-04-16 12:23:18 -0700648 public boolean isScreenOn() {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700649 return mDeviceInteractive;
Adrian Roos94e15a52015-04-16 12:23:18 -0700650 }
Selim Cinek3122fa82015-06-18 01:38:59 -0700651
652 @Override
653 public int getBouncerPromptReason() {
Lucas Dupinf2c53502019-10-03 13:56:18 -0700654 int currentUser = KeyguardUpdateMonitor.getCurrentUser();
655 boolean trust = mUpdateMonitor.isTrustUsuallyManaged(currentUser);
656 boolean biometrics = mUpdateMonitor.isUnlockingWithBiometricsPossible(currentUser);
657 boolean any = trust || biometrics;
658 KeyguardUpdateMonitor.StrongAuthTracker strongAuthTracker =
659 mUpdateMonitor.getStrongAuthTracker();
660 int strongAuth = strongAuthTracker.getStrongAuthForUser(currentUser);
Adrian Roosc13723f2016-01-12 20:29:03 +0100661
Lucas Dupinf2c53502019-10-03 13:56:18 -0700662 if (any && !strongAuthTracker.hasUserAuthenticatedSinceBoot()) {
663 return KeyguardSecurityView.PROMPT_REASON_RESTART;
664 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_TIMEOUT) != 0) {
665 return KeyguardSecurityView.PROMPT_REASON_TIMEOUT;
666 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW) != 0) {
667 return KeyguardSecurityView.PROMPT_REASON_DEVICE_ADMIN;
668 } else if (trust && (strongAuth & SOME_AUTH_REQUIRED_AFTER_USER_REQUEST) != 0) {
669 return KeyguardSecurityView.PROMPT_REASON_USER_REQUEST;
670 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_LOCKOUT) != 0) {
671 return KeyguardSecurityView.PROMPT_REASON_AFTER_LOCKOUT;
672 }
673 return KeyguardSecurityView.PROMPT_REASON_NONE;
Selim Cinek3122fa82015-06-18 01:38:59 -0700674 }
David Stevens53a39ea2017-08-23 18:41:49 -0700675
676 @Override
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800677 public CharSequence consumeCustomMessage() {
678 final CharSequence message = mCustomMessage;
679 mCustomMessage = null;
680 return message;
681 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700682 };
683
Dave Mankoffaa8b7ae2019-09-04 18:03:21 -0400684 @Inject
Dave Mankoffbb9575f2019-10-02 12:23:49 -0400685 public KeyguardViewMediator(
686 Context context,
687 FalsingManager falsingManager,
688 LockPatternUtils lockPatternUtils) {
Curtis Belmonte5cece532019-10-15 09:44:28 -0700689 this(context, falsingManager, lockPatternUtils, SystemUIFactory.getInstance());
690 }
691
692 @VisibleForTesting
693 KeyguardViewMediator(
694 Context context,
695 FalsingManager falsingManager,
696 LockPatternUtils lockPatternUtils,
697 SystemUIFactory systemUIFactory) {
Dave Mankoffa5d8a392019-10-10 12:21:09 -0400698 super(context);
Dave Mankoffaa8b7ae2019-09-04 18:03:21 -0400699 mFalsingManager = falsingManager;
Dave Mankoffbb9575f2019-10-02 12:23:49 -0400700 mLockPatternUtils = lockPatternUtils;
Curtis Belmonte5cece532019-10-15 09:44:28 -0700701 mStatusBarKeyguardViewManager = systemUIFactory.createStatusBarKeyguardViewManager(
702 mContext,
703 mViewMediatorCallback,
704 mLockPatternUtils);
Dave Mankoffaa8b7ae2019-09-04 18:03:21 -0400705 }
706
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200707 public void userActivity() {
Jeff Brown3dc524b2012-09-30 19:49:11 -0700708 mPM.userActivity(SystemClock.uptimeMillis(), false);
Jim Millerdcb3d842012-08-23 19:18:12 -0700709 }
710
Amith Yamasanieb437d42016-04-29 09:31:25 -0700711 boolean mustNotUnlockCurrentUser() {
Christine Franks338c6ed2017-08-08 09:39:16 -0700712 return UserManager.isSplitSystemUser()
Amith Yamasanieb437d42016-04-29 09:31:25 -0700713 && KeyguardUpdateMonitor.getCurrentUser() == UserHandle.USER_SYSTEM;
714 }
715
Jim Millerab954542014-10-10 18:21:49 -0700716 private void setupLocked() {
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200717 mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
Lucas Dupinf2c53502019-10-03 13:56:18 -0700718 mTrustManager = mContext.getSystemService(TrustManager.class);
Adrian Roos481a6df2014-11-20 19:48:56 +0100719
Mike Lockwood674d3e42009-10-06 09:28:54 -0400720 mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
721 mShowKeyguardWakeLock.setReferenceCounted(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800722
Adrian Roos1f8025a2016-12-27 10:12:13 -0800723 IntentFilter filter = new IntentFilter();
Adrian Roos1f8025a2016-12-27 10:12:13 -0800724 filter.addAction(Intent.ACTION_SHUTDOWN);
725 mContext.registerReceiver(mBroadcastReceiver, filter);
Jim Millerbbf1a742012-07-17 18:30:30 -0700726
Kevin Chyn18e91aa2018-04-11 12:55:45 -0700727 final IntentFilter delayedActionFilter = new IntentFilter();
728 delayedActionFilter.addAction(DELAYED_KEYGUARD_ACTION);
729 delayedActionFilter.addAction(DELAYED_LOCK_PROFILE_ACTION);
730 mContext.registerReceiver(mDelayedLockBroadcastReceiver, delayedActionFilter,
731 SYSTEMUI_PERMISSION, null /* scheduler */);
732
Robert Snoebergerbe35b762019-03-15 14:33:02 -0400733 InjectionInflationController injectionInflationController =
734 new InjectionInflationController(SystemUIFactory.getInstance().getRootComponent());
735 mKeyguardDisplayManager = new KeyguardDisplayManager(mContext,
736 injectionInflationController);
Jim Miller31921482013-11-06 20:43:55 -0800737
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200738 mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800739
Dave Mankoffe2294692019-08-14 11:53:13 -0400740 mUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800741
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.
Hyunyoung Song8f9d34c2019-08-30 14:47:43 -0700746 if (mContext.getResources().getBoolean(R.bool.config_enableKeyguardService)) {
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200747 setShowingLocked(!shouldWaitForProvisioning()
748 && !mLockPatternUtils.isLockScreenDisabled(
Lucas Dupinb3455e62019-07-11 11:47:13 +0900749 KeyguardUpdateMonitor.getCurrentUser()), true /* forceCallbacks */);
Leif Hendrik Wildenc6dc1c92018-02-01 10:54:15 -0800750 } else {
751 // The system's keyguard is disabled or missing.
Lucas Dupinb3455e62019-07-11 11:47:13 +0900752 setShowingLocked(false /* showing */, true /* forceCallbacks */);
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200753 }
Jim Millere5f17ab2013-11-13 15:40:48 -0800754
Daniel Sandler687a3272010-03-13 15:44:47 -0500755 final ContentResolver cr = mContext.getContentResolver();
Marco Nelissend5545bd2011-09-29 12:49:17 -0700756
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700757 mDeviceInteractive = mPM.isInteractive();
Daniel Hansson4b716862012-03-29 11:02:05 +0200758
Jean-Michel Trivi0616db42019-01-28 10:57:21 -0800759 mLockSounds = new SoundPool.Builder()
760 .setMaxStreams(1)
761 .setAudioAttributes(
762 new AudioAttributes.Builder()
763 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
764 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
765 .build())
766 .build();
Jim Millerb14288d2012-09-30 18:25:05 -0700767 String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700768 if (soundPath != null) {
769 mLockSoundId = mLockSounds.load(soundPath, 1);
770 }
771 if (soundPath == null || mLockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700772 Log.w(TAG, "failed to load lock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700773 }
Jim Millerb14288d2012-09-30 18:25:05 -0700774 soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700775 if (soundPath != null) {
776 mUnlockSoundId = mLockSounds.load(soundPath, 1);
777 }
778 if (soundPath == null || mUnlockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700779 Log.w(TAG, "failed to load unlock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700780 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200781 soundPath = Settings.Global.getString(cr, Settings.Global.TRUSTED_SOUND);
782 if (soundPath != null) {
783 mTrustedSoundId = mLockSounds.load(soundPath, 1);
784 }
785 if (soundPath == null || mTrustedSoundId == 0) {
786 Log.w(TAG, "failed to load trusted sound from " + soundPath);
787 }
788
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200789 int lockSoundDefaultAttenuation = mContext.getResources().getInteger(
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700790 com.android.internal.R.integer.config_lockSoundVolumeDb);
Jean-Michel Trivif2b0c112012-07-09 11:59:11 -0700791 mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20);
Adrian Roos0002a452014-07-03 13:46:07 +0200792
793 mHideAnimation = AnimationUtils.loadAnimation(mContext,
794 com.android.internal.R.anim.lock_screen_behind_enter);
Robin Leec41f6ec2017-01-10 17:02:34 +0000795
796 mWorkLockController = new WorkLockActivityController(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800797 }
798
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200799 @Override
800 public void start() {
Jim Millerab954542014-10-10 18:21:49 -0700801 synchronized (this) {
802 setupLocked();
803 }
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200804 }
805
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800806 /**
807 * Let us know that the system is ready after startup.
808 */
809 public void onSystemReady() {
Adrian Roos30a2ae62018-04-25 19:09:50 +0200810 mHandler.obtainMessage(SYSTEM_READY).sendToTarget();
811 }
812
813 private void handleSystemReady() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800814 synchronized (this) {
815 if (DEBUG) Log.d(TAG, "onSystemReady");
816 mSystemReady = true;
Jim Miller5ecd8112013-01-09 18:50:26 -0800817 doKeyguardLocked(null);
Selim Cinekedd32b82015-06-23 22:05:58 -0400818 mUpdateMonitor.registerCallback(mUpdateCallback);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800819 }
Jim Miller3fd47af2012-09-21 19:55:27 -0700820 // Most services aren't available until the system reaches the ready state, so we
821 // send it here when the device first boots.
822 maybeSendUserPresentBroadcast();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800823 }
824
825 /**
826 * Called to let us know the screen was turned off.
Adrian Roose99bc052017-11-20 17:55:31 +0100827 * @param why either {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_USER} or
828 * {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_TIMEOUT}.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800829 */
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700830 public void onStartedGoingToSleep(int why) {
831 if (DEBUG) Log.d(TAG, "onStartedGoingToSleep(" + why + ")");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800832 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700833 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700834 mGoingToSleep = true;
John Spurlock14adfe42012-11-08 10:29:26 -0500835
Curtis Belmontec6061d52019-10-18 16:13:10 -0700836 // Reset keyguard going away state so we can start listening for fingerprint. We
837 // explicitly DO NOT want to call mStatusBarWindowController.setKeyguardGoingAway(false)
838 // here, since that will mess with the device lock state.
839 mUpdateMonitor.setKeyguardGoingAway(false);
Curtis Belmonte5cece532019-10-15 09:44:28 -0700840
Jim Millera4edd152012-01-06 18:24:04 -0800841 // Lock immediately based on setting if secure (user has a pin/pattern/password).
842 // This also "locks" the device when not secure to provide easy access to the
843 // camera while preventing unwanted input.
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700844 int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jim Millera4edd152012-01-06 18:24:04 -0800845 final boolean lockImmediately =
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700846 mLockPatternUtils.getPowerButtonInstantlyLocks(currentUser)
847 || !mLockPatternUtils.isSecure(currentUser);
Clara Bayarri56878a92015-10-29 15:43:55 +0000848 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000849 mLockLater = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800850 if (mExitSecureCallback != null) {
851 if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled");
Jim Miller5ecd8112013-01-09 18:50:26 -0800852 try {
853 mExitSecureCallback.onKeyguardExitResult(false);
854 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800855 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800856 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800857 mExitSecureCallback = null;
858 if (!mExternallyEnabled) {
Jim Miller9c20d0e2010-01-20 15:00:23 -0800859 hideLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800860 }
861 } else if (mShowing) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700862 mPendingReset = true;
Adrian Roose99bc052017-11-20 17:55:31 +0100863 } else if ((why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_TIMEOUT && timeout > 0)
864 || (why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER && !lockImmediately)) {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700865 doKeyguardLaterLocked(timeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000866 mLockLater = true;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700867 } else if (!mLockPatternUtils.isLockScreenDisabled(currentUser)) {
868 mPendingLock = true;
869 }
870
Jorim Jaggi853cbe32015-06-04 16:31:54 -0700871 if (mPendingLock) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700872 playSounds(true);
873 }
874 }
Dave Mankoffe2294692019-08-14 11:53:13 -0400875 mUpdateMonitor.dispatchStartedGoingToSleep(why);
Jorim Jaggi18f18ae2015-09-10 15:48:21 -0700876 notifyStartedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700877 }
878
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700879 public void onFinishedGoingToSleep(int why, boolean cameraGestureTriggered) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700880 if (DEBUG) Log.d(TAG, "onFinishedGoingToSleep(" + why + ")");
881 synchronized (this) {
882 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700883 mGoingToSleep = false;
Adrian Roose4cb6c8a2017-07-19 18:08:07 +0200884 mWakeAndUnlocking = false;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700885
886 resetKeyguardDonePendingLocked();
887 mHideAnimationRun = false;
888
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700889 notifyFinishedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700890
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700891 if (cameraGestureTriggered) {
892 Log.i(TAG, "Camera gesture was triggered, preventing Keyguard locking.");
893
894 // Just to make sure, make sure the device is awake.
895 mContext.getSystemService(PowerManager.class).wakeUp(SystemClock.uptimeMillis(),
Michael Wrighte3001042019-02-05 00:13:14 +0000896 PowerManager.WAKE_REASON_CAMERA_LAUNCH,
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700897 "com.android.systemui:CAMERA_GESTURE_PREVENT_LOCK");
898 mPendingLock = false;
899 mPendingReset = false;
900 }
901
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700902 if (mPendingReset) {
903 resetStateLocked();
904 mPendingReset = false;
905 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000906
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700907 if (mPendingLock) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800908 doKeyguardLocked(null);
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700909 mPendingLock = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800910 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000911
912 // We do not have timeout and power button instant lock setting for profile lock.
913 // So we use the personal setting if there is any. But if there is no device
914 // we need to make sure we lock it immediately when the screen is off.
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700915 if (!mLockLater && !cameraGestureTriggered) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000916 doKeyguardForChildProfilesLocked();
917 }
918
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800919 }
Dave Mankoffe2294692019-08-14 11:53:13 -0400920 mUpdateMonitor.dispatchFinishedGoingToSleep(why);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800921 }
922
Clara Bayarri56878a92015-10-29 15:43:55 +0000923 private long getLockTimeout(int userId) {
Jeff Brown6aaf2952012-10-05 16:01:08 -0700924 // if the screen turned off because of timeout or the user hit the power button
925 // and we don't need to lock immediately, set an alarm
926 // to enable it a little bit later (i.e, give the user a chance
927 // to turn the screen back on within a certain window without
928 // having to unlock the screen)
929 final ContentResolver cr = mContext.getContentResolver();
930
Jeff Brown6aaf2952012-10-05 16:01:08 -0700931 // From SecuritySettings
932 final long lockAfterTimeout = Settings.Secure.getInt(cr,
933 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT,
934 KEYGUARD_LOCK_AFTER_DELAY_DEFAULT);
935
936 // From DevicePolicyAdmin
937 final long policyTimeout = mLockPatternUtils.getDevicePolicyManager()
Pavel Grafov28939982017-10-03 15:11:52 +0100938 .getMaximumTimeToLock(null, userId);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700939
940 long timeout;
Clara Bayarri56878a92015-10-29 15:43:55 +0000941
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000942 if (policyTimeout <= 0) {
Clara Bayarri56878a92015-10-29 15:43:55 +0000943 timeout = lockAfterTimeout;
944 } else {
945 // From DisplaySettings
946 long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT,
947 KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT);
948
Jeff Brown6aaf2952012-10-05 16:01:08 -0700949 // policy in effect. Make sure we don't go beyond policy limit.
950 displayTimeout = Math.max(displayTimeout, 0); // ignore negative values
951 timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000952 timeout = Math.max(timeout, 0);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700953 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700954 return timeout;
955 }
Jeff Brown6aaf2952012-10-05 16:01:08 -0700956
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700957 private void doKeyguardLaterLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000958 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700959 if (timeout == 0) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800960 doKeyguardLocked(null);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700961 } else {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700962 doKeyguardLaterLocked(timeout);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700963 }
964 }
965
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700966 private void doKeyguardLaterLocked(long timeout) {
967 // Lock in the future
968 long when = SystemClock.elapsedRealtime() + timeout;
969 Intent intent = new Intent(DELAYED_KEYGUARD_ACTION);
970 intent.putExtra("seq", mDelayedShowingSequence);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700971 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700972 PendingIntent sender = PendingIntent.getBroadcast(mContext,
973 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Jim Millera622d3cc2016-03-02 16:02:24 -0800974 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700975 if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = "
976 + mDelayedShowingSequence);
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000977 doKeyguardLaterForChildProfilesLocked();
Clara Bayarri56878a92015-10-29 15:43:55 +0000978 }
Clara Bayarri10ad84a2015-12-01 17:38:05 +0000979
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000980 private void doKeyguardLaterForChildProfilesLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000981 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700982 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
983 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
984 long userTimeout = getLockTimeout(profileId);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000985 if (userTimeout == 0) {
986 doKeyguardForChildProfilesLocked();
987 } else {
988 long userWhen = SystemClock.elapsedRealtime() + userTimeout;
989 Intent lockIntent = new Intent(DELAYED_LOCK_PROFILE_ACTION);
990 lockIntent.putExtra("seq", mDelayedProfileShowingSequence);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700991 lockIntent.putExtra(Intent.EXTRA_USER_ID, profileId);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700992 lockIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000993 PendingIntent lockSender = PendingIntent.getBroadcast(
994 mContext, 0, lockIntent, PendingIntent.FLAG_CANCEL_CURRENT);
995 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
996 userWhen, lockSender);
997 }
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000998 }
999 }
1000 }
1001
1002 private void doKeyguardForChildProfilesLocked() {
1003 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07001004 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
1005 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
1006 lockProfile(profileId);
Clara Bayarri56878a92015-10-29 15:43:55 +00001007 }
1008 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -07001009 }
1010
Jeff Brown6aaf2952012-10-05 16:01:08 -07001011 private void cancelDoKeyguardLaterLocked() {
1012 mDelayedShowingSequence++;
1013 }
1014
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001015 private void cancelDoKeyguardForChildProfilesLocked() {
1016 mDelayedProfileShowingSequence++;
1017 }
1018
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001019 /**
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001020 * Let's us know when the device is waking up.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001021 */
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001022 public void onStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001023 Trace.beginSection("KeyguardViewMediator#onStartedWakingUp");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001024
1025 // TODO: Rename all screen off/on references to interactive/sleeping
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001026 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001027 mDeviceInteractive = true;
Jeff Brown6aaf2952012-10-05 16:01:08 -07001028 cancelDoKeyguardLaterLocked();
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001029 cancelDoKeyguardForChildProfilesLocked();
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001030 if (DEBUG) Log.d(TAG, "onStartedWakingUp, seq = " + mDelayedShowingSequence);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001031 notifyStartedWakingUp();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001032 }
Dave Mankoffe2294692019-08-14 11:53:13 -04001033 mUpdateMonitor.dispatchStartedWakingUp();
Jim Miller3fd47af2012-09-21 19:55:27 -07001034 maybeSendUserPresentBroadcast();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001035 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -07001036 }
1037
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001038 public void onScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001039 Trace.beginSection("KeyguardViewMediator#onScreenTurningOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001040 notifyScreenOn(callback);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001041 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001042 }
1043
1044 public void onScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001045 Trace.beginSection("KeyguardViewMediator#onScreenTurnedOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001046 notifyScreenTurnedOn();
1047 mUpdateMonitor.dispatchScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001048 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001049 }
1050
1051 public void onScreenTurnedOff() {
1052 notifyScreenTurnedOff();
1053 mUpdateMonitor.dispatchScreenTurnedOff();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001054 }
1055
Jim Miller3fd47af2012-09-21 19:55:27 -07001056 private void maybeSendUserPresentBroadcast() {
Adrian Roos8150d2a2015-04-16 17:11:20 -07001057 if (mSystemReady && mLockPatternUtils.isLockScreenDisabled(
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001058 KeyguardUpdateMonitor.getCurrentUser())) {
Jim Miller3fd47af2012-09-21 19:55:27 -07001059 // Lock screen is disabled because the user has set the preference to "None".
1060 // In this case, send out ACTION_USER_PRESENT here instead of in
1061 // handleKeyguardDone()
1062 sendUserPresentBroadcast();
Adrian Roosfb95a812016-06-20 14:58:59 -07001063 } else if (mSystemReady && shouldWaitForProvisioning()) {
1064 // Skipping the lockscreen because we're not yet provisioned, but we still need to
1065 // notify the StrongAuthTracker that it's now safe to run trust agents, in case the
1066 // user sets a credential later.
1067 getLockPatternUtils().userPresent(KeyguardUpdateMonitor.getCurrentUser());
Jim Miller3fd47af2012-09-21 19:55:27 -07001068 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001069 }
1070
1071 /**
Jeff Brown6aaf2952012-10-05 16:01:08 -07001072 * A dream started. We should lock after the usual screen-off lock timeout but only
1073 * if there is a secure lock pattern.
1074 */
1075 public void onDreamingStarted() {
Dave Mankoffe2294692019-08-14 11:53:13 -04001076 mUpdateMonitor.dispatchDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001077 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001078 if (mDeviceInteractive
1079 && mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001080 doKeyguardLaterLocked();
1081 }
1082 }
1083 }
1084
1085 /**
1086 * A dream stopped.
1087 */
1088 public void onDreamingStopped() {
Dave Mankoffe2294692019-08-14 11:53:13 -04001089 mUpdateMonitor.dispatchDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001090 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001091 if (mDeviceInteractive) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001092 cancelDoKeyguardLaterLocked();
1093 }
1094 }
1095 }
1096
1097 /**
Adrian Roose99bc052017-11-20 17:55:31 +01001098 * Same semantics as {@link WindowManagerPolicyConstants#enableKeyguard}; provide
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001099 * a way for external stuff to override normal keyguard behavior. For instance
1100 * the phone app disables the keyguard when it receives incoming calls.
1101 */
1102 public void setKeyguardEnabled(boolean enabled) {
1103 synchronized (this) {
1104 if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")");
1105
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001106 mExternallyEnabled = enabled;
1107
1108 if (!enabled && mShowing) {
1109 if (mExitSecureCallback != null) {
1110 if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring");
1111 // we're in the process of handling a request to verify the user
1112 // can get past the keyguard. ignore extraneous requests to disable / reenable
1113 return;
1114 }
1115
1116 // hiding keyguard that is showing, remember to reshow later
1117 if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, "
1118 + "disabling status bar expansion");
1119 mNeedToReshowWhenReenabled = true;
Jim Millerab954542014-10-10 18:21:49 -07001120 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001121 hideLocked();
1122 } else if (enabled && mNeedToReshowWhenReenabled) {
1123 // reenabled after previously hidden, reshow
1124 if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling "
1125 + "status bar expansion");
1126 mNeedToReshowWhenReenabled = false;
Jim Millerab954542014-10-10 18:21:49 -07001127 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001128
1129 if (mExitSecureCallback != null) {
1130 if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting");
Jim Miller5ecd8112013-01-09 18:50:26 -08001131 try {
1132 mExitSecureCallback.onKeyguardExitResult(false);
1133 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001134 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001135 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001136 mExitSecureCallback = null;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001137 resetStateLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001138 } else {
Adam Cohenf7522022012-10-03 20:03:18 -07001139 showLocked(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001140
1141 // block until we know the keygaurd is done drawing (and post a message
1142 // to unblock us after a timeout so we don't risk blocking too long
1143 // and causing an ANR).
1144 mWaitingUntilKeyguardVisible = true;
1145 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS);
1146 if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false");
1147 while (mWaitingUntilKeyguardVisible) {
1148 try {
1149 wait();
1150 } catch (InterruptedException e) {
1151 Thread.currentThread().interrupt();
1152 }
1153 }
1154 if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible");
1155 }
1156 }
1157 }
1158 }
1159
1160 /**
1161 * @see android.app.KeyguardManager#exitKeyguardSecurely
1162 */
Jim Miller25190572013-02-28 17:36:24 -08001163 public void verifyUnlock(IKeyguardExitCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001164 Trace.beginSection("KeyguardViewMediator#verifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001165 synchronized (this) {
1166 if (DEBUG) Log.d(TAG, "verifyUnlock");
Jim Millerb256e4e22014-10-31 17:27:13 -07001167 if (shouldWaitForProvisioning()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001168 // don't allow this api when the device isn't provisioned
1169 if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned");
Jim Miller5ecd8112013-01-09 18:50:26 -08001170 try {
Jim Miller25190572013-02-28 17:36:24 -08001171 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001172 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001173 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001174 }
Mike Lockwood5d258b62009-12-02 13:50:45 -05001175 } else if (mExternallyEnabled) {
1176 // this only applies when the user has externally disabled the
1177 // keyguard. this is unexpected and means the user is not
1178 // using the api properly.
1179 Log.w(TAG, "verifyUnlock called when not externally disabled");
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 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001185 } else if (mExitSecureCallback != null) {
1186 // already in progress with someone else
Jim Miller5ecd8112013-01-09 18:50:26 -08001187 try {
Jim Miller25190572013-02-28 17:36:24 -08001188 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001189 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001190 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001191 }
Jorim Jaggi302475e2015-09-22 12:44:47 -07001192 } else if (!isSecure()) {
1193
1194 // Keyguard is not secure, no need to do anything, and we don't need to reshow
1195 // the Keyguard after the client releases the Keyguard lock.
1196 mExternallyEnabled = true;
1197 mNeedToReshowWhenReenabled = false;
1198 updateInputRestricted();
1199 try {
1200 callback.onKeyguardExitResult(true);
1201 } catch (RemoteException e) {
1202 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1203 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001204 } else {
Jorim Jaggi302475e2015-09-22 12:44:47 -07001205
1206 // Since we prevent apps from hiding the Keyguard if we are secure, this should be
1207 // a no-op as well.
1208 try {
1209 callback.onKeyguardExitResult(false);
1210 } catch (RemoteException e) {
1211 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1212 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001213 }
1214 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001215 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001216 }
1217
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001218 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001219 * Is the keyguard currently showing and not being force hidden?
Mike Lockwood09a40402009-11-08 00:33:23 -05001220 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001221 public boolean isShowingAndNotOccluded() {
1222 return mShowing && !mOccluded;
1223 }
1224
1225 /**
1226 * Notify us when the keyguard is occluded by another window
1227 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001228 public void setOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001229 Trace.beginSection("KeyguardViewMediator#setOccluded");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001230 if (DEBUG) Log.d(TAG, "setOccluded " + isOccluded);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001231 mHandler.removeMessages(SET_OCCLUDED);
Jorim Jaggi6626f542016-08-22 13:08:44 -07001232 Message msg = mHandler.obtainMessage(SET_OCCLUDED, isOccluded ? 1 : 0, animate ? 1 : 0);
Mike Lockwood9200a392009-11-17 20:25:58 -05001233 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001234 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001235 }
1236
Lucas Dupin2986c152018-04-09 20:49:41 -07001237 public boolean isHiding() {
1238 return mHiding;
1239 }
1240
Mike Lockwood9200a392009-11-17 20:25:58 -05001241 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001242 * Handles SET_OCCLUDED message sent by setOccluded()
Mike Lockwood9200a392009-11-17 20:25:58 -05001243 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001244 private void handleSetOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001245 Trace.beginSection("KeyguardViewMediator#handleSetOccluded");
Mike Lockwood09a40402009-11-08 00:33:23 -05001246 synchronized (KeyguardViewMediator.this) {
Adrian Roosf253eeb2015-04-15 18:03:08 -07001247 if (mHiding && isOccluded) {
1248 // We're in the process of going away but WindowManager wants to show a
1249 // SHOW_WHEN_LOCKED activity instead.
1250 startKeyguardExitAnimation(0, 0);
1251 }
1252
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001253 if (mOccluded != isOccluded) {
1254 mOccluded = isOccluded;
Kevin Chyn2fefd462017-04-28 12:18:19 -07001255 mUpdateMonitor.setKeyguardOccluded(isOccluded);
Selim Cinek2f6272e2017-03-15 16:19:10 -07001256 mStatusBarKeyguardViewManager.setOccluded(isOccluded, animate
1257 && mDeviceInteractive);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001258 adjustStatusBarLocked();
Mike Lockwood9200a392009-11-17 20:25:58 -05001259 }
Mike Lockwood09a40402009-11-08 00:33:23 -05001260 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001261 Trace.endSection();
Mike Lockwood09a40402009-11-08 00:33:23 -05001262 }
1263
1264 /**
Mike Lockwood28569302010-01-28 11:54:40 -05001265 * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout.
1266 * This must be safe to call from any thread and with any window manager locks held.
1267 */
Adam Cohenf7522022012-10-03 20:03:18 -07001268 public void doKeyguardTimeout(Bundle options) {
Mike Lockwood28569302010-01-28 11:54:40 -05001269 mHandler.removeMessages(KEYGUARD_TIMEOUT);
Adam Cohenf7522022012-10-03 20:03:18 -07001270 Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options);
Mike Lockwood28569302010-01-28 11:54:40 -05001271 mHandler.sendMessage(msg);
1272 }
1273
1274 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001275 * Given the state of the keyguard, is the input restricted?
1276 * Input is restricted when the keyguard is showing, or when the keyguard
1277 * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet.
1278 */
1279 public boolean isInputRestricted() {
Adrian Roos9f33d6c2015-06-15 15:58:35 -07001280 return mShowing || mNeedToReshowWhenReenabled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001281 }
1282
Jim Millerab954542014-10-10 18:21:49 -07001283 private void updateInputRestricted() {
1284 synchronized (this) {
1285 updateInputRestrictedLocked();
1286 }
1287 }
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001288
Jim Millerab954542014-10-10 18:21:49 -07001289 private void updateInputRestrictedLocked() {
1290 boolean inputRestricted = isInputRestricted();
1291 if (mInputRestricted != inputRestricted) {
1292 mInputRestricted = inputRestricted;
dooyoung.hwang328472e2015-05-21 16:09:43 +09001293 int size = mKeyguardStateCallbacks.size();
1294 for (int i = size - 1; i >= 0; i--) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001295 final IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001296 try {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001297 callback.onInputRestrictedStateChanged(inputRestricted);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001298 } catch (RemoteException e) {
1299 Slog.w(TAG, "Failed to call onDeviceProvisioned", e);
1300 if (e instanceof DeadObjectException) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001301 mKeyguardStateCallbacks.remove(callback);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001302 }
Jim Millerab954542014-10-10 18:21:49 -07001303 }
Jim Millerab954542014-10-10 18:21:49 -07001304 }
1305 }
1306 }
1307
Dianne Hackbornb446e972009-09-20 15:23:25 -07001308 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001309 * Enable the keyguard if the settings are appropriate.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001310 */
Adam Cohenf7522022012-10-03 20:03:18 -07001311 private void doKeyguardLocked(Bundle options) {
Adrian Roosca8a2162017-08-17 19:00:58 +02001312 if (KeyguardUpdateMonitor.CORE_APPS_ONLY) {
1313 // Don't show keyguard during half-booted cryptkeeper stage.
1314 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because booting to cryptkeeper");
1315 return;
1316 }
1317
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001318 // if another app is disabling us, don't show
1319 if (!mExternallyEnabled) {
1320 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled");
Karl Rosaenab100082009-03-24 22:35:17 -07001321
Adrian Roos1c8e3c02018-11-20 20:07:55 +01001322 mNeedToReshowWhenReenabled = true;
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001323 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001324 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001325
1326 // if the keyguard is already showing, don't bother
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001327 if (mStatusBarKeyguardViewManager.isShowing()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001328 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing");
Jorim Jaggi95e89ca2014-11-24 20:12:50 +01001329 resetStateLocked();
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001330 return;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001331 }
1332
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001333 // In split system user mode, we never unlock system user.
Amith Yamasanieb437d42016-04-29 09:31:25 -07001334 if (!mustNotUnlockCurrentUser()
Amith Yamasani27e025b2015-11-06 10:34:41 -08001335 || !mUpdateMonitor.isDeviceProvisioned()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001336
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001337 // if the setup wizard hasn't run yet, don't show
1338 final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", false);
1339 final boolean absent = SubscriptionManager.isValidSubscriptionId(
Adrian Roose92de952016-12-13 12:07:09 -08001340 mUpdateMonitor.getNextSubIdForState(ABSENT));
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001341 final boolean disabled = SubscriptionManager.isValidSubscriptionId(
1342 mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.PERM_DISABLED));
1343 final boolean lockedOrMissing = mUpdateMonitor.isSimPinSecure()
1344 || ((absent || disabled) && requireSim);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001345
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001346 if (!lockedOrMissing && shouldWaitForProvisioning()) {
1347 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned"
1348 + " and the sim is not locked or missing");
1349 return;
1350 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001351
Evan Rosky13a58a92016-07-27 15:51:09 -07001352 boolean forceShow = options != null && options.getBoolean(OPTION_FORCE_SHOW, false);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001353 if (mLockPatternUtils.isLockScreenDisabled(KeyguardUpdateMonitor.getCurrentUser())
Evan Rosky13a58a92016-07-27 15:51:09 -07001354 && !lockedOrMissing && !forceShow) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001355 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off");
1356 return;
1357 }
1358
1359 if (mLockPatternUtils.checkVoldPassword(KeyguardUpdateMonitor.getCurrentUser())) {
1360 if (DEBUG) Log.d(TAG, "Not showing lock screen since just decrypted");
1361 // Without this, settings is not enabled until the lock screen first appears
Lucas Dupinb3455e62019-07-11 11:47:13 +09001362 setShowingLocked(false);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001363 hideLocked();
1364 return;
1365 }
Paul Lawrence945490c2014-03-27 16:37:28 +00001366 }
1367
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001368 if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");
Adam Cohenf7522022012-10-03 20:03:18 -07001369 showLocked(options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001370 }
1371
Clara Bayarri56878a92015-10-29 15:43:55 +00001372 private void lockProfile(int userId) {
1373 mTrustManager.setDeviceLockedForUser(userId, true);
1374 }
1375
Jim Millerb256e4e22014-10-31 17:27:13 -07001376 private boolean shouldWaitForProvisioning() {
1377 return !mUpdateMonitor.isDeviceProvisioned() && !isSecure();
1378 }
1379
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001380 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001381 * Dismiss the keyguard through the security layers.
Jorim Jaggi241ae102016-11-02 21:57:33 -07001382 * @param callback Callback to be informed about the result
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001383 * @param message Message that should be displayed on the bouncer.
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001384 */
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001385 private void handleDismiss(IKeyguardDismissCallback callback, CharSequence message) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001386 if (mShowing) {
1387 if (callback != null) {
1388 mDismissCallbackRegistry.addCallback(callback);
1389 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001390 mCustomMessage = message;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001391 mStatusBarKeyguardViewManager.dismissAndCollapse();
Jorim Jaggi241ae102016-11-02 21:57:33 -07001392 } else if (callback != null) {
1393 new DismissCallbackWrapper(callback).notifyDismissError();
Jim Miller87d03662012-11-05 20:28:09 -08001394 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001395 }
1396
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001397 public void dismiss(IKeyguardDismissCallback callback, CharSequence message) {
1398 mHandler.obtainMessage(DISMISS, new DismissMessage(callback, message)).sendToTarget();
Jim Miller60013792013-10-03 18:31:34 -07001399 }
1400
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001401 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001402 * Send message to keyguard telling it to reset its state.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001403 * @see #handleReset
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001404 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001405 private void resetStateLocked() {
Jim Miller4894a012013-04-03 15:23:55 -07001406 if (DEBUG) Log.e(TAG, "resetStateLocked");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001407 Message msg = mHandler.obtainMessage(RESET);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001408 mHandler.sendMessage(msg);
1409 }
1410
1411 /**
1412 * Send message to keyguard telling it to verify unlock
1413 * @see #handleVerifyUnlock()
1414 */
1415 private void verifyUnlockLocked() {
1416 if (DEBUG) Log.d(TAG, "verifyUnlockLocked");
1417 mHandler.sendEmptyMessage(VERIFY_UNLOCK);
1418 }
1419
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001420 private void notifyStartedGoingToSleep() {
1421 if (DEBUG) Log.d(TAG, "notifyStartedGoingToSleep");
1422 mHandler.sendEmptyMessage(NOTIFY_STARTED_GOING_TO_SLEEP);
1423 }
1424
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001425 private void notifyFinishedGoingToSleep() {
1426 if (DEBUG) Log.d(TAG, "notifyFinishedGoingToSleep");
1427 mHandler.sendEmptyMessage(NOTIFY_FINISHED_GOING_TO_SLEEP);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001428 }
1429
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001430 private void notifyStartedWakingUp() {
1431 if (DEBUG) Log.d(TAG, "notifyStartedWakingUp");
1432 mHandler.sendEmptyMessage(NOTIFY_STARTED_WAKING_UP);
1433 }
1434
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001435 private void notifyScreenOn(IKeyguardDrawnCallback callback) {
1436 if (DEBUG) Log.d(TAG, "notifyScreenOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001437 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNING_ON, callback);
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001438 mHandler.sendMessage(msg);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001439 }
1440
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001441 private void notifyScreenTurnedOn() {
1442 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOn");
1443 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_ON);
1444 mHandler.sendMessage(msg);
1445 }
1446
1447 private void notifyScreenTurnedOff() {
1448 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOff");
1449 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_OFF);
1450 mHandler.sendMessage(msg);
1451 }
1452
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001453 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001454 * Send message to keyguard telling it to show itself
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001455 * @see #handleShow
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001456 */
Adam Cohenf7522022012-10-03 20:03:18 -07001457 private void showLocked(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001458 Trace.beginSection("KeyguardViewMediator#showLocked aqcuiring mShowKeyguardWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001459 if (DEBUG) Log.d(TAG, "showLocked");
Mike Lockwood674d3e42009-10-06 09:28:54 -04001460 // ensure we stay awake until we are finished displaying the keyguard
1461 mShowKeyguardWakeLock.acquire();
Adam Cohenf7522022012-10-03 20:03:18 -07001462 Message msg = mHandler.obtainMessage(SHOW, options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001463 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001464 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001465 }
1466
1467 /**
1468 * Send message to keyguard telling it to hide itself
Jim Miller9c20d0e2010-01-20 15:00:23 -08001469 * @see #handleHide()
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001470 */
1471 private void hideLocked() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001472 Trace.beginSection("KeyguardViewMediator#hideLocked");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001473 if (DEBUG) Log.d(TAG, "hideLocked");
1474 Message msg = mHandler.obtainMessage(HIDE);
1475 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001476 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001477 }
1478
Dianne Hackbornb446e972009-09-20 15:23:25 -07001479 public boolean isSecure() {
Evan Rosky13a58a92016-07-27 15:51:09 -07001480 return isSecure(KeyguardUpdateMonitor.getCurrentUser());
1481 }
1482
1483 public boolean isSecure(int userId) {
1484 return mLockPatternUtils.isSecure(userId)
Dave Mankoffe2294692019-08-14 11:53:13 -04001485 || mUpdateMonitor.isSimPinSecure();
Dianne Hackbornb446e972009-09-20 15:23:25 -07001486 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001487
Evan Rosky18396452016-07-27 15:19:37 -07001488 public void setSwitchingUser(boolean switching) {
Dave Mankoffe2294692019-08-14 11:53:13 -04001489 mUpdateMonitor.setSwitchingUser(switching);
Evan Rosky18396452016-07-27 15:19:37 -07001490 }
1491
Craig Mautnerf1b67412012-09-19 13:18:29 -07001492 /**
1493 * Update the newUserId. Call while holding WindowManagerService lock.
Jim Milleree82f8f2012-10-01 16:26:18 -07001494 * NOTE: Should only be called by KeyguardViewMediator in response to the user id changing.
1495 *
Craig Mautnerf1b67412012-09-19 13:18:29 -07001496 * @param newUserId The id of the incoming user.
1497 */
1498 public void setCurrentUser(int newUserId) {
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001499 KeyguardUpdateMonitor.setCurrentUser(newUserId);
Adrian Roosd88eb262016-08-04 14:50:48 -07001500 synchronized (this) {
1501 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(newUserId));
1502 }
Craig Mautnerf1b67412012-09-19 13:18:29 -07001503 }
1504
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001505 /**
1506 * This broadcast receiver should be registered with the SystemUI permission.
1507 */
1508 private final BroadcastReceiver mDelayedLockBroadcastReceiver = new BroadcastReceiver() {
Amith Yamasani52c489c2012-03-28 11:42:42 -07001509 @Override
1510 public void onReceive(Context context, Intent intent) {
Jim Millerbbf1a742012-07-17 18:30:30 -07001511 if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
1512 final int sequence = intent.getIntExtra("seq", 0);
Jim Millerf3447352011-08-07 14:00:09 -07001513 if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = "
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001514 + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001515 synchronized (KeyguardViewMediator.this) {
Jim Miller2967f482016-01-07 15:05:32 -08001516 if (mDelayedShowingSequence == sequence) {
1517 doKeyguardLocked(null);
1518 }
Clara Bayarri56878a92015-10-29 15:43:55 +00001519 }
1520 } else if (DELAYED_LOCK_PROFILE_ACTION.equals(intent.getAction())) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001521 final int sequence = intent.getIntExtra("seq", 0);
Clara Bayarri56878a92015-10-29 15:43:55 +00001522 int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, 0);
1523 if (userId != 0) {
1524 synchronized (KeyguardViewMediator.this) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001525 if (mDelayedProfileShowingSequence == sequence) {
1526 lockProfile(userId);
1527 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001528 }
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001529 }
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001530 }
1531 }
1532 };
1533
1534 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1535 @Override
1536 public void onReceive(Context context, Intent intent) {
1537 if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
Adrian Roos1f8025a2016-12-27 10:12:13 -08001538 synchronized (KeyguardViewMediator.this){
1539 mShuttingDown = true;
1540 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001541 }
1542 }
1543 };
1544
Jorim Jaggi241ae102016-11-02 21:57:33 -07001545 public void keyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001546 Trace.beginSection("KeyguardViewMediator#keyguardDone");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001547 if (DEBUG) Log.d(TAG, "keyguardDone()");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001548 userActivity();
Jim Miller60013792013-10-03 18:31:34 -07001549 EventLog.writeEvent(70000, 2);
Jorim Jaggi241ae102016-11-02 21:57:33 -07001550 Message msg = mHandler.obtainMessage(KEYGUARD_DONE);
Jim Miller60013792013-10-03 18:31:34 -07001551 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001552 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001553 }
1554
1555 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001556 * This handler will be associated with the policy thread, which will also
1557 * be the UI thread of the keyguard. Since the apis of the policy, and therefore
1558 * this class, can be called by other threads, any action that directly
1559 * interacts with the keyguard ui should be posted to this handler, rather
1560 * than called directly.
1561 */
Jim Millerdcb3d842012-08-23 19:18:12 -07001562 private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001563 @Override
Wink Saville37c124c2009-04-02 01:37:02 -07001564 public void handleMessage(Message msg) {
1565 switch (msg.what) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001566 case SHOW:
Adam Cohenf7522022012-10-03 20:03:18 -07001567 handleShow((Bundle) msg.obj);
Jim Miller60013792013-10-03 18:31:34 -07001568 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001569 case HIDE:
1570 handleHide();
Jim Miller60013792013-10-03 18:31:34 -07001571 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001572 case RESET:
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001573 handleReset();
Jim Miller60013792013-10-03 18:31:34 -07001574 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001575 case VERIFY_UNLOCK:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001576 Trace.beginSection("KeyguardViewMediator#handleMessage VERIFY_UNLOCK");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001577 handleVerifyUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001578 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001579 break;
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001580 case NOTIFY_STARTED_GOING_TO_SLEEP:
1581 handleNotifyStartedGoingToSleep();
1582 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001583 case NOTIFY_FINISHED_GOING_TO_SLEEP:
1584 handleNotifyFinishedGoingToSleep();
Jim Miller60013792013-10-03 18:31:34 -07001585 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001586 case NOTIFY_SCREEN_TURNING_ON:
Curtis Belmonte5cece532019-10-15 09:44:28 -07001587 Trace.beginSection(
1588 "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:
Curtis Belmonte5cece532019-10-15 09:44:28 -07001593 Trace.beginSection(
1594 "KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNED_ON");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001595 handleNotifyScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001596 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001597 break;
1598 case NOTIFY_SCREEN_TURNED_OFF:
1599 handleNotifyScreenTurnedOff();
1600 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001601 case NOTIFY_STARTED_WAKING_UP:
Curtis Belmonte5cece532019-10-15 09:44:28 -07001602 Trace.beginSection(
1603 "KeyguardViewMediator#handleMessage NOTIFY_STARTED_WAKING_UP");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001604 handleNotifyStartedWakingUp();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001605 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001606 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001607 case KEYGUARD_DONE:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001608 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001609 handleKeyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001610 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001611 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001612 case KEYGUARD_DONE_DRAWING:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001613 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_DRAWING");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001614 handleKeyguardDoneDrawing();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001615 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001616 break;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001617 case SET_OCCLUDED:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001618 Trace.beginSection("KeyguardViewMediator#handleMessage SET_OCCLUDED");
Jorim Jaggi6626f542016-08-22 13:08:44 -07001619 handleSetOccluded(msg.arg1 != 0, msg.arg2 != 0);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001620 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001621 break;
Mike Lockwood28569302010-01-28 11:54:40 -05001622 case KEYGUARD_TIMEOUT:
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001623 synchronized (KeyguardViewMediator.this) {
Adam Cohenf7522022012-10-03 20:03:18 -07001624 doKeyguardLocked((Bundle) msg.obj);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001625 }
1626 break;
Jim Miller60013792013-10-03 18:31:34 -07001627 case DISMISS:
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001628 final DismissMessage message = (DismissMessage) msg.obj;
1629 handleDismiss(message.getCallback(), message.getMessage());
Jim Miller60013792013-10-03 18:31:34 -07001630 break;
Jorim Jaggi0d674622014-05-21 01:34:15 +02001631 case START_KEYGUARD_EXIT_ANIM:
Curtis Belmonte5cece532019-10-15 09:44:28 -07001632 Trace.beginSection(
1633 "KeyguardViewMediator#handleMessage START_KEYGUARD_EXIT_ANIM");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001634 StartKeyguardExitAnimParams params = (StartKeyguardExitAnimParams) msg.obj;
1635 handleStartKeyguardExitAnimation(params.startTime, params.fadeoutDuration);
Dave Mankoffaa8b7ae2019-09-04 18:03:21 -04001636 mFalsingManager.onSucccessfulUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001637 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001638 break;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001639 case KEYGUARD_DONE_PENDING_TIMEOUT:
Curtis Belmonte5cece532019-10-15 09:44:28 -07001640 Trace.beginSection("KeyguardViewMediator#handleMessage"
1641 + " KEYGUARD_DONE_PENDING_TIMEOUT");
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001642 Log.w(TAG, "Timeout while waiting for activity drawn!");
Nick Desaulniers1d396752016-07-25 15:05:33 -07001643 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001644 break;
Adrian Roos30a2ae62018-04-25 19:09:50 +02001645 case SYSTEM_READY:
1646 handleSystemReady();
1647 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001648 }
1649 }
1650 };
1651
Jorim Jaggi241ae102016-11-02 21:57:33 -07001652 private void tryKeyguardDone() {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001653 if (!mKeyguardDonePending && mHideAnimationRun && !mHideAnimationRunning) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001654 handleKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001655 } else if (!mHideAnimationRun) {
1656 mHideAnimationRun = true;
1657 mHideAnimationRunning = true;
1658 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
1659 }
1660 }
1661
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001662 /**
1663 * @see #keyguardDone
1664 * @see #KEYGUARD_DONE
1665 */
Jorim Jaggi241ae102016-11-02 21:57:33 -07001666 private void handleKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001667 Trace.beginSection("KeyguardViewMediator#handleKeyguardDone");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001668 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001669 mUiOffloadThread.submit(() -> {
1670 if (mLockPatternUtils.isSecure(currentUser)) {
1671 mLockPatternUtils.getDevicePolicyManager().reportKeyguardDismissed(currentUser);
1672 }
1673 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001674 if (DEBUG) Log.d(TAG, "handleKeyguardDone");
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001675 synchronized (this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001676 resetKeyguardDonePendingLocked();
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001677 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001678
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001679 mUpdateMonitor.clearBiometricRecognized();
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -07001680
Jorim Jaggi4474f542015-07-09 16:08:02 -07001681 if (mGoingToSleep) {
1682 Log.i(TAG, "Device is going to sleep, aborting keyguardDone");
1683 return;
1684 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001685 if (mExitSecureCallback != null) {
1686 try {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001687 mExitSecureCallback.onKeyguardExitResult(true /* authenciated */);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001688 } catch (RemoteException e) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001689 Slog.w(TAG, "Failed to call onKeyguardExitResult()", e);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001690 }
1691
1692 mExitSecureCallback = null;
1693
Jorim Jaggi241ae102016-11-02 21:57:33 -07001694 // after succesfully exiting securely, no need to reshow
1695 // the keyguard when they've released the lock
1696 mExternallyEnabled = true;
1697 mNeedToReshowWhenReenabled = false;
1698 updateInputRestricted();
Jim Millere51cf7ae2013-06-25 18:31:56 -07001699 }
1700
1701 handleHide();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001702 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -07001703 }
1704
1705 private void sendUserPresentBroadcast() {
Jason Monkcf5a9532014-09-17 16:22:19 -04001706 synchronized (this) {
1707 if (mBootCompleted) {
Adrian Roos4ab7e592016-04-13 15:38:13 -07001708 int currentUserId = KeyguardUpdateMonitor.getCurrentUser();
1709 final UserHandle currentUser = new UserHandle(currentUserId);
Benjamin Franz4b9f8ed2014-12-01 16:51:48 +00001710 final UserManager um = (UserManager) mContext.getSystemService(
1711 Context.USER_SERVICE);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001712 mUiOffloadThread.submit(() -> {
1713 for (int profileId : um.getProfileIdsWithDisabled(currentUser.getIdentifier())) {
1714 mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, UserHandle.of(profileId));
1715 }
1716 getLockPatternUtils().userPresent(currentUserId);
1717 });
Jason Monkcf5a9532014-09-17 16:22:19 -04001718 } else {
1719 mBootSendUserPresent = true;
1720 }
1721 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001722 }
1723
1724 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001725 * @see #keyguardDone
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001726 * @see #KEYGUARD_DONE_DRAWING
1727 */
1728 private void handleKeyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001729 Trace.beginSection("KeyguardViewMediator#handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001730 synchronized(this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001731 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001732 if (mWaitingUntilKeyguardVisible) {
1733 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible");
1734 mWaitingUntilKeyguardVisible = false;
1735 notifyAll();
1736
1737 // there will usually be two of these sent, one as a timeout, and one
1738 // as a result of the callback, so remove any remaining messages from
1739 // the queue
1740 mHandler.removeMessages(KEYGUARD_DONE_DRAWING);
1741 }
1742 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001743 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001744 }
1745
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001746 private void playSounds(boolean locked) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001747 playSound(locked ? mLockSoundId : mUnlockSoundId);
1748 }
1749
1750 private void playSound(int soundId) {
1751 if (soundId == 0) return;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001752 final ContentResolver cr = mContext.getContentResolver();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001753 if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001754
Marco Nelissend5545bd2011-09-29 12:49:17 -07001755 mLockSounds.stop(mLockSoundStreamId);
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001756 // Init mAudioManager
1757 if (mAudioManager == null) {
1758 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
1759 if (mAudioManager == null) return;
John Spurlockee5ad722015-03-03 16:17:21 -05001760 mUiSoundsStreamType = mAudioManager.getUiSoundsStreamType();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001761 }
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001762
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001763 mUiOffloadThread.submit(() -> {
1764 // If the stream is muted, don't play the sound
1765 if (mAudioManager.isStreamMute(mUiSoundsStreamType)) return;
1766
1767 int id = mLockSounds.play(soundId,
1768 mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/);
1769 synchronized (this) {
1770 mLockSoundStreamId = id;
1771 }
1772 });
1773
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001774 }
Jim Miller2a98a4c2010-11-19 18:49:26 -08001775 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001776
Adrian Roos49e057d2014-08-13 17:14:51 +02001777 private void playTrustedSound() {
Adrian Roos49e057d2014-08-13 17:14:51 +02001778 playSound(mTrustedSoundId);
1779 }
1780
wilsonshih177261f2019-02-22 12:02:18 +08001781 private void updateActivityLockScreenState(boolean showing, boolean aodShowing) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001782 mUiOffloadThread.submit(() -> {
Lucas Dupinb3455e62019-07-11 11:47:13 +09001783 if (DEBUG) {
1784 Log.d(TAG, "updateActivityLockScreenState(" + showing + ", " + aodShowing + ")");
1785 }
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001786 try {
wilsonshih177261f2019-02-22 12:02:18 +08001787 ActivityTaskManager.getService().setLockScreenShown(showing, aodShowing);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001788 } catch (RemoteException e) {
1789 }
1790 });
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001791 }
1792
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001793 /**
1794 * Handle message sent by {@link #showLocked}.
1795 * @see #SHOW
1796 */
Adam Cohenf7522022012-10-03 20:03:18 -07001797 private void handleShow(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001798 Trace.beginSection("KeyguardViewMediator#handleShow");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001799 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
1800 if (mLockPatternUtils.isSecure(currentUser)) {
1801 mLockPatternUtils.getDevicePolicyManager().reportKeyguardSecured(currentUser);
Michal Karpinski779aad92016-01-20 11:56:22 +00001802 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001803 synchronized (KeyguardViewMediator.this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001804 if (!mSystemReady) {
1805 if (DEBUG) Log.d(TAG, "ignoring handleShow because system is not ready.");
1806 return;
1807 } else {
1808 if (DEBUG) Log.d(TAG, "handleShow");
1809 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001810
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001811 mHiding = false;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001812 mWakeAndUnlocking = false;
Lucas Dupinb3455e62019-07-11 11:47:13 +09001813 setShowingLocked(true);
1814 mStatusBarKeyguardViewManager.show(options);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001815 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001816 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001817 adjustStatusBarLocked();
Jeff Brown3dc524b2012-09-30 19:49:11 -07001818 userActivity();
Curtis Belmontec6061d52019-10-18 16:13:10 -07001819 mUpdateMonitor.setKeyguardGoingAway(false);
1820 mStatusBarWindowController.setKeyguardGoingAway(false);
Mike Lockwood674d3e42009-10-06 09:28:54 -04001821 mShowKeyguardWakeLock.release();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001822 }
Jim Miller31921482013-11-06 20:43:55 -08001823 mKeyguardDisplayManager.show();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001824 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001825 }
1826
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001827 private final Runnable mKeyguardGoingAwayRunnable = new Runnable() {
1828 @Override
1829 public void run() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001830 Trace.beginSection("KeyguardViewMediator.mKeyGuardGoingAwayRunnable");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001831 if (DEBUG) Log.d(TAG, "keyguardGoingAway");
wilsonshih2bc846c2019-05-02 14:35:21 +08001832 mStatusBarKeyguardViewManager.keyguardGoingAway();
Jorim Jaggi33ae80e2015-02-04 16:37:11 +01001833
wilsonshih2bc846c2019-05-02 14:35:21 +08001834 int flags = 0;
1835 if (mStatusBarKeyguardViewManager.shouldDisableWindowAnimationsForUnlock()
1836 || (mWakeAndUnlocking && !mPulsing)) {
1837 flags |= WindowManagerPolicyConstants
1838 .KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001839 }
wilsonshih2bc846c2019-05-02 14:35:21 +08001840 if (mStatusBarKeyguardViewManager.isGoingToNotificationShade()
1841 || (mWakeAndUnlocking && mPulsing)) {
1842 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE;
1843 }
1844 if (mStatusBarKeyguardViewManager.isUnlockWithWallpaper()) {
1845 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER;
1846 }
Issei Suzuki5609ccb2019-06-13 15:04:08 +02001847 if (mStatusBarKeyguardViewManager.shouldSubtleWindowAnimationsForUnlock()) {
1848 flags |= WindowManagerPolicyConstants
1849 .KEYGUARD_GOING_AWAY_FLAG_SUBTLE_WINDOW_ANIMATIONS;
1850 }
wilsonshih2bc846c2019-05-02 14:35:21 +08001851
Curtis Belmontec6061d52019-10-18 16:13:10 -07001852 mUpdateMonitor.setKeyguardGoingAway(true);
1853 mStatusBarWindowController.setKeyguardGoingAway(true);
wilsonshih2bc846c2019-05-02 14:35:21 +08001854
1855 // Don't actually hide the Keyguard at the moment, wait for window
1856 // manager until it tells us it's safe to do so with
1857 // startKeyguardExitAnimation.
1858 // Posting to mUiOffloadThread to ensure that calls to ActivityTaskManager will be in
1859 // order.
1860 final int keyguardFlag = flags;
1861 mUiOffloadThread.submit(() -> {
1862 try {
1863 ActivityTaskManager.getService().keyguardGoingAway(keyguardFlag);
1864 } catch (RemoteException e) {
1865 Log.e(TAG, "Error while calling WindowManager", e);
1866 }
1867 });
Nick Desaulniers1d396752016-07-25 15:05:33 -07001868 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001869 }
1870 };
1871
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001872 private final Runnable mHideAnimationFinishedRunnable = () -> {
1873 mHideAnimationRunning = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -07001874 tryKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001875 };
1876
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001877 /**
1878 * Handle message sent by {@link #hideLocked()}
1879 * @see #HIDE
1880 */
1881 private void handleHide() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001882 Trace.beginSection("KeyguardViewMediator#handleHide");
Lucas Dupin1c327432019-01-03 13:37:53 -08001883
1884 // It's possible that the device was unlocked in a dream state. It's time to wake up.
1885 if (mAodShowing) {
Michael Wrighte3001042019-02-05 00:13:14 +00001886 PowerManager pm = mContext.getSystemService(PowerManager.class);
1887 pm.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE,
1888 "com.android.systemui:BOUNCER_DOZING");
Lucas Dupin1c327432019-01-03 13:37:53 -08001889 }
1890
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001891 synchronized (KeyguardViewMediator.this) {
1892 if (DEBUG) Log.d(TAG, "handleHide");
Jorim Jaggib9d60792014-06-03 22:34:22 +02001893
Amith Yamasanieb437d42016-04-29 09:31:25 -07001894 if (mustNotUnlockCurrentUser()) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001895 // In split system user mode, we never unlock system user. The end user has to
1896 // switch to another user.
1897 // TODO: We should stop it early by disabling the swipe up flow. Right now swipe up
1898 // still completes and makes the screen blank.
1899 if (DEBUG) Log.d(TAG, "Split system user, quit unlocking.");
1900 return;
1901 }
Jorim Jaggi76a16232014-08-08 17:00:47 +02001902 mHiding = true;
Jorim Jaggib9d60792014-06-03 22:34:22 +02001903
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001904 if (mShowing && !mOccluded) {
1905 mKeyguardGoingAwayRunnable.run();
1906 } else {
Jorim Jaggi76a16232014-08-08 17:00:47 +02001907 handleStartKeyguardExitAnimation(
1908 SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(),
1909 mHideAnimation.getDuration());
Jorim Jaggi0d674622014-05-21 01:34:15 +02001910 }
1911 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001912 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001913 }
1914
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001915 private void handleStartKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001916 Trace.beginSection("KeyguardViewMediator#handleStartKeyguardExitAnimation");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001917 if (DEBUG) Log.d(TAG, "handleStartKeyguardExitAnimation startTime=" + startTime
1918 + " fadeoutDuration=" + fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02001919 synchronized (KeyguardViewMediator.this) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001920
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001921 if (!mHiding) {
Adrian Roos6ec76b72018-04-25 14:01:11 +02001922 // Tell ActivityManager that we canceled the keyguardExitAnimation.
Lucas Dupinb3455e62019-07-11 11:47:13 +09001923 setShowingLocked(mShowing, true /* force */);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001924 return;
1925 }
1926 mHiding = false;
1927
Jorim Jaggib774e552015-08-24 14:52:45 -07001928 if (mWakeAndUnlocking && mDrawnCallback != null) {
1929
1930 // Hack level over 9000: To speed up wake-and-unlock sequence, force it to report
1931 // the next draw from here so we don't have to wait for window manager to signal
1932 // this to our ViewRootImpl.
1933 mStatusBarKeyguardViewManager.getViewRootImpl().setReportNextDraw();
1934 notifyDrawn(mDrawnCallback);
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001935 mDrawnCallback = null;
Jorim Jaggib774e552015-08-24 14:52:45 -07001936 }
1937
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001938 // only play "unlock" noises if not on a call (since the incall UI
1939 // disables the keyguard)
1940 if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) {
1941 playSounds(false);
1942 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001943
Lucas Dupinb3455e62019-07-11 11:47:13 +09001944 setShowingLocked(false);
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001945 mWakeAndUnlocking = false;
Jorim Jaggi5277dea2017-05-18 02:05:29 +02001946 mDismissCallbackRegistry.notifyDismissSucceeded();
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001947 mStatusBarKeyguardViewManager.hide(startTime, fadeoutDuration);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001948 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001949 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001950 adjustStatusBarLocked();
Jim Miller705004b2014-09-04 16:51:20 -07001951 sendUserPresentBroadcast();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001952 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001953 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001954 }
1955
Mike Lockwood5f892c12009-11-19 23:39:13 -05001956 private void adjustStatusBarLocked() {
Matthew Ng66f0b702017-12-08 12:58:42 -08001957 adjustStatusBarLocked(false /* forceHideHomeRecentsButtons */);
1958 }
1959
1960 private void adjustStatusBarLocked(boolean forceHideHomeRecentsButtons) {
Mike Lockwood5f892c12009-11-19 23:39:13 -05001961 if (mStatusBarManager == null) {
1962 mStatusBarManager = (StatusBarManager)
1963 mContext.getSystemService(Context.STATUS_BAR_SERVICE);
1964 }
Matthew Ng78ba6e22018-09-24 16:55:36 -07001965
Mike Lockwood5f892c12009-11-19 23:39:13 -05001966 if (mStatusBarManager == null) {
1967 Log.w(TAG, "Could not get status bar manager");
1968 } else {
Daniel Sandlerdba93562011-10-06 16:39:58 -04001969 // Disable aspects of the system/status/navigation bars that must not be re-enabled by
1970 // windows that appear on top, ever
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001971 int flags = StatusBarManager.DISABLE_NONE;
Matthew Ng66f0b702017-12-08 12:58:42 -08001972 if (forceHideHomeRecentsButtons || isShowingAndNotOccluded()) {
1973 flags |= StatusBarManager.DISABLE_HOME | StatusBarManager.DISABLE_RECENT;
Jorim Jaggia005f1b2014-04-16 19:06:10 +02001974 }
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001975
1976 if (DEBUG) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001977 Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mOccluded=" + mOccluded
Matthew Ng66f0b702017-12-08 12:58:42 -08001978 + " isSecure=" + isSecure() + " force=" + forceHideHomeRecentsButtons
1979 + " --> flags=0x" + Integer.toHexString(flags));
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001980 }
1981
Jorim Jaggie3e0b062017-06-12 12:18:41 -07001982 mStatusBarManager.disable(flags);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001983 }
1984 }
1985
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001986 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001987 * Handle message sent by {@link #resetStateLocked}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001988 * @see #RESET
1989 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001990 private void handleReset() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001991 synchronized (KeyguardViewMediator.this) {
1992 if (DEBUG) Log.d(TAG, "handleReset");
Jorim Jaggife762342016-10-13 14:33:27 +02001993 mStatusBarKeyguardViewManager.reset(true /* hideBouncerWhenShowing */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001994 }
1995 }
1996
1997 /**
1998 * Handle message sent by {@link #verifyUnlock}
Craig Mautner904732c2012-10-17 15:20:24 -07001999 * @see #VERIFY_UNLOCK
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002000 */
2001 private void handleVerifyUnlock() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002002 Trace.beginSection("KeyguardViewMediator#handleVerifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002003 synchronized (KeyguardViewMediator.this) {
2004 if (DEBUG) Log.d(TAG, "handleVerifyUnlock");
Lucas Dupinb3455e62019-07-11 11:47:13 +09002005 setShowingLocked(true);
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07002006 mStatusBarKeyguardViewManager.dismissAndCollapse();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002007 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002008 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002009 }
2010
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07002011 private void handleNotifyStartedGoingToSleep() {
2012 synchronized (KeyguardViewMediator.this) {
2013 if (DEBUG) Log.d(TAG, "handleNotifyStartedGoingToSleep");
2014 mStatusBarKeyguardViewManager.onStartedGoingToSleep();
2015 }
2016 }
2017
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002018 /**
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002019 * Handle message sent by {@link #notifyFinishedGoingToSleep()}
2020 * @see #NOTIFY_FINISHED_GOING_TO_SLEEP
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002021 */
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002022 private void handleNotifyFinishedGoingToSleep() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002023 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002024 if (DEBUG) Log.d(TAG, "handleNotifyFinishedGoingToSleep");
2025 mStatusBarKeyguardViewManager.onFinishedGoingToSleep();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002026 }
2027 }
2028
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002029 private void handleNotifyStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002030 Trace.beginSection("KeyguardViewMediator#handleMotifyStartedWakingUp");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002031 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002032 if (DEBUG) Log.d(TAG, "handleNotifyWakingUp");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002033 mStatusBarKeyguardViewManager.onStartedWakingUp();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002034 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002035 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002036 }
2037
2038 private void handleNotifyScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002039 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurningOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002040 synchronized (KeyguardViewMediator.this) {
2041 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurningOn");
Jorim Jaggi93739112015-08-13 15:53:14 -07002042 mStatusBarKeyguardViewManager.onScreenTurningOn();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002043 if (callback != null) {
2044 if (mWakeAndUnlocking) {
2045 mDrawnCallback = callback;
2046 } else {
2047 notifyDrawn(callback);
2048 }
2049 }
2050 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002051 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002052 }
2053
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002054 private void handleNotifyScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002055 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurnedOn");
Jorim Jaggic3fe2042016-10-07 18:52:48 +02002056 if (LatencyTracker.isEnabled(mContext)) {
2057 LatencyTracker.getInstance(mContext).onActionEnd(LatencyTracker.ACTION_TURN_ON_SCREEN);
2058 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002059 synchronized (this) {
2060 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOn");
2061 mStatusBarKeyguardViewManager.onScreenTurnedOn();
2062 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002063 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002064 }
2065
2066 private void handleNotifyScreenTurnedOff() {
2067 synchronized (this) {
2068 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOff");
Jorim Jaggie93e6f92016-08-04 13:55:39 +02002069 mDrawnCallback = null;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002070 }
2071 }
2072
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002073 private void notifyDrawn(final IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002074 Trace.beginSection("KeyguardViewMediator#notifyDrawn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002075 try {
2076 callback.onDrawn();
2077 } catch (RemoteException e) {
2078 Slog.w(TAG, "Exception calling onDrawn():", e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002079 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002080 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002081 }
Jeff Sharkey054340d2011-09-01 22:28:03 -07002082
Jorim Jaggif8d77da2014-11-11 16:59:12 +01002083 private void resetKeyguardDonePendingLocked() {
2084 mKeyguardDonePending = false;
2085 mHandler.removeMessages(KEYGUARD_DONE_PENDING_TIMEOUT);
2086 }
2087
Jim Miller2967f482016-01-07 15:05:32 -08002088 @Override
Jim Millere5f910a2013-10-16 18:15:46 -07002089 public void onBootCompleted() {
2090 mUpdateMonitor.dispatchBootCompleted();
Jason Monkcf5a9532014-09-17 16:22:19 -04002091 synchronized (this) {
2092 mBootCompleted = true;
2093 if (mBootSendUserPresent) {
2094 sendUserPresentBroadcast();
2095 }
2096 }
Jim Millere5f910a2013-10-16 18:15:46 -07002097 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002098
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002099 public void onWakeAndUnlocking() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002100 Trace.beginSection("KeyguardViewMediator#onWakeAndUnlocking");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002101 mWakeAndUnlocking = true;
Jorim Jaggi241ae102016-11-02 21:57:33 -07002102 keyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07002103 Trace.endSection();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002104 }
2105
Jason Monk2a6ea9c2017-01-26 11:14:51 -05002106 public StatusBarKeyguardViewManager registerStatusBar(StatusBar statusBar,
Lucas Dupinbc9aac12018-03-04 20:18:15 -08002107 ViewGroup container, NotificationPanelView panelView,
Selim Cinek06c12d62019-07-01 19:44:18 -07002108 BiometricUnlockController biometricUnlockController, ViewGroup lockIconContainer,
Dave Mankoffaa8b7ae2019-09-04 18:03:21 -04002109 View notificationContainer, KeyguardBypassController bypassController) {
Lucas Dupinbc9aac12018-03-04 20:18:15 -08002110 mStatusBarKeyguardViewManager.registerStatusBar(statusBar, container, panelView,
Selim Cinek06c12d62019-07-01 19:44:18 -07002111 biometricUnlockController, mDismissCallbackRegistry, lockIconContainer,
Dave Mankoffaa8b7ae2019-09-04 18:03:21 -04002112 notificationContainer, bypassController, mFalsingManager);
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002113 return mStatusBarKeyguardViewManager;
2114 }
2115
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002116 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002117 Trace.beginSection("KeyguardViewMediator#startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002118 Message msg = mHandler.obtainMessage(START_KEYGUARD_EXIT_ANIM,
2119 new StartKeyguardExitAnimParams(startTime, fadeoutDuration));
Jorim Jaggi0d674622014-05-21 01:34:15 +02002120 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07002121 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02002122 }
2123
Andrew Zengb4045d32017-03-16 17:25:07 -07002124 public void onShortPowerPressedGoHome() {
2125 // do nothing
2126 }
2127
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002128 public ViewMediatorCallback getViewMediatorCallback() {
2129 return mViewMediatorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002130 }
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002131
Xiyuan Xia1b30f792016-01-06 08:50:30 -08002132 public LockPatternUtils getLockPatternUtils() {
2133 return mLockPatternUtils;
2134 }
2135
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002136 @Override
2137 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
2138 pw.print(" mSystemReady: "); pw.println(mSystemReady);
2139 pw.print(" mBootCompleted: "); pw.println(mBootCompleted);
2140 pw.print(" mBootSendUserPresent: "); pw.println(mBootSendUserPresent);
2141 pw.print(" mExternallyEnabled: "); pw.println(mExternallyEnabled);
Adrian Roos1f8025a2016-12-27 10:12:13 -08002142 pw.print(" mShuttingDown: "); pw.println(mShuttingDown);
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002143 pw.print(" mNeedToReshowWhenReenabled: "); pw.println(mNeedToReshowWhenReenabled);
2144 pw.print(" mShowing: "); pw.println(mShowing);
2145 pw.print(" mInputRestricted: "); pw.println(mInputRestricted);
2146 pw.print(" mOccluded: "); pw.println(mOccluded);
2147 pw.print(" mDelayedShowingSequence: "); pw.println(mDelayedShowingSequence);
2148 pw.print(" mExitSecureCallback: "); pw.println(mExitSecureCallback);
2149 pw.print(" mDeviceInteractive: "); pw.println(mDeviceInteractive);
2150 pw.print(" mGoingToSleep: "); pw.println(mGoingToSleep);
2151 pw.print(" mHiding: "); pw.println(mHiding);
Lucas Dupinb3455e62019-07-11 11:47:13 +09002152 pw.print(" mDozing: "); pw.println(mDozing);
2153 pw.print(" mAodShowing: "); pw.println(mAodShowing);
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002154 pw.print(" mWaitingUntilKeyguardVisible: "); pw.println(mWaitingUntilKeyguardVisible);
2155 pw.print(" mKeyguardDonePending: "); pw.println(mKeyguardDonePending);
2156 pw.print(" mHideAnimationRun: "); pw.println(mHideAnimationRun);
2157 pw.print(" mPendingReset: "); pw.println(mPendingReset);
2158 pw.print(" mPendingLock: "); pw.println(mPendingLock);
2159 pw.print(" mWakeAndUnlocking: "); pw.println(mWakeAndUnlocking);
2160 pw.print(" mDrawnCallback: "); pw.println(mDrawnCallback);
2161 }
2162
Lucas Dupin5a4f92c2018-07-02 13:15:23 -07002163 /**
Lucas Dupinb3455e62019-07-11 11:47:13 +09002164 * @param dozing true when AOD - or ambient mode - is showing.
Lucas Dupin5a4f92c2018-07-02 13:15:23 -07002165 */
Lucas Dupinb3455e62019-07-11 11:47:13 +09002166 public void setDozing(boolean dozing) {
2167 if (dozing == mDozing) {
2168 return;
2169 }
2170 mDozing = dozing;
2171 setShowingLocked(mShowing);
Lucas Dupin47a65c72018-02-15 14:16:18 -08002172 }
2173
Lucas Dupind35502f2018-06-27 13:35:52 -07002174 /**
2175 * @param pulsing true when device temporarily wakes up to display an incoming notification.
2176 */
2177 public void setPulsing(boolean pulsing) {
2178 mPulsing = pulsing;
2179 }
2180
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002181 private static class StartKeyguardExitAnimParams {
2182
2183 long startTime;
2184 long fadeoutDuration;
2185
2186 private StartKeyguardExitAnimParams(long startTime, long fadeoutDuration) {
2187 this.startTime = startTime;
2188 this.fadeoutDuration = fadeoutDuration;
2189 }
2190 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002191
Lucas Dupinb3455e62019-07-11 11:47:13 +09002192 private void setShowingLocked(boolean showing) {
2193 setShowingLocked(showing, false /* forceCallbacks */);
Jorim Jaggie8f321e2016-11-07 16:48:31 -08002194 }
2195
Lucas Dupinb3455e62019-07-11 11:47:13 +09002196 private void setShowingLocked(boolean showing, boolean forceCallbacks) {
2197 final boolean aodShowing = mDozing && !mWakeAndUnlocking;
Lucas Dupin47a65c72018-02-15 14:16:18 -08002198 final boolean notifyDefaultDisplayCallbacks = showing != mShowing
2199 || aodShowing != mAodShowing || forceCallbacks;
Lucas Dupinb3455e62019-07-11 11:47:13 +09002200 mShowing = showing;
2201 mAodShowing = aodShowing;
wilsonshih177261f2019-02-22 12:02:18 +08002202 if (notifyDefaultDisplayCallbacks) {
Lucas Dupinb3455e62019-07-11 11:47:13 +09002203 notifyDefaultDisplayCallbacks(showing);
wilsonshih177261f2019-02-22 12:02:18 +08002204 updateActivityLockScreenState(showing, aodShowing);
David Stevens53a39ea2017-08-23 18:41:49 -07002205 }
2206 }
2207
2208 private void notifyDefaultDisplayCallbacks(boolean showing) {
Lucas Dupin8968f6a2019-08-09 17:41:15 -07002209 // TODO(b/140053364)
2210 whitelistIpcs(() -> {
2211 int size = mKeyguardStateCallbacks.size();
2212 for (int i = size - 1; i >= 0; i--) {
2213 IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
2214 try {
2215 callback.onShowingStateChanged(showing);
2216 } catch (RemoteException e) {
2217 Slog.w(TAG, "Failed to call onShowingStateChanged", e);
2218 if (e instanceof DeadObjectException) {
2219 mKeyguardStateCallbacks.remove(callback);
2220 }
Jim Millerab954542014-10-10 18:21:49 -07002221 }
Jim Millerab954542014-10-10 18:21:49 -07002222 }
Lucas Dupin8968f6a2019-08-09 17:41:15 -07002223 });
David Stevens53a39ea2017-08-23 18:41:49 -07002224 updateInputRestrictedLocked();
2225 mUiOffloadThread.submit(() -> {
2226 mTrustManager.reportKeyguardShowingChanged();
2227 });
Adrian Roos481a6df2014-11-20 19:48:56 +01002228 }
Jim Millerab954542014-10-10 18:21:49 -07002229
Adrian Roosd88eb262016-08-04 14:50:48 -07002230 private void notifyTrustedChangedLocked(boolean trusted) {
2231 int size = mKeyguardStateCallbacks.size();
2232 for (int i = size - 1; i >= 0; i--) {
2233 try {
2234 mKeyguardStateCallbacks.get(i).onTrustedChanged(trusted);
2235 } catch (RemoteException e) {
2236 Slog.w(TAG, "Failed to call notifyTrustedChangedLocked", e);
2237 if (e instanceof DeadObjectException) {
2238 mKeyguardStateCallbacks.remove(i);
2239 }
2240 }
2241 }
2242 }
2243
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002244 private void notifyHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
2245 int size = mKeyguardStateCallbacks.size();
2246 for (int i = size - 1; i >= 0; i--) {
2247 try {
2248 mKeyguardStateCallbacks.get(i).onHasLockscreenWallpaperChanged(
2249 hasLockscreenWallpaper);
2250 } catch (RemoteException e) {
2251 Slog.w(TAG, "Failed to call onHasLockscreenWallpaperChanged", e);
2252 if (e instanceof DeadObjectException) {
2253 mKeyguardStateCallbacks.remove(i);
2254 }
2255 }
2256 }
2257 }
2258
Jim Millerab954542014-10-10 18:21:49 -07002259 public void addStateMonitorCallback(IKeyguardStateCallback callback) {
2260 synchronized (this) {
2261 mKeyguardStateCallbacks.add(callback);
2262 try {
2263 callback.onSimSecureStateChanged(mUpdateMonitor.isSimPinSecure());
2264 callback.onShowingStateChanged(mShowing);
Adrian Roos4a963ac2015-04-24 16:04:53 -07002265 callback.onInputRestrictedStateChanged(mInputRestricted);
Adrian Roosd88eb262016-08-04 14:50:48 -07002266 callback.onTrustedChanged(mUpdateMonitor.getUserHasTrust(
2267 KeyguardUpdateMonitor.getCurrentUser()));
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002268 callback.onHasLockscreenWallpaperChanged(mUpdateMonitor.hasLockscreenWallpaper());
Jim Millerab954542014-10-10 18:21:49 -07002269 } catch (RemoteException e) {
Adrian Roosd88eb262016-08-04 14:50:48 -07002270 Slog.w(TAG, "Failed to call to IKeyguardStateCallback", e);
Jim Millerab954542014-10-10 18:21:49 -07002271 }
2272 }
2273 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08002274
2275 private static class DismissMessage {
2276 private final CharSequence mMessage;
2277 private final IKeyguardDismissCallback mCallback;
2278
2279 DismissMessage(IKeyguardDismissCallback callback, CharSequence message) {
2280 mCallback = callback;
2281 mMessage = message;
2282 }
2283
2284 public IKeyguardDismissCallback getCallback() {
2285 return mCallback;
2286 }
2287
2288 public CharSequence getMessage() {
2289 return mMessage;
2290 }
2291 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002292}