blob: 5e38f2e667ff56c4388aa2353cb32b5e205e4b87 [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 Belmonte5cece532019-10-15 09:44:28 -0700836 // Reset keyguard going away state so we can start listening for biometric auth
837 setKeyguardGoingAway(false);
838
Jim Millera4edd152012-01-06 18:24:04 -0800839 // Lock immediately based on setting if secure (user has a pin/pattern/password).
840 // This also "locks" the device when not secure to provide easy access to the
841 // camera while preventing unwanted input.
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700842 int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jim Millera4edd152012-01-06 18:24:04 -0800843 final boolean lockImmediately =
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700844 mLockPatternUtils.getPowerButtonInstantlyLocks(currentUser)
845 || !mLockPatternUtils.isSecure(currentUser);
Clara Bayarri56878a92015-10-29 15:43:55 +0000846 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000847 mLockLater = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800848 if (mExitSecureCallback != null) {
849 if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled");
Jim Miller5ecd8112013-01-09 18:50:26 -0800850 try {
851 mExitSecureCallback.onKeyguardExitResult(false);
852 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800853 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800854 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800855 mExitSecureCallback = null;
856 if (!mExternallyEnabled) {
Jim Miller9c20d0e2010-01-20 15:00:23 -0800857 hideLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800858 }
859 } else if (mShowing) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700860 mPendingReset = true;
Adrian Roose99bc052017-11-20 17:55:31 +0100861 } else if ((why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_TIMEOUT && timeout > 0)
862 || (why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER && !lockImmediately)) {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700863 doKeyguardLaterLocked(timeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000864 mLockLater = true;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700865 } else if (!mLockPatternUtils.isLockScreenDisabled(currentUser)) {
866 mPendingLock = true;
867 }
868
Jorim Jaggi853cbe32015-06-04 16:31:54 -0700869 if (mPendingLock) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700870 playSounds(true);
871 }
872 }
Dave Mankoffe2294692019-08-14 11:53:13 -0400873 mUpdateMonitor.dispatchStartedGoingToSleep(why);
Jorim Jaggi18f18ae2015-09-10 15:48:21 -0700874 notifyStartedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700875 }
876
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700877 public void onFinishedGoingToSleep(int why, boolean cameraGestureTriggered) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700878 if (DEBUG) Log.d(TAG, "onFinishedGoingToSleep(" + why + ")");
879 synchronized (this) {
880 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700881 mGoingToSleep = false;
Adrian Roose4cb6c8a2017-07-19 18:08:07 +0200882 mWakeAndUnlocking = false;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700883
884 resetKeyguardDonePendingLocked();
885 mHideAnimationRun = false;
886
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700887 notifyFinishedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700888
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700889 if (cameraGestureTriggered) {
890 Log.i(TAG, "Camera gesture was triggered, preventing Keyguard locking.");
891
892 // Just to make sure, make sure the device is awake.
893 mContext.getSystemService(PowerManager.class).wakeUp(SystemClock.uptimeMillis(),
Michael Wrighte3001042019-02-05 00:13:14 +0000894 PowerManager.WAKE_REASON_CAMERA_LAUNCH,
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700895 "com.android.systemui:CAMERA_GESTURE_PREVENT_LOCK");
896 mPendingLock = false;
897 mPendingReset = false;
898 }
899
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700900 if (mPendingReset) {
901 resetStateLocked();
902 mPendingReset = false;
903 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000904
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700905 if (mPendingLock) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800906 doKeyguardLocked(null);
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700907 mPendingLock = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800908 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000909
910 // We do not have timeout and power button instant lock setting for profile lock.
911 // So we use the personal setting if there is any. But if there is no device
912 // we need to make sure we lock it immediately when the screen is off.
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700913 if (!mLockLater && !cameraGestureTriggered) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000914 doKeyguardForChildProfilesLocked();
915 }
916
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800917 }
Dave Mankoffe2294692019-08-14 11:53:13 -0400918 mUpdateMonitor.dispatchFinishedGoingToSleep(why);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800919 }
920
Clara Bayarri56878a92015-10-29 15:43:55 +0000921 private long getLockTimeout(int userId) {
Jeff Brown6aaf2952012-10-05 16:01:08 -0700922 // if the screen turned off because of timeout or the user hit the power button
923 // and we don't need to lock immediately, set an alarm
924 // to enable it a little bit later (i.e, give the user a chance
925 // to turn the screen back on within a certain window without
926 // having to unlock the screen)
927 final ContentResolver cr = mContext.getContentResolver();
928
Jeff Brown6aaf2952012-10-05 16:01:08 -0700929 // From SecuritySettings
930 final long lockAfterTimeout = Settings.Secure.getInt(cr,
931 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT,
932 KEYGUARD_LOCK_AFTER_DELAY_DEFAULT);
933
934 // From DevicePolicyAdmin
935 final long policyTimeout = mLockPatternUtils.getDevicePolicyManager()
Pavel Grafov28939982017-10-03 15:11:52 +0100936 .getMaximumTimeToLock(null, userId);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700937
938 long timeout;
Clara Bayarri56878a92015-10-29 15:43:55 +0000939
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000940 if (policyTimeout <= 0) {
Clara Bayarri56878a92015-10-29 15:43:55 +0000941 timeout = lockAfterTimeout;
942 } else {
943 // From DisplaySettings
944 long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT,
945 KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT);
946
Jeff Brown6aaf2952012-10-05 16:01:08 -0700947 // policy in effect. Make sure we don't go beyond policy limit.
948 displayTimeout = Math.max(displayTimeout, 0); // ignore negative values
949 timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000950 timeout = Math.max(timeout, 0);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700951 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700952 return timeout;
953 }
Jeff Brown6aaf2952012-10-05 16:01:08 -0700954
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700955 private void doKeyguardLaterLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000956 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700957 if (timeout == 0) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800958 doKeyguardLocked(null);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700959 } else {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700960 doKeyguardLaterLocked(timeout);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700961 }
962 }
963
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700964 private void doKeyguardLaterLocked(long timeout) {
965 // Lock in the future
966 long when = SystemClock.elapsedRealtime() + timeout;
967 Intent intent = new Intent(DELAYED_KEYGUARD_ACTION);
968 intent.putExtra("seq", mDelayedShowingSequence);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700969 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700970 PendingIntent sender = PendingIntent.getBroadcast(mContext,
971 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Jim Millera622d3cc2016-03-02 16:02:24 -0800972 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700973 if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = "
974 + mDelayedShowingSequence);
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000975 doKeyguardLaterForChildProfilesLocked();
Clara Bayarri56878a92015-10-29 15:43:55 +0000976 }
Clara Bayarri10ad84a2015-12-01 17:38:05 +0000977
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000978 private void doKeyguardLaterForChildProfilesLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000979 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700980 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
981 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
982 long userTimeout = getLockTimeout(profileId);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000983 if (userTimeout == 0) {
984 doKeyguardForChildProfilesLocked();
985 } else {
986 long userWhen = SystemClock.elapsedRealtime() + userTimeout;
987 Intent lockIntent = new Intent(DELAYED_LOCK_PROFILE_ACTION);
988 lockIntent.putExtra("seq", mDelayedProfileShowingSequence);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700989 lockIntent.putExtra(Intent.EXTRA_USER_ID, profileId);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700990 lockIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000991 PendingIntent lockSender = PendingIntent.getBroadcast(
992 mContext, 0, lockIntent, PendingIntent.FLAG_CANCEL_CURRENT);
993 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
994 userWhen, lockSender);
995 }
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000996 }
997 }
998 }
999
1000 private void doKeyguardForChildProfilesLocked() {
1001 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07001002 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
1003 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
1004 lockProfile(profileId);
Clara Bayarri56878a92015-10-29 15:43:55 +00001005 }
1006 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -07001007 }
1008
Jeff Brown6aaf2952012-10-05 16:01:08 -07001009 private void cancelDoKeyguardLaterLocked() {
1010 mDelayedShowingSequence++;
1011 }
1012
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001013 private void cancelDoKeyguardForChildProfilesLocked() {
1014 mDelayedProfileShowingSequence++;
1015 }
1016
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001017 /**
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001018 * Let's us know when the device is waking up.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001019 */
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001020 public void onStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001021 Trace.beginSection("KeyguardViewMediator#onStartedWakingUp");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001022
1023 // TODO: Rename all screen off/on references to interactive/sleeping
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001024 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001025 mDeviceInteractive = true;
Jeff Brown6aaf2952012-10-05 16:01:08 -07001026 cancelDoKeyguardLaterLocked();
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001027 cancelDoKeyguardForChildProfilesLocked();
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001028 if (DEBUG) Log.d(TAG, "onStartedWakingUp, seq = " + mDelayedShowingSequence);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001029 notifyStartedWakingUp();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001030 }
Dave Mankoffe2294692019-08-14 11:53:13 -04001031 mUpdateMonitor.dispatchStartedWakingUp();
Jim Miller3fd47af2012-09-21 19:55:27 -07001032 maybeSendUserPresentBroadcast();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001033 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -07001034 }
1035
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001036 public void onScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001037 Trace.beginSection("KeyguardViewMediator#onScreenTurningOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001038 notifyScreenOn(callback);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001039 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001040 }
1041
1042 public void onScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001043 Trace.beginSection("KeyguardViewMediator#onScreenTurnedOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001044 notifyScreenTurnedOn();
1045 mUpdateMonitor.dispatchScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001046 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001047 }
1048
1049 public void onScreenTurnedOff() {
1050 notifyScreenTurnedOff();
1051 mUpdateMonitor.dispatchScreenTurnedOff();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001052 }
1053
Jim Miller3fd47af2012-09-21 19:55:27 -07001054 private void maybeSendUserPresentBroadcast() {
Adrian Roos8150d2a2015-04-16 17:11:20 -07001055 if (mSystemReady && mLockPatternUtils.isLockScreenDisabled(
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001056 KeyguardUpdateMonitor.getCurrentUser())) {
Jim Miller3fd47af2012-09-21 19:55:27 -07001057 // Lock screen is disabled because the user has set the preference to "None".
1058 // In this case, send out ACTION_USER_PRESENT here instead of in
1059 // handleKeyguardDone()
1060 sendUserPresentBroadcast();
Adrian Roosfb95a812016-06-20 14:58:59 -07001061 } else if (mSystemReady && shouldWaitForProvisioning()) {
1062 // Skipping the lockscreen because we're not yet provisioned, but we still need to
1063 // notify the StrongAuthTracker that it's now safe to run trust agents, in case the
1064 // user sets a credential later.
1065 getLockPatternUtils().userPresent(KeyguardUpdateMonitor.getCurrentUser());
Jim Miller3fd47af2012-09-21 19:55:27 -07001066 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001067 }
1068
1069 /**
Jeff Brown6aaf2952012-10-05 16:01:08 -07001070 * A dream started. We should lock after the usual screen-off lock timeout but only
1071 * if there is a secure lock pattern.
1072 */
1073 public void onDreamingStarted() {
Dave Mankoffe2294692019-08-14 11:53:13 -04001074 mUpdateMonitor.dispatchDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001075 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001076 if (mDeviceInteractive
1077 && mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001078 doKeyguardLaterLocked();
1079 }
1080 }
1081 }
1082
1083 /**
1084 * A dream stopped.
1085 */
1086 public void onDreamingStopped() {
Dave Mankoffe2294692019-08-14 11:53:13 -04001087 mUpdateMonitor.dispatchDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001088 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001089 if (mDeviceInteractive) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001090 cancelDoKeyguardLaterLocked();
1091 }
1092 }
1093 }
1094
1095 /**
Adrian Roose99bc052017-11-20 17:55:31 +01001096 * Same semantics as {@link WindowManagerPolicyConstants#enableKeyguard}; provide
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001097 * a way for external stuff to override normal keyguard behavior. For instance
1098 * the phone app disables the keyguard when it receives incoming calls.
1099 */
1100 public void setKeyguardEnabled(boolean enabled) {
1101 synchronized (this) {
1102 if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")");
1103
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001104 mExternallyEnabled = enabled;
1105
1106 if (!enabled && mShowing) {
1107 if (mExitSecureCallback != null) {
1108 if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring");
1109 // we're in the process of handling a request to verify the user
1110 // can get past the keyguard. ignore extraneous requests to disable / reenable
1111 return;
1112 }
1113
1114 // hiding keyguard that is showing, remember to reshow later
1115 if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, "
1116 + "disabling status bar expansion");
1117 mNeedToReshowWhenReenabled = true;
Jim Millerab954542014-10-10 18:21:49 -07001118 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001119 hideLocked();
1120 } else if (enabled && mNeedToReshowWhenReenabled) {
1121 // reenabled after previously hidden, reshow
1122 if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling "
1123 + "status bar expansion");
1124 mNeedToReshowWhenReenabled = false;
Jim Millerab954542014-10-10 18:21:49 -07001125 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001126
1127 if (mExitSecureCallback != null) {
1128 if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting");
Jim Miller5ecd8112013-01-09 18:50:26 -08001129 try {
1130 mExitSecureCallback.onKeyguardExitResult(false);
1131 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001132 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001133 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001134 mExitSecureCallback = null;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001135 resetStateLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001136 } else {
Adam Cohenf7522022012-10-03 20:03:18 -07001137 showLocked(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001138
1139 // block until we know the keygaurd is done drawing (and post a message
1140 // to unblock us after a timeout so we don't risk blocking too long
1141 // and causing an ANR).
1142 mWaitingUntilKeyguardVisible = true;
1143 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS);
1144 if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false");
1145 while (mWaitingUntilKeyguardVisible) {
1146 try {
1147 wait();
1148 } catch (InterruptedException e) {
1149 Thread.currentThread().interrupt();
1150 }
1151 }
1152 if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible");
1153 }
1154 }
1155 }
1156 }
1157
1158 /**
1159 * @see android.app.KeyguardManager#exitKeyguardSecurely
1160 */
Jim Miller25190572013-02-28 17:36:24 -08001161 public void verifyUnlock(IKeyguardExitCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001162 Trace.beginSection("KeyguardViewMediator#verifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001163 synchronized (this) {
1164 if (DEBUG) Log.d(TAG, "verifyUnlock");
Jim Millerb256e4e22014-10-31 17:27:13 -07001165 if (shouldWaitForProvisioning()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001166 // don't allow this api when the device isn't provisioned
1167 if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned");
Jim Miller5ecd8112013-01-09 18:50:26 -08001168 try {
Jim Miller25190572013-02-28 17:36:24 -08001169 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001170 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001171 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001172 }
Mike Lockwood5d258b62009-12-02 13:50:45 -05001173 } else if (mExternallyEnabled) {
1174 // this only applies when the user has externally disabled the
1175 // keyguard. this is unexpected and means the user is not
1176 // using the api properly.
1177 Log.w(TAG, "verifyUnlock called when not externally disabled");
Jim Miller5ecd8112013-01-09 18:50:26 -08001178 try {
Jim Miller25190572013-02-28 17:36:24 -08001179 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001180 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001181 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001182 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001183 } else if (mExitSecureCallback != null) {
1184 // already in progress with someone else
Jim Miller5ecd8112013-01-09 18:50:26 -08001185 try {
Jim Miller25190572013-02-28 17:36:24 -08001186 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001187 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001188 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001189 }
Jorim Jaggi302475e2015-09-22 12:44:47 -07001190 } else if (!isSecure()) {
1191
1192 // Keyguard is not secure, no need to do anything, and we don't need to reshow
1193 // the Keyguard after the client releases the Keyguard lock.
1194 mExternallyEnabled = true;
1195 mNeedToReshowWhenReenabled = false;
1196 updateInputRestricted();
1197 try {
1198 callback.onKeyguardExitResult(true);
1199 } catch (RemoteException e) {
1200 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1201 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001202 } else {
Jorim Jaggi302475e2015-09-22 12:44:47 -07001203
1204 // Since we prevent apps from hiding the Keyguard if we are secure, this should be
1205 // a no-op as well.
1206 try {
1207 callback.onKeyguardExitResult(false);
1208 } catch (RemoteException e) {
1209 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1210 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001211 }
1212 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001213 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001214 }
1215
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001216 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001217 * Is the keyguard currently showing and not being force hidden?
Mike Lockwood09a40402009-11-08 00:33:23 -05001218 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001219 public boolean isShowingAndNotOccluded() {
1220 return mShowing && !mOccluded;
1221 }
1222
1223 /**
1224 * Notify us when the keyguard is occluded by another window
1225 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001226 public void setOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001227 Trace.beginSection("KeyguardViewMediator#setOccluded");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001228 if (DEBUG) Log.d(TAG, "setOccluded " + isOccluded);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001229 mHandler.removeMessages(SET_OCCLUDED);
Jorim Jaggi6626f542016-08-22 13:08:44 -07001230 Message msg = mHandler.obtainMessage(SET_OCCLUDED, isOccluded ? 1 : 0, animate ? 1 : 0);
Mike Lockwood9200a392009-11-17 20:25:58 -05001231 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001232 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001233 }
1234
Lucas Dupin2986c152018-04-09 20:49:41 -07001235 public boolean isHiding() {
1236 return mHiding;
1237 }
1238
Mike Lockwood9200a392009-11-17 20:25:58 -05001239 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001240 * Handles SET_OCCLUDED message sent by setOccluded()
Mike Lockwood9200a392009-11-17 20:25:58 -05001241 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001242 private void handleSetOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001243 Trace.beginSection("KeyguardViewMediator#handleSetOccluded");
Mike Lockwood09a40402009-11-08 00:33:23 -05001244 synchronized (KeyguardViewMediator.this) {
Adrian Roosf253eeb2015-04-15 18:03:08 -07001245 if (mHiding && isOccluded) {
1246 // We're in the process of going away but WindowManager wants to show a
1247 // SHOW_WHEN_LOCKED activity instead.
1248 startKeyguardExitAnimation(0, 0);
1249 }
1250
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001251 if (mOccluded != isOccluded) {
1252 mOccluded = isOccluded;
Kevin Chyn2fefd462017-04-28 12:18:19 -07001253 mUpdateMonitor.setKeyguardOccluded(isOccluded);
Selim Cinek2f6272e2017-03-15 16:19:10 -07001254 mStatusBarKeyguardViewManager.setOccluded(isOccluded, animate
1255 && mDeviceInteractive);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001256 adjustStatusBarLocked();
Mike Lockwood9200a392009-11-17 20:25:58 -05001257 }
Mike Lockwood09a40402009-11-08 00:33:23 -05001258 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001259 Trace.endSection();
Mike Lockwood09a40402009-11-08 00:33:23 -05001260 }
1261
1262 /**
Mike Lockwood28569302010-01-28 11:54:40 -05001263 * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout.
1264 * This must be safe to call from any thread and with any window manager locks held.
1265 */
Adam Cohenf7522022012-10-03 20:03:18 -07001266 public void doKeyguardTimeout(Bundle options) {
Mike Lockwood28569302010-01-28 11:54:40 -05001267 mHandler.removeMessages(KEYGUARD_TIMEOUT);
Adam Cohenf7522022012-10-03 20:03:18 -07001268 Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options);
Mike Lockwood28569302010-01-28 11:54:40 -05001269 mHandler.sendMessage(msg);
1270 }
1271
1272 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001273 * Given the state of the keyguard, is the input restricted?
1274 * Input is restricted when the keyguard is showing, or when the keyguard
1275 * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet.
1276 */
1277 public boolean isInputRestricted() {
Adrian Roos9f33d6c2015-06-15 15:58:35 -07001278 return mShowing || mNeedToReshowWhenReenabled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001279 }
1280
Jim Millerab954542014-10-10 18:21:49 -07001281 private void updateInputRestricted() {
1282 synchronized (this) {
1283 updateInputRestrictedLocked();
1284 }
1285 }
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001286
Jim Millerab954542014-10-10 18:21:49 -07001287 private void updateInputRestrictedLocked() {
1288 boolean inputRestricted = isInputRestricted();
1289 if (mInputRestricted != inputRestricted) {
1290 mInputRestricted = inputRestricted;
dooyoung.hwang328472e2015-05-21 16:09:43 +09001291 int size = mKeyguardStateCallbacks.size();
1292 for (int i = size - 1; i >= 0; i--) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001293 final IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001294 try {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001295 callback.onInputRestrictedStateChanged(inputRestricted);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001296 } catch (RemoteException e) {
1297 Slog.w(TAG, "Failed to call onDeviceProvisioned", e);
1298 if (e instanceof DeadObjectException) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001299 mKeyguardStateCallbacks.remove(callback);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001300 }
Jim Millerab954542014-10-10 18:21:49 -07001301 }
Jim Millerab954542014-10-10 18:21:49 -07001302 }
1303 }
1304 }
1305
Dianne Hackbornb446e972009-09-20 15:23:25 -07001306 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001307 * Enable the keyguard if the settings are appropriate.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001308 */
Adam Cohenf7522022012-10-03 20:03:18 -07001309 private void doKeyguardLocked(Bundle options) {
Adrian Roosca8a2162017-08-17 19:00:58 +02001310 if (KeyguardUpdateMonitor.CORE_APPS_ONLY) {
1311 // Don't show keyguard during half-booted cryptkeeper stage.
1312 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because booting to cryptkeeper");
1313 return;
1314 }
1315
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001316 // if another app is disabling us, don't show
1317 if (!mExternallyEnabled) {
1318 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled");
Karl Rosaenab100082009-03-24 22:35:17 -07001319
Adrian Roos1c8e3c02018-11-20 20:07:55 +01001320 mNeedToReshowWhenReenabled = true;
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001321 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001322 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001323
1324 // if the keyguard is already showing, don't bother
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001325 if (mStatusBarKeyguardViewManager.isShowing()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001326 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing");
Jorim Jaggi95e89ca2014-11-24 20:12:50 +01001327 resetStateLocked();
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001328 return;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001329 }
1330
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001331 // In split system user mode, we never unlock system user.
Amith Yamasanieb437d42016-04-29 09:31:25 -07001332 if (!mustNotUnlockCurrentUser()
Amith Yamasani27e025b2015-11-06 10:34:41 -08001333 || !mUpdateMonitor.isDeviceProvisioned()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001334
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001335 // if the setup wizard hasn't run yet, don't show
1336 final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", false);
1337 final boolean absent = SubscriptionManager.isValidSubscriptionId(
Adrian Roose92de952016-12-13 12:07:09 -08001338 mUpdateMonitor.getNextSubIdForState(ABSENT));
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001339 final boolean disabled = SubscriptionManager.isValidSubscriptionId(
1340 mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.PERM_DISABLED));
1341 final boolean lockedOrMissing = mUpdateMonitor.isSimPinSecure()
1342 || ((absent || disabled) && requireSim);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001343
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001344 if (!lockedOrMissing && shouldWaitForProvisioning()) {
1345 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned"
1346 + " and the sim is not locked or missing");
1347 return;
1348 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001349
Evan Rosky13a58a92016-07-27 15:51:09 -07001350 boolean forceShow = options != null && options.getBoolean(OPTION_FORCE_SHOW, false);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001351 if (mLockPatternUtils.isLockScreenDisabled(KeyguardUpdateMonitor.getCurrentUser())
Evan Rosky13a58a92016-07-27 15:51:09 -07001352 && !lockedOrMissing && !forceShow) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001353 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off");
1354 return;
1355 }
1356
1357 if (mLockPatternUtils.checkVoldPassword(KeyguardUpdateMonitor.getCurrentUser())) {
1358 if (DEBUG) Log.d(TAG, "Not showing lock screen since just decrypted");
1359 // Without this, settings is not enabled until the lock screen first appears
Lucas Dupinb3455e62019-07-11 11:47:13 +09001360 setShowingLocked(false);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001361 hideLocked();
1362 return;
1363 }
Paul Lawrence945490c2014-03-27 16:37:28 +00001364 }
1365
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001366 if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");
Adam Cohenf7522022012-10-03 20:03:18 -07001367 showLocked(options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001368 }
1369
Clara Bayarri56878a92015-10-29 15:43:55 +00001370 private void lockProfile(int userId) {
1371 mTrustManager.setDeviceLockedForUser(userId, true);
1372 }
1373
Jim Millerb256e4e22014-10-31 17:27:13 -07001374 private boolean shouldWaitForProvisioning() {
1375 return !mUpdateMonitor.isDeviceProvisioned() && !isSecure();
1376 }
1377
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001378 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001379 * Dismiss the keyguard through the security layers.
Jorim Jaggi241ae102016-11-02 21:57:33 -07001380 * @param callback Callback to be informed about the result
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001381 * @param message Message that should be displayed on the bouncer.
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001382 */
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001383 private void handleDismiss(IKeyguardDismissCallback callback, CharSequence message) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001384 if (mShowing) {
1385 if (callback != null) {
1386 mDismissCallbackRegistry.addCallback(callback);
1387 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001388 mCustomMessage = message;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001389 mStatusBarKeyguardViewManager.dismissAndCollapse();
Jorim Jaggi241ae102016-11-02 21:57:33 -07001390 } else if (callback != null) {
1391 new DismissCallbackWrapper(callback).notifyDismissError();
Jim Miller87d03662012-11-05 20:28:09 -08001392 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001393 }
1394
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001395 public void dismiss(IKeyguardDismissCallback callback, CharSequence message) {
1396 mHandler.obtainMessage(DISMISS, new DismissMessage(callback, message)).sendToTarget();
Jim Miller60013792013-10-03 18:31:34 -07001397 }
1398
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001399 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001400 * Send message to keyguard telling it to reset its state.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001401 * @see #handleReset
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001402 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001403 private void resetStateLocked() {
Jim Miller4894a012013-04-03 15:23:55 -07001404 if (DEBUG) Log.e(TAG, "resetStateLocked");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001405 Message msg = mHandler.obtainMessage(RESET);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001406 mHandler.sendMessage(msg);
1407 }
1408
1409 /**
1410 * Send message to keyguard telling it to verify unlock
1411 * @see #handleVerifyUnlock()
1412 */
1413 private void verifyUnlockLocked() {
1414 if (DEBUG) Log.d(TAG, "verifyUnlockLocked");
1415 mHandler.sendEmptyMessage(VERIFY_UNLOCK);
1416 }
1417
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001418 private void notifyStartedGoingToSleep() {
1419 if (DEBUG) Log.d(TAG, "notifyStartedGoingToSleep");
1420 mHandler.sendEmptyMessage(NOTIFY_STARTED_GOING_TO_SLEEP);
1421 }
1422
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001423 private void notifyFinishedGoingToSleep() {
1424 if (DEBUG) Log.d(TAG, "notifyFinishedGoingToSleep");
1425 mHandler.sendEmptyMessage(NOTIFY_FINISHED_GOING_TO_SLEEP);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001426 }
1427
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001428 private void notifyStartedWakingUp() {
1429 if (DEBUG) Log.d(TAG, "notifyStartedWakingUp");
1430 mHandler.sendEmptyMessage(NOTIFY_STARTED_WAKING_UP);
1431 }
1432
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001433 private void notifyScreenOn(IKeyguardDrawnCallback callback) {
1434 if (DEBUG) Log.d(TAG, "notifyScreenOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001435 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNING_ON, callback);
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001436 mHandler.sendMessage(msg);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001437 }
1438
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001439 private void notifyScreenTurnedOn() {
1440 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOn");
1441 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_ON);
1442 mHandler.sendMessage(msg);
1443 }
1444
1445 private void notifyScreenTurnedOff() {
1446 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOff");
1447 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_OFF);
1448 mHandler.sendMessage(msg);
1449 }
1450
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001451 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001452 * Send message to keyguard telling it to show itself
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001453 * @see #handleShow
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001454 */
Adam Cohenf7522022012-10-03 20:03:18 -07001455 private void showLocked(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001456 Trace.beginSection("KeyguardViewMediator#showLocked aqcuiring mShowKeyguardWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001457 if (DEBUG) Log.d(TAG, "showLocked");
Mike Lockwood674d3e42009-10-06 09:28:54 -04001458 // ensure we stay awake until we are finished displaying the keyguard
1459 mShowKeyguardWakeLock.acquire();
Adam Cohenf7522022012-10-03 20:03:18 -07001460 Message msg = mHandler.obtainMessage(SHOW, options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001461 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001462 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001463 }
1464
1465 /**
1466 * Send message to keyguard telling it to hide itself
Jim Miller9c20d0e2010-01-20 15:00:23 -08001467 * @see #handleHide()
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001468 */
1469 private void hideLocked() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001470 Trace.beginSection("KeyguardViewMediator#hideLocked");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001471 if (DEBUG) Log.d(TAG, "hideLocked");
1472 Message msg = mHandler.obtainMessage(HIDE);
1473 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001474 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001475 }
1476
Dianne Hackbornb446e972009-09-20 15:23:25 -07001477 public boolean isSecure() {
Evan Rosky13a58a92016-07-27 15:51:09 -07001478 return isSecure(KeyguardUpdateMonitor.getCurrentUser());
1479 }
1480
1481 public boolean isSecure(int userId) {
1482 return mLockPatternUtils.isSecure(userId)
Dave Mankoffe2294692019-08-14 11:53:13 -04001483 || mUpdateMonitor.isSimPinSecure();
Dianne Hackbornb446e972009-09-20 15:23:25 -07001484 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001485
Evan Rosky18396452016-07-27 15:19:37 -07001486 public void setSwitchingUser(boolean switching) {
Dave Mankoffe2294692019-08-14 11:53:13 -04001487 mUpdateMonitor.setSwitchingUser(switching);
Evan Rosky18396452016-07-27 15:19:37 -07001488 }
1489
Craig Mautnerf1b67412012-09-19 13:18:29 -07001490 /**
1491 * Update the newUserId. Call while holding WindowManagerService lock.
Jim Milleree82f8f2012-10-01 16:26:18 -07001492 * NOTE: Should only be called by KeyguardViewMediator in response to the user id changing.
1493 *
Craig Mautnerf1b67412012-09-19 13:18:29 -07001494 * @param newUserId The id of the incoming user.
1495 */
1496 public void setCurrentUser(int newUserId) {
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001497 KeyguardUpdateMonitor.setCurrentUser(newUserId);
Adrian Roosd88eb262016-08-04 14:50:48 -07001498 synchronized (this) {
1499 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(newUserId));
1500 }
Craig Mautnerf1b67412012-09-19 13:18:29 -07001501 }
1502
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001503 /**
1504 * This broadcast receiver should be registered with the SystemUI permission.
1505 */
1506 private final BroadcastReceiver mDelayedLockBroadcastReceiver = new BroadcastReceiver() {
Amith Yamasani52c489c2012-03-28 11:42:42 -07001507 @Override
1508 public void onReceive(Context context, Intent intent) {
Jim Millerbbf1a742012-07-17 18:30:30 -07001509 if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
1510 final int sequence = intent.getIntExtra("seq", 0);
Jim Millerf3447352011-08-07 14:00:09 -07001511 if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = "
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001512 + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001513 synchronized (KeyguardViewMediator.this) {
Jim Miller2967f482016-01-07 15:05:32 -08001514 if (mDelayedShowingSequence == sequence) {
1515 doKeyguardLocked(null);
1516 }
Clara Bayarri56878a92015-10-29 15:43:55 +00001517 }
1518 } else if (DELAYED_LOCK_PROFILE_ACTION.equals(intent.getAction())) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001519 final int sequence = intent.getIntExtra("seq", 0);
Clara Bayarri56878a92015-10-29 15:43:55 +00001520 int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, 0);
1521 if (userId != 0) {
1522 synchronized (KeyguardViewMediator.this) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001523 if (mDelayedProfileShowingSequence == sequence) {
1524 lockProfile(userId);
1525 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001526 }
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001527 }
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001528 }
1529 }
1530 };
1531
1532 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1533 @Override
1534 public void onReceive(Context context, Intent intent) {
1535 if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
Adrian Roos1f8025a2016-12-27 10:12:13 -08001536 synchronized (KeyguardViewMediator.this){
1537 mShuttingDown = true;
1538 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001539 }
1540 }
1541 };
1542
Jorim Jaggi241ae102016-11-02 21:57:33 -07001543 public void keyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001544 Trace.beginSection("KeyguardViewMediator#keyguardDone");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001545 if (DEBUG) Log.d(TAG, "keyguardDone()");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001546 userActivity();
Jim Miller60013792013-10-03 18:31:34 -07001547 EventLog.writeEvent(70000, 2);
Jorim Jaggi241ae102016-11-02 21:57:33 -07001548 Message msg = mHandler.obtainMessage(KEYGUARD_DONE);
Jim Miller60013792013-10-03 18:31:34 -07001549 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001550 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001551 }
1552
1553 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001554 * This handler will be associated with the policy thread, which will also
1555 * be the UI thread of the keyguard. Since the apis of the policy, and therefore
1556 * this class, can be called by other threads, any action that directly
1557 * interacts with the keyguard ui should be posted to this handler, rather
1558 * than called directly.
1559 */
Jim Millerdcb3d842012-08-23 19:18:12 -07001560 private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001561 @Override
Wink Saville37c124c2009-04-02 01:37:02 -07001562 public void handleMessage(Message msg) {
1563 switch (msg.what) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001564 case SHOW:
Adam Cohenf7522022012-10-03 20:03:18 -07001565 handleShow((Bundle) msg.obj);
Jim Miller60013792013-10-03 18:31:34 -07001566 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001567 case HIDE:
1568 handleHide();
Jim Miller60013792013-10-03 18:31:34 -07001569 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001570 case RESET:
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001571 handleReset();
Jim Miller60013792013-10-03 18:31:34 -07001572 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001573 case VERIFY_UNLOCK:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001574 Trace.beginSection("KeyguardViewMediator#handleMessage VERIFY_UNLOCK");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001575 handleVerifyUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001576 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001577 break;
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001578 case NOTIFY_STARTED_GOING_TO_SLEEP:
1579 handleNotifyStartedGoingToSleep();
1580 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001581 case NOTIFY_FINISHED_GOING_TO_SLEEP:
1582 handleNotifyFinishedGoingToSleep();
Jim Miller60013792013-10-03 18:31:34 -07001583 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001584 case NOTIFY_SCREEN_TURNING_ON:
Curtis Belmonte5cece532019-10-15 09:44:28 -07001585 Trace.beginSection(
1586 "KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNING_ON");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001587 handleNotifyScreenTurningOn((IKeyguardDrawnCallback) msg.obj);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001588 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001589 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001590 case NOTIFY_SCREEN_TURNED_ON:
Curtis Belmonte5cece532019-10-15 09:44:28 -07001591 Trace.beginSection(
1592 "KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNED_ON");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001593 handleNotifyScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001594 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001595 break;
1596 case NOTIFY_SCREEN_TURNED_OFF:
1597 handleNotifyScreenTurnedOff();
1598 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001599 case NOTIFY_STARTED_WAKING_UP:
Curtis Belmonte5cece532019-10-15 09:44:28 -07001600 Trace.beginSection(
1601 "KeyguardViewMediator#handleMessage NOTIFY_STARTED_WAKING_UP");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001602 handleNotifyStartedWakingUp();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001603 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001604 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001605 case KEYGUARD_DONE:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001606 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001607 handleKeyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001608 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001609 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001610 case KEYGUARD_DONE_DRAWING:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001611 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_DRAWING");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001612 handleKeyguardDoneDrawing();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001613 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001614 break;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001615 case SET_OCCLUDED:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001616 Trace.beginSection("KeyguardViewMediator#handleMessage SET_OCCLUDED");
Jorim Jaggi6626f542016-08-22 13:08:44 -07001617 handleSetOccluded(msg.arg1 != 0, msg.arg2 != 0);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001618 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001619 break;
Mike Lockwood28569302010-01-28 11:54:40 -05001620 case KEYGUARD_TIMEOUT:
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001621 synchronized (KeyguardViewMediator.this) {
Adam Cohenf7522022012-10-03 20:03:18 -07001622 doKeyguardLocked((Bundle) msg.obj);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001623 }
1624 break;
Jim Miller60013792013-10-03 18:31:34 -07001625 case DISMISS:
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001626 final DismissMessage message = (DismissMessage) msg.obj;
1627 handleDismiss(message.getCallback(), message.getMessage());
Jim Miller60013792013-10-03 18:31:34 -07001628 break;
Jorim Jaggi0d674622014-05-21 01:34:15 +02001629 case START_KEYGUARD_EXIT_ANIM:
Curtis Belmonte5cece532019-10-15 09:44:28 -07001630 Trace.beginSection(
1631 "KeyguardViewMediator#handleMessage START_KEYGUARD_EXIT_ANIM");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001632 StartKeyguardExitAnimParams params = (StartKeyguardExitAnimParams) msg.obj;
1633 handleStartKeyguardExitAnimation(params.startTime, params.fadeoutDuration);
Dave Mankoffaa8b7ae2019-09-04 18:03:21 -04001634 mFalsingManager.onSucccessfulUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001635 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001636 break;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001637 case KEYGUARD_DONE_PENDING_TIMEOUT:
Curtis Belmonte5cece532019-10-15 09:44:28 -07001638 Trace.beginSection("KeyguardViewMediator#handleMessage"
1639 + " KEYGUARD_DONE_PENDING_TIMEOUT");
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001640 Log.w(TAG, "Timeout while waiting for activity drawn!");
Nick Desaulniers1d396752016-07-25 15:05:33 -07001641 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001642 break;
Adrian Roos30a2ae62018-04-25 19:09:50 +02001643 case SYSTEM_READY:
1644 handleSystemReady();
1645 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001646 }
1647 }
1648 };
1649
Jorim Jaggi241ae102016-11-02 21:57:33 -07001650 private void tryKeyguardDone() {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001651 if (!mKeyguardDonePending && mHideAnimationRun && !mHideAnimationRunning) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001652 handleKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001653 } else if (!mHideAnimationRun) {
1654 mHideAnimationRun = true;
1655 mHideAnimationRunning = true;
1656 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
1657 }
1658 }
1659
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001660 /**
1661 * @see #keyguardDone
1662 * @see #KEYGUARD_DONE
1663 */
Jorim Jaggi241ae102016-11-02 21:57:33 -07001664 private void handleKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001665 Trace.beginSection("KeyguardViewMediator#handleKeyguardDone");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001666 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001667 mUiOffloadThread.submit(() -> {
1668 if (mLockPatternUtils.isSecure(currentUser)) {
1669 mLockPatternUtils.getDevicePolicyManager().reportKeyguardDismissed(currentUser);
1670 }
1671 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001672 if (DEBUG) Log.d(TAG, "handleKeyguardDone");
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001673 synchronized (this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001674 resetKeyguardDonePendingLocked();
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001675 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001676
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001677 mUpdateMonitor.clearBiometricRecognized();
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -07001678
Jorim Jaggi4474f542015-07-09 16:08:02 -07001679 if (mGoingToSleep) {
1680 Log.i(TAG, "Device is going to sleep, aborting keyguardDone");
1681 return;
1682 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001683 if (mExitSecureCallback != null) {
1684 try {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001685 mExitSecureCallback.onKeyguardExitResult(true /* authenciated */);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001686 } catch (RemoteException e) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001687 Slog.w(TAG, "Failed to call onKeyguardExitResult()", e);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001688 }
1689
1690 mExitSecureCallback = null;
1691
Jorim Jaggi241ae102016-11-02 21:57:33 -07001692 // after succesfully exiting securely, no need to reshow
1693 // the keyguard when they've released the lock
1694 mExternallyEnabled = true;
1695 mNeedToReshowWhenReenabled = false;
1696 updateInputRestricted();
Jim Millere51cf7ae2013-06-25 18:31:56 -07001697 }
1698
1699 handleHide();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001700 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -07001701 }
1702
1703 private void sendUserPresentBroadcast() {
Jason Monkcf5a9532014-09-17 16:22:19 -04001704 synchronized (this) {
1705 if (mBootCompleted) {
Adrian Roos4ab7e592016-04-13 15:38:13 -07001706 int currentUserId = KeyguardUpdateMonitor.getCurrentUser();
1707 final UserHandle currentUser = new UserHandle(currentUserId);
Benjamin Franz4b9f8ed2014-12-01 16:51:48 +00001708 final UserManager um = (UserManager) mContext.getSystemService(
1709 Context.USER_SERVICE);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001710 mUiOffloadThread.submit(() -> {
1711 for (int profileId : um.getProfileIdsWithDisabled(currentUser.getIdentifier())) {
1712 mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, UserHandle.of(profileId));
1713 }
1714 getLockPatternUtils().userPresent(currentUserId);
1715 });
Jason Monkcf5a9532014-09-17 16:22:19 -04001716 } else {
1717 mBootSendUserPresent = true;
1718 }
1719 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001720 }
1721
1722 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001723 * @see #keyguardDone
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001724 * @see #KEYGUARD_DONE_DRAWING
1725 */
1726 private void handleKeyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001727 Trace.beginSection("KeyguardViewMediator#handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001728 synchronized(this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001729 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001730 if (mWaitingUntilKeyguardVisible) {
1731 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible");
1732 mWaitingUntilKeyguardVisible = false;
1733 notifyAll();
1734
1735 // there will usually be two of these sent, one as a timeout, and one
1736 // as a result of the callback, so remove any remaining messages from
1737 // the queue
1738 mHandler.removeMessages(KEYGUARD_DONE_DRAWING);
1739 }
1740 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001741 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001742 }
1743
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001744 private void playSounds(boolean locked) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001745 playSound(locked ? mLockSoundId : mUnlockSoundId);
1746 }
1747
1748 private void playSound(int soundId) {
1749 if (soundId == 0) return;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001750 final ContentResolver cr = mContext.getContentResolver();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001751 if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001752
Marco Nelissend5545bd2011-09-29 12:49:17 -07001753 mLockSounds.stop(mLockSoundStreamId);
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001754 // Init mAudioManager
1755 if (mAudioManager == null) {
1756 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
1757 if (mAudioManager == null) return;
John Spurlockee5ad722015-03-03 16:17:21 -05001758 mUiSoundsStreamType = mAudioManager.getUiSoundsStreamType();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001759 }
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001760
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001761 mUiOffloadThread.submit(() -> {
1762 // If the stream is muted, don't play the sound
1763 if (mAudioManager.isStreamMute(mUiSoundsStreamType)) return;
1764
1765 int id = mLockSounds.play(soundId,
1766 mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/);
1767 synchronized (this) {
1768 mLockSoundStreamId = id;
1769 }
1770 });
1771
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001772 }
Jim Miller2a98a4c2010-11-19 18:49:26 -08001773 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001774
Adrian Roos49e057d2014-08-13 17:14:51 +02001775 private void playTrustedSound() {
Adrian Roos49e057d2014-08-13 17:14:51 +02001776 playSound(mTrustedSoundId);
1777 }
1778
wilsonshih177261f2019-02-22 12:02:18 +08001779 private void updateActivityLockScreenState(boolean showing, boolean aodShowing) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001780 mUiOffloadThread.submit(() -> {
Lucas Dupinb3455e62019-07-11 11:47:13 +09001781 if (DEBUG) {
1782 Log.d(TAG, "updateActivityLockScreenState(" + showing + ", " + aodShowing + ")");
1783 }
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001784 try {
wilsonshih177261f2019-02-22 12:02:18 +08001785 ActivityTaskManager.getService().setLockScreenShown(showing, aodShowing);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001786 } catch (RemoteException e) {
1787 }
1788 });
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001789 }
1790
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001791 /**
1792 * Handle message sent by {@link #showLocked}.
1793 * @see #SHOW
1794 */
Adam Cohenf7522022012-10-03 20:03:18 -07001795 private void handleShow(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001796 Trace.beginSection("KeyguardViewMediator#handleShow");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001797 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
1798 if (mLockPatternUtils.isSecure(currentUser)) {
1799 mLockPatternUtils.getDevicePolicyManager().reportKeyguardSecured(currentUser);
Michal Karpinski779aad92016-01-20 11:56:22 +00001800 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001801 synchronized (KeyguardViewMediator.this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001802 if (!mSystemReady) {
1803 if (DEBUG) Log.d(TAG, "ignoring handleShow because system is not ready.");
1804 return;
1805 } else {
1806 if (DEBUG) Log.d(TAG, "handleShow");
1807 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001808
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001809 mHiding = false;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001810 mWakeAndUnlocking = false;
Lucas Dupinb3455e62019-07-11 11:47:13 +09001811 setShowingLocked(true);
1812 mStatusBarKeyguardViewManager.show(options);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001813 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001814 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001815 adjustStatusBarLocked();
Jeff Brown3dc524b2012-09-30 19:49:11 -07001816 userActivity();
Curtis Belmonte5cece532019-10-15 09:44:28 -07001817 setKeyguardGoingAway(false);
Mike Lockwood674d3e42009-10-06 09:28:54 -04001818 mShowKeyguardWakeLock.release();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001819 }
Jim Miller31921482013-11-06 20:43:55 -08001820 mKeyguardDisplayManager.show();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001821 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001822 }
1823
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001824 private final Runnable mKeyguardGoingAwayRunnable = new Runnable() {
1825 @Override
1826 public void run() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001827 Trace.beginSection("KeyguardViewMediator.mKeyGuardGoingAwayRunnable");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001828 if (DEBUG) Log.d(TAG, "keyguardGoingAway");
wilsonshih2bc846c2019-05-02 14:35:21 +08001829 mStatusBarKeyguardViewManager.keyguardGoingAway();
Jorim Jaggi33ae80e2015-02-04 16:37:11 +01001830
wilsonshih2bc846c2019-05-02 14:35:21 +08001831 int flags = 0;
1832 if (mStatusBarKeyguardViewManager.shouldDisableWindowAnimationsForUnlock()
1833 || (mWakeAndUnlocking && !mPulsing)) {
1834 flags |= WindowManagerPolicyConstants
1835 .KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001836 }
wilsonshih2bc846c2019-05-02 14:35:21 +08001837 if (mStatusBarKeyguardViewManager.isGoingToNotificationShade()
1838 || (mWakeAndUnlocking && mPulsing)) {
1839 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE;
1840 }
1841 if (mStatusBarKeyguardViewManager.isUnlockWithWallpaper()) {
1842 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER;
1843 }
Issei Suzuki5609ccb2019-06-13 15:04:08 +02001844 if (mStatusBarKeyguardViewManager.shouldSubtleWindowAnimationsForUnlock()) {
1845 flags |= WindowManagerPolicyConstants
1846 .KEYGUARD_GOING_AWAY_FLAG_SUBTLE_WINDOW_ANIMATIONS;
1847 }
wilsonshih2bc846c2019-05-02 14:35:21 +08001848
Curtis Belmonte5cece532019-10-15 09:44:28 -07001849 setKeyguardGoingAway(true);
wilsonshih2bc846c2019-05-02 14:35:21 +08001850
1851 // Don't actually hide the Keyguard at the moment, wait for window
1852 // manager until it tells us it's safe to do so with
1853 // startKeyguardExitAnimation.
1854 // Posting to mUiOffloadThread to ensure that calls to ActivityTaskManager will be in
1855 // order.
1856 final int keyguardFlag = flags;
1857 mUiOffloadThread.submit(() -> {
1858 try {
1859 ActivityTaskManager.getService().keyguardGoingAway(keyguardFlag);
1860 } catch (RemoteException e) {
1861 Log.e(TAG, "Error while calling WindowManager", e);
1862 }
1863 });
Nick Desaulniers1d396752016-07-25 15:05:33 -07001864 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001865 }
1866 };
1867
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001868 private final Runnable mHideAnimationFinishedRunnable = () -> {
1869 mHideAnimationRunning = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -07001870 tryKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001871 };
1872
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001873 /**
1874 * Handle message sent by {@link #hideLocked()}
1875 * @see #HIDE
1876 */
1877 private void handleHide() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001878 Trace.beginSection("KeyguardViewMediator#handleHide");
Lucas Dupin1c327432019-01-03 13:37:53 -08001879
1880 // It's possible that the device was unlocked in a dream state. It's time to wake up.
1881 if (mAodShowing) {
Michael Wrighte3001042019-02-05 00:13:14 +00001882 PowerManager pm = mContext.getSystemService(PowerManager.class);
1883 pm.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE,
1884 "com.android.systemui:BOUNCER_DOZING");
Lucas Dupin1c327432019-01-03 13:37:53 -08001885 }
1886
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001887 synchronized (KeyguardViewMediator.this) {
1888 if (DEBUG) Log.d(TAG, "handleHide");
Jorim Jaggib9d60792014-06-03 22:34:22 +02001889
Amith Yamasanieb437d42016-04-29 09:31:25 -07001890 if (mustNotUnlockCurrentUser()) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001891 // In split system user mode, we never unlock system user. The end user has to
1892 // switch to another user.
1893 // TODO: We should stop it early by disabling the swipe up flow. Right now swipe up
1894 // still completes and makes the screen blank.
1895 if (DEBUG) Log.d(TAG, "Split system user, quit unlocking.");
1896 return;
1897 }
Jorim Jaggi76a16232014-08-08 17:00:47 +02001898 mHiding = true;
Jorim Jaggib9d60792014-06-03 22:34:22 +02001899
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001900 if (mShowing && !mOccluded) {
1901 mKeyguardGoingAwayRunnable.run();
1902 } else {
Jorim Jaggi76a16232014-08-08 17:00:47 +02001903 handleStartKeyguardExitAnimation(
1904 SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(),
1905 mHideAnimation.getDuration());
Jorim Jaggi0d674622014-05-21 01:34:15 +02001906 }
1907 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001908 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001909 }
1910
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001911 private void handleStartKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001912 Trace.beginSection("KeyguardViewMediator#handleStartKeyguardExitAnimation");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001913 if (DEBUG) Log.d(TAG, "handleStartKeyguardExitAnimation startTime=" + startTime
1914 + " fadeoutDuration=" + fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02001915 synchronized (KeyguardViewMediator.this) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001916
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001917 if (!mHiding) {
Adrian Roos6ec76b72018-04-25 14:01:11 +02001918 // Tell ActivityManager that we canceled the keyguardExitAnimation.
Lucas Dupinb3455e62019-07-11 11:47:13 +09001919 setShowingLocked(mShowing, true /* force */);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001920 return;
1921 }
1922 mHiding = false;
1923
Jorim Jaggib774e552015-08-24 14:52:45 -07001924 if (mWakeAndUnlocking && mDrawnCallback != null) {
1925
1926 // Hack level over 9000: To speed up wake-and-unlock sequence, force it to report
1927 // the next draw from here so we don't have to wait for window manager to signal
1928 // this to our ViewRootImpl.
1929 mStatusBarKeyguardViewManager.getViewRootImpl().setReportNextDraw();
1930 notifyDrawn(mDrawnCallback);
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001931 mDrawnCallback = null;
Jorim Jaggib774e552015-08-24 14:52:45 -07001932 }
1933
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001934 // only play "unlock" noises if not on a call (since the incall UI
1935 // disables the keyguard)
1936 if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) {
1937 playSounds(false);
1938 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001939
Lucas Dupinb3455e62019-07-11 11:47:13 +09001940 setShowingLocked(false);
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001941 mWakeAndUnlocking = false;
Jorim Jaggi5277dea2017-05-18 02:05:29 +02001942 mDismissCallbackRegistry.notifyDismissSucceeded();
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001943 mStatusBarKeyguardViewManager.hide(startTime, fadeoutDuration);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001944 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001945 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001946 adjustStatusBarLocked();
Jim Miller705004b2014-09-04 16:51:20 -07001947 sendUserPresentBroadcast();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001948 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001949 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001950 }
1951
Mike Lockwood5f892c12009-11-19 23:39:13 -05001952 private void adjustStatusBarLocked() {
Matthew Ng66f0b702017-12-08 12:58:42 -08001953 adjustStatusBarLocked(false /* forceHideHomeRecentsButtons */);
1954 }
1955
1956 private void adjustStatusBarLocked(boolean forceHideHomeRecentsButtons) {
Mike Lockwood5f892c12009-11-19 23:39:13 -05001957 if (mStatusBarManager == null) {
1958 mStatusBarManager = (StatusBarManager)
1959 mContext.getSystemService(Context.STATUS_BAR_SERVICE);
1960 }
Matthew Ng78ba6e22018-09-24 16:55:36 -07001961
Mike Lockwood5f892c12009-11-19 23:39:13 -05001962 if (mStatusBarManager == null) {
1963 Log.w(TAG, "Could not get status bar manager");
1964 } else {
Daniel Sandlerdba93562011-10-06 16:39:58 -04001965 // Disable aspects of the system/status/navigation bars that must not be re-enabled by
1966 // windows that appear on top, ever
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001967 int flags = StatusBarManager.DISABLE_NONE;
Matthew Ng66f0b702017-12-08 12:58:42 -08001968 if (forceHideHomeRecentsButtons || isShowingAndNotOccluded()) {
1969 flags |= StatusBarManager.DISABLE_HOME | StatusBarManager.DISABLE_RECENT;
Jorim Jaggia005f1b2014-04-16 19:06:10 +02001970 }
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001971
1972 if (DEBUG) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001973 Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mOccluded=" + mOccluded
Matthew Ng66f0b702017-12-08 12:58:42 -08001974 + " isSecure=" + isSecure() + " force=" + forceHideHomeRecentsButtons
1975 + " --> flags=0x" + Integer.toHexString(flags));
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001976 }
1977
Jorim Jaggie3e0b062017-06-12 12:18:41 -07001978 mStatusBarManager.disable(flags);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001979 }
1980 }
1981
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001982 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001983 * Handle message sent by {@link #resetStateLocked}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001984 * @see #RESET
1985 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001986 private void handleReset() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001987 synchronized (KeyguardViewMediator.this) {
1988 if (DEBUG) Log.d(TAG, "handleReset");
Jorim Jaggife762342016-10-13 14:33:27 +02001989 mStatusBarKeyguardViewManager.reset(true /* hideBouncerWhenShowing */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001990 }
1991 }
1992
1993 /**
1994 * Handle message sent by {@link #verifyUnlock}
Craig Mautner904732c2012-10-17 15:20:24 -07001995 * @see #VERIFY_UNLOCK
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001996 */
1997 private void handleVerifyUnlock() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001998 Trace.beginSection("KeyguardViewMediator#handleVerifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001999 synchronized (KeyguardViewMediator.this) {
2000 if (DEBUG) Log.d(TAG, "handleVerifyUnlock");
Lucas Dupinb3455e62019-07-11 11:47:13 +09002001 setShowingLocked(true);
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07002002 mStatusBarKeyguardViewManager.dismissAndCollapse();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002003 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002004 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002005 }
2006
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07002007 private void handleNotifyStartedGoingToSleep() {
2008 synchronized (KeyguardViewMediator.this) {
2009 if (DEBUG) Log.d(TAG, "handleNotifyStartedGoingToSleep");
2010 mStatusBarKeyguardViewManager.onStartedGoingToSleep();
2011 }
2012 }
2013
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002014 /**
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002015 * Handle message sent by {@link #notifyFinishedGoingToSleep()}
2016 * @see #NOTIFY_FINISHED_GOING_TO_SLEEP
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002017 */
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002018 private void handleNotifyFinishedGoingToSleep() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002019 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002020 if (DEBUG) Log.d(TAG, "handleNotifyFinishedGoingToSleep");
2021 mStatusBarKeyguardViewManager.onFinishedGoingToSleep();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002022 }
2023 }
2024
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002025 private void handleNotifyStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002026 Trace.beginSection("KeyguardViewMediator#handleMotifyStartedWakingUp");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002027 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002028 if (DEBUG) Log.d(TAG, "handleNotifyWakingUp");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002029 mStatusBarKeyguardViewManager.onStartedWakingUp();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002030 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002031 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002032 }
2033
2034 private void handleNotifyScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002035 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurningOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002036 synchronized (KeyguardViewMediator.this) {
2037 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurningOn");
Jorim Jaggi93739112015-08-13 15:53:14 -07002038 mStatusBarKeyguardViewManager.onScreenTurningOn();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002039 if (callback != null) {
2040 if (mWakeAndUnlocking) {
2041 mDrawnCallback = callback;
2042 } else {
2043 notifyDrawn(callback);
2044 }
2045 }
2046 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002047 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002048 }
2049
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002050 private void handleNotifyScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002051 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurnedOn");
Jorim Jaggic3fe2042016-10-07 18:52:48 +02002052 if (LatencyTracker.isEnabled(mContext)) {
2053 LatencyTracker.getInstance(mContext).onActionEnd(LatencyTracker.ACTION_TURN_ON_SCREEN);
2054 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002055 synchronized (this) {
2056 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOn");
2057 mStatusBarKeyguardViewManager.onScreenTurnedOn();
2058 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002059 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002060 }
2061
2062 private void handleNotifyScreenTurnedOff() {
2063 synchronized (this) {
2064 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOff");
Jorim Jaggie93e6f92016-08-04 13:55:39 +02002065 mDrawnCallback = null;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002066 }
2067 }
2068
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002069 private void notifyDrawn(final IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002070 Trace.beginSection("KeyguardViewMediator#notifyDrawn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002071 try {
2072 callback.onDrawn();
2073 } catch (RemoteException e) {
2074 Slog.w(TAG, "Exception calling onDrawn():", e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002075 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002076 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002077 }
Jeff Sharkey054340d2011-09-01 22:28:03 -07002078
Jorim Jaggif8d77da2014-11-11 16:59:12 +01002079 private void resetKeyguardDonePendingLocked() {
2080 mKeyguardDonePending = false;
2081 mHandler.removeMessages(KEYGUARD_DONE_PENDING_TIMEOUT);
2082 }
2083
Curtis Belmonte5cece532019-10-15 09:44:28 -07002084 private void setKeyguardGoingAway(boolean goingAway) {
2085 mUpdateMonitor.setKeyguardGoingAway(goingAway);
2086 mStatusBarWindowController.setKeyguardGoingAway(goingAway);
2087 }
2088
Jim Miller2967f482016-01-07 15:05:32 -08002089 @Override
Jim Millere5f910a2013-10-16 18:15:46 -07002090 public void onBootCompleted() {
2091 mUpdateMonitor.dispatchBootCompleted();
Jason Monkcf5a9532014-09-17 16:22:19 -04002092 synchronized (this) {
2093 mBootCompleted = true;
2094 if (mBootSendUserPresent) {
2095 sendUserPresentBroadcast();
2096 }
2097 }
Jim Millere5f910a2013-10-16 18:15:46 -07002098 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002099
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002100 public void onWakeAndUnlocking() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002101 Trace.beginSection("KeyguardViewMediator#onWakeAndUnlocking");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002102 mWakeAndUnlocking = true;
Jorim Jaggi241ae102016-11-02 21:57:33 -07002103 keyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07002104 Trace.endSection();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002105 }
2106
Jason Monk2a6ea9c2017-01-26 11:14:51 -05002107 public StatusBarKeyguardViewManager registerStatusBar(StatusBar statusBar,
Lucas Dupinbc9aac12018-03-04 20:18:15 -08002108 ViewGroup container, NotificationPanelView panelView,
Selim Cinek06c12d62019-07-01 19:44:18 -07002109 BiometricUnlockController biometricUnlockController, ViewGroup lockIconContainer,
Dave Mankoffaa8b7ae2019-09-04 18:03:21 -04002110 View notificationContainer, KeyguardBypassController bypassController) {
Lucas Dupinbc9aac12018-03-04 20:18:15 -08002111 mStatusBarKeyguardViewManager.registerStatusBar(statusBar, container, panelView,
Selim Cinek06c12d62019-07-01 19:44:18 -07002112 biometricUnlockController, mDismissCallbackRegistry, lockIconContainer,
Dave Mankoffaa8b7ae2019-09-04 18:03:21 -04002113 notificationContainer, bypassController, mFalsingManager);
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002114 return mStatusBarKeyguardViewManager;
2115 }
2116
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002117 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002118 Trace.beginSection("KeyguardViewMediator#startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002119 Message msg = mHandler.obtainMessage(START_KEYGUARD_EXIT_ANIM,
2120 new StartKeyguardExitAnimParams(startTime, fadeoutDuration));
Jorim Jaggi0d674622014-05-21 01:34:15 +02002121 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07002122 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02002123 }
2124
Andrew Zengb4045d32017-03-16 17:25:07 -07002125 public void onShortPowerPressedGoHome() {
2126 // do nothing
2127 }
2128
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002129 public ViewMediatorCallback getViewMediatorCallback() {
2130 return mViewMediatorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002131 }
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002132
Xiyuan Xia1b30f792016-01-06 08:50:30 -08002133 public LockPatternUtils getLockPatternUtils() {
2134 return mLockPatternUtils;
2135 }
2136
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002137 @Override
2138 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
2139 pw.print(" mSystemReady: "); pw.println(mSystemReady);
2140 pw.print(" mBootCompleted: "); pw.println(mBootCompleted);
2141 pw.print(" mBootSendUserPresent: "); pw.println(mBootSendUserPresent);
2142 pw.print(" mExternallyEnabled: "); pw.println(mExternallyEnabled);
Adrian Roos1f8025a2016-12-27 10:12:13 -08002143 pw.print(" mShuttingDown: "); pw.println(mShuttingDown);
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002144 pw.print(" mNeedToReshowWhenReenabled: "); pw.println(mNeedToReshowWhenReenabled);
2145 pw.print(" mShowing: "); pw.println(mShowing);
2146 pw.print(" mInputRestricted: "); pw.println(mInputRestricted);
2147 pw.print(" mOccluded: "); pw.println(mOccluded);
2148 pw.print(" mDelayedShowingSequence: "); pw.println(mDelayedShowingSequence);
2149 pw.print(" mExitSecureCallback: "); pw.println(mExitSecureCallback);
2150 pw.print(" mDeviceInteractive: "); pw.println(mDeviceInteractive);
2151 pw.print(" mGoingToSleep: "); pw.println(mGoingToSleep);
2152 pw.print(" mHiding: "); pw.println(mHiding);
Lucas Dupinb3455e62019-07-11 11:47:13 +09002153 pw.print(" mDozing: "); pw.println(mDozing);
2154 pw.print(" mAodShowing: "); pw.println(mAodShowing);
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002155 pw.print(" mWaitingUntilKeyguardVisible: "); pw.println(mWaitingUntilKeyguardVisible);
2156 pw.print(" mKeyguardDonePending: "); pw.println(mKeyguardDonePending);
2157 pw.print(" mHideAnimationRun: "); pw.println(mHideAnimationRun);
2158 pw.print(" mPendingReset: "); pw.println(mPendingReset);
2159 pw.print(" mPendingLock: "); pw.println(mPendingLock);
2160 pw.print(" mWakeAndUnlocking: "); pw.println(mWakeAndUnlocking);
2161 pw.print(" mDrawnCallback: "); pw.println(mDrawnCallback);
2162 }
2163
Lucas Dupin5a4f92c2018-07-02 13:15:23 -07002164 /**
Lucas Dupinb3455e62019-07-11 11:47:13 +09002165 * @param dozing true when AOD - or ambient mode - is showing.
Lucas Dupin5a4f92c2018-07-02 13:15:23 -07002166 */
Lucas Dupinb3455e62019-07-11 11:47:13 +09002167 public void setDozing(boolean dozing) {
2168 if (dozing == mDozing) {
2169 return;
2170 }
2171 mDozing = dozing;
2172 setShowingLocked(mShowing);
Lucas Dupin47a65c72018-02-15 14:16:18 -08002173 }
2174
Lucas Dupind35502f2018-06-27 13:35:52 -07002175 /**
2176 * @param pulsing true when device temporarily wakes up to display an incoming notification.
2177 */
2178 public void setPulsing(boolean pulsing) {
2179 mPulsing = pulsing;
2180 }
2181
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002182 private static class StartKeyguardExitAnimParams {
2183
2184 long startTime;
2185 long fadeoutDuration;
2186
2187 private StartKeyguardExitAnimParams(long startTime, long fadeoutDuration) {
2188 this.startTime = startTime;
2189 this.fadeoutDuration = fadeoutDuration;
2190 }
2191 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002192
Lucas Dupinb3455e62019-07-11 11:47:13 +09002193 private void setShowingLocked(boolean showing) {
2194 setShowingLocked(showing, false /* forceCallbacks */);
Jorim Jaggie8f321e2016-11-07 16:48:31 -08002195 }
2196
Lucas Dupinb3455e62019-07-11 11:47:13 +09002197 private void setShowingLocked(boolean showing, boolean forceCallbacks) {
2198 final boolean aodShowing = mDozing && !mWakeAndUnlocking;
Lucas Dupin47a65c72018-02-15 14:16:18 -08002199 final boolean notifyDefaultDisplayCallbacks = showing != mShowing
2200 || aodShowing != mAodShowing || forceCallbacks;
Lucas Dupinb3455e62019-07-11 11:47:13 +09002201 mShowing = showing;
2202 mAodShowing = aodShowing;
wilsonshih177261f2019-02-22 12:02:18 +08002203 if (notifyDefaultDisplayCallbacks) {
Lucas Dupinb3455e62019-07-11 11:47:13 +09002204 notifyDefaultDisplayCallbacks(showing);
wilsonshih177261f2019-02-22 12:02:18 +08002205 updateActivityLockScreenState(showing, aodShowing);
David Stevens53a39ea2017-08-23 18:41:49 -07002206 }
2207 }
2208
2209 private void notifyDefaultDisplayCallbacks(boolean showing) {
Lucas Dupin8968f6a2019-08-09 17:41:15 -07002210 // TODO(b/140053364)
2211 whitelistIpcs(() -> {
2212 int size = mKeyguardStateCallbacks.size();
2213 for (int i = size - 1; i >= 0; i--) {
2214 IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
2215 try {
2216 callback.onShowingStateChanged(showing);
2217 } catch (RemoteException e) {
2218 Slog.w(TAG, "Failed to call onShowingStateChanged", e);
2219 if (e instanceof DeadObjectException) {
2220 mKeyguardStateCallbacks.remove(callback);
2221 }
Jim Millerab954542014-10-10 18:21:49 -07002222 }
Jim Millerab954542014-10-10 18:21:49 -07002223 }
Lucas Dupin8968f6a2019-08-09 17:41:15 -07002224 });
David Stevens53a39ea2017-08-23 18:41:49 -07002225 updateInputRestrictedLocked();
2226 mUiOffloadThread.submit(() -> {
2227 mTrustManager.reportKeyguardShowingChanged();
2228 });
Adrian Roos481a6df2014-11-20 19:48:56 +01002229 }
Jim Millerab954542014-10-10 18:21:49 -07002230
Adrian Roosd88eb262016-08-04 14:50:48 -07002231 private void notifyTrustedChangedLocked(boolean trusted) {
2232 int size = mKeyguardStateCallbacks.size();
2233 for (int i = size - 1; i >= 0; i--) {
2234 try {
2235 mKeyguardStateCallbacks.get(i).onTrustedChanged(trusted);
2236 } catch (RemoteException e) {
2237 Slog.w(TAG, "Failed to call notifyTrustedChangedLocked", e);
2238 if (e instanceof DeadObjectException) {
2239 mKeyguardStateCallbacks.remove(i);
2240 }
2241 }
2242 }
2243 }
2244
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002245 private void notifyHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
2246 int size = mKeyguardStateCallbacks.size();
2247 for (int i = size - 1; i >= 0; i--) {
2248 try {
2249 mKeyguardStateCallbacks.get(i).onHasLockscreenWallpaperChanged(
2250 hasLockscreenWallpaper);
2251 } catch (RemoteException e) {
2252 Slog.w(TAG, "Failed to call onHasLockscreenWallpaperChanged", e);
2253 if (e instanceof DeadObjectException) {
2254 mKeyguardStateCallbacks.remove(i);
2255 }
2256 }
2257 }
2258 }
2259
Jim Millerab954542014-10-10 18:21:49 -07002260 public void addStateMonitorCallback(IKeyguardStateCallback callback) {
2261 synchronized (this) {
2262 mKeyguardStateCallbacks.add(callback);
2263 try {
2264 callback.onSimSecureStateChanged(mUpdateMonitor.isSimPinSecure());
2265 callback.onShowingStateChanged(mShowing);
Adrian Roos4a963ac2015-04-24 16:04:53 -07002266 callback.onInputRestrictedStateChanged(mInputRestricted);
Adrian Roosd88eb262016-08-04 14:50:48 -07002267 callback.onTrustedChanged(mUpdateMonitor.getUserHasTrust(
2268 KeyguardUpdateMonitor.getCurrentUser()));
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002269 callback.onHasLockscreenWallpaperChanged(mUpdateMonitor.hasLockscreenWallpaper());
Jim Millerab954542014-10-10 18:21:49 -07002270 } catch (RemoteException e) {
Adrian Roosd88eb262016-08-04 14:50:48 -07002271 Slog.w(TAG, "Failed to call to IKeyguardStateCallback", e);
Jim Millerab954542014-10-10 18:21:49 -07002272 }
2273 }
2274 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08002275
2276 private static class DismissMessage {
2277 private final CharSequence mMessage;
2278 private final IKeyguardDismissCallback mCallback;
2279
2280 DismissMessage(IKeyguardDismissCallback callback, CharSequence message) {
2281 mCallback = callback;
2282 mMessage = message;
2283 }
2284
2285 public IKeyguardDismissCallback getCallback() {
2286 return mCallback;
2287 }
2288
2289 public CharSequence getMessage() {
2290 return mMessage;
2291 }
2292 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002293}