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