blob: 49bdfda240324cde9aa9c609cfb3d168a235701b [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
Jim Millerdcb3d842012-08-23 19:18:12 -070019import android.app.Activity;
Adrian Roosb60d47c2014-09-08 19:23:00 +020020import android.app.ActivityManager;
Dianne Hackborn4994c662009-09-23 22:21:23 -070021import android.app.ActivityManagerNative;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080022import android.app.AlarmManager;
23import android.app.PendingIntent;
John Spurlock43d84512012-11-09 10:27:33 -050024import android.app.SearchManager;
Mike Lockwood5f892c12009-11-19 23:39:13 -050025import android.app.StatusBarManager;
Adrian Roos481a6df2014-11-20 19:48:56 +010026import android.app.trust.TrustManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080027import android.content.BroadcastReceiver;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -050028import android.content.ContentResolver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080029import android.content.Context;
30import android.content.Intent;
31import android.content.IntentFilter;
Adrian Roosbe47b072014-09-03 00:08:56 +020032import android.content.pm.UserInfo;
Daniel Sandleraec967a2010-02-20 01:05:22 -050033import android.media.AudioManager;
Marco Nelissend5545bd2011-09-29 12:49:17 -070034import android.media.SoundPool;
Adam Cohenf7522022012-10-03 20:03:18 -070035import android.os.Bundle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080036import android.os.Handler;
Jeff Brown109025d2012-08-14 20:41:30 -070037import android.os.Looper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080038import android.os.Message;
39import android.os.PowerManager;
Dianne Hackborn4994c662009-09-23 22:21:23 -070040import android.os.RemoteException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.os.SystemClock;
Jim Miller1b152022009-10-28 16:08:15 -070042import android.os.SystemProperties;
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -070043import android.os.UserHandle;
Amith Yamasanib70ff9a2012-09-07 18:28:11 -070044import android.os.UserManager;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -050045import android.provider.Settings;
Jim Miller52a61332014-11-12 19:29:51 -080046import android.telephony.SubscriptionManager;
Karl Rosaenab100082009-03-24 22:35:17 -070047import android.telephony.TelephonyManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080048import android.util.EventLog;
Karl Rosaenab100082009-03-24 22:35:17 -070049import android.util.Log;
Jim Miller25190572013-02-28 17:36:24 -080050import android.util.Slog;
Jorim Jaggi0d674622014-05-21 01:34:15 +020051import android.view.IWindowManager;
Jorim Jaggib690f0d2014-07-03 23:25:44 +020052import android.view.ViewGroup;
Jorim Jaggi0d674622014-05-21 01:34:15 +020053import android.view.WindowManagerGlobal;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080054import android.view.WindowManagerPolicy;
Adrian Roos0002a452014-07-03 13:46:07 +020055import android.view.animation.Animation;
56import android.view.animation.AnimationUtils;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010057import com.android.internal.policy.IKeyguardExitCallback;
58import com.android.internal.policy.IKeyguardShowCallback;
Jim Millerab954542014-10-10 18:21:49 -070059import com.android.internal.policy.IKeyguardStateCallback;
Adam Cohenf7522022012-10-03 20:03:18 -070060import com.android.internal.telephony.IccCardConstants;
61import com.android.internal.widget.LockPatternUtils;
Jim Miller52a61332014-11-12 19:29:51 -080062import com.android.keyguard.KeyguardConstants;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010063import com.android.keyguard.KeyguardDisplayManager;
64import com.android.keyguard.KeyguardUpdateMonitor;
65import com.android.keyguard.KeyguardUpdateMonitorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010066import com.android.keyguard.ViewMediatorCallback;
Jorim Jaggicff0acb2014-03-31 16:35:15 +020067import com.android.systemui.SystemUI;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010068import com.android.systemui.statusbar.phone.PhoneStatusBar;
Jorim Jaggiecc798e2014-05-26 18:14:37 +020069import com.android.systemui.statusbar.phone.ScrimController;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010070import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
71import com.android.systemui.statusbar.phone.StatusBarWindowManager;
Adrian Roos58b58fe2014-01-31 16:00:39 -080072
Jim Millerab954542014-10-10 18:21:49 -070073import java.util.ArrayList;
Benjamin Franz4b9f8ed2014-12-01 16:51:48 +000074import java.util.List;
Jim Millerab954542014-10-10 18:21:49 -070075
Jorim Jaggi5cf17872014-03-26 18:31:48 +010076import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
Jorim Jaggi5cf17872014-03-26 18:31:48 +010077
Wink Saville37c124c2009-04-02 01:37:02 -070078
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080079/**
80 * Mediates requests related to the keyguard. This includes queries about the
81 * state of the keyguard, power management events that effect whether the keyguard
82 * should be shown or reset, callbacks to the phone window manager to notify
83 * it of when the keyguard is showing, and events from the keyguard view itself
84 * stating that the keyguard was succesfully unlocked.
85 *
86 * Note that the keyguard view is shown when the screen is off (as appropriate)
87 * so that once the screen comes on, it will be ready immediately.
88 *
89 * Example queries about the keyguard:
90 * - is {movement, key} one that should wake the keygaurd?
91 * - is the keyguard showing?
92 * - are input events restricted due to the state of the keyguard?
93 *
94 * Callbacks to the phone window manager:
95 * - the keyguard is showing
96 *
97 * Example external events that translate to keyguard view changes:
98 * - screen turned off -> reset the keyguard, and show it so it will be ready
99 * next time the screen turns on
100 * - keyboard is slid open -> if the keyguard is not secure, hide it
101 *
102 * Events from the keyguard view:
103 * - user succesfully unlocked keyguard -> hide keyguard view, and no longer
104 * restrict input events.
105 *
106 * Note: in addition to normal power managment events that effect the state of
107 * whether the keyguard should be showing, external apps and services may request
108 * that the keyguard be disabled via {@link #setKeyguardEnabled(boolean)}. When
109 * false, this will override all other conditions for turning on the keyguard.
110 *
111 * Threading and synchronization:
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100112 * This class is created by the initialization routine of the {@link android.view.WindowManagerPolicy},
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800113 * and runs on its thread. The keyguard UI is created from that thread in the
114 * constructor of this class. The apis may be called from other threads, including the
Jeff Brown4532e612012-04-05 14:27:12 -0700115 * {@link com.android.server.input.InputManagerService}'s and {@link android.view.WindowManager}'s.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800116 * Therefore, methods on this class are synchronized, and any action that is pointed
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100117 * 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 -0800118 * thread of the keyguard.
119 */
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200120public class KeyguardViewMediator extends SystemUI {
Jim Millerbc4603b2010-08-30 21:21:34 -0700121 private static final int KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT = 30000;
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100122 private static final long KEYGUARD_DONE_PENDING_TIMEOUT_MS = 3000;
123
Jim Miller52a61332014-11-12 19:29:51 -0800124 private static final boolean DEBUG = KeyguardConstants.DEBUG;
125 private static final boolean DEBUG_SIM_STATES = KeyguardConstants.DEBUG_SIM_STATES;
Joe Onorato431bb222010-10-18 19:13:23 -0400126 private final static boolean DBG_WAKE = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800127
128 private final static String TAG = "KeyguardViewMediator";
129
Jim Miller9c20d0e2010-01-20 15:00:23 -0800130 private static final String DELAYED_KEYGUARD_ACTION =
Wink Saville37c124c2009-04-02 01:37:02 -0700131 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800132
133 // used for handler messages
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800134 private static final int SHOW = 2;
135 private static final int HIDE = 3;
136 private static final int RESET = 4;
137 private static final int VERIFY_UNLOCK = 5;
138 private static final int NOTIFY_SCREEN_OFF = 6;
139 private static final int NOTIFY_SCREEN_ON = 7;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800140 private static final int KEYGUARD_DONE = 9;
141 private static final int KEYGUARD_DONE_DRAWING = 10;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700142 private static final int KEYGUARD_DONE_AUTHENTICATING = 11;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100143 private static final int SET_OCCLUDED = 12;
Mike Lockwood28569302010-01-28 11:54:40 -0500144 private static final int KEYGUARD_TIMEOUT = 13;
Jim Miller60013792013-10-03 18:31:34 -0700145 private static final int DISMISS = 17;
Jorim Jaggi0d674622014-05-21 01:34:15 +0200146 private static final int START_KEYGUARD_EXIT_ANIM = 18;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200147 private static final int ON_ACTIVITY_DRAWN = 19;
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100148 private static final int KEYGUARD_DONE_PENDING_TIMEOUT = 20;
Jim Miller9c20d0e2010-01-20 15:00:23 -0800149
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800150 /**
151 * The default amount of time we stay awake (used for all key input)
152 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100153 public static final int AWAKE_INTERVAL_DEFAULT_MS = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800154
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800155 /**
156 * How long to wait after the screen turns off due to timeout before
157 * turning on the keyguard (i.e, the user has this much time to turn
158 * the screen back on without having to face the keyguard).
159 */
Jim Millerbc4603b2010-08-30 21:21:34 -0700160 private static final int KEYGUARD_LOCK_AFTER_DELAY_DEFAULT = 5000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800161
162 /**
Craig Mautnerf1b67412012-09-19 13:18:29 -0700163 * How long we'll wait for the {@link ViewMediatorCallback#keyguardDoneDrawing()}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800164 * callback before unblocking a call to {@link #setKeyguardEnabled(boolean)}
165 * that is reenabling the keyguard.
166 */
167 private static final int KEYGUARD_DONE_DRAWING_TIMEOUT_MS = 2000;
Jim Miller9c20d0e2010-01-20 15:00:23 -0800168
Daniel Sandler74d188c2011-08-10 00:00:31 -0400169 /**
Adrian Roos58b58fe2014-01-31 16:00:39 -0800170 * Secure setting whether analytics are collected on the keyguard.
171 */
172 private static final String KEYGUARD_ANALYTICS_SETTING = "keyguard_analytics";
173
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700174 /** The stream type that the lock sounds are tied to. */
John Spurlockee5ad722015-03-03 16:17:21 -0500175 private int mUiSoundsStreamType;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700176
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800177 private AlarmManager mAlarmManager;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700178 private AudioManager mAudioManager;
Mike Lockwood5f892c12009-11-19 23:39:13 -0500179 private StatusBarManager mStatusBarManager;
Chris Wrenf41c61b2012-11-29 15:19:54 -0500180 private boolean mSwitchingUser;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800181
182 private boolean mSystemReady;
Jason Monkcf5a9532014-09-17 16:22:19 -0400183 private boolean mBootCompleted;
184 private boolean mBootSendUserPresent;
Daniel Sandler0060a9b2010-03-15 23:09:57 -0400185
186 // Whether the next call to playSounds() should be skipped. Defaults to
187 // true because the first lock (on boot) should be silent.
188 private boolean mSuppressNextLockSound = true;
189
Jim Miller9c20d0e2010-01-20 15:00:23 -0800190
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800191 /** High level access to the power manager for WakeLocks */
192 private PowerManager mPM;
193
Jorim Jaggi0d674622014-05-21 01:34:15 +0200194 /** High level access to the window manager for dismissing keyguard animation */
195 private IWindowManager mWM;
196
Adrian Roos481a6df2014-11-20 19:48:56 +0100197
198 /** TrustManager for letting it know when we change visibility */
199 private TrustManager mTrustManager;
Amith Yamasanib70ff9a2012-09-07 18:28:11 -0700200
John Spurlock43d84512012-11-09 10:27:33 -0500201 /** SearchManager for determining whether or not search assistant is available */
202 private SearchManager mSearchManager;
203
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800204 /**
Mike Lockwood674d3e42009-10-06 09:28:54 -0400205 * Used to keep the device awake while to ensure the keyguard finishes opening before
206 * we sleep.
207 */
208 private PowerManager.WakeLock mShowKeyguardWakeLock;
209
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100210 private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800211
212 // these are protected by synchronized (this)
213
214 /**
Mike Lockwood5d258b62009-12-02 13:50:45 -0500215 * External apps (like the phone app) can tell us to disable the keygaurd.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800216 */
217 private boolean mExternallyEnabled = true;
218
219 /**
220 * Remember if an external call to {@link #setKeyguardEnabled} with value
221 * false caused us to hide the keyguard, so that we need to reshow it once
222 * the keygaurd is reenabled with another call with value true.
223 */
224 private boolean mNeedToReshowWhenReenabled = false;
225
226 // cached value of whether we are showing (need to know this to quickly
227 // answer whether the input should be restricted)
Jim Millere5f17ab2013-11-13 15:40:48 -0800228 private boolean mShowing;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800229
Jim Millerab954542014-10-10 18:21:49 -0700230 /** Cached value of #isInputRestricted */
231 private boolean mInputRestricted;
232
Mike Lockwood09a40402009-11-08 00:33:23 -0500233 // true if the keyguard is hidden by another window
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100234 private boolean mOccluded = false;
Mike Lockwood09a40402009-11-08 00:33:23 -0500235
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800236 /**
237 * Helps remember whether the screen has turned on since the last time
238 * it turned off due to timeout. see {@link #onScreenTurnedOff(int)}
239 */
240 private int mDelayedShowingSequence;
241
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800242 /**
243 * If the user has disabled the keyguard, then requests to exit, this is
244 * how we'll ultimately let them know whether it was successful. We use this
245 * var being non-null as an indicator that there is an in progress request.
246 */
Jim Miller25190572013-02-28 17:36:24 -0800247 private IKeyguardExitCallback mExitSecureCallback;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800248
249 // the properties of the keyguard
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800250
251 private KeyguardUpdateMonitor mUpdateMonitor;
252
Daniel Hansson4b716862012-03-29 11:02:05 +0200253 private boolean mScreenOn;
Karl Rosaenab100082009-03-24 22:35:17 -0700254
Daniel Sandlerf2d8e742010-02-22 13:09:48 -0500255 // last known state of the cellular connection
256 private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE;
257
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800258 /**
Jorim Jaggi53c68a42014-06-17 15:04:47 -0700259 * Whether a hide is pending an we are just waiting for #startKeyguardExitAnimation to be
260 * called.
261 * */
262 private boolean mHiding;
263
264 /**
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700265 * we send this intent when the keyguard is dismissed.
266 */
Jim Miller17f509a2013-02-28 18:36:12 -0800267 private static final Intent USER_PRESENT_INTENT = new Intent(Intent.ACTION_USER_PRESENT)
268 .addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
269 | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700270
271 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800272 * {@link #setKeyguardEnabled} waits on this condition when it reenables
273 * the keyguard.
274 */
275 private boolean mWaitingUntilKeyguardVisible = false;
Jim Millerbc4603b2010-08-30 21:21:34 -0700276 private LockPatternUtils mLockPatternUtils;
John Spurlock34c4fe52012-11-07 10:12:29 -0500277 private boolean mKeyguardDonePending = false;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200278 private boolean mHideAnimationRun = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800279
Marco Nelissend5545bd2011-09-29 12:49:17 -0700280 private SoundPool mLockSounds;
281 private int mLockSoundId;
282 private int mUnlockSoundId;
Adrian Roos49e057d2014-08-13 17:14:51 +0200283 private int mTrustedSoundId;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700284 private int mLockSoundStreamId;
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700285
286 /**
Adrian Roos0002a452014-07-03 13:46:07 +0200287 * The animation used for hiding keyguard. This is used to fetch the animation timings if
288 * WindowManager is not providing us with them.
289 */
290 private Animation mHideAnimation;
291
292 /**
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700293 * The volume applied to the lock/unlock sounds.
294 */
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200295 private float mLockSoundVolume;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700296
Jim Millerdcb3d842012-08-23 19:18:12 -0700297 /**
Jim Miller31921482013-11-06 20:43:55 -0800298 * For managing external displays
299 */
300 private KeyguardDisplayManager mKeyguardDisplayManager;
301
Jim Millerab954542014-10-10 18:21:49 -0700302 private final ArrayList<IKeyguardStateCallback> mKeyguardStateCallbacks = new ArrayList<>();
303
Jim Millerbbf1a742012-07-17 18:30:30 -0700304 KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {
305
306 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500307 public void onUserSwitching(int userId) {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700308 // Note that the mLockPatternUtils user has already been updated from setCurrentUser.
Adam Cohenf7522022012-10-03 20:03:18 -0700309 // We need to force a reset of the views, since lockNow (called by
310 // ActivityManagerService) will not reconstruct the keyguard if it is already showing.
Jim Millerbbf1a742012-07-17 18:30:30 -0700311 synchronized (KeyguardViewMediator.this) {
Chris Wrenf41c61b2012-11-29 15:19:54 -0500312 mSwitchingUser = true;
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100313 resetKeyguardDonePendingLocked();
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100314 resetStateLocked();
John Spurlock4e6922d2012-10-04 14:51:51 -0400315 adjustStatusBarLocked();
Dianne Hackborn5dc5a002012-09-15 19:33:48 -0700316 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700317 }
318
319 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500320 public void onUserSwitchComplete(int userId) {
321 mSwitchingUser = false;
Adrian Roosbe47b072014-09-03 00:08:56 +0200322 if (userId != UserHandle.USER_OWNER) {
323 UserInfo info = UserManager.get(mContext).getUserInfo(userId);
324 if (info != null && info.isGuest()) {
325 // If we just switched to a guest, try to dismiss keyguard.
326 dismiss();
327 }
328 }
Chris Wrenf41c61b2012-11-29 15:19:54 -0500329 }
330
331 @Override
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -0700332 public void onUserInfoChanged(int userId) {
Jim Millerbbf1a742012-07-17 18:30:30 -0700333 }
334
335 @Override
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100336 public void onPhoneStateChanged(int phoneState) {
Jim Millerbbf1a742012-07-17 18:30:30 -0700337 synchronized (KeyguardViewMediator.this) {
338 if (TelephonyManager.CALL_STATE_IDLE == phoneState // call ending
339 && !mScreenOn // screen off
340 && mExternallyEnabled) { // not disabled by any app
341
342 // note: this is a way to gracefully reenable the keyguard when the call
343 // ends and the screen is off without always reenabling the keyguard
344 // each time the screen turns off while in call (and having an occasional ugly
345 // flicker while turning back on the screen and disabling the keyguard again).
346 if (DEBUG) Log.d(TAG, "screen is off and call ended, let's make sure the "
347 + "keyguard is showing");
Jim Miller5ecd8112013-01-09 18:50:26 -0800348 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700349 }
350 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100351 }
Jim Millerb0304762012-03-13 20:01:25 -0700352
353 @Override
354 public void onClockVisibilityChanged() {
355 adjustStatusBarLocked();
356 }
357
358 @Override
359 public void onDeviceProvisioned() {
Jim Miller3fd47af2012-09-21 19:55:27 -0700360 sendUserPresentBroadcast();
Jim Millerab954542014-10-10 18:21:49 -0700361 updateInputRestricted();
Jim Millerb0304762012-03-13 20:01:25 -0700362 }
363
Jim Millerbbf1a742012-07-17 18:30:30 -0700364 @Override
Jim Miller52a61332014-11-12 19:29:51 -0800365 public void onSimStateChanged(int subId, int slotId, IccCardConstants.State simState) {
366
367 if (DEBUG_SIM_STATES) {
368 Log.d(TAG, "onSimStateChanged(subId=" + subId + ", slotId=" + slotId
369 + ",state=" + simState + ")");
370 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700371
Jim Millerab954542014-10-10 18:21:49 -0700372 try {
373 int size = mKeyguardStateCallbacks.size();
374 boolean simPinSecure = mUpdateMonitor.isSimPinSecure();
375 for (int i = 0; i < size; i++) {
376 mKeyguardStateCallbacks.get(i).onSimSecureStateChanged(simPinSecure);
377 }
378 } catch (RemoteException e) {
379 Slog.w(TAG, "Failed to call onSimSecureStateChanged", e);
380 }
381
Jim Millerbbf1a742012-07-17 18:30:30 -0700382 switch (simState) {
383 case NOT_READY:
384 case ABSENT:
385 // only force lock screen in case of missing sim if user hasn't
386 // gone through setup wizard
387 synchronized (this) {
Jim Millerb256e4e22014-10-31 17:27:13 -0700388 if (shouldWaitForProvisioning()) {
Jim Millerab954542014-10-10 18:21:49 -0700389 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800390 if (DEBUG_SIM_STATES) Log.d(TAG, "ICC_ABSENT isn't showing,"
Jim Millerbbf1a742012-07-17 18:30:30 -0700391 + " we need to show the keyguard since the "
392 + "device isn't provisioned yet.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800393 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700394 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100395 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700396 }
397 }
398 }
399 break;
400 case PIN_REQUIRED:
401 case PUK_REQUIRED:
402 synchronized (this) {
Jim Millerab954542014-10-10 18:21:49 -0700403 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800404 if (DEBUG_SIM_STATES) Log.d(TAG,
405 "INTENT_VALUE_ICC_LOCKED and keygaurd isn't "
Jim Millerbbf1a742012-07-17 18:30:30 -0700406 + "showing; need to show keyguard so user can enter sim pin");
Jim Miller5ecd8112013-01-09 18:50:26 -0800407 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700408 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100409 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700410 }
411 }
412 break;
413 case PERM_DISABLED:
414 synchronized (this) {
Jim Millerab954542014-10-10 18:21:49 -0700415 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800416 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED and "
Jim Millerbbf1a742012-07-17 18:30:30 -0700417 + "keygaurd isn't showing.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800418 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700419 } else {
Jim Miller52a61332014-11-12 19:29:51 -0800420 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED, resetStateLocked to"
Jim Millerbbf1a742012-07-17 18:30:30 -0700421 + "show permanently disabled message in lockscreen.");
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100422 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700423 }
424 }
425 break;
426 case READY:
427 synchronized (this) {
Jim Millerab954542014-10-10 18:21:49 -0700428 if (mShowing) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100429 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700430 }
431 }
432 break;
Jim Miller52a61332014-11-12 19:29:51 -0800433 default:
434 if (DEBUG_SIM_STATES) Log.v(TAG, "Ignoring state: " + simState);
435 break;
Jim Millerbbf1a742012-07-17 18:30:30 -0700436 }
437 }
438
Jim Millerf41fc962014-06-18 16:33:51 -0700439 public void onFingerprintRecognized(int userId) {
440 if (mStatusBarKeyguardViewManager.isBouncerShowing()) {
441 mViewMediatorCallback.keyguardDone(true);
Jim Miller25d7e512015-03-03 17:12:09 -0800442 } else {
443 mStatusBarKeyguardViewManager.animateCollapsePanels();
Jim Millerf41fc962014-06-18 16:33:51 -0700444 }
445 };
446
Jim Millerb0304762012-03-13 20:01:25 -0700447 };
448
Jim Millerdcb3d842012-08-23 19:18:12 -0700449 ViewMediatorCallback mViewMediatorCallback = new ViewMediatorCallback() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100450
Jeff Brownc7505bc2012-10-05 21:58:15 -0700451 public void userActivity() {
452 KeyguardViewMediator.this.userActivity();
453 }
454
Jim Millerdcb3d842012-08-23 19:18:12 -0700455 public void keyguardDone(boolean authenticated) {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100456 if (!mKeyguardDonePending) {
457 KeyguardViewMediator.this.keyguardDone(authenticated, true);
458 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700459 }
460
461 public void keyguardDoneDrawing() {
462 mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING);
463 }
464
465 @Override
466 public void setNeedsInput(boolean needsInput) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100467 mStatusBarKeyguardViewManager.setNeedsInput(needsInput);
Jim Millerdcb3d842012-08-23 19:18:12 -0700468 }
Jeff Brownc7505bc2012-10-05 21:58:15 -0700469
470 @Override
John Spurlock34c4fe52012-11-07 10:12:29 -0500471 public void keyguardDonePending() {
472 mKeyguardDonePending = true;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200473 mHideAnimationRun = true;
474 mStatusBarKeyguardViewManager.startPreHideAnimation(null /* finishRunnable */);
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100475 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_PENDING_TIMEOUT,
476 KEYGUARD_DONE_PENDING_TIMEOUT_MS);
John Spurlock34c4fe52012-11-07 10:12:29 -0500477 }
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800478
479 @Override
480 public void keyguardGone() {
481 mKeyguardDisplayManager.hide();
482 }
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200483
484 @Override
485 public void readyForKeyguardDone() {
486 if (mKeyguardDonePending) {
487 // Somebody has called keyguardDonePending before, which means that we are
488 // authenticated
489 KeyguardViewMediator.this.keyguardDone(true /* authenticated */, true /* wakeUp */);
490 }
491 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200492
493 @Override
Andrew Lee72b46d42015-01-30 13:23:21 -0800494 public void resetKeyguard() {
495 resetStateLocked();
496 }
497
498 @Override
Adrian Roos49e057d2014-08-13 17:14:51 +0200499 public void playTrustedSound() {
500 KeyguardViewMediator.this.playTrustedSound();
501 }
Jim Millerab954542014-10-10 18:21:49 -0700502
503 @Override
504 public boolean isInputRestricted() {
505 return KeyguardViewMediator.this.isInputRestricted();
506 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700507 };
508
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200509 public void userActivity() {
Jeff Brown3dc524b2012-09-30 19:49:11 -0700510 mPM.userActivity(SystemClock.uptimeMillis(), false);
Jim Millerdcb3d842012-08-23 19:18:12 -0700511 }
512
Jim Millerab954542014-10-10 18:21:49 -0700513 private void setupLocked() {
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200514 mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
Jorim Jaggi0d674622014-05-21 01:34:15 +0200515 mWM = WindowManagerGlobal.getWindowManagerService();
Adrian Roos481a6df2014-11-20 19:48:56 +0100516 mTrustManager = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE);
517
Mike Lockwood674d3e42009-10-06 09:28:54 -0400518 mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
519 mShowKeyguardWakeLock.setReferenceCounted(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800520
Jim Millerbbf1a742012-07-17 18:30:30 -0700521 mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(DELAYED_KEYGUARD_ACTION));
522
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200523 mKeyguardDisplayManager = new KeyguardDisplayManager(mContext);
Jim Miller31921482013-11-06 20:43:55 -0800524
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200525 mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800526
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200527 mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800528
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200529 mLockPatternUtils = new LockPatternUtils(mContext);
Adrian Roosb60d47c2014-09-08 19:23:00 +0200530 mLockPatternUtils.setCurrentUser(ActivityManager.getCurrentUser());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800531
Jim Millere5f17ab2013-11-13 15:40:48 -0800532 // Assume keyguard is showing (unless it's disabled) until we know for sure...
Jim Millerab954542014-10-10 18:21:49 -0700533 setShowingLocked(!shouldWaitForProvisioning() && !mLockPatternUtils.isLockScreenDisabled());
Adrian Roos481a6df2014-11-20 19:48:56 +0100534 mTrustManager.reportKeyguardShowingChanged();
Jim Millere5f17ab2013-11-13 15:40:48 -0800535
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200536 mStatusBarKeyguardViewManager = new StatusBarKeyguardViewManager(mContext,
537 mViewMediatorCallback, mLockPatternUtils);
Daniel Sandler687a3272010-03-13 15:44:47 -0500538 final ContentResolver cr = mContext.getContentResolver();
Marco Nelissend5545bd2011-09-29 12:49:17 -0700539
Daniel Hansson4b716862012-03-29 11:02:05 +0200540 mScreenOn = mPM.isScreenOn();
541
Marco Nelissend5545bd2011-09-29 12:49:17 -0700542 mLockSounds = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
Jim Millerb14288d2012-09-30 18:25:05 -0700543 String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700544 if (soundPath != null) {
545 mLockSoundId = mLockSounds.load(soundPath, 1);
546 }
547 if (soundPath == null || mLockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700548 Log.w(TAG, "failed to load lock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700549 }
Jim Millerb14288d2012-09-30 18:25:05 -0700550 soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700551 if (soundPath != null) {
552 mUnlockSoundId = mLockSounds.load(soundPath, 1);
553 }
554 if (soundPath == null || mUnlockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700555 Log.w(TAG, "failed to load unlock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700556 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200557 soundPath = Settings.Global.getString(cr, Settings.Global.TRUSTED_SOUND);
558 if (soundPath != null) {
559 mTrustedSoundId = mLockSounds.load(soundPath, 1);
560 }
561 if (soundPath == null || mTrustedSoundId == 0) {
562 Log.w(TAG, "failed to load trusted sound from " + soundPath);
563 }
564
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200565 int lockSoundDefaultAttenuation = mContext.getResources().getInteger(
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700566 com.android.internal.R.integer.config_lockSoundVolumeDb);
Jean-Michel Trivif2b0c112012-07-09 11:59:11 -0700567 mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20);
Adrian Roos0002a452014-07-03 13:46:07 +0200568
569 mHideAnimation = AnimationUtils.loadAnimation(mContext,
570 com.android.internal.R.anim.lock_screen_behind_enter);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800571 }
572
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200573 @Override
574 public void start() {
Jim Millerab954542014-10-10 18:21:49 -0700575 synchronized (this) {
576 setupLocked();
577 }
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200578 putComponent(KeyguardViewMediator.class, this);
579 }
580
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800581 /**
582 * Let us know that the system is ready after startup.
583 */
584 public void onSystemReady() {
John Spurlock43d84512012-11-09 10:27:33 -0500585 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800586 synchronized (this) {
587 if (DEBUG) Log.d(TAG, "onSystemReady");
588 mSystemReady = true;
Jim Millerbbf1a742012-07-17 18:30:30 -0700589 mUpdateMonitor.registerCallback(mUpdateCallback);
Jim Miller08697702012-10-22 16:49:52 -0700590
Jim Miller5ecd8112013-01-09 18:50:26 -0800591 doKeyguardLocked(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800592 }
Jim Miller3fd47af2012-09-21 19:55:27 -0700593 // Most services aren't available until the system reaches the ready state, so we
594 // send it here when the device first boots.
595 maybeSendUserPresentBroadcast();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800596 }
597
598 /**
599 * Called to let us know the screen was turned off.
Jeff Brownfb0448a2014-05-01 18:19:31 -0700600 * @param why either {@link android.view.WindowManagerPolicy#OFF_BECAUSE_OF_USER} or
601 * {@link android.view.WindowManagerPolicy#OFF_BECAUSE_OF_TIMEOUT}.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800602 */
603 public void onScreenTurnedOff(int why) {
604 synchronized (this) {
Karl Rosaenab100082009-03-24 22:35:17 -0700605 mScreenOn = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800606 if (DEBUG) Log.d(TAG, "onScreenTurnedOff(" + why + ")");
607
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100608 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200609 mHideAnimationRun = false;
John Spurlock14adfe42012-11-08 10:29:26 -0500610
Jim Millera4edd152012-01-06 18:24:04 -0800611 // Lock immediately based on setting if secure (user has a pin/pattern/password).
612 // This also "locks" the device when not secure to provide easy access to the
613 // camera while preventing unwanted input.
614 final boolean lockImmediately =
615 mLockPatternUtils.getPowerButtonInstantlyLocks() || !mLockPatternUtils.isSecure();
616
Selim Cinek7ff6eb62014-09-03 14:18:09 +0200617 notifyScreenOffLocked();
618
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800619 if (mExitSecureCallback != null) {
620 if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled");
Jim Miller5ecd8112013-01-09 18:50:26 -0800621 try {
622 mExitSecureCallback.onKeyguardExitResult(false);
623 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800624 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800625 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800626 mExitSecureCallback = null;
627 if (!mExternallyEnabled) {
Jim Miller9c20d0e2010-01-20 15:00:23 -0800628 hideLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800629 }
630 } else if (mShowing) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100631 resetStateLocked();
Jim Millera4edd152012-01-06 18:24:04 -0800632 } else if (why == WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT
633 || (why == WindowManagerPolicy.OFF_BECAUSE_OF_USER && !lockImmediately)) {
Jeff Brown6aaf2952012-10-05 16:01:08 -0700634 doKeyguardLaterLocked();
Mike Lockwood016e3972009-09-17 11:45:06 -0400635 } else {
Jim Miller5ecd8112013-01-09 18:50:26 -0800636 doKeyguardLocked(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800637 }
638 }
John Spurlock36a13422015-03-24 21:15:48 -0400639 KeyguardUpdateMonitor.getInstance(mContext).dispatchScreenTurnedOff(why);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800640 }
641
Jeff Brown6aaf2952012-10-05 16:01:08 -0700642 private void doKeyguardLaterLocked() {
643 // if the screen turned off because of timeout or the user hit the power button
644 // and we don't need to lock immediately, set an alarm
645 // to enable it a little bit later (i.e, give the user a chance
646 // to turn the screen back on within a certain window without
647 // having to unlock the screen)
648 final ContentResolver cr = mContext.getContentResolver();
649
650 // From DisplaySettings
651 long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT,
652 KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT);
653
654 // From SecuritySettings
655 final long lockAfterTimeout = Settings.Secure.getInt(cr,
656 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT,
657 KEYGUARD_LOCK_AFTER_DELAY_DEFAULT);
658
659 // From DevicePolicyAdmin
660 final long policyTimeout = mLockPatternUtils.getDevicePolicyManager()
661 .getMaximumTimeToLock(null, mLockPatternUtils.getCurrentUser());
662
663 long timeout;
664 if (policyTimeout > 0) {
665 // policy in effect. Make sure we don't go beyond policy limit.
666 displayTimeout = Math.max(displayTimeout, 0); // ignore negative values
667 timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout);
668 } else {
669 timeout = lockAfterTimeout;
670 }
671
672 if (timeout <= 0) {
673 // Lock now
674 mSuppressNextLockSound = true;
Jim Miller5ecd8112013-01-09 18:50:26 -0800675 doKeyguardLocked(null);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700676 } else {
677 // Lock in the future
678 long when = SystemClock.elapsedRealtime() + timeout;
679 Intent intent = new Intent(DELAYED_KEYGUARD_ACTION);
680 intent.putExtra("seq", mDelayedShowingSequence);
681 PendingIntent sender = PendingIntent.getBroadcast(mContext,
682 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
683 mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender);
684 if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = "
685 + mDelayedShowingSequence);
686 }
687 }
688
689 private void cancelDoKeyguardLaterLocked() {
690 mDelayedShowingSequence++;
691 }
692
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800693 /**
694 * Let's us know the screen was turned on.
695 */
Jim Miller25190572013-02-28 17:36:24 -0800696 public void onScreenTurnedOn(IKeyguardShowCallback callback) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800697 synchronized (this) {
Karl Rosaenab100082009-03-24 22:35:17 -0700698 mScreenOn = true;
Jeff Brown6aaf2952012-10-05 16:01:08 -0700699 cancelDoKeyguardLaterLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800700 if (DEBUG) Log.d(TAG, "onScreenTurnedOn, seq = " + mDelayedShowingSequence);
Jim Miller25190572013-02-28 17:36:24 -0800701 if (callback != null) {
702 notifyScreenOnLocked(callback);
Jim Millerd6523da2012-10-21 16:47:02 -0700703 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800704 }
Jim Miller20daffd2013-10-07 14:59:53 -0700705 KeyguardUpdateMonitor.getInstance(mContext).dispatchScreenTurnedOn();
Jim Miller3fd47af2012-09-21 19:55:27 -0700706 maybeSendUserPresentBroadcast();
707 }
708
709 private void maybeSendUserPresentBroadcast() {
Adam Lesinski61d94092014-09-15 15:27:19 -0700710 if (mSystemReady && mLockPatternUtils.isLockScreenDisabled()) {
Jim Miller3fd47af2012-09-21 19:55:27 -0700711 // Lock screen is disabled because the user has set the preference to "None".
712 // In this case, send out ACTION_USER_PRESENT here instead of in
713 // handleKeyguardDone()
714 sendUserPresentBroadcast();
715 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800716 }
717
718 /**
Jeff Brown6aaf2952012-10-05 16:01:08 -0700719 * A dream started. We should lock after the usual screen-off lock timeout but only
720 * if there is a secure lock pattern.
721 */
722 public void onDreamingStarted() {
723 synchronized (this) {
724 if (mScreenOn && mLockPatternUtils.isSecure()) {
725 doKeyguardLaterLocked();
726 }
727 }
728 }
729
730 /**
731 * A dream stopped.
732 */
733 public void onDreamingStopped() {
734 synchronized (this) {
735 if (mScreenOn) {
736 cancelDoKeyguardLaterLocked();
737 }
738 }
739 }
740
741 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100742 * Same semantics as {@link android.view.WindowManagerPolicy#enableKeyguard}; provide
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800743 * a way for external stuff to override normal keyguard behavior. For instance
744 * the phone app disables the keyguard when it receives incoming calls.
745 */
746 public void setKeyguardEnabled(boolean enabled) {
747 synchronized (this) {
748 if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")");
749
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800750 mExternallyEnabled = enabled;
751
752 if (!enabled && mShowing) {
753 if (mExitSecureCallback != null) {
754 if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring");
755 // we're in the process of handling a request to verify the user
756 // can get past the keyguard. ignore extraneous requests to disable / reenable
757 return;
758 }
759
760 // hiding keyguard that is showing, remember to reshow later
761 if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, "
762 + "disabling status bar expansion");
763 mNeedToReshowWhenReenabled = true;
Jim Millerab954542014-10-10 18:21:49 -0700764 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800765 hideLocked();
766 } else if (enabled && mNeedToReshowWhenReenabled) {
767 // reenabled after previously hidden, reshow
768 if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling "
769 + "status bar expansion");
770 mNeedToReshowWhenReenabled = false;
Jim Millerab954542014-10-10 18:21:49 -0700771 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800772
773 if (mExitSecureCallback != null) {
774 if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting");
Jim Miller5ecd8112013-01-09 18:50:26 -0800775 try {
776 mExitSecureCallback.onKeyguardExitResult(false);
777 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800778 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800779 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800780 mExitSecureCallback = null;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100781 resetStateLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800782 } else {
Adam Cohenf7522022012-10-03 20:03:18 -0700783 showLocked(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800784
785 // block until we know the keygaurd is done drawing (and post a message
786 // to unblock us after a timeout so we don't risk blocking too long
787 // and causing an ANR).
788 mWaitingUntilKeyguardVisible = true;
789 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS);
790 if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false");
791 while (mWaitingUntilKeyguardVisible) {
792 try {
793 wait();
794 } catch (InterruptedException e) {
795 Thread.currentThread().interrupt();
796 }
797 }
798 if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible");
799 }
800 }
801 }
802 }
803
804 /**
805 * @see android.app.KeyguardManager#exitKeyguardSecurely
806 */
Jim Miller25190572013-02-28 17:36:24 -0800807 public void verifyUnlock(IKeyguardExitCallback callback) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800808 synchronized (this) {
809 if (DEBUG) Log.d(TAG, "verifyUnlock");
Jim Millerb256e4e22014-10-31 17:27:13 -0700810 if (shouldWaitForProvisioning()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800811 // don't allow this api when the device isn't provisioned
812 if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned");
Jim Miller5ecd8112013-01-09 18:50:26 -0800813 try {
Jim Miller25190572013-02-28 17:36:24 -0800814 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -0800815 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800816 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800817 }
Mike Lockwood5d258b62009-12-02 13:50:45 -0500818 } else if (mExternallyEnabled) {
819 // this only applies when the user has externally disabled the
820 // keyguard. this is unexpected and means the user is not
821 // using the api properly.
822 Log.w(TAG, "verifyUnlock called when not externally disabled");
Jim Miller5ecd8112013-01-09 18:50:26 -0800823 try {
Jim Miller25190572013-02-28 17:36:24 -0800824 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -0800825 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800826 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800827 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800828 } else if (mExitSecureCallback != null) {
829 // already in progress with someone else
Jim Miller5ecd8112013-01-09 18:50:26 -0800830 try {
Jim Miller25190572013-02-28 17:36:24 -0800831 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -0800832 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800833 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800834 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800835 } else {
Jim Miller25190572013-02-28 17:36:24 -0800836 mExitSecureCallback = callback;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800837 verifyUnlockLocked();
838 }
839 }
840 }
841
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800842 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100843 * Is the keyguard currently showing and not being force hidden?
Mike Lockwood09a40402009-11-08 00:33:23 -0500844 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100845 public boolean isShowingAndNotOccluded() {
846 return mShowing && !mOccluded;
847 }
848
849 /**
850 * Notify us when the keyguard is occluded by another window
851 */
852 public void setOccluded(boolean isOccluded) {
853 if (DEBUG) Log.d(TAG, "setOccluded " + isOccluded);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100854 mHandler.removeMessages(SET_OCCLUDED);
855 Message msg = mHandler.obtainMessage(SET_OCCLUDED, (isOccluded ? 1 : 0), 0);
Mike Lockwood9200a392009-11-17 20:25:58 -0500856 mHandler.sendMessage(msg);
857 }
858
859 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100860 * Handles SET_OCCLUDED message sent by setOccluded()
Mike Lockwood9200a392009-11-17 20:25:58 -0500861 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100862 private void handleSetOccluded(boolean isOccluded) {
Mike Lockwood09a40402009-11-08 00:33:23 -0500863 synchronized (KeyguardViewMediator.this) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100864 if (mOccluded != isOccluded) {
865 mOccluded = isOccluded;
866 mStatusBarKeyguardViewManager.setOccluded(isOccluded);
Dianne Hackbornff5b1582012-04-12 17:24:07 -0700867 updateActivityLockScreenState();
Mike Lockwood5f892c12009-11-19 23:39:13 -0500868 adjustStatusBarLocked();
Mike Lockwood9200a392009-11-17 20:25:58 -0500869 }
Mike Lockwood09a40402009-11-08 00:33:23 -0500870 }
871 }
872
873 /**
Mike Lockwood28569302010-01-28 11:54:40 -0500874 * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout.
875 * This must be safe to call from any thread and with any window manager locks held.
876 */
Adam Cohenf7522022012-10-03 20:03:18 -0700877 public void doKeyguardTimeout(Bundle options) {
Mike Lockwood28569302010-01-28 11:54:40 -0500878 mHandler.removeMessages(KEYGUARD_TIMEOUT);
Adam Cohenf7522022012-10-03 20:03:18 -0700879 Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options);
Mike Lockwood28569302010-01-28 11:54:40 -0500880 mHandler.sendMessage(msg);
881 }
882
883 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800884 * Given the state of the keyguard, is the input restricted?
885 * Input is restricted when the keyguard is showing, or when the keyguard
886 * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet.
887 */
888 public boolean isInputRestricted() {
Jim Millerb256e4e22014-10-31 17:27:13 -0700889 return mShowing || mNeedToReshowWhenReenabled || shouldWaitForProvisioning();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800890 }
891
Jim Millerab954542014-10-10 18:21:49 -0700892 private void updateInputRestricted() {
893 synchronized (this) {
894 updateInputRestrictedLocked();
895 }
896 }
897 private void updateInputRestrictedLocked() {
898 boolean inputRestricted = isInputRestricted();
899 if (mInputRestricted != inputRestricted) {
900 mInputRestricted = inputRestricted;
901 try {
902 int size = mKeyguardStateCallbacks.size();
903 for (int i = 0; i < size; i++) {
904 mKeyguardStateCallbacks.get(i).onInputRestrictedStateChanged(inputRestricted);
905 }
906 } catch (RemoteException e) {
907 Slog.w(TAG, "Failed to call onDeviceProvisioned", e);
908 }
909 }
910 }
911
Dianne Hackbornb446e972009-09-20 15:23:25 -0700912 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700913 * Enable the keyguard if the settings are appropriate.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800914 */
Adam Cohenf7522022012-10-03 20:03:18 -0700915 private void doKeyguardLocked(Bundle options) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700916 // if another app is disabling us, don't show
917 if (!mExternallyEnabled) {
918 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled");
Karl Rosaenab100082009-03-24 22:35:17 -0700919
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700920 // note: we *should* set mNeedToReshowWhenReenabled=true here, but that makes
921 // for an occasional ugly flicker in this situation:
922 // 1) receive a call with the screen on (no keyguard) or make a call
923 // 2) screen times out
924 // 3) user hits key to turn screen back on
925 // instead, we reenable the keyguard when we know the screen is off and the call
926 // ends (see the broadcast receiver below)
927 // TODO: clean this up when we have better support at the window manager level
928 // for apps that wish to be on top of the keyguard
Dianne Hackborn38e29a62011-09-18 14:43:08 -0700929 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800930 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700931
932 // if the keyguard is already showing, don't bother
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100933 if (mStatusBarKeyguardViewManager.isShowing()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700934 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing");
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100935 resetStateLocked();
Dianne Hackborn38e29a62011-09-18 14:43:08 -0700936 return;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700937 }
938
939 // if the setup wizard hasn't run yet, don't show
Jim Miller52a61332014-11-12 19:29:51 -0800940 final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", false);
Wink Savillea54bf652014-12-11 13:37:50 -0800941 final boolean absent = SubscriptionManager.isValidSubscriptionId(
942 mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.ABSENT));
943 final boolean disabled = SubscriptionManager.isValidSubscriptionId(
944 mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.PERM_DISABLED));
Jim Miller52a61332014-11-12 19:29:51 -0800945 final boolean lockedOrMissing = mUpdateMonitor.isSimPinSecure()
946 || ((absent || disabled) && requireSim);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700947
Jim Millerb256e4e22014-10-31 17:27:13 -0700948 if (!lockedOrMissing && shouldWaitForProvisioning()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700949 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned"
950 + " and the sim is not locked or missing");
Dianne Hackborn38e29a62011-09-18 14:43:08 -0700951 return;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700952 }
953
Jorim Jaggid0b698f2014-07-02 16:46:27 +0200954 if (mLockPatternUtils.isLockScreenDisabled() && !lockedOrMissing) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700955 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off");
Dianne Hackborn38e29a62011-09-18 14:43:08 -0700956 return;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700957 }
958
Paul Lawrence945490c2014-03-27 16:37:28 +0000959 if (mLockPatternUtils.checkVoldPassword()) {
960 if (DEBUG) Log.d(TAG, "Not showing lock screen since just decrypted");
961 // Without this, settings is not enabled until the lock screen first appears
Jim Millerab954542014-10-10 18:21:49 -0700962 setShowingLocked(false);
Paul Lawrence945490c2014-03-27 16:37:28 +0000963 hideLocked();
964 return;
965 }
966
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700967 if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");
Adam Cohenf7522022012-10-03 20:03:18 -0700968 showLocked(options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800969 }
970
Jim Millerb256e4e22014-10-31 17:27:13 -0700971 private boolean shouldWaitForProvisioning() {
972 return !mUpdateMonitor.isDeviceProvisioned() && !isSecure();
973 }
974
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800975 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700976 * Dismiss the keyguard through the security layers.
977 */
Jim Miller60013792013-10-03 18:31:34 -0700978 public void handleDismiss() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100979 if (mShowing && !mOccluded) {
980 mStatusBarKeyguardViewManager.dismiss();
Jim Miller87d03662012-11-05 20:28:09 -0800981 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700982 }
983
Jim Miller60013792013-10-03 18:31:34 -0700984 public void dismiss() {
985 mHandler.sendEmptyMessage(DISMISS);
986 }
987
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700988 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800989 * Send message to keyguard telling it to reset its state.
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100990 * @see #handleReset
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800991 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100992 private void resetStateLocked() {
Jim Miller4894a012013-04-03 15:23:55 -0700993 if (DEBUG) Log.e(TAG, "resetStateLocked");
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100994 Message msg = mHandler.obtainMessage(RESET);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800995 mHandler.sendMessage(msg);
996 }
997
998 /**
999 * Send message to keyguard telling it to verify unlock
1000 * @see #handleVerifyUnlock()
1001 */
1002 private void verifyUnlockLocked() {
1003 if (DEBUG) Log.d(TAG, "verifyUnlockLocked");
1004 mHandler.sendEmptyMessage(VERIFY_UNLOCK);
1005 }
1006
1007
1008 /**
1009 * Send a message to keyguard telling it the screen just turned on.
1010 * @see #onScreenTurnedOff(int)
1011 * @see #handleNotifyScreenOff
1012 */
1013 private void notifyScreenOffLocked() {
1014 if (DEBUG) Log.d(TAG, "notifyScreenOffLocked");
1015 mHandler.sendEmptyMessage(NOTIFY_SCREEN_OFF);
1016 }
1017
1018 /**
1019 * Send a message to keyguard telling it the screen just turned on.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001020 * @see #onScreenTurnedOn
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001021 * @see #handleNotifyScreenOn
1022 */
Jim Miller25190572013-02-28 17:36:24 -08001023 private void notifyScreenOnLocked(IKeyguardShowCallback result) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001024 if (DEBUG) Log.d(TAG, "notifyScreenOnLocked");
Jim Miller5ecd8112013-01-09 18:50:26 -08001025 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_ON, result);
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001026 mHandler.sendMessage(msg);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001027 }
1028
1029 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001030 * Send message to keyguard telling it to show itself
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001031 * @see #handleShow
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001032 */
Adam Cohenf7522022012-10-03 20:03:18 -07001033 private void showLocked(Bundle options) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001034 if (DEBUG) Log.d(TAG, "showLocked");
Mike Lockwood674d3e42009-10-06 09:28:54 -04001035 // ensure we stay awake until we are finished displaying the keyguard
1036 mShowKeyguardWakeLock.acquire();
Adam Cohenf7522022012-10-03 20:03:18 -07001037 Message msg = mHandler.obtainMessage(SHOW, options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001038 mHandler.sendMessage(msg);
1039 }
1040
1041 /**
1042 * Send message to keyguard telling it to hide itself
Jim Miller9c20d0e2010-01-20 15:00:23 -08001043 * @see #handleHide()
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001044 */
1045 private void hideLocked() {
1046 if (DEBUG) Log.d(TAG, "hideLocked");
1047 Message msg = mHandler.obtainMessage(HIDE);
1048 mHandler.sendMessage(msg);
1049 }
1050
Dianne Hackbornb446e972009-09-20 15:23:25 -07001051 public boolean isSecure() {
Jim Millerdcb3d842012-08-23 19:18:12 -07001052 return mLockPatternUtils.isSecure()
1053 || KeyguardUpdateMonitor.getInstance(mContext).isSimPinSecure();
Dianne Hackbornb446e972009-09-20 15:23:25 -07001054 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001055
Craig Mautnerf1b67412012-09-19 13:18:29 -07001056 /**
1057 * Update the newUserId. Call while holding WindowManagerService lock.
Jim Milleree82f8f2012-10-01 16:26:18 -07001058 * NOTE: Should only be called by KeyguardViewMediator in response to the user id changing.
1059 *
Craig Mautnerf1b67412012-09-19 13:18:29 -07001060 * @param newUserId The id of the incoming user.
1061 */
1062 public void setCurrentUser(int newUserId) {
1063 mLockPatternUtils.setCurrentUser(newUserId);
1064 }
1065
Jim Millerbbf1a742012-07-17 18:30:30 -07001066 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
Amith Yamasani52c489c2012-03-28 11:42:42 -07001067 @Override
1068 public void onReceive(Context context, Intent intent) {
Jim Millerbbf1a742012-07-17 18:30:30 -07001069 if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
1070 final int sequence = intent.getIntExtra("seq", 0);
Jim Millerf3447352011-08-07 14:00:09 -07001071 if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = "
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001072 + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001073 synchronized (KeyguardViewMediator.this) {
1074 if (mDelayedShowingSequence == sequence) {
Jim Millerbbf1a742012-07-17 18:30:30 -07001075 // Don't play lockscreen SFX if the screen went off due to timeout.
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001076 mSuppressNextLockSound = true;
Jim Miller5ecd8112013-01-09 18:50:26 -08001077 doKeyguardLocked(null);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001078 }
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001079 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001080 }
1081 }
1082 };
1083
Dianne Hackborn05726582009-09-22 17:28:24 -07001084 public void keyguardDone(boolean authenticated, boolean wakeup) {
Jim Miller60013792013-10-03 18:31:34 -07001085 if (DEBUG) Log.d(TAG, "keyguardDone(" + authenticated + ")");
1086 EventLog.writeEvent(70000, 2);
Jim Miller60013792013-10-03 18:31:34 -07001087 Message msg = mHandler.obtainMessage(KEYGUARD_DONE, authenticated ? 1 : 0, wakeup ? 1 : 0);
1088 mHandler.sendMessage(msg);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001089 }
1090
1091 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001092 * This handler will be associated with the policy thread, which will also
1093 * be the UI thread of the keyguard. Since the apis of the policy, and therefore
1094 * this class, can be called by other threads, any action that directly
1095 * interacts with the keyguard ui should be posted to this handler, rather
1096 * than called directly.
1097 */
Jim Millerdcb3d842012-08-23 19:18:12 -07001098 private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001099 @Override
Wink Saville37c124c2009-04-02 01:37:02 -07001100 public void handleMessage(Message msg) {
1101 switch (msg.what) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001102 case SHOW:
Adam Cohenf7522022012-10-03 20:03:18 -07001103 handleShow((Bundle) msg.obj);
Jim Miller60013792013-10-03 18:31:34 -07001104 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001105 case HIDE:
1106 handleHide();
Jim Miller60013792013-10-03 18:31:34 -07001107 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001108 case RESET:
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001109 handleReset();
Jim Miller60013792013-10-03 18:31:34 -07001110 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001111 case VERIFY_UNLOCK:
1112 handleVerifyUnlock();
Jim Miller60013792013-10-03 18:31:34 -07001113 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001114 case NOTIFY_SCREEN_OFF:
1115 handleNotifyScreenOff();
Jim Miller60013792013-10-03 18:31:34 -07001116 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001117 case NOTIFY_SCREEN_ON:
Jim Miller25190572013-02-28 17:36:24 -08001118 handleNotifyScreenOn((IKeyguardShowCallback) msg.obj);
Jim Miller60013792013-10-03 18:31:34 -07001119 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001120 case KEYGUARD_DONE:
Jim Millere51cf7ae2013-06-25 18:31:56 -07001121 handleKeyguardDone(msg.arg1 != 0, msg.arg2 != 0);
Jim Miller60013792013-10-03 18:31:34 -07001122 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001123 case KEYGUARD_DONE_DRAWING:
1124 handleKeyguardDoneDrawing();
Jim Miller60013792013-10-03 18:31:34 -07001125 break;
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001126 case KEYGUARD_DONE_AUTHENTICATING:
Jim Millerdcb3d842012-08-23 19:18:12 -07001127 keyguardDone(true, true);
Jim Miller60013792013-10-03 18:31:34 -07001128 break;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001129 case SET_OCCLUDED:
1130 handleSetOccluded(msg.arg1 != 0);
Mike Lockwood9200a392009-11-17 20:25:58 -05001131 break;
Mike Lockwood28569302010-01-28 11:54:40 -05001132 case KEYGUARD_TIMEOUT:
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001133 synchronized (KeyguardViewMediator.this) {
Adam Cohenf7522022012-10-03 20:03:18 -07001134 doKeyguardLocked((Bundle) msg.obj);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001135 }
1136 break;
Jim Miller60013792013-10-03 18:31:34 -07001137 case DISMISS:
1138 handleDismiss();
1139 break;
Jorim Jaggi0d674622014-05-21 01:34:15 +02001140 case START_KEYGUARD_EXIT_ANIM:
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001141 StartKeyguardExitAnimParams params = (StartKeyguardExitAnimParams) msg.obj;
1142 handleStartKeyguardExitAnimation(params.startTime, params.fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02001143 break;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001144 case KEYGUARD_DONE_PENDING_TIMEOUT:
1145 Log.w(TAG, "Timeout while waiting for activity drawn!");
1146 // Fall through.
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001147 case ON_ACTIVITY_DRAWN:
1148 handleOnActivityDrawn();
1149 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001150 }
1151 }
1152 };
1153
1154 /**
1155 * @see #keyguardDone
1156 * @see #KEYGUARD_DONE
1157 */
Jim Millere51cf7ae2013-06-25 18:31:56 -07001158 private void handleKeyguardDone(boolean authenticated, boolean wakeup) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001159 if (DEBUG) Log.d(TAG, "handleKeyguardDone");
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001160 synchronized (this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001161 resetKeyguardDonePendingLocked();
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001162 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001163
1164 if (authenticated) {
1165 mUpdateMonitor.clearFailedUnlockAttempts();
Dianne Hackborn05726582009-09-22 17:28:24 -07001166 }
Jim Millerf41fc962014-06-18 16:33:51 -07001167 mUpdateMonitor.clearFingerprintRecognized();
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -07001168
Jim Millere51cf7ae2013-06-25 18:31:56 -07001169 if (mExitSecureCallback != null) {
1170 try {
1171 mExitSecureCallback.onKeyguardExitResult(authenticated);
1172 } catch (RemoteException e) {
1173 Slog.w(TAG, "Failed to call onKeyguardExitResult(" + authenticated + ")", e);
1174 }
1175
1176 mExitSecureCallback = null;
1177
1178 if (authenticated) {
1179 // after succesfully exiting securely, no need to reshow
1180 // the keyguard when they've released the lock
1181 mExternallyEnabled = true;
1182 mNeedToReshowWhenReenabled = false;
Jim Millerab954542014-10-10 18:21:49 -07001183 updateInputRestricted();
Jim Millere51cf7ae2013-06-25 18:31:56 -07001184 }
1185 }
1186
1187 handleHide();
Jim Miller3fd47af2012-09-21 19:55:27 -07001188 }
1189
1190 private void sendUserPresentBroadcast() {
Jason Monkcf5a9532014-09-17 16:22:19 -04001191 synchronized (this) {
1192 if (mBootCompleted) {
1193 final UserHandle currentUser = new UserHandle(mLockPatternUtils.getCurrentUser());
Benjamin Franz4b9f8ed2014-12-01 16:51:48 +00001194 final UserManager um = (UserManager) mContext.getSystemService(
1195 Context.USER_SERVICE);
1196 List <UserInfo> userHandles = um.getProfiles(currentUser.getIdentifier());
1197 for (UserInfo ui : userHandles) {
1198 mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, ui.getUserHandle());
1199 }
Jason Monkcf5a9532014-09-17 16:22:19 -04001200 } else {
1201 mBootSendUserPresent = true;
1202 }
1203 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001204 }
1205
1206 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001207 * @see #keyguardDone
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001208 * @see #KEYGUARD_DONE_DRAWING
1209 */
1210 private void handleKeyguardDoneDrawing() {
1211 synchronized(this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001212 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001213 if (mWaitingUntilKeyguardVisible) {
1214 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible");
1215 mWaitingUntilKeyguardVisible = false;
1216 notifyAll();
1217
1218 // there will usually be two of these sent, one as a timeout, and one
1219 // as a result of the callback, so remove any remaining messages from
1220 // the queue
1221 mHandler.removeMessages(KEYGUARD_DONE_DRAWING);
1222 }
1223 }
1224 }
1225
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001226 private void playSounds(boolean locked) {
1227 // User feedback for keyguard.
Daniel Sandler0060a9b2010-03-15 23:09:57 -04001228
1229 if (mSuppressNextLockSound) {
1230 mSuppressNextLockSound = false;
1231 return;
1232 }
1233
Adrian Roos49e057d2014-08-13 17:14:51 +02001234 playSound(locked ? mLockSoundId : mUnlockSoundId);
1235 }
1236
1237 private void playSound(int soundId) {
1238 if (soundId == 0) return;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001239 final ContentResolver cr = mContext.getContentResolver();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001240 if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001241
Marco Nelissend5545bd2011-09-29 12:49:17 -07001242 mLockSounds.stop(mLockSoundStreamId);
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001243 // Init mAudioManager
1244 if (mAudioManager == null) {
1245 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
1246 if (mAudioManager == null) return;
John Spurlockee5ad722015-03-03 16:17:21 -05001247 mUiSoundsStreamType = mAudioManager.getUiSoundsStreamType();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001248 }
1249 // If the stream is muted, don't play the sound
John Spurlockee5ad722015-03-03 16:17:21 -05001250 if (mAudioManager.isStreamMute(mUiSoundsStreamType)) return;
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001251
Adrian Roos49e057d2014-08-13 17:14:51 +02001252 mLockSoundStreamId = mLockSounds.play(soundId,
Jean-Michel Trivic55b3932012-06-05 11:57:59 -07001253 mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/);
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001254 }
Jim Miller2a98a4c2010-11-19 18:49:26 -08001255 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001256
Adrian Roos49e057d2014-08-13 17:14:51 +02001257 private void playTrustedSound() {
1258 if (mSuppressNextLockSound) {
1259 return;
1260 }
1261 playSound(mTrustedSoundId);
1262 }
1263
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001264 private void updateActivityLockScreenState() {
1265 try {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001266 ActivityManagerNative.getDefault().setLockScreenShown(mShowing && !mOccluded);
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001267 } catch (RemoteException e) {
1268 }
1269 }
1270
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001271 /**
1272 * Handle message sent by {@link #showLocked}.
1273 * @see #SHOW
1274 */
Adam Cohenf7522022012-10-03 20:03:18 -07001275 private void handleShow(Bundle options) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001276 synchronized (KeyguardViewMediator.this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001277 if (!mSystemReady) {
1278 if (DEBUG) Log.d(TAG, "ignoring handleShow because system is not ready.");
1279 return;
1280 } else {
1281 if (DEBUG) Log.d(TAG, "handleShow");
1282 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001283
Jim Millerab954542014-10-10 18:21:49 -07001284 setShowingLocked(true);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001285 mStatusBarKeyguardViewManager.show(options);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001286 mHiding = false;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001287 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001288 mHideAnimationRun = false;
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001289 updateActivityLockScreenState();
Mike Lockwood5f892c12009-11-19 23:39:13 -05001290 adjustStatusBarLocked();
Jeff Brown3dc524b2012-09-30 19:49:11 -07001291 userActivity();
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001292
1293 // Do this at the end to not slow down display of the keyguard.
1294 playSounds(true);
1295
Mike Lockwood674d3e42009-10-06 09:28:54 -04001296 mShowKeyguardWakeLock.release();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001297 }
Jim Miller31921482013-11-06 20:43:55 -08001298 mKeyguardDisplayManager.show();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001299 }
1300
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001301 private final Runnable mKeyguardGoingAwayRunnable = new Runnable() {
1302 @Override
1303 public void run() {
1304 try {
Jorim Jaggi33ae80e2015-02-04 16:37:11 +01001305 mStatusBarKeyguardViewManager.keyguardGoingAway();
1306
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001307 // Don't actually hide the Keyguard at the moment, wait for window
1308 // manager until it tells us it's safe to do so with
1309 // startKeyguardExitAnimation.
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02001310 mWM.keyguardGoingAway(
1311 mStatusBarKeyguardViewManager.shouldDisableWindowAnimationsForUnlock(),
1312 mStatusBarKeyguardViewManager.isGoingToNotificationShade());
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001313 } catch (RemoteException e) {
1314 Log.e(TAG, "Error while calling WindowManager", e);
1315 }
1316 }
1317 };
1318
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001319 /**
1320 * Handle message sent by {@link #hideLocked()}
1321 * @see #HIDE
1322 */
1323 private void handleHide() {
1324 synchronized (KeyguardViewMediator.this) {
1325 if (DEBUG) Log.d(TAG, "handleHide");
Jorim Jaggib9d60792014-06-03 22:34:22 +02001326
Jorim Jaggi76a16232014-08-08 17:00:47 +02001327 mHiding = true;
1328 if (mShowing && !mOccluded) {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001329 if (!mHideAnimationRun) {
1330 mStatusBarKeyguardViewManager.startPreHideAnimation(mKeyguardGoingAwayRunnable);
1331 } else {
1332 mKeyguardGoingAwayRunnable.run();
1333 }
Jorim Jaggi76a16232014-08-08 17:00:47 +02001334 } else {
Jorim Jaggib9d60792014-06-03 22:34:22 +02001335
Jorim Jaggi76a16232014-08-08 17:00:47 +02001336 // Don't try to rely on WindowManager - if Keyguard wasn't showing, window
1337 // manager won't start the exit animation.
1338 handleStartKeyguardExitAnimation(
1339 SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(),
1340 mHideAnimation.getDuration());
Jorim Jaggi0d674622014-05-21 01:34:15 +02001341 }
1342 }
1343 }
1344
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001345 private void handleOnActivityDrawn() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001346 if (DEBUG) Log.d(TAG, "handleOnActivityDrawn: mKeyguardDonePending=" + mKeyguardDonePending);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001347 if (mKeyguardDonePending) {
1348 mStatusBarKeyguardViewManager.onActivityDrawn();
1349 }
1350 }
1351
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001352 private void handleStartKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02001353 synchronized (KeyguardViewMediator.this) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001354
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001355 if (!mHiding) {
1356 return;
1357 }
1358 mHiding = false;
1359
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001360 // only play "unlock" noises if not on a call (since the incall UI
1361 // disables the keyguard)
1362 if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) {
1363 playSounds(false);
1364 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001365
Jim Millerab954542014-10-10 18:21:49 -07001366 setShowingLocked(false);
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001367 mStatusBarKeyguardViewManager.hide(startTime, fadeoutDuration);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001368 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001369 mHideAnimationRun = false;
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001370 updateActivityLockScreenState();
Mike Lockwood5f892c12009-11-19 23:39:13 -05001371 adjustStatusBarLocked();
Jim Miller705004b2014-09-04 16:51:20 -07001372 sendUserPresentBroadcast();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001373 }
1374 }
1375
Mike Lockwood5f892c12009-11-19 23:39:13 -05001376 private void adjustStatusBarLocked() {
1377 if (mStatusBarManager == null) {
1378 mStatusBarManager = (StatusBarManager)
1379 mContext.getSystemService(Context.STATUS_BAR_SERVICE);
1380 }
1381 if (mStatusBarManager == null) {
1382 Log.w(TAG, "Could not get status bar manager");
1383 } else {
Daniel Sandlerdba93562011-10-06 16:39:58 -04001384 // Disable aspects of the system/status/navigation bars that must not be re-enabled by
1385 // windows that appear on top, ever
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001386 int flags = StatusBarManager.DISABLE_NONE;
Mike Lockwoode3646dd2011-09-01 12:46:28 -04001387 if (mShowing) {
Jim Millere23ab8b2012-09-16 15:45:44 -07001388 // Permanently disable components not available when keyguard is enabled
1389 // (like recents). Temporary enable/disable (e.g. the "back" button) are
1390 // done in KeyguardHostView.
Daniel Sandlerdba93562011-10-06 16:39:58 -04001391 flags |= StatusBarManager.DISABLE_RECENT;
Jorim Jaggi118aece2014-08-25 15:25:38 +02001392 flags |= StatusBarManager.DISABLE_SEARCH;
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001393 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +02001394 if (isShowingAndNotOccluded()) {
1395 flags |= StatusBarManager.DISABLE_HOME;
1396 }
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001397
1398 if (DEBUG) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001399 Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mOccluded=" + mOccluded
Jeff Sharkey4519a022011-09-07 23:24:53 -07001400 + " isSecure=" + isSecure() + " --> flags=0x" + Integer.toHexString(flags));
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001401 }
1402
Jim Millerd6523da2012-10-21 16:47:02 -07001403 if (!(mContext instanceof Activity)) {
1404 mStatusBarManager.disable(flags);
1405 }
Mike Lockwood5f892c12009-11-19 23:39:13 -05001406 }
1407 }
1408
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001409 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001410 * Handle message sent by {@link #resetStateLocked}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001411 * @see #RESET
1412 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001413 private void handleReset() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001414 synchronized (KeyguardViewMediator.this) {
1415 if (DEBUG) Log.d(TAG, "handleReset");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001416 mStatusBarKeyguardViewManager.reset();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001417 }
1418 }
1419
1420 /**
1421 * Handle message sent by {@link #verifyUnlock}
Craig Mautner904732c2012-10-17 15:20:24 -07001422 * @see #VERIFY_UNLOCK
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001423 */
1424 private void handleVerifyUnlock() {
1425 synchronized (KeyguardViewMediator.this) {
1426 if (DEBUG) Log.d(TAG, "handleVerifyUnlock");
Jim Millerab954542014-10-10 18:21:49 -07001427 setShowingLocked(true);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001428 mStatusBarKeyguardViewManager.verifyUnlock();
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001429 updateActivityLockScreenState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001430 }
1431 }
1432
1433 /**
1434 * Handle message sent by {@link #notifyScreenOffLocked()}
1435 * @see #NOTIFY_SCREEN_OFF
1436 */
1437 private void handleNotifyScreenOff() {
1438 synchronized (KeyguardViewMediator.this) {
1439 if (DEBUG) Log.d(TAG, "handleNotifyScreenOff");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001440 mStatusBarKeyguardViewManager.onScreenTurnedOff();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001441 }
1442 }
1443
1444 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001445 * Handle message sent by {@link #notifyScreenOnLocked}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001446 * @see #NOTIFY_SCREEN_ON
1447 */
Jim Miller25190572013-02-28 17:36:24 -08001448 private void handleNotifyScreenOn(IKeyguardShowCallback callback) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001449 synchronized (KeyguardViewMediator.this) {
1450 if (DEBUG) Log.d(TAG, "handleNotifyScreenOn");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001451 mStatusBarKeyguardViewManager.onScreenTurnedOn(callback);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001452 }
1453 }
Jeff Sharkey054340d2011-09-01 22:28:03 -07001454
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001455 private void resetKeyguardDonePendingLocked() {
1456 mKeyguardDonePending = false;
1457 mHandler.removeMessages(KEYGUARD_DONE_PENDING_TIMEOUT);
1458 }
1459
Jim Millere5f910a2013-10-16 18:15:46 -07001460 public void onBootCompleted() {
1461 mUpdateMonitor.dispatchBootCompleted();
Jason Monkcf5a9532014-09-17 16:22:19 -04001462 synchronized (this) {
1463 mBootCompleted = true;
1464 if (mBootSendUserPresent) {
1465 sendUserPresentBroadcast();
1466 }
1467 }
Jim Millere5f910a2013-10-16 18:15:46 -07001468 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001469
Jorim Jaggi03c701e2014-04-02 12:39:51 +02001470 public StatusBarKeyguardViewManager registerStatusBar(PhoneStatusBar phoneStatusBar,
Jorim Jaggiecc798e2014-05-26 18:14:37 +02001471 ViewGroup container, StatusBarWindowManager statusBarWindowManager,
1472 ScrimController scrimController) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001473 mStatusBarKeyguardViewManager.registerStatusBar(phoneStatusBar, container,
Jorim Jaggiecc798e2014-05-26 18:14:37 +02001474 statusBarWindowManager, scrimController);
Jorim Jaggi03c701e2014-04-02 12:39:51 +02001475 return mStatusBarKeyguardViewManager;
1476 }
1477
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001478 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
1479 Message msg = mHandler.obtainMessage(START_KEYGUARD_EXIT_ANIM,
1480 new StartKeyguardExitAnimParams(startTime, fadeoutDuration));
Jorim Jaggi0d674622014-05-21 01:34:15 +02001481 mHandler.sendMessage(msg);
1482 }
1483
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001484 public void onActivityDrawn() {
1485 mHandler.sendEmptyMessage(ON_ACTIVITY_DRAWN);
1486 }
Jorim Jaggi03c701e2014-04-02 12:39:51 +02001487 public ViewMediatorCallback getViewMediatorCallback() {
1488 return mViewMediatorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001489 }
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001490
1491 private static class StartKeyguardExitAnimParams {
1492
1493 long startTime;
1494 long fadeoutDuration;
1495
1496 private StartKeyguardExitAnimParams(long startTime, long fadeoutDuration) {
1497 this.startTime = startTime;
1498 this.fadeoutDuration = fadeoutDuration;
1499 }
1500 }
Adrian Roos481a6df2014-11-20 19:48:56 +01001501
Jim Millerab954542014-10-10 18:21:49 -07001502 private void setShowingLocked(boolean showing) {
1503 if (showing != mShowing) {
1504 mShowing = showing;
1505 try {
1506 int size = mKeyguardStateCallbacks.size();
1507 for (int i = 0; i < size; i++) {
1508 mKeyguardStateCallbacks.get(i).onShowingStateChanged(showing);
1509 }
1510 } catch (RemoteException e) {
1511 Slog.w(TAG, "Failed to call onShowingStateChanged", e);
1512 }
1513 updateInputRestrictedLocked();
Adrian Roos481a6df2014-11-20 19:48:56 +01001514 mTrustManager.reportKeyguardShowingChanged();
1515 }
1516 }
Jim Millerab954542014-10-10 18:21:49 -07001517
1518 public void addStateMonitorCallback(IKeyguardStateCallback callback) {
1519 synchronized (this) {
1520 mKeyguardStateCallbacks.add(callback);
1521 try {
1522 callback.onSimSecureStateChanged(mUpdateMonitor.isSimPinSecure());
1523 callback.onShowingStateChanged(mShowing);
1524 } catch (RemoteException e) {
1525 Slog.w(TAG, "Failed to call onShowingStateChanged or onSimSecureStateChanged", e);
1526 }
1527 }
1528 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001529}