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