KeyguardViewMediator.java revision b690f0d5023fcf144f2701058d5a6f88d66cc97a
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 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 14 * limitations under the License 15 */ 16 17package com.android.systemui.keyguard; 18 19import android.app.Activity; 20import android.app.ActivityManagerNative; 21import android.app.AlarmManager; 22import android.app.PendingIntent; 23import android.app.SearchManager; 24import android.app.StatusBarManager; 25import android.content.BroadcastReceiver; 26import android.content.ContentResolver; 27import android.content.Context; 28import android.content.Intent; 29import android.content.IntentFilter; 30import android.media.AudioManager; 31import android.media.SoundPool; 32import android.os.Bundle; 33import android.os.Handler; 34import android.os.Looper; 35import android.os.Message; 36import android.os.PowerManager; 37import android.os.RemoteException; 38import android.os.SystemClock; 39import android.os.SystemProperties; 40import android.os.UserHandle; 41import android.os.UserManager; 42import android.provider.Settings; 43import android.telephony.TelephonyManager; 44import android.util.EventLog; 45import android.util.Log; 46import android.util.Slog; 47import android.view.IWindowManager; 48import android.view.ViewGroup; 49import android.view.WindowManagerGlobal; 50import android.view.WindowManagerPolicy; 51 52import com.android.internal.policy.IKeyguardExitCallback; 53import com.android.internal.policy.IKeyguardShowCallback; 54import com.android.internal.telephony.IccCardConstants; 55import com.android.internal.widget.LockPatternUtils; 56import com.android.keyguard.KeyguardDisplayManager; 57import com.android.keyguard.KeyguardUpdateMonitor; 58import com.android.keyguard.KeyguardUpdateMonitorCallback; 59import com.android.keyguard.MultiUserAvatarCache; 60import com.android.keyguard.ViewMediatorCallback; 61import com.android.systemui.SystemUI; 62import com.android.systemui.statusbar.phone.PhoneStatusBar; 63import com.android.systemui.statusbar.phone.ScrimController; 64import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; 65import com.android.systemui.statusbar.phone.StatusBarWindowManager; 66 67import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT; 68 69 70/** 71 * Mediates requests related to the keyguard. This includes queries about the 72 * state of the keyguard, power management events that effect whether the keyguard 73 * should be shown or reset, callbacks to the phone window manager to notify 74 * it of when the keyguard is showing, and events from the keyguard view itself 75 * stating that the keyguard was succesfully unlocked. 76 * 77 * Note that the keyguard view is shown when the screen is off (as appropriate) 78 * so that once the screen comes on, it will be ready immediately. 79 * 80 * Example queries about the keyguard: 81 * - is {movement, key} one that should wake the keygaurd? 82 * - is the keyguard showing? 83 * - are input events restricted due to the state of the keyguard? 84 * 85 * Callbacks to the phone window manager: 86 * - the keyguard is showing 87 * 88 * Example external events that translate to keyguard view changes: 89 * - screen turned off -> reset the keyguard, and show it so it will be ready 90 * next time the screen turns on 91 * - keyboard is slid open -> if the keyguard is not secure, hide it 92 * 93 * Events from the keyguard view: 94 * - user succesfully unlocked keyguard -> hide keyguard view, and no longer 95 * restrict input events. 96 * 97 * Note: in addition to normal power managment events that effect the state of 98 * whether the keyguard should be showing, external apps and services may request 99 * that the keyguard be disabled via {@link #setKeyguardEnabled(boolean)}. When 100 * false, this will override all other conditions for turning on the keyguard. 101 * 102 * Threading and synchronization: 103 * This class is created by the initialization routine of the {@link android.view.WindowManagerPolicy}, 104 * and runs on its thread. The keyguard UI is created from that thread in the 105 * constructor of this class. The apis may be called from other threads, including the 106 * {@link com.android.server.input.InputManagerService}'s and {@link android.view.WindowManager}'s. 107 * Therefore, methods on this class are synchronized, and any action that is pointed 108 * directly to the keyguard UI is posted to a {@link android.os.Handler} to ensure it is taken on the UI 109 * thread of the keyguard. 110 */ 111public class KeyguardViewMediator extends SystemUI { 112 private static final int KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT = 30000; 113 final static boolean DEBUG = false; 114 private final static boolean DBG_WAKE = false; 115 116 private final static String TAG = "KeyguardViewMediator"; 117 118 private static final String DELAYED_KEYGUARD_ACTION = 119 "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD"; 120 121 // used for handler messages 122 private static final int SHOW = 2; 123 private static final int HIDE = 3; 124 private static final int RESET = 4; 125 private static final int VERIFY_UNLOCK = 5; 126 private static final int NOTIFY_SCREEN_OFF = 6; 127 private static final int NOTIFY_SCREEN_ON = 7; 128 private static final int KEYGUARD_DONE = 9; 129 private static final int KEYGUARD_DONE_DRAWING = 10; 130 private static final int KEYGUARD_DONE_AUTHENTICATING = 11; 131 private static final int SET_OCCLUDED = 12; 132 private static final int KEYGUARD_TIMEOUT = 13; 133 private static final int DISMISS = 17; 134 private static final int START_KEYGUARD_EXIT_ANIM = 18; 135 136 /** 137 * The default amount of time we stay awake (used for all key input) 138 */ 139 public static final int AWAKE_INTERVAL_DEFAULT_MS = 10000; 140 141 /** 142 * How long to wait after the screen turns off due to timeout before 143 * turning on the keyguard (i.e, the user has this much time to turn 144 * the screen back on without having to face the keyguard). 145 */ 146 private static final int KEYGUARD_LOCK_AFTER_DELAY_DEFAULT = 5000; 147 148 /** 149 * How long we'll wait for the {@link ViewMediatorCallback#keyguardDoneDrawing()} 150 * callback before unblocking a call to {@link #setKeyguardEnabled(boolean)} 151 * that is reenabling the keyguard. 152 */ 153 private static final int KEYGUARD_DONE_DRAWING_TIMEOUT_MS = 2000; 154 155 /** 156 * Secure setting whether analytics are collected on the keyguard. 157 */ 158 private static final String KEYGUARD_ANALYTICS_SETTING = "keyguard_analytics"; 159 160 /** The stream type that the lock sounds are tied to. */ 161 private int mMasterStreamType; 162 163 private AlarmManager mAlarmManager; 164 private AudioManager mAudioManager; 165 private StatusBarManager mStatusBarManager; 166 private boolean mSwitchingUser; 167 168 private boolean mSystemReady; 169 170 // Whether the next call to playSounds() should be skipped. Defaults to 171 // true because the first lock (on boot) should be silent. 172 private boolean mSuppressNextLockSound = true; 173 174 175 /** High level access to the power manager for WakeLocks */ 176 private PowerManager mPM; 177 178 /** High level access to the window manager for dismissing keyguard animation */ 179 private IWindowManager mWM; 180 181 /** UserManager for querying number of users */ 182 private UserManager mUserManager; 183 184 /** SearchManager for determining whether or not search assistant is available */ 185 private SearchManager mSearchManager; 186 187 /** 188 * Used to keep the device awake while to ensure the keyguard finishes opening before 189 * we sleep. 190 */ 191 private PowerManager.WakeLock mShowKeyguardWakeLock; 192 193 private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager; 194 195 // these are protected by synchronized (this) 196 197 /** 198 * External apps (like the phone app) can tell us to disable the keygaurd. 199 */ 200 private boolean mExternallyEnabled = true; 201 202 /** 203 * Remember if an external call to {@link #setKeyguardEnabled} with value 204 * false caused us to hide the keyguard, so that we need to reshow it once 205 * the keygaurd is reenabled with another call with value true. 206 */ 207 private boolean mNeedToReshowWhenReenabled = false; 208 209 // cached value of whether we are showing (need to know this to quickly 210 // answer whether the input should be restricted) 211 private boolean mShowing; 212 213 // true if the keyguard is hidden by another window 214 private boolean mOccluded = false; 215 216 /** 217 * Helps remember whether the screen has turned on since the last time 218 * it turned off due to timeout. see {@link #onScreenTurnedOff(int)} 219 */ 220 private int mDelayedShowingSequence; 221 222 /** 223 * If the user has disabled the keyguard, then requests to exit, this is 224 * how we'll ultimately let them know whether it was successful. We use this 225 * var being non-null as an indicator that there is an in progress request. 226 */ 227 private IKeyguardExitCallback mExitSecureCallback; 228 229 // the properties of the keyguard 230 231 private KeyguardUpdateMonitor mUpdateMonitor; 232 233 private boolean mScreenOn; 234 235 // last known state of the cellular connection 236 private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE; 237 238 /** 239 * Whether a hide is pending an we are just waiting for #startKeyguardExitAnimation to be 240 * called. 241 * */ 242 private boolean mHiding; 243 244 /** 245 * we send this intent when the keyguard is dismissed. 246 */ 247 private static final Intent USER_PRESENT_INTENT = new Intent(Intent.ACTION_USER_PRESENT) 248 .addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING 249 | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); 250 251 /** 252 * {@link #setKeyguardEnabled} waits on this condition when it reenables 253 * the keyguard. 254 */ 255 private boolean mWaitingUntilKeyguardVisible = false; 256 private LockPatternUtils mLockPatternUtils; 257 private boolean mKeyguardDonePending = false; 258 259 private SoundPool mLockSounds; 260 private int mLockSoundId; 261 private int mUnlockSoundId; 262 private int mLockSoundStreamId; 263 264 /** 265 * The volume applied to the lock/unlock sounds. 266 */ 267 private float mLockSoundVolume; 268 269 /** 270 * For managing external displays 271 */ 272 private KeyguardDisplayManager mKeyguardDisplayManager; 273 274 KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() { 275 276 @Override 277 public void onUserSwitching(int userId) { 278 // Note that the mLockPatternUtils user has already been updated from setCurrentUser. 279 // We need to force a reset of the views, since lockNow (called by 280 // ActivityManagerService) will not reconstruct the keyguard if it is already showing. 281 synchronized (KeyguardViewMediator.this) { 282 mSwitchingUser = true; 283 resetStateLocked(); 284 adjustStatusBarLocked(); 285 // When we switch users we want to bring the new user to the biometric unlock even 286 // if the current user has gone to the backup. 287 KeyguardUpdateMonitor.getInstance(mContext).setAlternateUnlockEnabled(true); 288 } 289 } 290 291 @Override 292 public void onUserSwitchComplete(int userId) { 293 mSwitchingUser = false; 294 } 295 296 @Override 297 public void onUserRemoved(int userId) { 298 mLockPatternUtils.removeUser(userId); 299 MultiUserAvatarCache.getInstance().clear(userId); 300 } 301 302 @Override 303 public void onUserInfoChanged(int userId) { 304 MultiUserAvatarCache.getInstance().clear(userId); 305 } 306 307 @Override 308 public void onPhoneStateChanged(int phoneState) { 309 synchronized (KeyguardViewMediator.this) { 310 if (TelephonyManager.CALL_STATE_IDLE == phoneState // call ending 311 && !mScreenOn // screen off 312 && mExternallyEnabled) { // not disabled by any app 313 314 // note: this is a way to gracefully reenable the keyguard when the call 315 // ends and the screen is off without always reenabling the keyguard 316 // each time the screen turns off while in call (and having an occasional ugly 317 // flicker while turning back on the screen and disabling the keyguard again). 318 if (DEBUG) Log.d(TAG, "screen is off and call ended, let's make sure the " 319 + "keyguard is showing"); 320 doKeyguardLocked(null); 321 } 322 } 323 } 324 325 @Override 326 public void onClockVisibilityChanged() { 327 adjustStatusBarLocked(); 328 } 329 330 @Override 331 public void onDeviceProvisioned() { 332 sendUserPresentBroadcast(); 333 } 334 335 @Override 336 public void onSimStateChanged(IccCardConstants.State simState) { 337 if (DEBUG) Log.d(TAG, "onSimStateChanged: " + simState); 338 339 switch (simState) { 340 case NOT_READY: 341 case ABSENT: 342 // only force lock screen in case of missing sim if user hasn't 343 // gone through setup wizard 344 synchronized (this) { 345 if (!mUpdateMonitor.isDeviceProvisioned()) { 346 if (!isShowing()) { 347 if (DEBUG) Log.d(TAG, "ICC_ABSENT isn't showing," 348 + " we need to show the keyguard since the " 349 + "device isn't provisioned yet."); 350 doKeyguardLocked(null); 351 } else { 352 resetStateLocked(); 353 } 354 } 355 } 356 break; 357 case PIN_REQUIRED: 358 case PUK_REQUIRED: 359 synchronized (this) { 360 if (!isShowing()) { 361 if (DEBUG) Log.d(TAG, "INTENT_VALUE_ICC_LOCKED and keygaurd isn't " 362 + "showing; need to show keyguard so user can enter sim pin"); 363 doKeyguardLocked(null); 364 } else { 365 resetStateLocked(); 366 } 367 } 368 break; 369 case PERM_DISABLED: 370 synchronized (this) { 371 if (!isShowing()) { 372 if (DEBUG) Log.d(TAG, "PERM_DISABLED and " 373 + "keygaurd isn't showing."); 374 doKeyguardLocked(null); 375 } else { 376 if (DEBUG) Log.d(TAG, "PERM_DISABLED, resetStateLocked to" 377 + "show permanently disabled message in lockscreen."); 378 resetStateLocked(); 379 } 380 } 381 break; 382 case READY: 383 synchronized (this) { 384 if (isShowing()) { 385 resetStateLocked(); 386 } 387 } 388 break; 389 } 390 } 391 392 public void onFingerprintRecognized(int userId) { 393 if (mStatusBarKeyguardViewManager.isBouncerShowing()) { 394 mViewMediatorCallback.keyguardDone(true); 395 } 396 }; 397 398 }; 399 400 ViewMediatorCallback mViewMediatorCallback = new ViewMediatorCallback() { 401 402 public void userActivity() { 403 KeyguardViewMediator.this.userActivity(); 404 } 405 406 public void keyguardDone(boolean authenticated) { 407 KeyguardViewMediator.this.keyguardDone(authenticated, true); 408 } 409 410 public void keyguardDoneDrawing() { 411 mHandler.sendEmptyMessage(KEYGUARD_DONE_DRAWING); 412 } 413 414 @Override 415 public void setNeedsInput(boolean needsInput) { 416 mStatusBarKeyguardViewManager.setNeedsInput(needsInput); 417 } 418 419 @Override 420 public void onUserActivityTimeoutChanged() { 421 mStatusBarKeyguardViewManager.updateUserActivityTimeout(); 422 } 423 424 @Override 425 public void keyguardDonePending() { 426 mKeyguardDonePending = true; 427 } 428 429 @Override 430 public void keyguardGone() { 431 mKeyguardDisplayManager.hide(); 432 } 433 }; 434 435 public void userActivity() { 436 mPM.userActivity(SystemClock.uptimeMillis(), false); 437 } 438 439 private void setup() { 440 mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); 441 mWM = WindowManagerGlobal.getWindowManagerService(); 442 mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); 443 mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard"); 444 mShowKeyguardWakeLock.setReferenceCounted(false); 445 446 mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(DELAYED_KEYGUARD_ACTION)); 447 448 mKeyguardDisplayManager = new KeyguardDisplayManager(mContext); 449 450 mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); 451 452 mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext); 453 454 mLockPatternUtils = new LockPatternUtils(mContext); 455 mLockPatternUtils.setCurrentUser(UserHandle.USER_OWNER); 456 457 // Assume keyguard is showing (unless it's disabled) until we know for sure... 458 mShowing = (mUpdateMonitor.isDeviceProvisioned() || mLockPatternUtils.isSecure()) 459 && !mLockPatternUtils.isLockScreenDisabled(); 460 461 mStatusBarKeyguardViewManager = new StatusBarKeyguardViewManager(mContext, 462 mViewMediatorCallback, mLockPatternUtils); 463 final ContentResolver cr = mContext.getContentResolver(); 464 465 mScreenOn = mPM.isScreenOn(); 466 467 mLockSounds = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0); 468 String soundPath = Settings.Global.getString(cr, Settings.Global.LOCK_SOUND); 469 if (soundPath != null) { 470 mLockSoundId = mLockSounds.load(soundPath, 1); 471 } 472 if (soundPath == null || mLockSoundId == 0) { 473 Log.w(TAG, "failed to load lock sound from " + soundPath); 474 } 475 soundPath = Settings.Global.getString(cr, Settings.Global.UNLOCK_SOUND); 476 if (soundPath != null) { 477 mUnlockSoundId = mLockSounds.load(soundPath, 1); 478 } 479 if (soundPath == null || mUnlockSoundId == 0) { 480 Log.w(TAG, "failed to load unlock sound from " + soundPath); 481 } 482 int lockSoundDefaultAttenuation = mContext.getResources().getInteger( 483 com.android.internal.R.integer.config_lockSoundVolumeDb); 484 mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20); 485 } 486 487 @Override 488 public void start() { 489 setup(); 490 putComponent(KeyguardViewMediator.class, this); 491 } 492 493 /** 494 * Let us know that the system is ready after startup. 495 */ 496 public void onSystemReady() { 497 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); 498 synchronized (this) { 499 if (DEBUG) Log.d(TAG, "onSystemReady"); 500 mSystemReady = true; 501 mUpdateMonitor.registerCallback(mUpdateCallback); 502 503 // Suppress biometric unlock right after boot until things have settled if it is the 504 // selected security method, otherwise unsuppress it. It must be unsuppressed if it is 505 // not the selected security method for the following reason: if the user starts 506 // without a screen lock selected, the biometric unlock would be suppressed the first 507 // time they try to use it. 508 // 509 // Note that the biometric unlock will still not show if it is not the selected method. 510 // Calling setAlternateUnlockEnabled(true) simply says don't suppress it if it is the 511 // selected method. 512 if (mLockPatternUtils.usingBiometricWeak() 513 && mLockPatternUtils.isBiometricWeakInstalled()) { 514 if (DEBUG) Log.d(TAG, "suppressing biometric unlock during boot"); 515 mUpdateMonitor.setAlternateUnlockEnabled(false); 516 } else { 517 mUpdateMonitor.setAlternateUnlockEnabled(true); 518 } 519 520 doKeyguardLocked(null); 521 } 522 // Most services aren't available until the system reaches the ready state, so we 523 // send it here when the device first boots. 524 maybeSendUserPresentBroadcast(); 525 } 526 527 /** 528 * Called to let us know the screen was turned off. 529 * @param why either {@link android.view.WindowManagerPolicy#OFF_BECAUSE_OF_USER} or 530 * {@link android.view.WindowManagerPolicy#OFF_BECAUSE_OF_TIMEOUT}. 531 */ 532 public void onScreenTurnedOff(int why) { 533 synchronized (this) { 534 mScreenOn = false; 535 if (DEBUG) Log.d(TAG, "onScreenTurnedOff(" + why + ")"); 536 537 mKeyguardDonePending = false; 538 539 // Lock immediately based on setting if secure (user has a pin/pattern/password). 540 // This also "locks" the device when not secure to provide easy access to the 541 // camera while preventing unwanted input. 542 final boolean lockImmediately = 543 mLockPatternUtils.getPowerButtonInstantlyLocks() || !mLockPatternUtils.isSecure(); 544 545 if (mExitSecureCallback != null) { 546 if (DEBUG) Log.d(TAG, "pending exit secure callback cancelled"); 547 try { 548 mExitSecureCallback.onKeyguardExitResult(false); 549 } catch (RemoteException e) { 550 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); 551 } 552 mExitSecureCallback = null; 553 if (!mExternallyEnabled) { 554 hideLocked(); 555 } 556 } else if (mShowing) { 557 notifyScreenOffLocked(); 558 resetStateLocked(); 559 } else if (why == WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT 560 || (why == WindowManagerPolicy.OFF_BECAUSE_OF_USER && !lockImmediately)) { 561 doKeyguardLaterLocked(); 562 } else { 563 doKeyguardLocked(null); 564 } 565 } 566 KeyguardUpdateMonitor.getInstance(mContext).dispatchScreenTurndOff(why); 567 } 568 569 private void doKeyguardLaterLocked() { 570 // if the screen turned off because of timeout or the user hit the power button 571 // and we don't need to lock immediately, set an alarm 572 // to enable it a little bit later (i.e, give the user a chance 573 // to turn the screen back on within a certain window without 574 // having to unlock the screen) 575 final ContentResolver cr = mContext.getContentResolver(); 576 577 // From DisplaySettings 578 long displayTimeout = Settings.System.getInt(cr, SCREEN_OFF_TIMEOUT, 579 KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT); 580 581 // From SecuritySettings 582 final long lockAfterTimeout = Settings.Secure.getInt(cr, 583 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT, 584 KEYGUARD_LOCK_AFTER_DELAY_DEFAULT); 585 586 // From DevicePolicyAdmin 587 final long policyTimeout = mLockPatternUtils.getDevicePolicyManager() 588 .getMaximumTimeToLock(null, mLockPatternUtils.getCurrentUser()); 589 590 long timeout; 591 if (policyTimeout > 0) { 592 // policy in effect. Make sure we don't go beyond policy limit. 593 displayTimeout = Math.max(displayTimeout, 0); // ignore negative values 594 timeout = Math.min(policyTimeout - displayTimeout, lockAfterTimeout); 595 } else { 596 timeout = lockAfterTimeout; 597 } 598 599 if (timeout <= 0) { 600 // Lock now 601 mSuppressNextLockSound = true; 602 doKeyguardLocked(null); 603 } else { 604 // Lock in the future 605 long when = SystemClock.elapsedRealtime() + timeout; 606 Intent intent = new Intent(DELAYED_KEYGUARD_ACTION); 607 intent.putExtra("seq", mDelayedShowingSequence); 608 PendingIntent sender = PendingIntent.getBroadcast(mContext, 609 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); 610 mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender); 611 if (DEBUG) Log.d(TAG, "setting alarm to turn off keyguard, seq = " 612 + mDelayedShowingSequence); 613 } 614 } 615 616 private void cancelDoKeyguardLaterLocked() { 617 mDelayedShowingSequence++; 618 } 619 620 /** 621 * Let's us know the screen was turned on. 622 */ 623 public void onScreenTurnedOn(IKeyguardShowCallback callback) { 624 synchronized (this) { 625 mScreenOn = true; 626 cancelDoKeyguardLaterLocked(); 627 if (DEBUG) Log.d(TAG, "onScreenTurnedOn, seq = " + mDelayedShowingSequence); 628 if (callback != null) { 629 notifyScreenOnLocked(callback); 630 } 631 } 632 KeyguardUpdateMonitor.getInstance(mContext).dispatchScreenTurnedOn(); 633 maybeSendUserPresentBroadcast(); 634 } 635 636 private void maybeSendUserPresentBroadcast() { 637 if (mSystemReady && mLockPatternUtils.isLockScreenDisabled() 638 && !mUserManager.isUserSwitcherEnabled()) { 639 // Lock screen is disabled because the user has set the preference to "None". 640 // In this case, send out ACTION_USER_PRESENT here instead of in 641 // handleKeyguardDone() 642 sendUserPresentBroadcast(); 643 } 644 } 645 646 /** 647 * A dream started. We should lock after the usual screen-off lock timeout but only 648 * if there is a secure lock pattern. 649 */ 650 public void onDreamingStarted() { 651 synchronized (this) { 652 if (mScreenOn && mLockPatternUtils.isSecure()) { 653 doKeyguardLaterLocked(); 654 } 655 } 656 } 657 658 /** 659 * A dream stopped. 660 */ 661 public void onDreamingStopped() { 662 synchronized (this) { 663 if (mScreenOn) { 664 cancelDoKeyguardLaterLocked(); 665 } 666 } 667 } 668 669 /** 670 * Same semantics as {@link android.view.WindowManagerPolicy#enableKeyguard}; provide 671 * a way for external stuff to override normal keyguard behavior. For instance 672 * the phone app disables the keyguard when it receives incoming calls. 673 */ 674 public void setKeyguardEnabled(boolean enabled) { 675 synchronized (this) { 676 if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")"); 677 678 mExternallyEnabled = enabled; 679 680 if (!enabled && mShowing) { 681 if (mExitSecureCallback != null) { 682 if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring"); 683 // we're in the process of handling a request to verify the user 684 // can get past the keyguard. ignore extraneous requests to disable / reenable 685 return; 686 } 687 688 // hiding keyguard that is showing, remember to reshow later 689 if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, " 690 + "disabling status bar expansion"); 691 mNeedToReshowWhenReenabled = true; 692 hideLocked(); 693 } else if (enabled && mNeedToReshowWhenReenabled) { 694 // reenabled after previously hidden, reshow 695 if (DEBUG) Log.d(TAG, "previously hidden, reshowing, reenabling " 696 + "status bar expansion"); 697 mNeedToReshowWhenReenabled = false; 698 699 if (mExitSecureCallback != null) { 700 if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting"); 701 try { 702 mExitSecureCallback.onKeyguardExitResult(false); 703 } catch (RemoteException e) { 704 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); 705 } 706 mExitSecureCallback = null; 707 resetStateLocked(); 708 } else { 709 showLocked(null); 710 711 // block until we know the keygaurd is done drawing (and post a message 712 // to unblock us after a timeout so we don't risk blocking too long 713 // and causing an ANR). 714 mWaitingUntilKeyguardVisible = true; 715 mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS); 716 if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false"); 717 while (mWaitingUntilKeyguardVisible) { 718 try { 719 wait(); 720 } catch (InterruptedException e) { 721 Thread.currentThread().interrupt(); 722 } 723 } 724 if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible"); 725 } 726 } 727 } 728 } 729 730 /** 731 * @see android.app.KeyguardManager#exitKeyguardSecurely 732 */ 733 public void verifyUnlock(IKeyguardExitCallback callback) { 734 synchronized (this) { 735 if (DEBUG) Log.d(TAG, "verifyUnlock"); 736 if (!mUpdateMonitor.isDeviceProvisioned()) { 737 // don't allow this api when the device isn't provisioned 738 if (DEBUG) Log.d(TAG, "ignoring because device isn't provisioned"); 739 try { 740 callback.onKeyguardExitResult(false); 741 } catch (RemoteException e) { 742 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); 743 } 744 } else if (mExternallyEnabled) { 745 // this only applies when the user has externally disabled the 746 // keyguard. this is unexpected and means the user is not 747 // using the api properly. 748 Log.w(TAG, "verifyUnlock called when not externally disabled"); 749 try { 750 callback.onKeyguardExitResult(false); 751 } catch (RemoteException e) { 752 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); 753 } 754 } else if (mExitSecureCallback != null) { 755 // already in progress with someone else 756 try { 757 callback.onKeyguardExitResult(false); 758 } catch (RemoteException e) { 759 Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e); 760 } 761 } else { 762 mExitSecureCallback = callback; 763 verifyUnlockLocked(); 764 } 765 } 766 } 767 768 /** 769 * Is the keyguard currently showing? 770 */ 771 public boolean isShowing() { 772 return mShowing; 773 } 774 775 public boolean isOccluded() { 776 return mOccluded; 777 } 778 779 /** 780 * Is the keyguard currently showing and not being force hidden? 781 */ 782 public boolean isShowingAndNotOccluded() { 783 return mShowing && !mOccluded; 784 } 785 786 /** 787 * Notify us when the keyguard is occluded by another window 788 */ 789 public void setOccluded(boolean isOccluded) { 790 if (DEBUG) Log.d(TAG, "setOccluded " + isOccluded); 791 mHandler.removeMessages(SET_OCCLUDED); 792 Message msg = mHandler.obtainMessage(SET_OCCLUDED, (isOccluded ? 1 : 0), 0); 793 mHandler.sendMessage(msg); 794 } 795 796 /** 797 * Handles SET_OCCLUDED message sent by setOccluded() 798 */ 799 private void handleSetOccluded(boolean isOccluded) { 800 synchronized (KeyguardViewMediator.this) { 801 if (mOccluded != isOccluded) { 802 mOccluded = isOccluded; 803 mStatusBarKeyguardViewManager.setOccluded(isOccluded); 804 updateActivityLockScreenState(); 805 adjustStatusBarLocked(); 806 } 807 } 808 } 809 810 /** 811 * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout. 812 * This must be safe to call from any thread and with any window manager locks held. 813 */ 814 public void doKeyguardTimeout(Bundle options) { 815 mHandler.removeMessages(KEYGUARD_TIMEOUT); 816 Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options); 817 mHandler.sendMessage(msg); 818 } 819 820 /** 821 * Given the state of the keyguard, is the input restricted? 822 * Input is restricted when the keyguard is showing, or when the keyguard 823 * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet. 824 */ 825 public boolean isInputRestricted() { 826 return mShowing || mNeedToReshowWhenReenabled || !mUpdateMonitor.isDeviceProvisioned(); 827 } 828 829 /** 830 * Enable the keyguard if the settings are appropriate. 831 */ 832 private void doKeyguardLocked(Bundle options) { 833 // if another app is disabling us, don't show 834 if (!mExternallyEnabled) { 835 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled"); 836 837 // note: we *should* set mNeedToReshowWhenReenabled=true here, but that makes 838 // for an occasional ugly flicker in this situation: 839 // 1) receive a call with the screen on (no keyguard) or make a call 840 // 2) screen times out 841 // 3) user hits key to turn screen back on 842 // instead, we reenable the keyguard when we know the screen is off and the call 843 // ends (see the broadcast receiver below) 844 // TODO: clean this up when we have better support at the window manager level 845 // for apps that wish to be on top of the keyguard 846 return; 847 } 848 849 // if the keyguard is already showing, don't bother 850 if (mStatusBarKeyguardViewManager.isShowing()) { 851 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing"); 852 return; 853 } 854 855 // if the setup wizard hasn't run yet, don't show 856 final boolean requireSim = !SystemProperties.getBoolean("keyguard.no_require_sim", 857 false); 858 final boolean provisioned = mUpdateMonitor.isDeviceProvisioned(); 859 final IccCardConstants.State state = mUpdateMonitor.getSimState(); 860 final boolean lockedOrMissing = state.isPinLocked() 861 || ((state == IccCardConstants.State.ABSENT 862 || state == IccCardConstants.State.PERM_DISABLED) 863 && requireSim); 864 865 if (!lockedOrMissing && !provisioned) { 866 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned" 867 + " and the sim is not locked or missing"); 868 return; 869 } 870 871 if (mLockPatternUtils.isLockScreenDisabled() && !lockedOrMissing) { 872 if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off"); 873 return; 874 } 875 876 if (mLockPatternUtils.checkVoldPassword()) { 877 if (DEBUG) Log.d(TAG, "Not showing lock screen since just decrypted"); 878 // Without this, settings is not enabled until the lock screen first appears 879 mShowing = false; 880 hideLocked(); 881 return; 882 } 883 884 if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen"); 885 showLocked(options); 886 } 887 888 /** 889 * Dismiss the keyguard through the security layers. 890 */ 891 public void handleDismiss() { 892 if (mShowing && !mOccluded) { 893 mStatusBarKeyguardViewManager.dismiss(); 894 } 895 } 896 897 public void dismiss() { 898 mHandler.sendEmptyMessage(DISMISS); 899 } 900 901 /** 902 * Send message to keyguard telling it to reset its state. 903 * @see #handleReset 904 */ 905 private void resetStateLocked() { 906 if (DEBUG) Log.e(TAG, "resetStateLocked"); 907 Message msg = mHandler.obtainMessage(RESET); 908 mHandler.sendMessage(msg); 909 } 910 911 /** 912 * Send message to keyguard telling it to verify unlock 913 * @see #handleVerifyUnlock() 914 */ 915 private void verifyUnlockLocked() { 916 if (DEBUG) Log.d(TAG, "verifyUnlockLocked"); 917 mHandler.sendEmptyMessage(VERIFY_UNLOCK); 918 } 919 920 921 /** 922 * Send a message to keyguard telling it the screen just turned on. 923 * @see #onScreenTurnedOff(int) 924 * @see #handleNotifyScreenOff 925 */ 926 private void notifyScreenOffLocked() { 927 if (DEBUG) Log.d(TAG, "notifyScreenOffLocked"); 928 mHandler.sendEmptyMessage(NOTIFY_SCREEN_OFF); 929 } 930 931 /** 932 * Send a message to keyguard telling it the screen just turned on. 933 * @see #onScreenTurnedOn 934 * @see #handleNotifyScreenOn 935 */ 936 private void notifyScreenOnLocked(IKeyguardShowCallback result) { 937 if (DEBUG) Log.d(TAG, "notifyScreenOnLocked"); 938 Message msg = mHandler.obtainMessage(NOTIFY_SCREEN_ON, result); 939 mHandler.sendMessage(msg); 940 } 941 942 /** 943 * Send message to keyguard telling it to show itself 944 * @see #handleShow 945 */ 946 private void showLocked(Bundle options) { 947 if (DEBUG) Log.d(TAG, "showLocked"); 948 // ensure we stay awake until we are finished displaying the keyguard 949 mShowKeyguardWakeLock.acquire(); 950 Message msg = mHandler.obtainMessage(SHOW, options); 951 mHandler.sendMessage(msg); 952 } 953 954 /** 955 * Send message to keyguard telling it to hide itself 956 * @see #handleHide() 957 */ 958 private void hideLocked() { 959 if (DEBUG) Log.d(TAG, "hideLocked"); 960 Message msg = mHandler.obtainMessage(HIDE); 961 mHandler.sendMessage(msg); 962 } 963 964 public boolean isSecure() { 965 return mLockPatternUtils.isSecure() 966 || KeyguardUpdateMonitor.getInstance(mContext).isSimPinSecure(); 967 } 968 969 /** 970 * Update the newUserId. Call while holding WindowManagerService lock. 971 * NOTE: Should only be called by KeyguardViewMediator in response to the user id changing. 972 * 973 * @param newUserId The id of the incoming user. 974 */ 975 public void setCurrentUser(int newUserId) { 976 mLockPatternUtils.setCurrentUser(newUserId); 977 } 978 979 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { 980 @Override 981 public void onReceive(Context context, Intent intent) { 982 if (DELAYED_KEYGUARD_ACTION.equals(intent.getAction())) { 983 final int sequence = intent.getIntExtra("seq", 0); 984 if (DEBUG) Log.d(TAG, "received DELAYED_KEYGUARD_ACTION with seq = " 985 + sequence + ", mDelayedShowingSequence = " + mDelayedShowingSequence); 986 synchronized (KeyguardViewMediator.this) { 987 if (mDelayedShowingSequence == sequence) { 988 // Don't play lockscreen SFX if the screen went off due to timeout. 989 mSuppressNextLockSound = true; 990 doKeyguardLocked(null); 991 } 992 } 993 } 994 } 995 }; 996 997 public void keyguardDone(boolean authenticated, boolean wakeup) { 998 if (DEBUG) Log.d(TAG, "keyguardDone(" + authenticated + ")"); 999 EventLog.writeEvent(70000, 2); 1000 synchronized (this) { 1001 mKeyguardDonePending = false; 1002 } 1003 Message msg = mHandler.obtainMessage(KEYGUARD_DONE, authenticated ? 1 : 0, wakeup ? 1 : 0); 1004 mHandler.sendMessage(msg); 1005 } 1006 1007 /** 1008 * This handler will be associated with the policy thread, which will also 1009 * be the UI thread of the keyguard. Since the apis of the policy, and therefore 1010 * this class, can be called by other threads, any action that directly 1011 * interacts with the keyguard ui should be posted to this handler, rather 1012 * than called directly. 1013 */ 1014 private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) { 1015 @Override 1016 public void handleMessage(Message msg) { 1017 switch (msg.what) { 1018 case SHOW: 1019 handleShow((Bundle) msg.obj); 1020 break; 1021 case HIDE: 1022 handleHide(); 1023 break; 1024 case RESET: 1025 handleReset(); 1026 break; 1027 case VERIFY_UNLOCK: 1028 handleVerifyUnlock(); 1029 break; 1030 case NOTIFY_SCREEN_OFF: 1031 handleNotifyScreenOff(); 1032 break; 1033 case NOTIFY_SCREEN_ON: 1034 handleNotifyScreenOn((IKeyguardShowCallback) msg.obj); 1035 break; 1036 case KEYGUARD_DONE: 1037 handleKeyguardDone(msg.arg1 != 0, msg.arg2 != 0); 1038 break; 1039 case KEYGUARD_DONE_DRAWING: 1040 handleKeyguardDoneDrawing(); 1041 break; 1042 case KEYGUARD_DONE_AUTHENTICATING: 1043 keyguardDone(true, true); 1044 break; 1045 case SET_OCCLUDED: 1046 handleSetOccluded(msg.arg1 != 0); 1047 break; 1048 case KEYGUARD_TIMEOUT: 1049 synchronized (KeyguardViewMediator.this) { 1050 doKeyguardLocked((Bundle) msg.obj); 1051 } 1052 break; 1053 case DISMISS: 1054 handleDismiss(); 1055 break; 1056 case START_KEYGUARD_EXIT_ANIM: 1057 StartKeyguardExitAnimParams params = (StartKeyguardExitAnimParams) msg.obj; 1058 handleStartKeyguardExitAnimation(params.startTime, params.fadeoutDuration); 1059 break; 1060 } 1061 } 1062 }; 1063 1064 /** 1065 * @see #keyguardDone 1066 * @see #KEYGUARD_DONE 1067 */ 1068 private void handleKeyguardDone(boolean authenticated, boolean wakeup) { 1069 if (DEBUG) Log.d(TAG, "handleKeyguardDone"); 1070 1071 if (authenticated) { 1072 mUpdateMonitor.clearFailedUnlockAttempts(); 1073 } 1074 mUpdateMonitor.clearFingerprintRecognized(); 1075 1076 if (mExitSecureCallback != null) { 1077 try { 1078 mExitSecureCallback.onKeyguardExitResult(authenticated); 1079 } catch (RemoteException e) { 1080 Slog.w(TAG, "Failed to call onKeyguardExitResult(" + authenticated + ")", e); 1081 } 1082 1083 mExitSecureCallback = null; 1084 1085 if (authenticated) { 1086 // after succesfully exiting securely, no need to reshow 1087 // the keyguard when they've released the lock 1088 mExternallyEnabled = true; 1089 mNeedToReshowWhenReenabled = false; 1090 } 1091 } 1092 1093 handleHide(); 1094 sendUserPresentBroadcast(); 1095 } 1096 1097 private void sendUserPresentBroadcast() { 1098 final UserHandle currentUser = new UserHandle(mLockPatternUtils.getCurrentUser()); 1099 mContext.sendBroadcastAsUser(USER_PRESENT_INTENT, currentUser); 1100 } 1101 1102 /** 1103 * @see #keyguardDone 1104 * @see #KEYGUARD_DONE_DRAWING 1105 */ 1106 private void handleKeyguardDoneDrawing() { 1107 synchronized(this) { 1108 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing"); 1109 if (mWaitingUntilKeyguardVisible) { 1110 if (DEBUG) Log.d(TAG, "handleKeyguardDoneDrawing: notifying mWaitingUntilKeyguardVisible"); 1111 mWaitingUntilKeyguardVisible = false; 1112 notifyAll(); 1113 1114 // there will usually be two of these sent, one as a timeout, and one 1115 // as a result of the callback, so remove any remaining messages from 1116 // the queue 1117 mHandler.removeMessages(KEYGUARD_DONE_DRAWING); 1118 } 1119 } 1120 } 1121 1122 private void playSounds(boolean locked) { 1123 // User feedback for keyguard. 1124 1125 if (mSuppressNextLockSound) { 1126 mSuppressNextLockSound = false; 1127 return; 1128 } 1129 1130 final ContentResolver cr = mContext.getContentResolver(); 1131 if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) { 1132 final int whichSound = locked 1133 ? mLockSoundId 1134 : mUnlockSoundId; 1135 mLockSounds.stop(mLockSoundStreamId); 1136 // Init mAudioManager 1137 if (mAudioManager == null) { 1138 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); 1139 if (mAudioManager == null) return; 1140 mMasterStreamType = mAudioManager.getMasterStreamType(); 1141 } 1142 // If the stream is muted, don't play the sound 1143 if (mAudioManager.isStreamMute(mMasterStreamType)) return; 1144 1145 mLockSoundStreamId = mLockSounds.play(whichSound, 1146 mLockSoundVolume, mLockSoundVolume, 1/*priortiy*/, 0/*loop*/, 1.0f/*rate*/); 1147 } 1148 } 1149 1150 private void updateActivityLockScreenState() { 1151 try { 1152 ActivityManagerNative.getDefault().setLockScreenShown(mShowing && !mOccluded); 1153 } catch (RemoteException e) { 1154 } 1155 } 1156 1157 /** 1158 * Handle message sent by {@link #showLocked}. 1159 * @see #SHOW 1160 */ 1161 private void handleShow(Bundle options) { 1162 synchronized (KeyguardViewMediator.this) { 1163 if (!mSystemReady) { 1164 if (DEBUG) Log.d(TAG, "ignoring handleShow because system is not ready."); 1165 return; 1166 } else { 1167 if (DEBUG) Log.d(TAG, "handleShow"); 1168 } 1169 1170 mStatusBarKeyguardViewManager.show(options); 1171 mHiding = false; 1172 mShowing = true; 1173 mKeyguardDonePending = false; 1174 updateActivityLockScreenState(); 1175 adjustStatusBarLocked(); 1176 userActivity(); 1177 1178 // Do this at the end to not slow down display of the keyguard. 1179 playSounds(true); 1180 1181 mShowKeyguardWakeLock.release(); 1182 } 1183 mKeyguardDisplayManager.show(); 1184 } 1185 1186 /** 1187 * Handle message sent by {@link #hideLocked()} 1188 * @see #HIDE 1189 */ 1190 private void handleHide() { 1191 synchronized (KeyguardViewMediator.this) { 1192 if (DEBUG) Log.d(TAG, "handleHide"); 1193 try { 1194 mHiding = true; 1195 if (mShowing) { 1196 1197 // Don't actually hide the Keyguard at the moment, wait for window manager until 1198 // it tells us it's safe to do so with startKeyguardExitAnimation. 1199 mWM.keyguardGoingAway(); 1200 } else { 1201 1202 // Don't try to rely on WindowManager - if Keyguard wasn't showing, window 1203 // manager won't start the exit animation. 1204 handleStartKeyguardExitAnimation(0, 0); 1205 } 1206 } catch (RemoteException e) { 1207 Log.e(TAG, "Error while calling WindowManager", e); 1208 } 1209 } 1210 } 1211 1212 private void handleStartKeyguardExitAnimation(long startTime, long fadeoutDuration) { 1213 synchronized (KeyguardViewMediator.this) { 1214 1215 if (!mHiding) { 1216 return; 1217 } 1218 mHiding = false; 1219 1220 // only play "unlock" noises if not on a call (since the incall UI 1221 // disables the keyguard) 1222 if (TelephonyManager.EXTRA_STATE_IDLE.equals(mPhoneState)) { 1223 playSounds(false); 1224 } 1225 1226 mStatusBarKeyguardViewManager.hide(startTime, fadeoutDuration); 1227 mShowing = false; 1228 mKeyguardDonePending = false; 1229 updateActivityLockScreenState(); 1230 adjustStatusBarLocked(); 1231 } 1232 } 1233 1234 private void adjustStatusBarLocked() { 1235 if (mStatusBarManager == null) { 1236 mStatusBarManager = (StatusBarManager) 1237 mContext.getSystemService(Context.STATUS_BAR_SERVICE); 1238 } 1239 if (mStatusBarManager == null) { 1240 Log.w(TAG, "Could not get status bar manager"); 1241 } else { 1242 // Disable aspects of the system/status/navigation bars that must not be re-enabled by 1243 // windows that appear on top, ever 1244 int flags = StatusBarManager.DISABLE_NONE; 1245 if (mShowing) { 1246 // Permanently disable components not available when keyguard is enabled 1247 // (like recents). Temporary enable/disable (e.g. the "back" button) are 1248 // done in KeyguardHostView. 1249 flags |= StatusBarManager.DISABLE_RECENT; 1250 if (!isAssistantAvailable()) { 1251 flags |= StatusBarManager.DISABLE_SEARCH; 1252 } 1253 } 1254 if (isShowingAndNotOccluded()) { 1255 flags |= StatusBarManager.DISABLE_HOME; 1256 } 1257 1258 if (DEBUG) { 1259 Log.d(TAG, "adjustStatusBarLocked: mShowing=" + mShowing + " mOccluded=" + mOccluded 1260 + " isSecure=" + isSecure() + " --> flags=0x" + Integer.toHexString(flags)); 1261 } 1262 1263 if (!(mContext instanceof Activity)) { 1264 mStatusBarManager.disable(flags); 1265 } 1266 } 1267 } 1268 1269 /** 1270 * Handle message sent by {@link #resetStateLocked} 1271 * @see #RESET 1272 */ 1273 private void handleReset() { 1274 synchronized (KeyguardViewMediator.this) { 1275 if (DEBUG) Log.d(TAG, "handleReset"); 1276 mStatusBarKeyguardViewManager.reset(); 1277 } 1278 } 1279 1280 /** 1281 * Handle message sent by {@link #verifyUnlock} 1282 * @see #VERIFY_UNLOCK 1283 */ 1284 private void handleVerifyUnlock() { 1285 synchronized (KeyguardViewMediator.this) { 1286 if (DEBUG) Log.d(TAG, "handleVerifyUnlock"); 1287 mStatusBarKeyguardViewManager.verifyUnlock(); 1288 mShowing = true; 1289 updateActivityLockScreenState(); 1290 } 1291 } 1292 1293 /** 1294 * Handle message sent by {@link #notifyScreenOffLocked()} 1295 * @see #NOTIFY_SCREEN_OFF 1296 */ 1297 private void handleNotifyScreenOff() { 1298 synchronized (KeyguardViewMediator.this) { 1299 if (DEBUG) Log.d(TAG, "handleNotifyScreenOff"); 1300 mStatusBarKeyguardViewManager.onScreenTurnedOff(); 1301 } 1302 } 1303 1304 /** 1305 * Handle message sent by {@link #notifyScreenOnLocked} 1306 * @see #NOTIFY_SCREEN_ON 1307 */ 1308 private void handleNotifyScreenOn(IKeyguardShowCallback callback) { 1309 synchronized (KeyguardViewMediator.this) { 1310 if (DEBUG) Log.d(TAG, "handleNotifyScreenOn"); 1311 mStatusBarKeyguardViewManager.onScreenTurnedOn(callback); 1312 } 1313 } 1314 1315 public boolean isDismissable() { 1316 return mKeyguardDonePending || !isSecure(); 1317 } 1318 1319 private boolean isAssistantAvailable() { 1320 return mSearchManager != null 1321 && mSearchManager.getAssistIntent(mContext, false, UserHandle.USER_CURRENT) != null; 1322 } 1323 1324 public void onBootCompleted() { 1325 mUpdateMonitor.dispatchBootCompleted(); 1326 } 1327 1328 public StatusBarKeyguardViewManager registerStatusBar(PhoneStatusBar phoneStatusBar, 1329 ViewGroup container, StatusBarWindowManager statusBarWindowManager, 1330 ScrimController scrimController) { 1331 mStatusBarKeyguardViewManager.registerStatusBar(phoneStatusBar, container, 1332 statusBarWindowManager, scrimController); 1333 return mStatusBarKeyguardViewManager; 1334 } 1335 1336 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) { 1337 Message msg = mHandler.obtainMessage(START_KEYGUARD_EXIT_ANIM, 1338 new StartKeyguardExitAnimParams(startTime, fadeoutDuration)); 1339 mHandler.sendMessage(msg); 1340 } 1341 1342 public ViewMediatorCallback getViewMediatorCallback() { 1343 return mViewMediatorCallback; 1344 } 1345 1346 private static class StartKeyguardExitAnimParams { 1347 1348 long startTime; 1349 long fadeoutDuration; 1350 1351 private StartKeyguardExitAnimParams(long startTime, long fadeoutDuration) { 1352 this.startTime = startTime; 1353 this.fadeoutDuration = fadeoutDuration; 1354 } 1355 } 1356} 1357