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