blob: 89688fba1cc6a9ad042ecbb9e7e20fcf3c5905f0 [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
Lucas Dupind35502f2018-06-27 13:35:52 -0700347 /**
348 * @see #setPulsing(boolean)
349 */
350 private boolean mPulsing;
351
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000352 private boolean mLockLater;
353
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700354 private boolean mWakeAndUnlocking;
355 private IKeyguardDrawnCallback mDrawnCallback;
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800356 private boolean mLockWhenSimRemoved;
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800357 private CharSequence mCustomMessage;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700358
Jim Millerbbf1a742012-07-17 18:30:30 -0700359 KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {
360
361 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500362 public void onUserSwitching(int userId) {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700363 // Note that the mLockPatternUtils user has already been updated from setCurrentUser.
Adam Cohenf7522022012-10-03 20:03:18 -0700364 // We need to force a reset of the views, since lockNow (called by
365 // ActivityManagerService) will not reconstruct the keyguard if it is already showing.
Jim Millerbbf1a742012-07-17 18:30:30 -0700366 synchronized (KeyguardViewMediator.this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100367 resetKeyguardDonePendingLocked();
Alex Chau77ef9fc2018-04-11 15:41:32 +0100368 if (mLockPatternUtils.isLockScreenDisabled(userId)) {
369 // If we switching to a user that has keyguard disabled, dismiss keyguard.
370 dismiss(null /* callback */, null /* message */);
371 } else {
372 resetStateLocked();
373 }
John Spurlock4e6922d2012-10-04 14:51:51 -0400374 adjustStatusBarLocked();
Dianne Hackborn5dc5a002012-09-15 19:33:48 -0700375 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700376 }
377
378 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500379 public void onUserSwitchComplete(int userId) {
Xiaohui Chen87d0e252015-07-30 15:38:16 -0700380 if (userId != UserHandle.USER_SYSTEM) {
Adrian Roosbe47b072014-09-03 00:08:56 +0200381 UserInfo info = UserManager.get(mContext).getUserInfo(userId);
Kevin Chynf2c0a642017-05-25 11:29:08 -0700382 // Don't try to dismiss if the user has Pin/Patter/Password set
383 if (info == null || mLockPatternUtils.isSecure(userId)) {
384 return;
385 } else if (info.isGuest() || info.isDemo()) {
Adrian Roosbe47b072014-09-03 00:08:56 +0200386 // If we just switched to a guest, try to dismiss keyguard.
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800387 dismiss(null /* callback */, null /* message */);
Adrian Roosbe47b072014-09-03 00:08:56 +0200388 }
389 }
Chris Wrenf41c61b2012-11-29 15:19:54 -0500390 }
391
392 @Override
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -0700393 public void onUserInfoChanged(int userId) {
Jim Millerbbf1a742012-07-17 18:30:30 -0700394 }
395
396 @Override
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100397 public void onPhoneStateChanged(int phoneState) {
Jim Millerbbf1a742012-07-17 18:30:30 -0700398 synchronized (KeyguardViewMediator.this) {
399 if (TelephonyManager.CALL_STATE_IDLE == phoneState // call ending
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700400 && !mDeviceInteractive // screen off
Jim Millerbbf1a742012-07-17 18:30:30 -0700401 && mExternallyEnabled) { // not disabled by any app
402
403 // note: this is a way to gracefully reenable the keyguard when the call
404 // ends and the screen is off without always reenabling the keyguard
405 // each time the screen turns off while in call (and having an occasional ugly
406 // flicker while turning back on the screen and disabling the keyguard again).
407 if (DEBUG) Log.d(TAG, "screen is off and call ended, let's make sure the "
408 + "keyguard is showing");
Jim Miller5ecd8112013-01-09 18:50:26 -0800409 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700410 }
411 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100412 }
Jim Millerb0304762012-03-13 20:01:25 -0700413
414 @Override
415 public void onClockVisibilityChanged() {
416 adjustStatusBarLocked();
417 }
418
419 @Override
420 public void onDeviceProvisioned() {
Jim Miller3fd47af2012-09-21 19:55:27 -0700421 sendUserPresentBroadcast();
Amith Yamasanicb15d662015-11-10 11:11:15 -0800422 synchronized (KeyguardViewMediator.this) {
423 // If system user is provisioned, we might want to lock now to avoid showing launcher
Amith Yamasanieb437d42016-04-29 09:31:25 -0700424 if (mustNotUnlockCurrentUser()) {
Amith Yamasanicb15d662015-11-10 11:11:15 -0800425 doKeyguardLocked(null);
426 }
427 }
Jim Millerb0304762012-03-13 20:01:25 -0700428 }
429
Jim Millerbbf1a742012-07-17 18:30:30 -0700430 @Override
Jim Miller52a61332014-11-12 19:29:51 -0800431 public void onSimStateChanged(int subId, int slotId, IccCardConstants.State simState) {
432
433 if (DEBUG_SIM_STATES) {
434 Log.d(TAG, "onSimStateChanged(subId=" + subId + ", slotId=" + slotId
435 + ",state=" + simState + ")");
436 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700437
dooyoung.hwang328472e2015-05-21 16:09:43 +0900438 int size = mKeyguardStateCallbacks.size();
439 boolean simPinSecure = mUpdateMonitor.isSimPinSecure();
440 for (int i = size - 1; i >= 0; i--) {
441 try {
Jim Millerab954542014-10-10 18:21:49 -0700442 mKeyguardStateCallbacks.get(i).onSimSecureStateChanged(simPinSecure);
dooyoung.hwang328472e2015-05-21 16:09:43 +0900443 } catch (RemoteException e) {
444 Slog.w(TAG, "Failed to call onSimSecureStateChanged", e);
445 if (e instanceof DeadObjectException) {
446 mKeyguardStateCallbacks.remove(i);
447 }
Jim Millerab954542014-10-10 18:21:49 -0700448 }
Jim Millerab954542014-10-10 18:21:49 -0700449 }
450
Jim Millerbbf1a742012-07-17 18:30:30 -0700451 switch (simState) {
452 case NOT_READY:
453 case ABSENT:
454 // only force lock screen in case of missing sim if user hasn't
455 // gone through setup wizard
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800456 synchronized (KeyguardViewMediator.this) {
Jim Millerb256e4e22014-10-31 17:27:13 -0700457 if (shouldWaitForProvisioning()) {
Jim Millerab954542014-10-10 18:21:49 -0700458 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800459 if (DEBUG_SIM_STATES) Log.d(TAG, "ICC_ABSENT isn't showing,"
Jim Millerbbf1a742012-07-17 18:30:30 -0700460 + " we need to show the keyguard since the "
461 + "device isn't provisioned yet.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800462 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700463 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100464 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700465 }
466 }
Adrian Roose92de952016-12-13 12:07:09 -0800467 if (simState == ABSENT) {
468 // MVNO SIMs can become transiently NOT_READY when switching networks,
469 // so we should only lock when they are ABSENT.
470 onSimAbsentLocked();
471 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700472 }
473 break;
474 case PIN_REQUIRED:
475 case PUK_REQUIRED:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800476 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700477 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800478 if (DEBUG_SIM_STATES) Log.d(TAG,
479 "INTENT_VALUE_ICC_LOCKED and keygaurd isn't "
Jim Millerbbf1a742012-07-17 18:30:30 -0700480 + "showing; need to show keyguard so user can enter sim pin");
Jim Miller5ecd8112013-01-09 18:50:26 -0800481 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700482 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100483 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700484 }
485 }
486 break;
487 case PERM_DISABLED:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800488 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700489 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800490 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED and "
Jim Millerbbf1a742012-07-17 18:30:30 -0700491 + "keygaurd isn't showing.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800492 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700493 } else {
Jim Miller52a61332014-11-12 19:29:51 -0800494 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED, resetStateLocked to"
Jim Millerbbf1a742012-07-17 18:30:30 -0700495 + "show permanently disabled message in lockscreen.");
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100496 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700497 }
Adrian Roose92de952016-12-13 12:07:09 -0800498 onSimAbsentLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700499 }
500 break;
501 case READY:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800502 synchronized (KeyguardViewMediator.this) {
Jim Millerab954542014-10-10 18:21:49 -0700503 if (mShowing) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100504 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700505 }
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800506 mLockWhenSimRemoved = true;
Jim Millerbbf1a742012-07-17 18:30:30 -0700507 }
508 break;
Jim Miller52a61332014-11-12 19:29:51 -0800509 default:
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800510 if (DEBUG_SIM_STATES) Log.v(TAG, "Unspecific state: " + simState);
Jim Miller52a61332014-11-12 19:29:51 -0800511 break;
Jim Millerbbf1a742012-07-17 18:30:30 -0700512 }
513 }
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000514
Adrian Roose92de952016-12-13 12:07:09 -0800515 private void onSimAbsentLocked() {
Adrian Roos1f8025a2016-12-27 10:12:13 -0800516 if (isSecure() && mLockWhenSimRemoved && !mShuttingDown) {
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800517 mLockWhenSimRemoved = false;
518 MetricsLogger.action(mContext,
519 MetricsProto.MetricsEvent.ACTION_LOCK_BECAUSE_SIM_REMOVED, mShowing);
520 if (!mShowing) {
Adrian Roose92de952016-12-13 12:07:09 -0800521 Log.i(TAG, "SIM removed, showing keyguard");
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800522 doKeyguardLocked(null);
Adrian Roos1cffe3c2016-11-28 15:46:06 -0800523 }
524 }
525 }
526
Michal Karpinskied5c8f02016-02-09 15:43:41 +0000527 @Override
528 public void onFingerprintAuthFailed() {
529 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
530 if (mLockPatternUtils.isSecure(currentUser)) {
531 mLockPatternUtils.getDevicePolicyManager().reportFailedFingerprintAttempt(
532 currentUser);
533 }
534 }
535
536 @Override
537 public void onFingerprintAuthenticated(int userId) {
538 if (mLockPatternUtils.isSecure(userId)) {
539 mLockPatternUtils.getDevicePolicyManager().reportSuccessfulFingerprintAttempt(
540 userId);
541 }
542 }
Adrian Roosd88eb262016-08-04 14:50:48 -0700543
544 @Override
545 public void onTrustChanged(int userId) {
546 if (userId == KeyguardUpdateMonitor.getCurrentUser()) {
547 synchronized (KeyguardViewMediator.this) {
548 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(userId));
549 }
550 }
551 }
552
Jorim Jaggid11d1a92016-08-16 16:02:32 -0700553 @Override
554 public void onHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
555 synchronized (KeyguardViewMediator.this) {
556 notifyHasLockscreenWallpaperChanged(hasLockscreenWallpaper);
557 }
558 }
Jim Millerb0304762012-03-13 20:01:25 -0700559 };
560
Jim Millerdcb3d842012-08-23 19:18:12 -0700561 ViewMediatorCallback mViewMediatorCallback = new ViewMediatorCallback() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100562
Jim Miller2967f482016-01-07 15:05:32 -0800563 @Override
Jeff Brownc7505bc2012-10-05 21:58:15 -0700564 public void userActivity() {
565 KeyguardViewMediator.this.userActivity();
566 }
567
Jim Miller2967f482016-01-07 15:05:32 -0800568 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700569 public void keyguardDone(boolean strongAuth, int targetUserId) {
570 if (targetUserId != ActivityManager.getCurrentUser()) {
571 return;
572 }
573
Jorim Jaggi241ae102016-11-02 21:57:33 -0700574 tryKeyguardDone();
Jim Millerdcb3d842012-08-23 19:18:12 -0700575 }
576
Jim Miller2967f482016-01-07 15:05:32 -0800577 @Override
Jim Millerdcb3d842012-08-23 19:18:12 -0700578 public void keyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700579 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDoneDrawing");
Jim Millerdcb3d842012-08-23 19:18:12 -0700580 mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700581 Trace.endSection();
Jim Millerdcb3d842012-08-23 19:18:12 -0700582 }
583
584 @Override
585 public void setNeedsInput(boolean needsInput) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100586 mStatusBarKeyguardViewManager.setNeedsInput(needsInput);
Jim Millerdcb3d842012-08-23 19:18:12 -0700587 }
Jeff Brownc7505bc2012-10-05 21:58:15 -0700588
589 @Override
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700590 public void keyguardDonePending(boolean strongAuth, int targetUserId) {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700591 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDonePending");
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700592 if (targetUserId != ActivityManager.getCurrentUser()) {
Nick Desaulniersaeb2e1e2016-07-27 15:36:01 -0700593 Trace.endSection();
Vadim Tryshev8702ca72016-04-22 08:14:12 -0700594 return;
595 }
596
John Spurlock34c4fe52012-11-07 10:12:29 -0500597 mKeyguardDonePending = true;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200598 mHideAnimationRun = true;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700599 mHideAnimationRunning = true;
600 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100601 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_PENDING_TIMEOUT,
602 KEYGUARD_DONE_PENDING_TIMEOUT_MS);
Nick Desaulniers1d396752016-07-25 15:05:33 -0700603 Trace.endSection();
John Spurlock34c4fe52012-11-07 10:12:29 -0500604 }
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800605
606 @Override
607 public void keyguardGone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700608 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardGone");
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800609 mKeyguardDisplayManager.hide();
Nick Desaulniers1d396752016-07-25 15:05:33 -0700610 Trace.endSection();
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800611 }
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200612
613 @Override
614 public void readyForKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700615 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#readyForKeyguardDone");
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200616 if (mKeyguardDonePending) {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -0700617 mKeyguardDonePending = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -0700618 tryKeyguardDone();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200619 }
Nick Desaulniers1d396752016-07-25 15:05:33 -0700620 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200621 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200622
623 @Override
Andrew Lee72b46d42015-01-30 13:23:21 -0800624 public void resetKeyguard() {
625 resetStateLocked();
626 }
627
628 @Override
Matthew Ng66f0b702017-12-08 12:58:42 -0800629 public void onBouncerVisiblityChanged(boolean shown) {
630 synchronized (KeyguardViewMediator.this) {
631 adjustStatusBarLocked(shown);
632 }
633 }
634
635 @Override
Adrian Roos49e057d2014-08-13 17:14:51 +0200636 public void playTrustedSound() {
637 KeyguardViewMediator.this.playTrustedSound();
638 }
Jim Millerab954542014-10-10 18:21:49 -0700639
640 @Override
Adrian Roos94e15a52015-04-16 12:23:18 -0700641 public boolean isScreenOn() {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700642 return mDeviceInteractive;
Adrian Roos94e15a52015-04-16 12:23:18 -0700643 }
Selim Cinek3122fa82015-06-18 01:38:59 -0700644
645 @Override
646 public int getBouncerPromptReason() {
647 int currentUser = ActivityManager.getCurrentUser();
Adrian Roosc13723f2016-01-12 20:29:03 +0100648 boolean trust = mTrustManager.isTrustUsuallyManaged(currentUser);
649 boolean fingerprint = mUpdateMonitor.isUnlockWithFingerprintPossible(currentUser);
650 boolean any = trust || fingerprint;
651 KeyguardUpdateMonitor.StrongAuthTracker strongAuthTracker =
652 mUpdateMonitor.getStrongAuthTracker();
653 int strongAuth = strongAuthTracker.getStrongAuthForUser(currentUser);
654
655 if (any && !strongAuthTracker.hasUserAuthenticatedSinceBoot()) {
Selim Cinek3122fa82015-06-18 01:38:59 -0700656 return KeyguardSecurityView.PROMPT_REASON_RESTART;
Michal Karpinskic52f8672016-11-18 11:32:45 +0000657 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_TIMEOUT) != 0) {
Jorim Jaggi25b4d4b2015-08-11 15:54:06 -0700658 return KeyguardSecurityView.PROMPT_REASON_TIMEOUT;
Adrian Roosc13723f2016-01-12 20:29:03 +0100659 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW) != 0) {
660 return KeyguardSecurityView.PROMPT_REASON_DEVICE_ADMIN;
661 } else if (trust && (strongAuth & SOME_AUTH_REQUIRED_AFTER_USER_REQUEST) != 0) {
662 return KeyguardSecurityView.PROMPT_REASON_USER_REQUEST;
663 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_LOCKOUT) != 0) {
664 return KeyguardSecurityView.PROMPT_REASON_AFTER_LOCKOUT;
Selim Cinek3122fa82015-06-18 01:38:59 -0700665 }
666 return KeyguardSecurityView.PROMPT_REASON_NONE;
667 }
David Stevens53a39ea2017-08-23 18:41:49 -0700668
669 @Override
Lucas Dupinc80c67e2017-12-04 14:29:10 -0800670 public CharSequence consumeCustomMessage() {
671 final CharSequence message = mCustomMessage;
672 mCustomMessage = null;
673 return message;
674 }
675
676 @Override
David Stevens53a39ea2017-08-23 18:41:49 -0700677 public void onSecondaryDisplayShowingChanged(int displayId) {
678 synchronized (KeyguardViewMediator.this) {
Lucas Dupin47a65c72018-02-15 14:16:18 -0800679 setShowingLocked(mShowing, mAodShowing, displayId, false);
David Stevens53a39ea2017-08-23 18:41:49 -0700680 }
681 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700682 };
683
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200684 public void userActivity() {
Jeff Brown3dc524b2012-09-30 19:49:11 -0700685 mPM.userActivity(SystemClock.uptimeMillis(), false);
Jim Millerdcb3d842012-08-23 19:18:12 -0700686 }
687
Amith Yamasanieb437d42016-04-29 09:31:25 -0700688 boolean mustNotUnlockCurrentUser() {
Christine Franks338c6ed2017-08-08 09:39:16 -0700689 return UserManager.isSplitSystemUser()
Amith Yamasanieb437d42016-04-29 09:31:25 -0700690 && KeyguardUpdateMonitor.getCurrentUser() == UserHandle.USER_SYSTEM;
691 }
692
Jim Millerab954542014-10-10 18:21:49 -0700693 private void setupLocked() {
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200694 mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
Adrian Roos481a6df2014-11-20 19:48:56 +0100695 mTrustManager = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE);
696
Mike Lockwood674d3e42009-10-06 09:28:54 -0400697 mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
698 mShowKeyguardWakeLock.setReferenceCounted(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800699
Adrian Roos1f8025a2016-12-27 10:12:13 -0800700 IntentFilter filter = new IntentFilter();
Adrian Roos1f8025a2016-12-27 10:12:13 -0800701 filter.addAction(Intent.ACTION_SHUTDOWN);
702 mContext.registerReceiver(mBroadcastReceiver, filter);
Jim Millerbbf1a742012-07-17 18:30:30 -0700703
Kevin Chyn18e91aa2018-04-11 12:55:45 -0700704 final IntentFilter delayedActionFilter = new IntentFilter();
705 delayedActionFilter.addAction(DELAYED_KEYGUARD_ACTION);
706 delayedActionFilter.addAction(DELAYED_LOCK_PROFILE_ACTION);
707 mContext.registerReceiver(mDelayedLockBroadcastReceiver, delayedActionFilter,
708 SYSTEMUI_PERMISSION, null /* scheduler */);
709
David Stevens53a39ea2017-08-23 18:41:49 -0700710 mKeyguardDisplayManager = new KeyguardDisplayManager(mContext, mViewMediatorCallback);
Jim Miller31921482013-11-06 20:43:55 -0800711
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200712 mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800713
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200714 mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800715
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200716 mLockPatternUtils = new LockPatternUtils(mContext);
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700717 KeyguardUpdateMonitor.setCurrentUser(ActivityManager.getCurrentUser());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800718
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200719 // Assume keyguard is showing (unless it's disabled) until we know for sure, unless Keyguard
720 // is disabled.
721 if (mContext.getResources().getBoolean(
722 com.android.keyguard.R.bool.config_enableKeyguardService)) {
723 setShowingLocked(!shouldWaitForProvisioning()
724 && !mLockPatternUtils.isLockScreenDisabled(
David Stevens53a39ea2017-08-23 18:41:49 -0700725 KeyguardUpdateMonitor.getCurrentUser()),
Lucas Dupin47a65c72018-02-15 14:16:18 -0800726 mAodShowing, mSecondaryDisplayShowing, true /* forceCallbacks */);
Leif Hendrik Wildenc6dc1c92018-02-01 10:54:15 -0800727 } else {
728 // The system's keyguard is disabled or missing.
Lucas Dupin47a65c72018-02-15 14:16:18 -0800729 setShowingLocked(false, mAodShowing, mSecondaryDisplayShowing, true);
Jorim Jaggi7687aaa92017-05-12 00:21:06 +0200730 }
Jim Millere5f17ab2013-11-13 15:40:48 -0800731
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800732 mStatusBarKeyguardViewManager =
733 SystemUIFactory.getInstance().createStatusBarKeyguardViewManager(mContext,
734 mViewMediatorCallback, mLockPatternUtils);
Daniel Sandler687a3272010-03-13 15:44:47 -0500735 final ContentResolver cr = mContext.getContentResolver();
Marco Nelissend5545bd2011-09-29 12:49:17 -0700736
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700737 mDeviceInteractive = mPM.isInteractive();
Daniel Hansson4b716862012-03-29 11:02:05 +0200738
Marco Nelissend5545bd2011-09-29 12:49:17 -0700739 mLockSounds = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
Jim Millerb14288d2012-09-30 18:25:05 -0700740 String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700741 if (soundPath != null) {
742 mLockSoundId = mLockSounds.load(soundPath, 1);
743 }
744 if (soundPath == null || mLockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700745 Log.w(TAG, "failed to load lock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700746 }
Jim Millerb14288d2012-09-30 18:25:05 -0700747 soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700748 if (soundPath != null) {
749 mUnlockSoundId = mLockSounds.load(soundPath, 1);
750 }
751 if (soundPath == null || mUnlockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700752 Log.w(TAG, "failed to load unlock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700753 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200754 soundPath = Settings.Global.getString(cr, Settings.Global.TRUSTED_SOUND);
755 if (soundPath != null) {
756 mTrustedSoundId = mLockSounds.load(soundPath, 1);
757 }
758 if (soundPath == null || mTrustedSoundId == 0) {
759 Log.w(TAG, "failed to load trusted sound from " + soundPath);
760 }
761
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200762 int lockSoundDefaultAttenuation = mContext.getResources().getInteger(
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700763 com.android.internal.R.integer.config_lockSoundVolumeDb);
Jean-Michel Trivif2b0c112012-07-09 11:59:11 -0700764 mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20);
Adrian Roos0002a452014-07-03 13:46:07 +0200765
766 mHideAnimation = AnimationUtils.loadAnimation(mContext,
767 com.android.internal.R.anim.lock_screen_behind_enter);
Robin Leec41f6ec2017-01-10 17:02:34 +0000768
769 mWorkLockController = new WorkLockActivityController(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800770 }
771
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200772 @Override
773 public void start() {
Jim Millerab954542014-10-10 18:21:49 -0700774 synchronized (this) {
775 setupLocked();
776 }
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200777 putComponent(KeyguardViewMediator.class, this);
778 }
779
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800780 /**
781 * Let us know that the system is ready after startup.
782 */
783 public void onSystemReady() {
Adrian Roos30a2ae62018-04-25 19:09:50 +0200784 mHandler.obtainMessage(SYSTEM_READY).sendToTarget();
785 }
786
787 private void handleSystemReady() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800788 synchronized (this) {
789 if (DEBUG) Log.d(TAG, "onSystemReady");
790 mSystemReady = true;
Jim Miller5ecd8112013-01-09 18:50:26 -0800791 doKeyguardLocked(null);
Selim Cinekedd32b82015-06-23 22:05:58 -0400792 mUpdateMonitor.registerCallback(mUpdateCallback);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800793 }
Jim Miller3fd47af2012-09-21 19:55:27 -0700794 // Most services aren't available until the system reaches the ready state, so we
795 // send it here when the device first boots.
796 maybeSendUserPresentBroadcast();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800797 }
798
799 /**
800 * Called to let us know the screen was turned off.
Adrian Roose99bc052017-11-20 17:55:31 +0100801 * @param why either {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_USER} or
802 * {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_TIMEOUT}.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800803 */
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700804 public void onStartedGoingToSleep(int why) {
805 if (DEBUG) Log.d(TAG, "onStartedGoingToSleep(" + why + ")");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800806 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700807 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700808 mGoingToSleep = true;
John Spurlock14adfe42012-11-08 10:29:26 -0500809
Jim Millera4edd152012-01-06 18:24:04 -0800810 // Lock immediately based on setting if secure (user has a pin/pattern/password).
811 // This also "locks" the device when not secure to provide easy access to the
812 // camera while preventing unwanted input.
Adrian Roosd6aa6cb2015-04-16 19:31:29 -0700813 int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jim Millera4edd152012-01-06 18:24:04 -0800814 final boolean lockImmediately =
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700815 mLockPatternUtils.getPowerButtonInstantlyLocks(currentUser)
816 || !mLockPatternUtils.isSecure(currentUser);
Clara Bayarri56878a92015-10-29 15:43:55 +0000817 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000818 mLockLater = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800819 if (mExitSecureCallback != null) {
820 if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled");
Jim Miller5ecd8112013-01-09 18:50:26 -0800821 try {
822 mExitSecureCallback.onKeyguardExitResult(false);
823 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800824 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800825 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800826 mExitSecureCallback = null;
827 if (!mExternallyEnabled) {
Jim Miller9c20d0e2010-01-20 15:00:23 -0800828 hideLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800829 }
830 } else if (mShowing) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700831 mPendingReset = true;
Adrian Roose99bc052017-11-20 17:55:31 +0100832 } else if ((why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_TIMEOUT && timeout > 0)
833 || (why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER && !lockImmediately)) {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700834 doKeyguardLaterLocked(timeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000835 mLockLater = true;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700836 } else if (!mLockPatternUtils.isLockScreenDisabled(currentUser)) {
837 mPendingLock = true;
838 }
839
Jorim Jaggi853cbe32015-06-04 16:31:54 -0700840 if (mPendingLock) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700841 playSounds(true);
842 }
843 }
Jorim Jaggi95e40382015-09-16 15:53:42 -0700844 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedGoingToSleep(why);
Jorim Jaggi18f18ae2015-09-10 15:48:21 -0700845 notifyStartedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700846 }
847
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700848 public void onFinishedGoingToSleep(int why, boolean cameraGestureTriggered) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700849 if (DEBUG) Log.d(TAG, "onFinishedGoingToSleep(" + why + ")");
850 synchronized (this) {
851 mDeviceInteractive = false;
Jorim Jaggi4474f542015-07-09 16:08:02 -0700852 mGoingToSleep = false;
Adrian Roose4cb6c8a2017-07-19 18:08:07 +0200853 mWakeAndUnlocking = false;
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700854
855 resetKeyguardDonePendingLocked();
856 mHideAnimationRun = false;
857
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700858 notifyFinishedGoingToSleep();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700859
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700860 if (cameraGestureTriggered) {
861 Log.i(TAG, "Camera gesture was triggered, preventing Keyguard locking.");
862
863 // Just to make sure, make sure the device is awake.
864 mContext.getSystemService(PowerManager.class).wakeUp(SystemClock.uptimeMillis(),
865 "com.android.systemui:CAMERA_GESTURE_PREVENT_LOCK");
866 mPendingLock = false;
867 mPendingReset = false;
868 }
869
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700870 if (mPendingReset) {
871 resetStateLocked();
872 mPendingReset = false;
873 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000874
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700875 if (mPendingLock) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800876 doKeyguardLocked(null);
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700877 mPendingLock = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800878 }
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000879
880 // We do not have timeout and power button instant lock setting for profile lock.
881 // So we use the personal setting if there is any. But if there is no device
882 // we need to make sure we lock it immediately when the screen is off.
Jorim Jaggif1cdf952016-04-05 21:41:06 -0700883 if (!mLockLater && !cameraGestureTriggered) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000884 doKeyguardForChildProfilesLocked();
885 }
886
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800887 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700888 KeyguardUpdateMonitor.getInstance(mContext).dispatchFinishedGoingToSleep(why);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800889 }
890
Clara Bayarri56878a92015-10-29 15:43:55 +0000891 private long getLockTimeout(int userId) {
Jeff Brown6aaf2952012-10-05 16:01:08 -0700892 // if the screen turned off because of timeout or the user hit the power button
893 // and we don't need to lock immediately, set an alarm
894 // to enable it a little bit later (i.e, give the user a chance
895 // to turn the screen back on within a certain window without
896 // having to unlock the screen)
897 final ContentResolver cr = mContext.getContentResolver();
898
Jeff Brown6aaf2952012-10-05 16:01:08 -0700899 // From SecuritySettings
900 final long lockAfterTimeout = Settings.Secure.getInt(cr,
901 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT,
902 KEYGUARD_LOCK_AFTER_DELAY_DEFAULT);
903
904 // From DevicePolicyAdmin
905 final long policyTimeout = mLockPatternUtils.getDevicePolicyManager()
Pavel Grafov28939982017-10-03 15:11:52 +0100906 .getMaximumTimeToLock(null, userId);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700907
908 long timeout;
Clara Bayarri56878a92015-10-29 15:43:55 +0000909
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000910 if (policyTimeout <= 0) {
Clara Bayarri56878a92015-10-29 15:43:55 +0000911 timeout = lockAfterTimeout;
912 } else {
913 // From DisplaySettings
914 long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT,
915 KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT);
916
Jeff Brown6aaf2952012-10-05 16:01:08 -0700917 // policy in effect. Make sure we don't go beyond policy limit.
918 displayTimeout = Math.max(displayTimeout, 0); // ignore negative values
919 timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000920 timeout = Math.max(timeout, 0);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700921 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700922 return timeout;
923 }
Jeff Brown6aaf2952012-10-05 16:01:08 -0700924
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700925 private void doKeyguardLaterLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000926 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700927 if (timeout == 0) {
Jim Miller5ecd8112013-01-09 18:50:26 -0800928 doKeyguardLocked(null);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700929 } else {
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700930 doKeyguardLaterLocked(timeout);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700931 }
932 }
933
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700934 private void doKeyguardLaterLocked(long timeout) {
935 // Lock in the future
936 long when = SystemClock.elapsedRealtime() + timeout;
937 Intent intent = new Intent(DELAYED_KEYGUARD_ACTION);
938 intent.putExtra("seq", mDelayedShowingSequence);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700939 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700940 PendingIntent sender = PendingIntent.getBroadcast(mContext,
941 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Jim Millera622d3cc2016-03-02 16:02:24 -0800942 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender);
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700943 if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = "
944 + mDelayedShowingSequence);
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000945 doKeyguardLaterForChildProfilesLocked();
Clara Bayarri56878a92015-10-29 15:43:55 +0000946 }
Clara Bayarri10ad84a2015-12-01 17:38:05 +0000947
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000948 private void doKeyguardLaterForChildProfilesLocked() {
Clara Bayarri56878a92015-10-29 15:43:55 +0000949 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700950 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
951 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
952 long userTimeout = getLockTimeout(profileId);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000953 if (userTimeout == 0) {
954 doKeyguardForChildProfilesLocked();
955 } else {
956 long userWhen = SystemClock.elapsedRealtime() + userTimeout;
957 Intent lockIntent = new Intent(DELAYED_LOCK_PROFILE_ACTION);
958 lockIntent.putExtra("seq", mDelayedProfileShowingSequence);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700959 lockIntent.putExtra(Intent.EXTRA_USER_ID, profileId);
Jorim Jaggiad0ce3a2016-04-27 13:15:41 -0700960 lockIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000961 PendingIntent lockSender = PendingIntent.getBroadcast(
962 mContext, 0, lockIntent, PendingIntent.FLAG_CANCEL_CURRENT);
963 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
964 userWhen, lockSender);
965 }
Clara Bayarri3dc575f2016-02-17 15:17:14 +0000966 }
967 }
968 }
969
970 private void doKeyguardForChildProfilesLocked() {
971 UserManager um = UserManager.get(mContext);
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -0700972 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
973 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
974 lockProfile(profileId);
Clara Bayarri56878a92015-10-29 15:43:55 +0000975 }
976 }
Jorim Jaggi5c0c5ac82015-09-16 14:53:48 -0700977 }
978
Jeff Brown6aaf2952012-10-05 16:01:08 -0700979 private void cancelDoKeyguardLaterLocked() {
980 mDelayedShowingSequence++;
981 }
982
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000983 private void cancelDoKeyguardForChildProfilesLocked() {
984 mDelayedProfileShowingSequence++;
985 }
986
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800987 /**
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700988 * Let's us know when the device is waking up.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800989 */
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700990 public void onStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -0700991 Trace.beginSection("KeyguardViewMediator#onStartedWakingUp");
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700992
993 // TODO: Rename all screen off/on references to interactive/sleeping
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800994 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700995 mDeviceInteractive = true;
Jeff Brown6aaf2952012-10-05 16:01:08 -0700996 cancelDoKeyguardLaterLocked();
Tony Mak9c6e8ce2016-03-21 12:07:16 +0000997 cancelDoKeyguardForChildProfilesLocked();
Jorim Jaggid175b6c2015-05-27 15:39:09 -0700998 if (DEBUG) Log.d(TAG, "onStartedWakingUp, seq = " + mDelayedShowingSequence);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700999 notifyStartedWakingUp();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001000 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001001 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedWakingUp();
Jim Miller3fd47af2012-09-21 19:55:27 -07001002 maybeSendUserPresentBroadcast();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001003 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -07001004 }
1005
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001006 public void onScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001007 Trace.beginSection("KeyguardViewMediator#onScreenTurningOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001008 notifyScreenOn(callback);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001009 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001010 }
1011
1012 public void onScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001013 Trace.beginSection("KeyguardViewMediator#onScreenTurnedOn");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001014 notifyScreenTurnedOn();
1015 mUpdateMonitor.dispatchScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001016 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001017 }
1018
1019 public void onScreenTurnedOff() {
1020 notifyScreenTurnedOff();
1021 mUpdateMonitor.dispatchScreenTurnedOff();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001022 }
1023
Jim Miller3fd47af2012-09-21 19:55:27 -07001024 private void maybeSendUserPresentBroadcast() {
Adrian Roos8150d2a2015-04-16 17:11:20 -07001025 if (mSystemReady && mLockPatternUtils.isLockScreenDisabled(
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001026 KeyguardUpdateMonitor.getCurrentUser())) {
Jim Miller3fd47af2012-09-21 19:55:27 -07001027 // Lock screen is disabled because the user has set the preference to "None".
1028 // In this case, send out ACTION_USER_PRESENT here instead of in
1029 // handleKeyguardDone()
1030 sendUserPresentBroadcast();
Adrian Roosfb95a812016-06-20 14:58:59 -07001031 } else if (mSystemReady && shouldWaitForProvisioning()) {
1032 // Skipping the lockscreen because we're not yet provisioned, but we still need to
1033 // notify the StrongAuthTracker that it's now safe to run trust agents, in case the
1034 // user sets a credential later.
1035 getLockPatternUtils().userPresent(KeyguardUpdateMonitor.getCurrentUser());
Jim Miller3fd47af2012-09-21 19:55:27 -07001036 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001037 }
1038
1039 /**
Jeff Brown6aaf2952012-10-05 16:01:08 -07001040 * A dream started. We should lock after the usual screen-off lock timeout but only
1041 * if there is a secure lock pattern.
1042 */
1043 public void onDreamingStarted() {
Selim Cinek99415392016-09-09 14:58:41 -07001044 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001045 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001046 if (mDeviceInteractive
1047 && mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001048 doKeyguardLaterLocked();
1049 }
1050 }
1051 }
1052
1053 /**
1054 * A dream stopped.
1055 */
1056 public void onDreamingStopped() {
Selim Cinek99415392016-09-09 14:58:41 -07001057 KeyguardUpdateMonitor.getInstance(mContext).dispatchDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07001058 synchronized (this) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07001059 if (mDeviceInteractive) {
Jeff Brown6aaf2952012-10-05 16:01:08 -07001060 cancelDoKeyguardLaterLocked();
1061 }
1062 }
1063 }
1064
1065 /**
Adrian Roose99bc052017-11-20 17:55:31 +01001066 * Same semantics as {@link WindowManagerPolicyConstants#enableKeyguard}; provide
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001067 * a way for external stuff to override normal keyguard behavior. For instance
1068 * the phone app disables the keyguard when it receives incoming calls.
1069 */
1070 public void setKeyguardEnabled(boolean enabled) {
1071 synchronized (this) {
1072 if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")");
1073
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001074 mExternallyEnabled = enabled;
1075
1076 if (!enabled && mShowing) {
1077 if (mExitSecureCallback != null) {
1078 if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring");
1079 // we're in the process of handling a request to verify the user
1080 // can get past the keyguard. ignore extraneous requests to disable / reenable
1081 return;
1082 }
1083
1084 // hiding keyguard that is showing, remember to reshow later
1085 if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, "
1086 + "disabling status bar expansion");
1087 mNeedToReshowWhenReenabled = true;
Jim Millerab954542014-10-10 18:21:49 -07001088 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001089 hideLocked();
1090 } else if (enabled && mNeedToReshowWhenReenabled) {
1091 // reenabled after previously hidden, reshow
1092 if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling "
1093 + "status bar expansion");
1094 mNeedToReshowWhenReenabled = false;
Jim Millerab954542014-10-10 18:21:49 -07001095 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001096
1097 if (mExitSecureCallback != null) {
1098 if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting");
Jim Miller5ecd8112013-01-09 18:50:26 -08001099 try {
1100 mExitSecureCallback.onKeyguardExitResult(false);
1101 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001102 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001103 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001104 mExitSecureCallback = null;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001105 resetStateLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001106 } else {
Adam Cohenf7522022012-10-03 20:03:18 -07001107 showLocked(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001108
1109 // block until we know the keygaurd is done drawing (and post a message
1110 // to unblock us after a timeout so we don't risk blocking too long
1111 // and causing an ANR).
1112 mWaitingUntilKeyguardVisible = true;
1113 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS);
1114 if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false");
1115 while (mWaitingUntilKeyguardVisible) {
1116 try {
1117 wait();
1118 } catch (InterruptedException e) {
1119 Thread.currentThread().interrupt();
1120 }
1121 }
1122 if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible");
1123 }
1124 }
1125 }
1126 }
1127
1128 /**
1129 * @see android.app.KeyguardManager#exitKeyguardSecurely
1130 */
Jim Miller25190572013-02-28 17:36:24 -08001131 public void verifyUnlock(IKeyguardExitCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001132 Trace.beginSection("KeyguardViewMediator#verifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001133 synchronized (this) {
1134 if (DEBUG) Log.d(TAG, "verifyUnlock");
Jim Millerb256e4e22014-10-31 17:27:13 -07001135 if (shouldWaitForProvisioning()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001136 // don't allow this api when the device isn't provisioned
1137 if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned");
Jim Miller5ecd8112013-01-09 18:50:26 -08001138 try {
Jim Miller25190572013-02-28 17:36:24 -08001139 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001140 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001141 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001142 }
Mike Lockwood5d258b62009-12-02 13:50:45 -05001143 } else if (mExternallyEnabled) {
1144 // this only applies when the user has externally disabled the
1145 // keyguard. this is unexpected and means the user is not
1146 // using the api properly.
1147 Log.w(TAG, "verifyUnlock called when not externally disabled");
Jim Miller5ecd8112013-01-09 18:50:26 -08001148 try {
Jim Miller25190572013-02-28 17:36:24 -08001149 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001150 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001151 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001152 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001153 } else if (mExitSecureCallback != null) {
1154 // already in progress with someone else
Jim Miller5ecd8112013-01-09 18:50:26 -08001155 try {
Jim Miller25190572013-02-28 17:36:24 -08001156 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -08001157 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -08001158 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -08001159 }
Jorim Jaggi302475e2015-09-22 12:44:47 -07001160 } else if (!isSecure()) {
1161
1162 // Keyguard is not secure, no need to do anything, and we don't need to reshow
1163 // the Keyguard after the client releases the Keyguard lock.
1164 mExternallyEnabled = true;
1165 mNeedToReshowWhenReenabled = false;
1166 updateInputRestricted();
1167 try {
1168 callback.onKeyguardExitResult(true);
1169 } catch (RemoteException e) {
1170 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1171 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001172 } else {
Jorim Jaggi302475e2015-09-22 12:44:47 -07001173
1174 // Since we prevent apps from hiding the Keyguard if we are secure, this should be
1175 // a no-op as well.
1176 try {
1177 callback.onKeyguardExitResult(false);
1178 } catch (RemoteException e) {
1179 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1180 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001181 }
1182 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001183 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001184 }
1185
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001186 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001187 * Is the keyguard currently showing and not being force hidden?
Mike Lockwood09a40402009-11-08 00:33:23 -05001188 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001189 public boolean isShowingAndNotOccluded() {
1190 return mShowing && !mOccluded;
1191 }
1192
1193 /**
1194 * Notify us when the keyguard is occluded by another window
1195 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001196 public void setOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001197 Trace.beginSection("KeyguardViewMediator#setOccluded");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001198 if (DEBUG) Log.d(TAG, "setOccluded " + isOccluded);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001199 mHandler.removeMessages(SET_OCCLUDED);
Jorim Jaggi6626f542016-08-22 13:08:44 -07001200 Message msg = mHandler.obtainMessage(SET_OCCLUDED, isOccluded ? 1 : 0, animate ? 1 : 0);
Mike Lockwood9200a392009-11-17 20:25:58 -05001201 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001202 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001203 }
1204
Lucas Dupin2986c152018-04-09 20:49:41 -07001205 public boolean isHiding() {
1206 return mHiding;
1207 }
1208
Mike Lockwood9200a392009-11-17 20:25:58 -05001209 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001210 * Handles SET_OCCLUDED message sent by setOccluded()
Mike Lockwood9200a392009-11-17 20:25:58 -05001211 */
Jorim Jaggi6626f542016-08-22 13:08:44 -07001212 private void handleSetOccluded(boolean isOccluded, boolean animate) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001213 Trace.beginSection("KeyguardViewMediator#handleSetOccluded");
Mike Lockwood09a40402009-11-08 00:33:23 -05001214 synchronized (KeyguardViewMediator.this) {
Adrian Roosf253eeb2015-04-15 18:03:08 -07001215 if (mHiding && isOccluded) {
1216 // We're in the process of going away but WindowManager wants to show a
1217 // SHOW_WHEN_LOCKED activity instead.
1218 startKeyguardExitAnimation(0, 0);
1219 }
1220
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001221 if (mOccluded != isOccluded) {
1222 mOccluded = isOccluded;
Kevin Chyn2fefd462017-04-28 12:18:19 -07001223 mUpdateMonitor.setKeyguardOccluded(isOccluded);
Selim Cinek2f6272e2017-03-15 16:19:10 -07001224 mStatusBarKeyguardViewManager.setOccluded(isOccluded, animate
1225 && mDeviceInteractive);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001226 adjustStatusBarLocked();
Mike Lockwood9200a392009-11-17 20:25:58 -05001227 }
Mike Lockwood09a40402009-11-08 00:33:23 -05001228 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001229 Trace.endSection();
Mike Lockwood09a40402009-11-08 00:33:23 -05001230 }
1231
1232 /**
Mike Lockwood28569302010-01-28 11:54:40 -05001233 * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout.
1234 * This must be safe to call from any thread and with any window manager locks held.
1235 */
Adam Cohenf7522022012-10-03 20:03:18 -07001236 public void doKeyguardTimeout(Bundle options) {
Mike Lockwood28569302010-01-28 11:54:40 -05001237 mHandler.removeMessages(KEYGUARD_TIMEOUT);
Adam Cohenf7522022012-10-03 20:03:18 -07001238 Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options);
Mike Lockwood28569302010-01-28 11:54:40 -05001239 mHandler.sendMessage(msg);
1240 }
1241
1242 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001243 * Given the state of the keyguard, is the input restricted?
1244 * Input is restricted when the keyguard is showing, or when the keyguard
1245 * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet.
1246 */
1247 public boolean isInputRestricted() {
Adrian Roos9f33d6c2015-06-15 15:58:35 -07001248 return mShowing || mNeedToReshowWhenReenabled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001249 }
1250
Jim Millerab954542014-10-10 18:21:49 -07001251 private void updateInputRestricted() {
1252 synchronized (this) {
1253 updateInputRestrictedLocked();
1254 }
1255 }
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001256
Jim Millerab954542014-10-10 18:21:49 -07001257 private void updateInputRestrictedLocked() {
1258 boolean inputRestricted = isInputRestricted();
1259 if (mInputRestricted != inputRestricted) {
1260 mInputRestricted = inputRestricted;
dooyoung.hwang328472e2015-05-21 16:09:43 +09001261 int size = mKeyguardStateCallbacks.size();
1262 for (int i = size - 1; i >= 0; i--) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001263 final IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001264 try {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001265 callback.onInputRestrictedStateChanged(inputRestricted);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001266 } catch (RemoteException e) {
1267 Slog.w(TAG, "Failed to call onDeviceProvisioned", e);
1268 if (e instanceof DeadObjectException) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001269 mKeyguardStateCallbacks.remove(callback);
dooyoung.hwang328472e2015-05-21 16:09:43 +09001270 }
Jim Millerab954542014-10-10 18:21:49 -07001271 }
Jim Millerab954542014-10-10 18:21:49 -07001272 }
1273 }
1274 }
1275
Dianne Hackbornb446e972009-09-20 15:23:25 -07001276 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001277 * Enable the keyguard if the settings are appropriate.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001278 */
Adam Cohenf7522022012-10-03 20:03:18 -07001279 private void doKeyguardLocked(Bundle options) {
Adrian Roosca8a2162017-08-17 19:00:58 +02001280 if (KeyguardUpdateMonitor.CORE_APPS_ONLY) {
1281 // Don't show keyguard during half-booted cryptkeeper stage.
1282 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because booting to cryptkeeper");
1283 return;
1284 }
1285
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001286 // if another app is disabling us, don't show
1287 if (!mExternallyEnabled) {
1288 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled");
Karl Rosaenab100082009-03-24 22:35:17 -07001289
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001290 // note: we *should* set mNeedToReshowWhenReenabled=true here, but that makes
1291 // for an occasional ugly flicker in this situation:
1292 // 1) receive a call with the screen on (no keyguard) or make a call
1293 // 2) screen times out
1294 // 3) user hits key to turn screen back on
1295 // instead, we reenable the keyguard when we know the screen is off and the call
1296 // ends (see the broadcast receiver below)
1297 // TODO: clean this up when we have better support at the window manager level
1298 // for apps that wish to be on top of the keyguard
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001299 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001300 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001301
1302 // if the keyguard is already showing, don't bother
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001303 if (mStatusBarKeyguardViewManager.isShowing()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001304 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing");
Jorim Jaggi95e89ca2014-11-24 20:12:50 +01001305 resetStateLocked();
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001306 return;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001307 }
1308
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001309 // In split system user mode, we never unlock system user.
Amith Yamasanieb437d42016-04-29 09:31:25 -07001310 if (!mustNotUnlockCurrentUser()
Amith Yamasani27e025b2015-11-06 10:34:41 -08001311 || !mUpdateMonitor.isDeviceProvisioned()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001312
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001313 // if the setup wizard hasn't run yet, don't show
1314 final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", false);
1315 final boolean absent = SubscriptionManager.isValidSubscriptionId(
Adrian Roose92de952016-12-13 12:07:09 -08001316 mUpdateMonitor.getNextSubIdForState(ABSENT));
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001317 final boolean disabled = SubscriptionManager.isValidSubscriptionId(
1318 mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.PERM_DISABLED));
1319 final boolean lockedOrMissing = mUpdateMonitor.isSimPinSecure()
1320 || ((absent || disabled) && requireSim);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001321
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001322 if (!lockedOrMissing && shouldWaitForProvisioning()) {
1323 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned"
1324 + " and the sim is not locked or missing");
1325 return;
1326 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001327
Evan Rosky13a58a92016-07-27 15:51:09 -07001328 boolean forceShow = options != null && options.getBoolean(OPTION_FORCE_SHOW, false);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001329 if (mLockPatternUtils.isLockScreenDisabled(KeyguardUpdateMonitor.getCurrentUser())
Evan Rosky13a58a92016-07-27 15:51:09 -07001330 && !lockedOrMissing && !forceShow) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001331 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off");
1332 return;
1333 }
1334
1335 if (mLockPatternUtils.checkVoldPassword(KeyguardUpdateMonitor.getCurrentUser())) {
1336 if (DEBUG) Log.d(TAG, "Not showing lock screen since just decrypted");
1337 // Without this, settings is not enabled until the lock screen first appears
Lucas Dupin47a65c72018-02-15 14:16:18 -08001338 setShowingLocked(false, mAodShowing);
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001339 hideLocked();
1340 return;
1341 }
Paul Lawrence945490c2014-03-27 16:37:28 +00001342 }
1343
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001344 if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");
Adam Cohenf7522022012-10-03 20:03:18 -07001345 showLocked(options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001346 }
1347
Clara Bayarri56878a92015-10-29 15:43:55 +00001348 private void lockProfile(int userId) {
1349 mTrustManager.setDeviceLockedForUser(userId, true);
1350 }
1351
Jim Millerb256e4e22014-10-31 17:27:13 -07001352 private boolean shouldWaitForProvisioning() {
1353 return !mUpdateMonitor.isDeviceProvisioned() && !isSecure();
1354 }
1355
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001356 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001357 * Dismiss the keyguard through the security layers.
Jorim Jaggi241ae102016-11-02 21:57:33 -07001358 * @param callback Callback to be informed about the result
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001359 * @param message Message that should be displayed on the bouncer.
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001360 */
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001361 private void handleDismiss(IKeyguardDismissCallback callback, CharSequence message) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001362 if (mShowing) {
1363 if (callback != null) {
1364 mDismissCallbackRegistry.addCallback(callback);
1365 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001366 mCustomMessage = message;
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001367 mStatusBarKeyguardViewManager.dismissAndCollapse();
Jorim Jaggi241ae102016-11-02 21:57:33 -07001368 } else if (callback != null) {
1369 new DismissCallbackWrapper(callback).notifyDismissError();
Jim Miller87d03662012-11-05 20:28:09 -08001370 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001371 }
1372
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001373 public void dismiss(IKeyguardDismissCallback callback, CharSequence message) {
1374 mHandler.obtainMessage(DISMISS, new DismissMessage(callback, message)).sendToTarget();
Jim Miller60013792013-10-03 18:31:34 -07001375 }
1376
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001377 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001378 * Send message to keyguard telling it to reset its state.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001379 * @see #handleReset
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001380 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001381 private void resetStateLocked() {
Jim Miller4894a012013-04-03 15:23:55 -07001382 if (DEBUG) Log.e(TAG, "resetStateLocked");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001383 Message msg = mHandler.obtainMessage(RESET);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001384 mHandler.sendMessage(msg);
1385 }
1386
1387 /**
1388 * Send message to keyguard telling it to verify unlock
1389 * @see #handleVerifyUnlock()
1390 */
1391 private void verifyUnlockLocked() {
1392 if (DEBUG) Log.d(TAG, "verifyUnlockLocked");
1393 mHandler.sendEmptyMessage(VERIFY_UNLOCK);
1394 }
1395
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001396 private void notifyStartedGoingToSleep() {
1397 if (DEBUG) Log.d(TAG, "notifyStartedGoingToSleep");
1398 mHandler.sendEmptyMessage(NOTIFY_STARTED_GOING_TO_SLEEP);
1399 }
1400
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001401 private void notifyFinishedGoingToSleep() {
1402 if (DEBUG) Log.d(TAG, "notifyFinishedGoingToSleep");
1403 mHandler.sendEmptyMessage(NOTIFY_FINISHED_GOING_TO_SLEEP);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001404 }
1405
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001406 private void notifyStartedWakingUp() {
1407 if (DEBUG) Log.d(TAG, "notifyStartedWakingUp");
1408 mHandler.sendEmptyMessage(NOTIFY_STARTED_WAKING_UP);
1409 }
1410
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001411 private void notifyScreenOn(IKeyguardDrawnCallback callback) {
1412 if (DEBUG) Log.d(TAG, "notifyScreenOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001413 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNING_ON, callback);
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001414 mHandler.sendMessage(msg);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001415 }
1416
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001417 private void notifyScreenTurnedOn() {
1418 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOn");
1419 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_ON);
1420 mHandler.sendMessage(msg);
1421 }
1422
1423 private void notifyScreenTurnedOff() {
1424 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOff");
1425 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_OFF);
1426 mHandler.sendMessage(msg);
1427 }
1428
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001429 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001430 * Send message to keyguard telling it to show itself
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001431 * @see #handleShow
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001432 */
Adam Cohenf7522022012-10-03 20:03:18 -07001433 private void showLocked(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001434 Trace.beginSection("KeyguardViewMediator#showLocked aqcuiring mShowKeyguardWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001435 if (DEBUG) Log.d(TAG, "showLocked");
Mike Lockwood674d3e42009-10-06 09:28:54 -04001436 // ensure we stay awake until we are finished displaying the keyguard
1437 mShowKeyguardWakeLock.acquire();
Adam Cohenf7522022012-10-03 20:03:18 -07001438 Message msg = mHandler.obtainMessage(SHOW, options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001439 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001440 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001441 }
1442
1443 /**
1444 * Send message to keyguard telling it to hide itself
Jim Miller9c20d0e2010-01-20 15:00:23 -08001445 * @see #handleHide()
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001446 */
1447 private void hideLocked() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001448 Trace.beginSection("KeyguardViewMediator#hideLocked");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001449 if (DEBUG) Log.d(TAG, "hideLocked");
1450 Message msg = mHandler.obtainMessage(HIDE);
1451 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001452 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001453 }
1454
Dianne Hackbornb446e972009-09-20 15:23:25 -07001455 public boolean isSecure() {
Evan Rosky13a58a92016-07-27 15:51:09 -07001456 return isSecure(KeyguardUpdateMonitor.getCurrentUser());
1457 }
1458
1459 public boolean isSecure(int userId) {
1460 return mLockPatternUtils.isSecure(userId)
1461 || KeyguardUpdateMonitor.getInstance(mContext).isSimPinSecure();
Dianne Hackbornb446e972009-09-20 15:23:25 -07001462 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001463
Evan Rosky18396452016-07-27 15:19:37 -07001464 public void setSwitchingUser(boolean switching) {
Selim Cinekbbe19242017-12-08 15:42:08 -08001465 KeyguardUpdateMonitor.getInstance(mContext).setSwitchingUser(switching);
Evan Rosky18396452016-07-27 15:19:37 -07001466 }
1467
Craig Mautnerf1b67412012-09-19 13:18:29 -07001468 /**
1469 * Update the newUserId. Call while holding WindowManagerService lock.
Jim Milleree82f8f2012-10-01 16:26:18 -07001470 * NOTE: Should only be called by KeyguardViewMediator in response to the user id changing.
1471 *
Craig Mautnerf1b67412012-09-19 13:18:29 -07001472 * @param newUserId The id of the incoming user.
1473 */
1474 public void setCurrentUser(int newUserId) {
Adrian Roosd6aa6cb2015-04-16 19:31:29 -07001475 KeyguardUpdateMonitor.setCurrentUser(newUserId);
Adrian Roosd88eb262016-08-04 14:50:48 -07001476 synchronized (this) {
1477 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(newUserId));
1478 }
Craig Mautnerf1b67412012-09-19 13:18:29 -07001479 }
1480
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001481 /**
1482 * This broadcast receiver should be registered with the SystemUI permission.
1483 */
1484 private final BroadcastReceiver mDelayedLockBroadcastReceiver = new BroadcastReceiver() {
Amith Yamasani52c489c2012-03-28 11:42:42 -07001485 @Override
1486 public void onReceive(Context context, Intent intent) {
Jim Millerbbf1a742012-07-17 18:30:30 -07001487 if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
1488 final int sequence = intent.getIntExtra("seq", 0);
Jim Millerf3447352011-08-07 14:00:09 -07001489 if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = "
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001490 + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001491 synchronized (KeyguardViewMediator.this) {
Jim Miller2967f482016-01-07 15:05:32 -08001492 if (mDelayedShowingSequence == sequence) {
1493 doKeyguardLocked(null);
1494 }
Clara Bayarri56878a92015-10-29 15:43:55 +00001495 }
1496 } else if (DELAYED_LOCK_PROFILE_ACTION.equals(intent.getAction())) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001497 final int sequence = intent.getIntExtra("seq", 0);
Clara Bayarri56878a92015-10-29 15:43:55 +00001498 int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, 0);
1499 if (userId != 0) {
1500 synchronized (KeyguardViewMediator.this) {
Tony Mak9c6e8ce2016-03-21 12:07:16 +00001501 if (mDelayedProfileShowingSequence == sequence) {
1502 lockProfile(userId);
1503 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001504 }
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001505 }
Kevin Chyn18e91aa2018-04-11 12:55:45 -07001506 }
1507 }
1508 };
1509
1510 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1511 @Override
1512 public void onReceive(Context context, Intent intent) {
1513 if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
Adrian Roos1f8025a2016-12-27 10:12:13 -08001514 synchronized (KeyguardViewMediator.this){
1515 mShuttingDown = true;
1516 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001517 }
1518 }
1519 };
1520
Jorim Jaggi241ae102016-11-02 21:57:33 -07001521 public void keyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001522 Trace.beginSection("KeyguardViewMediator#keyguardDone");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001523 if (DEBUG) Log.d(TAG, "keyguardDone()");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001524 userActivity();
Jim Miller60013792013-10-03 18:31:34 -07001525 EventLog.writeEvent(70000, 2);
Jorim Jaggi241ae102016-11-02 21:57:33 -07001526 Message msg = mHandler.obtainMessage(KEYGUARD_DONE);
Jim Miller60013792013-10-03 18:31:34 -07001527 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001528 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001529 }
1530
1531 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001532 * This handler will be associated with the policy thread, which will also
1533 * be the UI thread of the keyguard. Since the apis of the policy, and therefore
1534 * this class, can be called by other threads, any action that directly
1535 * interacts with the keyguard ui should be posted to this handler, rather
1536 * than called directly.
1537 */
Jim Millerdcb3d842012-08-23 19:18:12 -07001538 private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001539 @Override
Wink Saville37c124c2009-04-02 01:37:02 -07001540 public void handleMessage(Message msg) {
1541 switch (msg.what) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001542 case SHOW:
Adam Cohenf7522022012-10-03 20:03:18 -07001543 handleShow((Bundle) msg.obj);
Jim Miller60013792013-10-03 18:31:34 -07001544 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001545 case HIDE:
1546 handleHide();
Jim Miller60013792013-10-03 18:31:34 -07001547 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001548 case RESET:
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001549 handleReset();
Jim Miller60013792013-10-03 18:31:34 -07001550 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001551 case VERIFY_UNLOCK:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001552 Trace.beginSection("KeyguardViewMediator#handleMessage VERIFY_UNLOCK");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001553 handleVerifyUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001554 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001555 break;
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001556 case NOTIFY_STARTED_GOING_TO_SLEEP:
1557 handleNotifyStartedGoingToSleep();
1558 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001559 case NOTIFY_FINISHED_GOING_TO_SLEEP:
1560 handleNotifyFinishedGoingToSleep();
Jim Miller60013792013-10-03 18:31:34 -07001561 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001562 case NOTIFY_SCREEN_TURNING_ON:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001563 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNING_ON");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001564 handleNotifyScreenTurningOn((IKeyguardDrawnCallback) msg.obj);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001565 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001566 break;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001567 case NOTIFY_SCREEN_TURNED_ON:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001568 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNED_ON");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001569 handleNotifyScreenTurnedOn();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001570 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001571 break;
1572 case NOTIFY_SCREEN_TURNED_OFF:
1573 handleNotifyScreenTurnedOff();
1574 break;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001575 case NOTIFY_STARTED_WAKING_UP:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001576 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_STARTED_WAKING_UP");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001577 handleNotifyStartedWakingUp();
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:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001581 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE");
Jorim Jaggi241ae102016-11-02 21:57:33 -07001582 handleKeyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001583 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001584 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001585 case KEYGUARD_DONE_DRAWING:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001586 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_DRAWING");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001587 handleKeyguardDoneDrawing();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001588 Trace.endSection();
Jim Miller60013792013-10-03 18:31:34 -07001589 break;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001590 case SET_OCCLUDED:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001591 Trace.beginSection("KeyguardViewMediator#handleMessage SET_OCCLUDED");
Jorim Jaggi6626f542016-08-22 13:08:44 -07001592 handleSetOccluded(msg.arg1 != 0, msg.arg2 != 0);
Nick Desaulniers1d396752016-07-25 15:05:33 -07001593 Trace.endSection();
Mike Lockwood9200a392009-11-17 20:25:58 -05001594 break;
Mike Lockwood28569302010-01-28 11:54:40 -05001595 case KEYGUARD_TIMEOUT:
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001596 synchronized (KeyguardViewMediator.this) {
Adam Cohenf7522022012-10-03 20:03:18 -07001597 doKeyguardLocked((Bundle) msg.obj);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001598 }
1599 break;
Jim Miller60013792013-10-03 18:31:34 -07001600 case DISMISS:
Lucas Dupinc80c67e2017-12-04 14:29:10 -08001601 final DismissMessage message = (DismissMessage) msg.obj;
1602 handleDismiss(message.getCallback(), message.getMessage());
Jim Miller60013792013-10-03 18:31:34 -07001603 break;
Jorim Jaggi0d674622014-05-21 01:34:15 +02001604 case START_KEYGUARD_EXIT_ANIM:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001605 Trace.beginSection("KeyguardViewMediator#handleMessage START_KEYGUARD_EXIT_ANIM");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001606 StartKeyguardExitAnimParams params = (StartKeyguardExitAnimParams) msg.obj;
1607 handleStartKeyguardExitAnimation(params.startTime, params.fadeoutDuration);
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -07001608 FalsingManager.getInstance(mContext).onSucccessfulUnlock();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001609 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001610 break;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001611 case KEYGUARD_DONE_PENDING_TIMEOUT:
Nick Desaulniers1d396752016-07-25 15:05:33 -07001612 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_PENDING_TIMEOUT");
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001613 Log.w(TAG, "Timeout while waiting for activity drawn!");
Nick Desaulniers1d396752016-07-25 15:05:33 -07001614 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001615 break;
Adrian Roos30a2ae62018-04-25 19:09:50 +02001616 case SYSTEM_READY:
1617 handleSystemReady();
1618 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001619 }
1620 }
1621 };
1622
Jorim Jaggi241ae102016-11-02 21:57:33 -07001623 private void tryKeyguardDone() {
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001624 if (!mKeyguardDonePending && mHideAnimationRun && !mHideAnimationRunning) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001625 handleKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001626 } else if (!mHideAnimationRun) {
1627 mHideAnimationRun = true;
1628 mHideAnimationRunning = true;
1629 mStatusBarKeyguardViewManager.startPreHideAnimation(mHideAnimationFinishedRunnable);
1630 }
1631 }
1632
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001633 /**
1634 * @see #keyguardDone
1635 * @see #KEYGUARD_DONE
1636 */
Jorim Jaggi241ae102016-11-02 21:57:33 -07001637 private void handleKeyguardDone() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001638 Trace.beginSection("KeyguardViewMediator#handleKeyguardDone");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001639 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001640 mUiOffloadThread.submit(() -> {
1641 if (mLockPatternUtils.isSecure(currentUser)) {
1642 mLockPatternUtils.getDevicePolicyManager().reportKeyguardDismissed(currentUser);
1643 }
1644 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001645 if (DEBUG) Log.d(TAG, "handleKeyguardDone");
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001646 synchronized (this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001647 resetKeyguardDonePendingLocked();
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001648 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001649
Jorim Jaggi241ae102016-11-02 21:57:33 -07001650 mUpdateMonitor.clearFailedUnlockAttempts();
Jim Millerf41fc962014-06-18 16:33:51 -07001651 mUpdateMonitor.clearFingerprintRecognized();
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -07001652
Jorim Jaggi4474f542015-07-09 16:08:02 -07001653 if (mGoingToSleep) {
1654 Log.i(TAG, "Device is going to sleep, aborting keyguardDone");
1655 return;
1656 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001657 if (mExitSecureCallback != null) {
1658 try {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001659 mExitSecureCallback.onKeyguardExitResult(true /* authenciated */);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001660 } catch (RemoteException e) {
Jorim Jaggi241ae102016-11-02 21:57:33 -07001661 Slog.w(TAG, "Failed to call onKeyguardExitResult()", e);
Jim Millere51cf7ae2013-06-25 18:31:56 -07001662 }
1663
1664 mExitSecureCallback = null;
1665
Jorim Jaggi241ae102016-11-02 21:57:33 -07001666 // after succesfully exiting securely, no need to reshow
1667 // the keyguard when they've released the lock
1668 mExternallyEnabled = true;
1669 mNeedToReshowWhenReenabled = false;
1670 updateInputRestricted();
Jim Millere51cf7ae2013-06-25 18:31:56 -07001671 }
1672
1673 handleHide();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001674 Trace.endSection();
Jim Miller3fd47af2012-09-21 19:55:27 -07001675 }
1676
1677 private void sendUserPresentBroadcast() {
Jason Monkcf5a9532014-09-17 16:22:19 -04001678 synchronized (this) {
1679 if (mBootCompleted) {
Adrian Roos4ab7e592016-04-13 15:38:13 -07001680 int currentUserId = KeyguardUpdateMonitor.getCurrentUser();
1681 final UserHandle currentUser = new UserHandle(currentUserId);
Benjamin Franz4b9f8ed2014-12-01 16:51:48 +00001682 final UserManager um = (UserManager) mContext.getSystemService(
1683 Context.USER_SERVICE);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001684 mUiOffloadThread.submit(() -> {
1685 for (int profileId : um.getProfileIdsWithDisabled(currentUser.getIdentifier())) {
1686 mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, UserHandle.of(profileId));
1687 }
1688 getLockPatternUtils().userPresent(currentUserId);
1689 });
Jason Monkcf5a9532014-09-17 16:22:19 -04001690 } else {
1691 mBootSendUserPresent = true;
1692 }
1693 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001694 }
1695
1696 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001697 * @see #keyguardDone
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001698 * @see #KEYGUARD_DONE_DRAWING
1699 */
1700 private void handleKeyguardDoneDrawing() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001701 Trace.beginSection("KeyguardViewMediator#handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001702 synchronized(this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001703 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001704 if (mWaitingUntilKeyguardVisible) {
1705 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible");
1706 mWaitingUntilKeyguardVisible = false;
1707 notifyAll();
1708
1709 // there will usually be two of these sent, one as a timeout, and one
1710 // as a result of the callback, so remove any remaining messages from
1711 // the queue
1712 mHandler.removeMessages(KEYGUARD_DONE_DRAWING);
1713 }
1714 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001715 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001716 }
1717
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001718 private void playSounds(boolean locked) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001719 playSound(locked ? mLockSoundId : mUnlockSoundId);
1720 }
1721
1722 private void playSound(int soundId) {
1723 if (soundId == 0) return;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001724 final ContentResolver cr = mContext.getContentResolver();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001725 if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001726
Marco Nelissend5545bd2011-09-29 12:49:17 -07001727 mLockSounds.stop(mLockSoundStreamId);
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001728 // Init mAudioManager
1729 if (mAudioManager == null) {
1730 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
1731 if (mAudioManager == null) return;
John Spurlockee5ad722015-03-03 16:17:21 -05001732 mUiSoundsStreamType = mAudioManager.getUiSoundsStreamType();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001733 }
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001734
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001735 mUiOffloadThread.submit(() -> {
1736 // If the stream is muted, don't play the sound
1737 if (mAudioManager.isStreamMute(mUiSoundsStreamType)) return;
1738
1739 int id = mLockSounds.play(soundId,
1740 mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/);
1741 synchronized (this) {
1742 mLockSoundStreamId = id;
1743 }
1744 });
1745
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001746 }
Jim Miller2a98a4c2010-11-19 18:49:26 -08001747 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001748
Adrian Roos49e057d2014-08-13 17:14:51 +02001749 private void playTrustedSound() {
Adrian Roos49e057d2014-08-13 17:14:51 +02001750 playSound(mTrustedSoundId);
1751 }
1752
Lucas Dupin47a65c72018-02-15 14:16:18 -08001753 private void updateActivityLockScreenState(boolean showing, boolean aodShowing,
1754 int secondaryDisplayShowing) {
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001755 mUiOffloadThread.submit(() -> {
1756 try {
Lucas Dupin47a65c72018-02-15 14:16:18 -08001757 ActivityManager.getService().setLockScreenShown(showing, aodShowing,
1758 secondaryDisplayShowing);
Jorim Jaggie549a8d2017-05-15 02:40:05 +02001759 } catch (RemoteException e) {
1760 }
1761 });
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001762 }
1763
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001764 /**
1765 * Handle message sent by {@link #showLocked}.
1766 * @see #SHOW
1767 */
Adam Cohenf7522022012-10-03 20:03:18 -07001768 private void handleShow(Bundle options) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001769 Trace.beginSection("KeyguardViewMediator#handleShow");
Michal Karpinskied5c8f02016-02-09 15:43:41 +00001770 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
1771 if (mLockPatternUtils.isSecure(currentUser)) {
1772 mLockPatternUtils.getDevicePolicyManager().reportKeyguardSecured(currentUser);
Michal Karpinski779aad92016-01-20 11:56:22 +00001773 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001774 synchronized (KeyguardViewMediator.this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001775 if (!mSystemReady) {
1776 if (DEBUG) Log.d(TAG, "ignoring handleShow because system is not ready.");
1777 return;
1778 } else {
1779 if (DEBUG) Log.d(TAG, "handleShow");
1780 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001781
Lucas Dupin47a65c72018-02-15 14:16:18 -08001782 setShowingLocked(true, mAodShowing);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001783 mStatusBarKeyguardViewManager.show(options);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001784 mHiding = false;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001785 mWakeAndUnlocking = false;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001786 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001787 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001788 adjustStatusBarLocked();
Jeff Brown3dc524b2012-09-30 19:49:11 -07001789 userActivity();
Mike Lockwood674d3e42009-10-06 09:28:54 -04001790 mShowKeyguardWakeLock.release();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001791 }
Jim Miller31921482013-11-06 20:43:55 -08001792 mKeyguardDisplayManager.show();
Nick Desaulniers1d396752016-07-25 15:05:33 -07001793 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001794 }
1795
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001796 private final Runnable mKeyguardGoingAwayRunnable = new Runnable() {
1797 @Override
1798 public void run() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001799 Trace.beginSection("KeyguardViewMediator.mKeyGuardGoingAwayRunnable");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001800 if (DEBUG) Log.d(TAG, "keyguardGoingAway");
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001801 try {
Jorim Jaggi33ae80e2015-02-04 16:37:11 +01001802 mStatusBarKeyguardViewManager.keyguardGoingAway();
1803
Adrian Roosd5c2db62016-03-08 16:11:31 -08001804 int flags = 0;
1805 if (mStatusBarKeyguardViewManager.shouldDisableWindowAnimationsForUnlock()
Lucas Dupind35502f2018-06-27 13:35:52 -07001806 || (mWakeAndUnlocking && !mPulsing)) {
1807 flags |= WindowManagerPolicyConstants
1808 .KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001809 }
Lucas Dupind35502f2018-06-27 13:35:52 -07001810 if (mStatusBarKeyguardViewManager.isGoingToNotificationShade()
1811 || (mWakeAndUnlocking && mPulsing)) {
Adrian Roose99bc052017-11-20 17:55:31 +01001812 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001813 }
1814 if (mStatusBarKeyguardViewManager.isUnlockWithWallpaper()) {
Adrian Roose99bc052017-11-20 17:55:31 +01001815 flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER;
Adrian Roosd5c2db62016-03-08 16:11:31 -08001816 }
1817
Kevin Chyn6db7d5f2017-05-03 22:24:31 -07001818 mUpdateMonitor.setKeyguardGoingAway(true /* goingAway */);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001819 // Don't actually hide the Keyguard at the moment, wait for window
1820 // manager until it tells us it's safe to do so with
1821 // startKeyguardExitAnimation.
Sudheer Shankadc589ac2016-11-10 15:30:17 -08001822 ActivityManager.getService().keyguardGoingAway(flags);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001823 } catch (RemoteException e) {
1824 Log.e(TAG, "Error while calling WindowManager", e);
1825 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001826 Trace.endSection();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001827 }
1828 };
1829
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001830 private final Runnable mHideAnimationFinishedRunnable = () -> {
1831 mHideAnimationRunning = false;
Jorim Jaggi241ae102016-11-02 21:57:33 -07001832 tryKeyguardDone();
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001833 };
1834
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001835 /**
1836 * Handle message sent by {@link #hideLocked()}
1837 * @see #HIDE
1838 */
1839 private void handleHide() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001840 Trace.beginSection("KeyguardViewMediator#handleHide");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001841 synchronized (KeyguardViewMediator.this) {
1842 if (DEBUG) Log.d(TAG, "handleHide");
Jorim Jaggib9d60792014-06-03 22:34:22 +02001843
Amith Yamasanieb437d42016-04-29 09:31:25 -07001844 if (mustNotUnlockCurrentUser()) {
Xiaohui Chenf561d7f2015-07-09 16:35:00 -07001845 // In split system user mode, we never unlock system user. The end user has to
1846 // switch to another user.
1847 // TODO: We should stop it early by disabling the swipe up flow. Right now swipe up
1848 // still completes and makes the screen blank.
1849 if (DEBUG) Log.d(TAG, "Split system user, quit unlocking.");
1850 return;
1851 }
Jorim Jaggi76a16232014-08-08 17:00:47 +02001852 mHiding = true;
Jorim Jaggib9d60792014-06-03 22:34:22 +02001853
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001854 if (mShowing && !mOccluded) {
1855 mKeyguardGoingAwayRunnable.run();
1856 } else {
Jorim Jaggi76a16232014-08-08 17:00:47 +02001857 handleStartKeyguardExitAnimation(
1858 SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(),
1859 mHideAnimation.getDuration());
Jorim Jaggi0d674622014-05-21 01:34:15 +02001860 }
1861 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001862 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02001863 }
1864
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001865 private void handleStartKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001866 Trace.beginSection("KeyguardViewMediator#handleStartKeyguardExitAnimation");
Jorim Jaggib9d04912016-08-04 17:28:08 +02001867 if (DEBUG) Log.d(TAG, "handleStartKeyguardExitAnimation startTime=" + startTime
1868 + " fadeoutDuration=" + fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02001869 synchronized (KeyguardViewMediator.this) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001870
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001871 if (!mHiding) {
Adrian Roos6ec76b72018-04-25 14:01:11 +02001872 // Tell ActivityManager that we canceled the keyguardExitAnimation.
1873 setShowingLocked(mShowing, mAodShowing, mSecondaryDisplayShowing, true /* force */);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001874 return;
1875 }
1876 mHiding = false;
1877
Jorim Jaggib774e552015-08-24 14:52:45 -07001878 if (mWakeAndUnlocking && mDrawnCallback != null) {
1879
1880 // Hack level over 9000: To speed up wake-and-unlock sequence, force it to report
1881 // the next draw from here so we don't have to wait for window manager to signal
1882 // this to our ViewRootImpl.
1883 mStatusBarKeyguardViewManager.getViewRootImpl().setReportNextDraw();
1884 notifyDrawn(mDrawnCallback);
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001885 mDrawnCallback = null;
Jorim Jaggib774e552015-08-24 14:52:45 -07001886 }
1887
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001888 // only play "unlock" noises if not on a call (since the incall UI
1889 // disables the keyguard)
1890 if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) {
1891 playSounds(false);
1892 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001893
Jorim Jaggie93e6f92016-08-04 13:55:39 +02001894 mWakeAndUnlocking = false;
Lucas Dupin47a65c72018-02-15 14:16:18 -08001895 setShowingLocked(false, mAodShowing);
Jorim Jaggi5277dea2017-05-18 02:05:29 +02001896 mDismissCallbackRegistry.notifyDismissSucceeded();
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001897 mStatusBarKeyguardViewManager.hide(startTime, fadeoutDuration);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001898 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001899 mHideAnimationRun = false;
Mike Lockwood5f892c12009-11-19 23:39:13 -05001900 adjustStatusBarLocked();
Jim Miller705004b2014-09-04 16:51:20 -07001901 sendUserPresentBroadcast();
Kevin Chyn6db7d5f2017-05-03 22:24:31 -07001902 mUpdateMonitor.setKeyguardGoingAway(false /* goingAway */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001903 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001904 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001905 }
1906
Mike Lockwood5f892c12009-11-19 23:39:13 -05001907 private void adjustStatusBarLocked() {
Matthew Ng66f0b702017-12-08 12:58:42 -08001908 adjustStatusBarLocked(false /* forceHideHomeRecentsButtons */);
1909 }
1910
1911 private void adjustStatusBarLocked(boolean forceHideHomeRecentsButtons) {
Mike Lockwood5f892c12009-11-19 23:39:13 -05001912 if (mStatusBarManager == null) {
1913 mStatusBarManager = (StatusBarManager)
1914 mContext.getSystemService(Context.STATUS_BAR_SERVICE);
1915 }
1916 if (mStatusBarManager == null) {
1917 Log.w(TAG, "Could not get status bar manager");
1918 } else {
Daniel Sandlerdba93562011-10-06 16:39:58 -04001919 // Disable aspects of the system/status/navigation bars that must not be re-enabled by
1920 // windows that appear on top, ever
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001921 int flags = StatusBarManager.DISABLE_NONE;
Matthew Ng66f0b702017-12-08 12:58:42 -08001922 if (forceHideHomeRecentsButtons || isShowingAndNotOccluded()) {
1923 flags |= StatusBarManager.DISABLE_HOME | StatusBarManager.DISABLE_RECENT;
Jorim Jaggia005f1b2014-04-16 19:06:10 +02001924 }
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001925
1926 if (DEBUG) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001927 Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mOccluded=" + mOccluded
Matthew Ng66f0b702017-12-08 12:58:42 -08001928 + " isSecure=" + isSecure() + " force=" + forceHideHomeRecentsButtons
1929 + " --> flags=0x" + Integer.toHexString(flags));
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001930 }
1931
Jorim Jaggie3e0b062017-06-12 12:18:41 -07001932 mStatusBarManager.disable(flags);
Mike Lockwood5f892c12009-11-19 23:39:13 -05001933 }
1934 }
1935
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001936 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001937 * Handle message sent by {@link #resetStateLocked}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001938 * @see #RESET
1939 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001940 private void handleReset() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001941 synchronized (KeyguardViewMediator.this) {
1942 if (DEBUG) Log.d(TAG, "handleReset");
Jorim Jaggife762342016-10-13 14:33:27 +02001943 mStatusBarKeyguardViewManager.reset(true /* hideBouncerWhenShowing */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001944 }
1945 }
1946
1947 /**
1948 * Handle message sent by {@link #verifyUnlock}
Craig Mautner904732c2012-10-17 15:20:24 -07001949 * @see #VERIFY_UNLOCK
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001950 */
1951 private void handleVerifyUnlock() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001952 Trace.beginSection("KeyguardViewMediator#handleVerifyUnlock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001953 synchronized (KeyguardViewMediator.this) {
1954 if (DEBUG) Log.d(TAG, "handleVerifyUnlock");
Lucas Dupin47a65c72018-02-15 14:16:18 -08001955 setShowingLocked(true, mAodShowing);
Jorim Jaggi8d5a6e72016-11-02 21:57:33 -07001956 mStatusBarKeyguardViewManager.dismissAndCollapse();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001957 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001958 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001959 }
1960
Jorim Jaggi18f18ae2015-09-10 15:48:21 -07001961 private void handleNotifyStartedGoingToSleep() {
1962 synchronized (KeyguardViewMediator.this) {
1963 if (DEBUG) Log.d(TAG, "handleNotifyStartedGoingToSleep");
1964 mStatusBarKeyguardViewManager.onStartedGoingToSleep();
1965 }
1966 }
1967
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001968 /**
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001969 * Handle message sent by {@link #notifyFinishedGoingToSleep()}
1970 * @see #NOTIFY_FINISHED_GOING_TO_SLEEP
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001971 */
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001972 private void handleNotifyFinishedGoingToSleep() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001973 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001974 if (DEBUG) Log.d(TAG, "handleNotifyFinishedGoingToSleep");
1975 mStatusBarKeyguardViewManager.onFinishedGoingToSleep();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001976 }
1977 }
1978
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001979 private void handleNotifyStartedWakingUp() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001980 Trace.beginSection("KeyguardViewMediator#handleMotifyStartedWakingUp");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001981 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001982 if (DEBUG) Log.d(TAG, "handleNotifyWakingUp");
Jorim Jaggi0d210f62015-07-10 14:24:44 -07001983 mStatusBarKeyguardViewManager.onStartedWakingUp();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001984 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07001985 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001986 }
1987
1988 private void handleNotifyScreenTurningOn(IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07001989 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurningOn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001990 synchronized (KeyguardViewMediator.this) {
1991 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurningOn");
Jorim Jaggi93739112015-08-13 15:53:14 -07001992 mStatusBarKeyguardViewManager.onScreenTurningOn();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07001993 if (callback != null) {
1994 if (mWakeAndUnlocking) {
1995 mDrawnCallback = callback;
1996 } else {
1997 notifyDrawn(callback);
1998 }
1999 }
2000 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002001 Trace.endSection();
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002002 }
2003
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002004 private void handleNotifyScreenTurnedOn() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002005 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurnedOn");
Jorim Jaggic3fe2042016-10-07 18:52:48 +02002006 if (LatencyTracker.isEnabled(mContext)) {
2007 LatencyTracker.getInstance(mContext).onActionEnd(LatencyTracker.ACTION_TURN_ON_SCREEN);
2008 }
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002009 synchronized (this) {
2010 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOn");
2011 mStatusBarKeyguardViewManager.onScreenTurnedOn();
2012 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002013 Trace.endSection();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002014 }
2015
2016 private void handleNotifyScreenTurnedOff() {
2017 synchronized (this) {
2018 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOff");
2019 mStatusBarKeyguardViewManager.onScreenTurnedOff();
Jorim Jaggie93e6f92016-08-04 13:55:39 +02002020 mDrawnCallback = null;
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002021 }
2022 }
2023
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002024 private void notifyDrawn(final IKeyguardDrawnCallback callback) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002025 Trace.beginSection("KeyguardViewMediator#notifyDrawn");
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07002026 try {
2027 callback.onDrawn();
2028 } catch (RemoteException e) {
2029 Slog.w(TAG, "Exception calling onDrawn():", e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002030 }
Nick Desaulniers1d396752016-07-25 15:05:33 -07002031 Trace.endSection();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002032 }
Jeff Sharkey054340d2011-09-01 22:28:03 -07002033
Jorim Jaggif8d77da2014-11-11 16:59:12 +01002034 private void resetKeyguardDonePendingLocked() {
2035 mKeyguardDonePending = false;
2036 mHandler.removeMessages(KEYGUARD_DONE_PENDING_TIMEOUT);
2037 }
2038
Jim Miller2967f482016-01-07 15:05:32 -08002039 @Override
Jim Millere5f910a2013-10-16 18:15:46 -07002040 public void onBootCompleted() {
2041 mUpdateMonitor.dispatchBootCompleted();
Jason Monkcf5a9532014-09-17 16:22:19 -04002042 synchronized (this) {
2043 mBootCompleted = true;
2044 if (mBootSendUserPresent) {
2045 sendUserPresentBroadcast();
2046 }
2047 }
Jim Millere5f910a2013-10-16 18:15:46 -07002048 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002049
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002050 public void onWakeAndUnlocking() {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002051 Trace.beginSection("KeyguardViewMediator#onWakeAndUnlocking");
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002052 mWakeAndUnlocking = true;
Jorim Jaggi241ae102016-11-02 21:57:33 -07002053 keyguardDone();
Nick Desaulniers1d396752016-07-25 15:05:33 -07002054 Trace.endSection();
Jorim Jaggi83eb6bb2015-08-17 17:38:58 -07002055 }
2056
Jason Monk2a6ea9c2017-01-26 11:14:51 -05002057 public StatusBarKeyguardViewManager registerStatusBar(StatusBar statusBar,
Lucas Dupinbc9aac12018-03-04 20:18:15 -08002058 ViewGroup container, NotificationPanelView panelView,
2059 FingerprintUnlockController fingerprintUnlockController) {
2060 mStatusBarKeyguardViewManager.registerStatusBar(statusBar, container, panelView,
Lucas Dupin9e3fa102017-11-08 17:16:55 -08002061 fingerprintUnlockController, mDismissCallbackRegistry);
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002062 return mStatusBarKeyguardViewManager;
2063 }
2064
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002065 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Nick Desaulniers1d396752016-07-25 15:05:33 -07002066 Trace.beginSection("KeyguardViewMediator#startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002067 Message msg = mHandler.obtainMessage(START_KEYGUARD_EXIT_ANIM,
2068 new StartKeyguardExitAnimParams(startTime, fadeoutDuration));
Jorim Jaggi0d674622014-05-21 01:34:15 +02002069 mHandler.sendMessage(msg);
Nick Desaulniers1d396752016-07-25 15:05:33 -07002070 Trace.endSection();
Jorim Jaggi0d674622014-05-21 01:34:15 +02002071 }
2072
Andrew Zengb4045d32017-03-16 17:25:07 -07002073 public void onShortPowerPressedGoHome() {
2074 // do nothing
2075 }
2076
Jorim Jaggi03c701e2014-04-02 12:39:51 +02002077 public ViewMediatorCallback getViewMediatorCallback() {
2078 return mViewMediatorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002079 }
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002080
Xiyuan Xia1b30f792016-01-06 08:50:30 -08002081 public LockPatternUtils getLockPatternUtils() {
2082 return mLockPatternUtils;
2083 }
2084
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002085 @Override
2086 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
2087 pw.print(" mSystemReady: "); pw.println(mSystemReady);
2088 pw.print(" mBootCompleted: "); pw.println(mBootCompleted);
2089 pw.print(" mBootSendUserPresent: "); pw.println(mBootSendUserPresent);
2090 pw.print(" mExternallyEnabled: "); pw.println(mExternallyEnabled);
Adrian Roos1f8025a2016-12-27 10:12:13 -08002091 pw.print(" mShuttingDown: "); pw.println(mShuttingDown);
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07002092 pw.print(" mNeedToReshowWhenReenabled: "); pw.println(mNeedToReshowWhenReenabled);
2093 pw.print(" mShowing: "); pw.println(mShowing);
2094 pw.print(" mInputRestricted: "); pw.println(mInputRestricted);
2095 pw.print(" mOccluded: "); pw.println(mOccluded);
2096 pw.print(" mDelayedShowingSequence: "); pw.println(mDelayedShowingSequence);
2097 pw.print(" mExitSecureCallback: "); pw.println(mExitSecureCallback);
2098 pw.print(" mDeviceInteractive: "); pw.println(mDeviceInteractive);
2099 pw.print(" mGoingToSleep: "); pw.println(mGoingToSleep);
2100 pw.print(" mHiding: "); pw.println(mHiding);
2101 pw.print(" mWaitingUntilKeyguardVisible: "); pw.println(mWaitingUntilKeyguardVisible);
2102 pw.print(" mKeyguardDonePending: "); pw.println(mKeyguardDonePending);
2103 pw.print(" mHideAnimationRun: "); pw.println(mHideAnimationRun);
2104 pw.print(" mPendingReset: "); pw.println(mPendingReset);
2105 pw.print(" mPendingLock: "); pw.println(mPendingLock);
2106 pw.print(" mWakeAndUnlocking: "); pw.println(mWakeAndUnlocking);
2107 pw.print(" mDrawnCallback: "); pw.println(mDrawnCallback);
2108 }
2109
Lucas Dupinc29b1462018-07-02 13:15:23 -07002110 /**
2111 * @param aodShowing true when AOD - or ambient mode - is showing.
2112 */
Lucas Dupin47a65c72018-02-15 14:16:18 -08002113 public void setAodShowing(boolean aodShowing) {
2114 setShowingLocked(mShowing, aodShowing);
2115 }
2116
Lucas Dupind35502f2018-06-27 13:35:52 -07002117 /**
2118 * @param pulsing true when device temporarily wakes up to display an incoming notification.
2119 */
2120 public void setPulsing(boolean pulsing) {
2121 mPulsing = pulsing;
2122 }
2123
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002124 private static class StartKeyguardExitAnimParams {
2125
2126 long startTime;
2127 long fadeoutDuration;
2128
2129 private StartKeyguardExitAnimParams(long startTime, long fadeoutDuration) {
2130 this.startTime = startTime;
2131 this.fadeoutDuration = fadeoutDuration;
2132 }
2133 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002134
Lucas Dupin47a65c72018-02-15 14:16:18 -08002135 private void setShowingLocked(boolean showing, boolean aodShowing) {
2136 setShowingLocked(showing, aodShowing, mSecondaryDisplayShowing,
2137 false /* forceCallbacks */);
Jorim Jaggie8f321e2016-11-07 16:48:31 -08002138 }
2139
Lucas Dupin47a65c72018-02-15 14:16:18 -08002140 private void setShowingLocked(boolean showing, boolean aodShowing, int secondaryDisplayShowing,
2141 boolean forceCallbacks) {
2142 final boolean notifyDefaultDisplayCallbacks = showing != mShowing
2143 || aodShowing != mAodShowing || forceCallbacks;
David Stevens53a39ea2017-08-23 18:41:49 -07002144 if (notifyDefaultDisplayCallbacks || secondaryDisplayShowing != mSecondaryDisplayShowing) {
Jim Millerab954542014-10-10 18:21:49 -07002145 mShowing = showing;
Lucas Dupin47a65c72018-02-15 14:16:18 -08002146 mAodShowing = aodShowing;
David Stevens53a39ea2017-08-23 18:41:49 -07002147 mSecondaryDisplayShowing = secondaryDisplayShowing;
2148 if (notifyDefaultDisplayCallbacks) {
2149 notifyDefaultDisplayCallbacks(showing);
2150 }
Lucas Dupin47a65c72018-02-15 14:16:18 -08002151 updateActivityLockScreenState(showing, aodShowing, secondaryDisplayShowing);
David Stevens53a39ea2017-08-23 18:41:49 -07002152 }
2153 }
2154
2155 private void notifyDefaultDisplayCallbacks(boolean showing) {
2156 int size = mKeyguardStateCallbacks.size();
2157 for (int i = size - 1; i >= 0; i--) {
2158 IKeyguardStateCallback callback = mKeyguardStateCallbacks.get(i);
2159 try {
2160 callback.onShowingStateChanged(showing);
2161 } catch (RemoteException e) {
2162 Slog.w(TAG, "Failed to call onShowingStateChanged", e);
2163 if (e instanceof DeadObjectException) {
2164 mKeyguardStateCallbacks.remove(callback);
Jim Millerab954542014-10-10 18:21:49 -07002165 }
Jim Millerab954542014-10-10 18:21:49 -07002166 }
Adrian Roos481a6df2014-11-20 19:48:56 +01002167 }
David Stevens53a39ea2017-08-23 18:41:49 -07002168 updateInputRestrictedLocked();
2169 mUiOffloadThread.submit(() -> {
2170 mTrustManager.reportKeyguardShowingChanged();
2171 });
Adrian Roos481a6df2014-11-20 19:48:56 +01002172 }
Jim Millerab954542014-10-10 18:21:49 -07002173
Adrian Roosd88eb262016-08-04 14:50:48 -07002174 private void notifyTrustedChangedLocked(boolean trusted) {
2175 int size = mKeyguardStateCallbacks.size();
2176 for (int i = size - 1; i >= 0; i--) {
2177 try {
2178 mKeyguardStateCallbacks.get(i).onTrustedChanged(trusted);
2179 } catch (RemoteException e) {
2180 Slog.w(TAG, "Failed to call notifyTrustedChangedLocked", e);
2181 if (e instanceof DeadObjectException) {
2182 mKeyguardStateCallbacks.remove(i);
2183 }
2184 }
2185 }
2186 }
2187
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002188 private void notifyHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
2189 int size = mKeyguardStateCallbacks.size();
2190 for (int i = size - 1; i >= 0; i--) {
2191 try {
2192 mKeyguardStateCallbacks.get(i).onHasLockscreenWallpaperChanged(
2193 hasLockscreenWallpaper);
2194 } catch (RemoteException e) {
2195 Slog.w(TAG, "Failed to call onHasLockscreenWallpaperChanged", e);
2196 if (e instanceof DeadObjectException) {
2197 mKeyguardStateCallbacks.remove(i);
2198 }
2199 }
2200 }
2201 }
2202
Jim Millerab954542014-10-10 18:21:49 -07002203 public void addStateMonitorCallback(IKeyguardStateCallback callback) {
2204 synchronized (this) {
2205 mKeyguardStateCallbacks.add(callback);
2206 try {
2207 callback.onSimSecureStateChanged(mUpdateMonitor.isSimPinSecure());
2208 callback.onShowingStateChanged(mShowing);
Adrian Roos4a963ac2015-04-24 16:04:53 -07002209 callback.onInputRestrictedStateChanged(mInputRestricted);
Adrian Roosd88eb262016-08-04 14:50:48 -07002210 callback.onTrustedChanged(mUpdateMonitor.getUserHasTrust(
2211 KeyguardUpdateMonitor.getCurrentUser()));
Jorim Jaggid11d1a92016-08-16 16:02:32 -07002212 callback.onHasLockscreenWallpaperChanged(mUpdateMonitor.hasLockscreenWallpaper());
Jim Millerab954542014-10-10 18:21:49 -07002213 } catch (RemoteException e) {
Adrian Roosd88eb262016-08-04 14:50:48 -07002214 Slog.w(TAG, "Failed to call to IKeyguardStateCallback", e);
Jim Millerab954542014-10-10 18:21:49 -07002215 }
2216 }
2217 }
Lucas Dupinc80c67e2017-12-04 14:29:10 -08002218
2219 private static class DismissMessage {
2220 private final CharSequence mMessage;
2221 private final IKeyguardDismissCallback mCallback;
2222
2223 DismissMessage(IKeyguardDismissCallback callback, CharSequence message) {
2224 mCallback = callback;
2225 mMessage = message;
2226 }
2227
2228 public IKeyguardDismissCallback getCallback() {
2229 return mCallback;
2230 }
2231
2232 public CharSequence getMessage() {
2233 return mMessage;
2234 }
2235 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002236}