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