blob: 6809e76c18e381369a99a2fd88782927f4b97520 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002 * Copyright (C) 2014 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
Jorim Jaggi5cf17872014-03-26 18:31:48 +010014 * limitations under the License
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080015 */
16
Jorim Jaggi5cf17872014-03-26 18:31:48 +010017package com.android.systemui.keyguard;
Jim Millerbc4603b2010-08-30 21:21:34 -070018
Jorim Jaggid11d1a92016-08-16 16:02:32 -070019import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
David Stevens53a39ea2017-08-23 18:41:49 -070020import static android.view.Display.INVALID_DISPLAY;
Adrian Roose92de952016-12-13 12:07:09 -080021
22import static com.android.internal.telephony.IccCardConstants.State.ABSENT;
Jorim Jaggid11d1a92016-08-16 16:02:32 -070023import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST;
24import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW;
25import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT;
Michal Karpinskic52f8672016-11-18 11:32:45 +000026import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT;
Jorim Jaggid11d1a92016-08-16 16:02:32 -070027
Adrian Roosb60d47c2014-09-08 19:23:00 +020028import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080029import android.app.AlarmManager;
30import android.app.PendingIntent;
Mike Lockwood5f892c12009-11-19 23:39:13 -050031import android.app.StatusBarManager;
Adrian Roos481a6df2014-11-20 19:48:56 +010032import android.app.trust.TrustManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080033import android.content.BroadcastReceiver;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -050034import android.content.ContentResolver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080035import android.content.Context;
36import android.content.Intent;
37import android.content.IntentFilter;
Adrian Roosbe47b072014-09-03 00:08:56 +020038import android.content.pm.UserInfo;
Daniel Sandleraec967a2010-02-20 01:05:22 -050039import android.media.AudioManager;
Marco Nelissend5545bd2011-09-29 12:49:17 -070040import android.media.SoundPool;
Adam Cohenf7522022012-10-03 20:03:18 -070041import android.os.Bundle;
dooyoung.hwang328472e2015-05-21 16:09:43 +090042import android.os.DeadObjectException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080043import android.os.Handler;
Jeff Brown109025d2012-08-14 20:41:30 -070044import android.os.Looper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080045import android.os.Message;
46import android.os.PowerManager;
Dianne Hackborn4994c662009-09-23 22:21:23 -070047import android.os.RemoteException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080048import android.os.SystemClock;
Jim Miller1b152022009-10-28 16:08:15 -070049import android.os.SystemProperties;
Nick Desaulniers1d396752016-07-25 15:05:33 -070050import android.os.Trace;
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -070051import android.os.UserHandle;
Amith Yamasanib70ff9a2012-09-07 18:28:11 -070052import android.os.UserManager;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -050053import android.provider.Settings;
Jim Miller52a61332014-11-12 19:29:51 -080054import android.telephony.SubscriptionManager;
Karl Rosaenab100082009-03-24 22:35:17 -070055import android.telephony.TelephonyManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080056import android.util.EventLog;
Karl Rosaenab100082009-03-24 22:35:17 -070057import android.util.Log;
Jim Miller25190572013-02-28 17:36:24 -080058import android.util.Slog;
Jorim Jaggib690f0d2014-07-03 23:25:44 +020059import android.view.ViewGroup;
Adrian Roose99bc052017-11-20 17:55:31 +010060import android.view.WindowManagerPolicyConstants;
Adrian Roos0002a452014-07-03 13:46:07 +020061import android.view.animation.Animation;
62import android.view.animation.AnimationUtils;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -070063
Adrian Roos1cffe3c2016-11-28 15:46:06 -080064import com.android.internal.logging.MetricsLogger;
65import com.android.internal.logging.nano.MetricsProto;
Jorim Jaggi241ae102016-11-02 21:57:33 -070066import com.android.internal.policy.IKeyguardDismissCallback;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -070067import com.android.internal.policy.IKeyguardDrawnCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010068import com.android.internal.policy.IKeyguardExitCallback;
Jim Millerab954542014-10-10 18:21:49 -070069import com.android.internal.policy.IKeyguardStateCallback;
Adam Cohenf7522022012-10-03 20:03:18 -070070import com.android.internal.telephony.IccCardConstants;
71import com.android.internal.widget.LockPatternUtils;
Jim Miller52a61332014-11-12 19:29:51 -080072import com.android.keyguard.KeyguardConstants;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010073import com.android.keyguard.KeyguardDisplayManager;
Selim Cinek3122fa82015-06-18 01:38:59 -070074import com.android.keyguard.KeyguardSecurityView;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010075import com.android.keyguard.KeyguardUpdateMonitor;
76import com.android.keyguard.KeyguardUpdateMonitorCallback;
Jason Monkea03be12017-12-04 11:08:41 -050077import com.android.internal.util.LatencyTracker;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010078import com.android.keyguard.ViewMediatorCallback;
Jorim Jaggie549a8d2017-05-15 02:40:05 +020079import com.android.systemui.Dependency;
Jorim Jaggicff0acb2014-03-31 16:35:15 +020080import com.android.systemui.SystemUI;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080081import com.android.systemui.SystemUIFactory;
Jorim Jaggie549a8d2017-05-15 02:40:05 +020082import com.android.systemui.UiOffloadThread;
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -070083import com.android.systemui.classifier.FalsingManager;
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -070084import com.android.systemui.statusbar.phone.FingerprintUnlockController;
Lucas Dupinbc9aac12018-03-04 20:18:15 -080085import com.android.systemui.statusbar.phone.NotificationPanelView;
Jason Monk2a6ea9c2017-01-26 11:14:51 -050086import com.android.systemui.statusbar.phone.StatusBar;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010087import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
Adrian Roos58b58fe2014-01-31 16:00:39 -080088
Jorim Jaggi84dc08a2015-09-11 17:45:22 -070089import java.io.FileDescriptor;
90import java.io.PrintWriter;
Jim Millerab954542014-10-10 18:21:49 -070091import java.util.ArrayList;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010092
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080093/**
94 * Mediates requests related to the keyguard. This includes queries about the
95 * state of the keyguard, power management events that effect whether the keyguard
96 * should be shown or reset, callbacks to the phone window manager to notify
97 * it of when the keyguard is showing, and events from the keyguard view itself
98 * stating that the keyguard was succesfully unlocked.
99 *
100 * Note that the keyguard view is shown when the screen is off (as appropriate)
101 * so that once the screen comes on, it will be ready immediately.
102 *
103 * Example queries about the keyguard:
104 * - is {movement, key} one that should wake the keygaurd?
105 * - is the keyguard showing?
106 * - are input events restricted due to the state of the keyguard?
107 *
108 * Callbacks to the phone window manager:
109 * - the keyguard is showing
110 *
111 * Example external events that translate to keyguard view changes:
112 * - screen turned off -> reset the keyguard, and show it so it will be ready
113 * next time the screen turns on
114 * - keyboard is slid open -> if the keyguard is not secure, hide it
115 *
116 * Events from the keyguard view:
117 * - user succesfully unlocked keyguard -> hide keyguard view, and no longer
118 * restrict input events.
119 *
120 * Note: in addition to normal power managment events that effect the state of
121 * whether the keyguard should be showing, external apps and services may request
122 * that the keyguard be disabled via {@link #setKeyguardEnabled(boolean)}. When
123 * false, this will override all other conditions for turning on the keyguard.
124 *
125 * Threading and synchronization:
Adrian Roose99bc052017-11-20 17:55:31 +0100126 * This class is created by the initialization routine of the {@link WindowManagerPolicyConstants},
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800127 * and runs on its thread. The keyguard UI is created from that thread in the
128 * constructor of this class. The apis may be called from other threads, including the
Jeff Brown4532e612012-04-05 14:27:12 -0700129 * {@link com.android.server.input.InputManagerService}'s and {@link android.view.WindowManager}'s.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800130 * Therefore, methods on this class are synchronized, and any action that is pointed
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100131 * directly to the keyguard UI is posted to a {@link android.os.Handler} to ensure it is taken on the UI
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800132 * thread of the keyguard.
133 */
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200134public class KeyguardViewMediator extends SystemUI {
Jim Millerbc4603b2010-08-30 21:21:34 -0700135 private static final int KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT = 30000;
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100136 private static final long KEYGUARD_DONE_PENDING_TIMEOUT_MS = 3000;
137
Jim Miller52a61332014-11-12 19:29:51 -0800138 private static final boolean DEBUG = KeyguardConstants.DEBUG;
139 private static final boolean DEBUG_SIM_STATES = KeyguardConstants.DEBUG_SIM_STATES;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800140
141 private final static String TAG = "KeyguardViewMediator";
142
Jim Miller9c20d0e2010-01-20 15:00:23 -0800143 private static final String DELAYED_KEYGUARD_ACTION =
Wink Saville37c124c2009-04-02 01:37:02 -0700144 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD";
Clara Bayarri56878a92015-10-29 15:43:55 +0000145 private static final String DELAYED_LOCK_PROFILE_ACTION =
146 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_LOCK";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800147
Kevin Chyn18e91aa2018-04-11 12:55:45 -0700148 private static final String SYSTEMUI_PERMISSION = "com.android.systemui.permission.SELF";
149
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800150 // used for handler messages
Jorim Jaggi8d786932016-10-26 19:08:36 -0700151 private static final int SHOW = 1;
152 private static final int HIDE = 2;
153 private static final int RESET = 3;
154 private static final int VERIFY_UNLOCK = 4;
155 private static final int NOTIFY_FINISHED_GOING_TO_SLEEP = 5;
156 private static final int NOTIFY_SCREEN_TURNING_ON = 6;
157 private static final int KEYGUARD_DONE = 7;
158 private static final int KEYGUARD_DONE_DRAWING = 8;
159 private static final int SET_OCCLUDED = 9;
160 private static final int KEYGUARD_TIMEOUT = 10;
161 private static final int DISMISS = 11;
162 private static final int START_KEYGUARD_EXIT_ANIM = 12;
163 private static final int KEYGUARD_DONE_PENDING_TIMEOUT = 13;
164 private static final int NOTIFY_STARTED_WAKING_UP = 14;
165 private static final int NOTIFY_SCREEN_TURNED_ON = 15;
166 private static final int NOTIFY_SCREEN_TURNED_OFF = 16;
167 private static final int NOTIFY_STARTED_GOING_TO_SLEEP = 17;
Adrian Roos30a2ae62018-04-25 19:09:50 +0200168 private static final int SYSTEM_READY = 18;
Jim Miller9c20d0e2010-01-20 15:00:23 -0800169
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800170 /**
171 * The default amount of time we stay awake (used for all key input)
172 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100173 public static final int AWAKE_INTERVAL_DEFAULT_MS = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800174
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800175 /**
176 * How long to wait after the screen turns off due to timeout before
177 * turning on the keyguard (i.e, the user has this much time to turn
178 * the screen back on without having to face the keyguard).
179 */
Jim Millerbc4603b2010-08-30 21:21:34 -0700180 private static final int KEYGUARD_LOCK_AFTER_DELAY_DEFAULT = 5000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800181
182 /**
Craig Mautnerf1b67412012-09-19 13:18:29 -0700183 * How long we'll wait for the {@link ViewMediatorCallback#keyguardDoneDrawing()}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800184 * callback before unblocking a call to {@link #setKeyguardEnabled(boolean)}
185 * that is reenabling the keyguard.
186 */
187 private static final int KEYGUARD_DONE_DRAWING_TIMEOUT_MS = 2000;
Jim Miller9c20d0e2010-01-20 15:00:23 -0800188
Daniel Sandler74d188c2011-08-10 00:00:31 -0400189 /**
Evan Rosky13a58a92016-07-27 15:51:09 -0700190 * Boolean option for doKeyguardLocked/doKeyguardTimeout which, when set to true, forces the
191 * keyguard to show even if it is disabled for the current user.
192 */
193 public static final String OPTION_FORCE_SHOW = "force_show";
194
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700195 /** The stream type that the lock sounds are tied to. */
John Spurlockee5ad722015-03-03 16:17:21 -0500196 private int mUiSoundsStreamType;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700197
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800198 private AlarmManager mAlarmManager;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700199 private AudioManager mAudioManager;
Mike Lockwood5f892c12009-11-19 23:39:13 -0500200 private StatusBarManager mStatusBarManager;
Jorim Jaggie549a8d2017-05-15 02:40:05 +0200201 private final UiOffloadThread mUiOffloadThread = Dependency.get(UiOffloadThread.class);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800202
203 private boolean mSystemReady;
Jason Monkcf5a9532014-09-17 16:22:19 -0400204 private boolean mBootCompleted;
205 private boolean mBootSendUserPresent;
Adrian Roos1f8025a2016-12-27 10:12:13 -0800206 private boolean mShuttingDown;
Daniel Sandler0060a9b2010-03-15 23:09:57 -0400207
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800208 /** High level access to the power manager for WakeLocks */
209 private PowerManager mPM;
210
Adrian Roos481a6df2014-11-20 19:48:56 +0100211 /** TrustManager for letting it know when we change visibility */
212 private TrustManager mTrustManager;
Amith Yamasanib70ff9a2012-09-07 18:28:11 -0700213
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800214 /**
Mike Lockwood674d3e42009-10-06 09:28:54 -0400215 * Used to keep the device awake while to ensure the keyguard finishes opening before
216 * we sleep.
217 */
218 private PowerManager.WakeLock mShowKeyguardWakeLock;
219
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100220 private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800221
222 // these are protected by synchronized (this)
223
224 /**
Mike Lockwood5d258b62009-12-02 13:50:45 -0500225 * External apps (like the phone app) can tell us to disable the keygaurd.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800226 */
227 private boolean mExternallyEnabled = true;
228
229 /**
230 * Remember if an external call to {@link #setKeyguardEnabled} with value
231 * false caused us to hide the keyguard, so that we need to reshow it once
232 * the keygaurd is reenabled with another call with value true.
233 */
234 private boolean mNeedToReshowWhenReenabled = false;
235
236 // cached value of whether we are showing (need to know this to quickly
237 // answer whether the input should be restricted)
Jim Millere5f17ab2013-11-13 15:40:48 -0800238 private boolean mShowing;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800239
Lucas Dupin47a65c72018-02-15 14:16:18 -0800240 // AOD is enabled and status bar is in AOD state.
241 private boolean mAodShowing;
242
David Stevens53a39ea2017-08-23 18:41:49 -0700243 // display id of the secondary display on which we have put a keyguard window
244 private int mSecondaryDisplayShowing = INVALID_DISPLAY;
245
Jim Millerab954542014-10-10 18:21:49 -0700246 /** Cached value of #isInputRestricted */
247 private boolean mInputRestricted;
248
Mike Lockwood09a40402009-11-08 00:33:23 -0500249 // true if the keyguard is hidden by another window
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100250 private boolean mOccluded = false;
Mike Lockwood09a40402009-11-08 00:33:23 -0500251
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800252 /**
253 * Helps remember whether the screen has turned on since the last time
254 * it turned off due to timeout. see {@link #onScreenTurnedOff(int)}
255 */
256 private int mDelayedShowingSequence;
257
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800258 /**
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000259 * Simiar to {@link #mDelayedProfileShowingSequence}, but it is for profile case.
260 */
261 private int mDelayedProfileShowingSequence;
262
263 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800264 * If the user has disabled the keyguard, then requests to exit, this is
265 * how we'll ultimately let them know whether it was successful. We use this
266 * var being non-null as an indicator that there is an in progress request.
267 */
Jim Miller25190572013-02-28 17:36:24 -0800268 private IKeyguardExitCallback mExitSecureCallback;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700269 private final DismissCallbackRegistry mDismissCallbackRegistry = new DismissCallbackRegistry();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800270
271 // the properties of the keyguard
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800272
273 private KeyguardUpdateMonitor mUpdateMonitor;
274
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700275 private boolean mDeviceInteractive;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700276 private boolean mGoingToSleep;
Karl Rosaenab100082009-03-24 22:35:17 -0700277
Daniel Sandlerf2d8e742010-02-22 13:09:48 -0500278 // last known state of the cellular connection
279 private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE;
280
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800281 /**
Jorim Jaggi53c68a42014-06-17 15:04:47 -0700282 * Whether a hide is pending an we are just waiting for #startKeyguardExitAnimation to be
283 * called.
284 * */
285 private boolean mHiding;
286
287 /**
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700288 * we send this intent when the keyguard is dismissed.
289 */
Jim Miller17f509a2013-02-28 18:36:12 -0800290 private static final Intent USER_PRESENT_INTENT = new Intent(Intent.ACTION_USER_PRESENT)
291 .addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
Chad Brubaker291df4f2017-03-14 10:23:02 -0700292 | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
293 | Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700294
295 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800296 * {@link #setKeyguardEnabled} waits on this condition when it reenables
297 * the keyguard.
298 */
299 private boolean mWaitingUntilKeyguardVisible = false;
Jim Millerbc4603b2010-08-30 21:21:34 -0700300 private LockPatternUtils mLockPatternUtils;
John Spurlock34c4fe52012-11-07 10:12:29 -0500301 private boolean mKeyguardDonePending = false;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200302 private boolean mHideAnimationRun = false;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700303 private boolean mHideAnimationRunning = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800304
Marco Nelissend5545bd2011-09-29 12:49:17 -0700305 private SoundPool mLockSounds;
306 private int mLockSoundId;
307 private int mUnlockSoundId;
Adrian Roos49e057d2014-08-13 17:14:51 +0200308 private int mTrustedSoundId;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700309 private int mLockSoundStreamId;
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700310
311 /**
Adrian Roos0002a452014-07-03 13:46:07 +0200312 * The animation used for hiding keyguard. This is used to fetch the animation timings if
313 * WindowManager is not providing us with them.
314 */
315 private Animation mHideAnimation;
316
317 /**
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700318 * The volume applied to the lock/unlock sounds.
319 */
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200320 private float mLockSoundVolume;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700321
Jim Millerdcb3d842012-08-23 19:18:12 -0700322 /**
Jim Miller31921482013-11-06 20:43:55 -0800323 * For managing external displays
324 */
325 private KeyguardDisplayManager mKeyguardDisplayManager;
326
Jim Millerab954542014-10-10 18:21:49 -0700327 private final ArrayList<IKeyguardStateCallback> mKeyguardStateCallbacks = new ArrayList<>();
328
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700329 /**
330 * When starting going to sleep, we figured out that we need to reset Keyguard state and this
331 * should be committed when finished going to sleep.
332 */
333 private boolean mPendingReset;
334
335 /**
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700336 * 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 -0700337 * committed when finished going to sleep.
338 */
339 private boolean mPendingLock;
340
Robin Leec41f6ec2017-01-10 17:02:34 +0000341 /**
342 * Controller for showing individual "work challenge" lock screen windows inside managed profile
343 * tasks when the current user has been unlocked but the profile is still locked.
344 */
345 private WorkLockActivityController mWorkLockController;
346
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000347 private boolean mLockLater;
348
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700349 private boolean mWakeAndUnlocking;
350 private IKeyguardDrawnCallback mDrawnCallback;
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800351 private boolean mLockWhenSimRemoved;
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800352 private CharSequence mCustomMessage;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700353
Jim Millerbbf1a742012-07-17 18:30:30 -0700354 KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {
355
356 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500357 public void onUserSwitching(int userId) {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700358 // Note that the mLockPatternUtils user has already been updated from setCurrentUser.
Adam Cohenf7522022012-10-03 20:03:18 -0700359 // We need to force a reset of the views, since lockNow (called by
360 // ActivityManagerService) will not reconstruct the keyguard if it is already showing.
Jim Millerbbf1a742012-07-17 18:30:30 -0700361 synchronized (KeyguardViewMediator.this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100362 resetKeyguardDonePendingLocked();
Alex Chau77ef9fc2018-04-11 15:41:32 +0100363 if (mLockPatternUtils.isLockScreenDisabled(userId)) {
364 // If we switching to a user that has keyguard disabled, dismiss keyguard.
365 dismiss(null /* callback */, null /* message */);
366 } else {
367 resetStateLocked();
368 }
John Spurlock4e6922d2012-10-04 14:51:51 -0400369 adjustStatusBarLocked();
Dianne Hackborn5dc5a002012-09-15 19:33:48 -0700370 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700371 }
372
373 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500374 public void onUserSwitchComplete(int userId) {
Xiaohui Chen87d0e252015-07-30 15:38:16 -0700375 if (userId != UserHandle.USER_SYSTEM) {
Adrian Roosbe47b072014-09-03 00:08:56 +0200376 UserInfo info = UserManager.get(mContext).getUserInfo(userId);
Kevin Chynf2c0a642017-05-25 11:29:08 -0700377 // Don't try to dismiss if the user has Pin/Patter/Password set
378 if (info == null || mLockPatternUtils.isSecure(userId)) {
379 return;
380 } else if (info.isGuest() || info.isDemo()) {
Adrian Roosbe47b072014-09-03 00:08:56 +0200381 // If we just switched to a guest, try to dismiss keyguard.
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800382 dismiss(null /* callback */, null /* message */);
Adrian Roosbe47b072014-09-03 00:08:56 +0200383 }
384 }
Chris Wrenf41c61b2012-11-29 15:19:54 -0500385 }
386
387 @Override
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -0700388 public void onUserInfoChanged(int userId) {
Jim Millerbbf1a742012-07-17 18:30:30 -0700389 }
390
391 @Override
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100392 public void onPhoneStateChanged(int phoneState) {
Jim Millerbbf1a742012-07-17 18:30:30 -0700393 synchronized (KeyguardViewMediator.this) {
394 if (TelephonyManager.CALL_STATE_IDLE == phoneState // call ending
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700395 && !mDeviceInteractive // screen off
Jim Millerbbf1a742012-07-17 18:30:30 -0700396 && mExternallyEnabled) { // not disabled by any app
397
398 // note: this is a way to gracefully reenable the keyguard when the call
399 // ends and the screen is off without always reenabling the keyguard
400 // each time the screen turns off while in call (and having an occasional ugly
401 // flicker while turning back on the screen and disabling the keyguard again).
402 if (DEBUG) Log.d(TAG, "screen is off and call ended, let's make sure the "
403 + "keyguard is showing");
Jim Miller5ecd8112013-01-09 18:50:26 -0800404 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700405 }
406 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100407 }
Jim Millerb0304762012-03-13 20:01:25 -0700408
409 @Override
410 public void onClockVisibilityChanged() {
411 adjustStatusBarLocked();
412 }
413
414 @Override
415 public void onDeviceProvisioned() {
Jim Miller3fd47af2012-09-21 19:55:27 -0700416 sendUserPresentBroadcast();
Amith Yamasanicb15d662015-11-10 11:11:15 -0800417 synchronized (KeyguardViewMediator.this) {
418 // If system user is provisioned, we might want to lock now to avoid showing launcher
Amith Yamasanieb437d42016-04-29 09:31:25 -0700419 if (mustNotUnlockCurrentUser()) {
Amith Yamasanicb15d662015-11-10 11:11:15 -0800420 doKeyguardLocked(null);
421 }
422 }
Jim Millerb0304762012-03-13 20:01:25 -0700423 }
424
Jim Millerbbf1a742012-07-17 18:30:30 -0700425 @Override
Jim Miller52a61332014-11-12 19:29:51 -0800426 public void onSimStateChanged(int subId, int slotId, IccCardConstants.State simState) {
427
428 if (DEBUG_SIM_STATES) {
429 Log.d(TAG, "onSimStateChanged(subId=" + subId + ", slotId=" + slotId
430 + ",state=" + simState + ")");
431 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700432
dooyoung.hwang328472e2015-05-21 16:09:43 +0900433 int size = mKeyguardStateCallbacks.size();
434 boolean simPinSecure = mUpdateMonitor.isSimPinSecure();
435 for (int i = size - 1; i >= 0; i--) {
436 try {
Jim Millerab954542014-10-10 18:21:49 -0700437 mKeyguardStateCallbacks.get(i).onSimSecureStateChanged(simPinSecure);
dooyoung.hwang328472e2015-05-21 16:09:43 +0900438 } catch (RemoteException e) {
439 Slog.w(TAG, "Failed to call onSimSecureStateChanged", e);
440 if (e instanceof DeadObjectException) {
441 mKeyguardStateCallbacks.remove(i);
442 }
Jim Millerab954542014-10-10 18:21:49 -0700443 }
Jim Millerab954542014-10-10 18:21:49 -0700444 }
445
Jim Millerbbf1a742012-07-17 18:30:30 -0700446 switch (simState) {
447 case NOT_READY:
448 case ABSENT:
449 // only force lock screen in case of missing sim if user hasn't
450 // gone through setup wizard
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800451 synchronized (KeyguardViewMediator.this) {
Jim Millerb256e4e22014-10-31 17:27:13 -0700452 if (shouldWaitForProvisioning()) {
Jim Millerab954542014-10-10 18:21:49 -0700453 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800454 if (DEBUG_SIM_STATES) Log.d(TAG, "ICC_ABSENT isn't showing,"
Jim Millerbbf1a742012-07-17 18:30:30 -0700455 + " we need to show the keyguard since the "
456 + "device isn't provisioned yet.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800457 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700458 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100459 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700460 }
461 }
Adrian Roose92de952016-12-13 12:07:09 -0800462 if (simState == ABSENT) {
463 // MVNO SIMs can become transiently NOT_READY when switching networks,
464 // so we should only lock when they are ABSENT.
465 onSimAbsentLocked();
466 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700467 }
468 break;
469 case PIN_REQUIRED:
470 case PUK_REQUIRED:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800471 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700472 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800473 if (DEBUG_SIM_STATES) Log.d(TAG,
474 "INTENT_VALUE_ICC_LOCKED and keygaurd isn't "
Jim Millerbbf1a742012-07-17 18:30:30 -0700475 + "showing; need to show keyguard so user can enter sim pin");
Jim Miller5ecd8112013-01-09 18:50:26 -0800476 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700477 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100478 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700479 }
480 }
481 break;
482 case PERM_DISABLED:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800483 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700484 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800485 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED and "
Jim Millerbbf1a742012-07-17 18:30:30 -0700486 + "keygaurd isn't showing.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800487 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700488 } else {
Jim Miller52a61332014-11-12 19:29:51 -0800489 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED, resetStateLocked to"
Jim Millerbbf1a742012-07-17 18:30:30 -0700490 + "show permanently disabled message in lockscreen.");
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100491 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700492 }
Adrian Roose92de952016-12-13 12:07:09 -0800493 onSimAbsentLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700494 }
495 break;
496 case READY:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800497 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700498 if (mShowing) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100499 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700500 }
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800501 mLockWhenSimRemoved = true;
Jim Millerbbf1a742012-07-17 18:30:30 -0700502 }
503 break;
Jim Miller52a61332014-11-12 19:29:51 -0800504 default:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800505 if (DEBUG_SIM_STATES) Log.v(TAG, "Unspecific state: " + simState);
Jim Miller52a61332014-11-12 19:29:51 -0800506 break;
Jim Millerbbf1a742012-07-17 18:30:30 -0700507 }
508 }
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000509
Adrian Roose92de952016-12-13 12:07:09 -0800510 private void onSimAbsentLocked() {
Adrian Roos1f8025a2016-12-27 10:12:13 -0800511 if (isSecure() && mLockWhenSimRemoved && !mShuttingDown) {
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800512 mLockWhenSimRemoved = false;
513 MetricsLogger.action(mContext,
514 MetricsProto.MetricsEvent.ACTION_LOCK_BECAUSE_SIM_REMOVED, mShowing);
515 if (!mShowing) {
Adrian Roose92de952016-12-13 12:07:09 -0800516 Log.i(TAG, "SIM removed, showing keyguard");
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800517 doKeyguardLocked(null);
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800518 }
519 }
520 }
521
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000522 @Override
523 public void onFingerprintAuthFailed() {
524 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
525 if (mLockPatternUtils.isSecure(currentUser)) {
526 mLockPatternUtils.getDevicePolicyManager().reportFailedFingerprintAttempt(
527 currentUser);
528 }
529 }
530
531 @Override
532 public void onFingerprintAuthenticated(int userId) {
533 if (mLockPatternUtils.isSecure(userId)) {
534 mLockPatternUtils.getDevicePolicyManager().reportSuccessfulFingerprintAttempt(
535 userId);
536 }
537 }
Adrian Roosd88eb262016-08-04 14:50:48 -0700538
539 @Override
540 public void onTrustChanged(int userId) {
541 if (userId == KeyguardUpdateMonitor.getCurrentUser()) {
542 synchronized (KeyguardViewMediator.this) {
543 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(userId));
544 }
545 }
546 }
547
Jorim Jaggid11d1a92016-08-16 16:02:32 -0700548 @Override
549 public void onHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
550 synchronized (KeyguardViewMediator.this) {
551 notifyHasLockscreenWallpaperChanged(hasLockscreenWallpaper);
552 }
553 }
Jim Millerb0304762012-03-13 20:01:25 -0700554 };
555
Jim Millerdcb3d842012-08-23 19:18:12 -0700556 ViewMediatorCallback mViewMediatorCallback = new ViewMediatorCallback() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100557
Jim Miller2967f482016-01-07 15:05:32 -0800558 @Override
Jeff Brownc7505bc2012-10-05 21:58:15 -0700559 public void userActivity() {
560 KeyguardViewMediator.this.userActivity();
561 }
562
Jim Miller2967f482016-01-07 15:05:32 -0800563 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700564 public void keyguardDone(boolean strongAuth, int targetUserId) {
565 if (targetUserId != ActivityManager.getCurrentUser()) {
566 return;
567 }
568
Jorim Jaggi241ae102016-11-02 21:57:33 -0700569 tryKeyguardDone();
Jim Millerdcb3d842012-08-23 19:18:12 -0700570 }
571
Jim Miller2967f482016-01-07 15:05:32 -0800572 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700573 public void keyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700574 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDoneDrawing");
Jim Millerdcb3d842012-08-23 19:18:12 -0700575 mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700576 Trace.endSection();
Jim Millerdcb3d842012-08-23 19:18:12 -0700577 }
578
579 @Override
580 public void setNeedsInput(boolean needsInput) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100581 mStatusBarKeyguardViewManager.setNeedsInput(needsInput);
Jim Millerdcb3d842012-08-23 19:18:12 -0700582 }
Jeff Brownc7505bc2012-10-05 21:58:15 -0700583
584 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700585 public void keyguardDonePending(boolean strongAuth, int targetUserId) {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700586 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDonePending");
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700587 if (targetUserId != ActivityManager.getCurrentUser()) {
Nick Desaulniersaeb2e1e2016-07-27 15:36:01 -0700588 Trace.endSection();
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700589 return;
590 }
591
John Spurlock34c4fe52012-11-07 10:12:29 -0500592 mKeyguardDonePending = true;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200593 mHideAnimationRun = true;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700594 mHideAnimationRunning = true;
595 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100596 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_PENDING_TIMEOUT,
597 KEYGUARD_DONE_PENDING_TIMEOUT_MS);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700598 Trace.endSection();
John Spurlock34c4fe52012-11-07 10:12:29 -0500599 }
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800600
601 @Override
602 public void keyguardGone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700603 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardGone");
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800604 mKeyguardDisplayManager.hide();
Nick Desaulniers1d396752016-07-25 15:05:33 -0700605 Trace.endSection();
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800606 }
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200607
608 @Override
609 public void readyForKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700610 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#readyForKeyguardDone");
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200611 if (mKeyguardDonePending) {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700612 mKeyguardDonePending = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700613 tryKeyguardDone();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200614 }
Nick Desaulniers1d396752016-07-25 15:05:33 -0700615 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200616 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200617
618 @Override
Andrew Lee72b46d42015-01-30 13:23:21 -0800619 public void resetKeyguard() {
620 resetStateLocked();
621 }
622
623 @Override
Matthew Ng66f0b702017-12-08 12:58:42 -0800624 public void onBouncerVisiblityChanged(boolean shown) {
625 synchronized (KeyguardViewMediator.this) {
626 adjustStatusBarLocked(shown);
627 }
628 }
629
630 @Override
Adrian Roos49e057d2014-08-13 17:14:51 +0200631 public void playTrustedSound() {
632 KeyguardViewMediator.this.playTrustedSound();
633 }
Jim Millerab954542014-10-10 18:21:49 -0700634
635 @Override
Adrian Roos94e15a52015-04-16 12:23:18 -0700636 public boolean isScreenOn() {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700637 return mDeviceInteractive;
Adrian Roos94e15a52015-04-16 12:23:18 -0700638 }
Selim Cinek3122fa82015-06-18 01:38:59 -0700639
640 @Override
641 public int getBouncerPromptReason() {
642 int currentUser = ActivityManager.getCurrentUser();
Adrian Roosc13723f2016-01-12 20:29:03 +0100643 boolean trust = mTrustManager.isTrustUsuallyManaged(currentUser);
644 boolean fingerprint = mUpdateMonitor.isUnlockWithFingerprintPossible(currentUser);
645 boolean any = trust || fingerprint;
646 KeyguardUpdateMonitor.StrongAuthTracker strongAuthTracker =
647 mUpdateMonitor.getStrongAuthTracker();
648 int strongAuth = strongAuthTracker.getStrongAuthForUser(currentUser);
649
650 if (any && !strongAuthTracker.hasUserAuthenticatedSinceBoot()) {
Selim Cinek3122fa82015-06-18 01:38:59 -0700651 return KeyguardSecurityView.PROMPT_REASON_RESTART;
Michal Karpinskic52f8672016-11-18 11:32:45 +0000652 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_TIMEOUT) != 0) {
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700653 return KeyguardSecurityView.PROMPT_REASON_TIMEOUT;
Adrian Roosc13723f2016-01-12 20:29:03 +0100654 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW) != 0) {
655 return KeyguardSecurityView.PROMPT_REASON_DEVICE_ADMIN;
656 } else if (trust && (strongAuth & SOME_AUTH_REQUIRED_AFTER_USER_REQUEST) != 0) {
657 return KeyguardSecurityView.PROMPT_REASON_USER_REQUEST;
658 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_LOCKOUT) != 0) {
659 return KeyguardSecurityView.PROMPT_REASON_AFTER_LOCKOUT;
Selim Cinek3122fa82015-06-18 01:38:59 -0700660 }
661 return KeyguardSecurityView.PROMPT_REASON_NONE;
662 }
David Stevens53a39ea2017-08-23 18:41:49 -0700663
664 @Override
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800665 public CharSequence consumeCustomMessage() {
666 final CharSequence message = mCustomMessage;
667 mCustomMessage = null;
668 return message;
669 }
670
671 @Override
David Stevens53a39ea2017-08-23 18:41:49 -0700672 public void onSecondaryDisplayShowingChanged(int displayId) {
673 synchronized (KeyguardViewMediator.this) {
Lucas Dupin47a65c72018-02-15 14:16:18 -0800674 setShowingLocked(mShowing, mAodShowing, displayId, false);
David Stevens53a39ea2017-08-23 18:41:49 -0700675 }
676 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700677 };
678
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200679 public void userActivity() {
Jeff Brown3dc524b2012-09-30 19:49:11 -0700680 mPM.userActivity(SystemClock.uptimeMillis(), false);
Jim Millerdcb3d842012-08-23 19:18:12 -0700681 }
682
Amith Yamasanieb437d42016-04-29 09:31:25 -0700683 boolean mustNotUnlockCurrentUser() {
Christine Franks338c6ed2017-08-08 09:39:16 -0700684 return UserManager.isSplitSystemUser()
Amith Yamasanieb437d42016-04-29 09:31:25 -0700685 && KeyguardUpdateMonitor.getCurrentUser() == UserHandle.USER_SYSTEM;
686 }
687
Jim Millerab954542014-10-10 18:21:49 -0700688 private void setupLocked() {
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200689 mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
Adrian Roos481a6df2014-11-20 19:48:56 +0100690 mTrustManager = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE);
691
Mike Lockwood674d3e42009-10-06 09:28:54 -0400692 mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
693 mShowKeyguardWakeLock.setReferenceCounted(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800694
Adrian Roos1f8025a2016-12-27 10:12:13 -0800695 IntentFilter filter = new IntentFilter();
Adrian Roos1f8025a2016-12-27 10:12:13 -0800696 filter.addAction(Intent.ACTION_SHUTDOWN);
697 mContext.registerReceiver(mBroadcastReceiver, filter);
Jim Millerbbf1a742012-07-17 18:30:30 -0700698
Kevin Chyn18e91aa2018-04-11 12:55:45 -0700699 final IntentFilter delayedActionFilter = new IntentFilter();
700 delayedActionFilter.addAction(DELAYED_KEYGUARD_ACTION);
701 delayedActionFilter.addAction(DELAYED_LOCK_PROFILE_ACTION);
702 mContext.registerReceiver(mDelayedLockBroadcastReceiver, delayedActionFilter,
703 SYSTEMUI_PERMISSION, null /* scheduler */);
704
David Stevens53a39ea2017-08-23 18:41:49 -0700705 mKeyguardDisplayManager = new KeyguardDisplayManager(mContext, mViewMediatorCallback);
Jim Miller31921482013-11-06 20:43:55 -0800706
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200707 mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800708
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200709 mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800710
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200711 mLockPatternUtils = new LockPatternUtils(mContext);
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700712 KeyguardUpdateMonitor.setCurrentUser(ActivityManager.getCurrentUser());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800713
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200714 // Assume keyguard is showing (unless it's disabled) until we know for sure, unless Keyguard
715 // is disabled.
716 if (mContext.getResources().getBoolean(
717 com.android.keyguard.R.bool.config_enableKeyguardService)) {
718 setShowingLocked(!shouldWaitForProvisioning()
719 && !mLockPatternUtils.isLockScreenDisabled(
David Stevens53a39ea2017-08-23 18:41:49 -0700720 KeyguardUpdateMonitor.getCurrentUser()),
Lucas Dupin47a65c72018-02-15 14:16:18 -0800721 mAodShowing, mSecondaryDisplayShowing, true /* forceCallbacks */);
Leif Hendrik Wildenc6dc1c92018-02-01 10:54:15 -0800722 } else {
723 // The system's keyguard is disabled or missing.
Lucas Dupin47a65c72018-02-15 14:16:18 -0800724 setShowingLocked(false, mAodShowing, mSecondaryDisplayShowing, true);
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200725 }
Jim Millere5f17ab2013-11-13 15:40:48 -0800726
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800727 mStatusBarKeyguardViewManager =
728 SystemUIFactory.getInstance().createStatusBarKeyguardViewManager(mContext,
729 mViewMediatorCallback, mLockPatternUtils);
Daniel Sandler687a3272010-03-13 15:44:47 -0500730 final ContentResolver cr = mContext.getContentResolver();
Marco Nelissend5545bd2011-09-29 12:49:17 -0700731
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700732 mDeviceInteractive = mPM.isInteractive();
Daniel Hansson4b716862012-03-29 11:02:05 +0200733
Marco Nelissend5545bd2011-09-29 12:49:17 -0700734 mLockSounds = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
Jim Millerb14288d2012-09-30 18:25:05 -0700735 String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700736 if (soundPath != null) {
737 mLockSoundId = mLockSounds.load(soundPath, 1);
738 }
739 if (soundPath == null || mLockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700740 Log.w(TAG, "failed to load lock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700741 }
Jim Millerb14288d2012-09-30 18:25:05 -0700742 soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700743 if (soundPath != null) {
744 mUnlockSoundId = mLockSounds.load(soundPath, 1);
745 }
746 if (soundPath == null || mUnlockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700747 Log.w(TAG, "failed to load unlock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700748 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200749 soundPath = Settings.Global.getString(cr, Settings.Global.TRUSTED_SOUND);
750 if (soundPath != null) {
751 mTrustedSoundId = mLockSounds.load(soundPath, 1);
752 }
753 if (soundPath == null || mTrustedSoundId == 0) {
754 Log.w(TAG, "failed to load trusted sound from " + soundPath);
755 }
756
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200757 int lockSoundDefaultAttenuation = mContext.getResources().getInteger(
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700758 com.android.internal.R.integer.config_lockSoundVolumeDb);
Jean-Michel Trivif2b0c112012-07-09 11:59:11 -0700759 mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20);
Adrian Roos0002a452014-07-03 13:46:07 +0200760
761 mHideAnimation = AnimationUtils.loadAnimation(mContext,
762 com.android.internal.R.anim.lock_screen_behind_enter);
Robin Leec41f6ec2017-01-10 17:02:34 +0000763
764 mWorkLockController = new WorkLockActivityController(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800765 }
766
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200767 @Override
768 public void start() {
Jim Millerab954542014-10-10 18:21:49 -0700769 synchronized (this) {
770 setupLocked();
771 }
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200772 putComponent(KeyguardViewMediator.class, this);
773 }
774
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800775 /**
776 * Let us know that the system is ready after startup.
777 */
778 public void onSystemReady() {
Adrian Roos30a2ae62018-04-25 19:09:50 +0200779 mHandler.obtainMessage(SYSTEM_READY).sendToTarget();
780 }
781
782 private void handleSystemReady() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800783 synchronized (this) {
784 if (DEBUG) Log.d(TAG, "onSystemReady");
785 mSystemReady = true;
Jim Miller5ecd8112013-01-09 18:50:26 -0800786 doKeyguardLocked(null);
Selim Cinekedd32b82015-06-23 22:05:58 -0400787 mUpdateMonitor.registerCallback(mUpdateCallback);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800788 }
Jim Miller3fd47af2012-09-21 19:55:27 -0700789 // Most services aren't available until the system reaches the ready state, so we
790 // send it here when the device first boots.
791 maybeSendUserPresentBroadcast();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800792 }
793
794 /**
795 * Called to let us know the screen was turned off.
Adrian Roose99bc052017-11-20 17:55:31 +0100796 * @param why either {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_USER} or
797 * {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_TIMEOUT}.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800798 */
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700799 public void onStartedGoingToSleep(int why) {
800 if (DEBUG) Log.d(TAG, "onStartedGoingToSleep(" + why + ")");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800801 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700802 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700803 mGoingToSleep = true;
John Spurlock14adfe42012-11-08 10:29:26 -0500804
Jim Millera4edd152012-01-06 18:24:04 -0800805 // Lock immediately based on setting if secure (user has a pin/pattern/password).
806 // This also "locks" the device when not secure to provide easy access to the
807 // camera while preventing unwanted input.
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700808 int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jim Millera4edd152012-01-06 18:24:04 -0800809 final boolean lockImmediately =
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700810 mLockPatternUtils.getPowerButtonInstantlyLocks(currentUser)
811 || !mLockPatternUtils.isSecure(currentUser);
Clara Bayarri56878a92015-10-29 15:43:55 +0000812 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000813 mLockLater = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800814 if (mExitSecureCallback != null) {
815 if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled");
Jim Miller5ecd8112013-01-09 18:50:26 -0800816 try {
817 mExitSecureCallback.onKeyguardExitResult(false);
818 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800819 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800820 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800821 mExitSecureCallback = null;
822 if (!mExternallyEnabled) {
Jim Miller9c20d0e2010-01-20 15:00:23 -0800823 hideLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800824 }
825 } else if (mShowing) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700826 mPendingReset = true;
Adrian Roose99bc052017-11-20 17:55:31 +0100827 } else if ((why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_TIMEOUT && timeout > 0)
828 || (why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER && !lockImmediately)) {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700829 doKeyguardLaterLocked(timeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000830 mLockLater = true;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700831 } else if (!mLockPatternUtils.isLockScreenDisabled(currentUser)) {
832 mPendingLock = true;
833 }
834
Jorim Jaggi853cbe32015-06-04 16:31:54 -0700835 if (mPendingLock) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700836 playSounds(true);
837 }
838 }
Jorim Jaggi95e40382015-09-16 15:53:42 -0700839 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedGoingToSleep(why);
Jorim Jaggi18f18ae2015-09-10 15:48:21 -0700840 notifyStartedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700841 }
842
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700843 public void onFinishedGoingToSleep(int why, boolean cameraGestureTriggered) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700844 if (DEBUG) Log.d(TAG, "onFinishedGoingToSleep(" + why + ")");
845 synchronized (this) {
846 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700847 mGoingToSleep = false;
Adrian Roose4cb6c8a2017-07-19 18:08:07 +0200848 mWakeAndUnlocking = false;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700849
850 resetKeyguardDonePendingLocked();
851 mHideAnimationRun = false;
852
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700853 notifyFinishedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700854
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700855 if (cameraGestureTriggered) {
856 Log.i(TAG, "Camera gesture was triggered, preventing Keyguard locking.");
857
858 // Just to make sure, make sure the device is awake.
859 mContext.getSystemService(PowerManager.class).wakeUp(SystemClock.uptimeMillis(),
860 "com.android.systemui:CAMERA_GESTURE_PREVENT_LOCK");
861 mPendingLock = false;
862 mPendingReset = false;
863 }
864
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700865 if (mPendingReset) {
866 resetStateLocked();
867 mPendingReset = false;
868 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000869
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700870 if (mPendingLock) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800871 doKeyguardLocked(null);
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700872 mPendingLock = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800873 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000874
875 // We do not have timeout and power button instant lock setting for profile lock.
876 // So we use the personal setting if there is any. But if there is no device
877 // we need to make sure we lock it immediately when the screen is off.
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700878 if (!mLockLater && !cameraGestureTriggered) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000879 doKeyguardForChildProfilesLocked();
880 }
881
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800882 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700883 KeyguardUpdateMonitor.getInstance(mContext).dispatchFinishedGoingToSleep(why);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800884 }
885
Clara Bayarri56878a92015-10-29 15:43:55 +0000886 private long getLockTimeout(int userId) {
Jeff Brown6aaf2952012-10-05 16:01:08 -0700887 // if the screen turned off because of timeout or the user hit the power button
888 // and we don't need to lock immediately, set an alarm
889 // to enable it a little bit later (i.e, give the user a chance
890 // to turn the screen back on within a certain window without
891 // having to unlock the screen)
892 final ContentResolver cr = mContext.getContentResolver();
893
Jeff Brown6aaf2952012-10-05 16:01:08 -0700894 // From SecuritySettings
895 final long lockAfterTimeout = Settings.Secure.getInt(cr,
896 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT,
897 KEYGUARD_LOCK_AFTER_DELAY_DEFAULT);
898
899 // From DevicePolicyAdmin
900 final long policyTimeout = mLockPatternUtils.getDevicePolicyManager()
Pavel Grafov28939982017-10-03 15:11:52 +0100901 .getMaximumTimeToLock(null, userId);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700902
903 long timeout;
Clara Bayarri56878a92015-10-29 15:43:55 +0000904
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000905 if (policyTimeout <= 0) {
Clara Bayarri56878a92015-10-29 15:43:55 +0000906 timeout = lockAfterTimeout;
907 } else {
908 // From DisplaySettings
909 long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT,
910 KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT);
911
Jeff Brown6aaf2952012-10-05 16:01:08 -0700912 // policy in effect. Make sure we don't go beyond policy limit.
913 displayTimeout = Math.max(displayTimeout, 0); // ignore negative values
914 timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000915 timeout = Math.max(timeout, 0);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700916 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700917 return timeout;
918 }
Jeff Brown6aaf2952012-10-05 16:01:08 -0700919
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700920 private void doKeyguardLaterLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000921 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700922 if (timeout == 0) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800923 doKeyguardLocked(null);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700924 } else {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700925 doKeyguardLaterLocked(timeout);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700926 }
927 }
928
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700929 private void doKeyguardLaterLocked(long timeout) {
930 // Lock in the future
931 long when = SystemClock.elapsedRealtime() + timeout;
932 Intent intent = new Intent(DELAYED_KEYGUARD_ACTION);
933 intent.putExtra("seq", mDelayedShowingSequence);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700934 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700935 PendingIntent sender = PendingIntent.getBroadcast(mContext,
936 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Jim Millera622d3cc2016-03-02 16:02:24 -0800937 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700938 if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = "
939 + mDelayedShowingSequence);
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000940 doKeyguardLaterForChildProfilesLocked();
Clara Bayarri56878a92015-10-29 15:43:55 +0000941 }
Clara Bayarri10ad84a2015-12-01 17:38:05 +0000942
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000943 private void doKeyguardLaterForChildProfilesLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000944 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700945 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
946 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
947 long userTimeout = getLockTimeout(profileId);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000948 if (userTimeout == 0) {
949 doKeyguardForChildProfilesLocked();
950 } else {
951 long userWhen = SystemClock.elapsedRealtime() + userTimeout;
952 Intent lockIntent = new Intent(DELAYED_LOCK_PROFILE_ACTION);
953 lockIntent.putExtra("seq", mDelayedProfileShowingSequence);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700954 lockIntent.putExtra(Intent.EXTRA_USER_ID, profileId);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700955 lockIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000956 PendingIntent lockSender = PendingIntent.getBroadcast(
957 mContext, 0, lockIntent, PendingIntent.FLAG_CANCEL_CURRENT);
958 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
959 userWhen, lockSender);
960 }
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000961 }
962 }
963 }
964
965 private void doKeyguardForChildProfilesLocked() {
966 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700967 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
968 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
969 lockProfile(profileId);
Clara Bayarri56878a92015-10-29 15:43:55 +0000970 }
971 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700972 }
973
Jeff Brown6aaf2952012-10-05 16:01:08 -0700974 private void cancelDoKeyguardLaterLocked() {
975 mDelayedShowingSequence++;
976 }
977
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000978 private void cancelDoKeyguardForChildProfilesLocked() {
979 mDelayedProfileShowingSequence++;
980 }
981
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800982 /**
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700983 * Let's us know when the device is waking up.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800984 */
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700985 public void onStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700986 Trace.beginSection("KeyguardViewMediator#onStartedWakingUp");
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700987
988 // TODO: Rename all screen off/on references to interactive/sleeping
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800989 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700990 mDeviceInteractive = true;
Jeff Brown6aaf2952012-10-05 16:01:08 -0700991 cancelDoKeyguardLaterLocked();
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000992 cancelDoKeyguardForChildProfilesLocked();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700993 if (DEBUG) Log.d(TAG, "onStartedWakingUp, seq = " + mDelayedShowingSequence);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700994 notifyStartedWakingUp();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800995 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700996 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedWakingUp();
Jim Miller3fd47af2012-09-21 19:55:27 -0700997 maybeSendUserPresentBroadcast();
Nick Desaulniers1d396752016-07-25 15:05:33 -0700998 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -0700999 }
1000
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001001 public void onScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001002 Trace.beginSection("KeyguardViewMediator#onScreenTurningOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001003 notifyScreenOn(callback);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001004 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001005 }
1006
1007 public void onScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001008 Trace.beginSection("KeyguardViewMediator#onScreenTurnedOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001009 notifyScreenTurnedOn();
1010 mUpdateMonitor.dispatchScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001011 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001012 }
1013
1014 public void onScreenTurnedOff() {
1015 notifyScreenTurnedOff();
1016 mUpdateMonitor.dispatchScreenTurnedOff();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001017 }
1018
Jim Miller3fd47af2012-09-21 19:55:27 -07001019 private void maybeSendUserPresentBroadcast() {
Adrian Roos8150d2a2015-04-16 17:11:20 -07001020 if (mSystemReady && mLockPatternUtils.isLockScreenDisabled(
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001021 KeyguardUpdateMonitor.getCurrentUser())) {
Jim Miller3fd47af2012-09-21 19:55:27 -07001022 // Lock screen is disabled because the user has set the preference to "None".
1023 // In this case, send out ACTION_USER_PRESENT here instead of in
1024 // handleKeyguardDone()
1025 sendUserPresentBroadcast();
Adrian Roosfb95a812016-06-20 14:58:59 -07001026 } else if (mSystemReady && shouldWaitForProvisioning()) {
1027 // Skipping the lockscreen because we're not yet provisioned, but we still need to
1028 // notify the StrongAuthTracker that it's now safe to run trust agents, in case the
1029 // user sets a credential later.
1030 getLockPatternUtils().userPresent(KeyguardUpdateMonitor.getCurrentUser());
Jim Miller3fd47af2012-09-21 19:55:27 -07001031 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001032 }
1033
1034 /**
Jeff Brown6aaf2952012-10-05 16:01:08 -07001035 * A dream started. We should lock after the usual screen-off lock timeout but only
1036 * if there is a secure lock pattern.
1037 */
1038 public void onDreamingStarted() {
Selim Cinek99415392016-09-09 14:58:41 -07001039 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001040 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001041 if (mDeviceInteractive
1042 && mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001043 doKeyguardLaterLocked();
1044 }
1045 }
1046 }
1047
1048 /**
1049 * A dream stopped.
1050 */
1051 public void onDreamingStopped() {
Selim Cinek99415392016-09-09 14:58:41 -07001052 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001053 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001054 if (mDeviceInteractive) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001055 cancelDoKeyguardLaterLocked();
1056 }
1057 }
1058 }
1059
1060 /**
Adrian Roose99bc052017-11-20 17:55:31 +01001061 * Same semantics as {@link WindowManagerPolicyConstants#enableKeyguard}; provide
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001062 * a way for external stuff to override normal keyguard behavior. For instance
1063 * the phone app disables the keyguard when it receives incoming calls.
1064 */
1065 public void setKeyguardEnabled(boolean enabled) {
1066 synchronized (this) {
1067 if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")");
1068
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001069 mExternallyEnabled = enabled;
1070
1071 if (!enabled && mShowing) {
1072 if (mExitSecureCallback != null) {
1073 if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring");
1074 // we're in the process of handling a request to verify the user
1075 // can get past the keyguard. ignore extraneous requests to disable / reenable
1076 return;
1077 }
1078
1079 // hiding keyguard that is showing, remember to reshow later
1080 if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, "
1081 + "disabling status bar expansion");
1082 mNeedToReshowWhenReenabled = true;
Jim Millerab954542014-10-10 18:21:49 -07001083 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001084 hideLocked();
1085 } else if (enabled && mNeedToReshowWhenReenabled) {
1086 // reenabled after previously hidden, reshow
1087 if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling "
1088 + "status bar expansion");
1089 mNeedToReshowWhenReenabled = false;
Jim Millerab954542014-10-10 18:21:49 -07001090 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001091
1092 if (mExitSecureCallback != null) {
1093 if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting");
Jim Miller5ecd8112013-01-09 18:50:26 -08001094 try {
1095 mExitSecureCallback.onKeyguardExitResult(false);
1096 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001097 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001098 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001099 mExitSecureCallback = null;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001100 resetStateLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001101 } else {
Adam Cohenf7522022012-10-03 20:03:18 -07001102 showLocked(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001103
1104 // block until we know the keygaurd is done drawing (and post a message
1105 // to unblock us after a timeout so we don't risk blocking too long
1106 // and causing an ANR).
1107 mWaitingUntilKeyguardVisible = true;
1108 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS);
1109 if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false");
1110 while (mWaitingUntilKeyguardVisible) {
1111 try {
1112 wait();
1113 } catch (InterruptedException e) {
1114 Thread.currentThread().interrupt();
1115 }
1116 }
1117 if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible");
1118 }
1119 }
1120 }
1121 }
1122
1123 /**
1124 * @see android.app.KeyguardManager#exitKeyguardSecurely
1125 */
Jim Miller25190572013-02-28 17:36:24 -08001126 public void verifyUnlock(IKeyguardExitCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001127 Trace.beginSection("KeyguardViewMediator#verifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001128 synchronized (this) {
1129 if (DEBUG) Log.d(TAG, "verifyUnlock");
Jim Millerb256e4e22014-10-31 17:27:13 -07001130 if (shouldWaitForProvisioning()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001131 // don't allow this api when the device isn't provisioned
1132 if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned");
Jim Miller5ecd8112013-01-09 18:50:26 -08001133 try {
Jim Miller25190572013-02-28 17:36:24 -08001134 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001135 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001136 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001137 }
Mike Lockwood5d258b62009-12-02 13:50:45 -05001138 } else if (mExternallyEnabled) {
1139 // this only applies when the user has externally disabled the
1140 // keyguard. this is unexpected and means the user is not
1141 // using the api properly.
1142 Log.w(TAG, "verifyUnlock called when not externally disabled");
Jim Miller5ecd8112013-01-09 18:50:26 -08001143 try {
Jim Miller25190572013-02-28 17:36:24 -08001144 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001145 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001146 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001147 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001148 } else if (mExitSecureCallback != null) {
1149 // already in progress with someone else
Jim Miller5ecd8112013-01-09 18:50:26 -08001150 try {
Jim Miller25190572013-02-28 17:36:24 -08001151 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001152 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001153 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001154 }
Jorim Jaggi302475e2015-09-22 12:44:47 -07001155 } else if (!isSecure()) {
1156
1157 // Keyguard is not secure, no need to do anything, and we don't need to reshow
1158 // the Keyguard after the client releases the Keyguard lock.
1159 mExternallyEnabled = true;
1160 mNeedToReshowWhenReenabled = false;
1161 updateInputRestricted();
1162 try {
1163 callback.onKeyguardExitResult(true);
1164 } catch (RemoteException e) {
1165 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1166 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001167 } else {
Jorim Jaggi302475e2015-09-22 12:44:47 -07001168
1169 // Since we prevent apps from hiding the Keyguard if we are secure, this should be
1170 // a no-op as well.
1171 try {
1172 callback.onKeyguardExitResult(false);
1173 } catch (RemoteException e) {
1174 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1175 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001176 }
1177 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001178 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001179 }
1180
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001181 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001182 * Is the keyguard currently showing and not being force hidden?
Mike Lockwood09a40402009-11-08 00:33:23 -05001183 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001184 public boolean isShowingAndNotOccluded() {
1185 return mShowing && !mOccluded;
1186 }
1187
1188 /**
1189 * Notify us when the keyguard is occluded by another window
1190 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001191 public void setOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001192 Trace.beginSection("KeyguardViewMediator#setOccluded");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001193 if (DEBUG) Log.d(TAG, "setOccluded " + isOccluded);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001194 mHandler.removeMessages(SET_OCCLUDED);
Jorim Jaggi6626f542016-08-22 13:08:44 -07001195 Message msg = mHandler.obtainMessage(SET_OCCLUDED, isOccluded ? 1 : 0, animate ? 1 : 0);
Mike Lockwood9200a392009-11-17 20:25:58 -05001196 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001197 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001198 }
1199
Lucas Dupin2986c152018-04-09 20:49:41 -07001200 public boolean isHiding() {
1201 return mHiding;
1202 }
1203
Mike Lockwood9200a392009-11-17 20:25:58 -05001204 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001205 * Handles SET_OCCLUDED message sent by setOccluded()
Mike Lockwood9200a392009-11-17 20:25:58 -05001206 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001207 private void handleSetOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001208 Trace.beginSection("KeyguardViewMediator#handleSetOccluded");
Mike Lockwood09a40402009-11-08 00:33:23 -05001209 synchronized (KeyguardViewMediator.this) {
Adrian Roosf253eeb2015-04-15 18:03:08 -07001210 if (mHiding && isOccluded) {
1211 // We're in the process of going away but WindowManager wants to show a
1212 // SHOW_WHEN_LOCKED activity instead.
1213 startKeyguardExitAnimation(0, 0);
1214 }
1215
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001216 if (mOccluded != isOccluded) {
1217 mOccluded = isOccluded;
Kevin Chyn2fefd462017-04-28 12:18:19 -07001218 mUpdateMonitor.setKeyguardOccluded(isOccluded);
Selim Cinek2f6272e2017-03-15 16:19:10 -07001219 mStatusBarKeyguardViewManager.setOccluded(isOccluded, animate
1220 && mDeviceInteractive);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001221 adjustStatusBarLocked();
Mike Lockwood9200a392009-11-17 20:25:58 -05001222 }
Mike Lockwood09a40402009-11-08 00:33:23 -05001223 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001224 Trace.endSection();
Mike Lockwood09a40402009-11-08 00:33:23 -05001225 }
1226
1227 /**
Mike Lockwood28569302010-01-28 11:54:40 -05001228 * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout.
1229 * This must be safe to call from any thread and with any window manager locks held.
1230 */
Adam Cohenf7522022012-10-03 20:03:18 -07001231 public void doKeyguardTimeout(Bundle options) {
Mike Lockwood28569302010-01-28 11:54:40 -05001232 mHandler.removeMessages(KEYGUARD_TIMEOUT);
Adam Cohenf7522022012-10-03 20:03:18 -07001233 Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options);
Mike Lockwood28569302010-01-28 11:54:40 -05001234 mHandler.sendMessage(msg);
1235 }
1236
1237 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001238 * Given the state of the keyguard, is the input restricted?
1239 * Input is restricted when the keyguard is showing, or when the keyguard
1240 * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet.
1241 */
1242 public boolean isInputRestricted() {
Adrian Roos9f33d6c2015-06-15 15:58:35 -07001243 return mShowing || mNeedToReshowWhenReenabled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001244 }
1245
Jim Millerab954542014-10-10 18:21:49 -07001246 private void updateInputRestricted() {
1247 synchronized (this) {
1248 updateInputRestrictedLocked();
1249 }
1250 }
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001251
Jim Millerab954542014-10-10 18:21:49 -07001252 private void updateInputRestrictedLocked() {
1253 boolean inputRestricted = isInputRestricted();
1254 if (mInputRestricted != inputRestricted) {
1255 mInputRestricted = inputRestricted;
dooyoung.hwang328472e2015-05-21 16:09:43 +09001256 int size = mKeyguardStateCallbacks.size();
1257 for (int i = size - 1; i >= 0; i--) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001258 final IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001259 try {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001260 callback.onInputRestrictedStateChanged(inputRestricted);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001261 } catch (RemoteException e) {
1262 Slog.w(TAG, "Failed to call onDeviceProvisioned", e);
1263 if (e instanceof DeadObjectException) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001264 mKeyguardStateCallbacks.remove(callback);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001265 }
Jim Millerab954542014-10-10 18:21:49 -07001266 }
Jim Millerab954542014-10-10 18:21:49 -07001267 }
1268 }
1269 }
1270
Dianne Hackbornb446e972009-09-20 15:23:25 -07001271 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001272 * Enable the keyguard if the settings are appropriate.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001273 */
Adam Cohenf7522022012-10-03 20:03:18 -07001274 private void doKeyguardLocked(Bundle options) {
Adrian Roosca8a2162017-08-17 19:00:58 +02001275 if (KeyguardUpdateMonitor.CORE_APPS_ONLY) {
1276 // Don't show keyguard during half-booted cryptkeeper stage.
1277 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because booting to cryptkeeper");
1278 return;
1279 }
1280
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001281 // if another app is disabling us, don't show
1282 if (!mExternallyEnabled) {
1283 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled");
Karl Rosaenab100082009-03-24 22:35:17 -07001284
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001285 // note: we *should* set mNeedToReshowWhenReenabled=true here, but that makes
1286 // for an occasional ugly flicker in this situation:
1287 // 1) receive a call with the screen on (no keyguard) or make a call
1288 // 2) screen times out
1289 // 3) user hits key to turn screen back on
1290 // instead, we reenable the keyguard when we know the screen is off and the call
1291 // ends (see the broadcast receiver below)
1292 // TODO: clean this up when we have better support at the window manager level
1293 // for apps that wish to be on top of the keyguard
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001294 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001295 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001296
1297 // if the keyguard is already showing, don't bother
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001298 if (mStatusBarKeyguardViewManager.isShowing()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001299 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing");
Jorim Jaggi95e89ca2014-11-24 20:12:50 +01001300 resetStateLocked();
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001301 return;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001302 }
1303
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001304 // In split system user mode, we never unlock system user.
Amith Yamasanieb437d42016-04-29 09:31:25 -07001305 if (!mustNotUnlockCurrentUser()
Amith Yamasani27e025b2015-11-06 10:34:41 -08001306 || !mUpdateMonitor.isDeviceProvisioned()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001307
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001308 // if the setup wizard hasn't run yet, don't show
1309 final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", false);
1310 final boolean absent = SubscriptionManager.isValidSubscriptionId(
Adrian Roose92de952016-12-13 12:07:09 -08001311 mUpdateMonitor.getNextSubIdForState(ABSENT));
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001312 final boolean disabled = SubscriptionManager.isValidSubscriptionId(
1313 mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.PERM_DISABLED));
1314 final boolean lockedOrMissing = mUpdateMonitor.isSimPinSecure()
1315 || ((absent || disabled) && requireSim);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001316
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001317 if (!lockedOrMissing && shouldWaitForProvisioning()) {
1318 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned"
1319 + " and the sim is not locked or missing");
1320 return;
1321 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001322
Evan Rosky13a58a92016-07-27 15:51:09 -07001323 boolean forceShow = options != null && options.getBoolean(OPTION_FORCE_SHOW, false);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001324 if (mLockPatternUtils.isLockScreenDisabled(KeyguardUpdateMonitor.getCurrentUser())
Evan Rosky13a58a92016-07-27 15:51:09 -07001325 && !lockedOrMissing && !forceShow) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001326 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off");
1327 return;
1328 }
1329
1330 if (mLockPatternUtils.checkVoldPassword(KeyguardUpdateMonitor.getCurrentUser())) {
1331 if (DEBUG) Log.d(TAG, "Not showing lock screen since just decrypted");
1332 // Without this, settings is not enabled until the lock screen first appears
Lucas Dupin47a65c72018-02-15 14:16:18 -08001333 setShowingLocked(false, mAodShowing);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001334 hideLocked();
1335 return;
1336 }
Paul Lawrence945490c2014-03-27 16:37:28 +00001337 }
1338
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001339 if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");
Adam Cohenf7522022012-10-03 20:03:18 -07001340 showLocked(options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001341 }
1342
Clara Bayarri56878a92015-10-29 15:43:55 +00001343 private void lockProfile(int userId) {
1344 mTrustManager.setDeviceLockedForUser(userId, true);
1345 }
1346
Jim Millerb256e4e22014-10-31 17:27:13 -07001347 private boolean shouldWaitForProvisioning() {
1348 return !mUpdateMonitor.isDeviceProvisioned() && !isSecure();
1349 }
1350
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001351 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001352 * Dismiss the keyguard through the security layers.
Jorim Jaggi241ae102016-11-02 21:57:33 -07001353 * @param callback Callback to be informed about the result
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001354 * @param message Message that should be displayed on the bouncer.
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001355 */
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001356 private void handleDismiss(IKeyguardDismissCallback callback, CharSequence message) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001357 if (mShowing) {
1358 if (callback != null) {
1359 mDismissCallbackRegistry.addCallback(callback);
1360 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001361 mCustomMessage = message;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001362 mStatusBarKeyguardViewManager.dismissAndCollapse();
Jorim Jaggi241ae102016-11-02 21:57:33 -07001363 } else if (callback != null) {
1364 new DismissCallbackWrapper(callback).notifyDismissError();
Jim Miller87d03662012-11-05 20:28:09 -08001365 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001366 }
1367
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001368 public void dismiss(IKeyguardDismissCallback callback, CharSequence message) {
1369 mHandler.obtainMessage(DISMISS, new DismissMessage(callback, message)).sendToTarget();
Jim Miller60013792013-10-03 18:31:34 -07001370 }
1371
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001372 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001373 * Send message to keyguard telling it to reset its state.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001374 * @see #handleReset
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001375 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001376 private void resetStateLocked() {
Jim Miller4894a012013-04-03 15:23:55 -07001377 if (DEBUG) Log.e(TAG, "resetStateLocked");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001378 Message msg = mHandler.obtainMessage(RESET);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001379 mHandler.sendMessage(msg);
1380 }
1381
1382 /**
1383 * Send message to keyguard telling it to verify unlock
1384 * @see #handleVerifyUnlock()
1385 */
1386 private void verifyUnlockLocked() {
1387 if (DEBUG) Log.d(TAG, "verifyUnlockLocked");
1388 mHandler.sendEmptyMessage(VERIFY_UNLOCK);
1389 }
1390
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001391 private void notifyStartedGoingToSleep() {
1392 if (DEBUG) Log.d(TAG, "notifyStartedGoingToSleep");
1393 mHandler.sendEmptyMessage(NOTIFY_STARTED_GOING_TO_SLEEP);
1394 }
1395
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001396 private void notifyFinishedGoingToSleep() {
1397 if (DEBUG) Log.d(TAG, "notifyFinishedGoingToSleep");
1398 mHandler.sendEmptyMessage(NOTIFY_FINISHED_GOING_TO_SLEEP);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001399 }
1400
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001401 private void notifyStartedWakingUp() {
1402 if (DEBUG) Log.d(TAG, "notifyStartedWakingUp");
1403 mHandler.sendEmptyMessage(NOTIFY_STARTED_WAKING_UP);
1404 }
1405
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001406 private void notifyScreenOn(IKeyguardDrawnCallback callback) {
1407 if (DEBUG) Log.d(TAG, "notifyScreenOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001408 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNING_ON, callback);
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001409 mHandler.sendMessage(msg);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001410 }
1411
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001412 private void notifyScreenTurnedOn() {
1413 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOn");
1414 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_ON);
1415 mHandler.sendMessage(msg);
1416 }
1417
1418 private void notifyScreenTurnedOff() {
1419 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOff");
1420 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_OFF);
1421 mHandler.sendMessage(msg);
1422 }
1423
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001424 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001425 * Send message to keyguard telling it to show itself
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001426 * @see #handleShow
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001427 */
Adam Cohenf7522022012-10-03 20:03:18 -07001428 private void showLocked(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001429 Trace.beginSection("KeyguardViewMediator#showLocked aqcuiring mShowKeyguardWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001430 if (DEBUG) Log.d(TAG, "showLocked");
Mike Lockwood674d3e42009-10-06 09:28:54 -04001431 // ensure we stay awake until we are finished displaying the keyguard
1432 mShowKeyguardWakeLock.acquire();
Adam Cohenf7522022012-10-03 20:03:18 -07001433 Message msg = mHandler.obtainMessage(SHOW, options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001434 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001435 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001436 }
1437
1438 /**
1439 * Send message to keyguard telling it to hide itself
Jim Miller9c20d0e2010-01-20 15:00:23 -08001440 * @see #handleHide()
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001441 */
1442 private void hideLocked() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001443 Trace.beginSection("KeyguardViewMediator#hideLocked");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001444 if (DEBUG) Log.d(TAG, "hideLocked");
1445 Message msg = mHandler.obtainMessage(HIDE);
1446 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001447 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001448 }
1449
Dianne Hackbornb446e972009-09-20 15:23:25 -07001450 public boolean isSecure() {
Evan Rosky13a58a92016-07-27 15:51:09 -07001451 return isSecure(KeyguardUpdateMonitor.getCurrentUser());
1452 }
1453
1454 public boolean isSecure(int userId) {
1455 return mLockPatternUtils.isSecure(userId)
1456 || KeyguardUpdateMonitor.getInstance(mContext).isSimPinSecure();
Dianne Hackbornb446e972009-09-20 15:23:25 -07001457 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001458
Evan Rosky18396452016-07-27 15:19:37 -07001459 public void setSwitchingUser(boolean switching) {
Selim Cinekbbe19242017-12-08 15:42:08 -08001460 KeyguardUpdateMonitor.getInstance(mContext).setSwitchingUser(switching);
Evan Rosky18396452016-07-27 15:19:37 -07001461 }
1462
Craig Mautnerf1b67412012-09-19 13:18:29 -07001463 /**
1464 * Update the newUserId. Call while holding WindowManagerService lock.
Jim Milleree82f8f2012-10-01 16:26:18 -07001465 * NOTE: Should only be called by KeyguardViewMediator in response to the user id changing.
1466 *
Craig Mautnerf1b67412012-09-19 13:18:29 -07001467 * @param newUserId The id of the incoming user.
1468 */
1469 public void setCurrentUser(int newUserId) {
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001470 KeyguardUpdateMonitor.setCurrentUser(newUserId);
Adrian Roosd88eb262016-08-04 14:50:48 -07001471 synchronized (this) {
1472 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(newUserId));
1473 }
Craig Mautnerf1b67412012-09-19 13:18:29 -07001474 }
1475
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001476 /**
1477 * This broadcast receiver should be registered with the SystemUI permission.
1478 */
1479 private final BroadcastReceiver mDelayedLockBroadcastReceiver = new BroadcastReceiver() {
Amith Yamasani52c489c2012-03-28 11:42:42 -07001480 @Override
1481 public void onReceive(Context context, Intent intent) {
Jim Millerbbf1a742012-07-17 18:30:30 -07001482 if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
1483 final int sequence = intent.getIntExtra("seq", 0);
Jim Millerf3447352011-08-07 14:00:09 -07001484 if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = "
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001485 + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001486 synchronized (KeyguardViewMediator.this) {
Jim Miller2967f482016-01-07 15:05:32 -08001487 if (mDelayedShowingSequence == sequence) {
1488 doKeyguardLocked(null);
1489 }
Clara Bayarri56878a92015-10-29 15:43:55 +00001490 }
1491 } else if (DELAYED_LOCK_PROFILE_ACTION.equals(intent.getAction())) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001492 final int sequence = intent.getIntExtra("seq", 0);
Clara Bayarri56878a92015-10-29 15:43:55 +00001493 int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, 0);
1494 if (userId != 0) {
1495 synchronized (KeyguardViewMediator.this) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001496 if (mDelayedProfileShowingSequence == sequence) {
1497 lockProfile(userId);
1498 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001499 }
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001500 }
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001501 }
1502 }
1503 };
1504
1505 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1506 @Override
1507 public void onReceive(Context context, Intent intent) {
1508 if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
Adrian Roos1f8025a2016-12-27 10:12:13 -08001509 synchronized (KeyguardViewMediator.this){
1510 mShuttingDown = true;
1511 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001512 }
1513 }
1514 };
1515
Jorim Jaggi241ae102016-11-02 21:57:33 -07001516 public void keyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001517 Trace.beginSection("KeyguardViewMediator#keyguardDone");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001518 if (DEBUG) Log.d(TAG, "keyguardDone()");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001519 userActivity();
Jim Miller60013792013-10-03 18:31:34 -07001520 EventLog.writeEvent(70000, 2);
Jorim Jaggi241ae102016-11-02 21:57:33 -07001521 Message msg = mHandler.obtainMessage(KEYGUARD_DONE);
Jim Miller60013792013-10-03 18:31:34 -07001522 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001523 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001524 }
1525
1526 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001527 * This handler will be associated with the policy thread, which will also
1528 * be the UI thread of the keyguard. Since the apis of the policy, and therefore
1529 * this class, can be called by other threads, any action that directly
1530 * interacts with the keyguard ui should be posted to this handler, rather
1531 * than called directly.
1532 */
Jim Millerdcb3d842012-08-23 19:18:12 -07001533 private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001534 @Override
Wink Saville37c124c2009-04-02 01:37:02 -07001535 public void handleMessage(Message msg) {
1536 switch (msg.what) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001537 case SHOW:
Adam Cohenf7522022012-10-03 20:03:18 -07001538 handleShow((Bundle) msg.obj);
Jim Miller60013792013-10-03 18:31:34 -07001539 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001540 case HIDE:
1541 handleHide();
Jim Miller60013792013-10-03 18:31:34 -07001542 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001543 case RESET:
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001544 handleReset();
Jim Miller60013792013-10-03 18:31:34 -07001545 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001546 case VERIFY_UNLOCK:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001547 Trace.beginSection("KeyguardViewMediator#handleMessage VERIFY_UNLOCK");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001548 handleVerifyUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001549 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001550 break;
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001551 case NOTIFY_STARTED_GOING_TO_SLEEP:
1552 handleNotifyStartedGoingToSleep();
1553 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001554 case NOTIFY_FINISHED_GOING_TO_SLEEP:
1555 handleNotifyFinishedGoingToSleep();
Jim Miller60013792013-10-03 18:31:34 -07001556 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001557 case NOTIFY_SCREEN_TURNING_ON:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001558 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNING_ON");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001559 handleNotifyScreenTurningOn((IKeyguardDrawnCallback) msg.obj);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001560 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001561 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001562 case NOTIFY_SCREEN_TURNED_ON:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001563 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNED_ON");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001564 handleNotifyScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001565 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001566 break;
1567 case NOTIFY_SCREEN_TURNED_OFF:
1568 handleNotifyScreenTurnedOff();
1569 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001570 case NOTIFY_STARTED_WAKING_UP:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001571 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_STARTED_WAKING_UP");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001572 handleNotifyStartedWakingUp();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001573 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001574 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001575 case KEYGUARD_DONE:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001576 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001577 handleKeyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001578 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001579 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001580 case KEYGUARD_DONE_DRAWING:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001581 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_DRAWING");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001582 handleKeyguardDoneDrawing();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001583 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001584 break;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001585 case SET_OCCLUDED:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001586 Trace.beginSection("KeyguardViewMediator#handleMessage SET_OCCLUDED");
Jorim Jaggi6626f542016-08-22 13:08:44 -07001587 handleSetOccluded(msg.arg1 != 0, msg.arg2 != 0);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001588 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001589 break;
Mike Lockwood28569302010-01-28 11:54:40 -05001590 case KEYGUARD_TIMEOUT:
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001591 synchronized (KeyguardViewMediator.this) {
Adam Cohenf7522022012-10-03 20:03:18 -07001592 doKeyguardLocked((Bundle) msg.obj);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001593 }
1594 break;
Jim Miller60013792013-10-03 18:31:34 -07001595 case DISMISS:
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001596 final DismissMessage message = (DismissMessage) msg.obj;
1597 handleDismiss(message.getCallback(), message.getMessage());
Jim Miller60013792013-10-03 18:31:34 -07001598 break;
Jorim Jaggi0d674622014-05-21 01:34:15 +02001599 case START_KEYGUARD_EXIT_ANIM:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001600 Trace.beginSection("KeyguardViewMediator#handleMessage START_KEYGUARD_EXIT_ANIM");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001601 StartKeyguardExitAnimParams params = (StartKeyguardExitAnimParams) msg.obj;
1602 handleStartKeyguardExitAnimation(params.startTime, params.fadeoutDuration);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001603 FalsingManager.getInstance(mContext).onSucccessfulUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001604 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001605 break;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001606 case KEYGUARD_DONE_PENDING_TIMEOUT:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001607 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_PENDING_TIMEOUT");
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001608 Log.w(TAG, "Timeout while waiting for activity drawn!");
Nick Desaulniers1d396752016-07-25 15:05:33 -07001609 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001610 break;
Adrian Roos30a2ae62018-04-25 19:09:50 +02001611 case SYSTEM_READY:
1612 handleSystemReady();
1613 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001614 }
1615 }
1616 };
1617
Jorim Jaggi241ae102016-11-02 21:57:33 -07001618 private void tryKeyguardDone() {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001619 if (!mKeyguardDonePending && mHideAnimationRun && !mHideAnimationRunning) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001620 handleKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001621 } else if (!mHideAnimationRun) {
1622 mHideAnimationRun = true;
1623 mHideAnimationRunning = true;
1624 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
1625 }
1626 }
1627
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001628 /**
1629 * @see #keyguardDone
1630 * @see #KEYGUARD_DONE
1631 */
Jorim Jaggi241ae102016-11-02 21:57:33 -07001632 private void handleKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001633 Trace.beginSection("KeyguardViewMediator#handleKeyguardDone");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001634 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001635 mUiOffloadThread.submit(() -> {
1636 if (mLockPatternUtils.isSecure(currentUser)) {
1637 mLockPatternUtils.getDevicePolicyManager().reportKeyguardDismissed(currentUser);
1638 }
1639 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001640 if (DEBUG) Log.d(TAG, "handleKeyguardDone");
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001641 synchronized (this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001642 resetKeyguardDonePendingLocked();
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001643 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001644
Jorim Jaggi241ae102016-11-02 21:57:33 -07001645 mUpdateMonitor.clearFailedUnlockAttempts();
Jim Millerf41fc962014-06-18 16:33:51 -07001646 mUpdateMonitor.clearFingerprintRecognized();
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -07001647
Jorim Jaggi4474f542015-07-09 16:08:02 -07001648 if (mGoingToSleep) {
1649 Log.i(TAG, "Device is going to sleep, aborting keyguardDone");
1650 return;
1651 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001652 if (mExitSecureCallback != null) {
1653 try {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001654 mExitSecureCallback.onKeyguardExitResult(true /* authenciated */);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001655 } catch (RemoteException e) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001656 Slog.w(TAG, "Failed to call onKeyguardExitResult()", e);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001657 }
1658
1659 mExitSecureCallback = null;
1660
Jorim Jaggi241ae102016-11-02 21:57:33 -07001661 // after succesfully exiting securely, no need to reshow
1662 // the keyguard when they've released the lock
1663 mExternallyEnabled = true;
1664 mNeedToReshowWhenReenabled = false;
1665 updateInputRestricted();
Jim Millere51cf7ae2013-06-25 18:31:56 -07001666 }
1667
1668 handleHide();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001669 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -07001670 }
1671
1672 private void sendUserPresentBroadcast() {
Jason Monkcf5a9532014-09-17 16:22:19 -04001673 synchronized (this) {
1674 if (mBootCompleted) {
Adrian Roos4ab7e592016-04-13 15:38:13 -07001675 int currentUserId = KeyguardUpdateMonitor.getCurrentUser();
1676 final UserHandle currentUser = new UserHandle(currentUserId);
Benjamin Franz4b9f8ed2014-12-01 16:51:48 +00001677 final UserManager um = (UserManager) mContext.getSystemService(
1678 Context.USER_SERVICE);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001679 mUiOffloadThread.submit(() -> {
1680 for (int profileId : um.getProfileIdsWithDisabled(currentUser.getIdentifier())) {
1681 mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, UserHandle.of(profileId));
1682 }
1683 getLockPatternUtils().userPresent(currentUserId);
1684 });
Jason Monkcf5a9532014-09-17 16:22:19 -04001685 } else {
1686 mBootSendUserPresent = true;
1687 }
1688 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001689 }
1690
1691 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001692 * @see #keyguardDone
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001693 * @see #KEYGUARD_DONE_DRAWING
1694 */
1695 private void handleKeyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001696 Trace.beginSection("KeyguardViewMediator#handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001697 synchronized(this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001698 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001699 if (mWaitingUntilKeyguardVisible) {
1700 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible");
1701 mWaitingUntilKeyguardVisible = false;
1702 notifyAll();
1703
1704 // there will usually be two of these sent, one as a timeout, and one
1705 // as a result of the callback, so remove any remaining messages from
1706 // the queue
1707 mHandler.removeMessages(KEYGUARD_DONE_DRAWING);
1708 }
1709 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001710 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001711 }
1712
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001713 private void playSounds(boolean locked) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001714 playSound(locked ? mLockSoundId : mUnlockSoundId);
1715 }
1716
1717 private void playSound(int soundId) {
1718 if (soundId == 0) return;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001719 final ContentResolver cr = mContext.getContentResolver();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001720 if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001721
Marco Nelissend5545bd2011-09-29 12:49:17 -07001722 mLockSounds.stop(mLockSoundStreamId);
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001723 // Init mAudioManager
1724 if (mAudioManager == null) {
1725 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
1726 if (mAudioManager == null) return;
John Spurlockee5ad722015-03-03 16:17:21 -05001727 mUiSoundsStreamType = mAudioManager.getUiSoundsStreamType();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001728 }
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001729
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001730 mUiOffloadThread.submit(() -> {
1731 // If the stream is muted, don't play the sound
1732 if (mAudioManager.isStreamMute(mUiSoundsStreamType)) return;
1733
1734 int id = mLockSounds.play(soundId,
1735 mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/);
1736 synchronized (this) {
1737 mLockSoundStreamId = id;
1738 }
1739 });
1740
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001741 }
Jim Miller2a98a4c2010-11-19 18:49:26 -08001742 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001743
Adrian Roos49e057d2014-08-13 17:14:51 +02001744 private void playTrustedSound() {
Adrian Roos49e057d2014-08-13 17:14:51 +02001745 playSound(mTrustedSoundId);
1746 }
1747
Lucas Dupin47a65c72018-02-15 14:16:18 -08001748 private void updateActivityLockScreenState(boolean showing, boolean aodShowing,
1749 int secondaryDisplayShowing) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001750 mUiOffloadThread.submit(() -> {
1751 try {
Lucas Dupin47a65c72018-02-15 14:16:18 -08001752 ActivityManager.getService().setLockScreenShown(showing, aodShowing,
1753 secondaryDisplayShowing);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001754 } catch (RemoteException e) {
1755 }
1756 });
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001757 }
1758
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001759 /**
1760 * Handle message sent by {@link #showLocked}.
1761 * @see #SHOW
1762 */
Adam Cohenf7522022012-10-03 20:03:18 -07001763 private void handleShow(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001764 Trace.beginSection("KeyguardViewMediator#handleShow");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001765 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
1766 if (mLockPatternUtils.isSecure(currentUser)) {
1767 mLockPatternUtils.getDevicePolicyManager().reportKeyguardSecured(currentUser);
Michal Karpinski779aad92016-01-20 11:56:22 +00001768 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001769 synchronized (KeyguardViewMediator.this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001770 if (!mSystemReady) {
1771 if (DEBUG) Log.d(TAG, "ignoring handleShow because system is not ready.");
1772 return;
1773 } else {
1774 if (DEBUG) Log.d(TAG, "handleShow");
1775 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001776
Lucas Dupin47a65c72018-02-15 14:16:18 -08001777 setShowingLocked(true, mAodShowing);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001778 mStatusBarKeyguardViewManager.show(options);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001779 mHiding = false;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001780 mWakeAndUnlocking = false;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001781 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001782 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001783 adjustStatusBarLocked();
Jeff Brown3dc524b2012-09-30 19:49:11 -07001784 userActivity();
Mike Lockwood674d3e42009-10-06 09:28:54 -04001785 mShowKeyguardWakeLock.release();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001786 }
Jim Miller31921482013-11-06 20:43:55 -08001787 mKeyguardDisplayManager.show();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001788 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001789 }
1790
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001791 private final Runnable mKeyguardGoingAwayRunnable = new Runnable() {
1792 @Override
1793 public void run() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001794 Trace.beginSection("KeyguardViewMediator.mKeyGuardGoingAwayRunnable");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001795 if (DEBUG) Log.d(TAG, "keyguardGoingAway");
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001796 try {
Jorim Jaggi33ae80e2015-02-04 16:37:11 +01001797 mStatusBarKeyguardViewManager.keyguardGoingAway();
1798
Adrian Roosd5c2db62016-03-08 16:11:31 -08001799 int flags = 0;
1800 if (mStatusBarKeyguardViewManager.shouldDisableWindowAnimationsForUnlock()
1801 || mWakeAndUnlocking) {
Adrian Roose99bc052017-11-20 17:55:31 +01001802 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001803 }
1804 if (mStatusBarKeyguardViewManager.isGoingToNotificationShade()) {
Adrian Roose99bc052017-11-20 17:55:31 +01001805 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001806 }
1807 if (mStatusBarKeyguardViewManager.isUnlockWithWallpaper()) {
Adrian Roose99bc052017-11-20 17:55:31 +01001808 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001809 }
1810
Kevin Chyn6db7d5f2017-05-03 22:24:31 -07001811 mUpdateMonitor.setKeyguardGoingAway(true /* goingAway */);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001812 // Don't actually hide the Keyguard at the moment, wait for window
1813 // manager until it tells us it's safe to do so with
1814 // startKeyguardExitAnimation.
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001815 ActivityManager.getService().keyguardGoingAway(flags);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001816 } catch (RemoteException e) {
1817 Log.e(TAG, "Error while calling WindowManager", e);
1818 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001819 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001820 }
1821 };
1822
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001823 private final Runnable mHideAnimationFinishedRunnable = () -> {
1824 mHideAnimationRunning = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -07001825 tryKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001826 };
1827
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001828 /**
1829 * Handle message sent by {@link #hideLocked()}
1830 * @see #HIDE
1831 */
1832 private void handleHide() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001833 Trace.beginSection("KeyguardViewMediator#handleHide");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001834 synchronized (KeyguardViewMediator.this) {
1835 if (DEBUG) Log.d(TAG, "handleHide");
Jorim Jaggib9d60792014-06-03 22:34:22 +02001836
Amith Yamasanieb437d42016-04-29 09:31:25 -07001837 if (mustNotUnlockCurrentUser()) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001838 // In split system user mode, we never unlock system user. The end user has to
1839 // switch to another user.
1840 // TODO: We should stop it early by disabling the swipe up flow. Right now swipe up
1841 // still completes and makes the screen blank.
1842 if (DEBUG) Log.d(TAG, "Split system user, quit unlocking.");
1843 return;
1844 }
Jorim Jaggi76a16232014-08-08 17:00:47 +02001845 mHiding = true;
Jorim Jaggib9d60792014-06-03 22:34:22 +02001846
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001847 if (mShowing && !mOccluded) {
1848 mKeyguardGoingAwayRunnable.run();
1849 } else {
Jorim Jaggi76a16232014-08-08 17:00:47 +02001850 handleStartKeyguardExitAnimation(
1851 SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(),
1852 mHideAnimation.getDuration());
Jorim Jaggi0d674622014-05-21 01:34:15 +02001853 }
1854 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001855 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001856 }
1857
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001858 private void handleStartKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001859 Trace.beginSection("KeyguardViewMediator#handleStartKeyguardExitAnimation");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001860 if (DEBUG) Log.d(TAG, "handleStartKeyguardExitAnimation startTime=" + startTime
1861 + " fadeoutDuration=" + fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02001862 synchronized (KeyguardViewMediator.this) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001863
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001864 if (!mHiding) {
Adrian Roos6ec76b72018-04-25 14:01:11 +02001865 // Tell ActivityManager that we canceled the keyguardExitAnimation.
1866 setShowingLocked(mShowing, mAodShowing, mSecondaryDisplayShowing, true /* force */);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001867 return;
1868 }
1869 mHiding = false;
1870
Jorim Jaggib774e552015-08-24 14:52:45 -07001871 if (mWakeAndUnlocking && mDrawnCallback != null) {
1872
1873 // Hack level over 9000: To speed up wake-and-unlock sequence, force it to report
1874 // the next draw from here so we don't have to wait for window manager to signal
1875 // this to our ViewRootImpl.
1876 mStatusBarKeyguardViewManager.getViewRootImpl().setReportNextDraw();
1877 notifyDrawn(mDrawnCallback);
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001878 mDrawnCallback = null;
Jorim Jaggib774e552015-08-24 14:52:45 -07001879 }
1880
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001881 // only play "unlock" noises if not on a call (since the incall UI
1882 // disables the keyguard)
1883 if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) {
1884 playSounds(false);
1885 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001886
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001887 mWakeAndUnlocking = false;
Lucas Dupin47a65c72018-02-15 14:16:18 -08001888 setShowingLocked(false, mAodShowing);
Jorim Jaggi5277dea2017-05-18 02:05:29 +02001889 mDismissCallbackRegistry.notifyDismissSucceeded();
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001890 mStatusBarKeyguardViewManager.hide(startTime, fadeoutDuration);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001891 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001892 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001893 adjustStatusBarLocked();
Jim Miller705004b2014-09-04 16:51:20 -07001894 sendUserPresentBroadcast();
Kevin Chyn6db7d5f2017-05-03 22:24:31 -07001895 mUpdateMonitor.setKeyguardGoingAway(false /* goingAway */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001896 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001897 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001898 }
1899
Mike Lockwood5f892c12009-11-19 23:39:13 -05001900 private void adjustStatusBarLocked() {
Matthew Ng66f0b702017-12-08 12:58:42 -08001901 adjustStatusBarLocked(false /* forceHideHomeRecentsButtons */);
1902 }
1903
1904 private void adjustStatusBarLocked(boolean forceHideHomeRecentsButtons) {
Mike Lockwood5f892c12009-11-19 23:39:13 -05001905 if (mStatusBarManager == null) {
1906 mStatusBarManager = (StatusBarManager)
1907 mContext.getSystemService(Context.STATUS_BAR_SERVICE);
1908 }
1909 if (mStatusBarManager == null) {
1910 Log.w(TAG, "Could not get status bar manager");
1911 } else {
Daniel Sandlerdba93562011-10-06 16:39:58 -04001912 // Disable aspects of the system/status/navigation bars that must not be re-enabled by
1913 // windows that appear on top, ever
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001914 int flags = StatusBarManager.DISABLE_NONE;
Matthew Ng66f0b702017-12-08 12:58:42 -08001915 if (forceHideHomeRecentsButtons || isShowingAndNotOccluded()) {
1916 flags |= StatusBarManager.DISABLE_HOME | StatusBarManager.DISABLE_RECENT;
Jorim Jaggia005f1b2014-04-16 19:06:10 +02001917 }
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001918
1919 if (DEBUG) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001920 Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mOccluded=" + mOccluded
Matthew Ng66f0b702017-12-08 12:58:42 -08001921 + " isSecure=" + isSecure() + " force=" + forceHideHomeRecentsButtons
1922 + " --> flags=0x" + Integer.toHexString(flags));
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001923 }
1924
Jorim Jaggie3e0b062017-06-12 12:18:41 -07001925 mStatusBarManager.disable(flags);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001926 }
1927 }
1928
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001929 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001930 * Handle message sent by {@link #resetStateLocked}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001931 * @see #RESET
1932 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001933 private void handleReset() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001934 synchronized (KeyguardViewMediator.this) {
1935 if (DEBUG) Log.d(TAG, "handleReset");
Jorim Jaggife762342016-10-13 14:33:27 +02001936 mStatusBarKeyguardViewManager.reset(true /* hideBouncerWhenShowing */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001937 }
1938 }
1939
1940 /**
1941 * Handle message sent by {@link #verifyUnlock}
Craig Mautner904732c2012-10-17 15:20:24 -07001942 * @see #VERIFY_UNLOCK
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001943 */
1944 private void handleVerifyUnlock() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001945 Trace.beginSection("KeyguardViewMediator#handleVerifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001946 synchronized (KeyguardViewMediator.this) {
1947 if (DEBUG) Log.d(TAG, "handleVerifyUnlock");
Lucas Dupin47a65c72018-02-15 14:16:18 -08001948 setShowingLocked(true, mAodShowing);
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001949 mStatusBarKeyguardViewManager.dismissAndCollapse();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001950 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001951 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001952 }
1953
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001954 private void handleNotifyStartedGoingToSleep() {
1955 synchronized (KeyguardViewMediator.this) {
1956 if (DEBUG) Log.d(TAG, "handleNotifyStartedGoingToSleep");
1957 mStatusBarKeyguardViewManager.onStartedGoingToSleep();
1958 }
1959 }
1960
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001961 /**
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001962 * Handle message sent by {@link #notifyFinishedGoingToSleep()}
1963 * @see #NOTIFY_FINISHED_GOING_TO_SLEEP
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001964 */
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001965 private void handleNotifyFinishedGoingToSleep() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001966 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001967 if (DEBUG) Log.d(TAG, "handleNotifyFinishedGoingToSleep");
1968 mStatusBarKeyguardViewManager.onFinishedGoingToSleep();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001969 }
1970 }
1971
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001972 private void handleNotifyStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001973 Trace.beginSection("KeyguardViewMediator#handleMotifyStartedWakingUp");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001974 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001975 if (DEBUG) Log.d(TAG, "handleNotifyWakingUp");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001976 mStatusBarKeyguardViewManager.onStartedWakingUp();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001977 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001978 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001979 }
1980
1981 private void handleNotifyScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001982 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurningOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001983 synchronized (KeyguardViewMediator.this) {
1984 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurningOn");
Jorim Jaggi93739112015-08-13 15:53:14 -07001985 mStatusBarKeyguardViewManager.onScreenTurningOn();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001986 if (callback != null) {
1987 if (mWakeAndUnlocking) {
1988 mDrawnCallback = callback;
1989 } else {
1990 notifyDrawn(callback);
1991 }
1992 }
1993 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001994 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001995 }
1996
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001997 private void handleNotifyScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001998 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurnedOn");
Jorim Jaggic3fe2042016-10-07 18:52:48 +02001999 if (LatencyTracker.isEnabled(mContext)) {
2000 LatencyTracker.getInstance(mContext).onActionEnd(LatencyTracker.ACTION_TURN_ON_SCREEN);
2001 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002002 synchronized (this) {
2003 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOn");
2004 mStatusBarKeyguardViewManager.onScreenTurnedOn();
2005 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002006 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002007 }
2008
2009 private void handleNotifyScreenTurnedOff() {
2010 synchronized (this) {
2011 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOff");
2012 mStatusBarKeyguardViewManager.onScreenTurnedOff();
Jorim Jaggie93e6f92016-08-04 13:55:39 +02002013 mDrawnCallback = null;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002014 }
2015 }
2016
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002017 private void notifyDrawn(final IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002018 Trace.beginSection("KeyguardViewMediator#notifyDrawn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002019 try {
2020 callback.onDrawn();
2021 } catch (RemoteException e) {
2022 Slog.w(TAG, "Exception calling onDrawn():", e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002023 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002024 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002025 }
Jeff Sharkey054340d2011-09-01 22:28:03 -07002026
Jorim Jaggif8d77da2014-11-11 16:59:12 +01002027 private void resetKeyguardDonePendingLocked() {
2028 mKeyguardDonePending = false;
2029 mHandler.removeMessages(KEYGUARD_DONE_PENDING_TIMEOUT);
2030 }
2031
Jim Miller2967f482016-01-07 15:05:32 -08002032 @Override
Jim Millere5f910a2013-10-16 18:15:46 -07002033 public void onBootCompleted() {
2034 mUpdateMonitor.dispatchBootCompleted();
Jason Monkcf5a9532014-09-17 16:22:19 -04002035 synchronized (this) {
2036 mBootCompleted = true;
2037 if (mBootSendUserPresent) {
2038 sendUserPresentBroadcast();
2039 }
2040 }
Jim Millere5f910a2013-10-16 18:15:46 -07002041 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002042
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002043 public void onWakeAndUnlocking() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002044 Trace.beginSection("KeyguardViewMediator#onWakeAndUnlocking");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002045 mWakeAndUnlocking = true;
Jorim Jaggi241ae102016-11-02 21:57:33 -07002046 keyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07002047 Trace.endSection();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002048 }
2049
Jason Monk2a6ea9c2017-01-26 11:14:51 -05002050 public StatusBarKeyguardViewManager registerStatusBar(StatusBar statusBar,
Lucas Dupinbc9aac12018-03-04 20:18:15 -08002051 ViewGroup container, NotificationPanelView panelView,
2052 FingerprintUnlockController fingerprintUnlockController) {
2053 mStatusBarKeyguardViewManager.registerStatusBar(statusBar, container, panelView,
Lucas Dupin9e3fa102017-11-08 17:16:55 -08002054 fingerprintUnlockController, mDismissCallbackRegistry);
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002055 return mStatusBarKeyguardViewManager;
2056 }
2057
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002058 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002059 Trace.beginSection("KeyguardViewMediator#startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002060 Message msg = mHandler.obtainMessage(START_KEYGUARD_EXIT_ANIM,
2061 new StartKeyguardExitAnimParams(startTime, fadeoutDuration));
Jorim Jaggi0d674622014-05-21 01:34:15 +02002062 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07002063 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02002064 }
2065
Andrew Zengb4045d32017-03-16 17:25:07 -07002066 public void onShortPowerPressedGoHome() {
2067 // do nothing
2068 }
2069
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002070 public ViewMediatorCallback getViewMediatorCallback() {
2071 return mViewMediatorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002072 }
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002073
Xiyuan Xia1b30f792016-01-06 08:50:30 -08002074 public LockPatternUtils getLockPatternUtils() {
2075 return mLockPatternUtils;
2076 }
2077
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002078 @Override
2079 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
2080 pw.print(" mSystemReady: "); pw.println(mSystemReady);
2081 pw.print(" mBootCompleted: "); pw.println(mBootCompleted);
2082 pw.print(" mBootSendUserPresent: "); pw.println(mBootSendUserPresent);
2083 pw.print(" mExternallyEnabled: "); pw.println(mExternallyEnabled);
Adrian Roos1f8025a2016-12-27 10:12:13 -08002084 pw.print(" mShuttingDown: "); pw.println(mShuttingDown);
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002085 pw.print(" mNeedToReshowWhenReenabled: "); pw.println(mNeedToReshowWhenReenabled);
2086 pw.print(" mShowing: "); pw.println(mShowing);
2087 pw.print(" mInputRestricted: "); pw.println(mInputRestricted);
2088 pw.print(" mOccluded: "); pw.println(mOccluded);
2089 pw.print(" mDelayedShowingSequence: "); pw.println(mDelayedShowingSequence);
2090 pw.print(" mExitSecureCallback: "); pw.println(mExitSecureCallback);
2091 pw.print(" mDeviceInteractive: "); pw.println(mDeviceInteractive);
2092 pw.print(" mGoingToSleep: "); pw.println(mGoingToSleep);
2093 pw.print(" mHiding: "); pw.println(mHiding);
2094 pw.print(" mWaitingUntilKeyguardVisible: "); pw.println(mWaitingUntilKeyguardVisible);
2095 pw.print(" mKeyguardDonePending: "); pw.println(mKeyguardDonePending);
2096 pw.print(" mHideAnimationRun: "); pw.println(mHideAnimationRun);
2097 pw.print(" mPendingReset: "); pw.println(mPendingReset);
2098 pw.print(" mPendingLock: "); pw.println(mPendingLock);
2099 pw.print(" mWakeAndUnlocking: "); pw.println(mWakeAndUnlocking);
2100 pw.print(" mDrawnCallback: "); pw.println(mDrawnCallback);
2101 }
2102
Lucas Dupin47a65c72018-02-15 14:16:18 -08002103 public void setAodShowing(boolean aodShowing) {
2104 setShowingLocked(mShowing, aodShowing);
2105 }
2106
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002107 private static class StartKeyguardExitAnimParams {
2108
2109 long startTime;
2110 long fadeoutDuration;
2111
2112 private StartKeyguardExitAnimParams(long startTime, long fadeoutDuration) {
2113 this.startTime = startTime;
2114 this.fadeoutDuration = fadeoutDuration;
2115 }
2116 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002117
Lucas Dupin47a65c72018-02-15 14:16:18 -08002118 private void setShowingLocked(boolean showing, boolean aodShowing) {
2119 setShowingLocked(showing, aodShowing, mSecondaryDisplayShowing,
2120 false /* forceCallbacks */);
Jorim Jaggie8f321e2016-11-07 16:48:31 -08002121 }
2122
Lucas Dupin47a65c72018-02-15 14:16:18 -08002123 private void setShowingLocked(boolean showing, boolean aodShowing, int secondaryDisplayShowing,
2124 boolean forceCallbacks) {
2125 final boolean notifyDefaultDisplayCallbacks = showing != mShowing
2126 || aodShowing != mAodShowing || forceCallbacks;
David Stevens53a39ea2017-08-23 18:41:49 -07002127 if (notifyDefaultDisplayCallbacks || secondaryDisplayShowing != mSecondaryDisplayShowing) {
Jim Millerab954542014-10-10 18:21:49 -07002128 mShowing = showing;
Lucas Dupin47a65c72018-02-15 14:16:18 -08002129 mAodShowing = aodShowing;
David Stevens53a39ea2017-08-23 18:41:49 -07002130 mSecondaryDisplayShowing = secondaryDisplayShowing;
2131 if (notifyDefaultDisplayCallbacks) {
2132 notifyDefaultDisplayCallbacks(showing);
2133 }
Lucas Dupin47a65c72018-02-15 14:16:18 -08002134 updateActivityLockScreenState(showing, aodShowing, secondaryDisplayShowing);
David Stevens53a39ea2017-08-23 18:41:49 -07002135 }
2136 }
2137
2138 private void notifyDefaultDisplayCallbacks(boolean showing) {
2139 int size = mKeyguardStateCallbacks.size();
2140 for (int i = size - 1; i >= 0; i--) {
2141 IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
2142 try {
2143 callback.onShowingStateChanged(showing);
2144 } catch (RemoteException e) {
2145 Slog.w(TAG, "Failed to call onShowingStateChanged", e);
2146 if (e instanceof DeadObjectException) {
2147 mKeyguardStateCallbacks.remove(callback);
Jim Millerab954542014-10-10 18:21:49 -07002148 }
Jim Millerab954542014-10-10 18:21:49 -07002149 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002150 }
David Stevens53a39ea2017-08-23 18:41:49 -07002151 updateInputRestrictedLocked();
2152 mUiOffloadThread.submit(() -> {
2153 mTrustManager.reportKeyguardShowingChanged();
2154 });
Adrian Roos481a6df2014-11-20 19:48:56 +01002155 }
Jim Millerab954542014-10-10 18:21:49 -07002156
Adrian Roosd88eb262016-08-04 14:50:48 -07002157 private void notifyTrustedChangedLocked(boolean trusted) {
2158 int size = mKeyguardStateCallbacks.size();
2159 for (int i = size - 1; i >= 0; i--) {
2160 try {
2161 mKeyguardStateCallbacks.get(i).onTrustedChanged(trusted);
2162 } catch (RemoteException e) {
2163 Slog.w(TAG, "Failed to call notifyTrustedChangedLocked", e);
2164 if (e instanceof DeadObjectException) {
2165 mKeyguardStateCallbacks.remove(i);
2166 }
2167 }
2168 }
2169 }
2170
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002171 private void notifyHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
2172 int size = mKeyguardStateCallbacks.size();
2173 for (int i = size - 1; i >= 0; i--) {
2174 try {
2175 mKeyguardStateCallbacks.get(i).onHasLockscreenWallpaperChanged(
2176 hasLockscreenWallpaper);
2177 } catch (RemoteException e) {
2178 Slog.w(TAG, "Failed to call onHasLockscreenWallpaperChanged", e);
2179 if (e instanceof DeadObjectException) {
2180 mKeyguardStateCallbacks.remove(i);
2181 }
2182 }
2183 }
2184 }
2185
Jim Millerab954542014-10-10 18:21:49 -07002186 public void addStateMonitorCallback(IKeyguardStateCallback callback) {
2187 synchronized (this) {
2188 mKeyguardStateCallbacks.add(callback);
2189 try {
2190 callback.onSimSecureStateChanged(mUpdateMonitor.isSimPinSecure());
2191 callback.onShowingStateChanged(mShowing);
Adrian Roos4a963ac2015-04-24 16:04:53 -07002192 callback.onInputRestrictedStateChanged(mInputRestricted);
Adrian Roosd88eb262016-08-04 14:50:48 -07002193 callback.onTrustedChanged(mUpdateMonitor.getUserHasTrust(
2194 KeyguardUpdateMonitor.getCurrentUser()));
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002195 callback.onHasLockscreenWallpaperChanged(mUpdateMonitor.hasLockscreenWallpaper());
Jim Millerab954542014-10-10 18:21:49 -07002196 } catch (RemoteException e) {
Adrian Roosd88eb262016-08-04 14:50:48 -07002197 Slog.w(TAG, "Failed to call to IKeyguardStateCallback", e);
Jim Millerab954542014-10-10 18:21:49 -07002198 }
2199 }
2200 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08002201
2202 private static class DismissMessage {
2203 private final CharSequence mMessage;
2204 private final IKeyguardDismissCallback mCallback;
2205
2206 DismissMessage(IKeyguardDismissCallback callback, CharSequence message) {
2207 mCallback = callback;
2208 mMessage = message;
2209 }
2210
2211 public IKeyguardDismissCallback getCallback() {
2212 return mCallback;
2213 }
2214
2215 public CharSequence getMessage() {
2216 return mMessage;
2217 }
2218 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002219}