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