blob: b828e78a8c574bf969e845d214131ac05124cf19 [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
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700174 /**
175 * How much faster we collapse the lockscreen when authenticating with fingerprint.
176 */
177 private static final float FINGERPRINT_COLLAPSE_SPEEDUP_FACTOR = 1.3f;
178
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700179 /** The stream type that the lock sounds are tied to. */
John Spurlockee5ad722015-03-03 16:17:21 -0500180 private int mUiSoundsStreamType;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700181
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800182 private AlarmManager mAlarmManager;
Amith Yamasani8cb751b2011-09-30 15:39:41 -0700183 private AudioManager mAudioManager;
Mike Lockwood5f892c12009-11-19 23:39:13 -0500184 private StatusBarManager mStatusBarManager;
Chris Wrenf41c61b2012-11-29 15:19:54 -0500185 private boolean mSwitchingUser;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800186
187 private boolean mSystemReady;
Jason Monkcf5a9532014-09-17 16:22:19 -0400188 private boolean mBootCompleted;
189 private boolean mBootSendUserPresent;
Daniel Sandler0060a9b2010-03-15 23:09:57 -0400190
191 // Whether the next call to playSounds() should be skipped. Defaults to
192 // true because the first lock (on boot) should be silent.
193 private boolean mSuppressNextLockSound = true;
194
Jim Miller9c20d0e2010-01-20 15:00:23 -0800195
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800196 /** High level access to the power manager for WakeLocks */
197 private PowerManager mPM;
198
Jorim Jaggi0d674622014-05-21 01:34:15 +0200199 /** High level access to the window manager for dismissing keyguard animation */
200 private IWindowManager mWM;
201
Adrian Roos481a6df2014-11-20 19:48:56 +0100202
203 /** TrustManager for letting it know when we change visibility */
204 private TrustManager mTrustManager;
Amith Yamasanib70ff9a2012-09-07 18:28:11 -0700205
John Spurlock43d84512012-11-09 10:27:33 -0500206 /** SearchManager for determining whether or not search assistant is available */
207 private SearchManager mSearchManager;
208
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800209 /**
Mike Lockwood674d3e42009-10-06 09:28:54 -0400210 * Used to keep the device awake while to ensure the keyguard finishes opening before
211 * we sleep.
212 */
213 private PowerManager.WakeLock mShowKeyguardWakeLock;
214
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100215 private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800216
217 // these are protected by synchronized (this)
218
219 /**
Mike Lockwood5d258b62009-12-02 13:50:45 -0500220 * External apps (like the phone app) can tell us to disable the keygaurd.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800221 */
222 private boolean mExternallyEnabled = true;
223
224 /**
225 * Remember if an external call to {@link #setKeyguardEnabled} with value
226 * false caused us to hide the keyguard, so that we need to reshow it once
227 * the keygaurd is reenabled with another call with value true.
228 */
229 private boolean mNeedToReshowWhenReenabled = false;
230
231 // cached value of whether we are showing (need to know this to quickly
232 // answer whether the input should be restricted)
Jim Millere5f17ab2013-11-13 15:40:48 -0800233 private boolean mShowing;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800234
Jim Millerab954542014-10-10 18:21:49 -0700235 /** Cached value of #isInputRestricted */
236 private boolean mInputRestricted;
237
Mike Lockwood09a40402009-11-08 00:33:23 -0500238 // true if the keyguard is hidden by another window
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100239 private boolean mOccluded = false;
Mike Lockwood09a40402009-11-08 00:33:23 -0500240
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800241 /**
242 * Helps remember whether the screen has turned on since the last time
243 * it turned off due to timeout. see {@link #onScreenTurnedOff(int)}
244 */
245 private int mDelayedShowingSequence;
246
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800247 /**
248 * If the user has disabled the keyguard, then requests to exit, this is
249 * how we'll ultimately let them know whether it was successful. We use this
250 * var being non-null as an indicator that there is an in progress request.
251 */
Jim Miller25190572013-02-28 17:36:24 -0800252 private IKeyguardExitCallback mExitSecureCallback;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800253
254 // the properties of the keyguard
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800255
256 private KeyguardUpdateMonitor mUpdateMonitor;
257
Daniel Hansson4b716862012-03-29 11:02:05 +0200258 private boolean mScreenOn;
Karl Rosaenab100082009-03-24 22:35:17 -0700259
Daniel Sandlerf2d8e742010-02-22 13:09:48 -0500260 // last known state of the cellular connection
261 private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE;
262
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800263 /**
Jorim Jaggi53c68a42014-06-17 15:04:47 -0700264 * Whether a hide is pending an we are just waiting for #startKeyguardExitAnimation to be
265 * called.
266 * */
267 private boolean mHiding;
268
269 /**
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700270 * we send this intent when the keyguard is dismissed.
271 */
Jim Miller17f509a2013-02-28 18:36:12 -0800272 private static final Intent USER_PRESENT_INTENT = new Intent(Intent.ACTION_USER_PRESENT)
273 .addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
274 | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
The Android Open Source Projectc84bf282009-03-09 11:52:14 -0700275
276 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800277 * {@link #setKeyguardEnabled} waits on this condition when it reenables
278 * the keyguard.
279 */
280 private boolean mWaitingUntilKeyguardVisible = false;
Jim Millerbc4603b2010-08-30 21:21:34 -0700281 private LockPatternUtils mLockPatternUtils;
John Spurlock34c4fe52012-11-07 10:12:29 -0500282 private boolean mKeyguardDonePending = false;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200283 private boolean mHideAnimationRun = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800284
Marco Nelissend5545bd2011-09-29 12:49:17 -0700285 private SoundPool mLockSounds;
286 private int mLockSoundId;
287 private int mUnlockSoundId;
Adrian Roos49e057d2014-08-13 17:14:51 +0200288 private int mTrustedSoundId;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700289 private int mLockSoundStreamId;
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700290
291 /**
Adrian Roos0002a452014-07-03 13:46:07 +0200292 * The animation used for hiding keyguard. This is used to fetch the animation timings if
293 * WindowManager is not providing us with them.
294 */
295 private Animation mHideAnimation;
296
297 /**
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700298 * The volume applied to the lock/unlock sounds.
299 */
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200300 private float mLockSoundVolume;
Marco Nelissend5545bd2011-09-29 12:49:17 -0700301
Jim Millerdcb3d842012-08-23 19:18:12 -0700302 /**
Jim Miller31921482013-11-06 20:43:55 -0800303 * For managing external displays
304 */
305 private KeyguardDisplayManager mKeyguardDisplayManager;
306
Jim Millerab954542014-10-10 18:21:49 -0700307 private final ArrayList<IKeyguardStateCallback> mKeyguardStateCallbacks = new ArrayList<>();
308
Jim Millerbbf1a742012-07-17 18:30:30 -0700309 KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {
310
311 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500312 public void onUserSwitching(int userId) {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700313 // Note that the mLockPatternUtils user has already been updated from setCurrentUser.
Adam Cohenf7522022012-10-03 20:03:18 -0700314 // We need to force a reset of the views, since lockNow (called by
315 // ActivityManagerService) will not reconstruct the keyguard if it is already showing.
Jim Millerbbf1a742012-07-17 18:30:30 -0700316 synchronized (KeyguardViewMediator.this) {
Chris Wrenf41c61b2012-11-29 15:19:54 -0500317 mSwitchingUser = true;
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100318 resetKeyguardDonePendingLocked();
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100319 resetStateLocked();
John Spurlock4e6922d2012-10-04 14:51:51 -0400320 adjustStatusBarLocked();
Dianne Hackborn5dc5a002012-09-15 19:33:48 -0700321 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700322 }
323
324 @Override
Chris Wrenf41c61b2012-11-29 15:19:54 -0500325 public void onUserSwitchComplete(int userId) {
326 mSwitchingUser = false;
Adrian Roosbe47b072014-09-03 00:08:56 +0200327 if (userId != UserHandle.USER_OWNER) {
328 UserInfo info = UserManager.get(mContext).getUserInfo(userId);
329 if (info != null && info.isGuest()) {
330 // If we just switched to a guest, try to dismiss keyguard.
331 dismiss();
332 }
333 }
Chris Wrenf41c61b2012-11-29 15:19:54 -0500334 }
335
336 @Override
Amith Yamasani6fc1d4e2013-05-08 16:43:58 -0700337 public void onUserInfoChanged(int userId) {
Jim Millerbbf1a742012-07-17 18:30:30 -0700338 }
339
340 @Override
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100341 public void onPhoneStateChanged(int phoneState) {
Jim Millerbbf1a742012-07-17 18:30:30 -0700342 synchronized (KeyguardViewMediator.this) {
343 if (TelephonyManager.CALL_STATE_IDLE == phoneState // call ending
344 && !mScreenOn // screen off
345 && mExternallyEnabled) { // not disabled by any app
346
347 // note: this is a way to gracefully reenable the keyguard when the call
348 // ends and the screen is off without always reenabling the keyguard
349 // each time the screen turns off while in call (and having an occasional ugly
350 // flicker while turning back on the screen and disabling the keyguard again).
351 if (DEBUG) Log.d(TAG, "screen is off and call ended, let's make sure the "
352 + "keyguard is showing");
Jim Miller5ecd8112013-01-09 18:50:26 -0800353 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700354 }
355 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100356 }
Jim Millerb0304762012-03-13 20:01:25 -0700357
358 @Override
359 public void onClockVisibilityChanged() {
360 adjustStatusBarLocked();
361 }
362
363 @Override
364 public void onDeviceProvisioned() {
Jim Miller3fd47af2012-09-21 19:55:27 -0700365 sendUserPresentBroadcast();
Jim Millerab954542014-10-10 18:21:49 -0700366 updateInputRestricted();
Jim Millerb0304762012-03-13 20:01:25 -0700367 }
368
Jim Millerbbf1a742012-07-17 18:30:30 -0700369 @Override
Jim Miller52a61332014-11-12 19:29:51 -0800370 public void onSimStateChanged(int subId, int slotId, IccCardConstants.State simState) {
371
372 if (DEBUG_SIM_STATES) {
373 Log.d(TAG, "onSimStateChanged(subId=" + subId + ", slotId=" + slotId
374 + ",state=" + simState + ")");
375 }
Jim Millerbbf1a742012-07-17 18:30:30 -0700376
Jim Millerab954542014-10-10 18:21:49 -0700377 try {
378 int size = mKeyguardStateCallbacks.size();
379 boolean simPinSecure = mUpdateMonitor.isSimPinSecure();
380 for (int i = 0; i < size; i++) {
381 mKeyguardStateCallbacks.get(i).onSimSecureStateChanged(simPinSecure);
382 }
383 } catch (RemoteException e) {
384 Slog.w(TAG, "Failed to call onSimSecureStateChanged", e);
385 }
386
Jim Millerbbf1a742012-07-17 18:30:30 -0700387 switch (simState) {
388 case NOT_READY:
389 case ABSENT:
390 // only force lock screen in case of missing sim if user hasn't
391 // gone through setup wizard
392 synchronized (this) {
Jim Millerb256e4e22014-10-31 17:27:13 -0700393 if (shouldWaitForProvisioning()) {
Jim Millerab954542014-10-10 18:21:49 -0700394 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800395 if (DEBUG_SIM_STATES) Log.d(TAG, "ICC_ABSENT isn't showing,"
Jim Millerbbf1a742012-07-17 18:30:30 -0700396 + " we need to show the keyguard since the "
397 + "device isn't provisioned yet.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800398 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700399 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100400 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700401 }
402 }
403 }
404 break;
405 case PIN_REQUIRED:
406 case PUK_REQUIRED:
407 synchronized (this) {
Jim Millerab954542014-10-10 18:21:49 -0700408 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800409 if (DEBUG_SIM_STATES) Log.d(TAG,
410 "INTENT_VALUE_ICC_LOCKED and keygaurd isn't "
Jim Millerbbf1a742012-07-17 18:30:30 -0700411 + "showing; need to show keyguard so user can enter sim pin");
Jim Miller5ecd8112013-01-09 18:50:26 -0800412 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700413 } else {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100414 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700415 }
416 }
417 break;
418 case PERM_DISABLED:
419 synchronized (this) {
Jim Millerab954542014-10-10 18:21:49 -0700420 if (!mShowing) {
Jim Miller52a61332014-11-12 19:29:51 -0800421 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED and "
Jim Millerbbf1a742012-07-17 18:30:30 -0700422 + "keygaurd isn't showing.");
Jim Miller5ecd8112013-01-09 18:50:26 -0800423 doKeyguardLocked(null);
Jim Millerbbf1a742012-07-17 18:30:30 -0700424 } else {
Jim Miller52a61332014-11-12 19:29:51 -0800425 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED, resetStateLocked to"
Jim Millerbbf1a742012-07-17 18:30:30 -0700426 + "show permanently disabled message in lockscreen.");
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100427 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700428 }
429 }
430 break;
431 case READY:
432 synchronized (this) {
Jim Millerab954542014-10-10 18:21:49 -0700433 if (mShowing) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100434 resetStateLocked();
Jim Millerbbf1a742012-07-17 18:30:30 -0700435 }
436 }
437 break;
Jim Miller52a61332014-11-12 19:29:51 -0800438 default:
439 if (DEBUG_SIM_STATES) Log.v(TAG, "Ignoring state: " + simState);
440 break;
Jim Millerbbf1a742012-07-17 18:30:30 -0700441 }
442 }
443
Jim Miller9f0753f2015-03-23 23:59:22 -0700444 @Override
445 public void onFingerprintAuthenticated(int userId) {
Jim Millerf41fc962014-06-18 16:33:51 -0700446 if (mStatusBarKeyguardViewManager.isBouncerShowing()) {
447 mViewMediatorCallback.keyguardDone(true);
Jim Miller25d7e512015-03-03 17:12:09 -0800448 } else {
Jorim Jaggif3b3bee2015-04-16 14:57:34 -0700449 mStatusBarKeyguardViewManager.animateCollapsePanels(
450 FINGERPRINT_COLLAPSE_SPEEDUP_FACTOR);
Jim Millerf41fc962014-06-18 16:33:51 -0700451 }
452 };
453
Jim Millerb0304762012-03-13 20:01:25 -0700454 };
455
Jim Millerdcb3d842012-08-23 19:18:12 -0700456 ViewMediatorCallback mViewMediatorCallback = new ViewMediatorCallback() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100457
Jeff Brownc7505bc2012-10-05 21:58:15 -0700458 public void userActivity() {
459 KeyguardViewMediator.this.userActivity();
460 }
461
Jim Millerdcb3d842012-08-23 19:18:12 -0700462 public void keyguardDone(boolean authenticated) {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +0100463 if (!mKeyguardDonePending) {
464 KeyguardViewMediator.this.keyguardDone(authenticated, true);
465 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700466 }
467
468 public void keyguardDoneDrawing() {
469 mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING);
470 }
471
472 @Override
473 public void setNeedsInput(boolean needsInput) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100474 mStatusBarKeyguardViewManager.setNeedsInput(needsInput);
Jim Millerdcb3d842012-08-23 19:18:12 -0700475 }
Jeff Brownc7505bc2012-10-05 21:58:15 -0700476
477 @Override
John Spurlock34c4fe52012-11-07 10:12:29 -0500478 public void keyguardDonePending() {
479 mKeyguardDonePending = true;
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200480 mHideAnimationRun = true;
481 mStatusBarKeyguardViewManager.startPreHideAnimation(null /* finishRunnable */);
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100482 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_PENDING_TIMEOUT,
483 KEYGUARD_DONE_PENDING_TIMEOUT_MS);
John Spurlock34c4fe52012-11-07 10:12:29 -0500484 }
Jim Miller0b9d8ac2013-11-07 19:15:49 -0800485
486 @Override
487 public void keyguardGone() {
488 mKeyguardDisplayManager.hide();
489 }
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200490
491 @Override
492 public void readyForKeyguardDone() {
493 if (mKeyguardDonePending) {
494 // Somebody has called keyguardDonePending before, which means that we are
495 // authenticated
496 KeyguardViewMediator.this.keyguardDone(true /* authenticated */, true /* wakeUp */);
497 }
498 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200499
500 @Override
Andrew Lee72b46d42015-01-30 13:23:21 -0800501 public void resetKeyguard() {
502 resetStateLocked();
503 }
504
505 @Override
Adrian Roos49e057d2014-08-13 17:14:51 +0200506 public void playTrustedSound() {
507 KeyguardViewMediator.this.playTrustedSound();
508 }
Jim Millerab954542014-10-10 18:21:49 -0700509
510 @Override
511 public boolean isInputRestricted() {
512 return KeyguardViewMediator.this.isInputRestricted();
513 }
Adrian Roos94e15a52015-04-16 12:23:18 -0700514
515 @Override
516 public boolean isScreenOn() {
517 return mScreenOn;
518 }
Jim Millerdcb3d842012-08-23 19:18:12 -0700519 };
520
Jorim Jaggib690f0d2014-07-03 23:25:44 +0200521 public void userActivity() {
Jeff Brown3dc524b2012-09-30 19:49:11 -0700522 mPM.userActivity(SystemClock.uptimeMillis(), false);
Jim Millerdcb3d842012-08-23 19:18:12 -0700523 }
524
Jim Millerab954542014-10-10 18:21:49 -0700525 private void setupLocked() {
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200526 mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
Jorim Jaggi0d674622014-05-21 01:34:15 +0200527 mWM = WindowManagerGlobal.getWindowManagerService();
Adrian Roos481a6df2014-11-20 19:48:56 +0100528 mTrustManager = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE);
529
Mike Lockwood674d3e42009-10-06 09:28:54 -0400530 mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
531 mShowKeyguardWakeLock.setReferenceCounted(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800532
Jim Millerbbf1a742012-07-17 18:30:30 -0700533 mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(DELAYED_KEYGUARD_ACTION));
534
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200535 mKeyguardDisplayManager = new KeyguardDisplayManager(mContext);
Jim Miller31921482013-11-06 20:43:55 -0800536
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200537 mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800538
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200539 mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800540
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200541 mLockPatternUtils = new LockPatternUtils(mContext);
Adrian Roosb60d47c2014-09-08 19:23:00 +0200542 mLockPatternUtils.setCurrentUser(ActivityManager.getCurrentUser());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800543
Jim Millere5f17ab2013-11-13 15:40:48 -0800544 // Assume keyguard is showing (unless it's disabled) until we know for sure...
Jim Millerab954542014-10-10 18:21:49 -0700545 setShowingLocked(!shouldWaitForProvisioning() && !mLockPatternUtils.isLockScreenDisabled());
Adrian Roos481a6df2014-11-20 19:48:56 +0100546 mTrustManager.reportKeyguardShowingChanged();
Jim Millere5f17ab2013-11-13 15:40:48 -0800547
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200548 mStatusBarKeyguardViewManager = new StatusBarKeyguardViewManager(mContext,
549 mViewMediatorCallback, mLockPatternUtils);
Daniel Sandler687a3272010-03-13 15:44:47 -0500550 final ContentResolver cr = mContext.getContentResolver();
Marco Nelissend5545bd2011-09-29 12:49:17 -0700551
Daniel Hansson4b716862012-03-29 11:02:05 +0200552 mScreenOn = mPM.isScreenOn();
553
Marco Nelissend5545bd2011-09-29 12:49:17 -0700554 mLockSounds = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
Jim Millerb14288d2012-09-30 18:25:05 -0700555 String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700556 if (soundPath != null) {
557 mLockSoundId = mLockSounds.load(soundPath, 1);
558 }
559 if (soundPath == null || mLockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700560 Log.w(TAG, "failed to load lock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700561 }
Jim Millerb14288d2012-09-30 18:25:05 -0700562 soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700563 if (soundPath != null) {
564 mUnlockSoundId = mLockSounds.load(soundPath, 1);
565 }
566 if (soundPath == null || mUnlockSoundId == 0) {
Jim Millerb14288d2012-09-30 18:25:05 -0700567 Log.w(TAG, "failed to load unlock sound from " + soundPath);
Marco Nelissend5545bd2011-09-29 12:49:17 -0700568 }
Adrian Roos49e057d2014-08-13 17:14:51 +0200569 soundPath = Settings.Global.getString(cr, Settings.Global.TRUSTED_SOUND);
570 if (soundPath != null) {
571 mTrustedSoundId = mLockSounds.load(soundPath, 1);
572 }
573 if (soundPath == null || mTrustedSoundId == 0) {
574 Log.w(TAG, "failed to load trusted sound from " + soundPath);
575 }
576
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200577 int lockSoundDefaultAttenuation = mContext.getResources().getInteger(
Jean-Michel Trivic55b3932012-06-05 11:57:59 -0700578 com.android.internal.R.integer.config_lockSoundVolumeDb);
Jean-Michel Trivif2b0c112012-07-09 11:59:11 -0700579 mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20);
Adrian Roos0002a452014-07-03 13:46:07 +0200580
581 mHideAnimation = AnimationUtils.loadAnimation(mContext,
582 com.android.internal.R.anim.lock_screen_behind_enter);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800583 }
584
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200585 @Override
586 public void start() {
Jim Millerab954542014-10-10 18:21:49 -0700587 synchronized (this) {
588 setupLocked();
589 }
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200590 putComponent(KeyguardViewMediator.class, this);
591 }
592
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800593 /**
594 * Let us know that the system is ready after startup.
595 */
596 public void onSystemReady() {
John Spurlock43d84512012-11-09 10:27:33 -0500597 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800598 synchronized (this) {
599 if (DEBUG) Log.d(TAG, "onSystemReady");
600 mSystemReady = true;
Jim Millerbbf1a742012-07-17 18:30:30 -0700601 mUpdateMonitor.registerCallback(mUpdateCallback);
Jim Miller08697702012-10-22 16:49:52 -0700602
Jim Miller5ecd8112013-01-09 18:50:26 -0800603 doKeyguardLocked(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800604 }
Jim Miller3fd47af2012-09-21 19:55:27 -0700605 // Most services aren't available until the system reaches the ready state, so we
606 // send it here when the device first boots.
607 maybeSendUserPresentBroadcast();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800608 }
609
610 /**
611 * Called to let us know the screen was turned off.
Jeff Brownfb0448a2014-05-01 18:19:31 -0700612 * @param why either {@link android.view.WindowManagerPolicy#OFF_BECAUSE_OF_USER} or
613 * {@link android.view.WindowManagerPolicy#OFF_BECAUSE_OF_TIMEOUT}.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800614 */
615 public void onScreenTurnedOff(int why) {
616 synchronized (this) {
Karl Rosaenab100082009-03-24 22:35:17 -0700617 mScreenOn = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800618 if (DEBUG) Log.d(TAG, "onScreenTurnedOff(" + why + ")");
619
Jorim Jaggif8d77da2014-11-11 16:59:12 +0100620 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +0200621 mHideAnimationRun = false;
John Spurlock14adfe42012-11-08 10:29:26 -0500622
Jim Millera4edd152012-01-06 18:24:04 -0800623 // Lock immediately based on setting if secure (user has a pin/pattern/password).
624 // This also "locks" the device when not secure to provide easy access to the
625 // camera while preventing unwanted input.
626 final boolean lockImmediately =
627 mLockPatternUtils.getPowerButtonInstantlyLocks() || !mLockPatternUtils.isSecure();
628
Selim Cinek7ff6eb62014-09-03 14:18:09 +0200629 notifyScreenOffLocked();
630
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800631 if (mExitSecureCallback != null) {
632 if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled");
Jim Miller5ecd8112013-01-09 18:50:26 -0800633 try {
634 mExitSecureCallback.onKeyguardExitResult(false);
635 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800636 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800637 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800638 mExitSecureCallback = null;
639 if (!mExternallyEnabled) {
Jim Miller9c20d0e2010-01-20 15:00:23 -0800640 hideLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800641 }
642 } else if (mShowing) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100643 resetStateLocked();
Jim Millera4edd152012-01-06 18:24:04 -0800644 } else if (why == WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT
645 || (why == WindowManagerPolicy.OFF_BECAUSE_OF_USER && !lockImmediately)) {
Jeff Brown6aaf2952012-10-05 16:01:08 -0700646 doKeyguardLaterLocked();
Mike Lockwood016e3972009-09-17 11:45:06 -0400647 } else {
Jim Miller5ecd8112013-01-09 18:50:26 -0800648 doKeyguardLocked(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800649 }
650 }
John Spurlock36a13422015-03-24 21:15:48 -0400651 KeyguardUpdateMonitor.getInstance(mContext).dispatchScreenTurnedOff(why);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800652 }
653
Jeff Brown6aaf2952012-10-05 16:01:08 -0700654 private void doKeyguardLaterLocked() {
655 // if the screen turned off because of timeout or the user hit the power button
656 // and we don't need to lock immediately, set an alarm
657 // to enable it a little bit later (i.e, give the user a chance
658 // to turn the screen back on within a certain window without
659 // having to unlock the screen)
660 final ContentResolver cr = mContext.getContentResolver();
661
662 // From DisplaySettings
663 long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT,
664 KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT);
665
666 // From SecuritySettings
667 final long lockAfterTimeout = Settings.Secure.getInt(cr,
668 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT,
669 KEYGUARD_LOCK_AFTER_DELAY_DEFAULT);
670
671 // From DevicePolicyAdmin
672 final long policyTimeout = mLockPatternUtils.getDevicePolicyManager()
673 .getMaximumTimeToLock(null, mLockPatternUtils.getCurrentUser());
674
675 long timeout;
676 if (policyTimeout > 0) {
677 // policy in effect. Make sure we don't go beyond policy limit.
678 displayTimeout = Math.max(displayTimeout, 0); // ignore negative values
679 timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout);
680 } else {
681 timeout = lockAfterTimeout;
682 }
683
684 if (timeout <= 0) {
685 // Lock now
686 mSuppressNextLockSound = true;
Jim Miller5ecd8112013-01-09 18:50:26 -0800687 doKeyguardLocked(null);
Jeff Brown6aaf2952012-10-05 16:01:08 -0700688 } else {
689 // Lock in the future
690 long when = SystemClock.elapsedRealtime() + timeout;
691 Intent intent = new Intent(DELAYED_KEYGUARD_ACTION);
692 intent.putExtra("seq", mDelayedShowingSequence);
693 PendingIntent sender = PendingIntent.getBroadcast(mContext,
694 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
695 mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender);
696 if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = "
697 + mDelayedShowingSequence);
698 }
699 }
700
701 private void cancelDoKeyguardLaterLocked() {
702 mDelayedShowingSequence++;
703 }
704
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800705 /**
706 * Let's us know the screen was turned on.
707 */
Jim Miller25190572013-02-28 17:36:24 -0800708 public void onScreenTurnedOn(IKeyguardShowCallback callback) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800709 synchronized (this) {
Karl Rosaenab100082009-03-24 22:35:17 -0700710 mScreenOn = true;
Jeff Brown6aaf2952012-10-05 16:01:08 -0700711 cancelDoKeyguardLaterLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800712 if (DEBUG) Log.d(TAG, "onScreenTurnedOn, seq = " + mDelayedShowingSequence);
Jim Miller25190572013-02-28 17:36:24 -0800713 if (callback != null) {
714 notifyScreenOnLocked(callback);
Jim Millerd6523da2012-10-21 16:47:02 -0700715 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800716 }
Jim Miller20daffd2013-10-07 14:59:53 -0700717 KeyguardUpdateMonitor.getInstance(mContext).dispatchScreenTurnedOn();
Jim Miller3fd47af2012-09-21 19:55:27 -0700718 maybeSendUserPresentBroadcast();
719 }
720
721 private void maybeSendUserPresentBroadcast() {
Adam Lesinski61d94092014-09-15 15:27:19 -0700722 if (mSystemReady && mLockPatternUtils.isLockScreenDisabled()) {
Jim Miller3fd47af2012-09-21 19:55:27 -0700723 // Lock screen is disabled because the user has set the preference to "None".
724 // In this case, send out ACTION_USER_PRESENT here instead of in
725 // handleKeyguardDone()
726 sendUserPresentBroadcast();
727 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800728 }
729
730 /**
Jeff Brown6aaf2952012-10-05 16:01:08 -0700731 * A dream started. We should lock after the usual screen-off lock timeout but only
732 * if there is a secure lock pattern.
733 */
734 public void onDreamingStarted() {
735 synchronized (this) {
736 if (mScreenOn && mLockPatternUtils.isSecure()) {
737 doKeyguardLaterLocked();
738 }
739 }
740 }
741
742 /**
743 * A dream stopped.
744 */
745 public void onDreamingStopped() {
746 synchronized (this) {
747 if (mScreenOn) {
748 cancelDoKeyguardLaterLocked();
749 }
750 }
751 }
752
753 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100754 * Same semantics as {@link android.view.WindowManagerPolicy#enableKeyguard}; provide
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800755 * a way for external stuff to override normal keyguard behavior. For instance
756 * the phone app disables the keyguard when it receives incoming calls.
757 */
758 public void setKeyguardEnabled(boolean enabled) {
759 synchronized (this) {
760 if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")");
761
longyu.huang261ec762015-03-22 21:14:58 -0700762 if (isSecure()) {
763 Log.d(TAG, "current mode is SecurityMode, ignore hide keyguard");
764 return;
765 }
766
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800767 mExternallyEnabled = enabled;
768
769 if (!enabled && mShowing) {
770 if (mExitSecureCallback != null) {
771 if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring");
772 // we're in the process of handling a request to verify the user
773 // can get past the keyguard. ignore extraneous requests to disable / reenable
774 return;
775 }
776
777 // hiding keyguard that is showing, remember to reshow later
778 if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, "
779 + "disabling status bar expansion");
780 mNeedToReshowWhenReenabled = true;
Jim Millerab954542014-10-10 18:21:49 -0700781 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800782 hideLocked();
783 } else if (enabled && mNeedToReshowWhenReenabled) {
784 // reenabled after previously hidden, reshow
785 if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling "
786 + "status bar expansion");
787 mNeedToReshowWhenReenabled = false;
Jim Millerab954542014-10-10 18:21:49 -0700788 updateInputRestrictedLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800789
790 if (mExitSecureCallback != null) {
791 if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting");
Jim Miller5ecd8112013-01-09 18:50:26 -0800792 try {
793 mExitSecureCallback.onKeyguardExitResult(false);
794 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800795 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800796 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800797 mExitSecureCallback = null;
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100798 resetStateLocked();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800799 } else {
Adam Cohenf7522022012-10-03 20:03:18 -0700800 showLocked(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800801
802 // block until we know the keygaurd is done drawing (and post a message
803 // to unblock us after a timeout so we don't risk blocking too long
804 // and causing an ANR).
805 mWaitingUntilKeyguardVisible = true;
806 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS);
807 if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false");
808 while (mWaitingUntilKeyguardVisible) {
809 try {
810 wait();
811 } catch (InterruptedException e) {
812 Thread.currentThread().interrupt();
813 }
814 }
815 if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible");
816 }
817 }
818 }
819 }
820
821 /**
822 * @see android.app.KeyguardManager#exitKeyguardSecurely
823 */
Jim Miller25190572013-02-28 17:36:24 -0800824 public void verifyUnlock(IKeyguardExitCallback callback) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800825 synchronized (this) {
826 if (DEBUG) Log.d(TAG, "verifyUnlock");
Jim Millerb256e4e22014-10-31 17:27:13 -0700827 if (shouldWaitForProvisioning()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800828 // don't allow this api when the device isn't provisioned
829 if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned");
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 }
Mike Lockwood5d258b62009-12-02 13:50:45 -0500835 } else if (mExternallyEnabled) {
836 // this only applies when the user has externally disabled the
837 // keyguard. this is unexpected and means the user is not
838 // using the api properly.
839 Log.w(TAG, "verifyUnlock called when not externally disabled");
Jim Miller5ecd8112013-01-09 18:50:26 -0800840 try {
Jim Miller25190572013-02-28 17:36:24 -0800841 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -0800842 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800843 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800844 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800845 } else if (mExitSecureCallback != null) {
846 // already in progress with someone else
Jim Miller5ecd8112013-01-09 18:50:26 -0800847 try {
Jim Miller25190572013-02-28 17:36:24 -0800848 callback.onKeyguardExitResult(false);
Jim Miller5ecd8112013-01-09 18:50:26 -0800849 } catch (RemoteException e) {
Jim Miller25190572013-02-28 17:36:24 -0800850 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
Jim Miller5ecd8112013-01-09 18:50:26 -0800851 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800852 } else {
Jim Miller25190572013-02-28 17:36:24 -0800853 mExitSecureCallback = callback;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800854 verifyUnlockLocked();
855 }
856 }
857 }
858
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800859 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100860 * Is the keyguard currently showing and not being force hidden?
Mike Lockwood09a40402009-11-08 00:33:23 -0500861 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100862 public boolean isShowingAndNotOccluded() {
863 return mShowing && !mOccluded;
864 }
865
866 /**
867 * Notify us when the keyguard is occluded by another window
868 */
869 public void setOccluded(boolean isOccluded) {
870 if (DEBUG) Log.d(TAG, "setOccluded " + isOccluded);
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100871 mHandler.removeMessages(SET_OCCLUDED);
872 Message msg = mHandler.obtainMessage(SET_OCCLUDED, (isOccluded ? 1 : 0), 0);
Mike Lockwood9200a392009-11-17 20:25:58 -0500873 mHandler.sendMessage(msg);
874 }
875
876 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100877 * Handles SET_OCCLUDED message sent by setOccluded()
Mike Lockwood9200a392009-11-17 20:25:58 -0500878 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100879 private void handleSetOccluded(boolean isOccluded) {
Mike Lockwood09a40402009-11-08 00:33:23 -0500880 synchronized (KeyguardViewMediator.this) {
Adrian Roosf253eeb2015-04-15 18:03:08 -0700881 if (mHiding && isOccluded) {
882 // We're in the process of going away but WindowManager wants to show a
883 // SHOW_WHEN_LOCKED activity instead.
884 startKeyguardExitAnimation(0, 0);
885 }
886
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100887 if (mOccluded != isOccluded) {
888 mOccluded = isOccluded;
889 mStatusBarKeyguardViewManager.setOccluded(isOccluded);
Dianne Hackbornff5b1582012-04-12 17:24:07 -0700890 updateActivityLockScreenState();
Mike Lockwood5f892c12009-11-19 23:39:13 -0500891 adjustStatusBarLocked();
Mike Lockwood9200a392009-11-17 20:25:58 -0500892 }
Mike Lockwood09a40402009-11-08 00:33:23 -0500893 }
894 }
895
896 /**
Mike Lockwood28569302010-01-28 11:54:40 -0500897 * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout.
898 * This must be safe to call from any thread and with any window manager locks held.
899 */
Adam Cohenf7522022012-10-03 20:03:18 -0700900 public void doKeyguardTimeout(Bundle options) {
Mike Lockwood28569302010-01-28 11:54:40 -0500901 mHandler.removeMessages(KEYGUARD_TIMEOUT);
Adam Cohenf7522022012-10-03 20:03:18 -0700902 Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options);
Mike Lockwood28569302010-01-28 11:54:40 -0500903 mHandler.sendMessage(msg);
904 }
905
906 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800907 * Given the state of the keyguard, is the input restricted?
908 * Input is restricted when the keyguard is showing, or when the keyguard
909 * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet.
910 */
911 public boolean isInputRestricted() {
Jim Millerb256e4e22014-10-31 17:27:13 -0700912 return mShowing || mNeedToReshowWhenReenabled || shouldWaitForProvisioning();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800913 }
914
Jim Millerab954542014-10-10 18:21:49 -0700915 private void updateInputRestricted() {
916 synchronized (this) {
917 updateInputRestrictedLocked();
918 }
919 }
920 private void updateInputRestrictedLocked() {
921 boolean inputRestricted = isInputRestricted();
922 if (mInputRestricted != inputRestricted) {
923 mInputRestricted = inputRestricted;
924 try {
925 int size = mKeyguardStateCallbacks.size();
926 for (int i = 0; i < size; i++) {
927 mKeyguardStateCallbacks.get(i).onInputRestrictedStateChanged(inputRestricted);
928 }
929 } catch (RemoteException e) {
930 Slog.w(TAG, "Failed to call onDeviceProvisioned", e);
931 }
932 }
933 }
934
Dianne Hackbornb446e972009-09-20 15:23:25 -0700935 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700936 * Enable the keyguard if the settings are appropriate.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800937 */
Adam Cohenf7522022012-10-03 20:03:18 -0700938 private void doKeyguardLocked(Bundle options) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700939 // if another app is disabling us, don't show
940 if (!mExternallyEnabled) {
941 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled");
Karl Rosaenab100082009-03-24 22:35:17 -0700942
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700943 // note: we *should* set mNeedToReshowWhenReenabled=true here, but that makes
944 // for an occasional ugly flicker in this situation:
945 // 1) receive a call with the screen on (no keyguard) or make a call
946 // 2) screen times out
947 // 3) user hits key to turn screen back on
948 // instead, we reenable the keyguard when we know the screen is off and the call
949 // ends (see the broadcast receiver below)
950 // TODO: clean this up when we have better support at the window manager level
951 // for apps that wish to be on top of the keyguard
Dianne Hackborn38e29a62011-09-18 14:43:08 -0700952 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800953 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700954
955 // if the keyguard is already showing, don't bother
Jorim Jaggi5cf17872014-03-26 18:31:48 +0100956 if (mStatusBarKeyguardViewManager.isShowing()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700957 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing");
Jorim Jaggi95e89ca2014-11-24 20:12:50 +0100958 resetStateLocked();
Dianne Hackborn38e29a62011-09-18 14:43:08 -0700959 return;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700960 }
961
962 // if the setup wizard hasn't run yet, don't show
Jim Miller52a61332014-11-12 19:29:51 -0800963 final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", false);
Wink Savillea54bf652014-12-11 13:37:50 -0800964 final boolean absent = SubscriptionManager.isValidSubscriptionId(
965 mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.ABSENT));
966 final boolean disabled = SubscriptionManager.isValidSubscriptionId(
967 mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.PERM_DISABLED));
Jim Miller52a61332014-11-12 19:29:51 -0800968 final boolean lockedOrMissing = mUpdateMonitor.isSimPinSecure()
969 || ((absent || disabled) && requireSim);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700970
Jim Millerb256e4e22014-10-31 17:27:13 -0700971 if (!lockedOrMissing && shouldWaitForProvisioning()) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700972 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned"
973 + " and the sim is not locked or missing");
Dianne Hackborn38e29a62011-09-18 14:43:08 -0700974 return;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700975 }
976
Jorim Jaggid0b698f2014-07-02 16:46:27 +0200977 if (mLockPatternUtils.isLockScreenDisabled() && !lockedOrMissing) {
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700978 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off");
Dianne Hackborn38e29a62011-09-18 14:43:08 -0700979 return;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700980 }
981
Paul Lawrence945490c2014-03-27 16:37:28 +0000982 if (mLockPatternUtils.checkVoldPassword()) {
983 if (DEBUG) Log.d(TAG, "Not showing lock screen since just decrypted");
984 // Without this, settings is not enabled until the lock screen first appears
Jim Millerab954542014-10-10 18:21:49 -0700985 setShowingLocked(false);
Paul Lawrence945490c2014-03-27 16:37:28 +0000986 hideLocked();
987 return;
988 }
989
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700990 if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");
Adam Cohenf7522022012-10-03 20:03:18 -0700991 showLocked(options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800992 }
993
Jim Millerb256e4e22014-10-31 17:27:13 -0700994 private boolean shouldWaitForProvisioning() {
995 return !mUpdateMonitor.isDeviceProvisioned() && !isSecure();
996 }
997
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800998 /**
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700999 * Dismiss the keyguard through the security layers.
1000 */
Jim Miller60013792013-10-03 18:31:34 -07001001 public void handleDismiss() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001002 if (mShowing && !mOccluded) {
1003 mStatusBarKeyguardViewManager.dismiss();
Jim Miller87d03662012-11-05 20:28:09 -08001004 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001005 }
1006
Jim Miller60013792013-10-03 18:31:34 -07001007 public void dismiss() {
1008 mHandler.sendEmptyMessage(DISMISS);
1009 }
1010
Craig Mautnerad09bcc2012-10-08 13:33:11 -07001011 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001012 * Send message to keyguard telling it to reset its state.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001013 * @see #handleReset
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001014 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001015 private void resetStateLocked() {
Jim Miller4894a012013-04-03 15:23:55 -07001016 if (DEBUG) Log.e(TAG, "resetStateLocked");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001017 Message msg = mHandler.obtainMessage(RESET);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001018 mHandler.sendMessage(msg);
1019 }
1020
1021 /**
1022 * Send message to keyguard telling it to verify unlock
1023 * @see #handleVerifyUnlock()
1024 */
1025 private void verifyUnlockLocked() {
1026 if (DEBUG) Log.d(TAG, "verifyUnlockLocked");
1027 mHandler.sendEmptyMessage(VERIFY_UNLOCK);
1028 }
1029
1030
1031 /**
1032 * Send a message to keyguard telling it the screen just turned on.
1033 * @see #onScreenTurnedOff(int)
1034 * @see #handleNotifyScreenOff
1035 */
1036 private void notifyScreenOffLocked() {
1037 if (DEBUG) Log.d(TAG, "notifyScreenOffLocked");
1038 mHandler.sendEmptyMessage(NOTIFY_SCREEN_OFF);
1039 }
1040
1041 /**
1042 * Send a message to keyguard telling it the screen just turned on.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001043 * @see #onScreenTurnedOn
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001044 * @see #handleNotifyScreenOn
1045 */
Jim Miller25190572013-02-28 17:36:24 -08001046 private void notifyScreenOnLocked(IKeyguardShowCallback result) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001047 if (DEBUG) Log.d(TAG, "notifyScreenOnLocked");
Jim Miller5ecd8112013-01-09 18:50:26 -08001048 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_ON, result);
Dianne Hackborn38e29a62011-09-18 14:43:08 -07001049 mHandler.sendMessage(msg);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001050 }
1051
1052 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001053 * Send message to keyguard telling it to show itself
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001054 * @see #handleShow
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001055 */
Adam Cohenf7522022012-10-03 20:03:18 -07001056 private void showLocked(Bundle options) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001057 if (DEBUG) Log.d(TAG, "showLocked");
Mike Lockwood674d3e42009-10-06 09:28:54 -04001058 // ensure we stay awake until we are finished displaying the keyguard
1059 mShowKeyguardWakeLock.acquire();
Adam Cohenf7522022012-10-03 20:03:18 -07001060 Message msg = mHandler.obtainMessage(SHOW, options);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001061 mHandler.sendMessage(msg);
1062 }
1063
1064 /**
1065 * Send message to keyguard telling it to hide itself
Jim Miller9c20d0e2010-01-20 15:00:23 -08001066 * @see #handleHide()
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001067 */
1068 private void hideLocked() {
1069 if (DEBUG) Log.d(TAG, "hideLocked");
1070 Message msg = mHandler.obtainMessage(HIDE);
1071 mHandler.sendMessage(msg);
1072 }
1073
Dianne Hackbornb446e972009-09-20 15:23:25 -07001074 public boolean isSecure() {
Jim Millerdcb3d842012-08-23 19:18:12 -07001075 return mLockPatternUtils.isSecure()
1076 || KeyguardUpdateMonitor.getInstance(mContext).isSimPinSecure();
Dianne Hackbornb446e972009-09-20 15:23:25 -07001077 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001078
Craig Mautnerf1b67412012-09-19 13:18:29 -07001079 /**
1080 * Update the newUserId. Call while holding WindowManagerService lock.
Jim Milleree82f8f2012-10-01 16:26:18 -07001081 * NOTE: Should only be called by KeyguardViewMediator in response to the user id changing.
1082 *
Craig Mautnerf1b67412012-09-19 13:18:29 -07001083 * @param newUserId The id of the incoming user.
1084 */
1085 public void setCurrentUser(int newUserId) {
1086 mLockPatternUtils.setCurrentUser(newUserId);
1087 }
1088
Jim Millerbbf1a742012-07-17 18:30:30 -07001089 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
Amith Yamasani52c489c2012-03-28 11:42:42 -07001090 @Override
1091 public void onReceive(Context context, Intent intent) {
Jim Millerbbf1a742012-07-17 18:30:30 -07001092 if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
1093 final int sequence = intent.getIntExtra("seq", 0);
Jim Millerf3447352011-08-07 14:00:09 -07001094 if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = "
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001095 + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001096 synchronized (KeyguardViewMediator.this) {
1097 if (mDelayedShowingSequence == sequence) {
Jim Millerbbf1a742012-07-17 18:30:30 -07001098 // Don't play lockscreen SFX if the screen went off due to timeout.
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001099 mSuppressNextLockSound = true;
Jim Miller5ecd8112013-01-09 18:50:26 -08001100 doKeyguardLocked(null);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001101 }
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001102 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001103 }
1104 }
1105 };
1106
Dianne Hackborn05726582009-09-22 17:28:24 -07001107 public void keyguardDone(boolean authenticated, boolean wakeup) {
Jim Miller60013792013-10-03 18:31:34 -07001108 if (DEBUG) Log.d(TAG, "keyguardDone(" + authenticated + ")");
1109 EventLog.writeEvent(70000, 2);
Jim Miller60013792013-10-03 18:31:34 -07001110 Message msg = mHandler.obtainMessage(KEYGUARD_DONE, authenticated ? 1 : 0, wakeup ? 1 : 0);
1111 mHandler.sendMessage(msg);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001112 }
1113
1114 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001115 * This handler will be associated with the policy thread, which will also
1116 * be the UI thread of the keyguard. Since the apis of the policy, and therefore
1117 * this class, can be called by other threads, any action that directly
1118 * interacts with the keyguard ui should be posted to this handler, rather
1119 * than called directly.
1120 */
Jim Millerdcb3d842012-08-23 19:18:12 -07001121 private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001122 @Override
Wink Saville37c124c2009-04-02 01:37:02 -07001123 public void handleMessage(Message msg) {
1124 switch (msg.what) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001125 case SHOW:
Adam Cohenf7522022012-10-03 20:03:18 -07001126 handleShow((Bundle) msg.obj);
Jim Miller60013792013-10-03 18:31:34 -07001127 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001128 case HIDE:
1129 handleHide();
Jim Miller60013792013-10-03 18:31:34 -07001130 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001131 case RESET:
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001132 handleReset();
Jim Miller60013792013-10-03 18:31:34 -07001133 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001134 case VERIFY_UNLOCK:
1135 handleVerifyUnlock();
Jim Miller60013792013-10-03 18:31:34 -07001136 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001137 case NOTIFY_SCREEN_OFF:
1138 handleNotifyScreenOff();
Jim Miller60013792013-10-03 18:31:34 -07001139 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001140 case NOTIFY_SCREEN_ON:
Jim Miller25190572013-02-28 17:36:24 -08001141 handleNotifyScreenOn((IKeyguardShowCallback) msg.obj);
Jim Miller60013792013-10-03 18:31:34 -07001142 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001143 case KEYGUARD_DONE:
Jim Millere51cf7ae2013-06-25 18:31:56 -07001144 handleKeyguardDone(msg.arg1 != 0, msg.arg2 != 0);
Jim Miller60013792013-10-03 18:31:34 -07001145 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001146 case KEYGUARD_DONE_DRAWING:
1147 handleKeyguardDoneDrawing();
Jim Miller60013792013-10-03 18:31:34 -07001148 break;
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001149 case KEYGUARD_DONE_AUTHENTICATING:
Jim Millerdcb3d842012-08-23 19:18:12 -07001150 keyguardDone(true, true);
Jim Miller60013792013-10-03 18:31:34 -07001151 break;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001152 case SET_OCCLUDED:
1153 handleSetOccluded(msg.arg1 != 0);
Mike Lockwood9200a392009-11-17 20:25:58 -05001154 break;
Mike Lockwood28569302010-01-28 11:54:40 -05001155 case KEYGUARD_TIMEOUT:
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001156 synchronized (KeyguardViewMediator.this) {
Adam Cohenf7522022012-10-03 20:03:18 -07001157 doKeyguardLocked((Bundle) msg.obj);
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001158 }
1159 break;
Jim Miller60013792013-10-03 18:31:34 -07001160 case DISMISS:
1161 handleDismiss();
1162 break;
Jorim Jaggi0d674622014-05-21 01:34:15 +02001163 case START_KEYGUARD_EXIT_ANIM:
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001164 StartKeyguardExitAnimParams params = (StartKeyguardExitAnimParams) msg.obj;
1165 handleStartKeyguardExitAnimation(params.startTime, params.fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02001166 break;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001167 case KEYGUARD_DONE_PENDING_TIMEOUT:
1168 Log.w(TAG, "Timeout while waiting for activity drawn!");
1169 // Fall through.
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001170 case ON_ACTIVITY_DRAWN:
1171 handleOnActivityDrawn();
1172 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001173 }
1174 }
1175 };
1176
1177 /**
1178 * @see #keyguardDone
1179 * @see #KEYGUARD_DONE
1180 */
Jim Millere51cf7ae2013-06-25 18:31:56 -07001181 private void handleKeyguardDone(boolean authenticated, boolean wakeup) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001182 if (DEBUG) Log.d(TAG, "handleKeyguardDone");
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001183 synchronized (this) {
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001184 resetKeyguardDonePendingLocked();
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001185 }
Jim Millere51cf7ae2013-06-25 18:31:56 -07001186
1187 if (authenticated) {
1188 mUpdateMonitor.clearFailedUnlockAttempts();
Dianne Hackborn05726582009-09-22 17:28:24 -07001189 }
Jim Millerf41fc962014-06-18 16:33:51 -07001190 mUpdateMonitor.clearFingerprintRecognized();
Jeff Sharkey6a25cbd2012-08-23 12:14:26 -07001191
Jim Millere51cf7ae2013-06-25 18:31:56 -07001192 if (mExitSecureCallback != null) {
1193 try {
1194 mExitSecureCallback.onKeyguardExitResult(authenticated);
1195 } catch (RemoteException e) {
1196 Slog.w(TAG, "Failed to call onKeyguardExitResult(" + authenticated + ")", e);
1197 }
1198
1199 mExitSecureCallback = null;
1200
1201 if (authenticated) {
1202 // after succesfully exiting securely, no need to reshow
1203 // the keyguard when they've released the lock
1204 mExternallyEnabled = true;
1205 mNeedToReshowWhenReenabled = false;
Jim Millerab954542014-10-10 18:21:49 -07001206 updateInputRestricted();
Jim Millere51cf7ae2013-06-25 18:31:56 -07001207 }
1208 }
1209
1210 handleHide();
Jim Miller3fd47af2012-09-21 19:55:27 -07001211 }
1212
1213 private void sendUserPresentBroadcast() {
Jason Monkcf5a9532014-09-17 16:22:19 -04001214 synchronized (this) {
1215 if (mBootCompleted) {
1216 final UserHandle currentUser = new UserHandle(mLockPatternUtils.getCurrentUser());
Benjamin Franz4b9f8ed2014-12-01 16:51:48 +00001217 final UserManager um = (UserManager) mContext.getSystemService(
1218 Context.USER_SERVICE);
1219 List <UserInfo> userHandles = um.getProfiles(currentUser.getIdentifier());
1220 for (UserInfo ui : userHandles) {
1221 mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, ui.getUserHandle());
1222 }
Jason Monkcf5a9532014-09-17 16:22:19 -04001223 } else {
1224 mBootSendUserPresent = true;
1225 }
1226 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001227 }
1228
1229 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001230 * @see #keyguardDone
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001231 * @see #KEYGUARD_DONE_DRAWING
1232 */
1233 private void handleKeyguardDoneDrawing() {
1234 synchronized(this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001235 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001236 if (mWaitingUntilKeyguardVisible) {
1237 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible");
1238 mWaitingUntilKeyguardVisible = false;
1239 notifyAll();
1240
1241 // there will usually be two of these sent, one as a timeout, and one
1242 // as a result of the callback, so remove any remaining messages from
1243 // the queue
1244 mHandler.removeMessages(KEYGUARD_DONE_DRAWING);
1245 }
1246 }
1247 }
1248
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001249 private void playSounds(boolean locked) {
1250 // User feedback for keyguard.
Daniel Sandler0060a9b2010-03-15 23:09:57 -04001251
1252 if (mSuppressNextLockSound) {
1253 mSuppressNextLockSound = false;
1254 return;
1255 }
1256
Adrian Roos49e057d2014-08-13 17:14:51 +02001257 playSound(locked ? mLockSoundId : mUnlockSoundId);
1258 }
1259
1260 private void playSound(int soundId) {
1261 if (soundId == 0) return;
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001262 final ContentResolver cr = mContext.getContentResolver();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001263 if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) {
Adrian Roos49e057d2014-08-13 17:14:51 +02001264
Marco Nelissend5545bd2011-09-29 12:49:17 -07001265 mLockSounds.stop(mLockSoundStreamId);
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001266 // Init mAudioManager
1267 if (mAudioManager == null) {
1268 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
1269 if (mAudioManager == null) return;
John Spurlockee5ad722015-03-03 16:17:21 -05001270 mUiSoundsStreamType = mAudioManager.getUiSoundsStreamType();
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001271 }
1272 // If the stream is muted, don't play the sound
John Spurlockee5ad722015-03-03 16:17:21 -05001273 if (mAudioManager.isStreamMute(mUiSoundsStreamType)) return;
Amith Yamasani8cb751b2011-09-30 15:39:41 -07001274
Adrian Roos49e057d2014-08-13 17:14:51 +02001275 mLockSoundStreamId = mLockSounds.play(soundId,
Jean-Michel Trivic55b3932012-06-05 11:57:59 -07001276 mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/);
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001277 }
Jim Miller2a98a4c2010-11-19 18:49:26 -08001278 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001279
Adrian Roos49e057d2014-08-13 17:14:51 +02001280 private void playTrustedSound() {
1281 if (mSuppressNextLockSound) {
1282 return;
1283 }
1284 playSound(mTrustedSoundId);
1285 }
1286
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001287 private void updateActivityLockScreenState() {
1288 try {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001289 ActivityManagerNative.getDefault().setLockScreenShown(mShowing && !mOccluded);
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001290 } catch (RemoteException e) {
1291 }
1292 }
1293
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001294 /**
1295 * Handle message sent by {@link #showLocked}.
1296 * @see #SHOW
1297 */
Adam Cohenf7522022012-10-03 20:03:18 -07001298 private void handleShow(Bundle options) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001299 synchronized (KeyguardViewMediator.this) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001300 if (!mSystemReady) {
1301 if (DEBUG) Log.d(TAG, "ignoring handleShow because system is not ready.");
1302 return;
1303 } else {
1304 if (DEBUG) Log.d(TAG, "handleShow");
1305 }
Jim Miller9c20d0e2010-01-20 15:00:23 -08001306
Jim Millerab954542014-10-10 18:21:49 -07001307 setShowingLocked(true);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001308 mStatusBarKeyguardViewManager.show(options);
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001309 mHiding = false;
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001310 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001311 mHideAnimationRun = false;
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001312 updateActivityLockScreenState();
Mike Lockwood5f892c12009-11-19 23:39:13 -05001313 adjustStatusBarLocked();
Jeff Brown3dc524b2012-09-30 19:49:11 -07001314 userActivity();
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07001315
1316 // Do this at the end to not slow down display of the keyguard.
1317 playSounds(true);
1318
Mike Lockwood674d3e42009-10-06 09:28:54 -04001319 mShowKeyguardWakeLock.release();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001320 }
Jim Miller31921482013-11-06 20:43:55 -08001321 mKeyguardDisplayManager.show();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001322 }
1323
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001324 private final Runnable mKeyguardGoingAwayRunnable = new Runnable() {
1325 @Override
1326 public void run() {
1327 try {
Jorim Jaggi33ae80e2015-02-04 16:37:11 +01001328 mStatusBarKeyguardViewManager.keyguardGoingAway();
1329
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001330 // Don't actually hide the Keyguard at the moment, wait for window
1331 // manager until it tells us it's safe to do so with
1332 // startKeyguardExitAnimation.
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02001333 mWM.keyguardGoingAway(
1334 mStatusBarKeyguardViewManager.shouldDisableWindowAnimationsForUnlock(),
1335 mStatusBarKeyguardViewManager.isGoingToNotificationShade());
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001336 } catch (RemoteException e) {
1337 Log.e(TAG, "Error while calling WindowManager", e);
1338 }
1339 }
1340 };
1341
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001342 /**
1343 * Handle message sent by {@link #hideLocked()}
1344 * @see #HIDE
1345 */
1346 private void handleHide() {
1347 synchronized (KeyguardViewMediator.this) {
1348 if (DEBUG) Log.d(TAG, "handleHide");
Jorim Jaggib9d60792014-06-03 22:34:22 +02001349
Jorim Jaggi76a16232014-08-08 17:00:47 +02001350 mHiding = true;
1351 if (mShowing && !mOccluded) {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001352 if (!mHideAnimationRun) {
1353 mStatusBarKeyguardViewManager.startPreHideAnimation(mKeyguardGoingAwayRunnable);
1354 } else {
1355 mKeyguardGoingAwayRunnable.run();
1356 }
Jorim Jaggi76a16232014-08-08 17:00:47 +02001357 } else {
Jorim Jaggib9d60792014-06-03 22:34:22 +02001358
Jorim Jaggi76a16232014-08-08 17:00:47 +02001359 // Don't try to rely on WindowManager - if Keyguard wasn't showing, window
1360 // manager won't start the exit animation.
1361 handleStartKeyguardExitAnimation(
1362 SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(),
1363 mHideAnimation.getDuration());
Jorim Jaggi0d674622014-05-21 01:34:15 +02001364 }
1365 }
1366 }
1367
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001368 private void handleOnActivityDrawn() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001369 if (DEBUG) Log.d(TAG, "handleOnActivityDrawn: mKeyguardDonePending=" + mKeyguardDonePending);
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001370 if (mKeyguardDonePending) {
1371 mStatusBarKeyguardViewManager.onActivityDrawn();
1372 }
1373 }
1374
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001375 private void handleStartKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02001376 synchronized (KeyguardViewMediator.this) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001377
Jorim Jaggi53c68a42014-06-17 15:04:47 -07001378 if (!mHiding) {
1379 return;
1380 }
1381 mHiding = false;
1382
Daniel Sandlerf2d8e742010-02-22 13:09:48 -05001383 // only play "unlock" noises if not on a call (since the incall UI
1384 // disables the keyguard)
1385 if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) {
1386 playSounds(false);
1387 }
Daniel Sandlerdb783bd2010-02-11 15:27:37 -05001388
Jim Millerab954542014-10-10 18:21:49 -07001389 setShowingLocked(false);
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001390 mStatusBarKeyguardViewManager.hide(startTime, fadeoutDuration);
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001391 resetKeyguardDonePendingLocked();
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001392 mHideAnimationRun = false;
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001393 updateActivityLockScreenState();
Mike Lockwood5f892c12009-11-19 23:39:13 -05001394 adjustStatusBarLocked();
Jim Miller705004b2014-09-04 16:51:20 -07001395 sendUserPresentBroadcast();
Jim Millerce7eb6d2015-04-03 19:29:13 -07001396 maybeStopListeningForFingerprint();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001397 }
1398 }
1399
Jim Millerce7eb6d2015-04-03 19:29:13 -07001400 private void maybeStopListeningForFingerprint() {
1401 mUpdateMonitor.stopListeningForFingerprint();
1402 }
1403
Mike Lockwood5f892c12009-11-19 23:39:13 -05001404 private void adjustStatusBarLocked() {
1405 if (mStatusBarManager == null) {
1406 mStatusBarManager = (StatusBarManager)
1407 mContext.getSystemService(Context.STATUS_BAR_SERVICE);
1408 }
1409 if (mStatusBarManager == null) {
1410 Log.w(TAG, "Could not get status bar manager");
1411 } else {
Daniel Sandlerdba93562011-10-06 16:39:58 -04001412 // Disable aspects of the system/status/navigation bars that must not be re-enabled by
1413 // windows that appear on top, ever
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001414 int flags = StatusBarManager.DISABLE_NONE;
Mike Lockwoode3646dd2011-09-01 12:46:28 -04001415 if (mShowing) {
Jim Millere23ab8b2012-09-16 15:45:44 -07001416 // Permanently disable components not available when keyguard is enabled
1417 // (like recents). Temporary enable/disable (e.g. the "back" button) are
1418 // done in KeyguardHostView.
Daniel Sandlerdba93562011-10-06 16:39:58 -04001419 flags |= StatusBarManager.DISABLE_RECENT;
Jorim Jaggi118aece2014-08-25 15:25:38 +02001420 flags |= StatusBarManager.DISABLE_SEARCH;
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001421 }
Jorim Jaggia005f1b2014-04-16 19:06:10 +02001422 if (isShowingAndNotOccluded()) {
1423 flags |= StatusBarManager.DISABLE_HOME;
1424 }
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001425
1426 if (DEBUG) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001427 Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mOccluded=" + mOccluded
Jeff Sharkey4519a022011-09-07 23:24:53 -07001428 + " isSecure=" + isSecure() + " --> flags=0x" + Integer.toHexString(flags));
Jeff Sharkeyf52c70b2011-08-30 22:05:47 -07001429 }
1430
Jim Millerd6523da2012-10-21 16:47:02 -07001431 if (!(mContext instanceof Activity)) {
1432 mStatusBarManager.disable(flags);
1433 }
Mike Lockwood5f892c12009-11-19 23:39:13 -05001434 }
1435 }
1436
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001437 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001438 * Handle message sent by {@link #resetStateLocked}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001439 * @see #RESET
1440 */
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001441 private void handleReset() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001442 synchronized (KeyguardViewMediator.this) {
1443 if (DEBUG) Log.d(TAG, "handleReset");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001444 mStatusBarKeyguardViewManager.reset();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001445 }
1446 }
1447
1448 /**
1449 * Handle message sent by {@link #verifyUnlock}
Craig Mautner904732c2012-10-17 15:20:24 -07001450 * @see #VERIFY_UNLOCK
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001451 */
1452 private void handleVerifyUnlock() {
1453 synchronized (KeyguardViewMediator.this) {
1454 if (DEBUG) Log.d(TAG, "handleVerifyUnlock");
Jim Millerab954542014-10-10 18:21:49 -07001455 setShowingLocked(true);
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001456 mStatusBarKeyguardViewManager.verifyUnlock();
Dianne Hackbornff5b1582012-04-12 17:24:07 -07001457 updateActivityLockScreenState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001458 }
1459 }
1460
1461 /**
1462 * Handle message sent by {@link #notifyScreenOffLocked()}
1463 * @see #NOTIFY_SCREEN_OFF
1464 */
1465 private void handleNotifyScreenOff() {
1466 synchronized (KeyguardViewMediator.this) {
1467 if (DEBUG) Log.d(TAG, "handleNotifyScreenOff");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001468 mStatusBarKeyguardViewManager.onScreenTurnedOff();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001469 }
1470 }
1471
1472 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001473 * Handle message sent by {@link #notifyScreenOnLocked}
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001474 * @see #NOTIFY_SCREEN_ON
1475 */
Jim Miller25190572013-02-28 17:36:24 -08001476 private void handleNotifyScreenOn(IKeyguardShowCallback callback) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001477 synchronized (KeyguardViewMediator.this) {
1478 if (DEBUG) Log.d(TAG, "handleNotifyScreenOn");
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001479 mStatusBarKeyguardViewManager.onScreenTurnedOn(callback);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001480 }
1481 }
Jeff Sharkey054340d2011-09-01 22:28:03 -07001482
Jorim Jaggif8d77da2014-11-11 16:59:12 +01001483 private void resetKeyguardDonePendingLocked() {
1484 mKeyguardDonePending = false;
1485 mHandler.removeMessages(KEYGUARD_DONE_PENDING_TIMEOUT);
1486 }
1487
Jim Millere5f910a2013-10-16 18:15:46 -07001488 public void onBootCompleted() {
1489 mUpdateMonitor.dispatchBootCompleted();
Jason Monkcf5a9532014-09-17 16:22:19 -04001490 synchronized (this) {
1491 mBootCompleted = true;
1492 if (mBootSendUserPresent) {
1493 sendUserPresentBroadcast();
1494 }
1495 }
Jim Millere5f910a2013-10-16 18:15:46 -07001496 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001497
Jorim Jaggi03c701e2014-04-02 12:39:51 +02001498 public StatusBarKeyguardViewManager registerStatusBar(PhoneStatusBar phoneStatusBar,
Jorim Jaggiecc798e2014-05-26 18:14:37 +02001499 ViewGroup container, StatusBarWindowManager statusBarWindowManager,
1500 ScrimController scrimController) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001501 mStatusBarKeyguardViewManager.registerStatusBar(phoneStatusBar, container,
Jorim Jaggiecc798e2014-05-26 18:14:37 +02001502 statusBarWindowManager, scrimController);
Jorim Jaggi03c701e2014-04-02 12:39:51 +02001503 return mStatusBarKeyguardViewManager;
1504 }
1505
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001506 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
1507 Message msg = mHandler.obtainMessage(START_KEYGUARD_EXIT_ANIM,
1508 new StartKeyguardExitAnimParams(startTime, fadeoutDuration));
Jorim Jaggi0d674622014-05-21 01:34:15 +02001509 mHandler.sendMessage(msg);
1510 }
1511
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02001512 public void onActivityDrawn() {
1513 mHandler.sendEmptyMessage(ON_ACTIVITY_DRAWN);
1514 }
Jorim Jaggi03c701e2014-04-02 12:39:51 +02001515 public ViewMediatorCallback getViewMediatorCallback() {
1516 return mViewMediatorCallback;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01001517 }
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001518
1519 private static class StartKeyguardExitAnimParams {
1520
1521 long startTime;
1522 long fadeoutDuration;
1523
1524 private StartKeyguardExitAnimParams(long startTime, long fadeoutDuration) {
1525 this.startTime = startTime;
1526 this.fadeoutDuration = fadeoutDuration;
1527 }
1528 }
Adrian Roos481a6df2014-11-20 19:48:56 +01001529
Jim Millerab954542014-10-10 18:21:49 -07001530 private void setShowingLocked(boolean showing) {
1531 if (showing != mShowing) {
1532 mShowing = showing;
1533 try {
1534 int size = mKeyguardStateCallbacks.size();
1535 for (int i = 0; i < size; i++) {
1536 mKeyguardStateCallbacks.get(i).onShowingStateChanged(showing);
1537 }
1538 } catch (RemoteException e) {
1539 Slog.w(TAG, "Failed to call onShowingStateChanged", e);
1540 }
1541 updateInputRestrictedLocked();
Adrian Roos481a6df2014-11-20 19:48:56 +01001542 mTrustManager.reportKeyguardShowingChanged();
1543 }
1544 }
Jim Millerab954542014-10-10 18:21:49 -07001545
1546 public void addStateMonitorCallback(IKeyguardStateCallback callback) {
1547 synchronized (this) {
1548 mKeyguardStateCallbacks.add(callback);
1549 try {
1550 callback.onSimSecureStateChanged(mUpdateMonitor.isSimPinSecure());
1551 callback.onShowingStateChanged(mShowing);
1552 } catch (RemoteException e) {
1553 Slog.w(TAG, "Failed to call onShowingStateChanged or onSimSecureStateChanged", e);
1554 }
1555 }
1556 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001557}