2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
14 * limitations under the License
17 package com.android.systemui.keyguard;
19 import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
20 import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST;
21 import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW;
22 import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT;
24 import android.app.Activity;
25 import android.app.ActivityManager;
26 import android.app.ActivityManagerNative;
27 import android.app.AlarmManager;
28 import android.app.PendingIntent;
29 import android.app.SearchManager;
30 import android.app.StatusBarManager;
31 import android.app.trust.TrustManager;
32 import android.content.BroadcastReceiver;
33 import android.content.ContentResolver;
34 import android.content.Context;
35 import android.content.Intent;
36 import android.content.IntentFilter;
37 import android.content.pm.UserInfo;
38 import android.media.AudioManager;
39 import android.media.SoundPool;
40 import android.os.Bundle;
41 import android.os.DeadObjectException;
42 import android.os.Handler;
43 import android.os.Looper;
44 import android.os.Message;
45 import android.os.PowerManager;
46 import android.os.RemoteException;
47 import android.os.SystemClock;
48 import android.os.SystemProperties;
49 import android.os.Trace;
50 import android.os.UserHandle;
51 import android.os.UserManager;
52 import android.os.storage.StorageManager;
53 import android.provider.Settings;
54 import android.telephony.SubscriptionManager;
55 import android.telephony.TelephonyManager;
56 import android.util.EventLog;
57 import android.util.Log;
58 import android.util.Slog;
59 import android.view.IWindowManager;
60 import android.view.ViewGroup;
61 import android.view.WindowManagerGlobal;
62 import android.view.WindowManagerPolicy;
63 import android.view.animation.Animation;
64 import android.view.animation.AnimationUtils;
66 import com.android.internal.policy.IKeyguardDrawnCallback;
67 import com.android.internal.policy.IKeyguardExitCallback;
68 import com.android.internal.policy.IKeyguardStateCallback;
69 import com.android.internal.telephony.IccCardConstants;
70 import com.android.internal.widget.LockPatternUtils;
71 import com.android.keyguard.KeyguardConstants;
72 import com.android.keyguard.KeyguardDisplayManager;
73 import com.android.keyguard.KeyguardSecurityView;
74 import com.android.keyguard.KeyguardUpdateMonitor;
75 import com.android.keyguard.KeyguardUpdateMonitorCallback;
76 import com.android.keyguard.ViewMediatorCallback;
77 import com.android.systemui.SystemUI;
78 import com.android.systemui.SystemUIFactory;
79 import com.android.systemui.classifier.FalsingManager;
80 import com.android.systemui.statusbar.phone.FingerprintUnlockController;
81 import com.android.systemui.statusbar.phone.PhoneStatusBar;
82 import com.android.systemui.statusbar.phone.ScrimController;
83 import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
84 import com.android.systemui.statusbar.phone.StatusBarWindowManager;
86 import java.io.FileDescriptor;
87 import java.io.PrintWriter;
88 import java.util.ArrayList;
91 * Mediates requests related to the keyguard. This includes queries about the
92 * state of the keyguard, power management events that effect whether the keyguard
93 * should be shown or reset, callbacks to the phone window manager to notify
94 * it of when the keyguard is showing, and events from the keyguard view itself
95 * stating that the keyguard was succesfully unlocked.
97 * Note that the keyguard view is shown when the screen is off (as appropriate)
98 * so that once the screen comes on, it will be ready immediately.
100 * Example queries about the keyguard:
101 * - is {movement, key} one that should wake the keygaurd?
102 * - is the keyguard showing?
103 * - are input events restricted due to the state of the keyguard?
105 * Callbacks to the phone window manager:
106 * - the keyguard is showing
108 * Example external events that translate to keyguard view changes:
109 * - screen turned off -> reset the keyguard, and show it so it will be ready
110 * next time the screen turns on
111 * - keyboard is slid open -> if the keyguard is not secure, hide it
113 * Events from the keyguard view:
114 * - user succesfully unlocked keyguard -> hide keyguard view, and no longer
115 * restrict input events.
117 * Note: in addition to normal power managment events that effect the state of
118 * whether the keyguard should be showing, external apps and services may request
119 * that the keyguard be disabled via {@link #setKeyguardEnabled(boolean)}. When
120 * false, this will override all other conditions for turning on the keyguard.
122 * Threading and synchronization:
123 * This class is created by the initialization routine of the {@link android.view.WindowManagerPolicy},
124 * and runs on its thread. The keyguard UI is created from that thread in the
125 * constructor of this class. The apis may be called from other threads, including the
126 * {@link com.android.server.input.InputManagerService}'s and {@link android.view.WindowManager}'s.
127 * Therefore, methods on this class are synchronized, and any action that is pointed
128 * directly to the keyguard UI is posted to a {@link android.os.Handler} to ensure it is taken on the UI
129 * thread of the keyguard.
131 public class KeyguardViewMediator extends SystemUI {
132 private static final int KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT = 30000;
133 private static final long KEYGUARD_DONE_PENDING_TIMEOUT_MS = 3000;
135 private static final boolean DEBUG = KeyguardConstants.DEBUG;
136 private static final boolean DEBUG_SIM_STATES = KeyguardConstants.DEBUG_SIM_STATES;
137 private final static boolean DBG_WAKE = false;
139 private final static String TAG = "KeyguardViewMediator";
141 private static final String DELAYED_KEYGUARD_ACTION =
142 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD";
143 private static final String DELAYED_LOCK_PROFILE_ACTION =
144 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_LOCK";
146 // used for handler messages
147 private static final int SHOW = 2;
148 private static final int HIDE = 3;
149 private static final int RESET = 4;
150 private static final int VERIFY_UNLOCK = 5;
151 private static final int NOTIFY_FINISHED_GOING_TO_SLEEP = 6;
152 private static final int NOTIFY_SCREEN_TURNING_ON = 7;
153 private static final int KEYGUARD_DONE = 9;
154 private static final int KEYGUARD_DONE_DRAWING = 10;
155 private static final int KEYGUARD_DONE_AUTHENTICATING = 11;
156 private static final int SET_OCCLUDED = 12;
157 private static final int KEYGUARD_TIMEOUT = 13;
158 private static final int DISMISS = 17;
159 private static final int START_KEYGUARD_EXIT_ANIM = 18;
160 private static final int ON_ACTIVITY_DRAWN = 19;
161 private static final int KEYGUARD_DONE_PENDING_TIMEOUT = 20;
162 private static final int NOTIFY_STARTED_WAKING_UP = 21;
163 private static final int NOTIFY_SCREEN_TURNED_ON = 22;
164 private static final int NOTIFY_SCREEN_TURNED_OFF = 23;
165 private static final int NOTIFY_STARTED_GOING_TO_SLEEP = 24;
168 * The default amount of time we stay awake (used for all key input)
170 public static final int AWAKE_INTERVAL_DEFAULT_MS = 10000;
173 * How long to wait after the screen turns off due to timeout before
174 * turning on the keyguard (i.e, the user has this much time to turn
175 * the screen back on without having to face the keyguard).
177 private static final int KEYGUARD_LOCK_AFTER_DELAY_DEFAULT = 5000;
180 * How long we'll wait for the {@link ViewMediatorCallback#keyguardDoneDrawing()}
181 * callback before unblocking a call to {@link #setKeyguardEnabled(boolean)}
182 * that is reenabling the keyguard.
184 private static final int KEYGUARD_DONE_DRAWING_TIMEOUT_MS = 2000;
187 * Secure setting whether analytics are collected on the keyguard.
189 private static final String KEYGUARD_ANALYTICS_SETTING = "keyguard_analytics";
191 /** The stream type that the lock sounds are tied to. */
192 private int mUiSoundsStreamType;
194 private AlarmManager mAlarmManager;
195 private AudioManager mAudioManager;
196 private StatusBarManager mStatusBarManager;
197 private boolean mSwitchingUser;
199 private boolean mSystemReady;
200 private boolean mBootCompleted;
201 private boolean mBootSendUserPresent;
203 /** High level access to the power manager for WakeLocks */
204 private PowerManager mPM;
206 /** High level access to the window manager for dismissing keyguard animation */
207 private IWindowManager mWM;
210 /** TrustManager for letting it know when we change visibility */
211 private TrustManager mTrustManager;
213 /** SearchManager for determining whether or not search assistant is available */
214 private SearchManager mSearchManager;
217 * Used to keep the device awake while to ensure the keyguard finishes opening before
220 private PowerManager.WakeLock mShowKeyguardWakeLock;
222 private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
224 // these are protected by synchronized (this)
227 * External apps (like the phone app) can tell us to disable the keygaurd.
229 private boolean mExternallyEnabled = true;
232 * Remember if an external call to {@link #setKeyguardEnabled} with value
233 * false caused us to hide the keyguard, so that we need to reshow it once
234 * the keygaurd is reenabled with another call with value true.
236 private boolean mNeedToReshowWhenReenabled = false;
238 // cached value of whether we are showing (need to know this to quickly
239 // answer whether the input should be restricted)
240 private boolean mShowing;
242 /** Cached value of #isInputRestricted */
243 private boolean mInputRestricted;
245 // true if the keyguard is hidden by another window
246 private boolean mOccluded = false;
249 * Helps remember whether the screen has turned on since the last time
250 * it turned off due to timeout. see {@link #onScreenTurnedOff(int)}
252 private int mDelayedShowingSequence;
255 * Simiar to {@link #mDelayedProfileShowingSequence}, but it is for profile case.
257 private int mDelayedProfileShowingSequence;
260 * If the user has disabled the keyguard, then requests to exit, this is
261 * how we'll ultimately let them know whether it was successful. We use this
262 * var being non-null as an indicator that there is an in progress request.
264 private IKeyguardExitCallback mExitSecureCallback;
266 // the properties of the keyguard
268 private KeyguardUpdateMonitor mUpdateMonitor;
270 private boolean mDeviceInteractive;
271 private boolean mGoingToSleep;
273 // last known state of the cellular connection
274 private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE;
277 * Whether a hide is pending an we are just waiting for #startKeyguardExitAnimation to be
280 private boolean mHiding;
283 * we send this intent when the keyguard is dismissed.
285 private static final Intent USER_PRESENT_INTENT = new Intent(Intent.ACTION_USER_PRESENT)
286 .addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
287 | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
290 * {@link #setKeyguardEnabled} waits on this condition when it reenables
293 private boolean mWaitingUntilKeyguardVisible = false;
294 private LockPatternUtils mLockPatternUtils;
295 private boolean mKeyguardDonePending = false;
296 private boolean mHideAnimationRun = false;
298 private SoundPool mLockSounds;
299 private int mLockSoundId;
300 private int mUnlockSoundId;
301 private int mTrustedSoundId;
302 private int mLockSoundStreamId;
305 * The animation used for hiding keyguard. This is used to fetch the animation timings if
306 * WindowManager is not providing us with them.
308 private Animation mHideAnimation;
311 * The volume applied to the lock/unlock sounds.
313 private float mLockSoundVolume;
316 * For managing external displays
318 private KeyguardDisplayManager mKeyguardDisplayManager;
320 private final ArrayList<IKeyguardStateCallback> mKeyguardStateCallbacks = new ArrayList<>();
323 * When starting going to sleep, we figured out that we need to reset Keyguard state and this
324 * should be committed when finished going to sleep.
326 private boolean mPendingReset;
329 * When starting going to sleep, we figured out that we need to lock Keyguard and this should be
330 * committed when finished going to sleep.
332 private boolean mPendingLock;
334 private boolean mLockLater;
336 private boolean mWakeAndUnlocking;
337 private IKeyguardDrawnCallback mDrawnCallback;
339 private boolean mIsPerUserLock;
341 KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {
344 public void onUserSwitching(int userId) {
345 // Note that the mLockPatternUtils user has already been updated from setCurrentUser.
346 // We need to force a reset of the views, since lockNow (called by
347 // ActivityManagerService) will not reconstruct the keyguard if it is already showing.
348 synchronized (KeyguardViewMediator.this) {
349 mSwitchingUser = true;
350 resetKeyguardDonePendingLocked();
352 adjustStatusBarLocked();
357 public void onUserSwitchComplete(int userId) {
358 mSwitchingUser = false;
359 if (userId != UserHandle.USER_SYSTEM) {
360 UserInfo info = UserManager.get(mContext).getUserInfo(userId);
361 if (info != null && (info.isGuest() || info.isDemo())) {
362 // If we just switched to a guest, try to dismiss keyguard.
363 dismiss(false /* allowWhileOccluded */);
369 public void onUserInfoChanged(int userId) {
373 public void onPhoneStateChanged(int phoneState) {
374 synchronized (KeyguardViewMediator.this) {
375 if (TelephonyManager.CALL_STATE_IDLE == phoneState // call ending
376 && !mDeviceInteractive // screen off
377 && mExternallyEnabled) { // not disabled by any app
379 // note: this is a way to gracefully reenable the keyguard when the call
380 // ends and the screen is off without always reenabling the keyguard
381 // each time the screen turns off while in call (and having an occasional ugly
382 // flicker while turning back on the screen and disabling the keyguard again).
383 if (DEBUG) Log.d(TAG, "screen is off and call ended, let's make sure the "
384 + "keyguard is showing");
385 doKeyguardLocked(null);
391 public void onClockVisibilityChanged() {
392 adjustStatusBarLocked();
396 public void onDeviceProvisioned() {
397 sendUserPresentBroadcast();
398 synchronized (KeyguardViewMediator.this) {
399 // If system user is provisioned, we might want to lock now to avoid showing launcher
400 if (mustNotUnlockCurrentUser()) {
401 doKeyguardLocked(null);
407 public void onSimStateChanged(int subId, int slotId, IccCardConstants.State simState) {
409 if (DEBUG_SIM_STATES) {
410 Log.d(TAG, "onSimStateChanged(subId=" + subId + ", slotId=" + slotId
411 + ",state=" + simState + ")");
414 int size = mKeyguardStateCallbacks.size();
415 boolean simPinSecure = mUpdateMonitor.isSimPinSecure();
416 for (int i = size - 1; i >= 0; i--) {
418 mKeyguardStateCallbacks.get(i).onSimSecureStateChanged(simPinSecure);
419 } catch (RemoteException e) {
420 Slog.w(TAG, "Failed to call onSimSecureStateChanged", e);
421 if (e instanceof DeadObjectException) {
422 mKeyguardStateCallbacks.remove(i);
430 // only force lock screen in case of missing sim if user hasn't
431 // gone through setup wizard
432 synchronized (this) {
433 if (shouldWaitForProvisioning()) {
435 if (DEBUG_SIM_STATES) Log.d(TAG, "ICC_ABSENT isn't showing,"
436 + " we need to show the keyguard since the "
437 + "device isn't provisioned yet.");
438 doKeyguardLocked(null);
447 synchronized (this) {
449 if (DEBUG_SIM_STATES) Log.d(TAG,
450 "INTENT_VALUE_ICC_LOCKED and keygaurd isn't "
451 + "showing; need to show keyguard so user can enter sim pin");
452 doKeyguardLocked(null);
459 synchronized (this) {
461 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED and "
462 + "keygaurd isn't showing.");
463 doKeyguardLocked(null);
465 if (DEBUG_SIM_STATES) Log.d(TAG, "PERM_DISABLED, resetStateLocked to"
466 + "show permanently disabled message in lockscreen.");
472 synchronized (this) {
479 if (DEBUG_SIM_STATES) Log.v(TAG, "Ignoring state: " + simState);
485 public void onFingerprintAuthFailed() {
486 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
487 if (mLockPatternUtils.isSecure(currentUser)) {
488 mLockPatternUtils.getDevicePolicyManager().reportFailedFingerprintAttempt(
494 public void onFingerprintAuthenticated(int userId) {
495 if (mLockPatternUtils.isSecure(userId)) {
496 mLockPatternUtils.getDevicePolicyManager().reportSuccessfulFingerprintAttempt(
502 public void onTrustChanged(int userId) {
503 if (userId == KeyguardUpdateMonitor.getCurrentUser()) {
504 synchronized (KeyguardViewMediator.this) {
505 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(userId));
511 public void onHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
512 synchronized (KeyguardViewMediator.this) {
513 notifyHasLockscreenWallpaperChanged(hasLockscreenWallpaper);
518 ViewMediatorCallback mViewMediatorCallback = new ViewMediatorCallback() {
521 public void userActivity() {
522 KeyguardViewMediator.this.userActivity();
526 public void keyguardDone(boolean strongAuth) {
527 if (!mKeyguardDonePending) {
528 KeyguardViewMediator.this.keyguardDone(true /* authenticated */);
531 mUpdateMonitor.reportSuccessfulStrongAuthUnlockAttempt();
536 public void keyguardDoneDrawing() {
537 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDoneDrawing");
538 mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING);
543 public void setNeedsInput(boolean needsInput) {
544 mStatusBarKeyguardViewManager.setNeedsInput(needsInput);
548 public void keyguardDonePending(boolean strongAuth) {
549 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardDonePending");
550 mKeyguardDonePending = true;
551 mHideAnimationRun = true;
552 mStatusBarKeyguardViewManager.startPreHideAnimation(null /* finishRunnable */);
553 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_PENDING_TIMEOUT,
554 KEYGUARD_DONE_PENDING_TIMEOUT_MS);
556 mUpdateMonitor.reportSuccessfulStrongAuthUnlockAttempt();
562 public void keyguardGone() {
563 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#keyguardGone");
564 mKeyguardDisplayManager.hide();
569 public void readyForKeyguardDone() {
570 Trace.beginSection("KeyguardViewMediator.mViewMediatorCallback#readyForKeyguardDone");
571 if (mKeyguardDonePending) {
572 // Somebody has called keyguardDonePending before, which means that we are
574 KeyguardViewMediator.this.keyguardDone(true /* authenticated */);
580 public void resetKeyguard() {
585 public void playTrustedSound() {
586 KeyguardViewMediator.this.playTrustedSound();
590 public boolean isInputRestricted() {
591 return KeyguardViewMediator.this.isInputRestricted();
595 public boolean isScreenOn() {
596 return mDeviceInteractive;
600 public int getBouncerPromptReason() {
601 int currentUser = ActivityManager.getCurrentUser();
602 boolean trust = mTrustManager.isTrustUsuallyManaged(currentUser);
603 boolean fingerprint = mUpdateMonitor.isUnlockWithFingerprintPossible(currentUser);
604 boolean any = trust || fingerprint;
605 KeyguardUpdateMonitor.StrongAuthTracker strongAuthTracker =
606 mUpdateMonitor.getStrongAuthTracker();
607 int strongAuth = strongAuthTracker.getStrongAuthForUser(currentUser);
609 if (any && !strongAuthTracker.hasUserAuthenticatedSinceBoot()) {
610 return KeyguardSecurityView.PROMPT_REASON_RESTART;
611 } else if (fingerprint && mUpdateMonitor.hasFingerprintUnlockTimedOut(currentUser)) {
612 return KeyguardSecurityView.PROMPT_REASON_TIMEOUT;
613 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW) != 0) {
614 return KeyguardSecurityView.PROMPT_REASON_DEVICE_ADMIN;
615 } else if (trust && (strongAuth & SOME_AUTH_REQUIRED_AFTER_USER_REQUEST) != 0) {
616 return KeyguardSecurityView.PROMPT_REASON_USER_REQUEST;
617 } else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_LOCKOUT) != 0) {
618 return KeyguardSecurityView.PROMPT_REASON_AFTER_LOCKOUT;
620 return KeyguardSecurityView.PROMPT_REASON_NONE;
624 public void userActivity() {
625 mPM.userActivity(SystemClock.uptimeMillis(), false);
628 boolean mustNotUnlockCurrentUser() {
629 return (UserManager.isSplitSystemUser() || UserManager.isDeviceInDemoMode(mContext))
630 && KeyguardUpdateMonitor.getCurrentUser() == UserHandle.USER_SYSTEM;
633 private void setupLocked() {
634 mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
635 mWM = WindowManagerGlobal.getWindowManagerService();
636 mTrustManager = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE);
638 mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
639 mShowKeyguardWakeLock.setReferenceCounted(false);
641 mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(DELAYED_KEYGUARD_ACTION));
642 mContext.registerReceiver(
643 mBroadcastReceiver, new IntentFilter(DELAYED_LOCK_PROFILE_ACTION));
645 mKeyguardDisplayManager = new KeyguardDisplayManager(mContext);
647 mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
649 mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
651 mLockPatternUtils = new LockPatternUtils(mContext);
652 KeyguardUpdateMonitor.setCurrentUser(ActivityManager.getCurrentUser());
654 // Assume keyguard is showing (unless it's disabled) until we know for sure...
655 setShowingLocked(!shouldWaitForProvisioning() && !mLockPatternUtils.isLockScreenDisabled(
656 KeyguardUpdateMonitor.getCurrentUser()));
657 updateInputRestrictedLocked();
658 mTrustManager.reportKeyguardShowingChanged();
660 mStatusBarKeyguardViewManager =
661 SystemUIFactory.getInstance().createStatusBarKeyguardViewManager(mContext,
662 mViewMediatorCallback, mLockPatternUtils);
663 final ContentResolver cr = mContext.getContentResolver();
665 mDeviceInteractive = mPM.isInteractive();
667 mLockSounds = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
668 String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND);
669 if (soundPath != null) {
670 mLockSoundId = mLockSounds.load(soundPath, 1);
672 if (soundPath == null || mLockSoundId == 0) {
673 Log.w(TAG, "failed to load lock sound from " + soundPath);
675 soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND);
676 if (soundPath != null) {
677 mUnlockSoundId = mLockSounds.load(soundPath, 1);
679 if (soundPath == null || mUnlockSoundId == 0) {
680 Log.w(TAG, "failed to load unlock sound from " + soundPath);
682 soundPath = Settings.Global.getString(cr, Settings.Global.TRUSTED_SOUND);
683 if (soundPath != null) {
684 mTrustedSoundId = mLockSounds.load(soundPath, 1);
686 if (soundPath == null || mTrustedSoundId == 0) {
687 Log.w(TAG, "failed to load trusted sound from " + soundPath);
690 int lockSoundDefaultAttenuation = mContext.getResources().getInteger(
691 com.android.internal.R.integer.config_lockSoundVolumeDb);
692 mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20);
694 mHideAnimation = AnimationUtils.loadAnimation(mContext,
695 com.android.internal.R.anim.lock_screen_behind_enter);
699 public void start() {
700 synchronized (this) {
703 putComponent(KeyguardViewMediator.class, this);
707 * Let us know that the system is ready after startup.
709 public void onSystemReady() {
710 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
711 synchronized (this) {
712 if (DEBUG) Log.d(TAG, "onSystemReady");
714 doKeyguardLocked(null);
715 mUpdateMonitor.registerCallback(mUpdateCallback);
717 mIsPerUserLock = StorageManager.isFileEncryptedNativeOrEmulated();
718 // Most services aren't available until the system reaches the ready state, so we
719 // send it here when the device first boots.
720 maybeSendUserPresentBroadcast();
724 * Called to let us know the screen was turned off.
725 * @param why either {@link android.view.WindowManagerPolicy#OFF_BECAUSE_OF_USER} or
726 * {@link android.view.WindowManagerPolicy#OFF_BECAUSE_OF_TIMEOUT}.
728 public void onStartedGoingToSleep(int why) {
729 if (DEBUG) Log.d(TAG, "onStartedGoingToSleep(" + why + ")");
730 synchronized (this) {
731 mDeviceInteractive = false;
732 mGoingToSleep = true;
734 // Lock immediately based on setting if secure (user has a pin/pattern/password).
735 // This also "locks" the device when not secure to provide easy access to the
736 // camera while preventing unwanted input.
737 int currentUser = KeyguardUpdateMonitor.getCurrentUser();
738 final boolean lockImmediately =
739 mLockPatternUtils.getPowerButtonInstantlyLocks(currentUser)
740 || !mLockPatternUtils.isSecure(currentUser);
741 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
743 if (mExitSecureCallback != null) {
744 if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled");
746 mExitSecureCallback.onKeyguardExitResult(false);
747 } catch (RemoteException e) {
748 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
750 mExitSecureCallback = null;
751 if (!mExternallyEnabled) {
754 } else if (mShowing) {
755 mPendingReset = true;
756 } else if ((why == WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT && timeout > 0)
757 || (why == WindowManagerPolicy.OFF_BECAUSE_OF_USER && !lockImmediately)) {
758 doKeyguardLaterLocked(timeout);
760 } else if (!mLockPatternUtils.isLockScreenDisabled(currentUser)) {
768 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedGoingToSleep(why);
769 notifyStartedGoingToSleep();
772 public void onFinishedGoingToSleep(int why, boolean cameraGestureTriggered) {
773 if (DEBUG) Log.d(TAG, "onFinishedGoingToSleep(" + why + ")");
774 synchronized (this) {
775 mDeviceInteractive = false;
776 mGoingToSleep = false;
778 resetKeyguardDonePendingLocked();
779 mHideAnimationRun = false;
781 notifyFinishedGoingToSleep();
783 if (cameraGestureTriggered) {
784 Log.i(TAG, "Camera gesture was triggered, preventing Keyguard locking.");
786 // Just to make sure, make sure the device is awake.
787 mContext.getSystemService(PowerManager.class).wakeUp(SystemClock.uptimeMillis(),
788 "com.android.systemui:CAMERA_GESTURE_PREVENT_LOCK");
789 mPendingLock = false;
790 mPendingReset = false;
795 mPendingReset = false;
799 doKeyguardLocked(null);
800 mPendingLock = false;
803 // We do not have timeout and power button instant lock setting for profile lock.
804 // So we use the personal setting if there is any. But if there is no device
805 // we need to make sure we lock it immediately when the screen is off.
806 if (!mLockLater && !cameraGestureTriggered) {
807 doKeyguardForChildProfilesLocked();
811 KeyguardUpdateMonitor.getInstance(mContext).dispatchFinishedGoingToSleep(why);
814 private long getLockTimeout(int userId) {
815 // if the screen turned off because of timeout or the user hit the power button
816 // and we don't need to lock immediately, set an alarm
817 // to enable it a little bit later (i.e, give the user a chance
818 // to turn the screen back on within a certain window without
819 // having to unlock the screen)
820 final ContentResolver cr = mContext.getContentResolver();
822 // From SecuritySettings
823 final long lockAfterTimeout = Settings.Secure.getInt(cr,
824 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT,
825 KEYGUARD_LOCK_AFTER_DELAY_DEFAULT);
827 // From DevicePolicyAdmin
828 final long policyTimeout = mLockPatternUtils.getDevicePolicyManager()
829 .getMaximumTimeToLockForUserAndProfiles(userId);
833 if (policyTimeout <= 0) {
834 timeout = lockAfterTimeout;
836 // From DisplaySettings
837 long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT,
838 KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT);
840 // policy in effect. Make sure we don't go beyond policy limit.
841 displayTimeout = Math.max(displayTimeout, 0); // ignore negative values
842 timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout);
843 timeout = Math.max(timeout, 0);
848 private void doKeyguardLaterLocked() {
849 long timeout = getLockTimeout(KeyguardUpdateMonitor.getCurrentUser());
851 doKeyguardLocked(null);
853 doKeyguardLaterLocked(timeout);
857 private void doKeyguardLaterLocked(long timeout) {
858 // Lock in the future
859 long when = SystemClock.elapsedRealtime() + timeout;
860 Intent intent = new Intent(DELAYED_KEYGUARD_ACTION);
861 intent.putExtra("seq", mDelayedShowingSequence);
862 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
863 PendingIntent sender = PendingIntent.getBroadcast(mContext,
864 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
865 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender);
866 if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = "
867 + mDelayedShowingSequence);
868 doKeyguardLaterForChildProfilesLocked();
871 private void doKeyguardLaterForChildProfilesLocked() {
872 UserManager um = UserManager.get(mContext);
873 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
874 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
875 long userTimeout = getLockTimeout(profileId);
876 if (userTimeout == 0) {
877 doKeyguardForChildProfilesLocked();
879 long userWhen = SystemClock.elapsedRealtime() + userTimeout;
880 Intent lockIntent = new Intent(DELAYED_LOCK_PROFILE_ACTION);
881 lockIntent.putExtra("seq", mDelayedProfileShowingSequence);
882 lockIntent.putExtra(Intent.EXTRA_USER_ID, profileId);
883 lockIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
884 PendingIntent lockSender = PendingIntent.getBroadcast(
885 mContext, 0, lockIntent, PendingIntent.FLAG_CANCEL_CURRENT);
886 mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
887 userWhen, lockSender);
893 private void doKeyguardForChildProfilesLocked() {
894 UserManager um = UserManager.get(mContext);
895 for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) {
896 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(profileId)) {
897 lockProfile(profileId);
902 private void cancelDoKeyguardLaterLocked() {
903 mDelayedShowingSequence++;
906 private void cancelDoKeyguardForChildProfilesLocked() {
907 mDelayedProfileShowingSequence++;
911 * Let's us know when the device is waking up.
913 public void onStartedWakingUp() {
914 Trace.beginSection("KeyguardViewMediator#onStartedWakingUp");
916 // TODO: Rename all screen off/on references to interactive/sleeping
917 synchronized (this) {
918 mDeviceInteractive = true;
919 cancelDoKeyguardLaterLocked();
920 cancelDoKeyguardForChildProfilesLocked();
921 if (DEBUG) Log.d(TAG, "onStartedWakingUp, seq = " + mDelayedShowingSequence);
922 notifyStartedWakingUp();
924 KeyguardUpdateMonitor.getInstance(mContext).dispatchStartedWakingUp();
925 maybeSendUserPresentBroadcast();
929 public void onScreenTurningOn(IKeyguardDrawnCallback callback) {
930 Trace.beginSection("KeyguardViewMediator#onScreenTurningOn");
931 notifyScreenOn(callback);
935 public void onScreenTurnedOn() {
936 Trace.beginSection("KeyguardViewMediator#onScreenTurnedOn");
937 notifyScreenTurnedOn();
938 mUpdateMonitor.dispatchScreenTurnedOn();
942 public void onScreenTurnedOff() {
943 notifyScreenTurnedOff();
944 mUpdateMonitor.dispatchScreenTurnedOff();
947 private void maybeSendUserPresentBroadcast() {
948 if (mSystemReady && mLockPatternUtils.isLockScreenDisabled(
949 KeyguardUpdateMonitor.getCurrentUser())) {
950 // Lock screen is disabled because the user has set the preference to "None".
951 // In this case, send out ACTION_USER_PRESENT here instead of in
952 // handleKeyguardDone()
953 sendUserPresentBroadcast();
954 } else if (mSystemReady && shouldWaitForProvisioning()) {
955 // Skipping the lockscreen because we're not yet provisioned, but we still need to
956 // notify the StrongAuthTracker that it's now safe to run trust agents, in case the
957 // user sets a credential later.
958 getLockPatternUtils().userPresent(KeyguardUpdateMonitor.getCurrentUser());
963 * A dream started. We should lock after the usual screen-off lock timeout but only
964 * if there is a secure lock pattern.
966 public void onDreamingStarted() {
967 synchronized (this) {
968 if (mDeviceInteractive
969 && mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())) {
970 doKeyguardLaterLocked();
978 public void onDreamingStopped() {
979 synchronized (this) {
980 if (mDeviceInteractive) {
981 cancelDoKeyguardLaterLocked();
987 * Same semantics as {@link android.view.WindowManagerPolicy#enableKeyguard}; provide
988 * a way for external stuff to override normal keyguard behavior. For instance
989 * the phone app disables the keyguard when it receives incoming calls.
991 public void setKeyguardEnabled(boolean enabled) {
992 synchronized (this) {
993 if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")");
995 mExternallyEnabled = enabled;
997 if (!enabled && mShowing) {
998 if (mExitSecureCallback != null) {
999 if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring");
1000 // we're in the process of handling a request to verify the user
1001 // can get past the keyguard. ignore extraneous requests to disable / reenable
1005 // hiding keyguard that is showing, remember to reshow later
1006 if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, "
1007 + "disabling status bar expansion");
1008 mNeedToReshowWhenReenabled = true;
1009 updateInputRestrictedLocked();
1011 } else if (enabled && mNeedToReshowWhenReenabled) {
1012 // reenabled after previously hidden, reshow
1013 if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling "
1014 + "status bar expansion");
1015 mNeedToReshowWhenReenabled = false;
1016 updateInputRestrictedLocked();
1018 if (mExitSecureCallback != null) {
1019 if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting");
1021 mExitSecureCallback.onKeyguardExitResult(false);
1022 } catch (RemoteException e) {
1023 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1025 mExitSecureCallback = null;
1030 // block until we know the keygaurd is done drawing (and post a message
1031 // to unblock us after a timeout so we don't risk blocking too long
1032 // and causing an ANR).
1033 mWaitingUntilKeyguardVisible = true;
1034 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS);
1035 if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false");
1036 while (mWaitingUntilKeyguardVisible) {
1039 } catch (InterruptedException e) {
1040 Thread.currentThread().interrupt();
1043 if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible");
1050 * @see android.app.KeyguardManager#exitKeyguardSecurely
1052 public void verifyUnlock(IKeyguardExitCallback callback) {
1053 Trace.beginSection("KeyguardViewMediator#verifyUnlock");
1054 synchronized (this) {
1055 if (DEBUG) Log.d(TAG, "verifyUnlock");
1056 if (shouldWaitForProvisioning()) {
1057 // don't allow this api when the device isn't provisioned
1058 if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned");
1060 callback.onKeyguardExitResult(false);
1061 } catch (RemoteException e) {
1062 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1064 } else if (mExternallyEnabled) {
1065 // this only applies when the user has externally disabled the
1066 // keyguard. this is unexpected and means the user is not
1067 // using the api properly.
1068 Log.w(TAG, "verifyUnlock called when not externally disabled");
1070 callback.onKeyguardExitResult(false);
1071 } catch (RemoteException e) {
1072 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1074 } else if (mExitSecureCallback != null) {
1075 // already in progress with someone else
1077 callback.onKeyguardExitResult(false);
1078 } catch (RemoteException e) {
1079 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1081 } else if (!isSecure()) {
1083 // Keyguard is not secure, no need to do anything, and we don't need to reshow
1084 // the Keyguard after the client releases the Keyguard lock.
1085 mExternallyEnabled = true;
1086 mNeedToReshowWhenReenabled = false;
1087 updateInputRestricted();
1089 callback.onKeyguardExitResult(true);
1090 } catch (RemoteException e) {
1091 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1095 // Since we prevent apps from hiding the Keyguard if we are secure, this should be
1098 callback.onKeyguardExitResult(false);
1099 } catch (RemoteException e) {
1100 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
1108 * Is the keyguard currently showing and not being force hidden?
1110 public boolean isShowingAndNotOccluded() {
1111 return mShowing && !mOccluded;
1115 * Notify us when the keyguard is occluded by another window
1117 public void setOccluded(boolean isOccluded) {
1118 Trace.beginSection("KeyguardViewMediator#setOccluded");
1119 if (DEBUG) Log.d(TAG, "setOccluded " + isOccluded);
1120 mHandler.removeMessages(SET_OCCLUDED);
1121 Message msg = mHandler.obtainMessage(SET_OCCLUDED, (isOccluded ? 1 : 0), 0);
1122 mHandler.sendMessage(msg);
1127 * Handles SET_OCCLUDED message sent by setOccluded()
1129 private void handleSetOccluded(boolean isOccluded) {
1130 Trace.beginSection("KeyguardViewMediator#handleSetOccluded");
1131 synchronized (KeyguardViewMediator.this) {
1132 if (mHiding && isOccluded) {
1133 // We're in the process of going away but WindowManager wants to show a
1134 // SHOW_WHEN_LOCKED activity instead.
1135 startKeyguardExitAnimation(0, 0);
1138 if (mOccluded != isOccluded) {
1139 mOccluded = isOccluded;
1140 mStatusBarKeyguardViewManager.setOccluded(isOccluded);
1141 updateActivityLockScreenState();
1142 adjustStatusBarLocked();
1149 * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout.
1150 * This must be safe to call from any thread and with any window manager locks held.
1152 public void doKeyguardTimeout(Bundle options) {
1153 mHandler.removeMessages(KEYGUARD_TIMEOUT);
1154 Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options);
1155 mHandler.sendMessage(msg);
1159 * Given the state of the keyguard, is the input restricted?
1160 * Input is restricted when the keyguard is showing, or when the keyguard
1161 * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet.
1163 public boolean isInputRestricted() {
1164 return mShowing || mNeedToReshowWhenReenabled;
1167 private void updateInputRestricted() {
1168 synchronized (this) {
1169 updateInputRestrictedLocked();
1172 private void updateInputRestrictedLocked() {
1173 boolean inputRestricted = isInputRestricted();
1174 if (mInputRestricted != inputRestricted) {
1175 mInputRestricted = inputRestricted;
1176 int size = mKeyguardStateCallbacks.size();
1177 for (int i = size - 1; i >= 0; i--) {
1179 mKeyguardStateCallbacks.get(i).onInputRestrictedStateChanged(inputRestricted);
1180 } catch (RemoteException e) {
1181 Slog.w(TAG, "Failed to call onDeviceProvisioned", e);
1182 if (e instanceof DeadObjectException) {
1183 mKeyguardStateCallbacks.remove(i);
1191 * Enable the keyguard if the settings are appropriate.
1193 private void doKeyguardLocked(Bundle options) {
1194 // if another app is disabling us, don't show
1195 if (!mExternallyEnabled) {
1196 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled");
1198 // note: we *should* set mNeedToReshowWhenReenabled=true here, but that makes
1199 // for an occasional ugly flicker in this situation:
1200 // 1) receive a call with the screen on (no keyguard) or make a call
1201 // 2) screen times out
1202 // 3) user hits key to turn screen back on
1203 // instead, we reenable the keyguard when we know the screen is off and the call
1204 // ends (see the broadcast receiver below)
1205 // TODO: clean this up when we have better support at the window manager level
1206 // for apps that wish to be on top of the keyguard
1210 // if the keyguard is already showing, don't bother
1211 if (mStatusBarKeyguardViewManager.isShowing()) {
1212 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing");
1217 // In split system user mode, we never unlock system user.
1218 if (!mustNotUnlockCurrentUser()
1219 || !mUpdateMonitor.isDeviceProvisioned()) {
1221 // if the setup wizard hasn't run yet, don't show
1222 final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", false);
1223 final boolean absent = SubscriptionManager.isValidSubscriptionId(
1224 mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.ABSENT));
1225 final boolean disabled = SubscriptionManager.isValidSubscriptionId(
1226 mUpdateMonitor.getNextSubIdForState(IccCardConstants.State.PERM_DISABLED));
1227 final boolean lockedOrMissing = mUpdateMonitor.isSimPinSecure()
1228 || ((absent || disabled) && requireSim);
1230 if (!lockedOrMissing && shouldWaitForProvisioning()) {
1231 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned"
1232 + " and the sim is not locked or missing");
1236 if (mLockPatternUtils.isLockScreenDisabled(KeyguardUpdateMonitor.getCurrentUser())
1237 && !lockedOrMissing) {
1238 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off");
1242 if (mLockPatternUtils.checkVoldPassword(KeyguardUpdateMonitor.getCurrentUser())) {
1243 if (DEBUG) Log.d(TAG, "Not showing lock screen since just decrypted");
1244 // Without this, settings is not enabled until the lock screen first appears
1245 setShowingLocked(false);
1247 mUpdateMonitor.reportSuccessfulStrongAuthUnlockAttempt();
1252 if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen");
1253 showLocked(options);
1256 private void lockProfile(int userId) {
1257 mTrustManager.setDeviceLockedForUser(userId, true);
1260 private boolean shouldWaitForProvisioning() {
1261 return !mUpdateMonitor.isDeviceProvisioned() && !isSecure();
1265 * Dismiss the keyguard through the security layers.
1266 * @param allowWhileOccluded if true, dismiss the keyguard even if it's currently occluded.
1268 public void handleDismiss(boolean allowWhileOccluded) {
1269 if (mShowing && (allowWhileOccluded || !mOccluded)) {
1270 mStatusBarKeyguardViewManager.dismiss();
1274 public void dismiss(boolean allowWhileOccluded) {
1275 mHandler.obtainMessage(DISMISS, allowWhileOccluded ? 1 : 0, 0).sendToTarget();
1279 * Send message to keyguard telling it to reset its state.
1282 private void resetStateLocked() {
1283 if (DEBUG) Log.e(TAG, "resetStateLocked");
1284 Message msg = mHandler.obtainMessage(RESET);
1285 mHandler.sendMessage(msg);
1289 * Send message to keyguard telling it to verify unlock
1290 * @see #handleVerifyUnlock()
1292 private void verifyUnlockLocked() {
1293 if (DEBUG) Log.d(TAG, "verifyUnlockLocked");
1294 mHandler.sendEmptyMessage(VERIFY_UNLOCK);
1297 private void notifyStartedGoingToSleep() {
1298 if (DEBUG) Log.d(TAG, "notifyStartedGoingToSleep");
1299 mHandler.sendEmptyMessage(NOTIFY_STARTED_GOING_TO_SLEEP);
1302 private void notifyFinishedGoingToSleep() {
1303 if (DEBUG) Log.d(TAG, "notifyFinishedGoingToSleep");
1304 mHandler.sendEmptyMessage(NOTIFY_FINISHED_GOING_TO_SLEEP);
1307 private void notifyStartedWakingUp() {
1308 if (DEBUG) Log.d(TAG, "notifyStartedWakingUp");
1309 mHandler.sendEmptyMessage(NOTIFY_STARTED_WAKING_UP);
1312 private void notifyScreenOn(IKeyguardDrawnCallback callback) {
1313 if (DEBUG) Log.d(TAG, "notifyScreenOn");
1314 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNING_ON, callback);
1315 mHandler.sendMessage(msg);
1318 private void notifyScreenTurnedOn() {
1319 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOn");
1320 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_ON);
1321 mHandler.sendMessage(msg);
1324 private void notifyScreenTurnedOff() {
1325 if (DEBUG) Log.d(TAG, "notifyScreenTurnedOff");
1326 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_TURNED_OFF);
1327 mHandler.sendMessage(msg);
1331 * Send message to keyguard telling it to show itself
1334 private void showLocked(Bundle options) {
1335 Trace.beginSection("KeyguardViewMediator#showLocked aqcuiring mShowKeyguardWakeLock");
1336 if (DEBUG) Log.d(TAG, "showLocked");
1337 // ensure we stay awake until we are finished displaying the keyguard
1338 mShowKeyguardWakeLock.acquire();
1339 Message msg = mHandler.obtainMessage(SHOW, options);
1340 mHandler.sendMessage(msg);
1345 * Send message to keyguard telling it to hide itself
1346 * @see #handleHide()
1348 private void hideLocked() {
1349 Trace.beginSection("KeyguardViewMediator#hideLocked");
1350 if (DEBUG) Log.d(TAG, "hideLocked");
1351 Message msg = mHandler.obtainMessage(HIDE);
1352 mHandler.sendMessage(msg);
1356 public boolean isSecure() {
1357 return mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser())
1358 || KeyguardUpdateMonitor.getInstance(mContext).isSimPinSecure();
1362 * Update the newUserId. Call while holding WindowManagerService lock.
1363 * NOTE: Should only be called by KeyguardViewMediator in response to the user id changing.
1365 * @param newUserId The id of the incoming user.
1367 public void setCurrentUser(int newUserId) {
1368 KeyguardUpdateMonitor.setCurrentUser(newUserId);
1369 synchronized (this) {
1370 notifyTrustedChangedLocked(mUpdateMonitor.getUserHasTrust(newUserId));
1374 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1376 public void onReceive(Context context, Intent intent) {
1377 if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) {
1378 final int sequence = intent.getIntExtra("seq", 0);
1379 if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = "
1380 + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence);
1381 synchronized (KeyguardViewMediator.this) {
1382 if (mDelayedShowingSequence == sequence) {
1383 doKeyguardLocked(null);
1386 } else if (DELAYED_LOCK_PROFILE_ACTION.equals(intent.getAction())) {
1387 final int sequence = intent.getIntExtra("seq", 0);
1388 int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, 0);
1390 synchronized (KeyguardViewMediator.this) {
1391 if (mDelayedProfileShowingSequence == sequence) {
1392 lockProfile(userId);
1400 public void keyguardDone(boolean authenticated) {
1401 Trace.beginSection("KeyguardViewMediator#keyguardDone");
1402 if (DEBUG) Log.d(TAG, "keyguardDone(" + authenticated +")");
1404 EventLog.writeEvent(70000, 2);
1405 Message msg = mHandler.obtainMessage(KEYGUARD_DONE, authenticated ? 1 : 0);
1406 mHandler.sendMessage(msg);
1411 * This handler will be associated with the policy thread, which will also
1412 * be the UI thread of the keyguard. Since the apis of the policy, and therefore
1413 * this class, can be called by other threads, any action that directly
1414 * interacts with the keyguard ui should be posted to this handler, rather
1415 * than called directly.
1417 private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) {
1419 public void handleMessage(Message msg) {
1422 handleShow((Bundle) msg.obj);
1431 Trace.beginSection("KeyguardViewMediator#handleMessage VERIFY_UNLOCK");
1432 handleVerifyUnlock();
1435 case NOTIFY_STARTED_GOING_TO_SLEEP:
1436 handleNotifyStartedGoingToSleep();
1438 case NOTIFY_FINISHED_GOING_TO_SLEEP:
1439 handleNotifyFinishedGoingToSleep();
1441 case NOTIFY_SCREEN_TURNING_ON:
1442 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNING_ON");
1443 handleNotifyScreenTurningOn((IKeyguardDrawnCallback) msg.obj);
1446 case NOTIFY_SCREEN_TURNED_ON:
1447 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_SCREEN_TURNED_ON");
1448 handleNotifyScreenTurnedOn();
1451 case NOTIFY_SCREEN_TURNED_OFF:
1452 handleNotifyScreenTurnedOff();
1454 case NOTIFY_STARTED_WAKING_UP:
1455 Trace.beginSection("KeyguardViewMediator#handleMessage NOTIFY_STARTED_WAKING_UP");
1456 handleNotifyStartedWakingUp();
1460 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE");
1461 handleKeyguardDone(msg.arg1 != 0);
1464 case KEYGUARD_DONE_DRAWING:
1465 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_DRAWING");
1466 handleKeyguardDoneDrawing();
1470 Trace.beginSection("KeyguardViewMediator#handleMessage SET_OCCLUDED");
1471 handleSetOccluded(msg.arg1 != 0);
1474 case KEYGUARD_TIMEOUT:
1475 synchronized (KeyguardViewMediator.this) {
1476 doKeyguardLocked((Bundle) msg.obj);
1480 handleDismiss(msg.arg1 == 1 ? true : false /* allowWhileOccluded */);
1482 case START_KEYGUARD_EXIT_ANIM:
1483 Trace.beginSection("KeyguardViewMediator#handleMessage START_KEYGUARD_EXIT_ANIM");
1484 StartKeyguardExitAnimParams params = (StartKeyguardExitAnimParams) msg.obj;
1485 handleStartKeyguardExitAnimation(params.startTime, params.fadeoutDuration);
1486 FalsingManager.getInstance(mContext).onSucccessfulUnlock();
1489 case KEYGUARD_DONE_PENDING_TIMEOUT:
1490 Trace.beginSection("KeyguardViewMediator#handleMessage KEYGUARD_DONE_PENDING_TIMEOUT");
1491 Log.w(TAG, "Timeout while waiting for activity drawn!");
1494 case ON_ACTIVITY_DRAWN:
1495 handleOnActivityDrawn();
1502 * @see #keyguardDone
1503 * @see #KEYGUARD_DONE
1505 private void handleKeyguardDone(boolean authenticated) {
1506 Trace.beginSection("KeyguardViewMediator#handleKeyguardDone");
1507 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
1508 if (mLockPatternUtils.isSecure(currentUser)) {
1509 mLockPatternUtils.getDevicePolicyManager().reportKeyguardDismissed(currentUser);
1511 if (DEBUG) Log.d(TAG, "handleKeyguardDone");
1512 synchronized (this) {
1513 resetKeyguardDonePendingLocked();
1516 if (authenticated) {
1517 mUpdateMonitor.clearFailedUnlockAttempts();
1519 mUpdateMonitor.clearFingerprintRecognized();
1521 if (mGoingToSleep) {
1522 Log.i(TAG, "Device is going to sleep, aborting keyguardDone");
1525 if (mExitSecureCallback != null) {
1527 mExitSecureCallback.onKeyguardExitResult(authenticated);
1528 } catch (RemoteException e) {
1529 Slog.w(TAG, "Failed to call onKeyguardExitResult(" + authenticated + ")", e);
1532 mExitSecureCallback = null;
1534 if (authenticated) {
1535 // after succesfully exiting securely, no need to reshow
1536 // the keyguard when they've released the lock
1537 mExternallyEnabled = true;
1538 mNeedToReshowWhenReenabled = false;
1539 updateInputRestricted();
1547 private void sendUserPresentBroadcast() {
1548 synchronized (this) {
1549 if (mBootCompleted) {
1550 int currentUserId = KeyguardUpdateMonitor.getCurrentUser();
1551 final UserHandle currentUser = new UserHandle(currentUserId);
1552 final UserManager um = (UserManager) mContext.getSystemService(
1553 Context.USER_SERVICE);
1554 for (int profileId : um.getProfileIdsWithDisabled(currentUser.getIdentifier())) {
1555 mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, UserHandle.of(profileId));
1557 getLockPatternUtils().userPresent(currentUserId);
1559 mBootSendUserPresent = true;
1565 * @see #keyguardDone
1566 * @see #KEYGUARD_DONE_DRAWING
1568 private void handleKeyguardDoneDrawing() {
1569 Trace.beginSection("KeyguardViewMediator#handleKeyguardDoneDrawing");
1570 synchronized(this) {
1571 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing");
1572 if (mWaitingUntilKeyguardVisible) {
1573 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible");
1574 mWaitingUntilKeyguardVisible = false;
1577 // there will usually be two of these sent, one as a timeout, and one
1578 // as a result of the callback, so remove any remaining messages from
1580 mHandler.removeMessages(KEYGUARD_DONE_DRAWING);
1586 private void playSounds(boolean locked) {
1587 playSound(locked ? mLockSoundId : mUnlockSoundId);
1590 private void playSound(int soundId) {
1591 if (soundId == 0) return;
1592 final ContentResolver cr = mContext.getContentResolver();
1593 if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) {
1595 mLockSounds.stop(mLockSoundStreamId);
1596 // Init mAudioManager
1597 if (mAudioManager == null) {
1598 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
1599 if (mAudioManager == null) return;
1600 mUiSoundsStreamType = mAudioManager.getUiSoundsStreamType();
1602 // If the stream is muted, don't play the sound
1603 if (mAudioManager.isStreamMute(mUiSoundsStreamType)) return;
1605 mLockSoundStreamId = mLockSounds.play(soundId,
1606 mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/);
1610 private void playTrustedSound() {
1611 playSound(mTrustedSoundId);
1614 private void updateActivityLockScreenState() {
1615 Trace.beginSection("KeyguardViewMediator#updateActivityLockScreenState");
1617 ActivityManagerNative.getDefault().setLockScreenShown(mShowing, mOccluded);
1618 } catch (RemoteException e) {
1624 * Handle message sent by {@link #showLocked}.
1627 private void handleShow(Bundle options) {
1628 Trace.beginSection("KeyguardViewMediator#handleShow");
1629 final int currentUser = KeyguardUpdateMonitor.getCurrentUser();
1630 if (mLockPatternUtils.isSecure(currentUser)) {
1631 mLockPatternUtils.getDevicePolicyManager().reportKeyguardSecured(currentUser);
1633 synchronized (KeyguardViewMediator.this) {
1634 if (!mSystemReady) {
1635 if (DEBUG) Log.d(TAG, "ignoring handleShow because system is not ready.");
1638 if (DEBUG) Log.d(TAG, "handleShow");
1641 setShowingLocked(true);
1642 mStatusBarKeyguardViewManager.show(options);
1644 mWakeAndUnlocking = false;
1645 resetKeyguardDonePendingLocked();
1646 mHideAnimationRun = false;
1647 updateActivityLockScreenState();
1648 adjustStatusBarLocked();
1651 mShowKeyguardWakeLock.release();
1653 mKeyguardDisplayManager.show();
1657 private final Runnable mKeyguardGoingAwayRunnable = new Runnable() {
1660 Trace.beginSection("KeyguardViewMediator.mKeyGuardGoingAwayRunnable");
1661 if (DEBUG) Log.d(TAG, "keyguardGoingAway");
1663 mStatusBarKeyguardViewManager.keyguardGoingAway();
1666 if (mStatusBarKeyguardViewManager.shouldDisableWindowAnimationsForUnlock()
1667 || mWakeAndUnlocking) {
1668 flags |= WindowManagerPolicy.KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS;
1670 if (mStatusBarKeyguardViewManager.isGoingToNotificationShade()) {
1671 flags |= WindowManagerPolicy.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE;
1673 if (mStatusBarKeyguardViewManager.isUnlockWithWallpaper()) {
1674 flags |= WindowManagerPolicy.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER;
1677 // Don't actually hide the Keyguard at the moment, wait for window
1678 // manager until it tells us it's safe to do so with
1679 // startKeyguardExitAnimation.
1680 ActivityManagerNative.getDefault().keyguardGoingAway(flags);
1681 } catch (RemoteException e) {
1682 Log.e(TAG, "Error while calling WindowManager", e);
1689 * Handle message sent by {@link #hideLocked()}
1692 private void handleHide() {
1693 Trace.beginSection("KeyguardViewMediator#handleHide");
1694 synchronized (KeyguardViewMediator.this) {
1695 if (DEBUG) Log.d(TAG, "handleHide");
1697 if (mustNotUnlockCurrentUser()) {
1698 // In split system user mode, we never unlock system user. The end user has to
1699 // switch to another user.
1700 // TODO: We should stop it early by disabling the swipe up flow. Right now swipe up
1701 // still completes and makes the screen blank.
1702 if (DEBUG) Log.d(TAG, "Split system user, quit unlocking.");
1706 if (mShowing && !mOccluded) {
1707 if (!mHideAnimationRun) {
1708 mStatusBarKeyguardViewManager.startPreHideAnimation(mKeyguardGoingAwayRunnable);
1710 mKeyguardGoingAwayRunnable.run();
1714 // Don't try to rely on WindowManager - if Keyguard wasn't showing, window
1715 // manager won't start the exit animation.
1716 handleStartKeyguardExitAnimation(
1717 SystemClock.uptimeMillis() + mHideAnimation.getStartOffset(),
1718 mHideAnimation.getDuration());
1724 private void handleOnActivityDrawn() {
1725 if (DEBUG) Log.d(TAG, "handleOnActivityDrawn: mKeyguardDonePending=" + mKeyguardDonePending);
1726 if (mKeyguardDonePending) {
1727 mStatusBarKeyguardViewManager.onActivityDrawn();
1731 private void handleStartKeyguardExitAnimation(long startTime, long fadeoutDuration) {
1732 Trace.beginSection("KeyguardViewMediator#handleStartKeyguardExitAnimation");
1733 if (DEBUG) Log.d(TAG, "handleStartKeyguardExitAnimation startTime=" + startTime
1734 + " fadeoutDuration=" + fadeoutDuration);
1735 synchronized (KeyguardViewMediator.this) {
1742 if (mWakeAndUnlocking && mDrawnCallback != null) {
1744 // Hack level over 9000: To speed up wake-and-unlock sequence, force it to report
1745 // the next draw from here so we don't have to wait for window manager to signal
1746 // this to our ViewRootImpl.
1747 mStatusBarKeyguardViewManager.getViewRootImpl().setReportNextDraw();
1748 notifyDrawn(mDrawnCallback);
1749 mDrawnCallback = null;
1752 // only play "unlock" noises if not on a call (since the incall UI
1753 // disables the keyguard)
1754 if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) {
1758 mWakeAndUnlocking = false;
1759 setShowingLocked(false);
1760 mStatusBarKeyguardViewManager.hide(startTime, fadeoutDuration);
1761 resetKeyguardDonePendingLocked();
1762 mHideAnimationRun = false;
1763 updateActivityLockScreenState();
1764 adjustStatusBarLocked();
1765 sendUserPresentBroadcast();
1770 private void adjustStatusBarLocked() {
1771 if (mStatusBarManager == null) {
1772 mStatusBarManager = (StatusBarManager)
1773 mContext.getSystemService(Context.STATUS_BAR_SERVICE);
1775 if (mStatusBarManager == null) {
1776 Log.w(TAG, "Could not get status bar manager");
1778 // Disable aspects of the system/status/navigation bars that must not be re-enabled by
1779 // windows that appear on top, ever
1780 int flags = StatusBarManager.DISABLE_NONE;
1782 // Permanently disable components not available when keyguard is enabled
1783 // (like recents). Temporary enable/disable (e.g. the "back" button) are
1784 // done in KeyguardHostView.
1785 flags |= StatusBarManager.DISABLE_RECENT;
1786 flags |= StatusBarManager.DISABLE_SEARCH;
1788 if (isShowingAndNotOccluded()) {
1789 flags |= StatusBarManager.DISABLE_HOME;
1793 Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mOccluded=" + mOccluded
1794 + " isSecure=" + isSecure() + " --> flags=0x" + Integer.toHexString(flags));
1797 if (!(mContext instanceof Activity)) {
1798 mStatusBarManager.disable(flags);
1804 * Handle message sent by {@link #resetStateLocked}
1807 private void handleReset() {
1808 synchronized (KeyguardViewMediator.this) {
1809 if (DEBUG) Log.d(TAG, "handleReset");
1810 mStatusBarKeyguardViewManager.reset();
1815 * Handle message sent by {@link #verifyUnlock}
1816 * @see #VERIFY_UNLOCK
1818 private void handleVerifyUnlock() {
1819 Trace.beginSection("KeyguardViewMediator#handleVerifyUnlock");
1820 synchronized (KeyguardViewMediator.this) {
1821 if (DEBUG) Log.d(TAG, "handleVerifyUnlock");
1822 setShowingLocked(true);
1823 mStatusBarKeyguardViewManager.verifyUnlock();
1824 updateActivityLockScreenState();
1829 private void handleNotifyStartedGoingToSleep() {
1830 synchronized (KeyguardViewMediator.this) {
1831 if (DEBUG) Log.d(TAG, "handleNotifyStartedGoingToSleep");
1832 mStatusBarKeyguardViewManager.onStartedGoingToSleep();
1837 * Handle message sent by {@link #notifyFinishedGoingToSleep()}
1838 * @see #NOTIFY_FINISHED_GOING_TO_SLEEP
1840 private void handleNotifyFinishedGoingToSleep() {
1841 synchronized (KeyguardViewMediator.this) {
1842 if (DEBUG) Log.d(TAG, "handleNotifyFinishedGoingToSleep");
1843 mStatusBarKeyguardViewManager.onFinishedGoingToSleep();
1847 private void handleNotifyStartedWakingUp() {
1848 Trace.beginSection("KeyguardViewMediator#handleMotifyStartedWakingUp");
1849 synchronized (KeyguardViewMediator.this) {
1850 if (DEBUG) Log.d(TAG, "handleNotifyWakingUp");
1851 mStatusBarKeyguardViewManager.onStartedWakingUp();
1856 private void handleNotifyScreenTurningOn(IKeyguardDrawnCallback callback) {
1857 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurningOn");
1858 synchronized (KeyguardViewMediator.this) {
1859 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurningOn");
1860 mStatusBarKeyguardViewManager.onScreenTurningOn();
1861 if (callback != null) {
1862 if (mWakeAndUnlocking) {
1863 mDrawnCallback = callback;
1865 notifyDrawn(callback);
1872 private void handleNotifyScreenTurnedOn() {
1873 Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurnedOn");
1874 synchronized (this) {
1875 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOn");
1876 mStatusBarKeyguardViewManager.onScreenTurnedOn();
1881 private void handleNotifyScreenTurnedOff() {
1882 synchronized (this) {
1883 if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOff");
1884 mStatusBarKeyguardViewManager.onScreenTurnedOff();
1885 mDrawnCallback = null;
1886 mWakeAndUnlocking = false;
1890 private void notifyDrawn(final IKeyguardDrawnCallback callback) {
1891 Trace.beginSection("KeyguardViewMediator#notifyDrawn");
1894 } catch (RemoteException e) {
1895 Slog.w(TAG, "Exception calling onDrawn():", e);
1900 private void resetKeyguardDonePendingLocked() {
1901 mKeyguardDonePending = false;
1902 mHandler.removeMessages(KEYGUARD_DONE_PENDING_TIMEOUT);
1906 public void onBootCompleted() {
1907 mUpdateMonitor.dispatchBootCompleted();
1908 synchronized (this) {
1909 mBootCompleted = true;
1910 if (mBootSendUserPresent) {
1911 sendUserPresentBroadcast();
1916 public void onWakeAndUnlocking() {
1917 Trace.beginSection("KeyguardViewMediator#onWakeAndUnlocking");
1918 mWakeAndUnlocking = true;
1919 keyguardDone(true /* authenticated */);
1923 public StatusBarKeyguardViewManager registerStatusBar(PhoneStatusBar phoneStatusBar,
1924 ViewGroup container, StatusBarWindowManager statusBarWindowManager,
1925 ScrimController scrimController,
1926 FingerprintUnlockController fingerprintUnlockController) {
1927 mStatusBarKeyguardViewManager.registerStatusBar(phoneStatusBar, container,
1928 statusBarWindowManager, scrimController, fingerprintUnlockController);
1929 return mStatusBarKeyguardViewManager;
1932 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
1933 Trace.beginSection("KeyguardViewMediator#startKeyguardExitAnimation");
1934 Message msg = mHandler.obtainMessage(START_KEYGUARD_EXIT_ANIM,
1935 new StartKeyguardExitAnimParams(startTime, fadeoutDuration));
1936 mHandler.sendMessage(msg);
1940 public void onActivityDrawn() {
1941 mHandler.sendEmptyMessage(ON_ACTIVITY_DRAWN);
1944 public ViewMediatorCallback getViewMediatorCallback() {
1945 return mViewMediatorCallback;
1948 public LockPatternUtils getLockPatternUtils() {
1949 return mLockPatternUtils;
1953 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1954 pw.print(" mSystemReady: "); pw.println(mSystemReady);
1955 pw.print(" mBootCompleted: "); pw.println(mBootCompleted);
1956 pw.print(" mBootSendUserPresent: "); pw.println(mBootSendUserPresent);
1957 pw.print(" mExternallyEnabled: "); pw.println(mExternallyEnabled);
1958 pw.print(" mNeedToReshowWhenReenabled: "); pw.println(mNeedToReshowWhenReenabled);
1959 pw.print(" mShowing: "); pw.println(mShowing);
1960 pw.print(" mInputRestricted: "); pw.println(mInputRestricted);
1961 pw.print(" mOccluded: "); pw.println(mOccluded);
1962 pw.print(" mDelayedShowingSequence: "); pw.println(mDelayedShowingSequence);
1963 pw.print(" mExitSecureCallback: "); pw.println(mExitSecureCallback);
1964 pw.print(" mDeviceInteractive: "); pw.println(mDeviceInteractive);
1965 pw.print(" mGoingToSleep: "); pw.println(mGoingToSleep);
1966 pw.print(" mHiding: "); pw.println(mHiding);
1967 pw.print(" mWaitingUntilKeyguardVisible: "); pw.println(mWaitingUntilKeyguardVisible);
1968 pw.print(" mKeyguardDonePending: "); pw.println(mKeyguardDonePending);
1969 pw.print(" mHideAnimationRun: "); pw.println(mHideAnimationRun);
1970 pw.print(" mPendingReset: "); pw.println(mPendingReset);
1971 pw.print(" mPendingLock: "); pw.println(mPendingLock);
1972 pw.print(" mWakeAndUnlocking: "); pw.println(mWakeAndUnlocking);
1973 pw.print(" mDrawnCallback: "); pw.println(mDrawnCallback);
1976 private static class StartKeyguardExitAnimParams {
1979 long fadeoutDuration;
1981 private StartKeyguardExitAnimParams(long startTime, long fadeoutDuration) {
1982 this.startTime = startTime;
1983 this.fadeoutDuration = fadeoutDuration;
1987 private void setShowingLocked(boolean showing) {
1988 if (showing != mShowing) {
1990 int size = mKeyguardStateCallbacks.size();
1991 for (int i = size - 1; i >= 0; i--) {
1993 mKeyguardStateCallbacks.get(i).onShowingStateChanged(showing);
1994 } catch (RemoteException e) {
1995 Slog.w(TAG, "Failed to call onShowingStateChanged", e);
1996 if (e instanceof DeadObjectException) {
1997 mKeyguardStateCallbacks.remove(i);
2001 updateInputRestrictedLocked();
2002 mTrustManager.reportKeyguardShowingChanged();
2006 private void notifyTrustedChangedLocked(boolean trusted) {
2007 int size = mKeyguardStateCallbacks.size();
2008 for (int i = size - 1; i >= 0; i--) {
2010 mKeyguardStateCallbacks.get(i).onTrustedChanged(trusted);
2011 } catch (RemoteException e) {
2012 Slog.w(TAG, "Failed to call notifyTrustedChangedLocked", e);
2013 if (e instanceof DeadObjectException) {
2014 mKeyguardStateCallbacks.remove(i);
2020 private void notifyHasLockscreenWallpaperChanged(boolean hasLockscreenWallpaper) {
2021 int size = mKeyguardStateCallbacks.size();
2022 for (int i = size - 1; i >= 0; i--) {
2024 mKeyguardStateCallbacks.get(i).onHasLockscreenWallpaperChanged(
2025 hasLockscreenWallpaper);
2026 } catch (RemoteException e) {
2027 Slog.w(TAG, "Failed to call onHasLockscreenWallpaperChanged", e);
2028 if (e instanceof DeadObjectException) {
2029 mKeyguardStateCallbacks.remove(i);
2035 public void addStateMonitorCallback(IKeyguardStateCallback callback) {
2036 synchronized (this) {
2037 mKeyguardStateCallbacks.add(callback);
2039 callback.onSimSecureStateChanged(mUpdateMonitor.isSimPinSecure());
2040 callback.onShowingStateChanged(mShowing);
2041 callback.onInputRestrictedStateChanged(mInputRestricted);
2042 callback.onTrustedChanged(mUpdateMonitor.getUserHasTrust(
2043 KeyguardUpdateMonitor.getCurrentUser()));
2044 callback.onHasLockscreenWallpaperChanged(mUpdateMonitor.hasLockscreenWallpaper());
2045 } catch (RemoteException e) {
2046 Slog.w(TAG, "Failed to call to IKeyguardStateCallback", e);